OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 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 "ipc/attachment_broker_privileged_mac.h" | 5 #include "ipc/attachment_broker_privileged_mac.h" |
6 | 6 |
7 #include "base/mac/scoped_mach_port.h" | 7 #include "base/mac/scoped_mach_port.h" |
8 #include "base/memory/shared_memory.h" | 8 #include "base/memory/shared_memory.h" |
| 9 #include "base/process/port_provider_mac.h" |
9 #include "base/process/process.h" | 10 #include "base/process/process.h" |
10 #include "ipc/attachment_broker_messages.h" | 11 #include "ipc/attachment_broker_messages.h" |
11 #include "ipc/brokerable_attachment.h" | 12 #include "ipc/brokerable_attachment.h" |
12 #include "ipc/ipc_channel.h" | 13 #include "ipc/ipc_channel.h" |
13 #include "ipc/mach_port_attachment_mac.h" | 14 #include "ipc/mach_port_attachment_mac.h" |
14 | 15 |
15 namespace { | 16 namespace { |
16 | 17 |
17 // Struct for sending a complex Mach message. | 18 // Struct for sending a complex Mach message. |
18 struct MachSendComplexMessage { | 19 struct MachSendComplexMessage { |
(...skipping 26 matching lines...) Expand all Loading... |
45 0, // receive limit | 46 0, // receive limit |
46 MACH_PORT_NULL, // receive name | 47 MACH_PORT_NULL, // receive name |
47 0, // timeout | 48 0, // timeout |
48 MACH_PORT_NULL); // notification port | 49 MACH_PORT_NULL); // notification port |
49 } | 50 } |
50 | 51 |
51 } // namespace | 52 } // namespace |
52 | 53 |
53 namespace IPC { | 54 namespace IPC { |
54 | 55 |
55 AttachmentBrokerPrivilegedMac::AttachmentBrokerPrivilegedMac() | 56 AttachmentBrokerPrivilegedMac::AttachmentBrokerPrivilegedMac() {} |
56 : port_provider_(nullptr) {} | |
57 | |
58 AttachmentBrokerPrivilegedMac::~AttachmentBrokerPrivilegedMac() {} | 57 AttachmentBrokerPrivilegedMac::~AttachmentBrokerPrivilegedMac() {} |
59 | 58 |
60 void AttachmentBrokerPrivilegedMac::SetPortProvider( | |
61 base::PortProvider* port_provider) { | |
62 CHECK(!port_provider_); | |
63 port_provider_ = port_provider; | |
64 } | |
65 | |
66 bool AttachmentBrokerPrivilegedMac::SendAttachmentToProcess( | 59 bool AttachmentBrokerPrivilegedMac::SendAttachmentToProcess( |
67 BrokerableAttachment* attachment, | 60 BrokerableAttachment* attachment, |
68 base::ProcessId destination_process) { | 61 base::ProcessId destination_process) { |
69 switch (attachment->GetBrokerableType()) { | 62 switch (attachment->GetBrokerableType()) { |
70 case BrokerableAttachment::MACH_PORT: { | 63 case BrokerableAttachment::MACH_PORT: { |
71 internal::MachPortAttachmentMac* mach_port_attachment = | 64 internal::MachPortAttachmentMac* mach_port_attachment = |
72 static_cast<internal::MachPortAttachmentMac*>(attachment); | 65 static_cast<internal::MachPortAttachmentMac*>(attachment); |
73 MachPortWireFormat wire_format = | 66 MachPortWireFormat wire_format = |
74 mach_port_attachment->GetWireFormat(destination_process); | 67 mach_port_attachment->GetWireFormat(destination_process); |
75 | 68 |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
173 } | 166 } |
174 | 167 |
175 LogError(DESTINATION_FOUND); | 168 LogError(DESTINATION_FOUND); |
176 sender->Send(new AttachmentBrokerMsg_MachPortHasBeenDuplicated(wire_format)); | 169 sender->Send(new AttachmentBrokerMsg_MachPortHasBeenDuplicated(wire_format)); |
177 } | 170 } |
178 | 171 |
179 mach_port_name_t AttachmentBrokerPrivilegedMac::CreateIntermediateMachPort( | 172 mach_port_name_t AttachmentBrokerPrivilegedMac::CreateIntermediateMachPort( |
180 base::ProcessId pid, | 173 base::ProcessId pid, |
181 base::mac::ScopedMachSendRight port_to_insert) { | 174 base::mac::ScopedMachSendRight port_to_insert) { |
182 DCHECK_NE(pid, base::GetCurrentProcId()); | 175 DCHECK_NE(pid, base::GetCurrentProcId()); |
183 mach_port_t task_port = port_provider_->TaskForPid(pid); | 176 mach_port_t task_port = port_provider()->TaskForPid(pid); |
184 if (task_port == MACH_PORT_NULL) { | 177 if (task_port == MACH_PORT_NULL) { |
185 // TODO(erikchen): UMA metric. | 178 // TODO(erikchen): UMA metric. |
186 return MACH_PORT_NULL; | 179 return MACH_PORT_NULL; |
187 } | 180 } |
188 return CreateIntermediateMachPort( | 181 return CreateIntermediateMachPort( |
189 task_port, base::mac::ScopedMachSendRight(port_to_insert.release())); | 182 task_port, base::mac::ScopedMachSendRight(port_to_insert.release())); |
190 } | 183 } |
191 | 184 |
192 mach_port_name_t AttachmentBrokerPrivilegedMac::CreateIntermediateMachPort( | 185 mach_port_name_t AttachmentBrokerPrivilegedMac::CreateIntermediateMachPort( |
193 mach_port_t task_port, | 186 mach_port_t task_port, |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
248 base::ProcessId pid, | 241 base::ProcessId pid, |
249 mach_port_name_t named_right) { | 242 mach_port_name_t named_right) { |
250 if (pid == base::GetCurrentProcId()) { | 243 if (pid == base::GetCurrentProcId()) { |
251 kern_return_t kr = mach_port_mod_refs(mach_task_self(), named_right, | 244 kern_return_t kr = mach_port_mod_refs(mach_task_self(), named_right, |
252 MACH_PORT_RIGHT_SEND, 1); | 245 MACH_PORT_RIGHT_SEND, 1); |
253 if (kr != KERN_SUCCESS) | 246 if (kr != KERN_SUCCESS) |
254 return base::mac::ScopedMachSendRight(MACH_PORT_NULL); | 247 return base::mac::ScopedMachSendRight(MACH_PORT_NULL); |
255 return base::mac::ScopedMachSendRight(named_right); | 248 return base::mac::ScopedMachSendRight(named_right); |
256 } | 249 } |
257 | 250 |
258 mach_port_t task_port = port_provider_->TaskForPid(pid); | 251 mach_port_t task_port = port_provider()->TaskForPid(pid); |
259 return ExtractNamedRight(task_port, named_right); | 252 return ExtractNamedRight(task_port, named_right); |
260 } | 253 } |
261 | 254 |
262 base::mac::ScopedMachSendRight AttachmentBrokerPrivilegedMac::ExtractNamedRight( | 255 base::mac::ScopedMachSendRight AttachmentBrokerPrivilegedMac::ExtractNamedRight( |
263 mach_port_t task_port, | 256 mach_port_t task_port, |
264 mach_port_name_t named_right) { | 257 mach_port_name_t named_right) { |
265 mach_port_t extracted_right = MACH_PORT_NULL; | 258 mach_port_t extracted_right = MACH_PORT_NULL; |
266 mach_msg_type_name_t extracted_right_type; | 259 mach_msg_type_name_t extracted_right_type; |
267 kern_return_t kr = | 260 kern_return_t kr = |
268 mach_port_extract_right(task_port, named_right, MACH_MSG_TYPE_COPY_SEND, | 261 mach_port_extract_right(task_port, named_right, MACH_MSG_TYPE_COPY_SEND, |
(...skipping 17 matching lines...) Expand all Loading... |
286 | 279 |
287 AttachmentBrokerPrivilegedMac::MachPortWireFormat | 280 AttachmentBrokerPrivilegedMac::MachPortWireFormat |
288 AttachmentBrokerPrivilegedMac::CopyWireFormat( | 281 AttachmentBrokerPrivilegedMac::CopyWireFormat( |
289 const MachPortWireFormat& wire_format, | 282 const MachPortWireFormat& wire_format, |
290 uint32_t mach_port) { | 283 uint32_t mach_port) { |
291 return MachPortWireFormat(mach_port, wire_format.destination_process, | 284 return MachPortWireFormat(mach_port, wire_format.destination_process, |
292 wire_format.attachment_id); | 285 wire_format.attachment_id); |
293 } | 286 } |
294 | 287 |
295 } // namespace IPC | 288 } // namespace IPC |
OLD | NEW |