diff --git a/kernel/Cargo.lock b/kernel/Cargo.lock index f63e1dd0..b1ba04c8 100644 --- a/kernel/Cargo.lock +++ b/kernel/Cargo.lock @@ -514,6 +514,7 @@ dependencies = [ "rcore-fs-sfs", "rcore-memory", "riscv", + "rkprobes", "rlibc", "rvm", "smoltcp", @@ -642,6 +643,12 @@ dependencies = [ "riscv-target", ] +[[package]] +name = "riscv-decode" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "920466101a1ec4ffac2ab9b72fa780eff62defa0ae9c4f77a07fa41dfd5450e6" + [[package]] name = "riscv-target" version = "0.1.2" @@ -652,6 +659,18 @@ dependencies = [ "regex", ] +[[package]] +name = "rkprobes" +version = "0.1.0" +source = "git+https://github.com/hm1229/rkprobes?rev=d6e0f96#d6e0f962618329315f7806cec66f2891822e8999" +dependencies = [ + "lazy_static", + "log", + "riscv-decode", + "spin", + "trapframe", +] + [[package]] name = "rlibc" version = "1.0.0" diff --git a/kernel/Cargo.toml b/kernel/Cargo.toml index 2cc0e74c..7ffa74e7 100644 --- a/kernel/Cargo.toml +++ b/kernel/Cargo.toml @@ -90,6 +90,7 @@ x86_64 = "0.11" [target.'cfg(any(target_arch = "riscv32", target_arch = "riscv64"))'.dependencies] riscv = { git = "https://github.com/rcore-riscv-hypervisor-dev/riscv" , rev = "3f5efb1", features = ["inline-asm", "hypervisor"] } +rkprobes = { git = "https://github.com/hm1229/rkprobes", rev = "d6e0f96" } [target.'cfg(target_arch = "aarch64")'.dependencies] aarch64 = { git = "https://github.com/rcore-os/aarch64", version = "3.0.1" } diff --git a/kernel/src/arch/riscv/interrupt/mod.rs b/kernel/src/arch/riscv/interrupt/mod.rs index cb320a6a..fe64d982 100644 --- a/kernel/src/arch/riscv/interrupt/mod.rs +++ b/kernel/src/arch/riscv/interrupt/mod.rs @@ -36,12 +36,12 @@ pub unsafe fn restore(flags: usize) { /// This function is called from `trap.asm`. #[no_mangle] pub extern "C" fn trap_handler(tf: &mut TrapFrame) { - trap_handler_no_frame(&mut tf.sepc); + trap_handler_no_frame(tf); } use crate::memory::AccessType; #[inline] -pub fn trap_handler_no_frame(sepc: &mut usize) { +pub fn trap_handler_no_frame(tf: &mut TrapFrame) { use self::scause::{Exception as E, Interrupt as I, Trap}; let scause = scause::read(); let stval = stval::read(); @@ -51,11 +51,12 @@ pub fn trap_handler_no_frame(sepc: &mut usize) { Trap::Interrupt(I::SupervisorExternal) => external(), Trap::Interrupt(I::SupervisorSoft) => ipi(), Trap::Interrupt(I::SupervisorTimer) => timer(), - Trap::Exception(E::LoadPageFault) => page_fault(stval, sepc, AccessType::read(is_user)), - Trap::Exception(E::StorePageFault) => page_fault(stval, sepc, AccessType::write(is_user)), + Trap::Exception(E::LoadPageFault) => page_fault(stval, &mut tf.sepc, AccessType::read(is_user)), + Trap::Exception(E::StorePageFault) => page_fault(stval, &mut tf.sepc, AccessType::write(is_user)), Trap::Exception(E::InstructionPageFault) => { - page_fault(stval, sepc, AccessType::execute(is_user)) + page_fault(stval, &mut tf.sepc, AccessType::execute(is_user)) } + Trap::Exception(E::Breakpoint) => rkprobes::kprobes_trap_handler(tf), _ => { let bits = scause.bits(); panic!("unhandled trap {:?} ({})", scause.cause(), bits); diff --git a/kernel/src/lib.rs b/kernel/src/lib.rs index 06f57dfe..dec7486a 100644 --- a/kernel/src/lib.rs +++ b/kernel/src/lib.rs @@ -8,7 +8,6 @@ #![feature(negative_impls)] #![feature(alloc_prelude)] #![feature(const_fn)] -#![feature(const_if_match)] #![feature(const_in_array_repeat_expressions)] #![deny(unused_must_use)] #![deny(stable_features)]