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

Closed
QRMOE wants to merge 3 commits from upstream-pr/4953 into main
QRMOE commented 2026-10-13 06:09:07 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by QRMOE on 2026-10-13T06:09:07Z.


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
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4839136322 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4953). Originally posted by [QRMOE](https://github.com/QRMOE) on 2026-10-13T06:09:07Z. --- ### 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`](https://github.com/freebsd/freebsd-src/blob/releng/11.4/lib/libthr/thread/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](https://github.com/boykopovar/AnyPS5/pull/4953#issuecomment-6140228527): 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](https://github.com/boykopovar/AnyPS5/pull/4953#issuecomment-6140476052): 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 - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except technical debt - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's technical debt file - [x] No notes, investigation `.md` files or images added to the repository - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] Unblocks: none - [x] AI-assisted: yes
xXPBSXx commented 2026-10-13 07:05:48 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-13T07:05:48Z.


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).

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6140228527 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4953#issuecomment-6140228527). Originally posted by [xXPBSXx](https://github.com/xXPBSXx) on 2026-10-13T07:05:48Z. --- 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 commented 2026-10-13 07:22:29 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by nicolasfalesy on 2026-10-13T07:22:29Z.


Linux test (Arch, GCC 16.2.1, glibc, Release), this PR merged onto main 7e181fcc3 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.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6140476052 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4953#issuecomment-6140476052). Originally posted by [nicolasfalesy](https://github.com/nicolasfalesy) on 2026-10-13T07:22:29Z. --- Linux test (Arch, GCC 16.2.1, glibc, Release), this PR merged onto `main` 7e181fcc3 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.
xXPBSXx commented 2026-10-13 12:00:24 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-13T12:00:24Z.


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).

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6145054491 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4953#issuecomment-6145054491). Originally posted by [xXPBSXx](https://github.com/xXPBSXx) on 2026-10-13T12:00:24Z. --- 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 commented 2026-10-14 00:03:26 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-14T00:03:26Z.


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.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6157803803 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4953#issuecomment-6157803803). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-14T00:03:26Z. --- 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 commented 2026-10-14 02:35:24 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-14T02:35:24Z.


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.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6159616417 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4953#issuecomment-6159616417). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-14T02:35:24Z. --- 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 commented 2026-10-15 07:47:28 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by QRMOE on 2026-10-15T07:47:28Z.


@MarcZX100 Thanks for catching that. Updated in d07879ff9: 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

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6187177959 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4953#issuecomment-6187177959). Originally posted by [QRMOE](https://github.com/QRMOE) on 2026-10-15T07:47:28Z. --- @MarcZX100 Thanks for catching that. Updated in d07879ff9: 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

Pull request closed

Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!4953
No description provided.