Skip to content

Commit 71ce8ce

Browse files
Andrew Boieandrewboie
authored andcommitted
kernel: consolidate error handling code
* z_NanoFatalErrorHandler() is now moved to common kernel code and renamed z_fatal_error(). Arches dump arch-specific info before calling. * z_SysFatalErrorHandler() is now moved to common kernel code and renamed k_sys_fatal_error_handler(). It is now much simpler; the default policy is simply to lock interrupts and halt the system. If an implementation of this function returns, then the currently running thread is aborted. * New arch-specific APIs introduced: - z_arch_system_halt() simply powers off or halts the system. * We now have a standard set of fatal exception reason codes, namespaced under K_ERR_* * CONFIG_SIMPLE_FATAL_ERROR_HANDLER deleted * LOG_PANIC() calls moved to k_sys_fatal_error_handler() Signed-off-by: Andrew Boie <[email protected]>
1 parent 81245a0 commit 71ce8ce

File tree

53 files changed

+392
-1178
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+392
-1178
lines changed

arch/Kconfig

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -241,15 +241,6 @@ config DYNAMIC_OBJECTS
241241
API call, or when the number of references to that object drops to
242242
zero.
243243

244-
config SIMPLE_FATAL_ERROR_HANDLER
245-
bool "Simple system fatal error handler"
246-
default y if !MULTITHREADING
247-
help
248-
Provides an implementation of _SysFatalErrorHandler() that hard hangs
249-
instead of aborting the faulting thread, and does not print anything,
250-
for footprint-concerned systems. Only enable this option if you do not
251-
want debug capabilities in case of system fatal error.
252-
253244
if ARCH_HAS_NOCACHE_MEMORY_SUPPORT
254245

255246
config NOCACHE_MEMORY

arch/arc/core/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ zephyr_library_sources(
1414
isr_wrapper.S
1515
regular_irq.S
1616
switch.S
17-
sys_fatal_error_handler.c
1817
prep_c.c
1918
reset.S
2019
vector_table.c

arch/arc/core/fatal.c

Lines changed: 4 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -19,74 +19,18 @@
1919
#include <sys/printk.h>
2020
#include <logging/log_ctrl.h>
2121

22-
/**
23-
*
24-
* @brief Kernel fatal error handler
25-
*
26-
* This routine is called when fatal error conditions are detected by software
27-
* and is responsible only for reporting the error. Once reported, it then
28-
* invokes the user provided routine z_SysFatalErrorHandler() which is
29-
* responsible for implementing the error handling policy.
30-
*
31-
* The caller is expected to always provide a usable ESF. In the event that the
32-
* fatal error does not have a hardware generated ESF, the caller should either
33-
* create its own or use a pointer to the global default ESF <_default_esf>.
34-
*
35-
* @return This function does not return.
36-
*/
37-
void z_NanoFatalErrorHandler(unsigned int reason, const NANO_ESF *pEsf)
22+
void z_arc_fatal_error(unsigned int reason, const NANO_ESF *esf)
3823
{
39-
LOG_PANIC();
40-
41-
switch (reason) {
42-
case _NANO_ERR_HW_EXCEPTION:
43-
break;
44-
45-
#if defined(CONFIG_STACK_CANARIES) || defined(CONFIG_ARC_STACK_CHECKING) \
46-
|| defined(CONFIG_STACK_SENTINEL) || defined(CONFIG_MPU_STACK_GUARD)
47-
case _NANO_ERR_STACK_CHK_FAIL:
48-
printk("***** Stack Check Fail! *****\n");
49-
break;
50-
#endif
51-
52-
case _NANO_ERR_ALLOCATION_FAIL:
53-
printk("**** Kernel Allocation Failure! ****\n");
54-
break;
55-
56-
case _NANO_ERR_KERNEL_OOPS:
57-
printk("***** Kernel OOPS! *****\n");
58-
break;
59-
60-
case _NANO_ERR_KERNEL_PANIC:
61-
printk("***** Kernel Panic! *****\n");
62-
break;
63-
64-
default:
65-
printk("**** Unknown Fatal Error %d! ****\n", reason);
66-
break;
67-
}
68-
69-
printk("Current thread ID = %p\n", k_current_get());
70-
71-
if (reason == _NANO_ERR_HW_EXCEPTION) {
24+
if (reason == K_ERR_CPU_EXCEPTION) {
7225
printk("Faulting instruction address = 0x%lx\n",
7326
z_arc_v2_aux_reg_read(_ARC_V2_ERET));
7427
}
7528

76-
/*
77-
* Now that the error has been reported, call the user implemented
78-
* policy
79-
* to respond to the error. The decisions as to what responses are
80-
* appropriate to the various errors are something the customer must
81-
* decide.
82-
*/
83-
84-
z_SysFatalErrorHandler(reason, pEsf);
29+
z_fatal_error(reason, esf);
8530
}
8631

8732
FUNC_NORETURN void z_arch_syscall_oops(void *ssf_ptr)
8833
{
89-
LOG_PANIC();
90-
z_SysFatalErrorHandler(_NANO_ERR_KERNEL_OOPS, ssf_ptr);
34+
z_arc_fatal_error(K_ERR_KERNEL_OOPS, ssf_ptr);
9135
CODE_UNREACHABLE;
9236
}

arch/arc/core/fault.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,7 @@ static void dump_exception_info(u32_t vector, u32_t cause, u32_t parameter)
371371
*
372372
* This routine is called when fatal error conditions are detected by hardware
373373
* and is responsible only for reporting the error. Once reported, it then
374-
* invokes the user provided routine z_SysFatalErrorHandler() which is
374+
* invokes the user provided routine k_sys_fatal_error_handler() which is
375375
* responsible for implementing the error handling policy.
376376
*/
377377
void _Fault(NANO_ESF *esf)
@@ -391,15 +391,14 @@ void _Fault(NANO_ESF *esf)
391391
}
392392
}
393393
#endif
394-
LOG_PANIC();
395394

396395
vector = Z_ARC_V2_ECR_VECTOR(ecr);
397396
cause = Z_ARC_V2_ECR_CODE(ecr);
398397
parameter = Z_ARC_V2_ECR_PARAMETER(ecr);
399398

400399
/* exception raised by kernel */
401400
if (vector == ARC_EV_TRAP && parameter == _TRAP_S_CALL_RUNTIME_EXCEPT) {
402-
z_NanoFatalErrorHandler(esf->r0, esf);
401+
z_arc_fatal_error(esf->r0, esf);
403402
return;
404403
}
405404

@@ -417,7 +416,7 @@ void _Fault(NANO_ESF *esf)
417416
* parameter = 0x2 | [0x4 | 0x8 | 0x1]
418417
*/
419418
if (vector == ARC_EV_PROT_V && parameter & 0x2) {
420-
z_NanoFatalErrorHandler(_NANO_ERR_STACK_CHK_FAIL, esf);
419+
z_arc_fatal_error(K_ERR_STACK_CHK_FAIL, esf);
421420
return;
422421
}
423422
#endif
@@ -426,10 +425,10 @@ void _Fault(NANO_ESF *esf)
426425
if (vector == ARC_EV_PROT_V && ((parameter == 0x4) ||
427426
(parameter == 0x24))) {
428427
if (z_check_thread_stack_fail(exc_addr, arc_exc_saved_sp)) {
429-
z_NanoFatalErrorHandler(_NANO_ERR_STACK_CHK_FAIL, esf);
428+
z_arc_fatal_error(K_ERR_STACK_CHK_FAIL, esf);
430429
return;
431430
}
432431
}
433432
#endif
434-
z_NanoFatalErrorHandler(_NANO_ERR_HW_EXCEPTION, esf);
433+
z_arc_fatal_error(K_ERR_CPU_EXCEPTION, esf);
435434
}

arch/arc/core/sys_fatal_error_handler.c

Lines changed: 0 additions & 74 deletions
This file was deleted.

arch/arc/include/kernel_arch_func.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ extern void z_arc_userspace_enter(k_thread_entry_t user_entry, void *p1,
6161

6262

6363
extern void z_arch_switch(void *switch_to, void **switched_from);
64-
64+
extern void z_arc_fatal_error(unsigned int reason, const NANO_ESF *esf);
6565
#endif /* _ASMLANGUAGE */
6666

6767
#ifdef __cplusplus

arch/arm/core/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ zephyr_library_sources(
1919
cpu_idle.S
2020
fault_s.S
2121
fatal.c
22-
sys_fatal_error_handler.c
2322
thread_abort.c
2423
)
2524

arch/arm/core/fatal.c

Lines changed: 5 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -20,102 +20,23 @@
2020
#include <sys/printk.h>
2121
#include <logging/log_ctrl.h>
2222

23-
/**
24-
*
25-
* @brief Kernel fatal error handler
26-
*
27-
* This routine is called when fatal error conditions are detected by software
28-
* and is responsible only for reporting the error. Once reported, it then
29-
* invokes the user provided routine z_SysFatalErrorHandler() which is
30-
* responsible for implementing the error handling policy.
31-
*
32-
* The caller is expected to always provide a usable ESF. In the event that the
33-
* fatal error does not have a hardware generated ESF, the caller should either
34-
* create its own or use a pointer to the global default ESF <_default_esf>.
35-
*
36-
* Unlike other arches, this function may return if z_SysFatalErrorHandler
37-
* determines that only the current thread should be aborted and the CPU
38-
* was in handler mode. PendSV will be asserted in this case and the current
39-
* thread taken off the run queue. Leaving the exception will immediately
40-
* trigger a context switch.
41-
*
42-
* @param reason the reason that the handler was called
43-
* @param pEsf pointer to the exception stack frame
44-
*
45-
* @return This function does not return.
46-
*/
47-
void z_NanoFatalErrorHandler(unsigned int reason,
48-
const NANO_ESF *pEsf)
23+
void z_arm_fatal_error(unsigned int reason, const NANO_ESF *esf)
4924
{
50-
#ifdef CONFIG_THREAD_NAME
51-
const char *thread_name = k_thread_name_get(k_current_get());
52-
#endif
53-
54-
LOG_PANIC();
55-
56-
switch (reason) {
57-
case _NANO_ERR_HW_EXCEPTION:
58-
printk("***** Hardware exception *****\n");
59-
break;
60-
#if defined(CONFIG_STACK_CANARIES) || defined(CONFIG_STACK_SENTINEL) || \
61-
defined(CONFIG_HW_STACK_PROTECTION) || \
62-
defined(CONFIG_USERSPACE)
63-
case _NANO_ERR_STACK_CHK_FAIL:
64-
printk("***** Stack Check Fail! *****\n");
65-
break;
66-
#endif /* CONFIG_STACK_CANARIES */
67-
68-
case _NANO_ERR_ALLOCATION_FAIL:
69-
printk("**** Kernel Allocation Failure! ****\n");
70-
break;
71-
72-
case _NANO_ERR_KERNEL_OOPS:
73-
printk("***** Kernel OOPS! *****\n");
74-
break;
75-
76-
case _NANO_ERR_KERNEL_PANIC:
77-
printk("***** Kernel Panic! *****\n");
78-
break;
79-
80-
default:
81-
printk("**** Unknown Fatal Error %d! ****\n", reason);
82-
break;
83-
}
84-
printk("Current thread ID = %p"
85-
#ifdef CONFIG_THREAD_NAME
86-
" (%s)"
87-
#endif
88-
"\n"
89-
"Faulting instruction address = 0x%x\n",
90-
k_current_get(),
91-
#ifdef CONFIG_THREAD_NAME
92-
thread_name ? thread_name : "unknown",
93-
#endif
94-
pEsf->basic.pc);
95-
96-
/*
97-
* Now that the error has been reported, call the user implemented
98-
* policy
99-
* to respond to the error. The decisions as to what responses are
100-
* appropriate to the various errors are something the customer must
101-
* decide.
102-
*/
103-
104-
z_SysFatalErrorHandler(reason, pEsf);
25+
printk("Faulting instruction address = 0x%x\n",
26+
esf->basic.pc);
27+
z_fatal_error(reason, esf);
10528
}
10629

10730
void z_do_kernel_oops(const NANO_ESF *esf)
10831
{
109-
z_NanoFatalErrorHandler(esf->basic.r0, esf);
32+
z_arm_fatal_error(esf->basic.r0, esf);
11033
}
11134

11235
FUNC_NORETURN void z_arch_syscall_oops(void *ssf_ptr)
11336
{
11437
u32_t *ssf_contents = ssf_ptr;
11538
NANO_ESF oops_esf = { 0 };
11639

117-
LOG_PANIC();
118-
11940
oops_esf.basic.pc = ssf_contents[3];
12041

12142
z_do_kernel_oops(&oops_esf);

0 commit comments

Comments
 (0)