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

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

Issue 1975073002: [mojo-edk] Broadcast surprise port disruptions (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@reenable-clean-shutdown
Patch Set: rebase 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 21 matching lines...) Expand all
32 enum class MessageType : uint32_t { 32 enum class MessageType : uint32_t {
33 ACCEPT_CHILD, 33 ACCEPT_CHILD,
34 ACCEPT_PARENT, 34 ACCEPT_PARENT,
35 ADD_BROKER_CLIENT, 35 ADD_BROKER_CLIENT,
36 BROKER_CLIENT_ADDED, 36 BROKER_CLIENT_ADDED,
37 ACCEPT_BROKER_CLIENT, 37 ACCEPT_BROKER_CLIENT,
38 PORTS_MESSAGE, 38 PORTS_MESSAGE,
39 REQUEST_PORT_MERGE, 39 REQUEST_PORT_MERGE,
40 REQUEST_INTRODUCTION, 40 REQUEST_INTRODUCTION,
41 INTRODUCE, 41 INTRODUCE,
42 BROADCAST,
42 #if defined(OS_WIN) || (defined(OS_MACOSX) && !defined(OS_IOS)) 43 #if defined(OS_WIN) || (defined(OS_MACOSX) && !defined(OS_IOS))
43 RELAY_PORTS_MESSAGE, 44 RELAY_PORTS_MESSAGE,
44 #endif 45 #endif
45 }; 46 };
46 47
47 struct Header { 48 struct Header {
48 MessageType type; 49 MessageType type;
49 uint32_t padding; 50 uint32_t padding;
50 }; 51 };
51 52
(...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after
322 ScopedPlatformHandleVectorPtr handles(new PlatformHandleVector()); 323 ScopedPlatformHandleVectorPtr handles(new PlatformHandleVector());
323 if (channel_handle.is_valid()) 324 if (channel_handle.is_valid())
324 handles->push_back(channel_handle.release()); 325 handles->push_back(channel_handle.release());
325 Channel::MessagePtr message = CreateMessage( 326 Channel::MessagePtr message = CreateMessage(
326 MessageType::INTRODUCE, sizeof(IntroductionData), handles->size(), &data); 327 MessageType::INTRODUCE, sizeof(IntroductionData), handles->size(), &data);
327 message->SetHandles(std::move(handles)); 328 message->SetHandles(std::move(handles));
328 data->name = name; 329 data->name = name;
329 WriteChannelMessage(std::move(message)); 330 WriteChannelMessage(std::move(message));
330 } 331 }
331 332
333 void NodeChannel::Broadcast(Channel::MessagePtr message) {
334 DCHECK(!message->has_handles());
335 void* data;
336 Channel::MessagePtr broadcast_message = CreateMessage(
337 MessageType::BROADCAST, message->data_num_bytes(), 0, &data);
338 memcpy(data, message->data(), message->data_num_bytes());
339 WriteChannelMessage(std::move(broadcast_message));
340 }
341
332 #if defined(OS_WIN) || (defined(OS_MACOSX) && !defined(OS_IOS)) 342 #if defined(OS_WIN) || (defined(OS_MACOSX) && !defined(OS_IOS))
333 void NodeChannel::RelayPortsMessage(const ports::NodeName& destination, 343 void NodeChannel::RelayPortsMessage(const ports::NodeName& destination,
334 Channel::MessagePtr message) { 344 Channel::MessagePtr message) {
335 #if defined(OS_WIN) 345 #if defined(OS_WIN)
336 DCHECK(message->has_handles()); 346 DCHECK(message->has_handles());
337 347
338 // Note that this is only used on Windows, and on Windows all platform 348 // Note that this is only used on Windows, and on Windows all platform
339 // handles are included in the message data. We blindly copy all the data 349 // handles are included in the message data. We blindly copy all the data
340 // here and the relay node (the parent) will duplicate handles as needed. 350 // here and the relay node (the parent) will duplicate handles as needed.
341 size_t num_bytes = sizeof(RelayPortsMessageData) + message->data_num_bytes(); 351 size_t num_bytes = sizeof(RelayPortsMessageData) + message->data_num_bytes();
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after
567 channel_handle = ScopedPlatformHandle(handles->at(0)); 577 channel_handle = ScopedPlatformHandle(handles->at(0));
568 handles->clear(); 578 handles->clear();
569 } 579 }
570 delegate_->OnIntroduce(remote_node_name_, data->name, 580 delegate_->OnIntroduce(remote_node_name_, data->name,
571 std::move(channel_handle)); 581 std::move(channel_handle));
572 return; 582 return;
573 } 583 }
574 break; 584 break;
575 } 585 }
576 586
587 case MessageType::BROADCAST: {
588 if (payload_size <= sizeof(Header))
589 break;
590 const void* data = static_cast<const void*>(
591 reinterpret_cast<const Header*>(payload) + 1);
592 Channel::MessagePtr message =
593 Channel::Message::Deserialize(data, payload_size - sizeof(Header));
594 if (!message) {
595 DLOG(ERROR) << "Dropping invalid broadcast message.";
596 break;
597 }
598 delegate_->OnBroadcast(std::move(message));
599 return;
600 }
601
577 #if defined(OS_WIN) || (defined(OS_MACOSX) && !defined(OS_IOS)) 602 #if defined(OS_WIN) || (defined(OS_MACOSX) && !defined(OS_IOS))
578 case MessageType::RELAY_PORTS_MESSAGE: { 603 case MessageType::RELAY_PORTS_MESSAGE: {
579 base::ProcessHandle from_process; 604 base::ProcessHandle from_process;
580 { 605 {
581 base::AutoLock lock(remote_process_handle_lock_); 606 base::AutoLock lock(remote_process_handle_lock_);
582 from_process = remote_process_handle_; 607 from_process = remote_process_handle_;
583 } 608 }
584 const RelayPortsMessageData* data; 609 const RelayPortsMessageData* data;
585 if (GetMessagePayload(payload, payload_size, &data)) { 610 if (GetMessagePayload(payload, payload_size, &data)) {
586 // Don't try to relay an empty message. 611 // Don't try to relay an empty message.
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
754 779
755 base::AutoLock lock(channel_lock_); 780 base::AutoLock lock(channel_lock_);
756 if (!channel_) 781 if (!channel_)
757 DLOG(ERROR) << "Dropping message on closed channel."; 782 DLOG(ERROR) << "Dropping message on closed channel.";
758 else 783 else
759 channel_->Write(std::move(message)); 784 channel_->Write(std::move(message));
760 } 785 }
761 786
762 } // namespace edk 787 } // namespace edk
763 } // namespace mojo 788 } // namespace mojo
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698