libc: Rewrite abort() using the new signals
Some checks failed
continuous-integration/drone/pr Build is failing

This commit is contained in:
apio 2023-07-10 21:08:23 +02:00
parent 8066e8f1d8
commit 3df40beaf2
Signed by: apio
GPG Key ID: B8A7D06E42258954

View File

@ -6,6 +6,7 @@
#include <luna/NumberParsing.h>
#include <luna/Sort.h>
#include <luna/Utf8.h>
#include <signal.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
@ -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();
}