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(); }