__aeabi_ldivmod: fix sign logic
[minix.git] / lib / libsys / panic.c
blob79c47bce20afcd1dd19e184350f499f8ee0d7511
1 #include <stdlib.h>
2 #include <signal.h>
3 #include <unistd.h>
4 #include <stdarg.h>
5 #include <minix/sysutil.h>
7 #include "syslib.h"
9 /*===========================================================================*
10 * panic *
11 *===========================================================================*/
12 void panic(const char *fmt, ...)
14 /* Something awful has happened. Panics are caused when an internal
15 * inconsistency is detected, e.g., a programming error or illegal
16 * value of a defined constant.
18 endpoint_t me = NONE;
19 char name[20];
20 int priv_flags;
21 void (*suicide)(void);
22 va_list args;
24 if(sys_whoami(&me, name, sizeof(name), &priv_flags) == OK && me != NONE)
25 printf("%s(%d): panic: ", name, me);
26 else
27 printf("(sys_whoami failed): panic: ");
29 if(fmt) {
30 va_start(args, fmt);
31 vprintf(fmt, args);
32 va_end(args);
33 } else {
34 printf("no message\n");
36 printf("\n");
38 printf("syslib:panic.c: stacktrace: ");
39 util_stacktrace();
41 /* Try exit */
42 _exit(1);
44 /* Try to signal ourself */
45 abort();
47 /* If exiting nicely through PM fails for some reason, try to
48 * commit suicide. E.g., message to PM might fail due to deadlock.
50 suicide = (void (*)(void)) -1;
51 suicide();
53 /* If committing suicide fails for some reason, hang. */
54 for(;;) { }