From 573b3e6eae1e759fbc12ef5fdd7defe7a9276deb Mon Sep 17 00:00:00 2001 From: vasilito Date: Thu, 2 Jul 2026 22:24:23 +0300 Subject: [PATCH] fix: handle early-boot exceptions in excp_handler gracefully MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit excp_handler() called context::current() unconditionally, which panics with 'not inside of context' when no context exists yet (before context::init() runs in kmain/kmain_ap). On bare metal, a page fault during BSP's start() — e.g. ACPI table access or device MMIO — caused page_fault_handler() to return Err, falling through to excp_handler(), which then panicked at context::current() instead of reporting the actual fault. Replace context::current() with context::try_current(). When None, log the exception details (kind, code, faulting address) and panic with a descriptive message. This turns an uninformative cascading panic into a diagnostic one that reveals the real faulting address. --- src/context/signal.rs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/context/signal.rs b/src/context/signal.rs index 19f4ebc01f..a472bb69bd 100644 --- a/src/context/signal.rs +++ b/src/context/signal.rs @@ -74,7 +74,21 @@ pub fn signal_handler(token: &mut CleanLockToken) { pub fn excp_handler(excp: syscall::Exception) { let mut token = unsafe { CleanLockToken::new() }; - let current = context::current(); + let Some(current) = context::try_current() else { + // No context exists — this happens during early boot (before + // context::init() in kmain) or very early in AP startup. The + // exception details (page fault address, stack trace, etc.) have + // already been printed by the caller in the exception handler. + // There is no userspace context to deliver a signal to, so halt. + info!( + "excp_handler: no current context (early boot), CPU {}, kind {}, code {}, address {:#x}", + crate::cpu_id(), + excp.kind, + excp.code, + excp.address + ); + panic!("unhandled exception during early boot (no context)"); + }; let context = current.write(token.token());