OLD | NEW |
1 // Copyright (c) 2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2008 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 | 5 |
6 #include "base/process_util.h" | 6 #include "base/process_util.h" |
7 | 7 |
8 #import <Cocoa/Cocoa.h> | 8 #import <Cocoa/Cocoa.h> |
9 #include <crt_externs.h> | 9 #include <crt_externs.h> |
10 #include <mach/mach_init.h> | 10 #include <mach/mach_init.h> |
11 #include <mach/task.h> | 11 #include <mach/task.h> |
12 #include <spawn.h> | 12 #include <spawn.h> |
13 #include <sys/sysctl.h> | 13 #include <sys/sysctl.h> |
14 #include <sys/types.h> | 14 #include <sys/types.h> |
15 #include <sys/wait.h> | 15 #include <sys/wait.h> |
16 | 16 |
17 #include <string> | 17 #include <string> |
18 | 18 |
19 #include "base/eintr_wrapper.h" | 19 #include "base/eintr_wrapper.h" |
20 #include "base/logging.h" | 20 #include "base/logging.h" |
21 #include "base/string_util.h" | 21 #include "base/string_util.h" |
| 22 #include "base/sys_string_conversions.h" |
22 #include "base/time.h" | 23 #include "base/time.h" |
23 | 24 |
24 namespace base { | 25 namespace base { |
25 | 26 |
26 void RestoreDefaultExceptionHandler() { | 27 void RestoreDefaultExceptionHandler() { |
27 // This function is tailored to remove the Breakpad exception handler. | 28 // This function is tailored to remove the Breakpad exception handler. |
28 // exception_mask matches s_exception_mask in | 29 // exception_mask matches s_exception_mask in |
29 // breakpad/src/client/mac/handler/exception_handler.cc | 30 // breakpad/src/client/mac/handler/exception_handler.cc |
30 const exception_mask_t exception_mask = EXC_MASK_BAD_ACCESS | | 31 const exception_mask_t exception_mask = EXC_MASK_BAD_ACCESS | |
31 EXC_MASK_BAD_INSTRUCTION | | 32 EXC_MASK_BAD_INSTRUCTION | |
32 EXC_MASK_ARITHMETIC | | 33 EXC_MASK_ARITHMETIC | |
33 EXC_MASK_BREAKPOINT; | 34 EXC_MASK_BREAKPOINT; |
34 | 35 |
35 // Setting the exception port to MACH_PORT_NULL may not be entirely | 36 // Setting the exception port to MACH_PORT_NULL may not be entirely |
36 // kosher to restore the default exception handler, but in practice, | 37 // kosher to restore the default exception handler, but in practice, |
37 // it results in the exception port being set to Apple Crash Reporter, | 38 // it results in the exception port being set to Apple Crash Reporter, |
38 // the desired behavior. | 39 // the desired behavior. |
39 task_set_exception_ports(mach_task_self(), exception_mask, MACH_PORT_NULL, | 40 task_set_exception_ports(mach_task_self(), exception_mask, MACH_PORT_NULL, |
40 EXCEPTION_DEFAULT, THREAD_STATE_NONE); | 41 EXCEPTION_DEFAULT, THREAD_STATE_NONE); |
41 } | 42 } |
42 | 43 |
43 NamedProcessIterator::NamedProcessIterator(const std::wstring& executable_name, | 44 NamedProcessIterator::NamedProcessIterator(const std::wstring& executable_name, |
44 const ProcessFilter* filter) | 45 const ProcessFilter* filter) |
45 : executable_name_(executable_name), | 46 : executable_name_(executable_name), |
46 index_of_kinfo_proc_(0), | 47 index_of_kinfo_proc_(0), |
47 filter_(filter) { | 48 filter_(filter) { |
48 // Get a snapshot of all of my processes (yes, as we loop it can go stale, but | 49 // Get a snapshot of all of my processes (yes, as we loop it can go stale, but |
49 // but trying to find where we were in a constantly changing list is basically | 50 // but trying to find where we were in a constantly changing list is basically |
50 // impossible. | 51 // impossible. |
51 | 52 |
52 int mib[] = { CTL_KERN, KERN_PROC, KERN_PROC_UID, geteuid() }; | 53 int mib[] = { CTL_KERN, KERN_PROC, KERN_PROC_UID, geteuid() }; |
53 | 54 |
54 // Since more processes could start between when we get the size and when | 55 // Since more processes could start between when we get the size and when |
55 // we get the list, we do a loop to keep trying until we get it. | 56 // we get the list, we do a loop to keep trying until we get it. |
56 bool done = false; | 57 bool done = false; |
57 int try_num = 1; | 58 int try_num = 1; |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
104 } while (result && !IncludeEntry()); | 105 } while (result && !IncludeEntry()); |
105 | 106 |
106 if (result) { | 107 if (result) { |
107 return &entry_; | 108 return &entry_; |
108 } | 109 } |
109 | 110 |
110 return NULL; | 111 return NULL; |
111 } | 112 } |
112 | 113 |
113 bool NamedProcessIterator::CheckForNextProcess() { | 114 bool NamedProcessIterator::CheckForNextProcess() { |
114 std::string executable_name_utf8(WideToUTF8(executable_name_)); | 115 std::string executable_name_utf8(base::SysWideToUTF8(executable_name_)); |
115 | 116 |
116 std::string data; | 117 std::string data; |
117 std::string exec_name; | 118 std::string exec_name; |
118 | 119 |
119 for (; index_of_kinfo_proc_ < kinfo_procs_.size(); ++index_of_kinfo_proc_) { | 120 for (; index_of_kinfo_proc_ < kinfo_procs_.size(); ++index_of_kinfo_proc_) { |
120 kinfo_proc* kinfo = &kinfo_procs_[index_of_kinfo_proc_]; | 121 kinfo_proc* kinfo = &kinfo_procs_[index_of_kinfo_proc_]; |
121 | 122 |
122 // Skip processes just awaiting collection | 123 // Skip processes just awaiting collection |
123 if ((kinfo->kp_proc.p_pid > 0) && (kinfo->kp_proc.p_stat == SZOMB)) | 124 if ((kinfo->kp_proc.p_pid > 0) && (kinfo->kp_proc.p_stat == SZOMB)) |
124 continue; | 125 continue; |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
206 void ProcessMetrics::GetCommittedKBytes(CommittedKBytes* usage) const { | 207 void ProcessMetrics::GetCommittedKBytes(CommittedKBytes* usage) const { |
207 } | 208 } |
208 | 209 |
209 bool ProcessMetrics::GetWorkingSetKBytes(WorkingSetKBytes* ws_usage) const { | 210 bool ProcessMetrics::GetWorkingSetKBytes(WorkingSetKBytes* ws_usage) const { |
210 return false; | 211 return false; |
211 } | 212 } |
212 | 213 |
213 // ------------------------------------------------------------------------ | 214 // ------------------------------------------------------------------------ |
214 | 215 |
215 } // namespace base | 216 } // namespace base |
OLD | NEW |