Skip to content

include/limits.h: decouple _POSIX_* invariant constants from Kconfig - #20765

Merged
acassis merged 1 commit into
apache:masterfrom
Swatantra-66:fix/limits-posix-constants
Oct 18, 2026
Merged

acassis merged 1 commit into
apache:masterfrom
Swatantra-66:fix/limits-posix-constants

Conversation

@Swatantra-66

Copy link
Copy Markdown
Contributor

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.

According to IEEE Std 1003.1 (POSIX), constants prefixed with _POSIX_*
and _POSIX2_* are invariant minimum values guaranteed by the standard,
not configurable implementation limits.

1. include/limits.h:
   - Restore _POSIX_* and _POSIX2_* constants to standard-defined
     invariant minimums (e.g. _POSIX_NAME_MAX = 14, _POSIX_PATH_MAX = 256,
     _POSIX_ARG_MAX = 4096, _POSIX2_LINE_MAX = 2048, _POSIX_OPEN_MAX = 20).
   - Direct implementation limits (NAME_MAX, PATH_MAX, ARG_MAX, LINE_MAX,
     OPEN_MAX, NGROUPS_MAX, AIO_LISTIO_MAX) to their Kconfig values.
   - Align STREAM_MAX with OPEN_MAX and provide fallback CONFIG_PATH_MAX
     of at least 256 so implementation limits satisfy POSIX invariants.
   - Define CLOCK_MAX with 64-bit fallback (int64_t clock_t).
2. include/stdio.h:
   - Include <limits.h> and define FILENAME_MAX as PATH_MAX and
     FOPEN_MAX as STREAM_MAX to align published stream and file limits.
3. include/sched.h:
   - Guard PTHREAD_KEYS_MAX with #ifndef to avoid redefinition.
4. include/unistd.h:
   - Set _POSIX_GETPW_R_SIZE_MAX to invariant 1024.
5. fs/vfs/fs_link.c:
   - Check link count against LINK_MAX instead of _POSIX_LINK_MAX.
6. sched/mqueue/mqueue.h:
   - Set MQ_PRIO_MAX to UCHAR_MAX instead of _POSIX_MQ_PRIO_MAX.
7. libs/libc/unistd/lib_pathconf.c & lib_sysconf.c:
   - Query runtime implementation limits (NAME_MAX, PIPE_BUF, AIO_MAX,
     CONFIG_LIBC_PASSWD_LINESIZE).

Resolves apache#15464.

Signed-off-by: Swatantra Yadav <[email protected]>
@github-actions github-actions Bot added Area: File System File System issues Size: M The size of the change in this PR is medium labels Oct 17, 2026
@github-actions

Copy link
Copy Markdown

MemBrowse Memory Report

No memory changes detected for:

@acassis
acassis merged commit 35c6d67 into apache:master Oct 18, 2026
53 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area: File System File System issues Size: M The size of the change in this PR is medium

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] many of _POSIX_xxx constants seem inappropriate

3 participants