OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "base/debug/close_handle_hook_win.h" | 5 #include "base/debug/close_handle_hook_win.h" |
6 | 6 |
7 #include <Windows.h> | 7 #include <Windows.h> |
8 #include <psapi.h> | 8 #include <psapi.h> |
9 #include <stddef.h> | 9 #include <stddef.h> |
10 | 10 |
11 #include <algorithm> | 11 #include <algorithm> |
12 #include <vector> | 12 #include <vector> |
13 | 13 |
14 #include "base/lazy_instance.h" | 14 #include "base/lazy_instance.h" |
15 #include "base/macros.h" | 15 #include "base/macros.h" |
16 #include "base/memory/scoped_ptr.h" | 16 #include "base/memory/scoped_ptr.h" |
17 #include "base/win/iat_patch_function.h" | 17 #include "base/win/iat_patch_function.h" |
18 #include "base/win/pe_image.h" | 18 #include "base/win/pe_image.h" |
19 #include "base/win/scoped_handle.h" | 19 #include "base/win/scoped_handle.h" |
20 #include "base/win/windows_version.h" | |
21 #include "build/build_config.h" | 20 #include "build/build_config.h" |
22 | 21 |
23 namespace { | 22 namespace { |
24 | 23 |
25 typedef BOOL (WINAPI* CloseHandleType) (HANDLE handle); | 24 typedef BOOL (WINAPI* CloseHandleType) (HANDLE handle); |
26 | 25 |
27 typedef BOOL (WINAPI* DuplicateHandleType)(HANDLE source_process, | 26 typedef BOOL (WINAPI* DuplicateHandleType)(HANDLE source_process, |
28 HANDLE source_handle, | 27 HANDLE source_handle, |
29 HANDLE target_process, | 28 HANDLE target_process, |
30 HANDLE* target_handle, | 29 HANDLE* target_handle, |
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
253 returned = std::min(kSize, returned); | 252 returned = std::min(kSize, returned); |
254 | 253 |
255 for (DWORD current = 0; current < returned; current++) { | 254 for (DWORD current = 0; current < returned; current++) { |
256 hooks->AddIATPatch(modules[current]); | 255 hooks->AddIATPatch(modules[current]); |
257 } | 256 } |
258 } | 257 } |
259 | 258 |
260 } // namespace | 259 } // namespace |
261 | 260 |
262 void InstallHandleHooks() { | 261 void InstallHandleHooks() { |
263 #if !defined(DISABLE_HANDLE_VERIFIER_HOOKS) | |
264 #if defined(_DEBUG) | |
265 // Handle hooks cause shutdown asserts in Debug on Windows 7. crbug.com/571304 | |
266 if (base::win::GetVersion() < base::win::VERSION_WIN8) | |
267 return; | |
268 #endif | |
269 HandleHooks* hooks = g_hooks.Pointer(); | 262 HandleHooks* hooks = g_hooks.Pointer(); |
270 | 263 |
271 // Performing EAT interception first is safer in the presence of other | 264 // Performing EAT interception first is safer in the presence of other |
272 // threads attempting to call CloseHandle. | 265 // threads attempting to call CloseHandle. |
273 hooks->AddEATPatch(); | 266 hooks->AddEATPatch(); |
274 PatchLoadedModules(hooks); | 267 PatchLoadedModules(hooks); |
275 #endif | |
276 } | 268 } |
277 | 269 |
278 void RemoveHandleHooks() { | 270 void RemoveHandleHooks() { |
279 // We are partching all loaded modules without forcing them to stay in memory, | 271 // We are partching all loaded modules without forcing them to stay in memory, |
280 // removing patches is not safe. | 272 // removing patches is not safe. |
281 } | 273 } |
282 | 274 |
283 } // namespace debug | 275 } // namespace debug |
284 } // namespace base | 276 } // namespace base |
OLD | NEW |