From 8975c0a33ea433c0371c22e65ccbd6b683219ddd Mon Sep 17 00:00:00 2001 From: Wayne Ren Date: Mon, 2 Mar 2020 13:45:34 +0800 Subject: [PATCH] arch: arc: the stack checking should consider the case of SMP the old codes just work for single core, we need to consider the case of SMP. In SMP, it's not easy to get current thread of current cpu in assembly, so we'd better do it in C. Signed-off-by: Wayne Ren --- arch/arc/core/thread.c | 4 ++-- arch/arc/core/userspace.S | 6 +++--- arch/arc/include/kernel_arch_func.h | 3 ++- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/arch/arc/core/thread.c b/arch/arc/core/thread.c index fdd8d81bd55..d36b8e60677 100644 --- a/arch/arc/core/thread.c +++ b/arch/arc/core/thread.c @@ -268,8 +268,8 @@ FUNC_NORETURN void arch_user_mode_enter(k_thread_entry_t user_entry, configure_mpu_thread(_current); z_arc_userspace_enter(user_entry, p1, p2, p3, - (u32_t)_current->stack_obj, - _current->stack_info.size); + (u32_t)_current->stack_obj, + _current->stack_info.size, _current); CODE_UNREACHABLE; } diff --git a/arch/arc/core/userspace.S b/arch/arc/core/userspace.S index 03e4ffaf694..aa266d49cc2 100644 --- a/arch/arc/core/userspace.S +++ b/arch/arc/core/userspace.S @@ -123,11 +123,11 @@ _clear_user_stack: jlt _clear_user_stack /* reload the stack checking regs as the original kernel stack - * becomess user stack + * becomes user stack */ #ifdef CONFIG_ARC_STACK_CHECKING - mov_s r1, _kernel - ld_s r2, [r1, _kernel_offset_to_current] +/* current thread in r6, SMP case is also considered */ + mov r2, r6 _load_stack_check_regs diff --git a/arch/arc/include/kernel_arch_func.h b/arch/arc/include/kernel_arch_func.h index c0b235cac4f..06409a928e1 100644 --- a/arch/arc/include/kernel_arch_func.h +++ b/arch/arc/include/kernel_arch_func.h @@ -64,7 +64,8 @@ extern void z_thread_entry_wrapper(void); extern void z_user_thread_entry_wrapper(void); extern void z_arc_userspace_enter(k_thread_entry_t user_entry, void *p1, - void *p2, void *p3, u32_t stack, u32_t size); + void *p2, void *p3, u32_t stack, u32_t size, + struct k_thread *thread); extern void arch_switch(void *switch_to, void **switched_from);