From a3b1af4e3d687e95b229bfe2f0f9818957fc4236 Mon Sep 17 00:00:00 2001 From: bitscher Date: Fri, 2 Sep 2022 00:32:33 -0700 Subject: [PATCH] Add SIGINT handler on posix systems (#145) --- src/Common/CMakeLists.txt | 3 +- .../ExceptionHandler_posix.cpp | 36 +++++++++++++++++++ ...Handler.cpp => ExceptionHandler_win32.cpp} | 35 ------------------ src/gui/CemuApp.cpp | 7 ---- 4 files changed, 38 insertions(+), 43 deletions(-) create mode 100644 src/Common/ExceptionHandler/ExceptionHandler_posix.cpp rename src/Common/ExceptionHandler/{ExceptionHandler.cpp => ExceptionHandler_win32.cpp} (96%) diff --git a/src/Common/CMakeLists.txt b/src/Common/CMakeLists.txt index a1d5b8ab..e7535795 100644 --- a/src/Common/CMakeLists.txt +++ b/src/Common/CMakeLists.txt @@ -11,18 +11,19 @@ target_sources(CemuCommon PRIVATE windows/platform.cpp windows/platform.h + ExceptionHandler/ExceptionHandler_win32.cpp ) else() target_sources(CemuCommon PRIVATE unix/platform.cpp unix/platform.h + ExceptionHandler/ExceptionHandler_posix.cpp ) endif() target_sources(CemuCommon PRIVATE - ExceptionHandler/ExceptionHandler.cpp ExceptionHandler/ExceptionHandler.h ) diff --git a/src/Common/ExceptionHandler/ExceptionHandler_posix.cpp b/src/Common/ExceptionHandler/ExceptionHandler_posix.cpp new file mode 100644 index 00000000..2f18c2d7 --- /dev/null +++ b/src/Common/ExceptionHandler/ExceptionHandler_posix.cpp @@ -0,0 +1,36 @@ +#include +#include + +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); +} diff --git a/src/Common/ExceptionHandler/ExceptionHandler.cpp b/src/Common/ExceptionHandler/ExceptionHandler_win32.cpp similarity index 96% rename from src/Common/ExceptionHandler/ExceptionHandler.cpp rename to src/Common/ExceptionHandler/ExceptionHandler_win32.cpp index 48a99033..25dca26f 100644 --- a/src/Common/ExceptionHandler/ExceptionHandler.cpp +++ b/src/Common/ExceptionHandler/ExceptionHandler_win32.cpp @@ -1,12 +1,6 @@ #include "Common/precompiled.h" #include "Cafe/CafeSystem.h" -#if BOOST_OS_LINUX || BOOST_OS_MACOS -#include -#include -#endif - -#if BOOST_OS_WINDOWS #include #include #include @@ -16,16 +10,11 @@ #include "Cafe/OS/libs/coreinit/coreinit_Thread.h" #include "Cafe/HW/Espresso/PPCState.h" -#endif - extern uint32 currentBaseApplicationHash; extern uint32 currentUpdatedApplicationHash; -#if BOOST_OS_WINDOWS - LONG handleException_SINGLE_STEP(PEXCEPTION_POINTERS pExceptionInfo) { - return EXCEPTION_CONTINUE_SEARCH; } @@ -416,27 +405,3 @@ void ExceptionHandler_init() AddVectoredExceptionHandler(1, VectoredExceptionHandler); 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 \ No newline at end of file diff --git a/src/gui/CemuApp.cpp b/src/gui/CemuApp.cpp index 37a40bab..17e31f7a 100644 --- a/src/gui/CemuApp.cpp +++ b/src/gui/CemuApp.cpp @@ -399,11 +399,4 @@ void CemuApp::ActivateApp(wxActivateEvent& event) event.Skip(); } -extern "C" -{ - CemuApp& wxGetAppWrapper() - { - return *static_cast(wxApp::GetInstance()); - }; -}