| 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/handle_table.h" | 5 #include "mojo/edk/system/handle_table.h" |
| 6 | 6 |
| 7 #include <limits> | 7 #include <limits> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 76 std::pair<MojoHandle, MojoHandle> HandleTable::AddHandlePair(Handle&& handle0, | 76 std::pair<MojoHandle, MojoHandle> HandleTable::AddHandlePair(Handle&& handle0, |
| 77 Handle&& handle1) { | 77 Handle&& handle1) { |
| 78 DCHECK(handle0); | 78 DCHECK(handle0); |
| 79 DCHECK(handle1); | 79 DCHECK(handle1); |
| 80 return (handle_to_entry_map_.size() + 1u < max_handle_table_size_) | 80 return (handle_to_entry_map_.size() + 1u < max_handle_table_size_) |
| 81 ? std::make_pair(AddHandleNoSizeCheck(std::move(handle0)), | 81 ? std::make_pair(AddHandleNoSizeCheck(std::move(handle0)), |
| 82 AddHandleNoSizeCheck(std::move(handle1))) | 82 AddHandleNoSizeCheck(std::move(handle1))) |
| 83 : std::make_pair(MOJO_HANDLE_INVALID, MOJO_HANDLE_INVALID); | 83 : std::make_pair(MOJO_HANDLE_INVALID, MOJO_HANDLE_INVALID); |
| 84 } | 84 } |
| 85 | 85 |
| 86 bool HandleTable::AddHandleVector(HandleVector* handles, |
| 87 MojoHandle* handle_values) { |
| 88 size_t max_message_num_handles = GetConfiguration().max_message_num_handles; |
| 89 |
| 90 DCHECK(handles); |
| 91 DCHECK_LE(handles->size(), max_message_num_handles); |
| 92 DCHECK(handle_values); |
| 93 DCHECK_LT( |
| 94 static_cast<uint64_t>(max_handle_table_size_) + max_message_num_handles, |
| 95 std::numeric_limits<size_t>::max()) |
| 96 << "Addition may overflow"; |
| 97 |
| 98 if (handle_to_entry_map_.size() + handles->size() > max_handle_table_size_) |
| 99 return false; |
| 100 |
| 101 for (size_t i = 0; i < handles->size(); i++) { |
| 102 if (handles->at(i)) { |
| 103 handle_values[i] = AddHandleNoSizeCheck(std::move(handles->at(i))); |
| 104 } else { |
| 105 LOG(WARNING) << "Invalid dispatcher at index " << i; |
| 106 handle_values[i] = MOJO_HANDLE_INVALID; |
| 107 } |
| 108 } |
| 109 return true; |
| 110 } |
| 111 |
| 112 // TODO(vtl): Delete this. |
| 86 bool HandleTable::AddDispatcherVector(const DispatcherVector& dispatchers, | 113 bool HandleTable::AddDispatcherVector(const DispatcherVector& dispatchers, |
| 87 MojoHandle* handles) { | 114 MojoHandle* handles) { |
| 88 size_t max_message_num_handles = GetConfiguration().max_message_num_handles; | 115 size_t max_message_num_handles = GetConfiguration().max_message_num_handles; |
| 89 | 116 |
| 90 DCHECK_LE(dispatchers.size(), max_message_num_handles); | 117 DCHECK_LE(dispatchers.size(), max_message_num_handles); |
| 91 DCHECK(handles); | 118 DCHECK(handles); |
| 92 DCHECK_LT( | 119 DCHECK_LT( |
| 93 static_cast<uint64_t>(max_handle_table_size_) + max_message_num_handles, | 120 static_cast<uint64_t>(max_handle_table_size_) + max_message_num_handles, |
| 94 std::numeric_limits<size_t>::max()) | 121 std::numeric_limits<size_t>::max()) |
| 95 << "Addition may overflow"; | 122 << "Addition may overflow"; |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 240 for (uint32_t i = 0; i < num_handles; i++) { | 267 for (uint32_t i = 0; i < num_handles; i++) { |
| 241 HandleToEntryMap::iterator it = handle_to_entry_map_.find(handle_values[i]); | 268 HandleToEntryMap::iterator it = handle_to_entry_map_.find(handle_values[i]); |
| 242 DCHECK(it != handle_to_entry_map_.end()); | 269 DCHECK(it != handle_to_entry_map_.end()); |
| 243 DCHECK(it->second.busy); | 270 DCHECK(it->second.busy); |
| 244 it->second.busy = false; | 271 it->second.busy = false; |
| 245 } | 272 } |
| 246 } | 273 } |
| 247 | 274 |
| 248 } // namespace system | 275 } // namespace system |
| 249 } // namespace mojo | 276 } // namespace mojo |
| OLD | NEW |