arch: riscv: stacktrace: refactor fatal stack bound

Pass the current thread to `walk_stackframe()`, so that we do
not need to hardcode `_current` in `in_fatal_stack_bound()`,
which will allow it to reuse the `in_stack_bound()`

Signed-off-by: Yong Cong Sin <ycsin@meta.com>
This commit is contained in:
Yong Cong Sin 2024-06-19 16:57:07 +08:00 committed by Anas Nashif
parent e6d8ed2e0d
commit b79a68fc49

View file

@ -69,31 +69,6 @@ static inline bool in_user_thread_stack_bound(uintptr_t addr, const struct k_thr
}
#endif /* CONFIG_USERSPACE */
static bool in_fatal_stack_bound(uintptr_t addr, const struct k_thread *const thread,
const struct arch_esf *esf)
{
ARG_UNUSED(thread);
if (!IS_ALIGNED(addr, sizeof(uintptr_t))) {
return false;
}
if (_current == NULL || arch_is_in_isr()) {
/* We were servicing an interrupt */
uint8_t cpu_id = IS_ENABLED(CONFIG_SMP) ? arch_curr_cpu()->id : 0U;
return in_irq_stack_bound(addr, cpu_id);
}
#ifdef CONFIG_USERSPACE
if ((esf != NULL) && ((esf->mstatus & MSTATUS_MPP) == PRV_U) &&
((_current->base.user_options & K_USER) != 0)) {
return in_user_thread_stack_bound(addr, _current);
}
#endif /* CONFIG_USERSPACE */
return in_kernel_thread_stack_bound(addr, _current);
}
static bool in_stack_bound(uintptr_t addr, const struct k_thread *const thread,
const struct arch_esf *esf)
{
@ -112,6 +87,23 @@ static bool in_stack_bound(uintptr_t addr, const struct k_thread *const thread,
return in_kernel_thread_stack_bound(addr, thread);
}
static bool in_fatal_stack_bound(uintptr_t addr, const struct k_thread *const thread,
const struct arch_esf *esf)
{
if (!IS_ALIGNED(addr, sizeof(uintptr_t))) {
return false;
}
if ((thread == NULL) || arch_is_in_isr()) {
/* We were servicing an interrupt */
uint8_t cpu_id = IS_ENABLED(CONFIG_SMP) ? arch_curr_cpu()->id : 0U;
return in_irq_stack_bound(addr, cpu_id);
}
return in_stack_bound(addr, thread, esf);
}
static inline bool in_text_region(uintptr_t addr)
{
extern uintptr_t __text_region_start, __text_region_end;
@ -245,6 +237,6 @@ void z_riscv_unwind_stack(const struct arch_esf *esf, const _callee_saved_t *csf
int i = 0;
LOG_ERR("call trace:");
walk_stackframe(print_trace_address, &i, NULL, esf, in_fatal_stack_bound, csf);
walk_stackframe(print_trace_address, &i, _current, esf, in_fatal_stack_bound, csf);
LOG_ERR("");
}