OLD | NEW |
| (Empty) |
1 // Copyright 2014 The Crashpad Authors. All rights reserved. | |
2 // | |
3 // Licensed under the Apache License, Version 2.0 (the "License"); | |
4 // you may not use this file except in compliance with the License. | |
5 // You may obtain a copy of the License at | |
6 // | |
7 // http://www.apache.org/licenses/LICENSE-2.0 | |
8 // | |
9 // Unless required by applicable law or agreed to in writing, software | |
10 // distributed under the License is distributed on an "AS IS" BASIS, | |
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
12 // See the License for the specific language governing permissions and | |
13 // limitations under the License. | |
14 | |
15 #include "util/mach/bootstrap.h" | |
16 | |
17 #include <AvailabilityMacros.h> | |
18 #include <servers/bootstrap.h> | |
19 | |
20 #include "base/basictypes.h" | |
21 #include "base/mac/scoped_mach_port.h" | |
22 #include "util/mac/mac_util.h" | |
23 | |
24 #if MAC_OS_X_VERSION_MIN_REQUIRED <= MAC_OS_X_VERSION_10_5 | |
25 namespace { | |
26 | |
27 // Wraps bootstrap_register to avoid the deprecation warning. It needs to be | |
28 // used on 10.5. | |
29 kern_return_t BootstrapRegister(mach_port_t bp, | |
30 name_t service_name, | |
31 mach_port_t sp) { | |
32 #pragma GCC diagnostic push | |
33 #pragma GCC diagnostic ignored "-Wdeprecated-declarations" | |
34 return bootstrap_register(bp, service_name, sp); | |
35 #pragma GCC diagnostic pop | |
36 } | |
37 | |
38 } // namespace | |
39 #endif | |
40 | |
41 namespace crashpad { | |
42 | |
43 kern_return_t BootstrapCheckIn(mach_port_t bp, | |
44 const std::string& service_name, | |
45 mach_port_t* service_port) { | |
46 // bootstrap_check_in (until the 10.6 SDK) and bootstrap_register (all SDKs) | |
47 // are declared with a char* argument, but they don’t actually modify the char | |
48 // data, so this is safe. | |
49 char* service_name_mutable = const_cast<char*>(service_name.c_str()); | |
50 | |
51 kern_return_t kr = bootstrap_check_in(bp, service_name_mutable, service_port); | |
52 | |
53 #if MAC_OS_X_VERSION_MIN_REQUIRED <= MAC_OS_X_VERSION_10_5 | |
54 if (kr == BOOTSTRAP_UNKNOWN_SERVICE && MacOSXMinorVersion() <= 5) { | |
55 // This code path should only be entered on 10.5 or earlier. | |
56 mach_port_t local_service_port; | |
57 kr = mach_port_allocate( | |
58 mach_task_self(), MACH_PORT_RIGHT_RECEIVE, &local_service_port); | |
59 if (kr != KERN_SUCCESS) { | |
60 return kr; | |
61 } | |
62 base::mac::ScopedMachReceiveRight service_port_receive_right_owner( | |
63 local_service_port); | |
64 | |
65 kr = mach_port_insert_right(mach_task_self(), | |
66 local_service_port, | |
67 local_service_port, | |
68 MACH_MSG_TYPE_MAKE_SEND); | |
69 if (kr != KERN_SUCCESS) { | |
70 return kr; | |
71 } | |
72 base::mac::ScopedMachSendRight service_port_send_right_owner( | |
73 local_service_port); | |
74 | |
75 kr = BootstrapRegister(bp, service_name_mutable, local_service_port); | |
76 if (kr != BOOTSTRAP_SUCCESS) { | |
77 return kr; | |
78 } | |
79 | |
80 ignore_result(service_port_receive_right_owner.release()); | |
81 *service_port = local_service_port; | |
82 } | |
83 #endif | |
84 | |
85 return kr; | |
86 } | |
87 | |
88 } // namespace crashpad | |
OLD | NEW |