minix/lib/libsys/panic.c

57 lines
1.3 KiB
C
Raw Normal View History

#include <stdlib.h>
#include <signal.h>
2009-08-17 19:56:34 +02:00
#include <unistd.h>
#include <stdarg.h>
#include <minix/sysutil.h>
#include "syslib.h"
2005-04-21 16:53:53 +02:00
/*===========================================================================*
* panic *
2005-04-21 16:53:53 +02:00
*===========================================================================*/
2012-03-25 20:25:53 +02:00
void panic(const char *fmt, ...)
2005-04-21 16:53:53 +02:00
{
/* Something awful has happened. Panics are caused when an internal
* inconsistency is detected, e.g., a programming error or illegal
* value of a defined constant.
*/
endpoint_t me = NONE;
char name[20];
2010-07-07 00:05:21 +02:00
int priv_flags;
void (*suicide)(void);
va_list args;
2010-07-07 00:05:21 +02:00
if(sys_whoami(&me, name, sizeof(name), &priv_flags) == OK && me != NONE)
printf("%s(%d): panic: ", name, me);
else
printf("(sys_whoami failed): panic: ");
if(fmt) {
va_start(args, fmt);
vprintf(fmt, args);
va_end(args);
} else {
printf("no message\n");
}
printf("\n");
printf("syslib:panic.c: stacktrace: ");
util_stacktrace();
/* Try exit */
_exit(1);
/* Try to signal ourself */
abort();
/* If exiting nicely through PM fails for some reason, try to
* commit suicide. E.g., message to PM might fail due to deadlock.
*/
suicide = (void (*)(void)) -1;
suicide();
/* If committing suicide fails for some reason, hang. */
for(;;) { }
2005-04-21 16:53:53 +02:00
}