mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-19 09:00:54 +00:00
kernel: services: don't crash when a process quits
When enumerating processes, the `find_process()` process didn't consult whether a process was actually free. This resulted in a crash, particularly when attaching a debugger to a crashed process. Signed-off-by: Sean Cross <sean@xobs.io>
This commit is contained in:
parent
6749f24b31
commit
2e88fb0620
1 changed files with 13 additions and 31 deletions
|
|
@ -509,47 +509,29 @@ impl SystemServices {
|
||||||
pub fn get_process(&self, pid: PID) -> Result<&Process, xous_kernel::Error> {
|
pub fn get_process(&self, pid: PID) -> Result<&Process, xous_kernel::Error> {
|
||||||
// PID0 doesn't exist -- process IDs are offset by 1.
|
// PID0 doesn't exist -- process IDs are offset by 1.
|
||||||
let pid_idx = pid.get() as usize - 1;
|
let pid_idx = pid.get() as usize - 1;
|
||||||
if cfg!(baremetal) && self.processes[pid_idx].mapping.get_pid() != pid {
|
if cfg!(baremetal) && self.processes[pid_idx].mapping.get_pid() != Some(pid) {
|
||||||
klog!(
|
Err(xous_kernel::Error::ProcessNotFound)
|
||||||
"Process doesn't match ({} vs {})",
|
} else if self.processes[pid_idx].state == ProcessState::Free {
|
||||||
self.processes[pid_idx].mapping.get_pid(),
|
Err(xous_kernel::Error::ProcessNotFound)
|
||||||
pid
|
} else {
|
||||||
);
|
Ok(&self.processes[pid_idx])
|
||||||
return Err(xous_kernel::Error::ProcessNotFound);
|
|
||||||
}
|
}
|
||||||
Ok(&self.processes[pid_idx])
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_process_mut(&mut self, pid: PID) -> Result<&mut Process, xous_kernel::Error> {
|
pub fn get_process_mut(&mut self, pid: PID) -> Result<&mut Process, xous_kernel::Error> {
|
||||||
// PID0 doesn't exist -- process IDs are offset by 1.
|
// PID0 doesn't exist -- process IDs are offset by 1.
|
||||||
let pid_idx = pid.get() as usize - 1;
|
let pid_idx = pid.get() as usize - 1;
|
||||||
|
if cfg!(baremetal) && self.processes[pid_idx].mapping.get_pid() != Some(pid) {
|
||||||
// if self.processes[pid_idx].mapping.get_pid() != pid {
|
Err(xous_kernel::Error::ProcessNotFound)
|
||||||
// println!(
|
} else if self.processes[pid_idx].state == ProcessState::Free {
|
||||||
// "Process doesn't match ({} vs {})",
|
Err(xous_kernel::Error::ProcessNotFound)
|
||||||
// self.processes[pid_idx].mapping.get_pid(),
|
} else {
|
||||||
// pid
|
Ok(&mut self.processes[pid_idx])
|
||||||
// );
|
}
|
||||||
// return Err(xous_kernel::Error::ProcessNotFound);
|
|
||||||
// }
|
|
||||||
Ok(&mut self.processes[pid_idx])
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn current_pid(&self) -> PID {
|
pub fn current_pid(&self) -> PID {
|
||||||
arch::process::current_pid()
|
arch::process::current_pid()
|
||||||
// PID0 doesn't exist -- process IDs are offset by 1.
|
|
||||||
// assert_eq!(
|
|
||||||
// self.processes[pid as usize - 1].mapping,
|
|
||||||
// MemoryMapping::current(),
|
|
||||||
// "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
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Create a stack frame in the specified process and jump to it.
|
/// Create a stack frame in the specified process and jump to it.
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue