From 3df40beaf260d20fa6236dd209c77fb22ef4e7e4 Mon Sep 17 00:00:00 2001 From: apio Date: Mon, 10 Jul 2023 21:08:23 +0200 Subject: [PATCH] libc: Rewrite abort() using the new signals --- libc/src/stdlib.cpp | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/libc/src/stdlib.cpp b/libc/src/stdlib.cpp index 5a31db25..c98ff791 100644 --- a/libc/src/stdlib.cpp +++ b/libc/src/stdlib.cpp @@ -6,6 +6,7 @@ #include #include #include +#include #include #include #include @@ -99,7 +100,25 @@ extern "C" __noreturn void abort() { - syscall(SYS_exit, 255); + // First, try to unblock SIGABRT and then raise it. + sigset_t set; + sigemptyset(&set); + sigaddset(&set, SIGABRT); + sigprocmask(SIG_UNBLOCK, &set, nullptr); + + raise(SIGABRT); + + // Still here? The program must have catched it. Reset the disposition to default. + struct sigaction act; + act.sa_handler = SIG_DFL; + sigemptyset(&act.sa_mask); + act.sa_flags = 0; + sigaction(SIGABRT, &act, nullptr); + + raise(SIGABRT); + + // There is no way we could end up here, unless there is some sort of race condition or the kernel decided to + // change the default action for SIGABRT because it's a Tuesday. __builtin_unreachable(); }