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/port_provider_mac.h" |
10 #include "base/process/process.h" | 10 #include "base/process/process.h" |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
46 0, // receive limit | 46 0, // receive limit |
47 MACH_PORT_NULL, // receive name | 47 MACH_PORT_NULL, // receive name |
48 0, // timeout | 48 0, // timeout |
49 MACH_PORT_NULL); // notification port | 49 MACH_PORT_NULL); // notification port |
50 } | 50 } |
51 | 51 |
52 } // namespace | 52 } // namespace |
53 | 53 |
54 namespace IPC { | 54 namespace IPC { |
55 | 55 |
56 AttachmentBrokerPrivilegedMac::AttachmentBrokerPrivilegedMac() {} | 56 AttachmentBrokerPrivilegedMac::AttachmentBrokerPrivilegedMac( |
| 57 base::PortProvider* port_provider) |
| 58 : port_provider_(port_provider) {} |
| 59 |
57 AttachmentBrokerPrivilegedMac::~AttachmentBrokerPrivilegedMac() {} | 60 AttachmentBrokerPrivilegedMac::~AttachmentBrokerPrivilegedMac() {} |
58 | 61 |
59 bool AttachmentBrokerPrivilegedMac::SendAttachmentToProcess( | 62 bool AttachmentBrokerPrivilegedMac::SendAttachmentToProcess( |
60 BrokerableAttachment* attachment, | 63 BrokerableAttachment* attachment, |
61 base::ProcessId destination_process) { | 64 base::ProcessId destination_process) { |
62 switch (attachment->GetBrokerableType()) { | 65 switch (attachment->GetBrokerableType()) { |
63 case BrokerableAttachment::MACH_PORT: { | 66 case BrokerableAttachment::MACH_PORT: { |
64 internal::MachPortAttachmentMac* mach_port_attachment = | 67 internal::MachPortAttachmentMac* mach_port_attachment = |
65 static_cast<internal::MachPortAttachmentMac*>(attachment); | 68 static_cast<internal::MachPortAttachmentMac*>(attachment); |
66 MachPortWireFormat wire_format = | 69 MachPortWireFormat wire_format = |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
166 } | 169 } |
167 | 170 |
168 LogError(DESTINATION_FOUND); | 171 LogError(DESTINATION_FOUND); |
169 sender->Send(new AttachmentBrokerMsg_MachPortHasBeenDuplicated(wire_format)); | 172 sender->Send(new AttachmentBrokerMsg_MachPortHasBeenDuplicated(wire_format)); |
170 } | 173 } |
171 | 174 |
172 mach_port_name_t AttachmentBrokerPrivilegedMac::CreateIntermediateMachPort( | 175 mach_port_name_t AttachmentBrokerPrivilegedMac::CreateIntermediateMachPort( |
173 base::ProcessId pid, | 176 base::ProcessId pid, |
174 base::mac::ScopedMachSendRight port_to_insert) { | 177 base::mac::ScopedMachSendRight port_to_insert) { |
175 DCHECK_NE(pid, base::GetCurrentProcId()); | 178 DCHECK_NE(pid, base::GetCurrentProcId()); |
176 mach_port_t task_port = port_provider()->TaskForPid(pid); | 179 mach_port_t task_port = port_provider_->TaskForPid(pid); |
177 if (task_port == MACH_PORT_NULL) { | 180 if (task_port == MACH_PORT_NULL) { |
178 // TODO(erikchen): UMA metric. | 181 // TODO(erikchen): UMA metric. |
179 return MACH_PORT_NULL; | 182 return MACH_PORT_NULL; |
180 } | 183 } |
181 return CreateIntermediateMachPort( | 184 return CreateIntermediateMachPort( |
182 task_port, base::mac::ScopedMachSendRight(port_to_insert.release())); | 185 task_port, base::mac::ScopedMachSendRight(port_to_insert.release())); |
183 } | 186 } |
184 | 187 |
185 mach_port_name_t AttachmentBrokerPrivilegedMac::CreateIntermediateMachPort( | 188 mach_port_name_t AttachmentBrokerPrivilegedMac::CreateIntermediateMachPort( |
186 mach_port_t task_port, | 189 mach_port_t task_port, |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
241 base::ProcessId pid, | 244 base::ProcessId pid, |
242 mach_port_name_t named_right) { | 245 mach_port_name_t named_right) { |
243 if (pid == base::GetCurrentProcId()) { | 246 if (pid == base::GetCurrentProcId()) { |
244 kern_return_t kr = mach_port_mod_refs(mach_task_self(), named_right, | 247 kern_return_t kr = mach_port_mod_refs(mach_task_self(), named_right, |
245 MACH_PORT_RIGHT_SEND, 1); | 248 MACH_PORT_RIGHT_SEND, 1); |
246 if (kr != KERN_SUCCESS) | 249 if (kr != KERN_SUCCESS) |
247 return base::mac::ScopedMachSendRight(MACH_PORT_NULL); | 250 return base::mac::ScopedMachSendRight(MACH_PORT_NULL); |
248 return base::mac::ScopedMachSendRight(named_right); | 251 return base::mac::ScopedMachSendRight(named_right); |
249 } | 252 } |
250 | 253 |
251 mach_port_t task_port = port_provider()->TaskForPid(pid); | 254 mach_port_t task_port = port_provider_->TaskForPid(pid); |
252 return ExtractNamedRight(task_port, named_right); | 255 return ExtractNamedRight(task_port, named_right); |
253 } | 256 } |
254 | 257 |
255 base::mac::ScopedMachSendRight AttachmentBrokerPrivilegedMac::ExtractNamedRight( | 258 base::mac::ScopedMachSendRight AttachmentBrokerPrivilegedMac::ExtractNamedRight( |
256 mach_port_t task_port, | 259 mach_port_t task_port, |
257 mach_port_name_t named_right) { | 260 mach_port_name_t named_right) { |
258 mach_port_t extracted_right = MACH_PORT_NULL; | 261 mach_port_t extracted_right = MACH_PORT_NULL; |
259 mach_msg_type_name_t extracted_right_type; | 262 mach_msg_type_name_t extracted_right_type; |
260 kern_return_t kr = | 263 kern_return_t kr = |
261 mach_port_extract_right(task_port, named_right, MACH_MSG_TYPE_COPY_SEND, | 264 mach_port_extract_right(task_port, named_right, MACH_MSG_TYPE_COPY_SEND, |
(...skipping 17 matching lines...) Expand all Loading... |
279 | 282 |
280 AttachmentBrokerPrivilegedMac::MachPortWireFormat | 283 AttachmentBrokerPrivilegedMac::MachPortWireFormat |
281 AttachmentBrokerPrivilegedMac::CopyWireFormat( | 284 AttachmentBrokerPrivilegedMac::CopyWireFormat( |
282 const MachPortWireFormat& wire_format, | 285 const MachPortWireFormat& wire_format, |
283 uint32_t mach_port) { | 286 uint32_t mach_port) { |
284 return MachPortWireFormat(mach_port, wire_format.destination_process, | 287 return MachPortWireFormat(mach_port, wire_format.destination_process, |
285 wire_format.attachment_id); | 288 wire_format.attachment_id); |
286 } | 289 } |
287 | 290 |
288 } // namespace IPC | 291 } // namespace IPC |
OLD | NEW |