Skip to content

unistd: handle required _SC* values in sysconf - #520

Draft
adamgreloch wants to merge 4 commits into
masterfrom
adamgreloch/RTOS-1438
Draft

unistd: handle required _SC* values in sysconf#520
adamgreloch wants to merge 4 commits into
masterfrom
adamgreloch/RTOS-1438

Conversation

@adamgreloch

Copy link
Copy Markdown
Member

Fixes: phoenix-rtos/phoenix-rtos-project#1458

Description

Motivation and Context

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Chore (refactoring, style fixes, git/CI config, submodule management, no code logic changes)

How Has This Been Tested?

  • Already covered by automatic testing.
  • New test added: (add PR link here).
  • Tested by hand on: (list targets here).

Checklist:

  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.
  • All new and existing linter checks and tests passed.
  • My changes generate no new compilation warnings for any of the targets.

Special treatment

  • This PR needs additional PRs to work (list the PRs, preferably in merge-order).
  • I will merge this PR by myself when appropriate.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request expands the sysconf implementation by defining and adding support for numerous POSIX system configuration constants (_SC_*). It also updates _SC_OPEN_MAX to return -1 for POSIX compliance. The review feedback highlights several areas for improvement: ensuring that limits associated with unsupported options also return -1 to comply with POSIX standards, returning defined limits like NGROUPS_MAX and PTHREAD_DESTRUCTOR_ITERATIONS instead of their POSIX minimums, and adding the missing _SC_CLK_TCK case to the sysconf switch statement.

Comment thread unistd/conf.c
Comment thread unistd/conf.c
Comment thread unistd/conf.c Outdated
Comment thread include/unistd.h
@github-actions

Copy link
Copy Markdown

Unit Test Results

13 287 tests  ±0   12 469 ✅ ±0   59m 22s ⏱️ +28s
   756 suites ±0      818 💤 ±0 
     1 files   ±0        0 ❌ ±0 

Results for commit 27ef143. ± Comparison against base commit 6a150a2.

@adamgreloch
adamgreloch force-pushed the adamgreloch/RTOS-1438 branch from 8f85816 to d81d4f7 Compare August 26, 2026 12:59
@adamgreloch
adamgreloch force-pushed the adamgreloch/RTOS-1438 branch from 6a9bd18 to 24ae168 Compare August 26, 2026 13:02
@github-actions

Copy link
Copy Markdown

Unit Test Results (nightly)

     1 files   3 182 suites   6h 8m 27s ⏱️
29 115 tests 25 021 ✅ 4 094 💤 0 ❌
29 301 runs  25 168 ✅ 4 133 💤 0 ❌

Results for commit 24ae168.

@adamgreloch

Copy link
Copy Markdown
Member Author

/gemini review

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request expands POSIX compliance by defining numerous _SC_* configuration constants in include/unistd.h and implementing their handling in sysconf within unistd/conf.c. Additionally, _SC_OPEN_MAX now returns -1 to remain POSIX-compliant. The review feedback suggests improving sysconf by returning the defined PTHREAD_DESTRUCTOR_ITERATIONS and NGROUPS_MAX constants instead of returning -1 or fallback values, respectively.

Comment thread unistd/conf.c
Comment on lines +70 to +75
case _SC_THREAD_DESTRUCTOR_ITERATIONS:
case _SC_THREAD_KEYS_MAX:
case _SC_THREAD_STACK_MIN:
case _SC_THREAD_THREADS_MAX:
/* The POSIX Threads option is not fully supported. */
return -1;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Since PTHREAD_DESTRUCTOR_ITERATIONS is defined in <limits.h> (via <posix/limits.h>), sysconf(_SC_THREAD_DESTRUCTOR_ITERATIONS) should return its value instead of -1 to be POSIX-compliant.

Suggested change
case _SC_THREAD_DESTRUCTOR_ITERATIONS:
case _SC_THREAD_KEYS_MAX:
case _SC_THREAD_STACK_MIN:
case _SC_THREAD_THREADS_MAX:
/* The POSIX Threads option is not fully supported. */
return -1;
case _SC_THREAD_DESTRUCTOR_ITERATIONS:
return PTHREAD_DESTRUCTOR_ITERATIONS;
case _SC_THREAD_KEYS_MAX:
case _SC_THREAD_STACK_MIN:
case _SC_THREAD_THREADS_MAX:
/* The POSIX Threads option is not fully supported. */
return -1;

Comment thread unistd/conf.c
Comment on lines +104 to +105
case _SC_NGROUPS_MAX:
return _POSIX_NGROUPS_MAX;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Since NGROUPS_MAX is defined in <limits.h>, sysconf(_SC_NGROUPS_MAX) should return NGROUPS_MAX instead of the POSIX minimum fallback _POSIX_NGROUPS_MAX. This ensures that any future changes to NGROUPS_MAX are automatically reflected in sysconf.

Suggested change
case _SC_NGROUPS_MAX:
return _POSIX_NGROUPS_MAX;
case _SC_NGROUPS_MAX:
return NGROUPS_MAX;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

sysconf() fails with EINVAL on not supported _SC_* constants

1 participant