[PATCH] D102944: [Windows] Use TerminateProcess to exit without running destructors
Martin Storsjö via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri May 21 13:54:04 PDT 2021
mstorsjo created this revision.
mstorsjo added reviewers: rnk, mati865.
Herald added subscribers: dexonsmith, hiraditya.
mstorsjo requested review of this revision.
Herald added a project: LLVM.
If exiting using _Exit or ExitProcess, DLLs are still unloaded
cleanly before exiting, running destructors and other cleanup in those
DLLs. When the caller expects to exit without cleanup, running
destructors in some loaded DLLs (which can be either libLLVM.dll or
e.g. libc++.dll) can cause deadlocks occasionally.
This is an alternative to D102684 <https://reviews.llvm.org/D102684>.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D102944
Files:
llvm/include/llvm/Support/Process.h
llvm/lib/Support/Process.cpp
llvm/lib/Support/Unix/Process.inc
llvm/lib/Support/Windows/Process.inc
Index: llvm/lib/Support/Windows/Process.inc
===================================================================
--- llvm/lib/Support/Windows/Process.inc
+++ llvm/lib/Support/Windows/Process.inc
@@ -503,3 +503,9 @@
// Windows 8 is version 6.2, service pack 0.
return GetWindowsOSVersion() >= llvm::VersionTuple(6, 2, 0, 0);
}
+
+LLVM_ATTRIBUTE_NORETURN
+void Process::ExitNoCleanup(int RetCode) {
+ TerminateProcess(GetCurrentProcess(), RetCode);
+ llvm_unreachable("TerminateProcess doesn't return");
+}
Index: llvm/lib/Support/Unix/Process.inc
===================================================================
--- llvm/lib/Support/Unix/Process.inc
+++ llvm/lib/Support/Unix/Process.inc
@@ -460,3 +460,6 @@
return ::rand();
#endif
}
+
+LLVM_ATTRIBUTE_NORETURN
+void Process::ExitNoCleanup(int RetCode) { _Exit(RetCode); }
Index: llvm/lib/Support/Process.cpp
===================================================================
--- llvm/lib/Support/Process.cpp
+++ llvm/lib/Support/Process.cpp
@@ -98,7 +98,7 @@
CRC->HandleExit(RetCode);
if (NoCleanup)
- _Exit(RetCode);
+ ExitNoCleanup(RetCode);
else
::exit(RetCode);
}
Index: llvm/include/llvm/Support/Process.h
===================================================================
--- llvm/include/llvm/Support/Process.h
+++ llvm/include/llvm/Support/Process.h
@@ -216,6 +216,10 @@
/// Use \arg NoCleanup for calling _exit() instead of exit().
LLVM_ATTRIBUTE_NORETURN
static void Exit(int RetCode, bool NoCleanup = false);
+
+private:
+ LLVM_ATTRIBUTE_NORETURN
+ static void ExitNoCleanup(int RetCode);
};
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D102944.347117.patch
Type: text/x-patch
Size: 1613 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210521/f91ad3c4/attachment.bin>
More information about the llvm-commits
mailing list