Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(244)

Side by Side Diff: chrome/app/close_handle_hook_win.cc

Issue 1343873002: Check for CloseHandle failures even when not debugging (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 DCHECK(result || handle == NULL || handle == INVALID_HANDLE_VALUE);
grt (UTC plus 2) 2015/09/15 14:08:07 nit: DPCHECK so that the last error code is nicely
brucedawson 2015/09/15 16:49:27 Done.
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
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 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698