Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2014 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/os_compatibility.h" | |
| 6 | |
| 7 #include <servers/bootstrap.h> | |
| 8 #include <unistd.h> | |
| 9 | |
| 10 #include "base/mac/mac_util.h" | |
| 11 | |
| 12 namespace sandbox { | |
| 13 | |
| 14 namespace { | |
| 15 | |
| 16 // Verified from launchd-329.3.3 (10.6.8). | |
| 17 struct look_up2_request_10_6 { | |
| 18 mach_msg_header_t Head; | |
| 19 NDR_record_t NDR; | |
| 20 name_t servicename; | |
| 21 pid_t targetpid; | |
| 22 uint64_t flags; | |
| 23 }; | |
| 24 | |
| 25 struct look_up2_reply_10_6 { | |
| 26 mach_msg_header_t Head; | |
| 27 mach_msg_body_t msgh_body; | |
| 28 mach_msg_port_descriptor_t service_port; | |
| 29 }; | |
| 30 | |
| 31 // Verified from: | |
| 32 // launchd-392.39 (10.7.5) | |
| 33 // launchd-442.26.2 (10.8.5) | |
| 34 // launchd-842.1.4 (10.9.0) | |
| 35 struct look_up2_request_10_7 { | |
| 36 mach_msg_header_t Head; | |
| 37 NDR_record_t NDR; | |
| 38 name_t servicename; | |
| 39 pid_t targetpid; | |
| 40 uuid_t instanceid; | |
| 41 uint64_t flags; | |
| 42 }; | |
| 43 | |
| 44 // look_up2_reply_10_7 is the same as the 10_6 version. | |
| 45 | |
| 46 template <typename R> | |
| 47 const char* LaunchdLookUp2GetRequestName(const mach_msg_header_t* header) { | |
| 48 DCHECK_EQ(sizeof(R), header->msgh_size); | |
| 49 const R* request = reinterpret_cast<const R*>(header); | |
| 50 return request->servicename; | |
|
Mark Mentovai
2014/05/06 20:51:50
This is dangerous without a length limitation. 10.
Robert Sesek
2014/05/08 20:58:12
Good catch. There's even BOOTSTRAP_MAX_NAME_LEN.
| |
| 51 } | |
| 52 | |
| 53 template <typename R> | |
| 54 void LaunchdLookUp2FillReply(mach_msg_header_t* header, mach_port_t port) { | |
| 55 R* reply = reinterpret_cast<R*>(header); | |
| 56 reply->Head.msgh_size = sizeof(R); | |
| 57 reply->Head.msgh_bits = | |
| 58 MACH_MSGH_BITS_REMOTE(MACH_MSG_TYPE_MOVE_SEND_ONCE) | | |
| 59 MACH_MSGH_BITS_COMPLEX; | |
| 60 reply->msgh_body.msgh_descriptor_count = 1; | |
| 61 reply->service_port.name = port; | |
| 62 reply->service_port.disposition = MACH_MSG_TYPE_PORT_SEND; | |
| 63 reply->service_port.type = MACH_MSG_PORT_DESCRIPTOR; | |
| 64 } | |
| 65 | |
| 66 } // namespace | |
| 67 | |
| 68 const LaunchdCompatibilityShim GetLaunchdCompatibilityShim() { | |
| 69 LaunchdCompatibilityShim shim = { | |
| 70 .msg_id_look_up2 = 404, | |
| 71 .msg_id_swap_integer = 416, | |
| 72 .look_up2_fill_reply = &LaunchdLookUp2FillReply<look_up2_reply_10_6> | |
| 73 }; | |
| 74 | |
| 75 if (base::mac::IsOSSnowLeopard()) { | |
| 76 shim.look_up2_get_request_name = | |
| 77 &LaunchdLookUp2GetRequestName<look_up2_request_10_6>; | |
| 78 } else if (base::mac::IsOSLion() || | |
|
Mark Mentovai
2014/05/06 20:51:50
You’ll do better with the OrEarlier/OrLater calls
Robert Sesek
2014/05/08 20:58:12
Done.
| |
| 79 base::mac::IsOSMountainLion() || | |
| 80 base::mac::IsOSMavericks()) { | |
| 81 shim.look_up2_get_request_name = | |
| 82 &LaunchdLookUp2GetRequestName<look_up2_request_10_7>; | |
| 83 } else { | |
| 84 LOG(ERROR) << "Unknown OS, using launchd compatibility shim from 10.7."; | |
| 85 shim.look_up2_get_request_name = | |
| 86 &LaunchdLookUp2GetRequestName<look_up2_request_10_7>; | |
| 87 } | |
| 88 | |
| 89 return shim; | |
| 90 } | |
| 91 | |
| 92 } // namespace sandbox | |
| OLD | NEW |