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 */
21 #define sigaction __sigaction
34 /* Our last ditch effort to commit suicide */
35 #if defined(__alpha__)
36 #define ABORT_INSTRUCTION asm ("call_pal 0")
37 #elif defined(__hppa__)
38 #define ABORT_INSTRUCTION asm ("iitlbp %r0,(%r0)")
39 #elif defined(__i386__)
40 #define ABORT_INSTRUCTION asm ("hlt")
41 #elif defined(__ia64__)
42 #define ABORT_INSTRUCTION asm ("break 0")
43 #elif defined(__m68k__)
44 #define ABORT_INSTRUCTION asm ("illegal")
45 #elif defined(__mc68000__)
46 #define ABORT_INSTRUCTION asm (".long 0xffffffff")
47 #elif defined(__mips__)
48 #define ABORT_INSTRUCTION asm ("break 255")
49 #elif defined(__powerpc__)
50 #define ABORT_INSTRUCTION asm (".long 0")
51 #elif defined(__s390__)
52 #define ABORT_INSTRUCTION asm (".word 0")
53 #elif defined(__sparc__)
54 #define ABORT_INSTRUCTION asm ("unimp 0xf00")
55 #elif defined(__SH5__)
56 #define ABORT_INSTRUCTION asm ("movi 0x10, r9; shori 0xff, r9; trapa r9")
57 #elif defined(__sh2__)
58 #define ABORT_INSTRUCTION asm ("trapa #32")
60 #define ABORT_INSTRUCTION asm ("trapa #0xff")
61 #elif defined(__x86_64__)
62 #define ABORT_INSTRUCTION asm ("hlt")
64 #define ABORT_INSTRUCTION
65 #warning no abort instruction define for your arch
68 #ifdef __UCLIBC_HAS_STDIO_SHUTDOWN_ON_ABORT__
69 extern void weak_function _stdio_term(void);
71 extern void _exit __P((int __status)) __attribute__ ((__noreturn__));
72 static int been_there_done_that = 0;
74 /* Be prepared in case multiple threads try to abort() */
75 #ifdef __UCLIBC_HAS_THREADS__
77 static pthread_mutex_t mylock = PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP;
79 #define LOCK __pthread_mutex_lock(&mylock)
80 #define UNLOCK __pthread_mutex_unlock(&mylock)
83 extern int __raise (int __sig) __THROW attribute_hidden;
84 /* Cause an abnormal program termination with core-dump */
89 /* Make sure we acquire the lock before proceeding */
92 /* Unmask SIGABRT to be sure we can get it */
93 if (__sigemptyset(&sigset) == 0 && __sigaddset(&sigset, SIGABRT) == 0) {
94 __sigprocmask(SIG_UNBLOCK, &sigset, (sigset_t *) NULL);
98 /* Try to suicide with a SIGABRT */
99 if (been_there_done_that == 0) {
100 been_there_done_that++;
102 #ifdef __UCLIBC_HAS_STDIO_SHUTDOWN_ON_ABORT__
103 /* If we are using stdio, try to shut it down. At the very least,
104 * this will attemt to commit all buffered writes. It may also
105 * unboffer all writable files, or close them outright.
106 * Check the stdio routines for details. */
118 /* Still here? Try to remove any signal handlers */
119 if (been_there_done_that == 1) {
120 struct sigaction act;
122 been_there_done_that++;
123 __memset(&act, '\0', sizeof(struct sigaction));
124 act.sa_handler = SIG_DFL;
125 __sigfillset(&act.sa_mask);
127 sigaction(SIGABRT, &act, NULL);
132 /* Still here? Try to suicide with an illegal instruction */
133 if (been_there_done_that == 2) {
134 been_there_done_that++;
138 /* Still here? Try to at least exit */
139 if (been_there_done_that == 3) {
140 been_there_done_that++;
144 /* Still here? We're screwed. Sleepy time. Good night. */
146 /* Try for ever and ever */