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

Unified Diff: base/win/scoped_handle.cc

Issue 1113063004: Add HANDLE_FLAG_PROTECT_FROM_CLOSE flag to Tracked/ScopedHandle. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Removed empty line Created 5 years, 8 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 | « no previous file | no next file » | 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..bc1858d4756b1e9c203896bc0a40b8de9afe20d7 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,10 @@ 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.
+ ::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 +176,15 @@ void ActiveVerifier::StopTracking(HANDLE handle, const void* owner,
if (!enabled_)
return;
+ // We expect handle to be protected till this point.
+ DWORD flags = 0;
+ ::GetHandleInformation(handle, &flags);
+ if (!(flags & HANDLE_FLAG_PROTECT_FROM_CLOSE))
grt (UTC plus 2) 2015/05/01 13:26:14 minor style nit: check what you care about rather
Shrikant Kelkar 2015/05/01 17:48:41 Done.
+ CHECK(FALSE);
+
+ // 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())
@@ -203,6 +212,15 @@ void ActiveVerifier::OnHandleBeingClosed(HANDLE handle) {
if (i == map_.end())
return;
+ // Mask out all protected handle close attempts. This will give us
+ // idea if protecting handle has any effect or not.
+ // TODO(shrikant): Remove this code once we see results of the above
+ // mentioned experiment.
+ DWORD flags = 0;
+ ::GetHandleInformation(handle, &flags);
+ if (flags & HANDLE_FLAG_PROTECT_FROM_CLOSE)
+ return;
+
Info other = i->second;
base::debug::Alias(&other);
CHECK(false);
« 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