| // Copyright 2026 The PDFium Authors | |
| // Use of this source code is governed by a BSD-style license that can be | |
| // found in the LICENSE file. | |
| #include "testing/preload.h" | |
| #include "build/build_config.h" | |
| #if BUILDFLAG(IS_WIN) | |
| #include <windows.h> | |
| #include <dbghelp.h> | |
| #endif | |
| namespace pdfium { | |
| void PreloadSymbols() { | |
| #if BUILDFLAG(IS_WIN) | |
| // In SDK 10.0.28000+, dbghelp.dll dynamically loads msdia140.dll at runtime, | |
| // and symbolization calls WinVerifyTrust() which creates threads in crypt32. | |
| // If dbghelp is initialized during ASAN symbolization of a crash, this | |
| // causes reentrancy or deadlocks inside AddressSanitizer's thread registry | |
| // or malloc handlers (see crbug.com/548509159). Therefore, preload these | |
| // DLLs and initialize DbgHelp before test execution starts. | |
| ::LoadLibraryW(L"dbghelp.dll"); | |
| ::LoadLibraryW(L"msdia140.dll"); | |
| if (::SymInitialize(::GetCurrentProcess(), nullptr, TRUE)) { | |
| ::SymCleanup(::GetCurrentProcess()); | |
| } | |
| #endif // BUILDFLAG(IS_WIN) | |
| } | |
| } // namespace pdfium |