mirror of
https://github.com/cemu-project/Cemu.git
synced 2025-07-04 05:51:19 +12:00
Add SIGINT handler on posix systems
There's currently no overlap between the windows and posix implementation of the exception handler so I split them into different files for better clarity. Added a signal handler for SIGINT to allow exiting on CTRL+C. Note that like the rest of the program it does not exit cleanly and triggers a SIGABRT.
This commit is contained in:
parent
a1611c49da
commit
cc12b74e71
3 changed files with 38 additions and 36 deletions
|
@ -11,18 +11,19 @@ target_sources(CemuCommon
|
||||||
PRIVATE
|
PRIVATE
|
||||||
windows/platform.cpp
|
windows/platform.cpp
|
||||||
windows/platform.h
|
windows/platform.h
|
||||||
|
ExceptionHandler/ExceptionHandler_win32.cpp
|
||||||
)
|
)
|
||||||
else()
|
else()
|
||||||
target_sources(CemuCommon
|
target_sources(CemuCommon
|
||||||
PRIVATE
|
PRIVATE
|
||||||
unix/platform.cpp
|
unix/platform.cpp
|
||||||
unix/platform.h
|
unix/platform.h
|
||||||
|
ExceptionHandler/ExceptionHandler_posix.cpp
|
||||||
)
|
)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
target_sources(CemuCommon
|
target_sources(CemuCommon
|
||||||
PRIVATE
|
PRIVATE
|
||||||
ExceptionHandler/ExceptionHandler.cpp
|
|
||||||
ExceptionHandler/ExceptionHandler.h
|
ExceptionHandler/ExceptionHandler.h
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
36
src/Common/ExceptionHandler/ExceptionHandler_posix.cpp
Normal file
36
src/Common/ExceptionHandler/ExceptionHandler_posix.cpp
Normal file
|
@ -0,0 +1,36 @@
|
||||||
|
#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);
|
||||||
|
}
|
|
@ -1,12 +1,6 @@
|
||||||
#include "Common/precompiled.h"
|
#include "Common/precompiled.h"
|
||||||
#include "Cafe/CafeSystem.h"
|
#include "Cafe/CafeSystem.h"
|
||||||
|
|
||||||
#if BOOST_OS_LINUX || BOOST_OS_MACOS
|
|
||||||
#include <signal.h>
|
|
||||||
#include <execinfo.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if BOOST_OS_WINDOWS
|
|
||||||
#include <Windows.h>
|
#include <Windows.h>
|
||||||
#include <Dbghelp.h>
|
#include <Dbghelp.h>
|
||||||
#include <shellapi.h>
|
#include <shellapi.h>
|
||||||
|
@ -16,16 +10,11 @@
|
||||||
#include "Cafe/OS/libs/coreinit/coreinit_Thread.h"
|
#include "Cafe/OS/libs/coreinit/coreinit_Thread.h"
|
||||||
#include "Cafe/HW/Espresso/PPCState.h"
|
#include "Cafe/HW/Espresso/PPCState.h"
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
extern uint32 currentBaseApplicationHash;
|
extern uint32 currentBaseApplicationHash;
|
||||||
extern uint32 currentUpdatedApplicationHash;
|
extern uint32 currentUpdatedApplicationHash;
|
||||||
|
|
||||||
#if BOOST_OS_WINDOWS
|
|
||||||
|
|
||||||
LONG handleException_SINGLE_STEP(PEXCEPTION_POINTERS pExceptionInfo)
|
LONG handleException_SINGLE_STEP(PEXCEPTION_POINTERS pExceptionInfo)
|
||||||
{
|
{
|
||||||
|
|
||||||
return EXCEPTION_CONTINUE_SEARCH;
|
return EXCEPTION_CONTINUE_SEARCH;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -416,27 +405,3 @@ void ExceptionHandler_init()
|
||||||
AddVectoredExceptionHandler(1, VectoredExceptionHandler);
|
AddVectoredExceptionHandler(1, VectoredExceptionHandler);
|
||||||
SetErrorMode(SEM_FAILCRITICALERRORS);
|
SetErrorMode(SEM_FAILCRITICALERRORS);
|
||||||
}
|
}
|
||||||
#else
|
|
||||||
|
|
||||||
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 ExceptionHandler_init()
|
|
||||||
{
|
|
||||||
signal(SIGSEGV, handler_SIGSEGV);
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
Loading…
Add table
Add a link
Reference in a new issue