Repository navigation
libs/libc/unistd: Answer every POSIX name in sysconf() - #21674
Merged
Merged
Conversation
|
xiaoxiang781216
previously approved these changes
Nov 11, 2026
casaroli
force-pushed
the
i-sysconf-up
branch
from
November 11, 2026 11:32
e09b5da to
b97f817
Compare
casaroli
requested review from
GUIDINGLI,
Ouss4,
anchao,
jerpelea,
masayuki2009,
pkarashchenko and
yamt
as code owners
November 11, 2026 11:33
sigqueue() never failed with EAGAIN. Each queued signal takes an entry
from the kernel heap, so a sender could queue signals without a limit to
a task that blocks them, or that does not run. POSIX requires EAGAIN
when {SIGQUEUE_MAX} signals that the process queued are still pending at
the receiver.
sigqueue() and pthread_sigqueue() now fail with EAGAIN when SIGQUEUE_MAX
(32) signals are pending in the task group of the receiver, or queued
there for a signal handler. nxsig_tcbdispatch() counts them in the
critical section that queues the signal, so senders on other CPUs cannot
pass the limit. The count reads the lists, so no counter must follow
the paths that deliver or discard a signal.
A new argument of nxsig_dispatch(), group_signal() and
nxsig_tcbdispatch() applies the limit; only sigqueue() and
pthread_sigqueue() set it. kill(), raise(), nxsig_queue() (aio,
drivers), the timers and the message queue notifications are not
limited, but their signals count.
Impact: sigqueue() and pthread_sigqueue() of more than 32 signals to a
receiver that does not take them now fail with EAGAIN, as POSIX
requires. The other senders do not change.
Assisted-by: Claude Code:claude-opus-5-5
Signed-off-by: Marco Casaroli <[email protected]>
Give the correct name of the error and say when it occurs. Assisted-by: Claude Code:claude-opus-5-5 Signed-off-by: Marco Casaroli <[email protected]>
sysconf() knew 21 names. For all other names of <unistd.h>, also for the limits that <limits.h> defines (LINE_MAX, HOST_NAME_MAX, TIMER_MAX, PTHREAD_KEYS_MAX, ...), it returned -1 with errno ENOSYS. POSIX requires EINVAL for a name that is not valid, and -1 without a change of errno for a valid name that has no limit or an option that is not supported. Programs read -1 as "no limit" and check errno. Return the value of the <limits.h> or <unistd.h> constant for each limit and option. For an option that <unistd.h> leaves undefined, return _POSIX_VERSION if the configuration has it (fsync(), IPv6, regcomp(), the priority inheritance and protection of mutexes), else -1. The names of the C compilation environments give 1 for the environment of the build. _SC_THREAD_THREADS_MAX is -1: the number of threads has no limit (the uint8_t member count of the task group is gone). _SC_PHYS_PAGES and _SC_AVPHYS_PAGES come from sysinfo(). _SC_GETGR_R_SIZE_MAX is the buffer that getgrgid_r() needs. Return -1 with errno unchanged for the other names, and -1 with EINVAL for a name that is not valid. Assisted-by: Claude Code:claude-opus-5-5 Signed-off-by: Marco Casaroli <[email protected]>
POSIX.1-2024 lists sysconf() names that <unistd.h> did not define: _SC_DEVICE_CONTROL, _SC_NSIG, _SC_THREAD_ROBUST_PRIO_INHERIT, _SC_THREAD_ROBUST_PRIO_PROTECT, _SC_V7_* and _SC_V8_* (the C compilation environments), and _SC_XOPEN_UUCP. Define them and answer them in sysconf(): _SC_NSIG is NSIG; the robust mutex names follow the priority options and CONFIG_PTHREAD_MUTEX_UNSAFE; the environment names give the same values as the _SC_V6_* names. NuttX has no posix_devctl() and no UUCP utilities: -1. Assisted-by: Claude Code:claude-opus-5-5 Signed-off-by: Marco Casaroli <[email protected]>
casaroli
force-pushed
the
i-sysconf-up
branch
from
November 11, 2026 12:29
b97f817 to
fccf6c9
Compare
xiaoxiang781216
approved these changes
Nov 11, 2026
acassis
approved these changes
Nov 11, 2026
1 task done
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
sysconf()knew 21 names. For all other names of<unistd.h>, also for the limits that<limits.h>defines (LINE_MAX,HOST_NAME_MAX,TIMER_MAX,PTHREAD_KEYS_MAX, ...), it returned -1 witherrnoENOSYS. POSIX requiresEINVALfor a name that is not valid, and -1 without a change oferrnofor a valid name that has no limit or an option that is not supported. Programs read -1 as "no limit" or "not supported" and checkerrnoto see an error.Commits 1 and 2 come first because
sysconf(_SC_SIGQUEUE_MAX)now gives 32, andsigqueue()never failed withEAGAIN. LTPsigqueue/9-1skipped itself whilesysconf()gave -1. With the new value it queued 33 signals and printedFailed: sigqueue() queued SIGQUEUE_MAX+1 signals; CI shows this as a timeout, because the runner waits 40 s forPASS. Each queued signal takes an entry from the kernel heap, so a sender could queue signals without a limit to a task that blocks them or does not run. POSIX requiresEAGAINwhen{SIGQUEUE_MAX}signals are still pending at the receiver. With commit 1,sigqueue()andpthread_sigqueue()fail withEAGAINwhen 32 signals are pending in the task group of the receiver, or queued there for a handler.nxsig_tcbdispatch()counts them in the critical section that queues the signal, so concurrent senders cannot pass the limit. A new argument ofnxsig_dispatch(),group_signal()andnxsig_tcbdispatch()applies the limit; onlysigqueue()andpthread_sigqueue()set it.kill(),raise(),nxsig_queue()(aio, drivers), timers and message queue notifications are not limited, but their signals count. Commit 2 corrects the error name (EGAIN) inDocumentation/reference/user/07_signals.rst.Commit 3 makes
sysconf()answer every name of<unistd.h>:<limits.h>constant (or the POSIX minimum, for thebc/expr/regexlimits that<limits.h>does not define).<unistd.h>macro. For an option that<unistd.h>leaves undefined,sysconf()gives_POSIX_VERSIONif the configuration has it, else -1:_SC_FSYNC(always),_SC_IPV6(CONFIG_NET_IPv6),_SC_REGEXP(CONFIG_LIBC_REGEX),_SC_THREAD_PRIO_INHERIT(CONFIG_PRIORITY_INHERITANCE),_SC_THREAD_PRIO_PROTECT(CONFIG_PRIORITY_PROTECT).Documentation/standards/posix.rstalready lists these options as supported with the same options._SC_V6_*,_SC_XBS5_*) give 1 for the environment of the build (from the sizes ofint,long, pointers andoff_t), else -1._SC_PHYS_PAGESand_SC_AVPHYS_PAGEScome fromsysinfo()._SC_GETGR_R_SIZE_MAXis the buffer thatgetgrgid_r()needs withCONFIG_LIBC_GROUP_FILE._SC_THREAD_THREADS_MAXis -1 (no limit). The value 255 came from theuint8_tmember count of the task group, which ec08031 removed; the PID hash table grows when it is full (sched/task/task_setup.c).posix_spawn()with process groups, ...) give -1 witherrnounchanged. A name that is not valid gives -1 withEINVAL._SC_THREAD_KEYS_MAXis 0 in a configuration without pthreads, which has noCONFIG_TLS_NELEM.Commit 4 adds the
sysconf()names of POSIX.1-2024 that<unistd.h>did not define, with their answers:_SC_NSIG(NSIG),_SC_THREAD_ROBUST_PRIO_INHERITand_SC_THREAD_ROBUST_PRIO_PROTECT(the priority option and robust mutexes,!CONFIG_PTHREAD_MUTEX_UNSAFE),_SC_V7_*and_SC_V8_*(the same as_SC_V6_*),_SC_DEVICE_CONTROLand_SC_XOPEN_UUCP(-1: noposix_devctl(), no UUCP utilities).The code stays a switch: a table of the values is not smaller with
-Os(cortex-m0: 624 bytes for a table, 452 for the switch; cortex-m4: 620 and 628).Impact
sigqueue()andpthread_sigqueue()fail withEAGAINwhen 32 signals are pending or queued for a handler in the receiving task group, in every build mode; before, they queued without a limit. The other senders (kill(),raise(),nxsig_queue(), timers, message queues, aio) do not change.sysconf()gives other results in every build mode. The values below are fromqemu-armv8a:knsh(master 03aea78, then this PR):_SC_AIO_LISTIO_MAX,_SC_AIO_MAX,_SC_ARG_MAX,_SC_ATEXIT_MAX,_SC_CLK_TCK,_SC_CLOCK_SELECTION,_SC_CPUTIME,_SC_GETPW_R_SIZE_MAX,_SC_IOV_MAX,_SC_MONOTONIC_CLOCK,_SC_NGROUPS_MAX,_SC_NPROCESSORS_CONF,_SC_NPROCESSORS_ONLN,_SC_OPEN_MAX,_SC_PAGESIZE,_SC_PRIORITIZED_IO,_SC_REALTIME_SIGNALS,_SC_THREAD_CPUTIME,_SC_THREAD_STACK_MIN.EINVAL(wasENOSYS).ENOSYS):_SC_AIO_PRIO_DELTA_MAX0,_SC_BC_BASE_MAX99,_SC_BC_DIM_MAX2048,_SC_BC_SCALE_MAX99,_SC_BC_STRING_MAX1000,_SC_CHILD_MAX25,_SC_COLL_WEIGHTS_MAX2,_SC_DELAYTIMER_MAX32,_SC_EXPR_NEST_MAX32,_SC_HOST_NAME_MAX32,_SC_LINE_MAX80,_SC_LOGIN_NAME_MAX33,_SC_MQ_OPEN_MAX8,_SC_MQ_PRIO_MAX255,_SC_RE_DUP_MAX255,_SC_RTSIG_MAX32,_SC_SEM_NSEMS_MAXand_SC_SEM_VALUE_MAXINT_MAX,_SC_SIGQUEUE_MAX32,_SC_STREAM_MAX256,_SC_SYMLOOP_MAX8,_SC_THREAD_DESTRUCTOR_ITERATIONS4,_SC_THREAD_KEYS_MAX0 (CONFIG_TLS_NELEM),_SC_TIMER_MAX32,_SC_TTY_NAME_MAX32,_SC_TZNAME_MAX6,_SC_PHYS_PAGES2354,_SC_AVPHYS_PAGES2274.ENOSYS): 201712 for_SC_BARRIERS,_SC_FSYNC,_SC_READER_WRITER_LOCKS,_SC_SHARED_MEMORY_OBJECTS,_SC_THREADS,_SC_THREAD_ATTR_STACKADDR,_SC_THREAD_ATTR_STACKSIZE,_SC_THREAD_PRIORITY_SCHEDULING,_SC_THREAD_PROCESS_SHARED,_SC_VERSION; 1 for_SC_MESSAGE_PASSING,_SC_PRIORITY_SCHEDULING,_SC_SYNCHRONIZED_IO,_SC_TIMEOUTS,_SC_TIMERS,_SC_XOPEN_UNIX; 700 for_SC_XOPEN_VERSION. With the configuration options on, also_SC_THREAD_PRIO_INHERIT,_SC_THREAD_PRIO_PROTECT,_SC_REGEXP,_SC_IPV6and one compilation environment name.errnounchanged (was -1 withENOSYS): the options of this configuration that are off (_SC_ASYNCHRONOUS_IO,_SC_MAPPED_FILES,_SC_SEMAPHORES,_SC_SPIN_LOCKS,_SC_SPORADIC_SERVER, ...), the options that NuttX does not have,_SC_GETGR_R_SIZE_MAXwithoutCONFIG_LIBC_GROUP_FILE, and the compilation environments that the build does not use._SC_THREAD_THREADS_MAX: -1 witherrnounchanged (was 255)._SC_NSIG64;_SC_DEVICE_CONTROL,_SC_THREAD_ROBUST_PRIO_INHERIT,_SC_THREAD_ROBUST_PRIO_PROTECT,_SC_V7_*,_SC_V8_*,_SC_XOPEN_UUCP.In nuttx and nuttx-apps,
sysconf()is called only for_SC_PAGESIZE(fs/mmap/fs_mmisc.c,lib_valloc.c,getpagesize(), lely-canopen),_SC_OPEN_MAX(getdtablesize(),nsh_envcmds.c) and_SC_NPROCESSORS_ONLN(libuv). These values do not change.Size:
sysconf()is linked only when a program calls it.lm3s6965-ek:qemu-protected(-Os, armv7-m):sysconf164 -> 676 bytes, text 127652 -> 128164.nucleo-l432kc:nsh,rv-virt:nshandqemu-armv8a:nshdo not link it (text unchanged).Testing
Test: apache/nuttx-apps#4022 (
testing/libc/sysconf): every name gives a value or -1 witherrnounchanged; -1,INT_MINandINT_MAXgive -1 withEINVAL; the limits and options give the value of their constant;_SC_OPEN_MAXis theRLIMIT_NOFILEsoft limit; the page, processor and compilation environment names give sane values. QEMU with HVF, 1 CPU:qemu-armv8a:knsh(kernel)qemu-armv8a:nsh(flat)qemu-armv8a:knshand:nshwithPRIORITY_INHERITANCE,PRIORITY_PROTECT,FS_LARGEFILE,TLS_NELEM=8,LIBC_REGEX_SC_THREAD_PRIO_INHERIT,_SC_THREAD_PRIO_PROTECT, both_SC_THREAD_ROBUST_PRIO_*and_SC_REGEXP201712,_SC_THREAD_KEYS_MAX8,_SC_V6_LP64_OFF641 (knsh)mps2-an500:knsh(protected, armv7-m, QEMU TCG)qemu-armv8a:knshandqemu-armv8a:nshSignals (commits 1 and 2), master 17637de and this PR:
sigqueue_9_1,sim:citest(Linux, CI image)sysconf()gives -1)sigqueue()givesEAGAIN); without commit 1 it failssigqueue,sigwait*,sigtimedwait,kill,raise,sigaction,sigprocmask, ...),sim:citestsigqueue()pass, the 33rd andpthread_sigqueue()giveEAGAIN;kill()is not limited;sigwaitinfo(), delivery and thread exit free the count; a timer, a message queue and an aio notification (with theSIGPOLLofnxsig_queue()) still come at the limit; 4 threads that send at the same time queue exactly 32sim:nsh(with aio),sim:smp(4 CPUs),qemu-armv8a:knshqemu-armv8a:knshandqemu-armv8a:nsh(HVF, 1 CPU)Signal builds with
EXTRAFLAGS=-Werror, each OK:qemu-armv8a:nsh,:knsh,:nsh_smp,mps2-an500:knsh(protected),rv-virt:nsh,sim:nsh,qemu-armv8a:nshwithCONFIG_ENABLE_PARTIAL_SIGNALS,esp32s3-devkit:knsh(the two changed esp32s3 files);qemu-armv8a:nshwithCONFIG_DISABLE_PTHREAD(no group members) compiles.Builds, each OK:
rv-virt:nsh(flat, rv32) andlm3s6965-ek:qemu-protected(protected, armv7-m) withEXTRAFLAGS=-Werror;ea3131:pgnsh(arm926,CONFIG_DISABLE_PTHREAD: noCONFIG_TLS_NELEM);qemu-armv8a:nshwith CMake (Ninja) and the test, no compiler warning inlib_sysconf.cor the test.Compared with glibc 2.43 (Fedora, x86_64): an invalid name gives -1 with
EINVALon both;_SC_PAGESIZE4096,_SC_IOV_MAX1024,_SC_RTSIG_MAX32,_SC_THREAD_DESTRUCTOR_ITERATIONS4,_SC_SEM_VALUE_MAXINT_MAXand_SC_THREAD_THREADS_MAX-1 are the same;_SC_OPEN_MAXis theRLIMIT_NOFILEsoft limit on both. The values that come from the configuration differ:_SC_CLK_TCK(NuttXCONFIG_USEC_PER_TICK, 1000 here; Linux 100),_SC_HOST_NAME_MAX(CONFIG_HOST_NAME_MAX32; Linux 64),_SC_NPROCESSORS_*(CONFIG_SMP_NCPUS).tools/checkpatch.sh -c -u -m -g origin/master..HEADpasses.