Skip to content

Commit

Permalink
Merge pull request #6027 from JonnyH/WIP/chained-signal-handler-andro…
Browse files Browse the repository at this point in the history
…id-debuggerd

Call the previously-set sigaction in fastmem handler if it's not our fault
  • Loading branch information
degasus committed Dec 9, 2017
2 parents aeaca50 + 7925de6 commit eb1ae38
Showing 1 changed file with 41 additions and 6 deletions.
47 changes: 41 additions & 6 deletions Source/Core/Core/MemTools.cpp
Expand Up @@ -232,6 +232,9 @@ void UninstallExceptionHandler()

#elif defined(_POSIX_VERSION) && !defined(_M_GENERIC)

static struct sigaction old_sa_segv;
static struct sigaction old_sa_bus;

static void sigsegv_handler(int sig, siginfo_t* info, void* raw_context)
{
if (sig != SIGSEGV && sig != SIGBUS)
Expand Down Expand Up @@ -264,10 +267,38 @@ static void sigsegv_handler(int sig, siginfo_t* info, void* raw_context)
))
{
// retry and crash
signal(SIGSEGV, SIG_DFL);
#ifdef __APPLE__
signal(SIGBUS, SIG_DFL);
#endif
// According to the sigaction man page, if sa_flags "SA_SIGINFO" is set to the sigaction
// function pointer, otherwise sa_handler contains one of:
// SIG_DEF: The 'default' action is performed
// SIG_IGN: The signal is ignored
// Any other value is a function pointer to a signal handler

struct sigaction* old_sa;
if (sig == SIGSEGV)
{
old_sa = &old_sa_segv;
}
else
{
old_sa = &old_sa_bus;
}

if (old_sa->sa_flags & SA_SIGINFO)
{
old_sa->sa_sigaction(sig, info, raw_context);
return;
}
if (old_sa->sa_handler == SIG_DFL)
{
signal(sig, SIG_DFL);
return;
}
if (old_sa->sa_handler == SIG_IGN)
{
// Ignore signal
return;
}
old_sa->sa_handler(sig);
}
}

Expand All @@ -288,9 +319,9 @@ void InstallExceptionHandler()
sa.sa_sigaction = &sigsegv_handler;
sa.sa_flags = SA_SIGINFO;
sigemptyset(&sa.sa_mask);
sigaction(SIGSEGV, &sa, nullptr);
sigaction(SIGSEGV, &sa, &old_sa_segv);
#ifdef __APPLE__
sigaction(SIGBUS, &sa, nullptr);
sigaction(SIGBUS, &sa, &old_sa_bus);
#endif
}

Expand All @@ -302,6 +333,10 @@ void UninstallExceptionHandler()
{
free(old_stack.ss_sp);
}
sigaction(SIGSEGV, &old_sa_segv, nullptr);
#ifdef __APPLE__
sigaction(SIGBUS, &old_sa_bus, nullptr);
#endif
}
#else // _M_GENERIC or unsupported platform

Expand Down

0 comments on commit eb1ae38

Please sign in to comment.