2005-10-17 15:19:22 +02:00
|
|
|
#include <stdlib.h>
|
2006-03-15 13:06:18 +01:00
|
|
|
#include <signal.h>
|
2009-08-17 19:56:34 +02:00
|
|
|
#include <unistd.h>
|
2010-03-05 16:05:11 +01:00
|
|
|
#include <stdarg.h>
|
2006-03-15 13:06:18 +01:00
|
|
|
#include <minix/sysutil.h>
|
2005-10-17 15:19:22 +02:00
|
|
|
|
2006-03-15 13:06:18 +01:00
|
|
|
#include "syslib.h"
|
2005-04-21 16:53:53 +02:00
|
|
|
|
|
|
|
/*===========================================================================*
|
2010-03-05 16:05:11 +01: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.
|
|
|
|
*/
|
2008-11-19 13:26:10 +01:00
|
|
|
endpoint_t me = NONE;
|
|
|
|
char name[20];
|
2010-07-07 00:05:21 +02:00
|
|
|
int priv_flags;
|
2005-10-17 15:19:22 +02:00
|
|
|
void (*suicide)(void);
|
2010-03-05 16:05:11 +01:00
|
|
|
va_list args;
|
|
|
|
|
2010-07-07 00:05:21 +02:00
|
|
|
if(sys_whoami(&me, name, sizeof(name), &priv_flags) == OK && me != NONE)
|
2010-03-05 16:05:11 +01:00
|
|
|
printf("%s(%d): panic: ", name, me);
|
2008-11-19 13:26:10 +01:00
|
|
|
else
|
2010-03-05 16:05:11 +01:00
|
|
|
printf("(sys_whoami failed): panic: ");
|
|
|
|
|
|
|
|
if(fmt) {
|
|
|
|
va_start(args, fmt);
|
|
|
|
vprintf(fmt, args);
|
2010-03-08 15:36:55 +01:00
|
|
|
va_end(args);
|
2010-03-05 16:05:11 +01:00
|
|
|
} else {
|
|
|
|
printf("no message\n");
|
|
|
|
}
|
|
|
|
printf("\n");
|
|
|
|
|
2008-11-19 13:26:10 +01:00
|
|
|
printf("syslib:panic.c: stacktrace: ");
|
|
|
|
util_stacktrace();
|
|
|
|
|
2007-04-23 14:13:51 +02:00
|
|
|
/* Try exit */
|
|
|
|
_exit(1);
|
|
|
|
|
|
|
|
/* Try to signal ourself */
|
|
|
|
abort();
|
|
|
|
|
2005-10-17 15:19:22 +02:00
|
|
|
/* 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
|
|
|
}
|
|
|
|
|