]> git.proxmox.com Git - rustc.git/blame - src/libcompiler_builtins/compiler-rt/lib/asan/asan_globals_win.cc
New upstream version 1.25.0+dfsg1
[rustc.git] / src / libcompiler_builtins / compiler-rt / lib / asan / asan_globals_win.cc
CommitLineData
7cac9316
XL
1//===-- asan_globals_win.cc -----------------------------------------------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// Global registration code that is linked into every Windows DLL and EXE.
11//
12//===----------------------------------------------------------------------===//
13
14#include "asan_interface_internal.h"
15#if SANITIZER_WINDOWS
16
17namespace __asan {
18
19#pragma section(".ASAN$GA", read, write) // NOLINT
20#pragma section(".ASAN$GZ", read, write) // NOLINT
21extern "C" __declspec(allocate(".ASAN$GA"))
22__asan_global __asan_globals_start = {};
23extern "C" __declspec(allocate(".ASAN$GZ"))
24__asan_global __asan_globals_end = {};
25#pragma comment(linker, "/merge:.ASAN=.data")
26
27static void call_on_globals(void (*hook)(__asan_global *, uptr)) {
28 __asan_global *start = &__asan_globals_start + 1;
29 __asan_global *end = &__asan_globals_end;
30 uptr bytediff = (uptr)end - (uptr)start;
31 if (bytediff % sizeof(__asan_global) != 0) {
2c00a5a8 32#ifdef SANITIZER_DLL_THUNK
7cac9316
XL
33 __debugbreak();
34#else
35 CHECK("corrupt asan global array");
36#endif
37 }
38 // We know end >= start because the linker sorts the portion after the dollar
39 // sign alphabetically.
40 uptr n = end - start;
41 hook(start, n);
42}
43
44static void register_dso_globals() {
45 call_on_globals(&__asan_register_globals);
46}
47
48static void unregister_dso_globals() {
49 call_on_globals(&__asan_unregister_globals);
50}
51
52// Register globals
53#pragma section(".CRT$XCU", long, read) // NOLINT
54#pragma section(".CRT$XTX", long, read) // NOLINT
55extern "C" __declspec(allocate(".CRT$XCU"))
56void (*const __asan_dso_reg_hook)() = &register_dso_globals;
57extern "C" __declspec(allocate(".CRT$XTX"))
58void (*const __asan_dso_unreg_hook)() = &unregister_dso_globals;
59
60} // namespace __asan
61
62#endif // SANITIZER_WINDOWS