kernel: implement panic()
This commit is contained in:
42
kernel/panic.c
Normal file
42
kernel/panic.c
Normal file
@@ -0,0 +1,42 @@
|
||||
#include <stdarg.h>
|
||||
#include <socks/machine/panic.h>
|
||||
#include <socks/libc/stdio.h>
|
||||
#include <socks/printk.h>
|
||||
#include <socks/sched.h>
|
||||
#include <socks/cpu.h>
|
||||
|
||||
static int has_panicked = 0;
|
||||
|
||||
void panic(const char *fmt, ...)
|
||||
{
|
||||
char buf[512];
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
vsnprintf(buf, sizeof(buf), fmt, args);
|
||||
va_end(args);
|
||||
|
||||
printk("---[ kernel panic: %s", buf);
|
||||
printk("kernel: " BUILD_ID ", compiler version: " __VERSION__);
|
||||
|
||||
task_t *task = current_task();
|
||||
thread_t *thr = current_thread();
|
||||
|
||||
if (task && thr) {
|
||||
printk("task: %s (id: %d, thread: %d)", task->t_name, task->t_id, thr->tr_id);
|
||||
} else {
|
||||
printk("task: [bootstrap]");
|
||||
}
|
||||
|
||||
printk("cpu: %u", this_cpu());
|
||||
|
||||
ml_print_cpu_state(NULL);
|
||||
|
||||
if (READ_ONCE(has_panicked)) {
|
||||
ml_halt_cpu();
|
||||
}
|
||||
|
||||
WRITE_ONCE(has_panicked, 1);
|
||||
|
||||
printk("---[ end kernel panic: %s", buf);
|
||||
ml_halt_cpu();
|
||||
}
|
||||
Reference in New Issue
Block a user