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 "chrome/app/close_handle_hook_win.h" | 5 #include "chrome/app/close_handle_hook_win.h" |
6 | 6 |
7 #include <Windows.h> | 7 #include <Windows.h> |
8 #include <psapi.h> | 8 #include <psapi.h> |
9 | 9 |
10 #include <vector> | 10 #include <vector> |
(...skipping 19 matching lines...) Expand all Loading... | |
30 DWORD options); | 30 DWORD options); |
31 | 31 |
32 CloseHandleType g_close_function = NULL; | 32 CloseHandleType g_close_function = NULL; |
33 DuplicateHandleType g_duplicate_function = NULL; | 33 DuplicateHandleType g_duplicate_function = NULL; |
34 | 34 |
35 // The entry point for CloseHandle interception. This function notifies the | 35 // The entry point for CloseHandle interception. This function notifies the |
36 // verifier about the handle that is being closed, and calls the original | 36 // verifier about the handle that is being closed, and calls the original |
37 // function. | 37 // function. |
38 BOOL WINAPI CloseHandleHook(HANDLE handle) { | 38 BOOL WINAPI CloseHandleHook(HANDLE handle) { |
39 base::win::OnHandleBeingClosed(handle); | 39 base::win::OnHandleBeingClosed(handle); |
40 return g_close_function(handle); | 40 BOOL result = g_close_function(handle); |
41 // Check for CloseHandle failures. | |
42 // urlmon closes a handle that is NULL so we can't fail on that. | |
43 // Also CloseHandle() under a debugger only throws an exception on handles | |
44 // that are neither NULL nor INVALID_HANDLE_VALUE. | |
45 DPCHECK(result || handle == NULL || handle == INVALID_HANDLE_VALUE); | |
rvargas (doing something else)
2015/09/15 18:08:04
This seems like a weird place to looks for close f
| |
46 return result; | |
41 } | 47 } |
42 | 48 |
43 BOOL WINAPI DuplicateHandleHook(HANDLE source_process, | 49 BOOL WINAPI DuplicateHandleHook(HANDLE source_process, |
44 HANDLE source_handle, | 50 HANDLE source_handle, |
45 HANDLE target_process, | 51 HANDLE target_process, |
46 HANDLE* target_handle, | 52 HANDLE* target_handle, |
47 DWORD desired_access, | 53 DWORD desired_access, |
48 BOOL inherit_handle, | 54 BOOL inherit_handle, |
49 DWORD options) { | 55 DWORD options) { |
50 if ((options & DUPLICATE_CLOSE_SOURCE) && | 56 if ((options & DUPLICATE_CLOSE_SOURCE) && |
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
274 // threads attempting to call CloseHandle. | 280 // threads attempting to call CloseHandle. |
275 hooks->AddEATPatch(); | 281 hooks->AddEATPatch(); |
276 PatchLoadedModules(hooks); | 282 PatchLoadedModules(hooks); |
277 } | 283 } |
278 } | 284 } |
279 | 285 |
280 void RemoveHandleHooks() { | 286 void RemoveHandleHooks() { |
281 // We are partching all loaded modules without forcing them to stay in memory, | 287 // We are partching all loaded modules without forcing them to stay in memory, |
282 // removing patches is not safe. | 288 // removing patches is not safe. |
283 } | 289 } |
OLD | NEW |