From 8eaff5d6d20c28923e50ff037d44692dee9e8648 Mon Sep 17 00:00:00 2001 From: Andrew Boie Date: Mon, 28 Aug 2017 16:02:24 -0700 Subject: [PATCH] k_thread_abort(): assert if abort essential thread Previously, this was only done if an essential thread self-exited, and was a runtime check that generated a kernel panic. Now if any thread has k_thread_abort() called on it, and that thread is essential to the system operation, this check is made. It is now an assertion. _NANO_ERR_INVALID_TASK_EXIT checks and printouts removed since this is now an assertion. Signed-off-by: Andrew Boie --- arch/arc/core/fatal.c | 4 ---- arch/arm/core/fatal.c | 4 ---- arch/arm/core/thread_abort.c | 4 ++++ arch/nios2/core/fatal.c | 5 ----- arch/riscv32/core/fatal.c | 4 ---- arch/x86/core/fatal.c | 4 ---- arch/xtensa/core/fatal.c | 3 --- include/arch/arc/v2/error.h | 1 - include/arch/arm/cortex_m/error.h | 1 - include/arch/nios2/arch.h | 1 - include/arch/riscv32/exp.h | 1 - include/arch/x86/arch.h | 2 -- include/arch/xtensa/arch.h | 1 - kernel/thread.c | 4 ---- kernel/thread_abort.c | 4 ++++ 15 files changed, 8 insertions(+), 35 deletions(-) diff --git a/arch/arc/core/fatal.c b/arch/arc/core/fatal.c index bc961534005..9ae2548277b 100644 --- a/arch/arc/core/fatal.c +++ b/arch/arc/core/fatal.c @@ -44,10 +44,6 @@ FUNC_NORETURN void _NanoFatalErrorHandler(unsigned int reason, case _NANO_ERR_HW_EXCEPTION: break; - case _NANO_ERR_INVALID_TASK_EXIT: - printk("***** Invalid Exit Software Error! *****\n"); - break; - #if defined(CONFIG_STACK_CANARIES) || defined(CONFIG_ARC_STACK_CHECKING) case _NANO_ERR_STACK_CHK_FAIL: printk("***** Stack Check Fail! *****\n"); diff --git a/arch/arm/core/fatal.c b/arch/arm/core/fatal.c index 93592374c20..fa46a43f0b1 100644 --- a/arch/arm/core/fatal.c +++ b/arch/arm/core/fatal.c @@ -46,10 +46,6 @@ void _NanoFatalErrorHandler(unsigned int reason, const NANO_ESF *pEsf) { switch (reason) { - case _NANO_ERR_INVALID_TASK_EXIT: - printk("***** Invalid Exit Software Error! *****\n"); - break; - #if defined(CONFIG_STACK_CANARIES) || defined(CONFIG_STACK_SENTINEL) case _NANO_ERR_STACK_CHK_FAIL: printk("***** Stack Check Fail! *****\n"); diff --git a/arch/arm/core/thread_abort.c b/arch/arm/core/thread_abort.c index cd32f99419c..86b76595859 100644 --- a/arch/arm/core/thread_abort.c +++ b/arch/arm/core/thread_abort.c @@ -22,6 +22,7 @@ #include #include #include +#include extern void _k_thread_single_abort(struct k_thread *thread); @@ -31,6 +32,9 @@ void k_thread_abort(k_tid_t thread) key = irq_lock(); + __ASSERT(!(thread->base.user_options & K_ESSENTIAL), + "essential thread aborted"); + _k_thread_single_abort(thread); _thread_monitor_exit(thread); diff --git a/arch/nios2/core/fatal.c b/arch/nios2/core/fatal.c index e046836b128..8b3a6204abb 100644 --- a/arch/nios2/core/fatal.c +++ b/arch/nios2/core/fatal.c @@ -56,11 +56,6 @@ FUNC_NORETURN void _NanoFatalErrorHandler(unsigned int reason, case _NANO_ERR_SPURIOUS_INT: break; - case _NANO_ERR_INVALID_TASK_EXIT: - printk("***** Invalid Exit Software Error! *****\n"); - break; - - case _NANO_ERR_ALLOCATION_FAIL: printk("**** Kernel Allocation Failure! ****\n"); break; diff --git a/arch/riscv32/core/fatal.c b/arch/riscv32/core/fatal.c index 006e92d589e..c688d4c2c16 100644 --- a/arch/riscv32/core/fatal.c +++ b/arch/riscv32/core/fatal.c @@ -65,10 +65,6 @@ FUNC_NORETURN void _NanoFatalErrorHandler(unsigned int reason, case _NANO_ERR_SPURIOUS_INT: break; - case _NANO_ERR_INVALID_TASK_EXIT: - printk("***** Invalid Exit Software Error! *****\n"); - break; - #if defined(CONFIG_STACK_CANARIES) || defined(CONFIG_STACK_SENTINEL) case _NANO_ERR_STACK_CHK_FAIL: printk("***** Stack Check Fail! *****\n"); diff --git a/arch/x86/core/fatal.c b/arch/x86/core/fatal.c index aa3d2020bf7..854d3c7214a 100644 --- a/arch/x86/core/fatal.c +++ b/arch/x86/core/fatal.c @@ -64,10 +64,6 @@ FUNC_NORETURN void _NanoFatalErrorHandler(unsigned int reason, printk("*****\n"); break; } - case _NANO_ERR_INVALID_TASK_EXIT: - printk("***** Invalid Exit Software Error! *****\n"); - break; - #if defined(CONFIG_STACK_CANARIES) || defined(CONFIG_STACK_SENTINEL) || \ defined(CONFIG_X86_STACK_PROTECTION) case _NANO_ERR_STACK_CHK_FAIL: diff --git a/arch/xtensa/core/fatal.c b/arch/xtensa/core/fatal.c index 6c18abe1f41..ab19ae31fab 100644 --- a/arch/xtensa/core/fatal.c +++ b/arch/xtensa/core/fatal.c @@ -52,9 +52,6 @@ FUNC_NORETURN void _NanoFatalErrorHandler(unsigned int reason, case _NANO_ERR_RESERVED_IRQ: break; - case _NANO_ERR_INVALID_TASK_EXIT: - printk("***** Invalid Exit Software Error! *****\n"); - break; #if defined(CONFIG_STACK_CANARIES) || defined(CONFIG_STACK_SENTINEL) case _NANO_ERR_STACK_CHK_FAIL: printk("***** Stack Check Fail! *****\n"); diff --git a/include/arch/arc/v2/error.h b/include/arch/arc/v2/error.h index 37e41085b24..2dc517c1c8f 100644 --- a/include/arch/arc/v2/error.h +++ b/include/arch/arc/v2/error.h @@ -28,7 +28,6 @@ extern void _SysFatalErrorHandler(unsigned int cause, const NANO_ESF *esf); #endif #define _NANO_ERR_HW_EXCEPTION (0) /* MPU/Bus/Usage fault */ -#define _NANO_ERR_INVALID_TASK_EXIT (1) /* Invalid task exit */ #define _NANO_ERR_STACK_CHK_FAIL (2) /* Stack corruption detected */ #define _NANO_ERR_ALLOCATION_FAIL (3) /* Kernel Allocation Failure */ #define _NANO_ERR_KERNEL_OOPS (4) /* Kernel oops (fatal to thread) */ diff --git a/include/arch/arm/cortex_m/error.h b/include/arch/arm/cortex_m/error.h index 2325227fece..b3cd064843f 100644 --- a/include/arch/arm/cortex_m/error.h +++ b/include/arch/arm/cortex_m/error.h @@ -26,7 +26,6 @@ extern void _SysFatalErrorHandler(unsigned int reason, const NANO_ESF *esf); #endif #define _NANO_ERR_HW_EXCEPTION (0) /* MPU/Bus/Usage fault */ -#define _NANO_ERR_INVALID_TASK_EXIT (1) /* Invalid task exit */ #define _NANO_ERR_STACK_CHK_FAIL (2) /* Stack corruption detected */ #define _NANO_ERR_ALLOCATION_FAIL (3) /* Kernel Allocation Failure */ #define _NANO_ERR_KERNEL_OOPS (4) /* Kernel oops (fatal to thread) */ diff --git a/include/arch/nios2/arch.h b/include/arch/nios2/arch.h index 364cd0233cd..2d59b61ffa0 100644 --- a/include/arch/nios2/arch.h +++ b/include/arch/nios2/arch.h @@ -25,7 +25,6 @@ extern "C" { #define STACK_ALIGN 4 #define _NANO_ERR_CPU_EXCEPTION (0) /* Any unhandled exception */ -#define _NANO_ERR_INVALID_TASK_EXIT (1) /* Invalid task exit */ #define _NANO_ERR_STACK_CHK_FAIL (2) /* Stack corruption detected */ #define _NANO_ERR_ALLOCATION_FAIL (3) /* Kernel Allocation Failure */ #define _NANO_ERR_SPURIOUS_INT (4) /* Spurious interrupt */ diff --git a/include/arch/riscv32/exp.h b/include/arch/riscv32/exp.h index 9da414263b3..33a0612e1fc 100644 --- a/include/arch/riscv32/exp.h +++ b/include/arch/riscv32/exp.h @@ -69,7 +69,6 @@ extern void _SysFatalErrorHandler(unsigned int reason, #endif /* _ASMLANGUAGE */ #define _NANO_ERR_CPU_EXCEPTION (0) /* Any unhandled exception */ -#define _NANO_ERR_INVALID_TASK_EXIT (1) /* Invalid task exit */ #define _NANO_ERR_STACK_CHK_FAIL (2) /* Stack corruption detected */ #define _NANO_ERR_ALLOCATION_FAIL (3) /* Kernel Allocation Failure */ #define _NANO_ERR_SPURIOUS_INT (4) /* Spurious interrupt */ diff --git a/include/arch/x86/arch.h b/include/arch/x86/arch.h index 92f20c43bfa..655f82bbf75 100644 --- a/include/arch/x86/arch.h +++ b/include/arch/x86/arch.h @@ -358,8 +358,6 @@ typedef struct nanoIsf { #define _NANO_ERR_PAGE_FAULT (1) /** General protection fault */ #define _NANO_ERR_GEN_PROT_FAULT (2) -/** Invalid task exit */ -#define _NANO_ERR_INVALID_TASK_EXIT (3) /** Stack corruption detected */ #define _NANO_ERR_STACK_CHK_FAIL (4) /** Kernel Allocation Failure */ diff --git a/include/arch/xtensa/arch.h b/include/arch/xtensa/arch.h index 02c42102db5..4f93d582118 100644 --- a/include/arch/xtensa/arch.h +++ b/include/arch/xtensa/arch.h @@ -31,7 +31,6 @@ extern "C" { #define SIZEOFUNIT_TO_OCTET(X) (X) #define _NANO_ERR_HW_EXCEPTION (0) /* MPU/Bus/Usage fault */ -#define _NANO_ERR_INVALID_TASK_EXIT (1) /* Invalid task exit */ #define _NANO_ERR_STACK_CHK_FAIL (2) /* Stack corruption detected */ #define _NANO_ERR_ALLOCATION_FAIL (3) /* Kernel Allocation Failure */ #define _NANO_ERR_RESERVED_IRQ (4) /* Reserved interrupt */ diff --git a/kernel/thread.c b/kernel/thread.c index a07be883a4a..9ea6da03714 100644 --- a/kernel/thread.c +++ b/kernel/thread.c @@ -189,10 +189,6 @@ FUNC_NORETURN void _thread_entry(void (*entry)(void *, void *, void *), _check_stack_sentinel(); #endif #ifdef CONFIG_MULTITHREADING - if (_is_thread_essential()) { - _k_except_reason(_NANO_ERR_INVALID_TASK_EXIT); - } - k_thread_abort(_current); #else for (;;) { diff --git a/kernel/thread_abort.c b/kernel/thread_abort.c index e4ad2249001..4ed44563db9 100644 --- a/kernel/thread_abort.c +++ b/kernel/thread_abort.c @@ -18,6 +18,7 @@ #include #include #include +#include extern void _k_thread_single_abort(struct k_thread *thread); @@ -28,6 +29,9 @@ void k_thread_abort(k_tid_t thread) key = irq_lock(); + __ASSERT(!(thread->base.user_options & K_ESSENTIAL), + "essential thread aborted"); + _k_thread_single_abort(thread); _thread_monitor_exit(thread);