Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(335)

Side by Side Diff: base/process/kill_mac.cc

Issue 18555002: Split out process killing functions from base/process_util.h into base/process/kill.h. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « base/process/kill.cc ('k') | base/process/kill_posix.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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/kill.h"
6 6
7 #import <Cocoa/Cocoa.h>
8 #include <crt_externs.h>
9 #include <errno.h>
10 #include <mach/mach.h>
11 #include <mach/mach_init.h>
12 #include <mach/mach_vm.h>
13 #include <mach/shared_region.h>
14 #include <mach/task.h>
15 #include <malloc/malloc.h>
16 #import <objc/runtime.h>
17 #include <signal.h> 7 #include <signal.h>
18 #include <spawn.h>
19 #include <sys/event.h> 8 #include <sys/event.h>
20 #include <sys/sysctl.h>
21 #include <sys/types.h> 9 #include <sys/types.h>
22 #include <sys/wait.h> 10 #include <sys/wait.h>
23 11
24 #include <new>
25 #include <string>
26
27 #include "base/containers/hash_tables.h"
28 #include "base/debug/debugger.h"
29 #include "base/file_util.h" 12 #include "base/file_util.h"
30 #include "base/lazy_instance.h"
31 #include "base/logging.h" 13 #include "base/logging.h"
32 #include "base/mac/mac_util.h"
33 #include "base/mac/scoped_mach_port.h"
34 #include "base/posix/eintr_wrapper.h" 14 #include "base/posix/eintr_wrapper.h"
35 #include "base/scoped_clear_errno.h"
36 #include "base/strings/string_util.h"
37 #include "base/sys_info.h"
38 #include "third_party/apple_apsl/CFBase.h"
39 #include "third_party/apple_apsl/malloc.h"
40 15
41 namespace base { 16 namespace base {
42 17
43 void RestoreDefaultExceptionHandler() {
44 // This function is tailored to remove the Breakpad exception handler.
45 // exception_mask matches s_exception_mask in
46 // breakpad/src/client/mac/handler/exception_handler.cc
47 const exception_mask_t exception_mask = EXC_MASK_BAD_ACCESS |
48 EXC_MASK_BAD_INSTRUCTION |
49 EXC_MASK_ARITHMETIC |
50 EXC_MASK_BREAKPOINT;
51
52 // Setting the exception port to MACH_PORT_NULL may not be entirely
53 // kosher to restore the default exception handler, but in practice,
54 // it results in the exception port being set to Apple Crash Reporter,
55 // the desired behavior.
56 task_set_exception_ports(mach_task_self(), exception_mask, MACH_PORT_NULL,
57 EXCEPTION_DEFAULT, THREAD_STATE_NONE);
58 }
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 { 18 namespace {
74 19
75 const int kWaitBeforeKillSeconds = 2; 20 const int kWaitBeforeKillSeconds = 2;
76 21
77 // Reap |child| process. This call blocks until completion. 22 // Reap |child| process. This call blocks until completion.
78 void BlockingReap(pid_t child) { 23 void BlockingReap(pid_t child) {
79 const pid_t result = HANDLE_EINTR(waitpid(child, NULL, 0)); 24 const pid_t result = HANDLE_EINTR(waitpid(child, NULL, 0));
80 if (result == -1) { 25 if (result == -1) {
81 DPLOG(ERROR) << "waitpid(" << child << ", NULL, 0)"; 26 DPLOG(ERROR) << "waitpid(" << child << ", NULL, 0)";
82 } 27 }
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
219 } 164 }
220 } 165 }
221 166
222 } // namespace 167 } // namespace
223 168
224 void EnsureProcessTerminated(ProcessHandle process) { 169 void EnsureProcessTerminated(ProcessHandle process) {
225 WaitForChildToDie(process, kWaitBeforeKillSeconds); 170 WaitForChildToDie(process, kWaitBeforeKillSeconds);
226 } 171 }
227 172
228 } // namespace base 173 } // namespace base
OLDNEW
« no previous file with comments | « base/process/kill.cc ('k') | base/process/kill_posix.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698