Repository navigation
Conversation
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 <marco.casaroli@gmail.com>
xiaoxiang781216
approved these changes
Nov 17, 2026
|
casaroli
marked this pull request as ready for review
November 17, 2026 23:34
casaroli
marked this pull request as draft
November 18, 2026 00:39
casaroli
marked this pull request as ready for review
November 18, 2026 00:39
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
depends-on: /pull/21975
Summary
On x86_64 (intel64), a divide error (ISR0) or an x87 FPU error (ISR16) goes to
x86_64_fault_kill_isr(). This handler 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. One example is a divide by zero in the idle task at boot, whichqemu-intel64:nshandqemu-intel64:knsh_romfswithCONFIG_RTC_HIRESand the HPET timer show: the console stays empty afterBooting from ROM...This PR sends the kernel faults to the panic path of
x86_64_fault_panic_isr(), which prints the exception and the register dump. A fault belongs to the kernel when the task is a kernel thread or the idle task, or, in a build with a user mode, when the CPU was in ring 0 (a system call or an interrupt handler).x86_64_fault_user_isr()makes the same decision for ISR6, ISR13 and ISR14, and arm64 and RISC-V make it for their user faults. A user task still gets SIGFPE.In the flat build all code runs in ring 0, so the CPL cannot tell a task from the kernel. There, only kernel threads and the idle task panic, and all other tasks get SIGFPE as before.
Impact
x86_64 intel64 only. A divide error or an x87 FPU error of the kernel now panics with a register dump instead of a silent hang. A user process in the kernel build and a task in the flat build get SIGFPE as before. Not a breaking change: no API change, and the flat build keeps SIGFPE for all tasks. No Kconfig change, no build file change.
Testing
QEMU 10.2.2 under KVM, GCC 12.3 in the NuttX CI image, make. "HPET" means
ARCH_INTEL64_HPET_ALARMandINTEL64_HPETinstead of the TSC deadline timer. A test program (ashello) divides by zero with a SIGFPE handler (fpe, the handler prints and calls_exit()) and without one (fpedef).nsh(flat), HPET,RTC,RTC_HIRESx86_64_fault_panic_isr: Exception 0 occurred, assertion inIdle_Task,CPL: 0, register dump withRSI: 0knsh_romfs(kernel), HPET,RTC,RTC_HIRESnsh, TSC deadlinehello fpe,hello fpedef,psSIGFPE caught; the default action endshello; NSH runs onknsh_romfs, HPET,SCHED_IRQMONITOR,ARCH_PERF_EVENTScat /proc/irqs(divide by zero inup_perf_convert()in a system call of NSH)/system/bin/init,CPL: 0nsh, HPET,SCHED_IRQMONITOR,ARCH_PERF_EVENTScat /proc/irqsshknsh_romfs, TSC deadline/system/bin/hello fpex86_64_sigdeliver(a separate master bug: the signal trampoline keeps the user CS)With a test-only fix of that trampoline bug (the trampoline gets the kernel CS and SS),
knsh_romfs/system/bin/hello fpeprintsSIGFPE caughton master and on this PR: the user process still gets SIGFPE.x86_64 has no protected build. No CI test covers this: ostest does not divide by zero, and no x86_64 CI configuration runs a kernel fault.
tools/checkpatch.sh -c -u -m -gpasses.