fix(libkernel): reject clocks libthr does not accept in pthread_condattr_setclock #9500

Merged
GitamarT045T3R merged 1 commit from upstream-pr/9500 into main 2026-10-25 17:42:47 +00:00
GitamarT045T3R commented 2026-10-21 23:33:16 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by GitamarT045T3R on 2026-10-21T23:33:16Z.


What

pthread_condattr_setclock and scePthreadCondattrSetclock stored any clock id. FreeBSD 11 libthr's _pthread_condattr_setclock accepts only CLOCK_REALTIME, CLOCK_VIRTUAL, CLOCK_PROF and CLOCK_MONOTONIC and returns EINVAL for anything else. scePthreadCondattrSetclock now answers SCE_KERNEL_ERROR_EINVAL for other ids, and pthread_condattr_setclock, which goes through it, answers EINVAL.

guest_pthread_condattr checked that ids 5 and 12 were accepted. That was the old behaviour ("the clock id is still stored as given" in 62ac8d655), not a console measurement, so the test now expects them to be refused.

Overlap: #8010 (pthread_condattr_getclock) also expects ids 5 and 12 to be stored. Whichever lands second updates that clock list.

Tested

Windows 10 Pro 22H2 (19045), MinGW-w64 GCC 15.2.0 (WinLibs r7), Ninja, Release, on main 0c6a5bd59:

  • guest_pthread_condattr accepts 0, 1, 2 and 4, and refuses -1, 3, 5, 12, 13, 14 and 15 through both calls. It fails with main's Cond.cpp and passes with this change.
  • guest_cond_timedwait still passes.
  • python tools/check_conventions.py --base origin/main passes.
  • Not built or run on Linux or macOS.

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 (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4959773468 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9500). Originally posted by [GitamarT045T3R](https://github.com/GitamarT045T3R) on 2026-10-21T23:33:16Z. --- ### What `pthread_condattr_setclock` and `scePthreadCondattrSetclock` stored any clock id. FreeBSD 11 libthr's [`_pthread_condattr_setclock`](https://github.com/freebsd/freebsd-src/blob/34bd34750187bae02a0086402c78c031c59dd8b3/lib/libthr/thread/thr_condattr.c#L92-L104) accepts only `CLOCK_REALTIME`, `CLOCK_VIRTUAL`, `CLOCK_PROF` and `CLOCK_MONOTONIC` and returns `EINVAL` for anything else. `scePthreadCondattrSetclock` now answers `SCE_KERNEL_ERROR_EINVAL` for other ids, and `pthread_condattr_setclock`, which goes through it, answers `EINVAL`. `guest_pthread_condattr` checked that ids 5 and 12 were accepted. That was the old behaviour ("the clock id is still stored as given" in 62ac8d655), not a console measurement, so the test now expects them to be refused. Overlap: #8010 (`pthread_condattr_getclock`) also expects ids 5 and 12 to be stored. Whichever lands second updates that clock list. ### Tested Windows 10 Pro 22H2 (19045), MinGW-w64 GCC 15.2.0 (WinLibs r7), Ninja, Release, on `main` `0c6a5bd59`: - `guest_pthread_condattr` accepts 0, 1, 2 and 4, and refuses -1, 3, 5, 12, 13, 14 and 15 through both calls. It fails with `main`'s `Cond.cpp` and passes with this change. - `guest_cond_timedwait` still passes. - `python tools/check_conventions.py --base origin/main` passes. - Not built or run on Linux or macOS. ### 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](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes
jotitadev commented 2026-10-22 00:03:47 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by jotitadev on 2026-10-22T00:03:47Z.

Review: COMMENTED


Linux run of the current change, since the description only lists Windows ("Not built or run on Linux or macOS").

Machine: Linux x86_64, i7-8700 (6 cores / 12 threads), Ubuntu 26.04, GCC 15.2, Release, BUILD_TESTING=ON. Head a4339207c merged onto main a6dcea927 (the merge touches only Cond.cpp and GuestPthreadCondattr.cpp).

  • Build ok. guest_pthread_condattr passes with the change: ids 0, 1, 2 and 4 accepted; -1, 3, 5, 12, 13, 14 and 15 refused through both calls.
  • Restoring libkernel/Pthread/src/Cond.cpp to main and keeping the test aborts guest_pthread_condattr, since main still stores ids 5 and 12 (returns 0) where the updated test expects EINVAL. So the test covers the change on this host as well.

Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5607701163 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9500#pullrequestreview-5607701163). Originally posted by [jotitadev](https://github.com/jotitadev) on 2026-10-22T00:03:47Z. **Review:** COMMENTED --- Linux run of the current change, since the description only lists Windows ("Not built or run on Linux or macOS"). Machine: Linux x86_64, i7-8700 (6 cores / 12 threads), Ubuntu 26.04, GCC 15.2, Release, `BUILD_TESTING=ON`. Head `a4339207c` merged onto `main` `a6dcea927` (the merge touches only `Cond.cpp` and `GuestPthreadCondattr.cpp`). - Build ok. `guest_pthread_condattr` passes with the change: ids 0, 1, 2 and 4 accepted; -1, 3, 5, 12, 13, 14 and 15 refused through both calls. - Restoring `libkernel/Pthread/src/Cond.cpp` to `main` and keeping the test aborts `guest_pthread_condattr`, since `main` still stores ids 5 and 12 (returns 0) where the updated test expects `EINVAL`. So the test covers the change on this host as well. Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.
MarcZX10 commented 2026-10-22 01:32:27 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-22T01:32:27Z.

Review: CHANGES_REQUESTED


The FreeBSD 11 libthr contract cited here supports accepting only realtime, virtual, profiling and monotonic clocks and returning EINVAL for other values. The updated test checks both the SCE and POSIX setters, including IDs 5/12 and invalid values. Hosted eligibility, conventions, intake, labels and report checks pass; product and relinker jobs were skipped. The author reports focused Windows results, and another reviewer reports the focused Linux run. I did not run local tests.

There is a concrete test conflict with open #8010. Its getter regression sets clock IDs 5 and 12 and expects them to be stored, while this change intentionally makes those setter calls fail. The PR description acknowledges whichever PR lands second must update its test, but the authors have not recorded an agreed order and this checklist still says Depends on: none. Please coordinate with #8010’s author, agree which change lands first, and update the dependent checklist/rebase so the getter test exercises only accepted values (or is otherwise revised consistently).

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5608245711 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9500#pullrequestreview-5608245711). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-22T01:32:27Z. **Review:** CHANGES_REQUESTED --- The FreeBSD 11 libthr contract cited here supports accepting only realtime, virtual, profiling and monotonic clocks and returning `EINVAL` for other values. The updated test checks both the SCE and POSIX setters, including IDs 5/12 and invalid values. Hosted eligibility, conventions, intake, labels and report checks pass; product and relinker jobs were skipped. The author reports focused Windows results, and another reviewer reports the focused Linux run. I did not run local tests. There is a concrete test conflict with open #8010. Its getter regression sets clock IDs 5 and 12 and expects them to be stored, while this change intentionally makes those setter calls fail. The PR description acknowledges whichever PR lands second must update its test, but the authors have not recorded an agreed order and this checklist still says `Depends on: none`. Please coordinate with #8010’s author, agree which change lands first, and update the dependent checklist/rebase so the getter test exercises only accepted values (or is otherwise revised consistently).
xXPBSXx commented 2026-10-22 04:12:00 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-22T04:12:00Z.


Linux data point for a4339207c2: WSL2 Ubuntu 24.04 (virtualised kernel, not bare-metal), GCC 13.3.0, Release, BUILD_TESTING=ON, PR head alone (not merged onto main; its merge-base is 0c6a5bd59).

  • With the PR: ctest -R '^guest_pthread_condattr$' passes 3 of 3.
  • With libkernel/Pthread/src/Cond.cpp restored to the merge-base (the PR's tests kept): fails (Subprocess aborted).
    Not tested: macOS, Windows, a title run.
    AI-assisted (Claude Code).
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6332497967 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9500#issuecomment-6332497967). Originally posted by [xXPBSXx](https://github.com/xXPBSXx) on 2026-10-22T04:12:00Z. --- Linux data point for `a4339207c2`: WSL2 Ubuntu 24.04 (virtualised kernel, not bare-metal), GCC 13.3.0, Release, `BUILD_TESTING=ON`, PR head alone (not merged onto `main`; its merge-base is `0c6a5bd59`). - With the PR: `ctest -R '^guest_pthread_condattr$'` passes 3 of 3. - With `libkernel/Pthread/src/Cond.cpp` restored to the merge-base (the PR's tests kept): fails (`Subprocess aborted`). Not tested: macOS, Windows, a title run. AI-assisted (Claude Code).
MarcZX10 commented 2026-10-22 04:25:39 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-22T04:25:39Z.

Review: DISMISSED


The clock allowlist matches the cited FreeBSD 11 libthr behavior, and the focused Windows/Linux test reports support the new rejection cases. The acknowledged overlap with #8010 is still unresolved: its getter test sets IDs 5 and 12, which this PR now rejects, but there is no author-agreed order in the PR and the checklist remains Depends on: none. Please coordinate with #8010’s author, record which PR lands first and declare Depends on if needed, then update the second PR’s test consistently. This branch/test base is 0c6a5bd593, behind current upstream main ab347d144d; rebase and rerun the focused condition-attribute and timed-wait tests plus conventions. Hosted product jobs are skipped. I did not run local tests.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5609250904 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9500#pullrequestreview-5609250904). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-22T04:25:39Z. **Review:** DISMISSED --- The clock allowlist matches the cited FreeBSD 11 libthr behavior, and the focused Windows/Linux test reports support the new rejection cases. The acknowledged overlap with #8010 is still unresolved: its getter test sets IDs 5 and 12, which this PR now rejects, but there is no author-agreed order in the PR and the checklist remains `Depends on: none`. Please coordinate with #8010’s author, record which PR lands first and declare `Depends on` if needed, then update the second PR’s test consistently. This branch/test base is 0c6a5bd593, behind current upstream main ab347d144d88fae054d9770cf0db8d3565735c02; rebase and rerun the focused condition-attribute and timed-wait tests plus conventions. Hosted product jobs are skipped. I did not run local tests.
GitamarT045T3R commented 2026-10-22 08:05:59 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by GitamarT045T3R on 2026-10-22T08:05:59Z.


Rebased onto main d6eafa54d (89031ca7b). guest_pthread_condattr and guest_cond_timedwait pass on Windows, and check_conventions passes.

Landing order with #8010 (@Piyush-Sagar): neither depends on the other, and either order works. The only shared line is the clock loop in GuestPthreadCondattr.cpp, which #8010 runs over {0, 1, 2, Monotonic, 5, 12} and this PR narrows to {0, 1, 2, Monotonic}:

  • If #8010 lands first, I rebase this PR onto it. I keep its CheckClock(&attr, clock) in the loop, drop 5 and 12 from the list, and check that a refused clock leaves the stored one unchanged.
  • If this PR lands first, #8010 drops 5 and 12 from its loop, since setclock refuses them, as FreeBSD 11 libthr does.

So Depends on stays none for both. @Piyush-Sagar, does that order work for you?

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6335902399 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9500#issuecomment-6335902399). Originally posted by [GitamarT045T3R](https://github.com/GitamarT045T3R) on 2026-10-22T08:05:59Z. --- Rebased onto `main` `d6eafa54d` (89031ca7b). `guest_pthread_condattr` and `guest_cond_timedwait` pass on Windows, and `check_conventions` passes. Landing order with #8010 (@Piyush-Sagar): neither depends on the other, and either order works. The only shared line is the clock loop in `GuestPthreadCondattr.cpp`, which #8010 runs over `{0, 1, 2, Monotonic, 5, 12}` and this PR narrows to `{0, 1, 2, Monotonic}`: - If #8010 lands first, I rebase this PR onto it. I keep its `CheckClock(&attr, clock)` in the loop, drop 5 and 12 from the list, and check that a refused clock leaves the stored one unchanged. - If this PR lands first, #8010 drops 5 and 12 from its loop, since `setclock` refuses them, as FreeBSD 11 libthr does. So `Depends on` stays none for both. @Piyush-Sagar, does that order work for you?
fogydes commented 2026-10-22 09:09:18 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by fogydes on 2026-10-22T09:09:18Z.


Verified against the cited FreeBSD 11 source (thr_condattr.c at 34bd3475): _pthread_condattr_setclock is exactly attr-check-first, then an allowlist of CLOCK_REALTIME, CLOCK_VIRTUAL, CLOCK_PROF, CLOCK_MONOTONIC, EINVAL otherwise — the diff's {0, 1, 2, 4} constexpr allowlist mirrors it constant by constant, and pthread_condattr_setclock_nid_postfix inherits the same reject through the existing error mapping without its own list. The test flip is the heart of it: the old accept-loop carried {0, 1, 2, 4, 5, 12} from 62ac8d655's implementation behavior, which the body honestly labels as never a console measurement, and the new reject loop ({-1, 3, 5, 12, 13, 14, 15} on both the sce and POSIX entry points with SceEinval/GuestEinval) replaced it without weakening the attr-null and getpshared coverage. Pre-registered guest_pthread_condattr_tests target, milliseconds of runtime.

Two notes, neither blocking:

  1. The reject list is representative rather than exhaustive — {6, 7, 10, 11} (second-of, uptime, fast/precise variants) go untested, though the implementation's allowlist makes accept/reject a pure function of the four-value list, so coverage of any two reject ids versus accept ids is the actual check.
  2. The pinned standard is FreeBSD 11 libthr, which is the right reference for this codebase's stated model; if a console measurement ever shows the console's libkernel accepting more ids than 11's list (no measurement exists today, for this or the previous behavior), that's a divergence for debt rather than a reason to extend the list now. The body already documents the old list's provenance, which is the honest record.

The #8010 overlap is acknowledged in the body with a concrete hand-off plan — whoever merges second must update the other test's id list, and the two PRs now disagree, so the ordering matters in practice.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6337067232 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9500#issuecomment-6337067232). Originally posted by [fogydes](https://github.com/fogydes) on 2026-10-22T09:09:18Z. --- Verified against the cited FreeBSD 11 source (`thr_condattr.c` at `34bd3475`): `_pthread_condattr_setclock` is exactly attr-check-first, then an allowlist of `CLOCK_REALTIME`, `CLOCK_VIRTUAL`, `CLOCK_PROF`, `CLOCK_MONOTONIC`, `EINVAL` otherwise — the diff's `{0, 1, 2, 4}` constexpr allowlist mirrors it constant by constant, and `pthread_condattr_setclock_nid_postfix` inherits the same reject through the existing error mapping without its own list. The test flip is the heart of it: the old accept-loop carried `{0, 1, 2, 4, 5, 12}` from `62ac8d655`'s implementation behavior, which the body honestly labels as never a console measurement, and the new reject loop (`{-1, 3, 5, 12, 13, 14, 15}` on both the sce and POSIX entry points with `SceEinval`/`GuestEinval`) replaced it without weakening the attr-null and getpshared coverage. Pre-registered `guest_pthread_condattr_tests` target, milliseconds of runtime. Two notes, neither blocking: 1. The reject list is representative rather than exhaustive — `{6, 7, 10, 11}` (second-of, uptime, fast/precise variants) go untested, though the implementation's allowlist makes accept/reject a pure function of the four-value list, so coverage of any two reject ids versus accept ids is the actual check. 2. The pinned standard is FreeBSD 11 libthr, which is the right reference for this codebase's stated model; if a console measurement ever shows the console's libkernel accepting more ids than 11's list (no measurement exists today, for this or the previous behavior), that's a divergence for debt rather than a reason to extend the list now. The body already documents the old list's provenance, which is the honest record. The #8010 overlap is acknowledged in the body with a concrete hand-off plan — whoever merges second must update the other test's id list, and the two PRs now disagree, so the ordering matters in practice.
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!9500
No description provided.