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

Andrew Ng via llvm-commits llvm-commits at lists.llvm.org
Fri Jul 8 02:32:06 PDT 2022


Author: Andrew Ng
Date: 2022-07-08T10:31:35+01:00
New Revision: 86a2f2e2db2aa9df39f38b59b238b21ec7229b02

URL: https://github.com/llvm/llvm-project/commit/86a2f2e2db2aa9df39f38b59b238b21ec7229b02
DIFF: https://github.com/llvm/llvm-project/commit/86a2f2e2db2aa9df39f38b59b238b21ec7229b02.diff

LOG: [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

Added: 
    

Modified: 
    llvm/lib/Support/Windows/Signals.inc

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Support/Windows/Signals.inc b/llvm/lib/Support/Windows/Signals.inc
index 32477de5184b9..1621f4a54b796 100644
--- a/llvm/lib/Support/Windows/Signals.inc
+++ b/llvm/lib/Support/Windows/Signals.inc
@@ -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;
 


        


More information about the llvm-commits mailing list