summaryrefslogtreecommitdiff
path: root/src/exit/abort.c
blob: 5e5a87c354184530dea743998e628a67b7769404 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include <stdlib.h>
#include <signal.h>
#include <string.h>
#include "syscall.h"
#include "pthread_impl.h"
#include "atomic.h"

_Noreturn void abort(void)
{
	struct sigaction abrtaction;
	sigset_t abrtset;

	raise(SIGABRT);
	__block_all_sigs(0);

	/* Unblock just SIGABRT, and set default handler */
	sigemptyset(&abrtset);
	sigaddset(&abrtset, SIGABRT);
	sigprocmask(SIG_UNBLOCK, &abrtset, 0);

	memset(&abrtaction, 0, sizeof(struct sigaction));
	abrtaction.sa_handler = SIG_DFL;

	sigaction(SIGABRT, &abrtaction, NULL);

	raise(SIGABRT);

	/* Ok, give up. */
	a_crash();
	raise(SIGKILL);
	_Exit(127);
}