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

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

Issue 1852143002: win: Remove GetModuleFromAddress, deduplicate __ImageBase code. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 4 years, 8 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
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/current_module.h"
19 20
20 extern "C" { 21 extern "C" {
21 __declspec(dllexport) void* GetHandleVerifier(); 22 __declspec(dllexport) void* GetHandleVerifier();
22 typedef void* (*GetHandleVerifierFn)(); 23 typedef void* (*GetHandleVerifierFn)();
23 } 24 }
24 25
25 // http://blogs.msdn.com/oldnewthing/archive/2004/10/25/247180.aspx
26 extern "C" IMAGE_DOS_HEADER __ImageBase;
27
28 namespace { 26 namespace {
29 27
30 struct HandleHash { 28 struct HandleHash {
31 size_t operator()(const HANDLE& handle) const { 29 size_t operator()(const HANDLE& handle) const {
32 char buffer[sizeof(handle)]; 30 char buffer[sizeof(handle)];
33 memcpy(buffer, &handle, sizeof(handle)); 31 memcpy(buffer, &handle, sizeof(handle));
34 return base::Hash(buffer, sizeof(buffer)); 32 return base::Hash(buffer, sizeof(buffer));
35 } 33 }
36 }; 34 };
37 35
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after
240 if (i == map_.end()) 238 if (i == map_.end())
241 return; 239 return;
242 240
243 Info other = i->second; 241 Info other = i->second;
244 base::debug::Alias(&other); 242 base::debug::Alias(&other);
245 base::debug::Alias(&creation_stack_); 243 base::debug::Alias(&creation_stack_);
246 CHECK(false); // CloseHandle called on tracked handle. 244 CHECK(false); // CloseHandle called on tracked handle.
247 } 245 }
248 246
249 HMODULE ActiveVerifier::GetModule() const { 247 HMODULE ActiveVerifier::GetModule() const {
250 return reinterpret_cast<HMODULE>(&__ImageBase); 248 return CURRENT_MODULE();
251 } 249 }
252 250
253 } // namespace 251 } // namespace
254 252
255 void* GetHandleVerifier() { 253 void* GetHandleVerifier() {
256 return ActiveVerifier::Get(); 254 return ActiveVerifier::Get();
257 } 255 }
258 256
259 namespace base { 257 namespace base {
260 namespace win { 258 namespace win {
(...skipping 22 matching lines...) Expand all
283 void OnHandleBeingClosed(HANDLE handle) { 281 void OnHandleBeingClosed(HANDLE handle) {
284 return ActiveVerifier::Get()->OnHandleBeingClosed(handle); 282 return ActiveVerifier::Get()->OnHandleBeingClosed(handle);
285 } 283 }
286 284
287 HMODULE GetHandleVerifierModuleForTesting() { 285 HMODULE GetHandleVerifierModuleForTesting() {
288 return g_active_verifier->GetModule(); 286 return g_active_verifier->GetModule();
289 } 287 }
290 288
291 } // namespace win 289 } // namespace win
292 } // namespace base 290 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698