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

Side by Side Diff: mojo/edk/system/node_channel.cc

Issue 2008953003: [mojo-edk] Explicitly serialise HANDLEs into messages instead of PlatformHandles. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: cast2 Created 4 years, 6 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 | « mojo/edk/system/message_pipe_dispatcher.cc ('k') | mojo/edk/system/node_controller.cc » ('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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 "mojo/edk/system/node_channel.h" 5 #include "mojo/edk/system/node_channel.h"
6 6
7 #include <cstring> 7 #include <cstring>
8 #include <limits> 8 #include <limits>
9 #include <sstream> 9 #include <sstream>
10 10
(...skipping 398 matching lines...) Expand 10 before | Expand all | Expand 10 after
409 { 409 {
410 base::AutoLock lock(remote_process_handle_lock_); 410 base::AutoLock lock(remote_process_handle_lock_);
411 if (handles && remote_process_handle_ != base::kNullProcessHandle) { 411 if (handles && remote_process_handle_ != base::kNullProcessHandle) {
412 // Note that we explicitly mark the handles as being owned by the sending 412 // Note that we explicitly mark the handles as being owned by the sending
413 // process before rewriting them, in order to accommodate RewriteHandles' 413 // process before rewriting them, in order to accommodate RewriteHandles'
414 // internal sanity checks. 414 // internal sanity checks.
415 for (auto& handle : *handles) 415 for (auto& handle : *handles)
416 handle.owning_process = remote_process_handle_; 416 handle.owning_process = remote_process_handle_;
417 if (!Channel::Message::RewriteHandles(remote_process_handle_, 417 if (!Channel::Message::RewriteHandles(remote_process_handle_,
418 base::GetCurrentProcessHandle(), 418 base::GetCurrentProcessHandle(),
419 handles->data(), handles->size())) { 419 handles.get())) {
420 DLOG(ERROR) << "Received one or more invalid handles."; 420 DLOG(ERROR) << "Received one or more invalid handles.";
421 } 421 }
422 } else if (handles) { 422 } else if (handles) {
423 // Handles received by an unknown process must already be owned by us. 423 // Handles received by an unknown process must already be owned by us.
424 for (auto& handle : *handles) 424 for (auto& handle : *handles)
425 handle.owning_process = base::GetCurrentProcessHandle(); 425 handle.owning_process = base::GetCurrentProcessHandle();
426 } 426 }
427 } 427 }
428 #elif defined(OS_MACOSX) && !defined(OS_IOS) 428 #elif defined(OS_MACOSX) && !defined(OS_IOS)
429 // If we're not the root, receive any mach ports from the message. If we're 429 // If we're not the root, receive any mach ports from the message. If we're
(...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after
721 721
722 if (message->has_handles()) { 722 if (message->has_handles()) {
723 base::ProcessHandle remote_process_handle; 723 base::ProcessHandle remote_process_handle;
724 { 724 {
725 base::AutoLock lock(remote_process_handle_lock_); 725 base::AutoLock lock(remote_process_handle_lock_);
726 remote_process_handle = remote_process_handle_; 726 remote_process_handle = remote_process_handle_;
727 } 727 }
728 728
729 // Rewrite outgoing handles if we have a handle to the destination process. 729 // Rewrite outgoing handles if we have a handle to the destination process.
730 if (remote_process_handle != base::kNullProcessHandle) { 730 if (remote_process_handle != base::kNullProcessHandle) {
731 if (!message->RewriteHandles(base::GetCurrentProcessHandle(), 731 ScopedPlatformHandleVectorPtr handles = message->TakeHandles();
732 remote_process_handle, message->handles(), 732 if (!Channel::Message::RewriteHandles(base::GetCurrentProcessHandle(),
733 message->num_handles())) { 733 remote_process_handle,
734 handles.get())) {
734 DLOG(ERROR) << "Failed to duplicate one or more outgoing handles."; 735 DLOG(ERROR) << "Failed to duplicate one or more outgoing handles.";
735 } 736 }
737 message->SetHandles(std::move(handles));
736 } 738 }
737 } 739 }
738 #elif defined(OS_MACOSX) && !defined(OS_IOS) 740 #elif defined(OS_MACOSX) && !defined(OS_IOS)
739 // On OSX, we need to transfer mach ports to the destination process before 741 // On OSX, we need to transfer mach ports to the destination process before
740 // transferring the message itself. 742 // transferring the message itself.
741 if (message->has_mach_ports()) { 743 if (message->has_mach_ports()) {
742 MachPortRelay* relay = delegate_->GetMachPortRelay(); 744 MachPortRelay* relay = delegate_->GetMachPortRelay();
743 if (relay) { 745 if (relay) {
744 base::ProcessHandle remote_process_handle; 746 base::ProcessHandle remote_process_handle;
745 { 747 {
(...skipping 26 matching lines...) Expand all
772 774
773 base::AutoLock lock(channel_lock_); 775 base::AutoLock lock(channel_lock_);
774 if (!channel_) 776 if (!channel_)
775 DLOG(ERROR) << "Dropping message on closed channel."; 777 DLOG(ERROR) << "Dropping message on closed channel.";
776 else 778 else
777 channel_->Write(std::move(message)); 779 channel_->Write(std::move(message));
778 } 780 }
779 781
780 } // namespace edk 782 } // namespace edk
781 } // namespace mojo 783 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/edk/system/message_pipe_dispatcher.cc ('k') | mojo/edk/system/node_controller.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698