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/location.h" | |
15 #include "base/logging.h" | 16 #include "base/logging.h" |
16 #include "base/macros.h" | 17 #include "base/macros.h" |
18 #include "base/process/memory.h" | |
17 #include "base/synchronization/lock_impl.h" | 19 #include "base/synchronization/lock_impl.h" |
18 #include "base/threading/thread_local.h" | 20 #include "base/threading/thread_local.h" |
19 | 21 |
20 extern "C" { | 22 extern "C" { |
21 __declspec(dllexport) void* GetHandleVerifier(); | 23 __declspec(dllexport) void* GetHandleVerifier(); |
22 typedef void* (*GetHandleVerifierFn)(); | 24 typedef void* (*GetHandleVerifierFn)(); |
23 } | 25 } |
24 | 26 |
25 namespace { | 27 namespace { |
26 | 28 |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
78 // The methods required by HandleTraits. They are virtual because we need to | 80 // The methods required by HandleTraits. They are virtual because we need to |
79 // forward the call execution to another module, instead of letting the | 81 // forward the call execution to another module, instead of letting the |
80 // compiler call the version that is linked in the current module. | 82 // compiler call the version that is linked in the current module. |
81 virtual bool CloseHandle(HANDLE handle); | 83 virtual bool CloseHandle(HANDLE handle); |
82 virtual void StartTracking(HANDLE handle, const void* owner, | 84 virtual void StartTracking(HANDLE handle, const void* owner, |
83 const void* pc1, const void* pc2); | 85 const void* pc1, const void* pc2); |
84 virtual void StopTracking(HANDLE handle, const void* owner, | 86 virtual void StopTracking(HANDLE handle, const void* owner, |
85 const void* pc1, const void* pc2); | 87 const void* pc1, const void* pc2); |
86 virtual void Disable(); | 88 virtual void Disable(); |
87 virtual void OnHandleBeingClosed(HANDLE handle); | 89 virtual void OnHandleBeingClosed(HANDLE handle); |
90 virtual bool GetCodeAddress(const void** pc) const; | |
88 | 91 |
89 private: | 92 private: |
90 ~ActiveVerifier(); // Not implemented. | 93 ~ActiveVerifier(); // Not implemented. |
91 | 94 |
92 static void InstallVerifier(); | 95 static void InstallVerifier(); |
93 | 96 |
94 base::debug::StackTrace creation_stack_; | 97 base::debug::StackTrace creation_stack_; |
95 bool enabled_; | 98 bool enabled_; |
96 base::ThreadLocalBoolean closing_; | 99 base::ThreadLocalBoolean closing_; |
97 NativeLock* lock_; | 100 NativeLock* lock_; |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
235 HandleMap::iterator i = map_.find(handle); | 238 HandleMap::iterator i = map_.find(handle); |
236 if (i == map_.end()) | 239 if (i == map_.end()) |
237 return; | 240 return; |
238 | 241 |
239 Info other = i->second; | 242 Info other = i->second; |
240 base::debug::Alias(&other); | 243 base::debug::Alias(&other); |
241 base::debug::Alias(&creation_stack_); | 244 base::debug::Alias(&creation_stack_); |
242 CHECK(false); // CloseHandle called on tracked handle. | 245 CHECK(false); // CloseHandle called on tracked handle. |
243 } | 246 } |
244 | 247 |
248 bool ActiveVerifier::GetCodeAddress(const void** pc) const { | |
249 if (enabled_) { | |
250 *pc = tracked_objects::GetProgramCounter(); | |
251 return true; | |
252 } | |
253 | |
254 return false; | |
255 } | |
256 | |
245 } // namespace | 257 } // namespace |
246 | 258 |
247 void* GetHandleVerifier() { | 259 void* GetHandleVerifier() { |
248 return ActiveVerifier::Get(); | 260 return ActiveVerifier::Get(); |
249 } | 261 } |
250 | 262 |
251 namespace base { | 263 namespace base { |
252 namespace win { | 264 namespace win { |
253 | 265 |
254 // Static. | 266 // Static. |
(...skipping 14 matching lines...) Expand all Loading... | |
269 } | 281 } |
270 | 282 |
271 void DisableHandleVerifier() { | 283 void DisableHandleVerifier() { |
272 return ActiveVerifier::Get()->Disable(); | 284 return ActiveVerifier::Get()->Disable(); |
273 } | 285 } |
274 | 286 |
275 void OnHandleBeingClosed(HANDLE handle) { | 287 void OnHandleBeingClosed(HANDLE handle) { |
276 return ActiveVerifier::Get()->OnHandleBeingClosed(handle); | 288 return ActiveVerifier::Get()->OnHandleBeingClosed(handle); |
277 } | 289 } |
278 | 290 |
291 HMODULE GetHandleVerifierModuleForTesting() { | |
292 const void* pc = nullptr; | |
293 | |
294 bool success = g_active_verifier->GetCodeAddress(&pc); | |
295 if (success) | |
296 return base::GetModuleFromAddress(pc); | |
scottmg
2016/03/11 19:02:18
Can you just use &__ImageBase instead?
.. Oh, I s
Will Harris
2016/03/11 20:35:31
I've actually changed this to use __ImageBase insi
| |
297 | |
298 return nullptr; | |
299 } | |
300 | |
279 } // namespace win | 301 } // namespace win |
280 } // namespace base | 302 } // namespace base |
OLD | NEW |