Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sched/signal: Simplified Implementation for SIGEV_THREAD_TID #13530

Merged
merged 5 commits into from
Sep 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions boards/arm/stm32/olimex-stm32-p407/scripts/memory.ld
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ MEMORY

/* 112Kb of contiguous SRAM */

ksram (rwx) : ORIGIN = 0x20000000, LENGTH = 16K
usram (rwx) : ORIGIN = 0x20004000, LENGTH = 16K
xsram (rwx) : ORIGIN = 0x20008000, LENGTH = 80K
ksram (rwx) : ORIGIN = 0x20000000, LENGTH = 8K
usram (rwx) : ORIGIN = 0x20002000, LENGTH = 8K
xsram (rwx) : ORIGIN = 0x20008000, LENGTH = 96K
}
2 changes: 2 additions & 0 deletions include/nuttx/signal.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,11 @@

struct sigwork_s
{
#ifdef CONFIG_SIG_EVTHREAD
struct work_s work; /* Work queue structure */
union sigval value; /* Data passed with notification */
sigev_notify_function_t func; /* Notification function */
#endif
};

#ifdef __cplusplus
Expand Down
31 changes: 22 additions & 9 deletions sched/signal/sig_dispatch.c
Original file line number Diff line number Diff line change
Expand Up @@ -600,7 +600,7 @@ int nxsig_tcbdispatch(FAR struct tcb_s *stcb, siginfo_t *info)
*
****************************************************************************/

int nxsig_dispatch(pid_t pid, FAR siginfo_t *info)
int nxsig_dispatch(pid_t pid, FAR siginfo_t *info, bool thread)
{
#ifdef HAVE_GROUP_MEMBERS
FAR struct tcb_s *stcb;
Expand Down Expand Up @@ -631,17 +631,30 @@ int nxsig_dispatch(pid_t pid, FAR siginfo_t *info)

if (group != NULL)
{
/* Yes.. call group_signal() to send the signal to the correct group
* member.
*/
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.
*/

return group_signal(group, info);
}
else
{
return -ESRCH;
if (stcb != NULL && group == this_task()->group)
{
return nxsig_tcbdispatch(stcb, info);
}
}
else
{
/* Yes.. call group_signal() to send the signal to the correct
* group member.
*/

return group_signal(group, info);
}
}

return -ESRCH;

#else
FAR struct tcb_s *stcb;

Expand Down
2 changes: 1 addition & 1 deletion sched/signal/sig_kill.c
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ int nxsig_kill(pid_t pid, int signo)

/* Send the signal */

return nxsig_dispatch(pid, &info);
return nxsig_dispatch(pid, &info, false);
}

/****************************************************************************
Expand Down
22 changes: 7 additions & 15 deletions sched/signal/sig_notification.c
Original file line number Diff line number Diff line change
Expand Up @@ -112,18 +112,19 @@ int nxsig_notification(pid_t pid, FAR struct sigevent *event,

if (event->sigev_notify & SIGEV_SIGNAL)
{
FAR struct tcb_s *rtcb = this_task();
siginfo_t info;
bool thread = false;

/* Yes.. Create the siginfo structure */

info.si_signo = event->sigev_signo;
info.si_code = code;
info.si_errno = OK;
#ifdef CONFIG_SCHED_HAVE_PARENT
info.si_pid = rtcb->pid;
info.si_pid = this_task()->pid;
info.si_status = OK;
#endif
info.si_user = NULL;

/* Some compilers (e.g., SDCC), do not permit assignment of aggregates.
* Use of memcpy() is overkill; We could just copy the larger of the
Expand All @@ -133,26 +134,17 @@ 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.
*/
/* SIGEV_THREAD_ID currently used only by POSIX timer. */

if (event->sigev_notify & SIGEV_THREAD_ID)
{
rtcb = nxsched_get_tcb(event->sigev_notify_thread_id);
if (rtcb != NULL)
{
return nxsig_tcbdispatch(rtcb, &info);
}
else
{
return -ENOENT;
}
thread = true;
pid = event->sigev_notify_thread_id;
}

/* Send the signal */

return nxsig_dispatch(pid, &info);
return nxsig_dispatch(pid, &info, thread);
}

#ifdef CONFIG_SIG_EVTHREAD
Expand Down
2 changes: 1 addition & 1 deletion sched/signal/sig_queue.c
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ int nxsig_queue(int pid, int signo, union sigval value)

/* Send the signal */

return nxsig_dispatch(pid, &info);
return nxsig_dispatch(pid, &info, false);
}

/****************************************************************************
Expand Down
3 changes: 2 additions & 1 deletion sched/signal/signal.h
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,8 @@ int nxsig_default_initialize(FAR struct tcb_s *tcb);

int nxsig_tcbdispatch(FAR struct tcb_s *stcb,
FAR siginfo_t *info);
int nxsig_dispatch(pid_t pid, FAR siginfo_t *info);
int nxsig_dispatch(pid_t pid, FAR siginfo_t *info,
bool thread);

/* sig_cleanup.c */

Expand Down
19 changes: 0 additions & 19 deletions sched/timer/timer_create.c
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
Loading