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
The following commit(s) were added to refs/heads/master by this push:
new c2eccbd124e arch/x86_64: Put each signal handler of a delivery under
the interrupted code.
c2eccbd124e is described below
commit c2eccbd124e608cc412b385dcf600df18f0adda2
Author: Marco Casaroli <[email protected]>
AuthorDate: Sun Nov 15 06:52:49 2026 +0100
arch/x86_64: Put each signal handler of a delivery under the interrupted
code.
Each system call entry sets xcp.saved_ursp to the user stack pointer,
and SYS_signal_handler builds the frame of a user signal handler under
it. A signal that comes while a handler runs is queued, and
nxsig_deliver() runs it when that handler returns, before the thread
goes back to the interrupted code. Then saved_ursp is the stack pointer
of the last system call of the handler before, and the next frame goes
under it. So each handler of a burst of signals starts lower on the
user stack, until the stack ends and the thread gets a page fault.
Keep saved_ursp in up_signal_dispatch() and put it back when the handler
returns. Then every handler of the delivery goes under the stack of the
interrupted code. arm64 and RISC-V take the stack pointer of the
interrupted code from its saved frame and do not have this problem.
Assisted-by: Claude Code:claude-opus-5-5
Signed-off-by: Marco Casaroli <[email protected]>
---
arch/x86_64/src/common/x86_64_signal_dispatch.c | 14 ++++++++++++++
1 file changed, 14 insertions(+)
diff --git a/arch/x86_64/src/common/x86_64_signal_dispatch.c
b/arch/x86_64/src/common/x86_64_signal_dispatch.c
index 8323fc2e583..598d617e156 100644
--- a/arch/x86_64/src/common/x86_64_signal_dispatch.c
+++ b/arch/x86_64/src/common/x86_64_signal_dispatch.c
@@ -69,10 +69,24 @@
void up_signal_dispatch(_sa_sigaction_t sighand, int signo,
siginfo_t *info, void *ucontext)
{
+#ifdef CONFIG_ARCH_KERNEL_STACK
+ /* The system calls of the handler change xcp.saved_ursp. Put it back:
+ * the next handler of this delivery must also go under the stack of the
+ * interrupted code, not under the stack of this handler.
+ */
+
+ struct tcb_s *rtcb = nxsched_self();
+ uint64_t ursp = rtcb->xcp.saved_ursp;
+#endif
+
/* Let sys_call4() do all of the work */
sys_call4(SYS_signal_handler, (uintptr_t)sighand, (uintptr_t)signo,
(uintptr_t)info, (uintptr_t)ucontext);
+
+#ifdef CONFIG_ARCH_KERNEL_STACK
+ rtcb->xcp.saved_ursp = ursp;
+#endif
}
#endif