OLD | NEW |
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 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
130 header->num_handles = static_cast<uint32_t>(num_handles); | 130 header->num_handles = static_cast<uint32_t>(num_handles); |
131 // (Okay to leave |platform_handle_table_offset|, |num_platform_handles|, and | 131 // (Okay to leave |platform_handle_table_offset|, |num_platform_handles|, and |
132 // |unused| be zero; we'll set the former two later if necessary.) | 132 // |unused| be zero; we'll set the former two later if necessary.) |
133 | 133 |
134 HandleTableEntry* handle_table = reinterpret_cast<HandleTableEntry*>( | 134 HandleTableEntry* handle_table = reinterpret_cast<HandleTableEntry*>( |
135 buffer_.get() + handle_table_start_offset); | 135 buffer_.get() + handle_table_start_offset); |
136 size_t current_offset = serialized_dispatcher_start_offset; | 136 size_t current_offset = serialized_dispatcher_start_offset; |
137 for (size_t i = 0; i < num_handles; i++) { | 137 for (size_t i = 0; i < num_handles; i++) { |
138 Dispatcher* dispatcher = (*dispatchers)[i].get(); | 138 Dispatcher* dispatcher = (*dispatchers)[i].get(); |
139 if (!dispatcher) { | 139 if (!dispatcher) { |
140 static_assert(Dispatcher::kTypeUnknown == 0, | 140 static_assert(static_cast<int32_t>(Dispatcher::Type::UNKNOWN) == 0, |
141 "Value of Dispatcher::kTypeUnknown must be 0"); | 141 "Value of Dispatcher::Type::UNKNOWN must be 0"); |
142 continue; | 142 continue; |
143 } | 143 } |
144 | 144 |
145 #if DCHECK_IS_ON() | 145 #if DCHECK_IS_ON() |
146 size_t old_platform_handles_size = | 146 size_t old_platform_handles_size = |
147 platform_handles_ ? platform_handles_->size() : 0; | 147 platform_handles_ ? platform_handles_->size() : 0; |
148 #endif | 148 #endif |
149 | 149 |
150 void* destination = buffer_.get() + current_offset; | 150 void* destination = buffer_.get() + current_offset; |
151 size_t actual_size = 0; | 151 size_t actual_size = 0; |
152 if (Dispatcher::TransportDataAccess::EndSerializeAndClose( | 152 if (Dispatcher::TransportDataAccess::EndSerializeAndClose( |
153 dispatcher, channel, destination, &actual_size, | 153 dispatcher, channel, destination, &actual_size, |
154 platform_handles_.get())) { | 154 platform_handles_.get())) { |
155 handle_table[i].type = static_cast<int32_t>(dispatcher->GetType()); | 155 handle_table[i].type = static_cast<int32_t>(dispatcher->GetType()); |
156 handle_table[i].offset = static_cast<uint32_t>(current_offset); | 156 handle_table[i].offset = static_cast<uint32_t>(current_offset); |
157 handle_table[i].size = static_cast<uint32_t>(actual_size); | 157 handle_table[i].size = static_cast<uint32_t>(actual_size); |
158 // (Okay to not set |unused| since we cleared the entire buffer.) | 158 // (Okay to not set |unused| since we cleared the entire buffer.) |
159 | 159 |
160 #if DCHECK_IS_ON() | 160 #if DCHECK_IS_ON() |
161 DCHECK_LE(actual_size, all_max_sizes[i]); | 161 DCHECK_LE(actual_size, all_max_sizes[i]); |
162 DCHECK_LE(platform_handles_ | 162 DCHECK_LE(platform_handles_ |
163 ? (platform_handles_->size() - old_platform_handles_size) | 163 ? (platform_handles_->size() - old_platform_handles_size) |
164 : 0, | 164 : 0, |
165 all_max_platform_handles[i]); | 165 all_max_platform_handles[i]); |
166 #endif | 166 #endif |
167 } else { | 167 } else { |
168 // Nothing to do on failure, since |buffer_| was cleared, and | 168 // Nothing to do on failure, since |buffer_| was cleared, and |
169 // |kTypeUnknown| is zero. The handle was simply closed. | 169 // |Type::UNKNOWN| is zero. The handle was simply closed. |
170 LOG(ERROR) << "Failed to serialize handle to remote message pipe"; | 170 LOG(ERROR) << "Failed to serialize handle to remote message pipe"; |
171 } | 171 } |
172 | 172 |
173 current_offset += MessageInTransit::RoundUpMessageAlignment(actual_size); | 173 current_offset += MessageInTransit::RoundUpMessageAlignment(actual_size); |
174 DCHECK_LE(current_offset, estimated_size); | 174 DCHECK_LE(current_offset, estimated_size); |
175 DCHECK_LE(platform_handles_ ? platform_handles_->size() : 0, | 175 DCHECK_LE(platform_handles_ ? platform_handles_->size() : 0, |
176 estimated_num_platform_handles); | 176 estimated_num_platform_handles); |
177 } | 177 } |
178 | 178 |
179 if (platform_handles_ && platform_handles_->size() > 0) { | 179 if (platform_handles_ && platform_handles_->size() > 0) { |
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
334 const void* source = static_cast<const char*>(buffer) + offset; | 334 const void* source = static_cast<const char*>(buffer) + offset; |
335 (*dispatchers)[i] = Dispatcher::TransportDataAccess::Deserialize( | 335 (*dispatchers)[i] = Dispatcher::TransportDataAccess::Deserialize( |
336 channel, handle_table[i].type, source, size, platform_handles.get()); | 336 channel, handle_table[i].type, source, size, platform_handles.get()); |
337 } | 337 } |
338 | 338 |
339 return dispatchers.Pass(); | 339 return dispatchers.Pass(); |
340 } | 340 } |
341 | 341 |
342 } // namespace system | 342 } // namespace system |
343 } // namespace mojo | 343 } // namespace mojo |
OLD | NEW |