Chromium Code Reviews| 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 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "mojo/edk/system/configuration.h" | 10 #include "mojo/edk/system/configuration.h" |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 74 return std::make_pair(AddDispatcherNoSizeCheck(dispatcher0), | 74 return std::make_pair(AddDispatcherNoSizeCheck(dispatcher0), |
| 75 AddDispatcherNoSizeCheck(dispatcher1)); | 75 AddDispatcherNoSizeCheck(dispatcher1)); |
| 76 } | 76 } |
| 77 | 77 |
| 78 bool HandleTable::AddDispatcherVector(const DispatcherVector& dispatchers, | 78 bool HandleTable::AddDispatcherVector(const DispatcherVector& dispatchers, |
| 79 MojoHandle* handles) { | 79 MojoHandle* handles) { |
| 80 size_t max_message_num_handles = GetConfiguration().max_message_num_handles; | 80 size_t max_message_num_handles = GetConfiguration().max_message_num_handles; |
| 81 size_t max_handle_table_size = GetConfiguration().max_handle_table_size; | 81 size_t max_handle_table_size = GetConfiguration().max_handle_table_size; |
| 82 | 82 |
| 83 DCHECK_LE(dispatchers.size(), max_message_num_handles); | 83 DCHECK_LE(dispatchers.size(), max_message_num_handles); |
| 84 DCHECK(handles); | 84 CHECK(handles); |
|
jam
2015/12/03 03:42:36
for here and below, there were death tests that ex
| |
| 85 DCHECK_LT( | 85 DCHECK_LT( |
| 86 static_cast<uint64_t>(max_handle_table_size) + max_message_num_handles, | 86 static_cast<uint64_t>(max_handle_table_size) + max_message_num_handles, |
| 87 std::numeric_limits<size_t>::max()) | 87 std::numeric_limits<size_t>::max()) |
| 88 << "Addition may overflow"; | 88 << "Addition may overflow"; |
| 89 | 89 |
| 90 if (handle_to_entry_map_.size() + dispatchers.size() > max_handle_table_size) | 90 if (handle_to_entry_map_.size() + dispatchers.size() > max_handle_table_size) |
| 91 return false; | 91 return false; |
| 92 | 92 |
| 93 for (size_t i = 0; i < dispatchers.size(); i++) { | 93 for (size_t i = 0; i < dispatchers.size(); i++) { |
| 94 if (dispatchers[i]) { | 94 if (dispatchers[i]) { |
| 95 handles[i] = AddDispatcherNoSizeCheck(dispatchers[i]); | 95 handles[i] = AddDispatcherNoSizeCheck(dispatchers[i]); |
| 96 } else { | 96 } else { |
| 97 LOG(WARNING) << "Invalid dispatcher at index " << i; | 97 LOG(WARNING) << "Invalid dispatcher at index " << i; |
| 98 handles[i] = MOJO_HANDLE_INVALID; | 98 handles[i] = MOJO_HANDLE_INVALID; |
| 99 } | 99 } |
| 100 } | 100 } |
| 101 return true; | 101 return true; |
| 102 } | 102 } |
| 103 | 103 |
| 104 MojoResult HandleTable::MarkBusyAndStartTransport( | 104 MojoResult HandleTable::MarkBusyAndStartTransport( |
| 105 MojoHandle disallowed_handle, | 105 MojoHandle disallowed_handle, |
| 106 const MojoHandle* handles, | 106 const MojoHandle* handles, |
| 107 uint32_t num_handles, | 107 uint32_t num_handles, |
| 108 std::vector<DispatcherTransport>* transports) { | 108 std::vector<DispatcherTransport>* transports) { |
| 109 DCHECK_NE(disallowed_handle, MOJO_HANDLE_INVALID); | 109 DCHECK_NE(disallowed_handle, MOJO_HANDLE_INVALID); |
| 110 DCHECK(handles); | 110 CHECK(handles); |
| 111 DCHECK_LE(num_handles, GetConfiguration().max_message_num_handles); | 111 DCHECK_LE(num_handles, GetConfiguration().max_message_num_handles); |
| 112 DCHECK(transports); | 112 DCHECK(transports); |
| 113 DCHECK_EQ(transports->size(), num_handles); | 113 DCHECK_EQ(transports->size(), num_handles); |
| 114 | 114 |
| 115 std::vector<Entry*> entries(num_handles); | 115 std::vector<Entry*> entries(num_handles); |
| 116 | 116 |
| 117 // First verify all the handles and get their dispatchers. | 117 // First verify all the handles and get their dispatchers. |
| 118 uint32_t i; | 118 uint32_t i; |
| 119 MojoResult error_result = MOJO_RESULT_INTERNAL; | 119 MojoResult error_result = MOJO_RESULT_INTERNAL; |
| 120 for (i = 0; i < num_handles; i++) { | 120 for (i = 0; i < num_handles; i++) { |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 234 for (uint32_t i = 0; i < num_handles; i++) { | 234 for (uint32_t i = 0; i < num_handles; i++) { |
| 235 HandleToEntryMap::iterator it = handle_to_entry_map_.find(handles[i]); | 235 HandleToEntryMap::iterator it = handle_to_entry_map_.find(handles[i]); |
| 236 DCHECK(it != handle_to_entry_map_.end()); | 236 DCHECK(it != handle_to_entry_map_.end()); |
| 237 DCHECK(it->second.busy); | 237 DCHECK(it->second.busy); |
| 238 it->second.busy = false; | 238 it->second.busy = false; |
| 239 } | 239 } |
| 240 } | 240 } |
| 241 | 241 |
| 242 } // namespace edk | 242 } // namespace edk |
| 243 } // namespace mojo | 243 } // namespace mojo |
| OLD | NEW |