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

Unified Diff: mojo/edk/system/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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | mojo/edk/system/node_channel.h » ('j') | mojo/edk/system/node_controller.cc » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/edk/system/channel.cc
diff --git a/mojo/edk/system/channel.cc b/mojo/edk/system/channel.cc
index 2976a21b8a4b2d5b4a8e289fb0748991998bef30..c3e66cba266b359986e803708413e8b246c03fe8 100644
--- a/mojo/edk/system/channel.cc
+++ b/mojo/edk/system/channel.cc
@@ -124,12 +124,6 @@ Channel::Message::~Message() {
// static
Channel::MessagePtr Channel::Message::Deserialize(const void* data,
size_t data_num_bytes) {
-#if !defined(OS_WIN) && !(defined(OS_MACOSX) && !defined(OS_IOS))
- // We only serialize messages into other messages when performing message
- // relay on Windows and OSX.
- NOTREACHED();
- return nullptr;
-#else
if (data_num_bytes < sizeof(Header))
return nullptr;
@@ -140,6 +134,7 @@ Channel::MessagePtr Channel::Message::Deserialize(const void* data,
return nullptr;
}
+#if !defined(OS_ANDROID) && !defined(OS_CHROMEOS)
if (header->num_bytes < header->num_header_bytes) {
DLOG(ERROR) << "Decoding invalid message: " << header->num_bytes << " < "
<< header->num_header_bytes;
@@ -147,41 +142,53 @@ Channel::MessagePtr Channel::Message::Deserialize(const void* data,
}
uint32_t extra_header_size = header->num_header_bytes - sizeof(Header);
+ size_t payload_size = data_num_bytes - header->num_header_bytes;
+ const char* payload =
+ static_cast<const char*>(data) + header->num_header_bytes;
#if defined(OS_WIN)
uint32_t max_handles = extra_header_size / sizeof(PlatformHandle);
#elif defined(OS_MACOSX) && !defined(OS_IOS)
uint32_t max_handles = extra_header_size / sizeof(MachPortsEntry);
+#else
+ const uint32_t max_handles = 0;
#endif
+
+#else // !defined(OS_ANDROID) && !defined(OS_CHROMEOS)
+ // We only serialize messages with handles into other messages when performing
+ // message relay on Windows and OSX.
+ const uint32_t max_handles = 0;
+ const char* payload = static_cast<const char*>(data) + sizeof(Header);
+ size_t payload_size = data_num_bytes;
+#endif // !defined(OS_ANDROID) && !defined(OS_CHROMEOS)
+
if (header->num_handles > max_handles) {
DLOG(ERROR) << "Decoding invalid message:" << header->num_handles
<< " > " << max_handles;
return nullptr;
}
- MessagePtr message(new Message(data_num_bytes - header->num_header_bytes,
- max_handles));
+ MessagePtr message(new Message(payload_size, max_handles));
DCHECK_EQ(message->data_num_bytes(), data_num_bytes);
+
+ // Copy all payload bytes.
+ if (payload_size)
+ memcpy(message->mutable_payload(), payload, payload_size);
+
+#if !defined(OS_ANDROID) && !defined(OS_CHROMEOS)
DCHECK_EQ(message->extra_header_size(), extra_header_size);
DCHECK_EQ(message->header_->num_header_bytes, header->num_header_bytes);
- if (data_num_bytes > header->num_header_bytes) {
- // Copy all payload bytes.
- memcpy(message->mutable_payload(),
- static_cast<const char*>(data) + header->num_header_bytes,
- data_num_bytes - header->num_header_bytes);
- }
-
if (message->extra_header_size()) {
// Copy extra header bytes.
memcpy(message->mutable_extra_header(),
static_cast<const char*>(data) + sizeof(Header),
message->extra_header_size());
}
+#endif // !defined(OS_ANDROID) && !defined(OS_CHROMEOS)
message->header_->num_handles = header->num_handles;
return message;
-#endif
}
size_t Channel::Message::payload_size() const {
« no previous file with comments | « no previous file | mojo/edk/system/node_channel.h » ('j') | mojo/edk/system/node_controller.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698