Skip to content

Commit 57c1f22

Browse files
ycsindleach02
authored andcommitted
arch: riscv: stacktrace: fix user thread stack bound check
According to the riscv's `arch.h`: +------------+ <- thread.arch.priv_stack_start | Guard | } Z_RISCV_STACK_GUARD_SIZE +------------+ | Priv Stack | } CONFIG_PRIVILEGED_STACK_SIZE +------------+ <- thread.arch.priv_stack_start + CONFIG_PRIVILEGED_STACK_SIZE + Z_RISCV_STACK_GUARD_SIZE The start of the privilege stack should be: `thread.arch.priv_stack_start + Z_RISCV_STACK_GUARD_SIZE` Instead of `thread.arch.priv_stack_start - CONFIG_PRIVILEGED_STACK_SIZE` For the `end`, use the same equation of `top_of_priv_stack` in the `arch_user_mode_enter()` Signed-off-by: Yong Cong Sin <ycsin@meta.com> (cherry picked from commit 7db18ab)
1 parent dc7129b commit 57c1f22

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

arch/riscv/core/stacktrace.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,12 @@ static inline bool in_user_thread_stack_bound(uintptr_t addr, const struct k_thr
5858

5959
/* See: zephyr/include/zephyr/arch/riscv/arch.h */
6060
if (IS_ENABLED(CONFIG_PMP_POWER_OF_TWO_ALIGNMENT)) {
61-
start = thread->arch.priv_stack_start - CONFIG_PRIVILEGED_STACK_SIZE;
62-
end = thread->arch.priv_stack_start;
61+
start = thread->arch.priv_stack_start + Z_RISCV_STACK_GUARD_SIZE;
6362
} else {
6463
start = thread->stack_info.start - CONFIG_PRIVILEGED_STACK_SIZE;
65-
end = thread->stack_info.start;
6664
}
65+
end = Z_STACK_PTR_ALIGN(thread->arch.priv_stack_start + K_KERNEL_STACK_RESERVED +
66+
CONFIG_PRIVILEGED_STACK_SIZE);
6767

6868
return (addr >= start) && (addr < end);
6969
}

0 commit comments

Comments
 (0)