Skip to content

fix(libkernel): reject unsupported POSIX condition clocks - #4953

Closed
QRMOE wants to merge 3 commits into
boykopovar:mainfrom
QRMOE:fix-posix-condattr-clock-validation
Closed

QRMOE wants to merge 3 commits into
boykopovar:mainfrom
QRMOE:fix-posix-condattr-clock-validation

Conversation

@QRMOE

@QRMOE QRMOE commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

What

Reject unsupported clock IDs in pthread_condattr_setclock with guest EINVAL (22), preserving the previous clock selection and the caller's errno. On main, selecting an invalid ID such as INT32_MIN succeeds and stores that ID; a later absolute condition wait reaches the unsupported-clock exception instead of the caller receiving the attribute error.

Keep the four accepted FreeBSD 11 IDs: 0 (CLOCK_REALTIME), 1 (CLOCK_VIRTUAL), 2 (CLOCK_PROF) and 4 (CLOCK_MONOTONIC). This follows thr_condattr.c. The validation is in the existing POSIX wrapper; no new exports are introduced. Console clock acceptance has not been measured and is recorded in technical debt.

Tested

Windows, MinGW GCC 15.2, Release, BUILD_TESTING=ON, negative control on main 88107b7de, final branch rebased onto ea2bbefb2:

  • The regression fails on unchanged main: pthread_condattr_setclock accepted unsupported clock -2147483648: result 0.
  • All four accepted IDs pass. Invalid negative IDs, the other public clock IDs through 15 and INT32_MAX return 22, preserve the selected attribute and leave errno unchanged. Null and uninitialized attributes still return 22.
  • A condition created with each accepted clock after the rejected selections still performs an expired absolute wait, returns guest ETIMEDOUT (60), and returns with its mutex owned by the caller.
  • Explicit libs build and eight clock, condition, mutex/attribute and patched-library loading tests passed, including after the final rebase. The final test, with an explicit attribute-preservation assertion, also passed. Conventions and whitespace checks passed.
  • A full Windows build was attempted on the previous base 88107b7de. All remaining components built, but Windows denied recreation of eight unrelated test outputs (guest_sce_net, guest_poll, guest_socket_read_write, guest_tcp, guest_socket_pair, guest_dup, guest_socket_events and guest_fstatfs). Avast's log records automatic sandboxing of the test programs. The local full-build limitation remains; local full-build success is not claimed.
  • No title playback or console measurement was performed.

Review validation

  • xXPBSXx's Windows report: Reports the relevant Windows test passing in a combined merge; the PR was not tested alone and no negative control was performed in that report.
  • nicolasfalesy's Linux report: Linux relevant runtime checks passed in a combined merge, and failed when this PR's source change was reverted while retaining the test.

Ready for maintainer review. Full Linux/Windows CI requires a maintainer's manual dispatch; marking this PR ready does not claim those jobs passed.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Unblocks: none
  • AI-assisted: yes

@xXPBSXx

xXPBSXx commented Oct 13, 2026

Copy link
Copy Markdown
Contributor

Windows test of this PR.

Environment: Windows 10 (19045), MinGW-w64 GCC 15.2.0 (WinLibs r7), Release, BUILD_TESTING=ON, -j2, libusb-cmake from a local checkout. Built from main ea2bbefb2 with this PR and six other open PRs (#4958, #4956, #4954, #4953, #4946, #4942, #4927) merged together; the merges had no conflict.

Result: guest_cond_timedwait (1 of 1) pass.

Not checked: whether the test fails without the change in the library code; the PR was not tested alone, only in the combined merge (the tests of the other PRs in the batch also pass); no title run; Linux not tested.

AI-assisted (Claude Code).

@nicolasfalesy

Copy link
Copy Markdown
Contributor

Linux test (Arch, GCC 16.2.1, glibc, Release), this PR merged onto main 7e181fc together with #4963, #4953, #4946 and #4942 (no conflicts): guest_cond_timedwait passes. With Cond.cpp put back to main's version it fails on Linux too, so the check guards the change on both systems.

@QRMOE
QRMOE marked this pull request as ready for review October 13, 2026 10:55
@xXPBSXx

xXPBSXx commented Oct 13, 2026

Copy link
Copy Markdown
Contributor

Windows counter-test (follow-up to the earlier Windows run): Windows 10 (19045), MinGW-w64 GCC 15.2.0 (WinLibs r7), Release, this PR merged onto main 2a2a3dc65. guest_cond_timedwait passes with the PR; with the PR's source files replaced by main's, same test, it aborts.

Not tested: Linux, a console, a title run.

AI-assisted (Claude Code).

@MarcZX10

Copy link
Copy Markdown
Contributor

Coordination note: I opened #5566 for the FreeBSD-compatible handling of a negative tv_sec in pthread_cond_timedwait. The current #4953 test uses expired{-1, 0} and expects ETIMEDOUT; the FreeBSD implementation validates tv_sec < 0 first and returns EINVAL, so that assertion will conflict if either change lands first. Could you change that expected result to EINVAL (and rebase after whichever PR merges first)? The production changes remain separate: #4953 validates clock IDs, while #5566 validates the deadline.

AI-assisted: yes; reviewed by MarcZX100.

@oneandonlydean

Copy link
Copy Markdown
Collaborator

Closing: no title is known to reach this. With the queue at 700+ open PRs, please hold off on new PRs that don't name a title needing the change until it's down. If a title stops on this on current main, reopen with the title ID and the log line.

@QRMOE

QRMOE commented Oct 15, 2026

Copy link
Copy Markdown
Contributor Author

@MarcZX100 Thanks for catching that. Updated in d07879f: the clock-attribute regression now uses the valid expired deadline {0, 0} and still expects ETIMEDOUT. This keeps the clock-ID test independent of negative-deadline validation, so it doesn’t pin the old negative-tv_sec behaviour or require #5566 to land first.

On Windows, MinGW GCC 15.2 Release, the test built and passed with #4953 merged onto main d92a8dad3, and also passed after applying #5566’s negative-tv_sec validation to that combination. Conventions and whitespace checks passed.

@oneandonlydean Understood on the closure. I’m leaving this PR closed and will only revisit it with a title ID and a current-main failure log; I’ll hold off on new PRs without a title needing the change.

AI-assisted: yes

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants