Index: base/process_util_ios.mm |
diff --git a/base/process_util_ios.mm b/base/process_util_ios.mm |
new file mode 100644 |
index 0000000000000000000000000000000000000000..7e2c507d987f0ba137e475de7029788a518506ec |
--- /dev/null |
+++ b/base/process_util_ios.mm |
@@ -0,0 +1,95 @@ |
+// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "base/process_util.h" |
+ |
+#import <Foundation/Foundation.h> |
+#include <iostream> |
Mark Mentovai
2012/07/11 12:36:51
C++ system headers belong in a separate section th
stuartmorgan
2012/07/11 13:56:57
Done.
|
+#include <mach/task.h> |
+ |
+#include "base/logging.h" |
+ |
+// This is just enough of a shim to let the support needed by test_support |
+// link. In general, process_util isn't valid on iOS. |
+ |
+namespace base { |
+ |
+namespace { |
+ |
+void StackDumpSignalHandler(int signal) { |
+ LOG(ERROR) << "Received signal " << signal; |
+ NSArray *stack_symbols = [NSThread callStackSymbols]; |
+ for (NSString* stack_symbol in stack_symbols) { |
+ std::cerr << "\t" << [stack_symbol UTF8String] << "\n"; |
Mark Mentovai
2012/07/11 12:36:51
When do we ever use C++ streams and cerr as oppose
stuartmorgan
2012/07/11 13:56:57
Done.
|
+ } |
+ _exit(1); |
+} |
+ |
+bool GetTaskInfo(task_basic_info_64* task_info_data) { |
+ mach_msg_type_number_t count = TASK_BASIC_INFO_64_COUNT; |
+ kern_return_t kr = task_info(mach_task_self(), |
+ TASK_BASIC_INFO_64, |
+ reinterpret_cast<task_info_t>(task_info_data), |
+ &count); |
+ return kr == KERN_SUCCESS; |
+} |
+ |
+} // anonymous namespace |
Mark Mentovai
2012/07/11 12:36:51
Normally, anonymous namespaces just close with //
stuartmorgan
2012/07/11 13:56:57
Done.
|
+ |
+ProcessId GetCurrentProcId() { |
+ return getpid(); |
+} |
+ |
+void EnableTerminationOnHeapCorruption() { |
+ // On iOS, there nothing to do AFAIK. |
+} |
+ |
+void EnableTerminationOnOutOfMemory() { |
+ // iOS provides this for free! |
+} |
+ |
+bool EnableInProcessStackDumping() { |
+ // When running in an application, our code typically expects SIGPIPE |
+ // to be ignored. Therefore, when testing that same code, it should run |
+ // with SIGPIPE ignored as well. |
+ struct sigaction action; |
+ action.sa_handler = SIG_IGN; |
+ action.sa_flags = 0; |
+ sigemptyset(&action.sa_mask); |
+ bool success = (sigaction(SIGPIPE, &action, NULL) == 0); |
+ |
+ success &= (signal(SIGILL, &StackDumpSignalHandler) != SIG_ERR); |
+ success &= (signal(SIGABRT, &StackDumpSignalHandler) != SIG_ERR); |
+ success &= (signal(SIGFPE, &StackDumpSignalHandler) != SIG_ERR); |
+ success &= (signal(SIGBUS, &StackDumpSignalHandler) != SIG_ERR); |
+ success &= (signal(SIGSEGV, &StackDumpSignalHandler) != SIG_ERR); |
+ success &= (signal(SIGSYS, &StackDumpSignalHandler) != SIG_ERR); |
+ |
+ return success; |
+} |
+ |
+void RaiseProcessToHighPriority() { |
+ // Impossible on iOS. Do nothing. |
+} |
+ |
+ProcessMetrics::ProcessMetrics(ProcessHandle process, |
+ ProcessMetrics::PortProvider* port_provider) {} |
Mark Mentovai
2012/07/11 12:36:51
The port provider interface is nonsense on iOS, wh
stuartmorgan
2012/07/11 13:56:57
Done. (I suspect it was the other way to avoid cha
Mark Mentovai
2012/07/11 14:04:21
stuartmorgan wrote:
stuartmorgan
2012/07/11 14:18:03
Sure, but the same logic applies to the CreateProc
|
+ |
+ProcessMetrics::~ProcessMetrics() {} |
+ |
+// static |
+ProcessMetrics* ProcessMetrics::CreateProcessMetrics( |
+ ProcessHandle process, |
+ ProcessMetrics::PortProvider* port_provider) { |
+ return new ProcessMetrics(process, port_provider); |
+} |
+ |
+size_t ProcessMetrics::GetWorkingSetSize() const { |
+ task_basic_info_64 task_info_data; |
+ if (!GetTaskInfo(&task_info_data)) |
+ return 0; |
+ return task_info_data.resident_size; |
+} |
+ |
+} // namespace base |