path: root/src/exit
diff options
authorRich Felker <>2018-09-01 01:54:44 -0400
committerRich Felker <>2018-09-01 02:06:10 -0400
commit9b14ad541068d4f7d0be9bcd1ff4c70090d868d3 (patch)
treeee80fd4be7d6d4a96858e02d76e4b53f038bf35d /src/exit
parent0b4c92b7acf63529858e7f8a3bb6505cd2b6e962 (diff)
always terminate by SIGABRT when abort is called
Linux makes this surprisingly difficult, but it can be done. the trick here is using the fact that we control the implementation of sigaction to prevent changing the disposition of SIGABRT to anything but SIG_DFL after abort has tried and failed to terminate the process simply by calling raise(SIGABRT).
Diffstat (limited to 'src/exit')
1 files changed, 19 insertions, 0 deletions
diff --git a/src/exit/abort.c b/src/exit/abort.c
index ecc0f735..d6bd546b 100644
--- a/src/exit/abort.c
+++ b/src/exit/abort.c
@@ -3,11 +3,30 @@
#include "syscall.h"
#include "pthread_impl.h"
#include "atomic.h"
+#include "libc.h"
+#include "ksigaction.h"
+volatile int __abort_lock[1];
_Noreturn void abort(void)
+ /* If there was a SIGABRT handler installed and it returned, or if
+ * SIGABRT was blocked or ignored, take an AS-safe lock to prevent
+ * sigaction from installing a new SIGABRT handler, uninstall any
+ * handler that may be present, and re-raise the signal to generate
+ * the default action of abnormal termination. */
+ LOCK(__abort_lock);
+ __syscall(SYS_rt_sigaction, SIGABRT,
+ &(struct k_sigaction){.handler = SIG_DFL}, 0, _NSIG/8);
+ __syscall(SYS_tkill, __pthread_self()->tid, SIGABRT);
+ __syscall(SYS_rt_sigprocmask, SIG_UNBLOCK,
+ &(long[_NSIG/(8*sizeof(long))]){1UL<<(SIGABRT-1)}, 0, _NSIG/8);
+ /* Beyond this point should be unreachable. */