secondary cache feature in vm.
[minix.git] / lib / libsys / panic.c
blob464101d81478db1f5bc701861f58a391c88fd4df
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 PUBLIC 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 void (*suicide)(void);
21 static int panicing= 0;
22 va_list args;
24 if(panicing) return;
25 panicing= 1;
27 if(sys_whoami(&me, name, sizeof(name)) == OK && me != NONE)
28 printf("%s(%d): panic: ", name, me);
29 else
30 printf("(sys_whoami failed): panic: ");
32 if(fmt) {
33 va_start(args, fmt);
34 vprintf(fmt, args);
35 va_end(args);
36 } else {
37 printf("no message\n");
39 printf("\n");
41 printf("syslib:panic.c: stacktrace: ");
42 util_stacktrace();
44 /* Try exit */
45 _exit(1);
47 /* Try to signal ourself */
48 abort();
50 /* If exiting nicely through PM fails for some reason, try to
51 * commit suicide. E.g., message to PM might fail due to deadlock.
53 suicide = (void (*)(void)) -1;
54 suicide();
56 /* If committing suicide fails for some reason, hang. */
57 for(;;) { }