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

Unified Diff: base/win/scoped_handle.cc

Issue 1772343007: Two HandleVerifier thread safety fixes. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 9 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 c429375b9cbb4a9a373508eb574b5e68627cc605..65b5b74762397418ee7fcfefb542846b27638a66 100644
--- a/base/win/scoped_handle.cc
+++ b/base/win/scoped_handle.cc
@@ -117,6 +117,8 @@ ActiveVerifier* ActiveVerifier::Get() {
void ActiveVerifier::InstallVerifier() {
#if defined(COMPONENT_BUILD)
AutoNativeLock lock(g_lock.Get());
+ if (g_active_verifier)
+ return;
g_active_verifier = new ActiveVerifier(true);
#else
// If you are reading this, wondering why your process seems deadlocked, take
@@ -128,17 +130,34 @@ void ActiveVerifier::InstallVerifier() {
reinterpret_cast<GetHandleVerifierFn>(::GetProcAddress(
main_module, "GetHandleVerifier"));
+ // This should only happen if running in a DLL is linked with base but the
+ // hosting EXE is not. In this case, create an ActiveVerifier for the current
+ // module but leave it disabled.
if (!get_handle_verifier) {
g_active_verifier = new ActiveVerifier(false);
return;
}
- ActiveVerifier* verifier =
+ // Check if in the main module.
+ if (get_handle_verifier == GetHandleVerifier) {
+ AutoNativeLock lock(g_lock.Get());
+ if (g_active_verifier)
+ return;
+ g_active_verifier = new ActiveVerifier(true);
+ return;
+ }
+
+ ActiveVerifier* main_module_verifier =
reinterpret_cast<ActiveVerifier*>(get_handle_verifier());
+ // Main module should always on-demand create a verifier.
+ DCHECK(main_module_verifier);
+
// 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);
+ if (g_active_verifier)
scottmg 2016/03/10 20:31:26 Maybe an extra comment here describing what we dis
Will Harris 2016/03/10 21:08:45 Done.
+ return;
+ g_active_verifier = main_module_verifier;
#endif
}
@@ -221,7 +240,7 @@ void ActiveVerifier::OnHandleBeingClosed(HANDLE handle) {
} // namespace
void* GetHandleVerifier() {
- return g_active_verifier;
+ return ActiveVerifier::Get();
}
namespace base {
« 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