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