kernel: riscv: threads: ensure registers are zeroed

The register set should be cleared already, however it is possible
(though remote) that register values are not cleared when a thread is
created.

Ordinarily threads are zeroed when destroyed, but this makes sure
they're zeroed upon creation as well.

Signed-off-by: Sean Cross <sean@xobs.io>
This commit is contained in:
Sean Cross 2023-12-25 23:29:20 +08:00
parent d798962151
commit f2e9d2b76c

View file

@ -414,11 +414,17 @@ impl Process {
// Create the new context and set it to run in the new address space.
let pid = self.pid.get();
let thread = self.thread_mut(new_tid);
// println!("Setting up thread {}, pid {}", new_tid, pid);
let sp = setup.stack.as_ptr() as usize + setup.stack.len();
if sp <= 16 {
return Err(xous_kernel::Error::BadAddress);
}
// Zero out the thread registers, including special ones like `$tp`.
// This should already have been done by the destructor, but do it
// again anyway.
for val in &mut thread.registers {
*val = 0;
}
thread.sepc = 0;
crate::arch::syscall::invoke(
thread,
pid == 1,