From 6a41b524b9703d3c08f9bb074c75dce7865ee3be Mon Sep 17 00:00:00 2001 From: Jukka Laitinen Date: Fri, 29 Aug 2025 18:05:32 +0300 Subject: [PATCH 1/2] sched/signal/sig_dispatch.c: Correct signal dispatch to specific thread The signal dispatch is called from interrupt handlers as well, so this_task() is wrong. The thread to which the signal is supposed to be delivered is known (stcb), use that. Signed-off-by: Jukka Laitinen --- sched/signal/sig_dispatch.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/sched/signal/sig_dispatch.c b/sched/signal/sig_dispatch.c index b1cb1e9d4ef6e..59c98ee7c22b4 100644 --- a/sched/signal/sig_dispatch.c +++ b/sched/signal/sig_dispatch.c @@ -755,12 +755,12 @@ int nxsig_dispatch(pid_t pid, FAR siginfo_t *info, bool thread) { if (thread) { - /* Before the notification, we should validate the tid and - * and make sure that the notified thread is in same process - * with the current thread. + /* Before the notification, we should validate the tid. If the + * signal is to be delivered to a thread which has exited, it is + * just dropped. */ - if (stcb != NULL && group == this_task()->group) + if (stcb != NULL) { return nxsig_tcbdispatch(stcb, info, false); } From 26bae56ac614cce168c7a7b6fa4d702a1e894965 Mon Sep 17 00:00:00 2001 From: Jukka Laitinen Date: Fri, 29 Aug 2025 18:55:28 +0300 Subject: [PATCH 2/2] sched/signal/sig_dispatch.c: Simplify the nxsig_dispatch The nxsig_dispatch should just deliver the signal to either a thread by pid (tid) or to the process (group) by pid. Simplify the code so that the intent is more obvious. Signed-off-by: Jukka Laitinen --- sched/signal/sig_dispatch.c | 67 +++++++------------------------------ 1 file changed, 13 insertions(+), 54 deletions(-) diff --git a/sched/signal/sig_dispatch.c b/sched/signal/sig_dispatch.c index 59c98ee7c22b4..f65adac2bb667 100644 --- a/sched/signal/sig_dispatch.c +++ b/sched/signal/sig_dispatch.c @@ -725,70 +725,29 @@ int nxsig_tcbdispatch(FAR struct tcb_s *stcb, siginfo_t *info, int nxsig_dispatch(pid_t pid, FAR siginfo_t *info, bool thread) { #ifdef HAVE_GROUP_MEMBERS - FAR struct tcb_s *stcb; - FAR struct task_group_s *group; - - /* Get the TCB associated with the pid */ - - stcb = nxsched_get_tcb(pid); - if (stcb != NULL) + if (!thread) { - /* The task/thread associated with this PID is still active. Get its - * task group. + /* Find the group by process PID and call group signal() to send the + * signal to the correct group member. */ - group = stcb->group; + FAR struct task_group_s *group = task_getgroup(pid); + if (group != NULL) + { + return group_signal(group, info); + } } else +#endif { - /* The task/thread associated with this PID has exited. In the normal - * usage model, the PID should correspond to the PID of the task that - * created the task group. Try looking it up. - */ - - group = task_getgroup(pid); - } - - /* Did we locate the group? */ - - if (group != NULL) - { - if (thread) - { - /* Before the notification, we should validate the tid. If the - * signal is to be delivered to a thread which has exited, it is - * just dropped. - */ + /* Get the TCB associated with the thread TID */ - if (stcb != NULL) - { - return nxsig_tcbdispatch(stcb, info, false); - } - } - else + FAR struct tcb_s *stcb = nxsched_get_tcb(pid); + if (stcb != NULL) { - /* Yes.. call group_signal() to send the signal to the correct - * group member. - */ - - return group_signal(group, info); + return nxsig_tcbdispatch(stcb, info, false); } } return -ESRCH; - -#else - FAR struct tcb_s *stcb; - - /* Get the TCB associated with the pid */ - - stcb = nxsched_get_tcb(pid); - if (stcb == NULL) - { - return -ESRCH; - } - - return nxsig_tcbdispatch(stcb, info, false); - -#endif }