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

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


The following commit(s) were added to refs/heads/master by this push:
     new ca7608c2ac3 sched/irq: add a check for the interrupt stack in 
irq_dispatch
ca7608c2ac3 is described below

commit ca7608c2ac3aeedefcf02817b5e466d3c53aba2c
Author: guoshengyuan1 <[email protected]>
AuthorDate: Mon Sep 29 11:02:00 2025 +0800

    sched/irq: add a check for the interrupt stack in irq_dispatch
    
    After irq_dispatch finished, the interrupt stack will be checked to
    determine whether overflow occurs.
    The relevant configuration reuses the configuration of stack overflow
    detection during context switching.
    
    Signed-off-by: guoshengyuan1 <[email protected]>
---
 arch/arm/src/common/arm_checkstack.c         | 10 +++++++---
 arch/arm64/src/common/arm64_checkstack.c     | 10 +++++++---
 arch/avr/src/avr/avr_checkstack.c            | 10 +++++++---
 arch/ceva/src/common/ceva_checkstack.c       | 10 +++++++---
 arch/or1k/src/common/or1k_checkstack.c       | 10 +++++++---
 arch/risc-v/src/common/riscv_checkstack.c    | 10 +++++++---
 arch/sparc/src/common/sparc_checkstack.c     | 10 +++++++---
 arch/tricore/src/common/tricore_checkstack.c | 10 +++++++---
 arch/x86_64/src/intel64/intel64_checkstack.c | 10 +++++++---
 arch/xtensa/src/common/xtensa_checkstack.c   |  9 +++++++--
 include/nuttx/arch.h                         |  2 +-
 sched/irq/irq_dispatch.c                     |  5 +++++
 sched/misc/assert.c                          |  4 ++--
 13 files changed, 78 insertions(+), 32 deletions(-)

diff --git a/arch/arm/src/common/arm_checkstack.c 
b/arch/arm/src/common/arm_checkstack.c
index b8f62ab5612..918b65d872d 100644
--- a/arch/arm/src/common/arm_checkstack.c
+++ b/arch/arm/src/common/arm_checkstack.c
@@ -226,10 +226,14 @@ size_t up_check_tcbstack(struct tcb_s *tcb, size_t 
check_size)
 }
 
 #if CONFIG_ARCH_INTERRUPTSTACK > 3
-size_t up_check_intstack(int cpu)
+size_t up_check_intstack(int cpu, size_t check_size)
 {
-  return arm_stack_check((void *)up_get_intstackbase(cpu),
-                         STACK_ALIGN_DOWN(CONFIG_ARCH_INTERRUPTSTACK));
+  if (check_size == 0)
+    {
+      check_size = STACK_ALIGN_DOWN(CONFIG_ARCH_INTERRUPTSTACK);
+    }
+
+  return arm_stack_check((void *)up_get_intstackbase(cpu), check_size);
 }
 #endif
 
diff --git a/arch/arm64/src/common/arm64_checkstack.c 
b/arch/arm64/src/common/arm64_checkstack.c
index ae1a8f62656..f89a3aa0370 100644
--- a/arch/arm64/src/common/arm64_checkstack.c
+++ b/arch/arm64/src/common/arm64_checkstack.c
@@ -236,10 +236,14 @@ size_t up_check_tcbstack(struct tcb_s *tcb, size_t 
check_size)
 }
 
 #if CONFIG_ARCH_INTERRUPTSTACK > 7
-size_t up_check_intstack(int cpu)
+size_t up_check_intstack(int cpu, size_t check_size)
 {
-  return arm64_stack_check((void *)up_get_intstackbase(cpu),
-                           STACK_ALIGN_DOWN(CONFIG_ARCH_INTERRUPTSTACK));
+  if (check_size == 0)
+    {
+      check_size = STACK_ALIGN_DOWN(CONFIG_ARCH_INTERRUPTSTACK);
+    }
+
+  return arm64_stack_check((void *)up_get_intstackbase(cpu), check_size);
 }
 #endif
 
diff --git a/arch/avr/src/avr/avr_checkstack.c 
b/arch/avr/src/avr/avr_checkstack.c
index e9d3c52dfcc..039a8eadcc5 100644
--- a/arch/avr/src/avr/avr_checkstack.c
+++ b/arch/avr/src/avr/avr_checkstack.c
@@ -150,10 +150,14 @@ size_t up_check_tcbstack(FAR struct tcb_s *tcb, size_t 
check_size)
 }
 
 #if CONFIG_ARCH_INTERRUPTSTACK > 3
-size_t up_check_intstack(int cpu)
+size_t up_check_intstack(int cpu, size_t check_size)
 {
-  uintptr_t start = (uintptr_t)g_intstackalloc;
-  return avr_stack_check(start, CONFIG_ARCH_INTERRUPTSTACK & ~3);
+  if (check_size == 0)
+    {
+      check_size = CONFIG_ARCH_INTERRUPTSTACK & ~3;
+    }
+
+  return avr_stack_check((uintptr_t)g_intstackalloc, check_size);
 }
 #endif
 
diff --git a/arch/ceva/src/common/ceva_checkstack.c 
b/arch/ceva/src/common/ceva_checkstack.c
index c7d73bdb98f..cb92fe182cf 100644
--- a/arch/ceva/src/common/ceva_checkstack.c
+++ b/arch/ceva/src/common/ceva_checkstack.c
@@ -144,10 +144,14 @@ size_t up_check_tcbstack(struct tcb_s *tcb, size_t 
check_size)
   return ceva_stack_check((uintptr_t)tcb->stack_alloc_ptr, check_size);
 }
 
-size_t up_check_intstack(int cpu)
+size_t up_check_intstack(int cpu, size_t check_size)
 {
-  return ceva_stack_check((uintptr_t)g_intstackalloc,
-                          g_intstackbase - g_intstackalloc);
+  if (check_size == 0)
+    {
+      check_size = g_intstackbase - g_intstackalloc;
+    }
+
+  return ceva_stack_check((uintptr_t)g_intstackalloc, check_size);
 }
 
 #endif /* CONFIG_STACK_COLORATION */
diff --git a/arch/or1k/src/common/or1k_checkstack.c 
b/arch/or1k/src/common/or1k_checkstack.c
index 838282c9327..1eebdf0e56b 100644
--- a/arch/or1k/src/common/or1k_checkstack.c
+++ b/arch/or1k/src/common/or1k_checkstack.c
@@ -121,10 +121,14 @@ size_t up_check_tcbstack(struct tcb_s *tcb, size_t 
check_size)
 }
 
 #if CONFIG_ARCH_INTERRUPTSTACK > 3
-size_t up_check_intstack(int cpu)
+size_t up_check_intstack(int cpu, size_t check_size)
 {
-  return or1k_stack_check((uintptr_t)g_intstackalloc,
-                          (CONFIG_ARCH_INTERRUPTSTACK & ~3));
+  if (check_size == 0)
+    {
+      check_size = CONFIG_ARCH_INTERRUPTSTACK & ~3;
+    }
+
+  return or1k_stack_check((uintptr_t)g_intstackalloc, check_size);
 }
 #endif
 
diff --git a/arch/risc-v/src/common/riscv_checkstack.c 
b/arch/risc-v/src/common/riscv_checkstack.c
index d6054f822ba..460a28fbf06 100644
--- a/arch/risc-v/src/common/riscv_checkstack.c
+++ b/arch/risc-v/src/common/riscv_checkstack.c
@@ -182,10 +182,14 @@ size_t up_check_tcbstack(struct tcb_s *tcb, size_t 
check_size)
 }
 
 #if CONFIG_ARCH_INTERRUPTSTACK > 15
-size_t up_check_intstack(int cpu)
+size_t up_check_intstack(int cpu, size_t check_size)
 {
-  return riscv_stack_check((uintptr_t)g_intstackalloc,
-                           (CONFIG_ARCH_INTERRUPTSTACK & ~15));
+  if (check_size == 0)
+    {
+      check_size = CONFIG_ARCH_INTERRUPTSTACK & ~15;
+    }
+
+  return riscv_stack_check((uintptr_t)g_intstackalloc, check_size);
 }
 #endif
 
diff --git a/arch/sparc/src/common/sparc_checkstack.c 
b/arch/sparc/src/common/sparc_checkstack.c
index 91c7fcf8e2c..47f0191a58f 100644
--- a/arch/sparc/src/common/sparc_checkstack.c
+++ b/arch/sparc/src/common/sparc_checkstack.c
@@ -206,10 +206,14 @@ size_t up_check_tcbstack(struct tcb_s *tcb, size_t 
check_size)
 }
 
 #if CONFIG_ARCH_INTERRUPTSTACK > 7
-size_t up_check_intstack(int cpu)
+size_t up_check_intstack(int cpu, size_t check_size)
 {
-  return sparc_stack_check((void *)up_get_intstackbase(cpu),
-                           STACK_ALIGN_DOWN(CONFIG_ARCH_INTERRUPTSTACK));
+  if (check_size == 0)
+    {
+      check_size = STACK_ALIGN_DOWN(CONFIG_ARCH_INTERRUPTSTACK);
+    }
+
+  return sparc_stack_check((void *)up_get_intstackbase(cpu), check_size);
 }
 #endif
 
diff --git a/arch/tricore/src/common/tricore_checkstack.c 
b/arch/tricore/src/common/tricore_checkstack.c
index 2b47107ae8c..8d2563c2792 100644
--- a/arch/tricore/src/common/tricore_checkstack.c
+++ b/arch/tricore/src/common/tricore_checkstack.c
@@ -143,10 +143,14 @@ size_t up_check_tcbstack(struct tcb_s *tcb, size_t 
check_size)
 }
 
 #if CONFIG_ARCH_INTERRUPTSTACK > 15
-size_t up_check_intstack(int cpu)
+size_t up_check_intstack(int cpu, size_t check_size)
 {
-  return tricore_stack_check((uintptr_t)g_intstackalloc,
-                           (CONFIG_ARCH_INTERRUPTSTACK & ~15));
+  if (check_size == 0)
+    {
+      check_size = CONFIG_ARCH_INTERRUPTSTACK & ~15;
+    }
+
+  return tricore_stack_check((uintptr_t)g_intstackalloc, check_size);
 }
 #endif
 
diff --git a/arch/x86_64/src/intel64/intel64_checkstack.c 
b/arch/x86_64/src/intel64/intel64_checkstack.c
index c7cdcf780a8..a1593ca8420 100644
--- a/arch/x86_64/src/intel64/intel64_checkstack.c
+++ b/arch/x86_64/src/intel64/intel64_checkstack.c
@@ -180,10 +180,14 @@ size_t up_check_tcbstack(struct tcb_s *tcb, size_t 
check_size)
 }
 
 #if CONFIG_ARCH_INTERRUPTSTACK > 3
-size_t up_check_intstack(int cpu)
+size_t up_check_intstack(int cpu, size_t check_size)
 {
-  return x86_64_stack_check((void *)up_get_intstackbase(cpu),
-                            STACK_ALIGN_DOWN(CONFIG_ARCH_INTERRUPTSTACK));
+  if (check_size == 0)
+    {
+      check_size = STACK_ALIGN_DOWN(CONFIG_ARCH_INTERRUPTSTACK);
+    }
+
+  return x86_64_stack_check((void *)up_get_intstackbase(cpu), check_size);
 }
 #endif
 
diff --git a/arch/xtensa/src/common/xtensa_checkstack.c 
b/arch/xtensa/src/common/xtensa_checkstack.c
index 5c7ba62cd59..51504e7115b 100644
--- a/arch/xtensa/src/common/xtensa_checkstack.c
+++ b/arch/xtensa/src/common/xtensa_checkstack.c
@@ -164,9 +164,14 @@ size_t up_check_tcbstack(struct tcb_s *tcb, size_t 
check_size)
 }
 
 #if CONFIG_ARCH_INTERRUPTSTACK > 15
-size_t up_check_intstack(int cpu)
+size_t up_check_intstack(int cpu, size_t check_size)
 {
-  return xtensa_stack_check(up_get_intstackbase(cpu), INTSTACK_SIZE);
+  if (check_size == 0)
+    {
+      check_size = INTSTACK_SIZE;
+    }
+
+  return xtensa_stack_check(up_get_intstackbase(cpu), check_size);
 }
 #endif
 
diff --git a/include/nuttx/arch.h b/include/nuttx/arch.h
index 13fd3571e09..b60446ae011 100644
--- a/include/nuttx/arch.h
+++ b/include/nuttx/arch.h
@@ -2565,7 +2565,7 @@ void irq_dispatch(int irq, FAR void *context);
 struct tcb_s;
 size_t up_check_tcbstack(FAR struct tcb_s *tcb, size_t check_size);
 #if defined(CONFIG_ARCH_INTERRUPTSTACK) && CONFIG_ARCH_INTERRUPTSTACK > 3
-size_t up_check_intstack(int cpu);
+size_t up_check_intstack(int cpu, size_t check_size);
 #endif
 #endif
 
diff --git a/sched/irq/irq_dispatch.c b/sched/irq/irq_dispatch.c
index 2e9bb602d6a..561eae68787 100644
--- a/sched/irq/irq_dispatch.c
+++ b/sched/irq/irq_dispatch.c
@@ -157,4 +157,9 @@ void irq_dispatch(int irq, FAR void *context)
       kmm_checkcorruption();
     }
 #endif
+
+#if defined(CONFIG_STACKCHECK_SOFTWARE) && CONFIG_STACKCHECK_MARGIN > 0
+    DEBUGASSERT(up_check_intstack(this_cpu(),
+                                  CONFIG_STACKCHECK_MARGIN) == 0);
+#endif
 }
diff --git a/sched/misc/assert.c b/sched/misc/assert.c
index 80c23814f6c..c9cb58ac4cc 100644
--- a/sched/misc/assert.c
+++ b/sched/misc/assert.c
@@ -296,7 +296,7 @@ static void dump_stacks(FAR struct tcb_s *rtcb, uintptr_t 
sp)
                      intstack_base,
                      intstack_size,
 #ifdef CONFIG_STACK_COLORATION
-                     up_check_intstack(cpu)
+                     up_check_intstack(cpu, 0)
 #else
                      0
 #endif
@@ -500,7 +500,7 @@ static void dump_tasks(void)
   for (cpu = 0; cpu < CONFIG_SMP_NCPUS; cpu++)
     {
 #  ifdef CONFIG_STACK_COLORATION
-      size_t stack_used = up_check_intstack(cpu);
+      size_t stack_used = up_check_intstack(cpu, 0);
       size_t stack_filled = 0;
 
       if (stack_used > 0)

Reply via email to