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); |