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

Side by Side Diff: ipc/attachment_broker_privileged_mac.cc

Issue 1739203004: Add support for Attachment Brokering of IPC::Channels on multiple threads. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix windows comiple error. Created 4 years, 9 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
OLDNEW
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 <stdint.h> 7 #include <stdint.h>
8 8
9 #include "base/mac/scoped_mach_port.h" 9 #include "base/mac/scoped_mach_port.h"
10 #include "base/memory/shared_memory.h" 10 #include "base/memory/shared_memory.h"
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
207 HandleReceivedAttachment(attachment); 207 HandleReceivedAttachment(attachment);
208 } 208 }
209 209
210 bool AttachmentBrokerPrivilegedMac::RouteWireFormatToAnother( 210 bool AttachmentBrokerPrivilegedMac::RouteWireFormatToAnother(
211 const MachPortWireFormat& wire_format) { 211 const MachPortWireFormat& wire_format) {
212 DCHECK_NE(wire_format.destination_process, base::Process::Current().Pid()); 212 DCHECK_NE(wire_format.destination_process, base::Process::Current().Pid());
213 213
214 // Another process is the destination. 214 // Another process is the destination.
215 base::ProcessId dest = wire_format.destination_process; 215 base::ProcessId dest = wire_format.destination_process;
216 base::AutoLock auto_lock(*get_lock()); 216 base::AutoLock auto_lock(*get_lock());
217 Sender* sender = GetSenderWithProcessId(dest); 217 AttachmentBrokerPrivileged::EndpointRunnerPair pair =
218 if (!sender) { 218 GetSenderWithProcessId(dest);
219 if (!pair.first) {
219 // Assuming that this message was not sent from a malicious process, the 220 // Assuming that this message was not sent from a malicious process, the
220 // channel endpoint that would have received this message will block 221 // channel endpoint that would have received this message will block
221 // forever. 222 // forever.
222 LOG(ERROR) << "Failed to deliver brokerable attachment to process with id: " 223 LOG(ERROR) << "Failed to deliver brokerable attachment to process with id: "
223 << dest; 224 << dest;
224 LogError(DESTINATION_NOT_FOUND); 225 LogError(DESTINATION_NOT_FOUND);
225 return false; 226 return false;
226 } 227 }
227 228
228 LogError(DESTINATION_FOUND); 229 LogError(DESTINATION_FOUND);
229 sender->Send(new AttachmentBrokerMsg_MachPortHasBeenDuplicated(wire_format)); 230 SendMessageToEndpoint(
231 pair, new AttachmentBrokerMsg_MachPortHasBeenDuplicated(wire_format));
230 return true; 232 return true;
231 } 233 }
232 234
233 mach_port_name_t AttachmentBrokerPrivilegedMac::CreateIntermediateMachPort( 235 mach_port_name_t AttachmentBrokerPrivilegedMac::CreateIntermediateMachPort(
234 mach_port_t task_port, 236 mach_port_t task_port,
235 base::mac::ScopedMachSendRight port_to_insert) { 237 base::mac::ScopedMachSendRight port_to_insert) {
236 DCHECK_NE(mach_task_self(), task_port); 238 DCHECK_NE(mach_task_self(), task_port);
237 DCHECK_NE(static_cast<mach_port_name_t>(MACH_PORT_NULL), task_port); 239 DCHECK_NE(static_cast<mach_port_name_t>(MACH_PORT_NULL), task_port);
238 240
239 // Make a port with receive rights in the destination task. 241 // Make a port with receive rights in the destination task.
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
317 base::AutoLock l(precursors_lock_); 319 base::AutoLock l(precursors_lock_);
318 auto it = precursors_.find(pid); 320 auto it = precursors_.find(pid);
319 if (it == precursors_.end()) 321 if (it == precursors_.end())
320 return; 322 return;
321 323
322 // Whether this process is the destination process. 324 // Whether this process is the destination process.
323 bool to_self = pid == base::GetCurrentProcId(); 325 bool to_self = pid == base::GetCurrentProcId();
324 326
325 if (!to_self) { 327 if (!to_self) {
326 base::AutoLock auto_lock(*get_lock()); 328 base::AutoLock auto_lock(*get_lock());
327 if (!GetSenderWithProcessId(pid)) { 329 AttachmentBrokerPrivileged::EndpointRunnerPair pair =
330 GetSenderWithProcessId(pid);
331 if (!pair.first) {
328 // If there is no sender, then the destination process is no longer 332 // If there is no sender, then the destination process is no longer
329 // running, or never existed to begin with. 333 // running, or never existed to begin with.
330 LogError(DESTINATION_NOT_FOUND); 334 LogError(DESTINATION_NOT_FOUND);
331 delete it->second; 335 delete it->second;
332 precursors_.erase(it); 336 precursors_.erase(it);
333 return; 337 return;
334 } 338 }
335 } 339 }
336 340
337 mach_port_t task_port = port_provider_->TaskForPid(pid); 341 mach_port_t task_port = port_provider_->TaskForPid(pid);
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
387 391
388 void AttachmentBrokerPrivilegedMac::ProcessExtractorsForProcess( 392 void AttachmentBrokerPrivilegedMac::ProcessExtractorsForProcess(
389 base::ProcessId pid) { 393 base::ProcessId pid) {
390 base::AutoLock l(extractors_lock_); 394 base::AutoLock l(extractors_lock_);
391 auto it = extractors_.find(pid); 395 auto it = extractors_.find(pid);
392 if (it == extractors_.end()) 396 if (it == extractors_.end())
393 return; 397 return;
394 398
395 { 399 {
396 base::AutoLock auto_lock(*get_lock()); 400 base::AutoLock auto_lock(*get_lock());
397 if (!GetSenderWithProcessId(pid)) { 401 AttachmentBrokerPrivileged::EndpointRunnerPair pair =
402 GetSenderWithProcessId(pid);
403 if (!pair.first) {
398 // If there is no sender, then the source process is no longer running. 404 // If there is no sender, then the source process is no longer running.
399 LogError(ERROR_SOURCE_NOT_FOUND); 405 LogError(ERROR_SOURCE_NOT_FOUND);
400 delete it->second; 406 delete it->second;
401 extractors_.erase(it); 407 extractors_.erase(it);
402 return; 408 return;
403 } 409 }
404 } 410 }
405 411
406 mach_port_t task_port = port_provider_->TaskForPid(pid); 412 mach_port_t task_port = port_provider_->TaskForPid(pid);
407 413
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
442 448
443 auto it = extractors_.find(source_pid); 449 auto it = extractors_.find(source_pid);
444 if (it == extractors_.end()) 450 if (it == extractors_.end())
445 extractors_[source_pid] = new ScopedVector<AttachmentExtractor>; 451 extractors_[source_pid] = new ScopedVector<AttachmentExtractor>;
446 452
447 extractors_[source_pid]->push_back( 453 extractors_[source_pid]->push_back(
448 new AttachmentExtractor(source_pid, dest_pid, port, id)); 454 new AttachmentExtractor(source_pid, dest_pid, port, id));
449 } 455 }
450 456
451 } // namespace IPC 457 } // namespace IPC
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698