summaryrefslogtreecommitdiff
path: root/minix/lib/libsys/panic.c
blob: 6b6bbf3e97483a3cf28160981e04df23d46578aa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#include <stdlib.h>
#include <signal.h>
#include <unistd.h>
#include <stdarg.h>
#include <minix/sysutil.h>

#include "syslib.h"

void panic_hook(void);

__weak_alias(panic_hook, __panic_hook);

void __panic_hook(void)
{
	;
}

/*===========================================================================*
 *				panic				     *
 *===========================================================================*/
void panic(const char *fmt, ...)
{
/* 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];
  int priv_flags;
  int init_flags;
  void (*suicide)(void);
  va_list args;

  if(sys_whoami(&me, name, sizeof(name), &priv_flags, &init_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();

  panic_hook();

  /* 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(;;) { }
}