| 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/current_module.h" | 19 #include "base/win/current_module.h" |
| 20 | 20 |
| 21 #if BUILDFLAG(ENABLE_HANDLE_VERIFIER) |
| 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 { |
| 29 size_t operator()(const HANDLE& handle) const { | 30 size_t operator()(const HANDLE& handle) const { |
| 30 char buffer[sizeof(handle)]; | 31 char buffer[sizeof(handle)]; |
| (...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 247 HMODULE ActiveVerifier::GetModule() const { | 248 HMODULE ActiveVerifier::GetModule() const { |
| 248 return CURRENT_MODULE(); | 249 return CURRENT_MODULE(); |
| 249 } | 250 } |
| 250 | 251 |
| 251 } // namespace | 252 } // namespace |
| 252 | 253 |
| 253 void* GetHandleVerifier() { | 254 void* GetHandleVerifier() { |
| 254 return ActiveVerifier::Get(); | 255 return ActiveVerifier::Get(); |
| 255 } | 256 } |
| 256 | 257 |
| 258 #endif // BUILDFLAG(ENABLE_HANDLE_VERIFIER) |
| 259 |
| 257 namespace base { | 260 namespace base { |
| 258 namespace win { | 261 namespace win { |
| 259 | 262 |
| 260 // Static. | 263 // Static. |
| 261 bool HandleTraits::CloseHandle(HANDLE handle) { | 264 bool HandleTraits::CloseHandle(HANDLE handle) { |
| 265 #if BUILDFLAG(ENABLE_HANDLE_VERIFIER) |
| 262 return ActiveVerifier::Get()->CloseHandle(handle); | 266 return ActiveVerifier::Get()->CloseHandle(handle); |
| 267 #else // BUILDFLAG(ENABLE_HANDLE_VERIFIER) |
| 268 if (!::CloseHandle(handle)) |
| 269 CHECK(false); |
| 270 return true; |
| 271 #endif |
| 263 } | 272 } |
| 264 | 273 |
| 274 void OnHandleBeingClosed(HANDLE handle) { |
| 275 #if BUILDFLAG(ENABLE_HANDLE_VERIFIER) |
| 276 return ActiveVerifier::Get()->OnHandleBeingClosed(handle); |
| 277 #endif |
| 278 } |
| 279 |
| 280 #if BUILDFLAG(ENABLE_HANDLE_VERIFIER) |
| 265 // Static. | 281 // Static. |
| 266 void VerifierTraits::StartTracking(HANDLE handle, const void* owner, | 282 void VerifierTraits::StartTracking(HANDLE handle, const void* owner, |
| 267 const void* pc1, const void* pc2) { | 283 const void* pc1, const void* pc2) { |
| 268 return ActiveVerifier::Get()->StartTracking(handle, owner, pc1, pc2); | 284 return ActiveVerifier::Get()->StartTracking(handle, owner, pc1, pc2); |
| 269 } | 285 } |
| 270 | 286 |
| 271 // Static. | 287 // Static. |
| 272 void VerifierTraits::StopTracking(HANDLE handle, const void* owner, | 288 void VerifierTraits::StopTracking(HANDLE handle, const void* owner, |
| 273 const void* pc1, const void* pc2) { | 289 const void* pc1, const void* pc2) { |
| 274 return ActiveVerifier::Get()->StopTracking(handle, owner, pc1, pc2); | 290 return ActiveVerifier::Get()->StopTracking(handle, owner, pc1, pc2); |
| 275 } | 291 } |
| 276 | 292 |
| 277 void DisableHandleVerifier() { | |
| 278 return ActiveVerifier::Get()->Disable(); | |
| 279 } | |
| 280 | |
| 281 void OnHandleBeingClosed(HANDLE handle) { | |
| 282 return ActiveVerifier::Get()->OnHandleBeingClosed(handle); | |
| 283 } | |
| 284 | |
| 285 HMODULE GetHandleVerifierModuleForTesting() { | 293 HMODULE GetHandleVerifierModuleForTesting() { |
| 286 return g_active_verifier->GetModule(); | 294 return g_active_verifier->GetModule(); |
| 287 } | 295 } |
| 296 #endif // BUILDFLAG(ENABLE_HANDLE_VERIFIER) |
| 297 |
| 298 void DisableHandleVerifier() { |
| 299 #if BUILDFLAG(ENABLE_HANDLE_VERIFIER) |
| 300 return ActiveVerifier::Get()->Disable(); |
| 301 #endif |
| 302 } |
| 288 | 303 |
| 289 } // namespace win | 304 } // namespace win |
| 290 } // namespace base | 305 } // namespace base |
| OLD | NEW |