1 #include <stdlib.h>
2 #include <signal.h>
3 #include "syscall.h"
4 #include "pthread_impl.h"
5 #include "atomic.h"
6 #include "lock.h"
7 #include "ksigaction.h"
8
abort(void)9 _Noreturn void abort(void)
10 {
11 sigset_t set, pending;
12 sigemptyset(&set);
13 sigaddset(&set, SIGABRT);
14
15 sigpending(&pending);
16 __syscall(SYS_rt_sigprocmask, SIG_UNBLOCK, &set, 0, _NSIG / 8);
17 if (!sigismember(&pending, SIGABRT)) {
18 raise(SIGABRT);
19 }
20 /* If there was a SIGABRT handler installed and it returned, or if
21 * SIGABRT was blocked or ignored, take an AS-safe lock to prevent
22 * sigaction from installing a new SIGABRT handler, uninstall any
23 * handler that may be present, and re-raise the signal to generate
24 * the default action of abnormal termination. */
25 __block_all_sigs(0);
26 LOCK(__abort_lock);
27 signal(SIGABRT, SIG_DFL);
28 __syscall(SYS_tkill, __pthread_self()->tid, SIGABRT);
29 __syscall(SYS_rt_sigprocmask, SIG_UNBLOCK,
30 &(long[_NSIG/(8*sizeof(long))]){1UL<<(SIGABRT-1)}, 0, _NSIG/8);
31
32 /* Beyond this point should be unreachable. */
33 a_crash();
34 raise(SIGKILL);
35 _Exit(127);
36 }
37