From b60e09062d4c83c2e70fefb5f26110089cb2699f Mon Sep 17 00:00:00 2001 From: Daniel Leung Date: Wed, 27 Mar 2024 15:00:27 -0700 Subject: [PATCH] cmsis_rtos_v1: support memory mapped stack at abort hook This extends the thread abort hook to support memory mapped stack. The calculation to find out to which instance of thread pools the outgoing thread belongs requires physical address. So find the physical address via the memory mapped stack for that. Signed-off-by: Daniel Leung --- subsys/portability/cmsis_rtos_v1/cmsis_thread.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/subsys/portability/cmsis_rtos_v1/cmsis_thread.c b/subsys/portability/cmsis_rtos_v1/cmsis_thread.c index 6ce53fe719..41752a5179 100644 --- a/subsys/portability/cmsis_rtos_v1/cmsis_thread.c +++ b/subsys/portability/cmsis_rtos_v1/cmsis_thread.c @@ -47,7 +47,17 @@ void thread_abort_hook(struct k_thread *thread) if (thread_def != NULL) { /* get thread instance index according to stack address */ - offset = thread->stack_info.start - (uintptr_t)thread_def->stack_mem; + uintptr_t stack_start; + +#ifdef CONFIG_THREAD_STACK_MEM_MAPPED + /* The offset calculation below requires physical address. */ + extern int arch_page_phys_get(void *virt, uintptr_t *phys); + (void)arch_page_phys_get((void *)thread->stack_info.start, &stack_start); +#else + stack_start = thread->stack_info.start; +#endif /* CONFIG_THREAD_STACK_MEM_MAPPED */ + + offset = stack_start - (uintptr_t)thread_def->stack_mem; instance = offset / K_THREAD_STACK_LEN(CONFIG_CMSIS_THREAD_MAX_STACK_SIZE); sys_bitarray_clear_bit((sys_bitarray_t *)(thread_def->status_mask), instance); }