From ecbce84385402a48dc00cff0928a863e29da3dda Mon Sep 17 00:00:00 2001 From: bunnie Date: Sun, 31 Mar 2024 17:21:54 +0800 Subject: [PATCH] add some debug & add state visibility @xobs made the `state` element of a process publicly read-only visible through a function call. I don't think this is a security issue but please lmk if that's a problem. --- kernel/src/services.rs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/kernel/src/services.rs b/kernel/src/services.rs index f6d59946e..547ef0608 100644 --- a/kernel/src/services.rs +++ b/kernel/src/services.rs @@ -265,6 +265,9 @@ impl Process { self.state = ProcessState::Free; Ok(()) } + + /// Reveal state for debugging outside the crate. + pub fn state(&self) -> ProcessState { self.state } } #[cfg(not(baremetal))] @@ -679,6 +682,12 @@ impl SystemServices { ); } CallbackType::Swap(args) => { + #[cfg(feature = "debug-swap")] + { + let pid = crate::arch::process::current_pid(); + let hardware_pid = (riscv::register::satp::read().bits() >> 22) & ((1 << 9) - 1); + println!("bef invoke PROCESS_TABLE.current: {}, hw_pid: {}", pid.get(), hardware_pid); + } arch::syscall::invoke( arch_process.current_thread_mut(), pid.get() == 1,