From 0373ba0fab026266aa2c9849ce59b76afac2ee38 Mon Sep 17 00:00:00 2001 From: ouyangxiangzhen Date: Sat, 14 Sep 2024 18:04:50 +0800 Subject: [PATCH] sched/signal: Simplified Implementation for SIGEV_THREAD_TID. This commit simplified the implementation for SIGEV_THREAD_TID. Signed-off-by: ouyangxiangzhen --- sched/signal/sig_notification.c | 12 +++++++----- sched/timer/timer_create.c | 19 ------------------- 2 files changed, 7 insertions(+), 24 deletions(-) diff --git a/sched/signal/sig_notification.c b/sched/signal/sig_notification.c index bfe456e8d1..b102da7839 100644 --- a/sched/signal/sig_notification.c +++ b/sched/signal/sig_notification.c @@ -134,16 +134,18 @@ int nxsig_notification(pid_t pid, FAR struct sigevent *event, memcpy(&info.si_value, &event->sigev_value, sizeof(union sigval)); - /* Used only by POSIX timer. Notice that it is UNSAFE, unless - * we GUARANTEE that event->sigev_notify_thread_id is valid. + /* Used only by POSIX timer. Before the notification, we should + * validate the tid and make sure that the notified thread is + * in same process with current thread. */ if (event->sigev_notify & SIGEV_THREAD_ID) { - rtcb = nxsched_get_tcb(event->sigev_notify_thread_id); - if (rtcb != NULL) + FAR struct tcb_s *ptcb; + ptcb = nxsched_get_tcb(event->sigev_notify_thread_id); + if (ptcb != NULL && ptcb->group == rtcb->group) { - return nxsig_tcbdispatch(rtcb, &info); + return nxsig_tcbdispatch(ptcb, &info); } else { diff --git a/sched/timer/timer_create.c b/sched/timer/timer_create.c index 646d19ac8b..40016f8fe6 100644 --- a/sched/timer/timer_create.c +++ b/sched/timer/timer_create.c @@ -191,25 +191,6 @@ int timer_create(clockid_t clockid, FAR struct sigevent *evp, if (evp) { - FAR struct tcb_s *ntcb; - - /* Check the SIGEV_THREAD_ID and validate the tid */ - - if (evp->sigev_notify & SIGEV_THREAD_ID) - { - /* Make sure that the notified thread is - * in same process with current thread. - */ - - ntcb = nxsched_get_tcb(evp->sigev_notify_thread_id); - - if (ntcb == NULL || tcb->group != ntcb->group) - { - set_errno(EINVAL); - return ERROR; - } - } - /* Yes, copy the entire struct sigevent content */ memcpy(&ret->pt_event, evp, sizeof(struct sigevent));