| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_closer_agent.h" | 5 #include "sandbox/win/src/handle_closer_agent.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "sandbox/win/src/nt_internals.h" | 8 #include "sandbox/win/src/nt_internals.h" |
| 9 #include "sandbox/win/src/win_utils.h" | 9 #include "sandbox/win/src/win_utils.h" |
| 10 | 10 |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 81 const size_t kHandleOffset = sizeof(HANDLE); | 81 const size_t kHandleOffset = sizeof(HANDLE); |
| 82 | 82 |
| 83 if (!::GetProcessHandleCount(::GetCurrentProcess(), &handle_count)) | 83 if (!::GetProcessHandleCount(::GetCurrentProcess(), &handle_count)) |
| 84 return false; | 84 return false; |
| 85 | 85 |
| 86 // Set up buffers for the type info and the name. | 86 // Set up buffers for the type info and the name. |
| 87 std::vector<BYTE> type_info_buffer(sizeof(OBJECT_TYPE_INFORMATION) + | 87 std::vector<BYTE> type_info_buffer(sizeof(OBJECT_TYPE_INFORMATION) + |
| 88 32 * sizeof(wchar_t)); | 88 32 * sizeof(wchar_t)); |
| 89 OBJECT_TYPE_INFORMATION* type_info = | 89 OBJECT_TYPE_INFORMATION* type_info = |
| 90 reinterpret_cast<OBJECT_TYPE_INFORMATION*>(&(type_info_buffer[0])); | 90 reinterpret_cast<OBJECT_TYPE_INFORMATION*>(&(type_info_buffer[0])); |
| 91 string16 handle_name; | 91 base::string16 handle_name; |
| 92 HANDLE handle = NULL; | 92 HANDLE handle = NULL; |
| 93 int invalid_count = 0; | 93 int invalid_count = 0; |
| 94 | 94 |
| 95 // Keep incrementing until we hit the number of handles reported by | 95 // Keep incrementing until we hit the number of handles reported by |
| 96 // GetProcessHandleCount(). If we hit a very long sequence of invalid | 96 // GetProcessHandleCount(). If we hit a very long sequence of invalid |
| 97 // handles we assume that we've run past the end of the table. | 97 // handles we assume that we've run past the end of the table. |
| 98 while (handle_count && invalid_count < kInvalidHandleThreshold) { | 98 while (handle_count && invalid_count < kInvalidHandleThreshold) { |
| 99 reinterpret_cast<size_t&>(handle) += kHandleOffset; | 99 reinterpret_cast<size_t&>(handle) += kHandleOffset; |
| 100 NTSTATUS rc; | 100 NTSTATUS rc; |
| 101 | 101 |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 136 return false; | 136 return false; |
| 137 if (!::CloseHandle(handle)) | 137 if (!::CloseHandle(handle)) |
| 138 return false; | 138 return false; |
| 139 } | 139 } |
| 140 } | 140 } |
| 141 | 141 |
| 142 return true; | 142 return true; |
| 143 } | 143 } |
| 144 | 144 |
| 145 } // namespace sandbox | 145 } // namespace sandbox |
| OLD | NEW |