Cemu/src/Common/ExceptionHandler/ExceptionHandler_posix.cpp
Timothy Redaelli 96d98fd3ab Use _Exit instead of exit under Linux
The best ExitProcess alternative for Linux is _Exit since it doesn't
call exit handlers.

This fixes also #178 since, with exit, it aborts due to some std::threads
not correctly joined.
2022-09-08 11:06:52 +02:00

37 lines
855 B
C++

#include <signal.h>
#include <execinfo.h>
void handler_SIGSEGV(int sig)
{
printf("SIGSEGV!\n");
void *array[32];
size_t size;
// get void*'s for all entries on the stack
size = backtrace(array, 32);
// print out all the frames to stderr
fprintf(stderr, "Error: signal %d:\n", sig);
backtrace_symbols_fd(array, size, STDERR_FILENO);
exit(1);
}
void handler_SIGINT(int sig)
{
/*
* Received when pressing CTRL + C in a console
* Ideally should be exiting cleanly after saving settings but currently
* there's no clean exit pathway (at least on linux) and exiting the app
* by any mean ends up with a SIGABRT from the standard library destroying
* threads.
*/
_Exit(0);
}
void ExceptionHandler_init()
{
signal(SIGSEGV, handler_SIGSEGV);
signal(SIGINT, handler_SIGINT);
}