From 9a10f50ce1118dbb1e8b015c0489174cbe074a1c Mon Sep 17 00:00:00 2001 From: Sean Cross Date: Sat, 14 Mar 2020 21:28:01 +0800 Subject: [PATCH] kernel: services: keep track of current pid Currently we use the ASID inside the MMU to figure out the current PID. We should also keep track of what we think it is, for consistency. Signed-off-by: Sean Cross --- kernel/src/services.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/kernel/src/services.rs b/kernel/src/services.rs index 30240427e..d4f332993 100644 --- a/kernel/src/services.rs +++ b/kernel/src/services.rs @@ -142,6 +142,9 @@ pub struct InitialProcess { /// A big unifying struct containing all of the system state. /// This is inherited from the stage 1 bootloader. pub struct SystemServices { + /// Current PID + pid: PID, + /// A table of all processes in the system pub processes: [Process; MAX_PROCESS_COUNT], @@ -150,6 +153,7 @@ pub struct SystemServices { } static mut SYSTEM_SERVICES: SystemServices = SystemServices { + pid: 1 as PID, processes: [Process { state: ProcessState::Free, ppid: 0, @@ -264,6 +268,11 @@ impl SystemServices { "process memory map doesn't match -- current_pid: {}", pid ); + assert_eq!( + pid, self.pid, + "current pid {} doesn't match arch pid: {}", + self.pid, pid + ); pid as PID } @@ -315,6 +324,7 @@ impl SystemServices { // Switch to new process memory space, allowing us to save the context // if necessary. process.mapping.activate(); + self.pid = pid; let context = ProcessContext::current(); @@ -347,6 +357,7 @@ impl SystemServices { // Save state if the PID has changed let context = if pid != previous_pid { let context = { + self.pid = pid; let new = self.get_process_mut(pid)?; match new.state { ProcessState::Free => return Err(xous::Error::ProcessNotFound),