123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126 |
- #define _GNU_SOURCE
- #include <features.h>
- #include <signal.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <unistd.h>
- #include <signal.h>
- #include <errno.h>
-
- #if defined(__i386__)
- #define ABORT_INSTRUCTION asm ("hlt")
- #elif defined(__ia64__)
- #define ABORT_INSTRUCTION asm ("break 0")
- #elif defined(__mc68000__)
- #define ABORT_INSTRUCTION asm (".long 0xffffffff")
- #elif defined(__mips__)
- #define ABORT_INSTRUCTION asm ("break 255")
- #elif defined(__s390__)
- #define ABORT_INSTRUCTION asm (".word 0")
- #elif defined(__sparc__)
- #define ABORT_INSTRUCTION asm ("unimp 0xf00")
- #elif defined(__x86_64__)
- #define ABORT_INSTRUCTION asm ("hlt")
- #else
- #define ABORT_INSTRUCTION
- #endif
- extern void weak_function _stdio_term(void);
- extern void _exit __P((int __status)) __attribute__ ((__noreturn__));
- static int been_there_done_that = 0;
- #ifdef __UCLIBC_HAS_THREADS__
- #include <pthread.h>
- static pthread_mutex_t mylock = PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP;
- # define LOCK __pthread_mutex_lock(&mylock)
- # define UNLOCK __pthread_mutex_unlock(&mylock);
- #else
- # define LOCK
- # define UNLOCK
- #endif
- void abort(void)
- {
- sigset_t sigset;
-
- LOCK;
-
- if (__sigemptyset(&sigset) == 0 && __sigaddset(&sigset, SIGABRT) == 0) {
- sigprocmask(SIG_UNBLOCK, &sigset, (sigset_t *) NULL);
- }
-
- if (_stdio_term)
- _stdio_term();
- while (1) {
-
- if (been_there_done_that == 0) {
- been_there_done_that++;
- UNLOCK;
- raise(SIGABRT);
- LOCK;
- }
-
- if (been_there_done_that == 1) {
- struct sigaction act;
- been_there_done_that++;
- memset (&act, '\0', sizeof (struct sigaction));
- act.sa_handler = SIG_DFL;
- __sigfillset (&act.sa_mask);
- act.sa_flags = 0;
- sigaction (SIGABRT, &act, NULL);
- }
-
- if (been_there_done_that == 2) {
- been_there_done_that++;
- ABORT_INSTRUCTION;
- }
-
- if (been_there_done_that == 3) {
- been_there_done_that++;
- _exit (127);
- }
-
- while (1)
-
- ABORT_INSTRUCTION;
- }
- }
|