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 91cc9f56502 arch/sim: Deliver a signal after the interrupt, not in it.
91cc9f56502 is described below
commit 91cc9f56502f1d5cc26e688c06017ce6222a52b7
Author: Marco Casaroli <[email protected]>
AuthorDate: Thu Nov 12 00:00:30 2026 +0100
arch/sim: Deliver a signal after the interrupt, not in it.
up_schedule_sigaction() ran the signal handler at once when the target was
the running task, also when an interrupt handler called it. A timer that
signals a running task (for example alarm() while the task spins) then ran
the handler of the task inside sim_doirq(), in interrupt context. A handler
that calls exit() exits the task from the interrupt handler and breaks the
scheduler state: the next blocking call of the shell fails the assertion
!is_idle_task(rtcb) in nxsem_wait_slow(). The LTP tests pthread_spin_lock
1-1 and 3-2 do this.
Other architectures change the return context of the interrupt, so that the
task runs the handler after the interrupt. Do the same in the simulator: in
an interrupt handler, up_schedule_sigaction() keeps sigdeliver, and
sim_doirq() calls sim_sigdeliver() when the interrupted task resumes, as
up_switch_context() already does for a task that it switches back in. A
signal that another task sends to a task that an interrupt preempted now
also runs when that task resumes, not at its next context switch.
Assisted-by: Claude Code:claude-opus-5-5
Signed-off-by: Marco Casaroli <[email protected]>
---
arch/sim/src/sim/sim_doirq.c | 10 ++++++++++
arch/sim/src/sim/sim_schedulesigaction.c | 9 ++++++---
2 files changed, 16 insertions(+), 3 deletions(-)
diff --git a/arch/sim/src/sim/sim_doirq.c b/arch/sim/src/sim/sim_doirq.c
index 4086530d82d..d195ec6a7be 100644
--- a/arch/sim/src/sim/sim_doirq.c
+++ b/arch/sim/src/sim/sim_doirq.c
@@ -110,6 +110,16 @@ void *sim_doirq(int irq, void *context)
sim_fullcontextrestore(regs);
}
+#ifdef CONFIG_ENABLE_ALL_SIGNALS
+ else
+ {
+ /* The task resumes here, out of the interrupt handler. Deliver the
+ * signals that the interrupt handler queued for it.
+ */
+
+ sim_sigdeliver();
+ }
+#endif
return NULL;
}
diff --git a/arch/sim/src/sim/sim_schedulesigaction.c
b/arch/sim/src/sim/sim_schedulesigaction.c
index ba69906b7da..6e0e085e059 100644
--- a/arch/sim/src/sim/sim_schedulesigaction.c
+++ b/arch/sim/src/sim/sim_schedulesigaction.c
@@ -75,11 +75,14 @@
void up_schedule_sigaction(struct tcb_s *tcb)
{
- /* We don't have to anything complex for the simulated target */
-
sinfo("tcb=%p\n", tcb);
- if (tcb == this_task())
+ /* Run the handler now only in the thread context of the task. In an
+ * interrupt handler, keep sigdeliver: sim_doirq() runs it when the task
+ * resumes, and up_switch_context() when the task is switched back in.
+ */
+
+ if (tcb == this_task() && !up_interrupt_context())
{
(tcb->sigdeliver)(tcb);
tcb->sigdeliver = NULL;