| OLD | NEW |
| 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" | |
| 20 #include "base/win/current_module.h" | 19 #include "base/win/current_module.h" |
| 21 | 20 |
| 22 extern "C" { | 21 extern "C" { |
| 23 __declspec(dllexport) void* GetHandleVerifier(); | 22 __declspec(dllexport) void* GetHandleVerifier(); |
| 24 typedef void* (*GetHandleVerifierFn)(); | 23 typedef void* (*GetHandleVerifierFn)(); |
| 25 } | 24 } |
| 26 | 25 |
| 27 namespace { | 26 namespace { |
| 28 | 27 |
| 29 struct HandleHash { | 28 struct HandleHash { |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 125 // Another thread in this module might be trying to assign the global | 124 // Another thread in this module might be trying to assign the global |
| 126 // verifier, so check that within the lock here. | 125 // verifier, so check that within the lock here. |
| 127 if (g_active_verifier) | 126 if (g_active_verifier) |
| 128 return; | 127 return; |
| 129 g_active_verifier = | 128 g_active_verifier = |
| 130 existing_verifier ? existing_verifier : new ActiveVerifier(enabled); | 129 existing_verifier ? existing_verifier : new ActiveVerifier(enabled); |
| 131 } | 130 } |
| 132 | 131 |
| 133 // static | 132 // static |
| 134 void ActiveVerifier::InstallVerifier() { | 133 void ActiveVerifier::InstallVerifier() { |
| 135 #if BUILDFLAG(SINGLE_MODULE_MODE_HANDLE_VERIFIER) | 134 #if defined(COMPONENT_BUILD) |
| 136 // Component build has one Active Verifier per module. | 135 // Component build has one Active Verifier per module. |
| 137 ThreadSafeAssignOrCreateActiveVerifier(nullptr, true); | 136 ThreadSafeAssignOrCreateActiveVerifier(nullptr, true); |
| 138 #else | 137 #else |
| 139 // If you are reading this, wondering why your process seems deadlocked, take | 138 // If you are reading this, wondering why your process seems deadlocked, take |
| 140 // a look at your DllMain code and remove things that should not be done | 139 // a look at your DllMain code and remove things that should not be done |
| 141 // there, like doing whatever gave you that nice windows handle you are trying | 140 // there, like doing whatever gave you that nice windows handle you are trying |
| 142 // to store in a ScopedHandle. | 141 // to store in a ScopedHandle. |
| 143 HMODULE main_module = ::GetModuleHandle(NULL); | 142 HMODULE main_module = ::GetModuleHandle(NULL); |
| 144 GetHandleVerifierFn get_handle_verifier = | 143 GetHandleVerifierFn get_handle_verifier = |
| 145 reinterpret_cast<GetHandleVerifierFn>(::GetProcAddress( | 144 reinterpret_cast<GetHandleVerifierFn>(::GetProcAddress( |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 282 void OnHandleBeingClosed(HANDLE handle) { | 281 void OnHandleBeingClosed(HANDLE handle) { |
| 283 return ActiveVerifier::Get()->OnHandleBeingClosed(handle); | 282 return ActiveVerifier::Get()->OnHandleBeingClosed(handle); |
| 284 } | 283 } |
| 285 | 284 |
| 286 HMODULE GetHandleVerifierModuleForTesting() { | 285 HMODULE GetHandleVerifierModuleForTesting() { |
| 287 return g_active_verifier->GetModule(); | 286 return g_active_verifier->GetModule(); |
| 288 } | 287 } |
| 289 | 288 |
| 290 } // namespace win | 289 } // namespace win |
| 291 } // namespace base | 290 } // namespace base |
| OLD | NEW |