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

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: Reduced scope of changes to only deal with valid handles. 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 | « 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 2ebef320bb8b143d4f2944ac87f3afbbc4ef8c69..1a6a54e757574b17b272768c1506caa26a544cbb 100644
--- a/base/win/scoped_handle.cc
+++ b/base/win/scoped_handle.cc
@@ -152,6 +152,20 @@ 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.
+ if (!::SetHandleInformation(handle, HANDLE_FLAG_PROTECT_FROM_CLOSE,
+ HANDLE_FLAG_PROTECT_FROM_CLOSE)) {
+ DWORD error = GetLastError();
+ // Even our unittests provide invalid/fabricated handles. Reducing scope
+ // of change to only deal with valid handles.
+ // TODO(shrikant): If this feature has to be permanent then decide right way
+ // for unit test ScopedProcessHandleInformation.
+ if (error != ERROR_INVALID_HANDLE) {
cpu_(ooo_6.6-7.5) 2015/05/08 02:45:18 what other error would SetHandleInformation could
+ base::debug::Alias(&error);
+ CHECK(false);
+ }
+ }
+
// Grab the thread id before the lock.
DWORD thread_id = GetCurrentThreadId();
@@ -172,6 +186,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 | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698