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

Side by Side Diff: sandbox/mac/os_compatibility.cc

Issue 264923003: Initial implementation of the Mac Bootstrap Sandbox. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase for sandbox_export.h Created 6 years, 7 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 | « sandbox/mac/os_compatibility.h ('k') | sandbox/mac/policy.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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 // TODO(rsesek): Libc provides strnlen() starting in 10.7.
47 size_t strnlen(const char* str, size_t maxlen) {
48 size_t len = 0;
49 for (; len < maxlen; ++len, ++str) {
50 if (*str == '\0')
51 break;
52 }
53 return len;
54 }
55
56 template <typename R>
57 std::string LaunchdLookUp2GetRequestName(const mach_msg_header_t* header) {
58 DCHECK_EQ(sizeof(R), header->msgh_size);
59 const R* request = reinterpret_cast<const R*>(header);
60 // Make sure the name is properly NUL-terminated.
61 const size_t name_length =
62 strnlen(request->servicename, BOOTSTRAP_MAX_NAME_LEN);
63 std::string name = std::string(request->servicename, name_length);
64 return name;
65 }
66
67 template <typename R>
68 void LaunchdLookUp2FillReply(mach_msg_header_t* header, mach_port_t port) {
69 R* reply = reinterpret_cast<R*>(header);
70 reply->Head.msgh_size = sizeof(R);
71 reply->Head.msgh_bits =
72 MACH_MSGH_BITS_REMOTE(MACH_MSG_TYPE_MOVE_SEND_ONCE) |
73 MACH_MSGH_BITS_COMPLEX;
74 reply->msgh_body.msgh_descriptor_count = 1;
75 reply->service_port.name = port;
76 reply->service_port.disposition = MACH_MSG_TYPE_PORT_SEND;
77 reply->service_port.type = MACH_MSG_PORT_DESCRIPTOR;
78 }
79
80 } // namespace
81
82 const LaunchdCompatibilityShim GetLaunchdCompatibilityShim() {
83 LaunchdCompatibilityShim shim = {
84 .msg_id_look_up2 = 404,
85 .msg_id_swap_integer = 416,
86 .look_up2_fill_reply = &LaunchdLookUp2FillReply<look_up2_reply_10_6>
87 };
88
89 if (base::mac::IsOSSnowLeopard()) {
90 shim.look_up2_get_request_name =
91 &LaunchdLookUp2GetRequestName<look_up2_request_10_6>;
92 } else if (base::mac::IsOSLionOrLater() &&
93 !base::mac::IsOSLaterThanMavericks_DontCallThis()) {
94 shim.look_up2_get_request_name =
95 &LaunchdLookUp2GetRequestName<look_up2_request_10_7>;
96 } else {
97 DLOG(ERROR) << "Unknown OS, using launchd compatibility shim from 10.7.";
98 shim.look_up2_get_request_name =
99 &LaunchdLookUp2GetRequestName<look_up2_request_10_7>;
100 }
101
102 return shim;
103 }
104
105 } // namespace sandbox
OLDNEW
« no previous file with comments | « sandbox/mac/os_compatibility.h ('k') | sandbox/mac/policy.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698