1 /* Copyright (C) 1991 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
4 The GNU C Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public License as
6 published by the Free Software Foundation; either version 2 of the
7 License, or (at your option) any later version.
9 The GNU C Library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
14 You should have received a copy of the GNU Library General Public
15 License along with the GNU C Library; see the file COPYING.LIB. If
16 not, see <http://www.gnu.org/licenses/>. */
18 /* Hacked up for uClibc by Erik Andersen */
30 /* Defeat compiler optimization which assumes function addresses are never NULL */
31 static __always_inline int not_null_ptr(const void *p)
35 : "=r" (q) /* output */
41 /* Our last ditch effort to commit suicide */
42 #ifdef __UCLIBC_ABORT_INSTRUCTION__
43 # define ABORT_INSTRUCTION __asm__(__UCLIBC_ABORT_INSTRUCTION__)
45 # define ABORT_INSTRUCTION
46 # warning "no abort instruction defined for your arch"
49 static smallint been_there_done_that = 0;
51 /* Be prepared in case multiple threads try to abort() */
52 #include <bits/uClibc_mutex.h>
53 __UCLIBC_MUTEX_STATIC(mylock, PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP);
55 /* Cause an abnormal program termination with core-dump */
60 /* Make sure we acquire the lock before proceeding */
61 __UCLIBC_MUTEX_LOCK_CANCEL_UNSAFE(mylock);
63 /* Unmask SIGABRT to be sure we can get it */
65 __sigaddset(&sigs, SIGABRT);
66 sigprocmask(SIG_UNBLOCK, &sigs, NULL);
69 /* Try to suicide with a SIGABRT */
70 if (been_there_done_that == 0) {
71 been_there_done_that++;
73 #ifdef __UCLIBC_HAS_STDIO_SHUTDOWN_ON_ABORT__
74 /* If we are using stdio, try to shut it down. At the very least,
75 * this will attempt to commit all buffered writes. It may also
76 * unbuffer all writable files, or close them outright.
77 * Check the stdio routines for details. */
78 if (not_null_ptr(_stdio_term)) {
84 __UCLIBC_MUTEX_UNLOCK_CANCEL_UNSAFE(mylock);
86 __UCLIBC_MUTEX_LOCK_CANCEL_UNSAFE(mylock);
89 /* Still here? Try to remove any signal handlers */
90 if (been_there_done_that == 1) {
93 been_there_done_that++;
94 memset(&act, '\0', sizeof(struct sigaction));
95 if (SIG_DFL) /* if it's constant zero, already done */
96 act.sa_handler = SIG_DFL;
97 __sigfillset(&act.sa_mask);
98 sigaction(SIGABRT, &act, NULL);
103 /* Still here? Try to suicide with an illegal instruction */
104 if (been_there_done_that == 2) {
105 been_there_done_that++;
109 /* Still here? Try to at least exit */
110 if (been_there_done_that == 3) {
111 been_there_done_that++;
115 /* Still here? We're screwed. Sleepy time. Good night. */
117 /* Try for ever and ever */
121 libc_hidden_def(abort)