123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150 |
- #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(__alpha__)
- #define ABORT_INSTRUCTION asm ("call_pal 0")
- #elif defined(__hppa__)
- #define ABORT_INSTRUCTION asm ("iitlbp %r0,(%r0)")
- #elif defined(__i386__)
- #define ABORT_INSTRUCTION asm ("hlt")
- #elif defined(__ia64__)
- #define ABORT_INSTRUCTION asm ("break 0")
- #elif defined(__m68k__)
- #define ABORT_INSTRUCTION asm ("illegal")
- #elif defined(__mc68000__)
- #define ABORT_INSTRUCTION asm (".long 0xffffffff")
- #elif defined(__mips__)
- #define ABORT_INSTRUCTION asm ("break 255")
- #elif defined(__powerpc__)
- #define ABORT_INSTRUCTION asm (".long 0")
- #elif defined(__s390__)
- #define ABORT_INSTRUCTION asm (".word 0")
- #elif defined(__sparc__)
- #define ABORT_INSTRUCTION asm ("unimp 0xf00")
- #elif defined(__SH5__)
- #define ABORT_INSTRUCTION asm ("movi 0x10, r9; shori 0xff, r9; trapa r9")
- #elif defined(__sh2__)
- #define ABORT_INSTRUCTION asm ("trapa #32")
- #elif defined(__sh__)
- #define ABORT_INSTRUCTION asm ("trapa #0xff")
- #elif defined(__x86_64__)
- #define ABORT_INSTRUCTION asm ("hlt")
- #else
- #define ABORT_INSTRUCTION
- #warning no abort instruction define for your arch
- #endif
- #ifdef __UCLIBC_HAS_STDIO_SHUTDOWN_ON_ABORT__
- extern void weak_function _stdio_term(void);
- #endif
- 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
- extern int __raise (int __sig) __THROW attribute_hidden;
- void abort(void)
- {
- sigset_t sigset;
-
- LOCK;
-
- if (__sigemptyset(&sigset) == 0 && __sigaddset(&sigset, SIGABRT) == 0) {
- sigprocmask(SIG_UNBLOCK, &sigset, (sigset_t *) NULL);
- }
- while (1) {
-
- if (been_there_done_that == 0) {
- been_there_done_that++;
- #ifdef __UCLIBC_HAS_STDIO_SHUTDOWN_ON_ABORT__
-
- if (_stdio_term) {
- _stdio_term();
- }
- #endif
- abort_it:
- 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);
- goto abort_it;
- }
-
- 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;
- }
- }
|