From f32818135c16ec63f621e1c61b38bd2534940261 Mon Sep 17 00:00:00 2001 From: yinshengkai Date: Wed, 27 Dec 2023 17:32:53 +0800 Subject: [PATCH 1/3] assert: Avoid recursive calls of Assert After the structure of the kernel core is wrong, dump_stack, dumpstack is easy to appear crash Signed-off-by: yinshengkai --- sched/misc/assert.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/sched/misc/assert.c b/sched/misc/assert.c index 2500b0c2bb4b8..6d17472b6e887 100644 --- a/sched/misc/assert.c +++ b/sched/misc/assert.c @@ -104,6 +104,8 @@ static FAR const char * const g_ttypenames[4] = "Invalid" }; +static bool g_fatal_assert = false; + /**************************************************************************** * Private Functions ****************************************************************************/ @@ -549,6 +551,11 @@ void _assert(FAR const char *filename, int linenum, flags = enter_critical_section(); + if (g_fatal_assert) + { + goto reset; + } + /* try to save current context if regs is null */ if (regs == NULL) @@ -567,7 +574,11 @@ void _assert(FAR const char *filename, int linenum, { fatal = false; } + else #endif + { + g_fatal_assert = true; + } notifier_data.rtcb = rtcb; notifier_data.regs = regs; @@ -666,6 +677,7 @@ void _assert(FAR const char *filename, int linenum, reboot_notifier_call_chain(SYS_HALT, NULL); +reset: #if CONFIG_BOARD_RESET_ON_ASSERT >= 1 board_reset(CONFIG_BOARD_ASSERT_RESET_VALUE); #else From 7efe1212758cf9378c3fe6a35bf6a4b033b349fe Mon Sep 17 00:00:00 2001 From: yinshengkai Date: Thu, 11 Jan 2024 11:35:27 +0800 Subject: [PATCH 2/3] assert: pause all other CPUs when assert Signed-off-by: yinshengkai --- sched/misc/assert.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/sched/misc/assert.c b/sched/misc/assert.c index 6d17472b6e887..ea0910046ee80 100644 --- a/sched/misc/assert.c +++ b/sched/misc/assert.c @@ -522,6 +522,25 @@ static void dump_deadlock(void) } #endif +/**************************************************************************** + * Name: pause_all_cpu + ****************************************************************************/ + +#ifdef CONFIG_SMP +static void pause_all_cpu(void) +{ + int cpu; + + for (cpu = 0; cpu < CONFIG_SMP_NCPUS; cpu++) + { + if (cpu != this_cpu()) + { + up_cpu_pause(cpu); + } + } +} +#endif + /**************************************************************************** * Public Functions ****************************************************************************/ @@ -556,6 +575,13 @@ void _assert(FAR const char *filename, int linenum, goto reset; } + if (fatal) + { +#ifdef CONFIG_SMP + pause_all_cpu(); +#endif + } + /* try to save current context if regs is null */ if (regs == NULL) From 2a1571bb9a7a9d3c87066194b7c82ab9b95103b4 Mon Sep 17 00:00:00 2001 From: yinshengkai Date: Tue, 25 Jun 2024 11:33:47 +0800 Subject: [PATCH 3/3] sched: support dumping all file information during assert Signed-off-by: yinshengkai --- sched/misc/assert.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/sched/misc/assert.c b/sched/misc/assert.c index ea0910046ee80..31419abaecc89 100644 --- a/sched/misc/assert.c +++ b/sched/misc/assert.c @@ -27,6 +27,7 @@ #include #include #include +#include #include #include #include @@ -414,6 +415,18 @@ static void dump_backtrace(FAR struct tcb_s *tcb, FAR void *arg) } #endif +/**************************************************************************** + * Name: dump_filelist + ****************************************************************************/ + +#ifdef CONFIG_SCHED_DUMP_ON_EXIT +static void dump_filelist(FAR struct tcb_s *tcb, FAR void *arg) +{ + FAR struct filelist *filelist = &tcb->group->tg_filelist; + files_dumplist(filelist); +} +#endif + /**************************************************************************** * Name: dump_tasks ****************************************************************************/ @@ -495,6 +508,10 @@ static void dump_tasks(void) #ifdef CONFIG_SCHED_BACKTRACE nxsched_foreach(dump_backtrace, NULL); #endif + +#ifdef CONFIG_SCHED_DUMP_ON_EXIT + nxsched_foreach(dump_filelist, NULL); +#endif } /****************************************************************************