mirror of
https://github.com/stenzek/duckstation.git
synced 2025-07-18 16:10:07 +00:00
CrashHandler: Catch SIGABRT
This commit is contained in:
parent
9c81425043
commit
6f65a15bb9
@ -6,6 +6,7 @@
|
||||
#include "file_system.h"
|
||||
#include "string_util.h"
|
||||
#include <cinttypes>
|
||||
#include <csignal>
|
||||
#include <cstdio>
|
||||
#include <ctime>
|
||||
|
||||
@ -195,6 +196,21 @@ static void PureCallHandler()
|
||||
__fastfail(FAST_FAIL_INVALID_ARG);
|
||||
}
|
||||
|
||||
static void AbortSignalHandler(int signal)
|
||||
{
|
||||
// if the debugger is attached, or we're recursively crashing, let it take care of it.
|
||||
if (!s_in_crash_handler && !IsDebuggerPresent())
|
||||
{
|
||||
s_in_crash_handler = true;
|
||||
if (s_cleanup_handler)
|
||||
s_cleanup_handler();
|
||||
|
||||
WriteMinidumpAndCallstack(nullptr, "Pure call handler invoked");
|
||||
}
|
||||
|
||||
TerminateProcess(GetCurrentProcess(), 0xFAFAFAFAu);
|
||||
}
|
||||
|
||||
bool CrashHandler::Install(CleanupHandler cleanup_handler)
|
||||
{
|
||||
// load dbghelp at install/startup, that way we're not LoadLibrary()'ing after a crash
|
||||
@ -208,6 +224,12 @@ bool CrashHandler::Install(CleanupHandler cleanup_handler)
|
||||
SetUnhandledExceptionFilter(ExceptionHandler);
|
||||
_set_invalid_parameter_handler(InvalidParameterHandler);
|
||||
_set_purecall_handler(PureCallHandler);
|
||||
#ifdef _DEBUG
|
||||
_set_abort_behavior(_WRITE_ABORT_MSG, _WRITE_ABORT_MSG | _CALL_REPORTFAULT);
|
||||
#else
|
||||
_set_abort_behavior(_WRITE_ABORT_MSG | _CALL_REPORTFAULT, _WRITE_ABORT_MSG | _CALL_REPORTFAULT);
|
||||
#endif
|
||||
signal(SIGABRT, AbortSignalHandler);
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -391,6 +413,10 @@ bool CrashHandler::Install(CleanupHandler cleanup_handler)
|
||||
if (sigaction(SIGSEGV, &sa, nullptr) != 0)
|
||||
return false;
|
||||
|
||||
sa.sa_flags = SA_SIGINFO;
|
||||
if (sigaction(SIGABRT, &sa, nullptr) != 0)
|
||||
return false;
|
||||
|
||||
s_cleanup_handler = cleanup_handler;
|
||||
return true;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user