From 1d2ee95e9c1a8b2cabd5688efd6a7ba9a67b652a Mon Sep 17 00:00:00 2001 From: ouyangxiangzhen Date: Fri, 12 Jul 2024 09:45:07 +0800 Subject: [PATCH 1/5] signal: Add siginfo initializer This patch is to make Coverity happy. Signed-off-by: ouyangxiangzhen --- sched/signal/sig_notification.c | 1 + 1 file changed, 1 insertion(+) diff --git a/sched/signal/sig_notification.c b/sched/signal/sig_notification.c index a213c48563749..bfe456e8d1016 100644 --- a/sched/signal/sig_notification.c +++ b/sched/signal/sig_notification.c @@ -124,6 +124,7 @@ int nxsig_notification(pid_t pid, FAR struct sigevent *event, info.si_pid = rtcb->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 From ee764d1b3c36a0f58081c52594f9dc58744a40a4 Mon Sep 17 00:00:00 2001 From: ouyangxiangzhen Date: Sat, 14 Sep 2024 18:04:50 +0800 Subject: [PATCH 2/5] 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 bfe456e8d1016..b102da7839621 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 646d19ac8b3fa..40016f8fe6f80 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)); From 804fb72c4febe24924cc20147442b388ff70d296 Mon Sep 17 00:00:00 2001 From: ouyangxiangzhen Date: Thu, 19 Sep 2024 10:43:59 +0800 Subject: [PATCH 3/5] sched/signal: Simplify the implementation of SIGEV_THREAD_TID. This commit simplified thread ID dispatching logic by integrating it into the `nxsig_dispatch` function. Signed-off-by: ouyangxiangzhen --- sched/signal/sig_dispatch.c | 31 ++++++++++++++++++++++--------- sched/signal/sig_kill.c | 2 +- sched/signal/sig_notification.c | 23 ++++++----------------- sched/signal/sig_queue.c | 2 +- sched/signal/signal.h | 3 ++- 5 files changed, 32 insertions(+), 29 deletions(-) diff --git a/sched/signal/sig_dispatch.c b/sched/signal/sig_dispatch.c index d69fa046fa0da..7e238b8e95f7d 100644 --- a/sched/signal/sig_dispatch.c +++ b/sched/signal/sig_dispatch.c @@ -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; @@ -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; diff --git a/sched/signal/sig_kill.c b/sched/signal/sig_kill.c index 471beae977aa5..c3840e3a6c4cb 100644 --- a/sched/signal/sig_kill.c +++ b/sched/signal/sig_kill.c @@ -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); } /**************************************************************************** diff --git a/sched/signal/sig_notification.c b/sched/signal/sig_notification.c index b102da7839621..8f962603906e5 100644 --- a/sched/signal/sig_notification.c +++ b/sched/signal/sig_notification.c @@ -112,8 +112,8 @@ 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 */ @@ -121,7 +121,7 @@ int nxsig_notification(pid_t pid, FAR struct sigevent *event, 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; @@ -134,28 +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. Before the notification, we should - * validate the tid and make sure that the notified thread is - * in same process with current thread. - */ + /* SIGEV_THREAD_ID currently used only by POSIX timer. */ if (event->sigev_notify & SIGEV_THREAD_ID) { - FAR struct tcb_s *ptcb; - ptcb = nxsched_get_tcb(event->sigev_notify_thread_id); - if (ptcb != NULL && ptcb->group == rtcb->group) - { - return nxsig_tcbdispatch(ptcb, &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 diff --git a/sched/signal/sig_queue.c b/sched/signal/sig_queue.c index acea7b590f93a..cc0589e611e9a 100644 --- a/sched/signal/sig_queue.c +++ b/sched/signal/sig_queue.c @@ -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); } /**************************************************************************** diff --git a/sched/signal/signal.h b/sched/signal/signal.h index c4d88e144214f..7fef91d116d4c 100644 --- a/sched/signal/signal.h +++ b/sched/signal/signal.h @@ -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 */ From e3876c534dc7c6934a0560ead91d28a8b136e815 Mon Sep 17 00:00:00 2001 From: ouyangxiangzhen Date: Fri, 20 Sep 2024 09:47:35 +0800 Subject: [PATCH 4/5] Revert "olimex-stm32-p407: adjust memory layout" This reverts commit 9a9d0a647ef1b123627872ab7e139c1c5b9be1a0. --- boards/arm/stm32/olimex-stm32-p407/scripts/memory.ld | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/boards/arm/stm32/olimex-stm32-p407/scripts/memory.ld b/boards/arm/stm32/olimex-stm32-p407/scripts/memory.ld index eab64c6580b45..96fa7b81383a1 100644 --- a/boards/arm/stm32/olimex-stm32-p407/scripts/memory.ld +++ b/boards/arm/stm32/olimex-stm32-p407/scripts/memory.ld @@ -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 } From 1a20c23446555790212a015ad6316c5fe76220f4 Mon Sep 17 00:00:00 2001 From: ouyangxiangzhen Date: Mon, 23 Sep 2024 09:29:57 +0800 Subject: [PATCH 5/5] sched/signal: Add ifdef macro to reduce the bss size. This commit added ifdef macro to sigwork_s. When CONFIG_SIG_EVTHREAD is not defined, the struct sigwork_s will be empty struct, which is helpful to reduce bss size. Signed-off-by: ouyangxiangzhen --- include/nuttx/signal.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/include/nuttx/signal.h b/include/nuttx/signal.h index 875cba404217b..cd52a9d1e0adf 100644 --- a/include/nuttx/signal.h +++ b/include/nuttx/signal.h @@ -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