fix: handle early-boot exceptions in excp_handler gracefully
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.
This commit is contained in:
+13
-1
@@ -74,7 +74,19 @@ 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 {
|
||||
let kind = excp.kind;
|
||||
let code = excp.code;
|
||||
let address = excp.address;
|
||||
info!(
|
||||
"excp_handler: no current context (early boot), CPU {}, kind {}, code {}, address {:#x}",
|
||||
crate::cpu_id(),
|
||||
kind,
|
||||
code,
|
||||
address
|
||||
);
|
||||
panic!("unhandled exception during early boot (no context)");
|
||||
};
|
||||
|
||||
let context = current.write(token.token());
|
||||
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
#![cfg_attr(not(test), no_std)]
|
||||
|
||||
@@ -70,6 +70,8 @@ mod log;
|
||||
/// Memory management
|
||||
mod memory;
|
||||
|
||||
mod numa;
|
||||
|
||||
/// Panic
|
||||
mod panic;
|
||||
|
||||
|
||||
+1
-1
@@ -7,7 +7,7 @@ use core::sync::atomic::{AtomicBool, Ordering};
|
||||
|
||||
const MAX_NUMA_NODES: usize = 8;
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
#[derive(Debug)]
|
||||
pub struct NumaHint {
|
||||
pub node_id: u8,
|
||||
pub cpus: LogicalCpuSet,
|
||||
|
||||
Reference in New Issue
Block a user