| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "sandbox/win/src/handle_table.h" | 5 #include "sandbox/win/src/handle_table.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <cstdlib> | 8 #include <cstdlib> |
| 9 | 9 |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 57 handle_info_buffer_.resize(0); | 57 handle_info_buffer_.resize(0); |
| 58 return; | 58 return; |
| 59 } | 59 } |
| 60 | 60 |
| 61 // Sort it to make process lookups faster. | 61 // Sort it to make process lookups faster. |
| 62 std::sort(handle_info_internal()->Information, | 62 std::sort(handle_info_internal()->Information, |
| 63 handle_info_internal()->Information + | 63 handle_info_internal()->Information + |
| 64 handle_info_internal()->NumberOfHandles, CompareHandleEntries); | 64 handle_info_internal()->NumberOfHandles, CompareHandleEntries); |
| 65 } | 65 } |
| 66 | 66 |
| 67 HandleTable::~HandleTable() { |
| 68 } |
| 69 |
| 67 HandleTable::Iterator HandleTable::HandlesForProcess(ULONG process_id) const { | 70 HandleTable::Iterator HandleTable::HandlesForProcess(ULONG process_id) const { |
| 68 SYSTEM_HANDLE_INFORMATION key; | 71 SYSTEM_HANDLE_INFORMATION key; |
| 69 key.ProcessId = static_cast<USHORT>(process_id); | 72 key.ProcessId = static_cast<USHORT>(process_id); |
| 70 | 73 |
| 71 const SYSTEM_HANDLE_INFORMATION* start = handle_info()->Information; | 74 const SYSTEM_HANDLE_INFORMATION* start = handle_info()->Information; |
| 72 const SYSTEM_HANDLE_INFORMATION* finish = | 75 const SYSTEM_HANDLE_INFORMATION* finish = |
| 73 &handle_info()->Information[handle_info()->NumberOfHandles]; | 76 &handle_info()->Information[handle_info()->NumberOfHandles]; |
| 74 | 77 |
| 75 start = std::lower_bound(start, finish, key, CompareHandleEntries); | 78 start = std::lower_bound(start, finish, key, CompareHandleEntries); |
| 76 if (start->ProcessId != process_id) | 79 if (start->ProcessId != process_id) |
| 77 return Iterator(*this, finish, finish); | 80 return Iterator(*this, finish, finish); |
| 78 finish = std::upper_bound(start, finish, key, CompareHandleEntries); | 81 finish = std::upper_bound(start, finish, key, CompareHandleEntries); |
| 79 return Iterator(*this, start, finish); | 82 return Iterator(*this, start, finish); |
| 80 } | 83 } |
| 81 | 84 |
| 82 HandleTable::HandleEntry::HandleEntry( | 85 HandleTable::HandleEntry::HandleEntry( |
| 83 const SYSTEM_HANDLE_INFORMATION* handle_info_entry) | 86 const SYSTEM_HANDLE_INFORMATION* handle_info_entry) |
| 84 : handle_entry_(handle_info_entry), last_entry_(0) { | 87 : handle_entry_(handle_info_entry), last_entry_(0) { |
| 85 } | 88 } |
| 86 | 89 |
| 90 HandleTable::HandleEntry::~HandleEntry() { |
| 91 } |
| 92 |
| 87 void HandleTable::HandleEntry::UpdateInfo(UpdateType flag) { | 93 void HandleTable::HandleEntry::UpdateInfo(UpdateType flag) { |
| 88 static NtQueryObject QueryObject = NULL; | 94 static NtQueryObject QueryObject = NULL; |
| 89 if (!QueryObject) | 95 if (!QueryObject) |
| 90 ResolveNTFunctionPtr("NtQueryObject", &QueryObject); | 96 ResolveNTFunctionPtr("NtQueryObject", &QueryObject); |
| 91 | 97 |
| 92 NTSTATUS result; | 98 NTSTATUS result; |
| 93 | 99 |
| 94 // Always update the basic type info, but grab the names as needed. | 100 // Always update the basic type info, but grab the names as needed. |
| 95 if (needs_info_update()) { | 101 if (needs_info_update()) { |
| 96 handle_name_.clear(); | 102 handle_name_.clear(); |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 174 const SYSTEM_HANDLE_INFORMATION* start, | 180 const SYSTEM_HANDLE_INFORMATION* start, |
| 175 const SYSTEM_HANDLE_INFORMATION* end) | 181 const SYSTEM_HANDLE_INFORMATION* end) |
| 176 : table_(table), current_(start), end_(end) { | 182 : table_(table), current_(start), end_(end) { |
| 177 } | 183 } |
| 178 | 184 |
| 179 HandleTable::Iterator::Iterator(const Iterator& it) | 185 HandleTable::Iterator::Iterator(const Iterator& it) |
| 180 : table_(it.table_), current_(it.current_.handle_entry_), end_(it.end_) { | 186 : table_(it.table_), current_(it.current_.handle_entry_), end_(it.end_) { |
| 181 } | 187 } |
| 182 | 188 |
| 183 } // namespace sandbox | 189 } // namespace sandbox |
| OLD | NEW |