mirror of
https://github.com/capstone-engine/llvm-capstone.git
synced 2024-11-23 22:00:10 +00:00
[Windows] Use TerminateProcess to exit without running destructors
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. Differential Revision: https://reviews.llvm.org/D102944
This commit is contained in:
parent
c5638a71d8
commit
b4fd512c36
@ -216,6 +216,10 @@ public:
|
||||
/// 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);
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -98,7 +98,7 @@ void Process::Exit(int RetCode, bool NoCleanup) {
|
||||
CRC->HandleExit(RetCode);
|
||||
|
||||
if (NoCleanup)
|
||||
_Exit(RetCode);
|
||||
ExitNoCleanup(RetCode);
|
||||
else
|
||||
::exit(RetCode);
|
||||
}
|
||||
|
@ -460,3 +460,6 @@ unsigned llvm::sys::Process::GetRandomNumber() {
|
||||
return ::rand();
|
||||
#endif
|
||||
}
|
||||
|
||||
LLVM_ATTRIBUTE_NORETURN
|
||||
void Process::ExitNoCleanup(int RetCode) { _Exit(RetCode); }
|
||||
|
@ -503,3 +503,9 @@ bool llvm::RunningWindows8OrGreater() {
|
||||
// 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");
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user