Index: lib/asan/asan_win.cc =================================================================== --- lib/asan/asan_win.cc +++ lib/asan/asan_win.cc @@ -291,6 +291,15 @@ // On Win64, we map memory on demand with access violation handler. // Install our exception handler. CHECK(AddVectoredExceptionHandler(TRUE, &ShadowExceptionHandler)); + + // This module must not be unloaded while ShadowExceptionHandler is still + // registered as an exception handler. Ideally we'd do proper cleanup with + // RemoveVectoredExceptionHandler, but in the short term just pin the DLL. + HMODULE unused; + CHECK(GetModuleHandleExW(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS | + GET_MODULE_HANDLE_EX_FLAG_PIN, + (LPCWSTR)&ShadowExceptionHandler, + &unused)); #endif }