Skip to content

Commit

Permalink
kernel_riscv: log task name if a trap is taken from userspace
Browse files Browse the repository at this point in the history
  • Loading branch information
IsaacWoods committed Apr 4, 2024
1 parent ac34695 commit 2c06385
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions kernel/kernel_riscv/src/trap.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
use crate::interrupts;
use core::arch::asm;
use hal::memory::VAddr;
use hal_riscv::hw::csr::{Scause, Sepc, Stvec};
use hal::memory::{Frame, VAddr};
use hal_riscv::{
hw::csr::{Scause, Sepc, Stvec},
platform::kernel_map,
};
use tracing::info;

/// Install the proper trap handler. This handler is able to take traps from both S-mode and
Expand Down Expand Up @@ -44,6 +47,10 @@ extern "C" fn trap_handler(trap_frame: &mut TrapFrame, scause: usize, stval: usi
}
Ok(other) => {
info!("Trap! Cause = {:?}. Stval = {:#x?}", other, stval);
if trap_frame.sepc < usize::from(kernel_map::KERNEL_ADDRESS_SPACE_START) {
let cpu_scheduler = crate::SCHEDULER.get().for_this_cpu();
info!("Trap occurred in user task: {}", cpu_scheduler.running_task.as_ref().unwrap().name);
}
info!("Trap frame: {:#x?}", trap_frame);
panic!();
}
Expand Down

0 comments on commit 2c06385

Please sign in to comment.