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

GUIDINGLI 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 4abc231df49 arch/x86_64/intel64: Panic on a divide error in the kernel.
4abc231df49 is described below

commit 4abc231df492144345bb378f049a54c96f11524e
Author: Marco Casaroli <[email protected]>
AuthorDate: Tue Nov 17 14:03:34 2026 +0100

    arch/x86_64/intel64: Panic on a divide error in the kernel.
    
    x86_64_fault_kill_isr() handles ISR0 (divide error) and ISR16 (x87 FPU
    error).  It sends SIGFPE to the running task and returns to the
    instruction that faulted.  When the kernel itself faulted, no task can
    handle the signal: the CPU executes the same instruction again and again,
    and the system hangs without a message.
    
    Use the panic path of x86_64_fault_panic_isr() when the fault belongs to
    the kernel: the task is a kernel thread or the idle task, or, in a build
    with a user mode, the CPU was in ring 0.  x86_64_fault_user_isr() makes
    the same decision for ISR6, ISR13 and ISR14.  A user task still gets
    SIGFPE.  In the flat build all code runs in ring 0, so there the task
    type alone decides, as before for all tasks except the kernel threads.
    
    Assisted-by: Claude Code:claude-opus-5-5
    Signed-off-by: Marco Casaroli <[email protected]>
---
 arch/x86_64/src/intel64/intel64_irq.c | 20 +++++++++++++++++++-
 1 file changed, 19 insertions(+), 1 deletion(-)

diff --git a/arch/x86_64/src/intel64/intel64_irq.c 
b/arch/x86_64/src/intel64/intel64_irq.c
index c86c5b6eec0..52791fce5c6 100644
--- a/arch/x86_64/src/intel64/intel64_irq.c
+++ b/arch/x86_64/src/intel64/intel64_irq.c
@@ -620,13 +620,31 @@ static int x86_64_fault_user_isr(int irq, void *c, void 
*arg)
 
 /****************************************************************************
  * Name: x86_64_fault_kill_isr
+ *
+ * Description:
+ *   Send SIGFPE to the task that raised a divide error or an x87 FPU
+ *   error.  The handler returns to the instruction that faulted, so a fault
+ *   of the kernel itself (a kernel thread, the idle task, or ring 0 code in
+ *   a build with a user mode) panics instead of looping on that instruction.
+ *
  ****************************************************************************/
 
 static int x86_64_fault_kill_isr(int irq, void *c, void *arg)
 {
+  struct tcb_s *tcb = this_task();
+
+  if ((tcb->flags & TCB_FLAG_TTYPE_MASK) == TCB_FLAG_TTYPE_KERNEL
+#ifndef CONFIG_BUILD_FLAT
+      || (tcb->xcp.regs[REG_CS] & X86_GDT_PL_MASK) != X86_GDT_RPL_USER
+#endif
+     )
+    {
+      return x86_64_fault_panic_isr(irq, c, arg);
+    }
+
   __asm__ volatile("fnclex":::"memory");
 
-  nxsig_kill(running_task()->pid, SIGFPE);
+  nxsig_kill(tcb->pid, SIGFPE);
 
   return 0;
 }

Reply via email to