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

Unified Diff: mojo/system/message_in_transit.cc

Issue 227383006: Mojo: Allow dispatchers to attach PlatformHandles to the MessageInTransit on serialization. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 8 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 | « mojo/system/message_in_transit.h ('k') | mojo/system/message_pipe_dispatcher.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/system/message_in_transit.cc
diff --git a/mojo/system/message_in_transit.cc b/mojo/system/message_in_transit.cc
index 069218828d3edeccc8ad00b64cb769db8e011baa..73cefe38dda703bda5dc23be400904719104dbd2 100644
--- a/mojo/system/message_in_transit.cc
+++ b/mojo/system/message_in_transit.cc
@@ -55,6 +55,8 @@ STATIC_CONST_MEMBER_DEFINITION const MessageInTransit::EndpointId
STATIC_CONST_MEMBER_DEFINITION const size_t MessageInTransit::kMessageAlignment;
STATIC_CONST_MEMBER_DEFINITION const size_t
MessageInTransit::kMaxSerializedDispatcherSize;
+STATIC_CONST_MEMBER_DEFINITION const size_t
+ MessageInTransit::kMaxSerializedDispatcherPlatformHandles;
// For each attached (Mojo) handle, there'll be a handle table entry and
// serialized dispatcher data.
@@ -62,6 +64,9 @@ STATIC_CONST_MEMBER_DEFINITION const size_t
const size_t MessageInTransit::kMaxSecondaryBufferSize = kMaxMessageNumHandles *
(sizeof(HandleTableEntry) + kMaxSerializedDispatcherSize);
+const size_t MessageInTransit::kMaxPlatformHandles =
+ kMaxMessageNumHandles * kMaxSerializedDispatcherPlatformHandles;
+
MessageInTransit::View::View(size_t message_size, const void* buffer)
: buffer_(buffer) {
size_t next_message_size = 0;
@@ -216,14 +221,31 @@ void MessageInTransit::SerializeAndCloseDispatchers(Channel* channel) {
// The size of the secondary buffer. We'll start with the size of the handle
// table, and add to it as we go along.
size_t size = handle_table_size;
- for (size_t i = 0; i < dispatchers_->size(); i++) {
+ size_t num_platform_handles = 0;
+#if DCHECK_IS_ON
+ std::vector<size_t> all_max_sizes(num_handles());
+ std::vector<size_t> all_max_platform_handles(num_handles());
+#endif
+ for (size_t i = 0; i < num_handles(); i++) {
if (Dispatcher* dispatcher = (*dispatchers_)[i].get()) {
- size_t max_serialized_size =
- Dispatcher::MessageInTransitAccess::GetMaximumSerializedSize(
- dispatcher, channel);
- DCHECK_LE(max_serialized_size, kMaxSerializedDispatcherSize);
- size += RoundUpMessageAlignment(max_serialized_size);
+ size_t max_size = 0;
+ size_t max_platform_handles = 0;
+ Dispatcher::MessageInTransitAccess::StartSerialize(
+ dispatcher, channel, &max_size, &max_platform_handles);
+
+ DCHECK_LE(max_size, kMaxSerializedDispatcherSize);
+ size += RoundUpMessageAlignment(max_size);
DCHECK_LE(size, kMaxSecondaryBufferSize);
+
+ DCHECK_LE(max_platform_handles,
+ kMaxSerializedDispatcherPlatformHandles);
+ num_platform_handles += max_platform_handles;
+ DCHECK_LE(num_platform_handles, kMaxPlatformHandles);
+
+#if DCHECK_IS_ON
+ all_max_sizes[i] = max_size;
+ all_max_platform_handles[i] = max_platform_handles;
+#endif
}
}
@@ -234,10 +256,15 @@ void MessageInTransit::SerializeAndCloseDispatchers(Channel* channel) {
// serialize).
memset(secondary_buffer_, 0, size);
+ if (num_platform_handles > 0) {
+ DCHECK(!platform_handles_);
+ platform_handles_.reset(new std::vector<embedder::PlatformHandle>());
+ }
+
HandleTableEntry* handle_table =
static_cast<HandleTableEntry*>(secondary_buffer_);
size_t current_offset = handle_table_size;
- for (size_t i = 0; i < dispatchers_->size(); i++) {
+ for (size_t i = 0; i < num_handles(); i++) {
Dispatcher* dispatcher = (*dispatchers_)[i].get();
if (!dispatcher) {
COMPILE_ASSERT(Dispatcher::kTypeUnknown == 0,
@@ -245,13 +272,26 @@ void MessageInTransit::SerializeAndCloseDispatchers(Channel* channel) {
continue;
}
+#if DCHECK_IS_ON
+ size_t old_platform_handles_size =
+ platform_handles_ ? platform_handles_->size() : 0;
+#endif
+
void* destination = static_cast<char*>(secondary_buffer_) + current_offset;
size_t actual_size = 0;
- if (Dispatcher::MessageInTransitAccess::SerializeAndClose(
- dispatcher, channel, destination, &actual_size)) {
+ if (Dispatcher::MessageInTransitAccess::EndSerializeAndClose(
+ dispatcher, channel, destination, &actual_size,
+ platform_handles_.get())) {
handle_table[i].type = static_cast<int32_t>(dispatcher->GetType());
handle_table[i].offset = static_cast<uint32_t>(current_offset);
handle_table[i].size = static_cast<uint32_t>(actual_size);
+
+#if DCHECK_IS_ON
+ DCHECK_LE(actual_size, all_max_sizes[i]);
+ DCHECK_LE(platform_handles_ ? (platform_handles_->size() -
+ old_platform_handles_size) : 0,
+ all_max_platform_handles[i]);
+#endif
} else {
// Nothing to do on failure, since |secondary_buffer_| was cleared, and
// |kTypeUnknown| is zero. The handle was simply closed.
@@ -260,6 +300,8 @@ void MessageInTransit::SerializeAndCloseDispatchers(Channel* channel) {
current_offset += RoundUpMessageAlignment(actual_size);
DCHECK_LE(current_offset, size);
+ DCHECK_LE(platform_handles_ ? platform_handles_->size() : 0,
+ num_platform_handles);
}
UpdateTotalSize();
« no previous file with comments | « mojo/system/message_in_transit.h ('k') | mojo/system/message_pipe_dispatcher.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698