Path: blob/main/contrib/llvm-project/compiler-rt/lib/asan/asan_globals_win.cpp
35233 views
//===-- asan_globals_win.cpp ----------------------------------------------===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//7//8// Global registration code that is linked into every Windows DLL and EXE.9//10//===----------------------------------------------------------------------===//1112#include "asan_interface_internal.h"13#if SANITIZER_WINDOWS1415namespace __asan {1617#pragma section(".ASAN$GA", read, write)18#pragma section(".ASAN$GZ", read, write)19extern "C" alignas(sizeof(__asan_global))20__declspec(allocate(".ASAN$GA")) __asan_global __asan_globals_start = {};21extern "C" alignas(sizeof(__asan_global))22__declspec(allocate(".ASAN$GZ")) __asan_global __asan_globals_end = {};23#pragma comment(linker, "/merge:.ASAN=.data")2425static void call_on_globals(void (*hook)(__asan_global *, uptr)) {26__asan_global *start = &__asan_globals_start + 1;27__asan_global *end = &__asan_globals_end;28uptr bytediff = (uptr)end - (uptr)start;29if (bytediff % sizeof(__asan_global) != 0) {30#if defined(SANITIZER_DLL_THUNK) || defined(SANITIZER_DYNAMIC_RUNTIME_THUNK)31__debugbreak();32#else33CHECK("corrupt asan global array");34#endif35}36// We know end >= start because the linker sorts the portion after the dollar37// sign alphabetically.38uptr n = end - start;39hook(start, n);40}4142static void register_dso_globals() {43call_on_globals(&__asan_register_globals);44}4546static void unregister_dso_globals() {47call_on_globals(&__asan_unregister_globals);48}4950// Register globals51#pragma section(".CRT$XCU", long, read)52#pragma section(".CRT$XTX", long, read)53extern "C" __declspec(allocate(".CRT$XCU"))54void (*const __asan_dso_reg_hook)() = ®ister_dso_globals;55extern "C" __declspec(allocate(".CRT$XTX"))56void (*const __asan_dso_unreg_hook)() = &unregister_dso_globals;5758} // namespace __asan5960#endif // SANITIZER_WINDOWS616263