diff options
| author | Dimitry Andric <dim@FreeBSD.org> | 2022-07-03 14:10:23 +0000 |
|---|---|---|
| committer | Dimitry Andric <dim@FreeBSD.org> | 2022-07-03 14:10:23 +0000 |
| commit | 145449b1e420787bb99721a429341fa6be3adfb6 (patch) | |
| tree | 1d56ae694a6de602e348dd80165cf881a36600ed /llvm/lib/Support/CrashRecoveryContext.cpp | |
| parent | ecbca9f5fb7d7613d2b94982c4825eb0d33d6842 (diff) | |
Diffstat (limited to 'llvm/lib/Support/CrashRecoveryContext.cpp')
| -rw-r--r-- | llvm/lib/Support/CrashRecoveryContext.cpp | 20 |
1 files changed, 13 insertions, 7 deletions
diff --git a/llvm/lib/Support/CrashRecoveryContext.cpp b/llvm/lib/Support/CrashRecoveryContext.cpp index 2ee3074b840e..292ba63d14aa 100644 --- a/llvm/lib/Support/CrashRecoveryContext.cpp +++ b/llvm/lib/Support/CrashRecoveryContext.cpp @@ -9,6 +9,7 @@ #include "llvm/Support/CrashRecoveryContext.h" #include "llvm/Config/llvm-config.h" #include "llvm/Support/ErrorHandling.h" +#include "llvm/Support/ExitCodes.h" #include "llvm/Support/ManagedStatic.h" #include "llvm/Support/Signals.h" #include "llvm/Support/ThreadLocal.h" @@ -16,10 +17,6 @@ #include <mutex> #include <setjmp.h> -#if !defined(_MSC_VER) && !defined(_WIN32) -#include "llvm/Support/ExitCodes.h" -#endif - using namespace llvm; namespace { @@ -97,7 +94,7 @@ static ManagedStatic<sys::ThreadLocal<const CrashRecoveryContext>> static void installExceptionOrSignalHandlers(); static void uninstallExceptionOrSignalHandlers(); -CrashRecoveryContextCleanup::~CrashRecoveryContextCleanup() {} +CrashRecoveryContextCleanup::~CrashRecoveryContextCleanup() = default; CrashRecoveryContext::CrashRecoveryContext() { // On Windows, if abort() was previously triggered (and caught by a previous @@ -445,7 +442,7 @@ bool CrashRecoveryContext::RunSafely(function_ref<void()> Fn) { llvm_unreachable("Most likely setjmp wasn't called!"); } -bool CrashRecoveryContext::throwIfCrash(int RetCode) { +bool CrashRecoveryContext::isCrash(int RetCode) { #if defined(_WIN32) // On Windows, the high bits are reserved for kernel return codes. Values // starting with 0x80000000 are reserved for "warnings"; values of 0xC0000000 @@ -454,12 +451,21 @@ bool CrashRecoveryContext::throwIfCrash(int RetCode) { unsigned Code = ((unsigned)RetCode & 0xF0000000) >> 28; if (Code != 0xC && Code != 8) return false; - ::RaiseException(RetCode, 0, 0, NULL); #else // On Unix, signals are represented by return codes of 128 or higher. // Exit code 128 is a reserved value and should not be raised as a signal. if (RetCode <= 128) return false; +#endif + return true; +} + +bool CrashRecoveryContext::throwIfCrash(int RetCode) { + if (!isCrash(RetCode)) + return false; +#if defined(_WIN32) + ::RaiseException(RetCode, 0, 0, NULL); +#else llvm::sys::unregisterHandlers(); raise(RetCode - 128); #endif |
