OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "sandbox/mac/pre_exec_delegate.h" | |
6 | |
7 #include <mach/mach.h> | |
8 #include <servers/bootstrap.h> | |
9 | |
10 #include "base/logging.h" | |
11 #include "sandbox/mac/bootstrap_sandbox.h" | |
12 | |
13 namespace sandbox { | |
14 | |
15 PreExecDelegate::PreExecDelegate( | |
16 const std::string& sandbox_server_bootstrap_name, | |
17 uint64_t sandbox_token) | |
18 : sandbox_server_bootstrap_name_(sandbox_server_bootstrap_name), | |
19 sandbox_server_bootstrap_name_ptr_( | |
20 sandbox_server_bootstrap_name_.c_str()), | |
21 sandbox_token_(sandbox_token) { | |
22 } | |
23 | |
24 PreExecDelegate::~PreExecDelegate() {} | |
25 | |
26 void PreExecDelegate::RunAsyncSafe() { | |
27 mach_port_t sandbox_server_port = MACH_PORT_NULL; | |
28 kern_return_t kr = bootstrap_look_up(bootstrap_port, | |
29 sandbox_server_bootstrap_name_ptr_, &sandbox_server_port); | |
30 if (kr != KERN_SUCCESS) | |
31 RAW_LOG(FATAL, "Failed to look up bootstrap sandbox server port."); | |
32 | |
33 mach_port_t new_bootstrap_port = MACH_PORT_NULL; | |
34 if (!BootstrapSandbox::ClientCheckIn(sandbox_server_port, | |
35 sandbox_token_, | |
36 &new_bootstrap_port)) { | |
37 RAW_LOG(FATAL, "Failed to check in with sandbox server."); | |
38 } | |
39 | |
40 kr = task_set_bootstrap_port(mach_task_self(), new_bootstrap_port); | |
41 if (kr != KERN_SUCCESS) | |
42 RAW_LOG(FATAL, "Failed to replace bootstrap port."); | |
43 | |
44 // On OS X 10.10 and higher, libxpc uses the port stash to transfer the | |
45 // XPC root port. This is effectively the same connection as the Mach | |
46 // bootstrap port, but not transferred using the task special port. | |
47 // Therefore, stash the replacement bootstrap port, so that on 10.10 it | |
48 // will be retrieved by the XPC code and used as a replacement for the | |
49 // XPC root port as well. | |
50 kr = mach_ports_register(mach_task_self(), &new_bootstrap_port, 1); | |
Mark Mentovai
2015/09/17 19:45:16
Any reason to do this pre-10.10? It gives the chil
Robert Sesek
2015/09/17 20:27:24
Done.
| |
51 if (kr != KERN_SUCCESS) | |
52 RAW_LOG(ERROR, "Failed to register replacement bootstrap port."); | |
53 } | |
54 | |
55 } // namespace sandbox | |
OLD | NEW |