casaroli opened a new pull request, #21897: URL: https://github.com/apache/nuttx/pull/21897
## Summary In an x86_64 kernel build, each system call entry sets `xcp.saved_ursp` to the user stack pointer, and `SYS_signal_handler` puts the frame of a user signal handler under it. A signal that comes while a handler runs is queued. `nxsig_deliver()` runs it when that handler returns, before the thread goes back to the interrupted code. At that time `saved_ursp` is the stack pointer of the last system call of the handler before (for example `sem_post()` or `pthread_kill()`), so the next handler starts lower on the user stack. Each handler of a burst moves down the stack, until the stack ends and the thread gets a page fault. `up_signal_dispatch()` now keeps `saved_ursp` and puts it back when the handler returns. Every handler of one delivery then goes under the stack of the interrupted code. ## Impact x86_64 kernel builds with `CONFIG_ARCH_KERNEL_STACK` (qemu-intel64:knsh_romfs) only. A flat build does not build x86_64_signal_dispatch.c, and x86_64 has no protected build. arm64 and RISC-V take the user stack pointer of the interrupted code from its saved frame, so they do not have this problem. No API change, no documentation change. ## Testing Test program `sigburst.c`, qemu-intel64:knsh_romfs (kernel build, QEMU TCG, 1 CPU, HPET alarm timer). The handlers note the lowest and the highest address of a local variable; PASS is a spread of at most 1024 bytes. `chain`: a thread with a 64 KiB stack waits in `sem_wait()`; the handler of SIGUSR1 sends SIGUSR2 to its own thread and the other way round, 2000 handlers. `chaininfo`: the same with `SA_SIGINFO`. `pairs`: the pattern of ostest's nested signal test, 2000 pairs. - master fab614ba83d: chain FAIL (stops after 10 handlers, spread 4176 bytes, about 460 bytes per handler), chaininfo FAIL (10 handlers, 4320 bytes), pairs PASS (spread 0: with 1 CPU the signals of a pair do not come while a handler runs). ostest: `Exiting with status 0`. - this PR (on 46066440966): chain, chaininfo and pairs PASS, 2000 handlers each, spread 0 bytes. ostest: `Exiting with status 0`. Not tested in a flat build: a flat build does not build x86_64_signal_dispatch.c, so it compiles nothing of this change. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
