1 //===-- asan_globals_win.cc -----------------------------------------------===//
3 // This file is distributed under the University of Illinois Open Source
4 // License. See LICENSE.TXT for details.
6 //===----------------------------------------------------------------------===//
8 // Global registration code that is linked into every Windows DLL and EXE.
10 //===----------------------------------------------------------------------===//
12 #include "asan_interface_internal.h"
17 #pragma section(".ASAN$GA", read, write) // NOLINT
18 #pragma section(".ASAN$GZ", read, write) // NOLINT
19 extern "C" __declspec(allocate(".ASAN$GA"))
20 __asan_global __asan_globals_start
= {};
21 extern "C" __declspec(allocate(".ASAN$GZ"))
22 __asan_global __asan_globals_end
= {};
23 #pragma comment(linker, "/merge:.ASAN=.data")
25 static void call_on_globals(void (*hook
)(__asan_global
*, uptr
)) {
26 __asan_global
*start
= &__asan_globals_start
+ 1;
27 __asan_global
*end
= &__asan_globals_end
;
28 uptr bytediff
= (uptr
)end
- (uptr
)start
;
29 if (bytediff
% sizeof(__asan_global
) != 0) {
30 #ifdef SANITIZER_DLL_THUNK
33 CHECK("corrupt asan global array");
36 // We know end >= start because the linker sorts the portion after the dollar
37 // sign alphabetically.
42 static void register_dso_globals() {
43 call_on_globals(&__asan_register_globals
);
46 static void unregister_dso_globals() {
47 call_on_globals(&__asan_unregister_globals
);
51 #pragma section(".CRT$XCU", long, read) // NOLINT
52 #pragma section(".CRT$XTX", long, read) // NOLINT
53 extern "C" __declspec(allocate(".CRT$XCU"))
54 void (*const __asan_dso_reg_hook
)() = ®ister_dso_globals
;
55 extern "C" __declspec(allocate(".CRT$XTX"))
56 void (*const __asan_dso_unreg_hook
)() = &unregister_dso_globals
;
60 #endif // SANITIZER_WINDOWS