| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #include "base/process_util.h" | 5 #include "base/process_util.h" |
| 6 | 6 |
| 7 #import <Cocoa/Cocoa.h> | 7 #import <Cocoa/Cocoa.h> |
| 8 #include <crt_externs.h> | 8 #include <crt_externs.h> |
| 9 #include <errno.h> | 9 #include <errno.h> |
| 10 #include <mach/mach.h> | 10 #include <mach/mach.h> |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 50 EXC_MASK_BREAKPOINT; | 50 EXC_MASK_BREAKPOINT; |
| 51 | 51 |
| 52 // Setting the exception port to MACH_PORT_NULL may not be entirely | 52 // Setting the exception port to MACH_PORT_NULL may not be entirely |
| 53 // kosher to restore the default exception handler, but in practice, | 53 // kosher to restore the default exception handler, but in practice, |
| 54 // it results in the exception port being set to Apple Crash Reporter, | 54 // it results in the exception port being set to Apple Crash Reporter, |
| 55 // the desired behavior. | 55 // the desired behavior. |
| 56 task_set_exception_ports(mach_task_self(), exception_mask, MACH_PORT_NULL, | 56 task_set_exception_ports(mach_task_self(), exception_mask, MACH_PORT_NULL, |
| 57 EXCEPTION_DEFAULT, THREAD_STATE_NONE); | 57 EXCEPTION_DEFAULT, THREAD_STATE_NONE); |
| 58 } | 58 } |
| 59 | 59 |
| 60 ProcessId GetParentProcessId(ProcessHandle process) { | |
| 61 struct kinfo_proc info; | |
| 62 size_t length = sizeof(struct kinfo_proc); | |
| 63 int mib[4] = { CTL_KERN, KERN_PROC, KERN_PROC_PID, process }; | |
| 64 if (sysctl(mib, 4, &info, &length, NULL, 0) < 0) { | |
| 65 DPLOG(ERROR) << "sysctl"; | |
| 66 return -1; | |
| 67 } | |
| 68 if (length == 0) | |
| 69 return -1; | |
| 70 return info.kp_eproc.e_ppid; | |
| 71 } | |
| 72 | |
| 73 } // namespace base | 60 } // namespace base |
| OLD | NEW |