From 0df493a13ab8b03267bd9387a36c9163392d438e Mon Sep 17 00:00:00 2001 From: Augustin Cavalier Date: Sun, 2 Sep 2018 00:13:40 -0400 Subject: [PATCH] libroot: Fix handling of debugger() call in abort(). The kernel's handling of SIGABRT is just to terminate the application immediately without doing anything else (it only notifies the debugger if there's one installed for this application already.) More serious faults (e.g. SIGSEGV) originate in the kernel and handle this logic before they even invoke the signal handler. So the correct solution is to do the same here in libroot. This incurs a very, very slight performance penalty of the syscall time for sigaction(), though I expect whatever applications are causing SIGABRT to be invoked more than once a second will call raise() directly instead of abort()... --- src/system/libroot/posix/stdlib/exit.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/system/libroot/posix/stdlib/exit.cpp b/src/system/libroot/posix/stdlib/exit.cpp index 0e103099a8..2bc67821e7 100644 --- a/src/system/libroot/posix/stdlib/exit.cpp +++ b/src/system/libroot/posix/stdlib/exit.cpp @@ -288,8 +288,14 @@ abort() { fprintf(stderr, "Abort\n"); + // If there's no handler installed for SIGABRT, call debugger(). + struct sigaction signalAction; + if (sigaction(SIGABRT, NULL, &signalAction) == 0 + && signalAction.sa_handler == SIG_DFL) { + debugger("abort() called"); + } + raise(SIGABRT); - debugger("abort() called"); exit(EXIT_FAILURE); }