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, write to the Free Software Foundation, Inc., 675 Mass Ave,
17 Cambridge, MA 02139, USA. */
19 /* Hacked up for uClibc by Erik Andersen */
32 /* Our last ditch effort to commit suicide */
34 #define ABORT_INSTRUCTION asm ("hlt")
35 #elif defined(__ia64__)
36 #define ABORT_INSTRUCTION asm ("break 0")
37 #elif defined(__mc68000__)
38 #define ABORT_INSTRUCTION asm (".long 0xffffffff")
39 #elif defined(__mips__)
40 #define ABORT_INSTRUCTION asm ("break 255")
41 #elif defined(__s390__)
42 #define ABORT_INSTRUCTION asm (".word 0")
43 #elif defined(__sparc__)
44 #define ABORT_INSTRUCTION asm ("unimp 0xf00")
45 #elif defined(__x86_64__)
46 #define ABORT_INSTRUCTION asm ("hlt")
48 #define ABORT_INSTRUCTION
51 extern void weak_function _stdio_term(void);
52 extern void _exit __P((int __status)) __attribute__ ((__noreturn__));
53 static int been_there_done_that = 0;
55 /* Be prepared in case multiple threads try to abort(). */
56 #ifdef __UCLIBC_HAS_THREADS__
58 static pthread_mutex_t mylock = PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP;
59 # define LOCK pthread_mutex_lock(&mylock)
60 # define UNLOCK pthread_mutex_unlock(&mylock);
67 /* Cause an abnormal program termination with core-dump. */
72 /* Make sure we acquire the lock before proceeding. */
75 /* Unmask SIGABRT to be sure we can get it */
76 if (__sigemptyset(&sigset) == 0 && __sigaddset(&sigset, SIGABRT) == 0) {
77 sigprocmask(SIG_UNBLOCK, &sigset, (sigset_t *) NULL);
80 /* If we are using stdio, try to shut it down. At the very least,
81 * this will attempt to commit all buffered writes. It may also
82 * unbuffer all writable files, or close them outright.
83 * Check the stdio routines for details. */
88 /* Try to suicide with a SIGABRT. */
89 if (been_there_done_that == 0) {
90 been_there_done_that++;
96 /* Still here? Try to remove any signal handlers. */
97 if (been_there_done_that == 1) {
100 been_there_done_that++;
101 memset (&act, '\0', sizeof (struct sigaction));
102 act.sa_handler = SIG_DFL;
103 __sigfillset (&act.sa_mask);
105 sigaction (SIGABRT, &act, NULL);
108 /* Still here? Try to suicide with an illegal instruction */
109 if (been_there_done_that == 2) {
110 been_there_done_that++;
114 /* Still here? Try to at least exit */
115 if (been_there_done_that == 3) {
116 been_there_done_that++;
120 /* Still here? We're screwed. Sleepy time. Good night */
122 /* Try for ever and ever. */