mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-17 08:40:52 +00:00
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:
parent
d798962151
commit
f2e9d2b76c
1 changed files with 7 additions and 1 deletions
|
|
@ -414,11 +414,17 @@ impl Process {
|
||||||
// Create the new context and set it to run in the new address space.
|
// Create the new context and set it to run in the new address space.
|
||||||
let pid = self.pid.get();
|
let pid = self.pid.get();
|
||||||
let thread = self.thread_mut(new_tid);
|
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();
|
let sp = setup.stack.as_ptr() as usize + setup.stack.len();
|
||||||
if sp <= 16 {
|
if sp <= 16 {
|
||||||
return Err(xous_kernel::Error::BadAddress);
|
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(
|
crate::arch::syscall::invoke(
|
||||||
thread,
|
thread,
|
||||||
pid == 1,
|
pid == 1,
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue