Implement signals, finally! #30

Merged
apio merged 14 commits from finally-signals into main 2023-07-10 20:16:00 +00:00
Showing only changes of commit 3df40beaf2 - Show all commits

View File

@ -6,6 +6,7 @@
#include <luna/NumberParsing.h> #include <luna/NumberParsing.h>
#include <luna/Sort.h> #include <luna/Sort.h>
#include <luna/Utf8.h> #include <luna/Utf8.h>
#include <signal.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <sys/stat.h> #include <sys/stat.h>
@ -99,7 +100,25 @@ extern "C"
__noreturn void abort() __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(); __builtin_unreachable();
} }