summaryrefslogtreecommitdiffstats
path: root/libc/stdlib/abort.c
diff options
context:
space:
mode:
Diffstat (limited to 'libc/stdlib/abort.c')
-rw-r--r--libc/stdlib/abort.c129
1 files changed, 75 insertions, 54 deletions
diff --git a/libc/stdlib/abort.c b/libc/stdlib/abort.c
index e34c86778..77c2cdc69 100644
--- a/libc/stdlib/abort.c
+++ b/libc/stdlib/abort.c
@@ -30,99 +30,120 @@ Cambridge, MA 02139, USA. */
/* Our last ditch effort to commit suicide */
-#if defined(__i386__)
+#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(__x86_64__)
-#define ABORT_INSTRUCTION asm ("hlt")
-#elif defined(__hppa__)
-#define ABORT_INSTRUCTION asm ("iitlbp %r0,(%r0)")
-#elif defined(__powerpc__)
-#define ABORT_INSTRUCTION asm (".long 0")
#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;
-/* Be prepared in case multiple threads try to abort(). */
+/* Be prepared in case multiple threads try to abort() */
#ifdef __UCLIBC_HAS_THREADS__
-#include <pthread.h>
+# 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);
+# define UNLOCK __pthread_mutex_unlock(&mylock)
#else
# define LOCK
# define UNLOCK
#endif
-/* Cause an abnormal program termination with core-dump. */
+/* Cause an abnormal program termination with core-dump */
void abort(void)
{
- sigset_t sigset;
-
- /* Make sure we acquire the lock before proceeding. */
- LOCK;
-
- /* Unmask SIGABRT to be sure we can get it */
- if (__sigemptyset(&sigset) == 0 && __sigaddset(&sigset, SIGABRT) == 0) {
- sigprocmask(SIG_UNBLOCK, &sigset, (sigset_t *) NULL);
- }
-
- while (1) {
- /* Try to suicide with a SIGABRT. */
- if (been_there_done_that == 0) {
- been_there_done_that++;
- UNLOCK;
- raise(SIGABRT);
- LOCK;
- }
+ sigset_t sigset;
- /* Still here? Try to remove any signal handlers. */
- if (been_there_done_that == 1) {
- struct sigaction act;
+ /* Make sure we acquire the lock before proceeding */
+ LOCK;
- 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);
+ /* Unmask SIGABRT to be sure we can get it */
+ if (__sigemptyset(&sigset) == 0 && __sigaddset(&sigset, SIGABRT) == 0) {
+ sigprocmask(SIG_UNBLOCK, &sigset, (sigset_t *) NULL);
}
- /* Still here? Try to suicide with an illegal instruction */
- if (been_there_done_that == 2) {
- been_there_done_that++;
- ABORT_INSTRUCTION;
- }
+ while (1) {
+ /* Try to suicide with a SIGABRT */
+ if (been_there_done_that == 0) {
+ been_there_done_that++;
+
+#ifdef __UCLIBC_HAS_STDIO_SHUTDOWN_ON_ABORT__
+ /* If we are using stdio, try to shut it down. At the very least,
+ * this will attemt to commit all buffered writes. It may also
+ * unboffer all writable files, or close them outright.
+ * Check the stdio routines for details. */
+ if (_stdio_term) {
+ _stdio_term();
+ }
+#endif
- /* Still here? Try to at least exit */
- if (been_there_done_that == 3) {
- been_there_done_that++;
- _exit (127);
+abort_it:
+ UNLOCK;
+ raise(SIGABRT);
+ LOCK;
+ }
+
+ /* Still here? Try to remove any signal handlers */
+ 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;
+ }
+
+ /* Still here? Try to suicide with an illegal instruction */
+ if (been_there_done_that == 2) {
+ been_there_done_that++;
+ ABORT_INSTRUCTION;
+ }
+
+ /* Still here? Try to at least exit */
+ if (been_there_done_that == 3) {
+ been_there_done_that++;
+ _exit(127);
+ }
+
+ /* Still here? We're screwed. Sleepy time. Good night. */
+ while (1)
+ /* Try for ever and ever */
+ ABORT_INSTRUCTION;
}
-
- /* Still here? We're screwed. Sleepy time. Good night */
- while (1)
- /* Try for ever and ever. */
- ABORT_INSTRUCTION;
- }
}
-