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

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

Issue 851503003: Update from https://crrev.com/311076 (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 11 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 | « gpu/tools/compositor_model_bench/compositor_model_bench.cc ('k') | net/base/net_error_list.h » ('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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/transport_data.h" 5 #include "mojo/edk/system/transport_data.h"
6 6
7 #include <string.h> 7 #include <string.h>
8 8
9 #include "base/compiler_specific.h" 9 #include "base/compiler_specific.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 71
72 // The offset to the start of the (Mojo) handle table. 72 // The offset to the start of the (Mojo) handle table.
73 const size_t handle_table_start_offset = sizeof(Header); 73 const size_t handle_table_start_offset = sizeof(Header);
74 // The offset to the start of the serialized dispatcher data. 74 // The offset to the start of the serialized dispatcher data.
75 const size_t serialized_dispatcher_start_offset = 75 const size_t serialized_dispatcher_start_offset =
76 handle_table_start_offset + num_handles * sizeof(HandleTableEntry); 76 handle_table_start_offset + num_handles * sizeof(HandleTableEntry);
77 // The estimated size of the secondary buffer. We compute this estimate below. 77 // The estimated size of the secondary buffer. We compute this estimate below.
78 // It must be at least as big as the (eventual) actual size. 78 // It must be at least as big as the (eventual) actual size.
79 size_t estimated_size = serialized_dispatcher_start_offset; 79 size_t estimated_size = serialized_dispatcher_start_offset;
80 size_t estimated_num_platform_handles = 0; 80 size_t estimated_num_platform_handles = 0;
81 #if DCHECK_IS_ON 81 #if DCHECK_IS_ON()
82 std::vector<size_t> all_max_sizes(num_handles); 82 std::vector<size_t> all_max_sizes(num_handles);
83 std::vector<size_t> all_max_platform_handles(num_handles); 83 std::vector<size_t> all_max_platform_handles(num_handles);
84 #endif 84 #endif
85 for (size_t i = 0; i < num_handles; i++) { 85 for (size_t i = 0; i < num_handles; i++) {
86 if (Dispatcher* dispatcher = (*dispatchers)[i].get()) { 86 if (Dispatcher* dispatcher = (*dispatchers)[i].get()) {
87 size_t max_size = 0; 87 size_t max_size = 0;
88 size_t max_platform_handles = 0; 88 size_t max_platform_handles = 0;
89 Dispatcher::TransportDataAccess::StartSerialize( 89 Dispatcher::TransportDataAccess::StartSerialize(
90 dispatcher, channel, &max_size, &max_platform_handles); 90 dispatcher, channel, &max_size, &max_platform_handles);
91 91
92 DCHECK_LE(max_size, kMaxSerializedDispatcherSize); 92 DCHECK_LE(max_size, kMaxSerializedDispatcherSize);
93 estimated_size += MessageInTransit::RoundUpMessageAlignment(max_size); 93 estimated_size += MessageInTransit::RoundUpMessageAlignment(max_size);
94 DCHECK_LE(estimated_size, GetMaxBufferSize()); 94 DCHECK_LE(estimated_size, GetMaxBufferSize());
95 95
96 DCHECK_LE(max_platform_handles, kMaxSerializedDispatcherPlatformHandles); 96 DCHECK_LE(max_platform_handles, kMaxSerializedDispatcherPlatformHandles);
97 estimated_num_platform_handles += max_platform_handles; 97 estimated_num_platform_handles += max_platform_handles;
98 DCHECK_LE(estimated_num_platform_handles, GetMaxPlatformHandles()); 98 DCHECK_LE(estimated_num_platform_handles, GetMaxPlatformHandles());
99 99
100 #if DCHECK_IS_ON 100 #if DCHECK_IS_ON()
101 all_max_sizes[i] = max_size; 101 all_max_sizes[i] = max_size;
102 all_max_platform_handles[i] = max_platform_handles; 102 all_max_platform_handles[i] = max_platform_handles;
103 #endif 103 #endif
104 } 104 }
105 } 105 }
106 106
107 size_t size_per_platform_handle = 0; 107 size_t size_per_platform_handle = 0;
108 if (estimated_num_platform_handles > 0) { 108 if (estimated_num_platform_handles > 0) {
109 size_per_platform_handle = channel->GetSerializedPlatformHandleSize(); 109 size_per_platform_handle = channel->GetSerializedPlatformHandleSize();
110 DCHECK_LE(size_per_platform_handle, kMaxSizePerPlatformHandle); 110 DCHECK_LE(size_per_platform_handle, kMaxSizePerPlatformHandle);
(...skipping 23 matching lines...) Expand all
134 buffer_.get() + handle_table_start_offset); 134 buffer_.get() + handle_table_start_offset);
135 size_t current_offset = serialized_dispatcher_start_offset; 135 size_t current_offset = serialized_dispatcher_start_offset;
136 for (size_t i = 0; i < num_handles; i++) { 136 for (size_t i = 0; i < num_handles; i++) {
137 Dispatcher* dispatcher = (*dispatchers)[i].get(); 137 Dispatcher* dispatcher = (*dispatchers)[i].get();
138 if (!dispatcher) { 138 if (!dispatcher) {
139 static_assert(Dispatcher::kTypeUnknown == 0, 139 static_assert(Dispatcher::kTypeUnknown == 0,
140 "Value of Dispatcher::kTypeUnknown must be 0"); 140 "Value of Dispatcher::kTypeUnknown must be 0");
141 continue; 141 continue;
142 } 142 }
143 143
144 #if DCHECK_IS_ON 144 #if DCHECK_IS_ON()
145 size_t old_platform_handles_size = 145 size_t old_platform_handles_size =
146 platform_handles_ ? platform_handles_->size() : 0; 146 platform_handles_ ? platform_handles_->size() : 0;
147 #endif 147 #endif
148 148
149 void* destination = buffer_.get() + current_offset; 149 void* destination = buffer_.get() + current_offset;
150 size_t actual_size = 0; 150 size_t actual_size = 0;
151 if (Dispatcher::TransportDataAccess::EndSerializeAndClose( 151 if (Dispatcher::TransportDataAccess::EndSerializeAndClose(
152 dispatcher, channel, destination, &actual_size, 152 dispatcher, channel, destination, &actual_size,
153 platform_handles_.get())) { 153 platform_handles_.get())) {
154 handle_table[i].type = static_cast<int32_t>(dispatcher->GetType()); 154 handle_table[i].type = static_cast<int32_t>(dispatcher->GetType());
155 handle_table[i].offset = static_cast<uint32_t>(current_offset); 155 handle_table[i].offset = static_cast<uint32_t>(current_offset);
156 handle_table[i].size = static_cast<uint32_t>(actual_size); 156 handle_table[i].size = static_cast<uint32_t>(actual_size);
157 // (Okay to not set |unused| since we cleared the entire buffer.) 157 // (Okay to not set |unused| since we cleared the entire buffer.)
158 158
159 #if DCHECK_IS_ON 159 #if DCHECK_IS_ON()
160 DCHECK_LE(actual_size, all_max_sizes[i]); 160 DCHECK_LE(actual_size, all_max_sizes[i]);
161 DCHECK_LE(platform_handles_ 161 DCHECK_LE(platform_handles_
162 ? (platform_handles_->size() - old_platform_handles_size) 162 ? (platform_handles_->size() - old_platform_handles_size)
163 : 0, 163 : 0,
164 all_max_platform_handles[i]); 164 all_max_platform_handles[i]);
165 #endif 165 #endif
166 } else { 166 } else {
167 // Nothing to do on failure, since |buffer_| was cleared, and 167 // Nothing to do on failure, since |buffer_| was cleared, and
168 // |kTypeUnknown| is zero. The handle was simply closed. 168 // |kTypeUnknown| is zero. The handle was simply closed.
169 LOG(ERROR) << "Failed to serialize handle to remote message pipe"; 169 LOG(ERROR) << "Failed to serialize handle to remote message pipe";
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
335 const void* source = static_cast<const char*>(buffer) + offset; 335 const void* source = static_cast<const char*>(buffer) + offset;
336 (*dispatchers)[i] = Dispatcher::TransportDataAccess::Deserialize( 336 (*dispatchers)[i] = Dispatcher::TransportDataAccess::Deserialize(
337 channel, handle_table[i].type, source, size, platform_handles.get()); 337 channel, handle_table[i].type, source, size, platform_handles.get());
338 } 338 }
339 339
340 return dispatchers.Pass(); 340 return dispatchers.Pass();
341 } 341 }
342 342
343 } // namespace system 343 } // namespace system
344 } // namespace mojo 344 } // namespace mojo
OLDNEW
« no previous file with comments | « gpu/tools/compositor_model_bench/compositor_model_bench.cc ('k') | net/base/net_error_list.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698