From 27459a13e4460c658cca3fc9e9ded3076805a259 Mon Sep 17 00:00:00 2001 From: Krzysztof Chruscinski Date: Wed, 19 Sep 2018 11:13:57 +0200 Subject: [PATCH] arch: Add LOG_PANIC to fault handlers Added LOG_PANIC to fault handlers to ensure that log is flush and logger processes messages in a blocking way in fault handler. Signed-off-by: Krzysztof Chruscinski --- arch/arc/core/fatal.c | 4 ++++ arch/arc/core/fault.c | 3 +++ arch/arm/core/fatal.c | 6 +++++- arch/arm/core/fault.c | 3 +++ arch/nios2/core/fatal.c | 3 +++ arch/posix/core/fatal.c | 3 +++ arch/riscv32/core/fatal.c | 5 +++++ arch/x86/core/fatal.c | 3 +++ arch/x86/core/sys_fatal_error_handler.c | 3 +++ arch/xtensa/core/fatal.c | 3 +++ 10 files changed, 35 insertions(+), 1 deletion(-) diff --git a/arch/arc/core/fatal.c b/arch/arc/core/fatal.c index 3fb91560c1f..5c22b7249bc 100644 --- a/arch/arc/core/fatal.c +++ b/arch/arc/core/fatal.c @@ -17,6 +17,7 @@ #include #include #include +#include /** * @@ -35,6 +36,8 @@ */ void _NanoFatalErrorHandler(unsigned int reason, const NANO_ESF *pEsf) { + LOG_PANIC(); + switch (reason) { case _NANO_ERR_HW_EXCEPTION: break; @@ -83,6 +86,7 @@ void _NanoFatalErrorHandler(unsigned int reason, const NANO_ESF *pEsf) FUNC_NORETURN void _arch_syscall_oops(void *ssf_ptr) { + LOG_PANIC(); _SysFatalErrorHandler(_NANO_ERR_KERNEL_OOPS, ssf_ptr); CODE_UNREACHABLE; } diff --git a/arch/arc/core/fault.c b/arch/arc/core/fault.c index a51154c7fae..ccf6bcadc40 100644 --- a/arch/arc/core/fault.c +++ b/arch/arc/core/fault.c @@ -19,6 +19,7 @@ #include #include #include +#include #ifdef CONFIG_USERSPACE Z_EXC_DECLARE(z_arch_user_string_nlen); @@ -42,6 +43,8 @@ void _Fault(NANO_ESF *esf) u32_t exc_addr = _arc_v2_aux_reg_read(_ARC_V2_EFA); u32_t ecr = _arc_v2_aux_reg_read(_ARC_V2_ECR); + LOG_PANIC(); + #ifdef CONFIG_USERSPACE for (int i = 0; i < ARRAY_SIZE(exceptions); i++) { u32_t start = (u32_t)exceptions[i].start; diff --git a/arch/arm/core/fatal.c b/arch/arm/core/fatal.c index 623c257926b..09a1c510995 100644 --- a/arch/arm/core/fatal.c +++ b/arch/arm/core/fatal.c @@ -18,7 +18,7 @@ #include #include #include - +#include /** * @@ -47,6 +47,8 @@ void _NanoFatalErrorHandler(unsigned int reason, const NANO_ESF *pEsf) { + LOG_PANIC(); + switch (reason) { case _NANO_ERR_HW_EXCEPTION: printk("***** Hardware exception *****\n"); @@ -98,6 +100,8 @@ FUNC_NORETURN void _arch_syscall_oops(void *ssf_ptr) u32_t *ssf_contents = ssf_ptr; NANO_ESF oops_esf = { 0 }; + LOG_PANIC(); + oops_esf.pc = ssf_contents[3]; _do_kernel_oops(&oops_esf); diff --git a/arch/arm/core/fault.c b/arch/arm/core/fault.c index ee16e5dfd05..9bc7206190a 100644 --- a/arch/arm/core/fault.c +++ b/arch/arm/core/fault.c @@ -18,6 +18,7 @@ #include #include #include +#include #ifdef CONFIG_PRINTK #include @@ -670,6 +671,8 @@ void _Fault(NANO_ESF *esf, u32_t exc_return) u32_t reason; int fault = SCB->ICSR & SCB_ICSR_VECTACTIVE_Msk; + LOG_PANIC(); + #if defined(CONFIG_ARM_SECURE_FIRMWARE) if ((exc_return & EXC_RETURN_INDICATOR_PREFIX) != EXC_RETURN_INDICATOR_PREFIX) { diff --git a/arch/nios2/core/fatal.c b/arch/nios2/core/fatal.c index 8b3a6204abb..bec5894278f 100644 --- a/arch/nios2/core/fatal.c +++ b/arch/nios2/core/fatal.c @@ -9,6 +9,7 @@ #include #include #include +#include const NANO_ESF _default_esf = { 0xdeadbaad, @@ -50,6 +51,8 @@ const NANO_ESF _default_esf = { FUNC_NORETURN void _NanoFatalErrorHandler(unsigned int reason, const NANO_ESF *esf) { + LOG_PANIC(); + #ifdef CONFIG_PRINTK switch (reason) { case _NANO_ERR_CPU_EXCEPTION: diff --git a/arch/posix/core/fatal.c b/arch/posix/core/fatal.c index 988932ac88e..e1a80842459 100644 --- a/arch/posix/core/fatal.c +++ b/arch/posix/core/fatal.c @@ -10,6 +10,7 @@ #include #include #include +#include #include "posix_soc_if.h" const NANO_ESF _default_esf = { @@ -34,6 +35,8 @@ const NANO_ESF _default_esf = { FUNC_NORETURN void _NanoFatalErrorHandler(unsigned int reason, const NANO_ESF *esf) { + LOG_PANIC(); + #ifdef CONFIG_PRINTK switch (reason) { case _NANO_ERR_CPU_EXCEPTION: diff --git a/arch/riscv32/core/fatal.c b/arch/riscv32/core/fatal.c index 601dad7cb27..078fbfa6ba1 100644 --- a/arch/riscv32/core/fatal.c +++ b/arch/riscv32/core/fatal.c @@ -8,6 +8,7 @@ #include #include #include +#include const NANO_ESF _default_esf = { 0xdeadbaad, @@ -60,6 +61,8 @@ const NANO_ESF _default_esf = { FUNC_NORETURN void _NanoFatalErrorHandler(unsigned int reason, const NANO_ESF *esf) { + LOG_PANIC(); + switch (reason) { case _NANO_ERR_CPU_EXCEPTION: case _NANO_ERR_SPURIOUS_INT: @@ -135,6 +138,8 @@ FUNC_NORETURN __weak void _SysFatalErrorHandler(unsigned int reason, { ARG_UNUSED(esf); + LOG_PANIC(); + #if !defined(CONFIG_SIMPLE_FATAL_ERROR_HANDLER) #ifdef CONFIG_STACK_SENTINEL if (reason == _NANO_ERR_STACK_CHK_FAIL) { diff --git a/arch/x86/core/fatal.c b/arch/x86/core/fatal.c index 5a0516c5af4..e1376b9d8ae 100644 --- a/arch/x86/core/fatal.c +++ b/arch/x86/core/fatal.c @@ -22,6 +22,7 @@ #include #include #include +#include __weak void _debug_fatal_hook(const NANO_ESF *esf) { ARG_UNUSED(esf); } @@ -83,6 +84,8 @@ static void unwind_stack(u32_t base_ptr) FUNC_NORETURN void _NanoFatalErrorHandler(unsigned int reason, const NANO_ESF *pEsf) { + LOG_PANIC(); + _debug_fatal_hook(pEsf); #ifdef CONFIG_PRINTK diff --git a/arch/x86/core/sys_fatal_error_handler.c b/arch/x86/core/sys_fatal_error_handler.c index 9ef9375c829..47f04cc203a 100644 --- a/arch/x86/core/sys_fatal_error_handler.c +++ b/arch/x86/core/sys_fatal_error_handler.c @@ -17,6 +17,7 @@ #include #include #include +#include /** * @@ -43,6 +44,8 @@ FUNC_NORETURN __weak void _SysFatalErrorHandler(unsigned int reason, { ARG_UNUSED(pEsf); + LOG_PANIC(); + #if !defined(CONFIG_SIMPLE_FATAL_ERROR_HANDLER) #ifdef CONFIG_STACK_SENTINEL if (reason == _NANO_ERR_STACK_CHK_FAIL) { diff --git a/arch/xtensa/core/fatal.c b/arch/xtensa/core/fatal.c index c48e26b2ed1..938c3fcac04 100644 --- a/arch/xtensa/core/fatal.c +++ b/arch/xtensa/core/fatal.c @@ -10,6 +10,7 @@ #include #include #include +#include #ifdef XT_SIMULATOR #include @@ -51,6 +52,8 @@ const NANO_ESF _default_esf = { XTENSA_ERR_NORET void _NanoFatalErrorHandler(unsigned int reason, const NANO_ESF *pEsf) { + LOG_PANIC(); + switch (reason) { case _NANO_ERR_HW_EXCEPTION: case _NANO_ERR_RESERVED_IRQ: