From 4e17946960e17b72d88898a04870380b69b61997 Mon Sep 17 00:00:00 2001 From: Sean Cross Date: Wed, 7 Jul 2021 14:32:36 +0800 Subject: [PATCH] kernel: riscv: ensure stack is 16-byte aligned Make sure processes are set up such that the stack is aligned to a 16-byte boundary. Signed-off-by: Sean Cross --- kernel/src/arch/riscv/process.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/kernel/src/arch/riscv/process.rs b/kernel/src/arch/riscv/process.rs index 385025d5b..e61ab4c4e 100644 --- a/kernel/src/arch/riscv/process.rs +++ b/kernel/src/arch/riscv/process.rs @@ -372,11 +372,15 @@ impl Process { 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 { + Err(xous_kernel::Error::BadAddress)?; + } crate::arch::syscall::invoke( thread, pid == 1, entrypoint, - setup.stack.as_ptr() as usize + setup.stack.len(), + (sp - 16) & !0xf, EXIT_THREAD, &[setup.arg1, setup.arg2, setup.arg3, setup.arg4], );