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

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

Issue 1853713004: mac: Remove some 10.6-SDK-only sandbox code. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: comment Created 4 years, 8 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
« no previous file with comments | « sandbox/mac/bootstrap_sandbox_unittest.mm ('k') | sandbox/mac/sandbox_mac.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 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 "sandbox/mac/os_compatibility.h" 5 #include "sandbox/mac/os_compatibility.h"
6 6
7 #include <servers/bootstrap.h> 7 #include <servers/bootstrap.h>
8 #include <stddef.h> 8 #include <stddef.h>
9 #include <stdint.h> 9 #include <stdint.h>
10 #include <unistd.h> 10 #include <unistd.h>
11 11
12 #include "base/mac/mac_util.h" 12 #include "base/mac/mac_util.h"
13 #include "sandbox/mac/xpc.h" 13 #include "sandbox/mac/xpc.h"
14 14
15 namespace sandbox { 15 namespace sandbox {
16 16
17 namespace { 17 namespace {
18 18
19 #pragma pack(push, 4) 19 #pragma pack(push, 4)
20 // Verified from launchd-329.3.3 (10.6.8). 20 // Verified from launchd-329.3.3 (10.6.8).
21 struct look_up2_request_10_6 { 21 // look_up2_reply_10_7 is the same as the 10_6 version.
22 mach_msg_header_t Head; 22 struct look_up2_reply_10_7 {
23 NDR_record_t NDR;
24 name_t servicename;
25 pid_t targetpid;
26 uint64_t flags;
27 };
28
29 struct look_up2_reply_10_6 {
30 mach_msg_header_t Head; 23 mach_msg_header_t Head;
31 mach_msg_body_t msgh_body; 24 mach_msg_body_t msgh_body;
32 mach_msg_port_descriptor_t service_port; 25 mach_msg_port_descriptor_t service_port;
33 }; 26 };
34 27
35 // Verified from: 28 // Verified from:
36 // launchd-392.39 (10.7.5) 29 // launchd-392.39 (10.7.5)
37 // launchd-442.26.2 (10.8.5) 30 // launchd-442.26.2 (10.8.5)
38 // launchd-842.1.4 (10.9.0) 31 // launchd-842.1.4 (10.9.0)
39 struct look_up2_request_10_7 { 32 struct look_up2_request_10_7 {
40 mach_msg_header_t Head; 33 mach_msg_header_t Head;
41 NDR_record_t NDR; 34 NDR_record_t NDR;
42 name_t servicename; 35 name_t servicename;
43 pid_t targetpid; 36 pid_t targetpid;
44 uuid_t instanceid; 37 uuid_t instanceid;
45 uint64_t flags; 38 uint64_t flags;
46 }; 39 };
47 40
48 // look_up2_reply_10_7 is the same as the 10_6 version.
49
50 // Verified from: 41 // Verified from:
51 // launchd-329.3.3 (10.6.8) 42 // launchd-329.3.3 (10.6.8)
52 // launchd-392.39 (10.7.5) 43 // launchd-392.39 (10.7.5)
53 // launchd-442.26.2 (10.8.5) 44 // launchd-442.26.2 (10.8.5)
54 // launchd-842.1.4 (10.9.0) 45 // launchd-842.1.4 (10.9.0)
55 typedef int vproc_gsk_t; // Defined as an enum in liblaunch/vproc_priv.h. 46 typedef int vproc_gsk_t; // Defined as an enum in liblaunch/vproc_priv.h.
56 struct swap_integer_request_10_6 { 47 struct swap_integer_request_10_7 {
57 mach_msg_header_t Head; 48 mach_msg_header_t Head;
58 NDR_record_t NDR; 49 NDR_record_t NDR;
59 vproc_gsk_t inkey; 50 vproc_gsk_t inkey;
60 vproc_gsk_t outkey; 51 vproc_gsk_t outkey;
61 int64_t inval; 52 int64_t inval;
62 }; 53 };
63 #pragma pack(pop) 54 #pragma pack(pop)
64 55
65 // TODO(rsesek): Libc provides strnlen() starting in 10.7. 56 // TODO(rsesek): Libc provides strnlen() starting in 10.7.
66 size_t strnlen(const char* str, size_t maxlen) { 57 size_t strnlen(const char* str, size_t maxlen) {
67 size_t len = 0; 58 size_t len = 0;
68 for (; len < maxlen; ++len, ++str) { 59 for (; len < maxlen; ++len, ++str) {
69 if (*str == '\0') 60 if (*str == '\0')
70 break; 61 break;
71 } 62 }
72 return len; 63 return len;
73 } 64 }
74 65
75 class OSCompatibility_10_6 : public OSCompatibility { 66 class OSCompatibility_10_7 : public OSCompatibility {
76 public: 67 public:
77 OSCompatibility_10_6() {} 68 OSCompatibility_10_7() {}
78 ~OSCompatibility_10_6() override {} 69 ~OSCompatibility_10_7() override {}
79 70
80 uint64_t GetMessageSubsystem(const IPCMessage message) override { 71 uint64_t GetMessageSubsystem(const IPCMessage message) override {
81 return (message.mach->msgh_id / 100) * 100; 72 return (message.mach->msgh_id / 100) * 100;
82 } 73 }
83 74
84 uint64_t GetMessageID(const IPCMessage message) override { 75 uint64_t GetMessageID(const IPCMessage message) override {
85 return message.mach->msgh_id; 76 return message.mach->msgh_id;
86 } 77 }
87 78
88 bool IsServiceLookUpRequest(const IPCMessage message) override { 79 bool IsServiceLookUpRequest(const IPCMessage message) override {
89 return GetMessageID(message) == 404; 80 return GetMessageID(message) == 404;
90 } 81 }
91 82
92 bool IsVprocSwapInteger(const IPCMessage message) override { 83 bool IsVprocSwapInteger(const IPCMessage message) override {
93 return GetMessageID(message) == 416; 84 return GetMessageID(message) == 416;
94 } 85 }
95 86
96 bool IsXPCDomainManagement(const IPCMessage message) override { 87 bool IsXPCDomainManagement(const IPCMessage message) override {
97 return false; 88 return false;
98 } 89 }
99 90
100 std::string GetServiceLookupName(const IPCMessage message) override { 91 std::string GetServiceLookupName(const IPCMessage message) override {
101 return GetRequestName<look_up2_request_10_6>(message); 92 return GetRequestName<look_up2_request_10_7>(message);
102 } 93 }
103 94
104 void WriteServiceLookUpReply(IPCMessage message, 95 void WriteServiceLookUpReply(IPCMessage message,
105 mach_port_t service_port) override { 96 mach_port_t service_port) override {
106 auto reply = reinterpret_cast<look_up2_reply_10_6*>(message.mach); 97 auto reply = reinterpret_cast<look_up2_reply_10_7*>(message.mach);
107 reply->Head.msgh_size = sizeof(*reply); 98 reply->Head.msgh_size = sizeof(*reply);
108 reply->Head.msgh_bits = 99 reply->Head.msgh_bits =
109 MACH_MSGH_BITS_REMOTE(MACH_MSG_TYPE_MOVE_SEND_ONCE) | 100 MACH_MSGH_BITS_REMOTE(MACH_MSG_TYPE_MOVE_SEND_ONCE) |
110 MACH_MSGH_BITS_COMPLEX; 101 MACH_MSGH_BITS_COMPLEX;
111 reply->msgh_body.msgh_descriptor_count = 1; 102 reply->msgh_body.msgh_descriptor_count = 1;
112 reply->service_port.name = service_port; 103 reply->service_port.name = service_port;
113 reply->service_port.disposition = MACH_MSG_TYPE_COPY_SEND; 104 reply->service_port.disposition = MACH_MSG_TYPE_COPY_SEND;
114 reply->service_port.type = MACH_MSG_PORT_DESCRIPTOR; 105 reply->service_port.type = MACH_MSG_PORT_DESCRIPTOR;
115 } 106 }
116 107
117 bool IsSwapIntegerReadOnly(const IPCMessage message) override { 108 bool IsSwapIntegerReadOnly(const IPCMessage message) override {
118 auto request = 109 auto request =
119 reinterpret_cast<const swap_integer_request_10_6*>(message.mach); 110 reinterpret_cast<const swap_integer_request_10_7*>(message.mach);
120 return request->inkey == 0 && request->inval == 0 && request->outkey != 0; 111 return request->inkey == 0 && request->inval == 0 && request->outkey != 0;
121 } 112 }
122 113
123 protected: 114 protected:
124 // The 10.6 and 10.7 implementations are the same except for struct offsets, 115 // The 10.6 and 10.7 implementations are the same except for struct offsets,
125 // so provide this templatized helper. 116 // so provide this templatized helper.
126 template <typename R> 117 template <typename R>
127 static std::string GetRequestName(const IPCMessage message) { 118 static std::string GetRequestName(const IPCMessage message) {
128 mach_msg_header_t* header = message.mach; 119 mach_msg_header_t* header = message.mach;
129 DCHECK_EQ(sizeof(R), header->msgh_size); 120 DCHECK_EQ(sizeof(R), header->msgh_size);
130 const R* request = reinterpret_cast<const R*>(header); 121 const R* request = reinterpret_cast<const R*>(header);
131 // Make sure the name is properly NUL-terminated. 122 // Make sure the name is properly NUL-terminated.
132 const size_t name_length = 123 const size_t name_length =
133 strnlen(request->servicename, BOOTSTRAP_MAX_NAME_LEN); 124 strnlen(request->servicename, BOOTSTRAP_MAX_NAME_LEN);
134 std::string name = std::string(request->servicename, name_length); 125 std::string name = std::string(request->servicename, name_length);
135 return name; 126 return name;
136 } 127 }
137 }; 128 };
138 129
139 class OSCompatibility_10_7 : public OSCompatibility_10_6 {
140 public:
141 OSCompatibility_10_7() {}
142 ~OSCompatibility_10_7() override {}
143
144 std::string GetServiceLookupName(const IPCMessage message) override {
145 return GetRequestName<look_up2_request_10_7>(message);
146 }
147 };
148
149 class OSCompatibility_10_10 : public OSCompatibility { 130 class OSCompatibility_10_10 : public OSCompatibility {
150 public: 131 public:
151 OSCompatibility_10_10() {} 132 OSCompatibility_10_10() {}
152 ~OSCompatibility_10_10() override {} 133 ~OSCompatibility_10_10() override {}
153 134
154 uint64_t GetMessageSubsystem(const IPCMessage message) override { 135 uint64_t GetMessageSubsystem(const IPCMessage message) override {
155 return xpc_dictionary_get_uint64(message.xpc, "subsystem"); 136 return xpc_dictionary_get_uint64(message.xpc, "subsystem");
156 } 137 }
157 138
158 uint64_t GetMessageID(const IPCMessage message) override { 139 uint64_t GetMessageID(const IPCMessage message) override {
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
191 return xpc_dictionary_get_bool(message.xpc, "set") == false && 172 return xpc_dictionary_get_bool(message.xpc, "set") == false &&
192 xpc_dictionary_get_uint64(message.xpc, "ingsk") == 0 && 173 xpc_dictionary_get_uint64(message.xpc, "ingsk") == 0 &&
193 xpc_dictionary_get_int64(message.xpc, "in") == 0; 174 xpc_dictionary_get_int64(message.xpc, "in") == 0;
194 } 175 }
195 }; 176 };
196 177
197 } // namespace 178 } // namespace
198 179
199 // static 180 // static
200 scoped_ptr<OSCompatibility> OSCompatibility::CreateForPlatform() { 181 scoped_ptr<OSCompatibility> OSCompatibility::CreateForPlatform() {
201 if (base::mac::IsOSSnowLeopard()) 182 if (base::mac::IsOSLionOrLater() && base::mac::IsOSMavericksOrEarlier())
202 return make_scoped_ptr(new OSCompatibility_10_6());
203 else if (base::mac::IsOSLionOrLater() && base::mac::IsOSMavericksOrEarlier())
204 return make_scoped_ptr(new OSCompatibility_10_7()); 183 return make_scoped_ptr(new OSCompatibility_10_7());
205 else 184 else
206 return make_scoped_ptr(new OSCompatibility_10_10()); 185 return make_scoped_ptr(new OSCompatibility_10_10());
207 } 186 }
208 187
209 OSCompatibility::~OSCompatibility() {} 188 OSCompatibility::~OSCompatibility() {}
210 189
211 } // namespace sandbox 190 } // namespace sandbox
OLDNEW
« no previous file with comments | « sandbox/mac/bootstrap_sandbox_unittest.mm ('k') | sandbox/mac/sandbox_mac.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698