Swatantra-66 opened a new pull request, #20765:
URL: https://github.com/apache/nuttx/pull/20765

   ## Summary
   According to IEEE Std 1003.1 (POSIX), constants prefixed with `_POSIX_*` and 
`_POSIX2_*` specify invariant minimum limits that any conforming implementation 
must support, not configurable implementation-specific maximums (issue #15464). 
Previously, NuttX defined several `_POSIX_*` constants using Kconfig options 
(e.g., `CONFIG_NAME_MAX`, `CONFIG_PATH_MAX`, `CONFIG_LIBC_OPEN_MAX`), which 
violated POSIX guarantees and caused discrepancies when configurations used 
values lower than the standard minimums.
   
   This PR addresses issue #15464 and audits in-tree consumers:
   1. **`include/limits.h`**:
      - Restored standard POSIX invariant minimums (`_POSIX_NAME_MAX = 14`, 
`_POSIX_PATH_MAX = 256`, `_POSIX_ARG_MAX = 4096`, `_POSIX2_LINE_MAX = 2048`, 
`_POSIX_OPEN_MAX = 20`, `_POSIX_CHILD_MAX = 25`, `_POSIX_NGROUPS_MAX = 8`, 
`_POSIX_STREAM_MAX = 8`, `_POSIX_TZNAME_MAX = 6`, `_POSIX_MQ_PRIO_MAX = 32`, 
`_POSIX_SEM_NSEMS_MAX = 256`, `_POSIX_SEM_VALUE_MAX = 32767`, 
`_POSIX_CLOCKRES_MIN = 20000000`, `_POSIX_AIO_LISTIO_MAX = 2`).
      - Directed implementation limits (`NAME_MAX`, `PATH_MAX`, `ARG_MAX`, 
`LINE_MAX`, `OPEN_MAX`, `NGROUPS_MAX`, `AIO_LISTIO_MAX`) directly to their 
Kconfig values.
      - Raised fallback `CONFIG_PATH_MAX` to `256` so unconfigured builds meet 
`_POSIX_PATH_MAX`.
      - Defined `STREAM_MAX` as `OPEN_MAX` and set `CLOCK_MAX` to `INT64_MAX` 
with `LLONG_MAX` fallback.
      - Guarded `PTHREAD_KEYS_MAX` with `#ifndef`.
   2. **`include/stdio.h`**:
      - Included `<limits.h>`, defined `FILENAME_MAX PATH_MAX` and `FOPEN_MAX 
STREAM_MAX` to strictly align file and stream limits (`FOPEN_MAX == STREAM_MAX 
== OPEN_MAX`).
   3. **`include/sched.h`**:
      - Guarded `PTHREAD_KEYS_MAX` with `#ifndef PTHREAD_KEYS_MAX`.
   4. **`include/unistd.h`**:
      - Defined standard invariant `_POSIX_GETPW_R_SIZE_MAX 1024`.
   5. **`fs/vfs/fs_link.c`**:
      - Updated link count check against `LINK_MAX` (128) instead of 
`_POSIX_LINK_MAX` (8).
   6. **`sched/mqueue/mqueue.h`**:
      - Set `MQ_PRIO_MAX` to `UCHAR_MAX` instead of `_POSIX_MQ_PRIO_MAX` (32) 
to prevent rejecting valid priorities up to 255.
   7. **`libs/libc/unistd/lib_pathconf.c` & `lib_sysconf.c`**:
      - Updated to report actual runtime limits (`NAME_MAX`, `PIPE_BUF`, 
`AIO_MAX`, `CONFIG_LIBC_PASSWD_LINESIZE`).
   
   ## Impact
   - **POSIX Standard Compliance**: Eliminates contradictions where 
applications relying on standard `_POSIX_*` guarantees experienced unexpected 
overflows or failures.
   - **Embedded Adaptability**: System limits (`NAME_MAX`, `PATH_MAX`, 
`OPEN_MAX`, etc.) remain fully user-configurable via Kconfig for 
resource-constrained targets.
   - **ABI / API**: Fully backward-compatible for existing applications and 
configurations.
   
   ## Testing
   - Verified with `./tools/checkpatch.sh -u HEAD` (0 errors, 0 warnings).
   - Verified with `./tools/nxstyle` across all modified files (0 errors, 0 
warnings).
   
   Resolves #15464.
   


-- 
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]

Reply via email to