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/launch.h" | 5 #include "base/process/launch.h" |
6 | 6 |
7 #include <mach/mach.h> | 7 #include <mach/mach.h> |
8 #include <servers/bootstrap.h> | 8 #include <servers/bootstrap.h> |
9 | 9 |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 10 matching lines...) Expand all Loading... |
21 EXC_MASK_BREAKPOINT; | 21 EXC_MASK_BREAKPOINT; |
22 | 22 |
23 // Setting the exception port to MACH_PORT_NULL may not be entirely | 23 // Setting the exception port to MACH_PORT_NULL may not be entirely |
24 // kosher to restore the default exception handler, but in practice, | 24 // kosher to restore the default exception handler, but in practice, |
25 // it results in the exception port being set to Apple Crash Reporter, | 25 // it results in the exception port being set to Apple Crash Reporter, |
26 // the desired behavior. | 26 // the desired behavior. |
27 task_set_exception_ports(mach_task_self(), exception_mask, MACH_PORT_NULL, | 27 task_set_exception_ports(mach_task_self(), exception_mask, MACH_PORT_NULL, |
28 EXCEPTION_DEFAULT, THREAD_STATE_NONE); | 28 EXCEPTION_DEFAULT, THREAD_STATE_NONE); |
29 } | 29 } |
30 | 30 |
31 void ReplaceBootstrapPort(const std::string& new_bootstrap_name) { | |
32 // This function is called between fork() and exec(), so it should take care | |
33 // to run properly in that situation. | |
34 | |
35 mach_port_t port = MACH_PORT_NULL; | |
36 kern_return_t kr = bootstrap_look_up(bootstrap_port, | |
37 new_bootstrap_name.c_str(), &port); | |
38 if (kr != KERN_SUCCESS) { | |
39 RAW_LOG(FATAL, "Failed to look up replacement bootstrap port."); | |
40 } | |
41 | |
42 kr = task_set_bootstrap_port(mach_task_self(), port); | |
43 if (kr != KERN_SUCCESS) { | |
44 RAW_LOG(FATAL, "Failed to replace bootstrap port."); | |
45 } | |
46 | |
47 // On OS X 10.10 and higher, libxpc uses the port stash to transfer the | |
48 // XPC root port. This is effectively the same connection as the Mach | |
49 // bootstrap port, but not transferred using the task special port. | |
50 // Therefore, stash the replacement bootstrap port, so that on 10.10 it | |
51 // will be retrieved by the XPC code and used as a replacement for the | |
52 // XPC root port as well. | |
53 kr = mach_ports_register(mach_task_self(), &port, 1); | |
54 if (kr != KERN_SUCCESS) { | |
55 RAW_LOG(ERROR, "Failed to register replacement bootstrap port."); | |
56 } | |
57 } | |
58 | |
59 } // namespace base | 31 } // namespace base |
OLD | NEW |