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

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: remove handles accessor Created 4 years, 7 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 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 ScopedPlatformHandleVectorPtr handles = message->TakeHandles();
731 if (!message->RewriteHandles(base::GetCurrentProcessHandle(), 732 if (!message->RewriteHandles(base::GetCurrentProcessHandle(),
Ken Rockot(use gerrit already) 2016/05/25 15:48:12 nit: While you're here please update this call sit
Anand Mistry (off Chromium) 2016/05/25 23:36:38 Done.
732 remote_process_handle, message->handles(), 733 remote_process_handle, handles.get())) {
733 message->num_handles())) {
734 DLOG(ERROR) << "Failed to duplicate one or more outgoing handles."; 734 DLOG(ERROR) << "Failed to duplicate one or more outgoing handles.";
735 } 735 }
736 message->SetHandles(std::move(handles));
736 } 737 }
737 } 738 }
738 #elif defined(OS_MACOSX) && !defined(OS_IOS) 739 #elif defined(OS_MACOSX) && !defined(OS_IOS)
739 // On OSX, we need to transfer mach ports to the destination process before 740 // On OSX, we need to transfer mach ports to the destination process before
740 // transferring the message itself. 741 // transferring the message itself.
741 if (message->has_mach_ports()) { 742 if (message->has_mach_ports()) {
742 MachPortRelay* relay = delegate_->GetMachPortRelay(); 743 MachPortRelay* relay = delegate_->GetMachPortRelay();
743 if (relay) { 744 if (relay) {
744 base::ProcessHandle remote_process_handle; 745 base::ProcessHandle remote_process_handle;
745 { 746 {
(...skipping 26 matching lines...) Expand all
772 773
773 base::AutoLock lock(channel_lock_); 774 base::AutoLock lock(channel_lock_);
774 if (!channel_) 775 if (!channel_)
775 DLOG(ERROR) << "Dropping message on closed channel."; 776 DLOG(ERROR) << "Dropping message on closed channel.";
776 else 777 else
777 channel_->Write(std::move(message)); 778 channel_->Write(std::move(message));
778 } 779 }
779 780
780 } // namespace edk 781 } // namespace edk
781 } // namespace mojo 782 } // namespace mojo
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698