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

Unified Diff: base/win/scoped_handle.cc

Issue 1141793003: Update from https://crrev.com/329939 (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 7 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/win/resource_util.h ('k') | base/win/startup_information.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/win/scoped_handle.cc
diff --git a/base/win/scoped_handle.cc b/base/win/scoped_handle.cc
index 33a8aa5c743b7b27eab6349fa1f0ee953dca6909..ce944e43b9fe3fb30a7b699863efeb9ab0c8ee13 100644
--- a/base/win/scoped_handle.cc
+++ b/base/win/scoped_handle.cc
@@ -132,10 +132,6 @@ void ActiveVerifier::InstallVerifier() {
// This lock only protects against races in this module, which is fine.
AutoNativeLock lock(g_lock.Get());
g_active_verifier = verifier ? verifier : new ActiveVerifier(true);
-
- // TODO(shrikant): Enable handle verifier after figuring out
- // AppContainer/DuplicateHandle error.
- g_active_verifier->Disable();
#endif
}
@@ -156,6 +152,12 @@ void ActiveVerifier::StartTracking(HANDLE handle, const void* owner,
if (!enabled_)
return;
+ // Idea here is to make our handles non-closable until we close it ourselves.
+ // Handles provided could be totally fabricated especially through our
+ // unittest, we are ignoring that for now by not checking return value.
+ ::SetHandleInformation(handle, HANDLE_FLAG_PROTECT_FROM_CLOSE,
+ HANDLE_FLAG_PROTECT_FROM_CLOSE);
+
// Grab the thread id before the lock.
DWORD thread_id = GetCurrentThreadId();
@@ -176,6 +178,15 @@ void ActiveVerifier::StopTracking(HANDLE handle, const void* owner,
if (!enabled_)
return;
+ // We expect handle to be protected till this point.
+ DWORD flags = 0;
+ if (::GetHandleInformation(handle, &flags)) {
+ CHECK_NE(0U, (flags & HANDLE_FLAG_PROTECT_FROM_CLOSE));
+
+ // Unprotect handle so that it could be closed.
+ ::SetHandleInformation(handle, HANDLE_FLAG_PROTECT_FROM_CLOSE, 0);
+ }
+
AutoNativeLock lock(*lock_);
HandleMap::iterator i = map_.find(handle);
if (i == map_.end())
« no previous file with comments | « base/win/resource_util.h ('k') | base/win/startup_information.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698