feat(ke/panic): add panic lock

This commit is contained in:
Loïc Grégoire
2026-05-02 12:14:45 -04:00
parent 07cc976467
commit c82f9759b4
2 changed files with 7 additions and 1 deletions
+1
View File
@@ -48,6 +48,7 @@ export fn isr_handler_main(frame: *const amd64.IrqFrame) callconv(.{ .x86_64_sys
const ipl = ke.ipl.set_hardware(.Device);
if (frame.intno < 32) {
ki.panic.panic_lock.acquire_no_ipl();
std.log.err("Unhandled exception: 0x{x} ({s}), err=0x{x}, pc=0x{x}", .{ frame.intno, exception_msg[frame.intno], frame.errcode, frame.rip });
std.log.err("RAX=0x{x:0>16} RBX=0x{x:0>16} RCX=0x{x:0>16} RDX=0x{x:0>16}", .{ frame.rax, frame.rbx, frame.rcx, frame.rdx });
std.log.err("RSI=0x{x:0>16} RDI=0x{x:0>16} RBP=0x{x:0>16} RSP=0x{x:0>16}", .{ frame.rsi, frame.rdi, frame.rbp, frame.rsp });
+6 -1
View File
@@ -70,14 +70,18 @@ fn walk_stack_frame(base: usize) void {
}
}
pub var panic_lock: ke.SpinLock = .init();
pub fn panic_with_frame(
msg: []const u8,
frame: usize,
) noreturn {
std.log.err("KERNEL PANIC: {s}", .{msg});
std.log.err("KERNEL PANIC: {s} on CPU {}, curthread is {*}", .{ msg, ke.cpu.current(), ki.sched.percpu.local().current_thread.? });
std.log.err("Stack trace:", .{});
walk_stack_frame(frame);
panic_lock.release_no_ipl();
while (true) {}
}
@@ -88,5 +92,6 @@ pub fn panic(
if (config.arch == .um) {
std.debug.defaultPanic(msg, first_trace_addr);
}
panic_lock.acquire_no_ipl();
panic_with_frame(msg, @frameAddress());
}