VM: simplify slab allocator
[minix.git] / lib / libsys / panic.c
blob711859bf9a4c39ba2dd1237c3a190d3685bdf6ba
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 #ifndef __NBSD_LIBC
45 /* Try to signal ourself */
46 abort();
47 #endif
49 /* If exiting nicely through PM fails for some reason, try to
50 * commit suicide. E.g., message to PM might fail due to deadlock.
52 suicide = (void (*)(void)) -1;
53 suicide();
55 /* If committing suicide fails for some reason, hang. */
56 for(;;) { }