From d109805cb2f31d17f4d9a9f8062d746afb038074 Mon Sep 17 00:00:00 2001 From: Shih-Wei Teng Date: Wed, 6 Jan 2021 14:50:21 +0800 Subject: [PATCH] RISC-V: Round up pre-populated stack frame to arch stack alignment The stack frame size, used for context switch, is rounded up to 16-bytes alignment. Therefore, we need round down the pointer of top of the pre-populated stack frame so that the preserved stack frame size is also rounded up to 16-bytes alignment. Fixes #29535 Signed-off-by: Shih-Wei Teng --- arch/riscv/core/thread.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/arch/riscv/core/thread.c b/arch/riscv/core/thread.c index 54f08660718..9ad30a4b223 100644 --- a/arch/riscv/core/thread.c +++ b/arch/riscv/core/thread.c @@ -37,7 +37,9 @@ void arch_new_thread(struct k_thread *thread, k_thread_stack_t *stack, #endif /* Initial stack frame for thread */ - stack_init = Z_STACK_PTR_TO_FRAME(struct __esf, stack_ptr); + stack_init = (struct __esf *)Z_STACK_PTR_ALIGN( + Z_STACK_PTR_TO_FRAME(struct __esf, stack_ptr) + ); /* Setup the initial stack frame */ stack_init->a0 = (ulong_t)entry;