Handle SIGABRT and SIGSEGV on Windows (#3511)

* Handle SIGABRT and SIGSEGV on Windows

* Address code review
This commit is contained in:
theohax 2021-10-21 15:43:56 +03:00 committed by GitHub
commit f1f67265f4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -19,6 +19,11 @@ namespace
{
void nano_abort_signal_handler (int signum)
{
// remove `signum` from signal handling when under Windows
#ifdef _WIN32
std::signal (signum, SIG_DFL);
#endif
// create some debugging log files
nano::dump_crash_stacktrace ();
nano::create_load_memory_address_files ();
@ -29,9 +34,12 @@ void nano_abort_signal_handler (int signum)
void install_abort_signal_handler ()
{
#ifndef _WIN32
// We catch signal SIGSEGV and SIGABRT not via the signal manager because we want these signal handlers
// to be executed in the stack of the code that caused the signal, so we can dump the stacktrace.
#ifdef _WIN32
std::signal (SIGSEGV, nano_abort_signal_handler);
std::signal (SIGABRT, nano_abort_signal_handler);
#else
struct sigaction sa = {};
sa.sa_handler = nano_abort_signal_handler;
sigemptyset (&sa.sa_mask);