sched/signal: Add support for disabling all signal functions

Signals in NuttX serve two primary purposes:

      1. Synchronization and wake-up:
        Signals can be used to block threads on specific signal sets and later
        wake them up by delivering the corresponding signals to those threads.

      2. Asynchronous notification:
        Signals can also be used to install callback handlers for specific signals, allowing threads to
        asynchronously invoke those handlers when the signals are delivered.

    This change introduces the ability to  disable all signal functionality to reduce footprint for NuttX.

Signed-off-by: Chengdong Wang wangchengdong@lixiang.com
This commit is contained in:
wangchengdong
2026-01-12 09:11:52 +08:00
committed by Alan C. Assis
parent 0ea686bc5b
commit faf864b04f
19 changed files with 104 additions and 53 deletions
+2 -1
View File
@@ -640,10 +640,11 @@ static ssize_t proc_status(FAR struct proc_file_s *procfile,
}
/* Show the signal mask. Note: sigset_t is uint32_t on NuttX. */
#ifndef CONFIG_DISABLE_ALL_SIGNALS
linesize = procfs_snprintf(procfile->line, STATUS_LINELEN,
"%-12s" SIGSET_FMT "\n",
"SigMask:", SIGSET_ELEM(&tcb->sigprocmask));
#endif
copysize = procfs_memcpy(procfile->line, linesize, buffer, remaining,
&offset);
+1
View File
@@ -51,6 +51,7 @@ endif # TIMER_FD
config SIGNAL_FD
bool "SignalFD"
depends on !DISABLE_ALL_SIGNALS
default n
---help---
Create a file descriptor for accepting signals
+2
View File
@@ -667,9 +667,11 @@ struct tcb_s
sq_queue_t sigpendactionq; /* List of pending signal actions */
sq_queue_t sigpostedq; /* List of posted signals */
#endif /* CONFIG_ENABLE_ALL_SIGNALS*/
#ifndef CONFIG_DISABLE_ALL_SIGNALS
sigset_t sigprocmask; /* Signals that are blocked */
sigset_t sigwaitmask; /* Waiting for pending signals */
siginfo_t *sigunbinfo; /* Signal info when task unblocked */
#endif /* !CONFIG_DISABLE_ALL_SIGNALS */
/* Robust mutex support ***************************************************/
+2
View File
@@ -158,11 +158,13 @@ SYSCALL_LOOKUP(tgkill, 3)
SYSCALL_LOOKUP(sigaction, 3)
SYSCALL_LOOKUP(sigpending, 1)
#endif
#ifndef CONFIG_DISABLE_ALL_SIGNALS
SYSCALL_LOOKUP(sigprocmask, 3)
SYSCALL_LOOKUP(sigqueue, 3)
SYSCALL_LOOKUP(sigsuspend, 1)
SYSCALL_LOOKUP(sigtimedwait, 3)
SYSCALL_LOOKUP(sigwaitinfo, 2)
#endif
SYSCALL_LOOKUP(clock_nanosleep, 4)
/* The following are only defined if the system clock is enabled in the
+5 -5
View File
@@ -269,11 +269,11 @@
"setlogmask","syslog.h","","int","int"
"setpriority","sys/resource.h","","int","int","id_t","int"
"shutdown","sys/socket.h","defined(CONFIG_NET)","int","int","int"
"sigaddset","signal.h","","int","FAR sigset_t *","int"
"sigdelset","signal.h","","int","FAR sigset_t *","int"
"sigemptyset","signal.h","","int","FAR sigset_t *"
"sigfillset","signal.h","","int","FAR sigset_t *"
"sigismember","signal.h","","int","FAR const sigset_t *","int"
"sigaddset","signal.h","!defined(CONFIG_DISABLE_ALL_SIGNALS)","int","FAR sigset_t *","int"
"sigdelset","signal.h","!defined(CONFIG_DISABLE_ALL_SIGNALS)","int","FAR sigset_t *","int"
"sigemptyset","signal.h","!defined(CONFIG_DISABLE_ALL_SIGNALS)","int","FAR sigset_t *"
"sigfillset","signal.h","!defined(CONFIG_DISABLE_ALL_SIGNALS)","int","FAR sigset_t *"
"sigismember","signal.h","!defined(CONFIG_DISABLE_ALL_SIGNALS)","int","FAR const sigset_t *","int"
"signal","signal.h","defined(CONFIG_ENABLE_ALL_SIGNALS)","_sa_handler_t","int","_sa_handler_t"
"sleep","unistd.h","","unsigned int","unsigned int"
"snprintf","stdio.h","","int","FAR char *","size_t","FAR const IPTR char *","..."
1 __assert assert.h void FAR const char * int FAR const char *
269 setlogmask syslog.h int int
270 setpriority sys/resource.h int int id_t int
271 shutdown sys/socket.h defined(CONFIG_NET) int int int
272 sigaddset signal.h !defined(CONFIG_DISABLE_ALL_SIGNALS) int FAR sigset_t * int
273 sigdelset signal.h !defined(CONFIG_DISABLE_ALL_SIGNALS) int FAR sigset_t * int
274 sigemptyset signal.h !defined(CONFIG_DISABLE_ALL_SIGNALS) int FAR sigset_t *
275 sigfillset signal.h !defined(CONFIG_DISABLE_ALL_SIGNALS) int FAR sigset_t *
276 sigismember signal.h !defined(CONFIG_DISABLE_ALL_SIGNALS) int FAR const sigset_t * int
277 signal signal.h defined(CONFIG_ENABLE_ALL_SIGNALS) _sa_handler_t int _sa_handler_t
278 sleep unistd.h unsigned int unsigned int
279 snprintf stdio.h int FAR char * size_t FAR const IPTR char *
+21 -19
View File
@@ -20,25 +20,27 @@
#
# ##############################################################################
set(SRCS
sig_addset.c
sig_delset.c
sig_emptyset.c
sig_fillset.c
sig_nandset.c
sig_andset.c
sig_orset.c
sig_xorset.c
sig_isemptyset.c
sig_killpg.c
sig_altstack.c
sig_hold.c
sig_ismember.c
sig_pause.c
sig_psignal.c
sig_raise.c
sig_relse.c
sig_wait.c)
if(NOT CONFIG_DISABLE_ALL_SIGNALS)
set(SRCS
sig_addset.c
sig_delset.c
sig_emptyset.c
sig_fillset.c
sig_nandset.c
sig_andset.c
sig_orset.c
sig_xorset.c
sig_isemptyset.c
sig_killpg.c
sig_altstack.c
sig_hold.c
sig_ismember.c
sig_pause.c
sig_psignal.c
sig_raise.c
sig_relse.c
sig_wait.c)
endif()
if(CONFIG_ENABLE_ALL_SIGNALS)
list(APPEND SRCS sig_ignore.c sig_interrupt.c sig_set.c sig_signal.c)
+2
View File
@@ -22,11 +22,13 @@
# Add the signal C files to the build
ifneq ($(CONFIG_DISABLE_ALL_SIGNALS),y)
CSRCS += sig_addset.c sig_delset.c sig_emptyset.c sig_fillset.c
CSRCS += sig_nandset.c sig_andset.c sig_orset.c sig_xorset.c
CSRCS += sig_isemptyset.c sig_killpg.c sig_altstack.c
CSRCS += sig_hold.c sig_ismember.c sig_pause.c sig_psignal.c
CSRCS += sig_raise.c sig_relse.c sig_wait.c
endif
ifeq ($(CONFIG_ENABLE_ALL_SIGNALS),y)
CSRCS += sig_ignore.c sig_interrupt.c sig_set.c sig_signal.c
+2
View File
@@ -87,7 +87,9 @@ int posix_spawnattr_init(posix_spawnattr_t *attr)
/* Empty signal mask */
#ifndef CONFIG_DISABLE_ALL_SIGNALS
sigemptyset(&attr->sigmask);
#endif
#ifdef CONFIG_SCHED_SPORADIC
/* Sporadic scheduling parameters */
+15
View File
@@ -1578,6 +1578,21 @@ config ENABLE_PARTIAL_SIGNALS
- Applications using basic signals without fork/exec
- Resource-constrained real-time systems
config DISABLE_ALL_SIGNALS
bool "Disable all signal support"
select DISABLE_MQUEUE_NOTIFICATION
---help---
Disable all signal-related functionality, including signal
handling, thread cancellation, timers, and process-related
notifications.
This option provides the smallest footprint and maximum
resource savings.
Typical use cases:
- Hard real-time or safety-critical systems
- Applications that do not use POSIX signals or timers
endchoice
config SIG_PREALLOC_ACTIONS
+5 -2
View File
@@ -27,8 +27,11 @@ set(SRCS
group_setupidlefiles.c
group_setuptaskfiles.c
group_foreachchild.c
group_killchildren.c
group_signal.c)
group_killchildren.c)
if(NOT CONFIG_DISABLE_ALL_SIGNALS)
list(APPEND SRCS group_signal.c)
endif()
if(CONFIG_SCHED_HAVE_PARENT)
if(CONFIG_SCHED_CHILD_STATUS)
+5 -1
View File
@@ -22,7 +22,11 @@
CSRCS += group_create.c group_join.c group_leave.c
CSRCS += group_setupidlefiles.c group_setuptaskfiles.c
CSRCS += group_foreachchild.c group_killchildren.c group_signal.c
CSRCS += group_foreachchild.c group_killchildren.c
ifneq ($(CONFIG_DISABLE_ALL_SIGNALS),y)
CSRCS += group_signal.c
endif
ifeq ($(CONFIG_SCHED_HAVE_PARENT),y)
ifeq ($(CONFIG_SCHED_CHILD_STATUS),y)
+4
View File
@@ -405,7 +405,9 @@ static void dump_task(FAR struct tcb_s *tcb, FAR void *arg)
#endif
" %3d %-8s %-7s %-3c"
" %-18s"
#ifndef CONFIG_DISABLE_ALL_SIGNALS
" " SIGSET_FMT
#endif
" %p"
" %7zu"
#ifdef CONFIG_STACK_COLORATION
@@ -427,7 +429,9 @@ static void dump_task(FAR struct tcb_s *tcb, FAR void *arg)
>> TCB_FLAG_TTYPE_SHIFT]
, tcb->flags & TCB_FLAG_EXIT_PROCESSING ? 'P' : '-'
, state
#ifndef CONFIG_DISABLE_ALL_SIGNALS
, SIGSET_ELEM(&tcb->sigprocmask)
#endif
, tcb->stack_base_ptr
, tcb->adj_stack_size
#ifdef CONFIG_STACK_COLORATION
+4
View File
@@ -65,7 +65,9 @@
void nx_pthread_exit(FAR void *exit_value)
{
FAR struct tcb_s *tcb = this_task();
#ifndef CONFIG_DISABLE_ALL_SIGNALS
sigset_t set;
#endif
int status;
sinfo("exit_value=%p\n", exit_value);
@@ -76,8 +78,10 @@ void nx_pthread_exit(FAR void *exit_value)
* are performing the JOIN handshake.
*/
#ifndef CONFIG_DISABLE_ALL_SIGNALS
sigfillset(&set);
nxsig_procmask(SIG_SETMASK, &set, NULL);
#endif
/* Complete pending join operations */
+19 -17
View File
@@ -20,23 +20,25 @@
#
# ##############################################################################
set(SRCS
sig_procmask.c
sig_suspend.c
sig_kill.c
sig_tgkill.c
sig_queue.c
sig_waitinfo.c
sig_timedwait.c
sig_lowest.c
sig_notification.c
sig_dispatch.c
sig_pause.c
sig_nanosleep.c
sig_usleep.c
sig_sleep.c
sig_ppoll.c
sig_pselect.c)
if(NOT CONFIG_DISABLE_ALL_SIGNALS)
set(SRCS
sig_procmask.c
sig_suspend.c
sig_kill.c
sig_tgkill.c
sig_queue.c
sig_waitinfo.c
sig_timedwait.c
sig_lowest.c
sig_notification.c
sig_dispatch.c
sig_pause.c
sig_nanosleep.c
sig_usleep.c
sig_sleep.c
sig_ppoll.c
sig_pselect.c)
endif()
if(CONFIG_ENABLE_ALL_SIGNALS)
list(
+2 -1
View File
@@ -19,11 +19,12 @@
# under the License.
#
############################################################################
ifneq ($(CONFIG_DISABLE_ALL_SIGNALS),y)
CSRCS += sig_dispatch.c sig_kill.c sig_lowest.c sig_nanosleep.c
CSRCS += sig_notification.c sig_pause.c sig_ppoll.c sig_procmask.c
CSRCS += sig_pselect.c sig_queue.c sig_sleep.c sig_suspend.c sig_tgkill.c
CSRCS += sig_timedwait.c sig_usleep.c sig_waitinfo.c
endif
ifeq ($(CONFIG_ENABLE_ALL_SIGNALS),y)
CSRCS += sig_action.c sig_allocpendingsigaction.c sig_cleanup.c sig_deliver.c
+2
View File
@@ -122,7 +122,9 @@ static void nxtask_reset_task(FAR struct tcb_s *tcb, bool remove)
#ifdef CONFIG_ENABLE_ALL_SIGNALS
nxsig_cleanup(tcb); /* Deallocate Signal lists */
#endif
#ifndef CONFIG_DISABLE_ALL_SIGNALS
sigemptyset(&tcb->sigprocmask); /* Reset sigprocmask */
#endif
/* Reset the current task priority */
+2
View File
@@ -461,7 +461,9 @@ static int nxthread_setup_scheduler(FAR struct tcb_s *tcb, int priority,
* inherit the signal mask of the parent thread.
*/
#ifndef CONFIG_DISABLE_ALL_SIGNALS
tcb->sigprocmask = rtcb->sigprocmask;
#endif
/* Initialize the task state. It does not get a valid state
* until it is activated.
+2
View File
@@ -157,6 +157,7 @@ int spawn_execattrs(pid_t pid, FAR const posix_spawnattr_t *attr)
/* Firstly, set the signal mask if requested to do so */
#ifndef CONFIG_DISABLE_ALL_SIGNALS
if ((attr->flags & POSIX_SPAWN_SETSIGMASK) != 0)
{
FAR struct tcb_s *tcb = nxsched_get_tcb(pid);
@@ -165,6 +166,7 @@ int spawn_execattrs(pid_t pid, FAR const posix_spawnattr_t *attr)
tcb->sigprocmask = attr->sigmask;
}
}
#endif
/* If we are only setting the priority, then call sched_setparm()
* to set the priority of the of the new task.
+7 -7
View File
@@ -105,10 +105,10 @@
"pipe2","unistd.h","defined(CONFIG_PIPES) && CONFIG_DEV_PIPE_SIZE > 0","int","int [2]|FAR int *","int"
"poll","poll.h","","int","FAR struct pollfd *","nfds_t","int"
"posix_spawn","spawn.h","!defined(CONFIG_BINFMT_DISABLE) && defined(CONFIG_LIBC_EXECFUNCS)","int","FAR pid_t *","FAR const char *","FAR const posix_spawn_file_actions_t *","FAR const posix_spawnattr_t *","FAR char * const []|FAR char * const *","FAR char * const []|FAR char * const *"
"ppoll","poll.h","","int","FAR struct pollfd *","nfds_t","FAR const struct timespec *","FAR const sigset_t *"
"ppoll","poll.h","!defined(CONFIG_DISABLE_ALL_SIGNALS)","int","FAR struct pollfd *","nfds_t","FAR const struct timespec *","FAR const sigset_t *"
"prctl","sys/prctl.h","","int","int","...","uintptr_t","uintptr_t"
"pread","unistd.h","","ssize_t","int","FAR void *","size_t","off_t"
"pselect","sys/select.h","","int","int","FAR fd_set *","FAR fd_set *","FAR fd_set *","FAR const struct timespec *","FAR const sigset_t *"
"pselect","sys/select.h","!defined(CONFIG_DISABLE_ALL_SIGNALS)","int","int","FAR fd_set *","FAR fd_set *","FAR fd_set *","FAR const struct timespec *","FAR const sigset_t *"
"pthread_cancel","pthread.h","!defined(CONFIG_DISABLE_PTHREAD)","int","pthread_t"
"pthread_cond_broadcast","pthread.h","!defined(CONFIG_DISABLE_PTHREAD)","int","FAR pthread_cond_t *"
"pthread_cond_clockwait","pthread.h","!defined(CONFIG_DISABLE_PTHREAD)","int","FAR pthread_cond_t *","FAR pthread_mutex_t *","clockid_t","FAR const struct timespec *"
@@ -177,11 +177,11 @@
"signal","signal.h","defined(CONFIG_ENABLE_ALL_SIGNALS)","_sa_handler_t","int","_sa_handler_t"
"signalfd","sys/signalfd.h","defined(CONFIG_SIGNAL_FD)","int","int","FAR const sigset_t *","int"
"sigpending","signal.h","defined(CONFIG_ENABLE_ALL_SIGNALS)","int","FAR sigset_t *"
"sigprocmask","signal.h","","int","int","FAR const sigset_t *","FAR sigset_t *"
"sigqueue","signal.h","","int","int","int","union sigval|FAR void *|sival_ptr"
"sigsuspend","signal.h","","int","FAR const sigset_t *"
"sigtimedwait","signal.h","","int","FAR const sigset_t *","FAR struct siginfo *","FAR const struct timespec *"
"sigwaitinfo","signal.h","","int","FAR const sigset_t *","FAR struct siginfo *"
"sigprocmask","signal.h","!defined(CONFIG_DISABLE_ALL_SIGNALS)","int","int","FAR const sigset_t *","FAR sigset_t *"
"sigqueue","signal.h","!defined(CONFIG_DISABLE_ALL_SIGNALS)","int","int","int","union sigval|FAR void *|sival_ptr"
"sigsuspend","signal.h","!defined(CONFIG_DISABLE_ALL_SIGNALS)","int","FAR const sigset_t *"
"sigtimedwait","signal.h","!defined(CONFIG_DISABLE_ALL_SIGNALS)","int","FAR const sigset_t *","FAR struct siginfo *","FAR const struct timespec *"
"sigwaitinfo","signal.h","!defined(CONFIG_DISABLE_ALL_SIGNALS)","int","FAR const sigset_t *","FAR struct siginfo *"
"socket","sys/socket.h","defined(CONFIG_NET)","int","int","int","int"
"socketpair","sys/socket.h","defined(CONFIG_NET)","int","int","int","int","int [2]|FAR int *"
"stat","sys/stat.h","","int","FAR const char *","FAR struct stat *"
1 _assert assert.h void FAR const char * int FAR const char * FAR void *
105 pipe2 unistd.h defined(CONFIG_PIPES) && CONFIG_DEV_PIPE_SIZE > 0 int int [2]|FAR int * int
106 poll poll.h int FAR struct pollfd * nfds_t int
107 posix_spawn spawn.h !defined(CONFIG_BINFMT_DISABLE) && defined(CONFIG_LIBC_EXECFUNCS) int FAR pid_t * FAR const char * FAR const posix_spawn_file_actions_t * FAR const posix_spawnattr_t *
108 ppoll poll.h !defined(CONFIG_DISABLE_ALL_SIGNALS) int FAR struct pollfd * nfds_t FAR const struct timespec * FAR const sigset_t *
109 prctl sys/prctl.h int int ... uintptr_t uintptr_t
110 pread unistd.h ssize_t int FAR void * size_t off_t
111 pselect sys/select.h !defined(CONFIG_DISABLE_ALL_SIGNALS) int int FAR fd_set * FAR fd_set * FAR fd_set *
112 pthread_cancel pthread.h !defined(CONFIG_DISABLE_PTHREAD) int pthread_t
113 pthread_cond_broadcast pthread.h !defined(CONFIG_DISABLE_PTHREAD) int FAR pthread_cond_t *
114 pthread_cond_clockwait pthread.h !defined(CONFIG_DISABLE_PTHREAD) int FAR pthread_cond_t * FAR pthread_mutex_t * clockid_t FAR const struct timespec *
177 signal signal.h defined(CONFIG_ENABLE_ALL_SIGNALS) _sa_handler_t int _sa_handler_t
178 signalfd sys/signalfd.h defined(CONFIG_SIGNAL_FD) int int FAR const sigset_t * int
179 sigpending signal.h defined(CONFIG_ENABLE_ALL_SIGNALS) int FAR sigset_t *
180 sigprocmask signal.h !defined(CONFIG_DISABLE_ALL_SIGNALS) int int FAR const sigset_t * FAR sigset_t *
181 sigqueue signal.h !defined(CONFIG_DISABLE_ALL_SIGNALS) int int int union sigval|FAR void *|sival_ptr
182 sigsuspend signal.h !defined(CONFIG_DISABLE_ALL_SIGNALS) int FAR const sigset_t *
183 sigtimedwait signal.h !defined(CONFIG_DISABLE_ALL_SIGNALS) int FAR const sigset_t * FAR struct siginfo * FAR const struct timespec *
184 sigwaitinfo signal.h !defined(CONFIG_DISABLE_ALL_SIGNALS) int FAR const sigset_t * FAR struct siginfo *
185 socket sys/socket.h defined(CONFIG_NET) int int int int
186 socketpair sys/socket.h defined(CONFIG_NET) int int int int int [2]|FAR int *
187 stat sys/stat.h int FAR const char * FAR struct stat *