casaroli opened a new pull request, #21674: URL: https://github.com/apache/nuttx/pull/21674
## 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 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" or "not supported" and check `errno` to see an error. Commit 1 makes `sysconf()` answer every name of `<unistd.h>`: - A limit gives the value of its `<limits.h>` constant (or the POSIX minimum, for the `bc`/`expr`/`regex` limits that `<limits.h>` does not define). - An option gives the value of its `<unistd.h>` macro. For an option that `<unistd.h>` leaves undefined, `sysconf()` gives `_POSIX_VERSION` if 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.rst` already lists these options as supported with the same options. - The names of the C compilation environments (`_SC_V6_*`, `_SC_XBS5_*`) give 1 for the environment of the build (from the sizes of `int`, `long`, pointers and `off_t`), else -1. - `_SC_PHYS_PAGES` and `_SC_AVPHYS_PAGES` come from `sysinfo()`. `_SC_GETGR_R_SIZE_MAX` is the buffer that `getgrgid_r()` needs with `CONFIG_LIBC_GROUP_FILE`. - `_SC_THREAD_THREADS_MAX` is -1 (no limit). The value 255 came from the `uint8_t` member count of the task group, which ec08031e4bf removed; the PID hash table grows when it is full (`sched/task/task_setup.c`). - The other names (tracing, batch, STREAMS, job control, `posix_spawn()` with process groups, ...) give -1 with `errno` unchanged. A name that is not valid gives -1 with `EINVAL`. - `_SC_THREAD_KEYS_MAX` is 0 in a configuration without pthreads, which has no `CONFIG_TLS_NELEM`. Commit 2 adds the `sysconf()` names of POSIX.1-2024 that `<unistd.h>` did not define, with their answers: `_SC_NSIG` (`NSIG`), `_SC_THREAD_ROBUST_PRIO_INHERIT` and `_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_CONTROL` and `_SC_XOPEN_UUCP` (-1: no `posix_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 `sysconf()` gives other results in every build mode. The values below are from `qemu-armv8a:knsh` (master 03aea786390, then this PR): - Same as before (19 names): `_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`. - A name that is not valid: -1 with `EINVAL` (was `ENOSYS`). - Limits that now give a value (was -1 with `ENOSYS`): `_SC_AIO_PRIO_DELTA_MAX` 0, `_SC_BC_BASE_MAX` 99, `_SC_BC_DIM_MAX` 2048, `_SC_BC_SCALE_MAX` 99, `_SC_BC_STRING_MAX` 1000, `_SC_CHILD_MAX` 25, `_SC_COLL_WEIGHTS_MAX` 2, `_SC_DELAYTIMER_MAX` 32, `_SC_EXPR_NEST_MAX` 32, `_SC_HOST_NAME_MAX` 32, `_SC_LINE_MAX` 80, `_SC_LOGIN_NAME_MAX` 33, `_SC_MQ_OPEN_MAX` 8, `_SC_MQ_PRIO_MAX` 255, `_SC_RE_DUP_MAX` 255, `_SC_RTSIG_MAX` 32, `_SC_SEM_NSEMS_MAX` and `_SC_SEM_VALUE_MAX` `INT_MAX`, `_SC_SIGQUEUE_MAX` 32, `_SC_STREAM_MAX` 256, `_SC_SYMLOOP_MAX` 8, `_SC_THREAD_DESTRUCTOR_ITERATIONS` 4, `_SC_THREAD_KEYS_MAX` 0 (`CONFIG_TLS_NELEM`), `_SC_TIMER_MAX` 32, `_SC_TTY_NAME_MAX` 32, `_SC_TZNAME_MAX` 6, `_SC_PHYS_PAGES` 2354, `_SC_AVPHYS_PAGES` 2274. - Options that now give a value (was -1 with `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_IPV6` and one compilation environment name. - 61 names now give -1 with `errno` unchanged (was -1 with `ENOSYS`): 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_MAX` without `CONFIG_LIBC_GROUP_FILE`, and the compilation environments that the build does not use. - `_SC_THREAD_THREADS_MAX`: -1 with `errno` unchanged (was 255). - New names: `_SC_NSIG` 64; `_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): `sysconf` 164 -> 676 bytes, text 127652 -> 128164. `nucleo-l432kc:nsh`, `rv-virt:nsh` and `qemu-armv8a:nsh` do not link it (text unchanged). ## Testing Test: apache/nuttx-apps#NNNN (`testing/libc/sysconf`): every name gives a value or -1 with `errno` unchanged; -1, `INT_MIN` and `INT_MAX` give -1 with `EINVAL`; the limits and options give the value of their constant; `_SC_OPEN_MAX` is the `RLIMIT_NOFILE` soft limit; the page, processor and compilation environment names give sane values. QEMU with HVF, 1 CPU: | Configuration | master 03aea786390 | this PR | |---|---|---| | `qemu-armv8a:knsh` (kernel) | 126 names, 144 errors | 139 names, 0 errors | | `qemu-armv8a:nsh` (flat) | 126 names, 143 errors | 139 names, 0 errors | | `qemu-armv8a:knsh` and `:nsh` with `PRIORITY_INHERITANCE`, `PRIORITY_PROTECT`, `FS_LARGEFILE`, `TLS_NELEM=8`, `LIBC_REGEX` | | 139 names, 0 errors; `_SC_THREAD_PRIO_INHERIT`, `_SC_THREAD_PRIO_PROTECT`, both `_SC_THREAD_ROBUST_PRIO_*` and `_SC_REGEXP` 201712, `_SC_THREAD_KEYS_MAX` 8, `_SC_V6_LP64_OFF64` 1 (knsh) | | `mps2-an500:knsh` (protected, armv7-m, QEMU TCG) | | 139 names, 0 errors | | ostest, `qemu-armv8a:knsh` and `qemu-armv8a:nsh` | status 0 | status 0 | Builds, each OK: `rv-virt:nsh` (flat, rv32) and `lm3s6965-ek:qemu-protected` (protected, armv7-m) with `EXTRAFLAGS=-Werror`; `ea3131:pgnsh` (arm926, `CONFIG_DISABLE_PTHREAD`: no `CONFIG_TLS_NELEM`); `qemu-armv8a:nsh` with CMake (Ninja) and the test, no compiler warning in `lib_sysconf.c` or the test. Compared with glibc 2.43 (Fedora, x86_64): an invalid name gives -1 with `EINVAL` on both; `_SC_PAGESIZE` 4096, `_SC_IOV_MAX` 1024, `_SC_RTSIG_MAX` 32, `_SC_THREAD_DESTRUCTOR_ITERATIONS` 4, `_SC_SEM_VALUE_MAX` `INT_MAX` and `_SC_THREAD_THREADS_MAX` -1 are the same; `_SC_OPEN_MAX` is the `RLIMIT_NOFILE` soft limit on both. The values that come from the configuration differ: `_SC_CLK_TCK` (NuttX `CONFIG_USEC_PER_TICK`, 1000 here; Linux 100), `_SC_HOST_NAME_MAX` (`CONFIG_HOST_NAME_MAX` 32; Linux 64), `_SC_NPROCESSORS_*` (`CONFIG_SMP_NCPUS`). `tools/checkpatch.sh -c -u -m -g origin/master..HEAD` passes. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
