[Support] Fix Windows dump file hang with multi-threaded crashes

Prevents deadlock between MiniDumpWriteDump and
CryptAcquireContextW (called via fs::createTemporaryFile) in
WriteWindowsDumpFile.

However, there's no guarantee that deadlock can't still occur between
MiniDumpWriteDump and some other Win32 API call. But that would appear
to be the "accepted" risk of using MiniDumpWriteDump in this manner.

Differential Revision: https://reviews.llvm.org/D129004
This commit is contained in:
Andrew Ng 2022-06-30 18:55:53 +01:00
parent 1d27f26426
commit 86a2f2e2db
1 changed files with 5 additions and 0 deletions

View File

@ -731,6 +731,11 @@ static bool GetDumpType(HKEY Key, MINIDUMP_TYPE &ResultType) {
/// otherwise.
static std::error_code WINAPI
WriteWindowsDumpFile(PMINIDUMP_EXCEPTION_INFORMATION ExceptionInfo) {
struct ScopedCriticalSection {
ScopedCriticalSection() { EnterCriticalSection(&CriticalSection); }
~ScopedCriticalSection() { LeaveCriticalSection(&CriticalSection); }
} SCS;
using namespace llvm;
using namespace llvm::sys;