123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121 |
- #include <features.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <unistd.h>
- #include <signal.h>
- #include <errno.h>
- static __always_inline int not_null_ptr(const void *p)
- {
- const void *q;
- __asm__ (""
- : "=r" (q)
- : "0" (p)
- );
- return q != 0;
- }
- #ifdef __UCLIBC_ABORT_INSTRUCTION__
- # define ABORT_INSTRUCTION __asm__(__UCLIBC_ABORT_INSTRUCTION__)
- #else
- # define ABORT_INSTRUCTION
- # warning "no abort instruction defined for your arch"
- #endif
- static smallint been_there_done_that = 0;
- #include <bits/uClibc_mutex.h>
- __UCLIBC_MUTEX_STATIC(mylock, PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP);
- void abort(void)
- {
- sigset_t sigs;
-
- __UCLIBC_MUTEX_LOCK_CANCEL_UNSAFE(mylock);
-
- __sigemptyset(&sigs);
- __sigaddset(&sigs, SIGABRT);
- sigprocmask(SIG_UNBLOCK, &sigs, NULL);
- while (1) {
-
- if (been_there_done_that == 0) {
- been_there_done_that++;
- #ifdef __UCLIBC_HAS_STDIO_SHUTDOWN_ON_ABORT__
-
- if (not_null_ptr(_stdio_term)) {
- _stdio_term();
- }
- #endif
- abort_it:
- __UCLIBC_MUTEX_UNLOCK_CANCEL_UNSAFE(mylock);
- raise(SIGABRT);
- __UCLIBC_MUTEX_LOCK_CANCEL_UNSAFE(mylock);
- }
-
- if (been_there_done_that == 1) {
- struct sigaction act;
- been_there_done_that++;
- memset(&act, '\0', sizeof(struct sigaction));
- if (SIG_DFL)
- act.sa_handler = SIG_DFL;
- __sigfillset(&act.sa_mask);
- 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;
- }
- }
- libc_hidden_def(abort)
|