This is an automated email from the ASF dual-hosted git repository.

acassis pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git

commit b3794c8af7a54af9e4cfc2832b075fa7f5a51110
Author: yinshengkai <[email protected]>
AuthorDate: Wed Dec 27 17:32:53 2023 +0800

    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 <[email protected]>
---
 sched/misc/assert.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/sched/misc/assert.c b/sched/misc/assert.c
index 2500b0c2bb..6d17472b6e 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

Reply via email to