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

Side by Side Diff: base/win/scoped_handle.cc

Issue 1977833003: Add a buildflag to use the handle verifier in a per module mode. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix the GN config. Created 4 years, 6 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 unified diff | Download patch
« no previous file with comments | « base/win/BUILD.gn ('k') | base/win/scoped_handle_test_dll.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/win/scoped_handle.h" 5 #include "base/win/scoped_handle.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <unordered_map> 9 #include <unordered_map>
10 10
11 #include "base/debug/alias.h" 11 #include "base/debug/alias.h"
12 #include "base/debug/stack_trace.h" 12 #include "base/debug/stack_trace.h"
13 #include "base/hash.h" 13 #include "base/hash.h"
14 #include "base/lazy_instance.h" 14 #include "base/lazy_instance.h"
15 #include "base/logging.h" 15 #include "base/logging.h"
16 #include "base/macros.h" 16 #include "base/macros.h"
17 #include "base/synchronization/lock_impl.h" 17 #include "base/synchronization/lock_impl.h"
18 #include "base/threading/thread_local.h" 18 #include "base/threading/thread_local.h"
19 #include "base/win/base_features.h"
19 #include "base/win/current_module.h" 20 #include "base/win/current_module.h"
20 21
21 extern "C" { 22 extern "C" {
22 __declspec(dllexport) void* GetHandleVerifier(); 23 __declspec(dllexport) void* GetHandleVerifier();
23 typedef void* (*GetHandleVerifierFn)(); 24 typedef void* (*GetHandleVerifierFn)();
24 } 25 }
25 26
26 namespace { 27 namespace {
27 28
28 struct HandleHash { 29 struct HandleHash {
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 // Another thread in this module might be trying to assign the global 125 // Another thread in this module might be trying to assign the global
125 // verifier, so check that within the lock here. 126 // verifier, so check that within the lock here.
126 if (g_active_verifier) 127 if (g_active_verifier)
127 return; 128 return;
128 g_active_verifier = 129 g_active_verifier =
129 existing_verifier ? existing_verifier : new ActiveVerifier(enabled); 130 existing_verifier ? existing_verifier : new ActiveVerifier(enabled);
130 } 131 }
131 132
132 // static 133 // static
133 void ActiveVerifier::InstallVerifier() { 134 void ActiveVerifier::InstallVerifier() {
134 #if defined(COMPONENT_BUILD) 135 #if BUILDFLAG(SINGLE_MODULE_MODE_HANDLE_VERIFIER)
135 // Component build has one Active Verifier per module. 136 // Component build has one Active Verifier per module.
136 ThreadSafeAssignOrCreateActiveVerifier(nullptr, true); 137 ThreadSafeAssignOrCreateActiveVerifier(nullptr, true);
137 #else 138 #else
138 // If you are reading this, wondering why your process seems deadlocked, take 139 // If you are reading this, wondering why your process seems deadlocked, take
139 // a look at your DllMain code and remove things that should not be done 140 // a look at your DllMain code and remove things that should not be done
140 // there, like doing whatever gave you that nice windows handle you are trying 141 // there, like doing whatever gave you that nice windows handle you are trying
141 // to store in a ScopedHandle. 142 // to store in a ScopedHandle.
142 HMODULE main_module = ::GetModuleHandle(NULL); 143 HMODULE main_module = ::GetModuleHandle(NULL);
143 GetHandleVerifierFn get_handle_verifier = 144 GetHandleVerifierFn get_handle_verifier =
144 reinterpret_cast<GetHandleVerifierFn>(::GetProcAddress( 145 reinterpret_cast<GetHandleVerifierFn>(::GetProcAddress(
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
281 void OnHandleBeingClosed(HANDLE handle) { 282 void OnHandleBeingClosed(HANDLE handle) {
282 return ActiveVerifier::Get()->OnHandleBeingClosed(handle); 283 return ActiveVerifier::Get()->OnHandleBeingClosed(handle);
283 } 284 }
284 285
285 HMODULE GetHandleVerifierModuleForTesting() { 286 HMODULE GetHandleVerifierModuleForTesting() {
286 return g_active_verifier->GetModule(); 287 return g_active_verifier->GetModule();
287 } 288 }
288 289
289 } // namespace win 290 } // namespace win
290 } // namespace base 291 } // namespace base
OLDNEW
« no previous file with comments | « base/win/BUILD.gn ('k') | base/win/scoped_handle_test_dll.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698