From d6c67c555f4e4e38a83b07271a39f0e1fd7bdb80 Mon Sep 17 00:00:00 2001 From: Yanfeng Liu Date: Tue, 16 Jul 2024 14:41:04 +0800 Subject: [PATCH] riscv/trap: fix sp restore logic This fixes stack pointer restore logic to avoid parent stack corruption by forked child in PROTECTED build. Signed-off-by: Yanfeng Liu --- arch/risc-v/src/common/riscv_exception_common.S | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/arch/risc-v/src/common/riscv_exception_common.S b/arch/risc-v/src/common/riscv_exception_common.S index 9035947031404..7bcf2d2d72ac9 100644 --- a/arch/risc-v/src/common/riscv_exception_common.S +++ b/arch/risc-v/src/common/riscv_exception_common.S @@ -231,7 +231,11 @@ return_from_exception: load_ctx sp +#ifdef CONFIG_ARCH_KERNEL_STACK REGLOAD sp, REG_SP(sp) /* restore original sp */ +#else + addi sp, sp, XCPTCONTEXT_SIZE +#endif /* Return from exception */