From e705624cff2913b66c65023228634ead445e2c20 Mon Sep 17 00:00:00 2001 From: David Major Date: Wed, 26 Sep 2018 16:28:39 +0000 Subject: [PATCH] [winasan] Pin the ASan DLL to prevent unloading Differential Revision: https://reviews.llvm.org/D52505 llvm-svn: 343123 --- compiler-rt/lib/asan/asan_win.cc | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/compiler-rt/lib/asan/asan_win.cc b/compiler-rt/lib/asan/asan_win.cc index 3b6424e..c8af8c9 100644 --- a/compiler-rt/lib/asan/asan_win.cc +++ b/compiler-rt/lib/asan/asan_win.cc @@ -167,6 +167,14 @@ INTERCEPTOR_WINAPI(void, NtTerminateThread, void *rcx) { namespace __asan { void InitializePlatformInterceptors() { + // The interceptors were not designed to be removable, so we have to keep this + // module alive for the life of the process. + HMODULE pinned; + CHECK(GetModuleHandleExW(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS | + GET_MODULE_HANDLE_EX_FLAG_PIN, + (LPCWSTR)&InitializePlatformInterceptors, + &pinned)); + ASAN_INTERCEPT_FUNC(CreateThread); ASAN_INTERCEPT_FUNC(SetUnhandledExceptionFilter); CHECK(::__interception::OverrideFunction("NtTerminateThread", -- 2.7.4