fix(libkernel): reject clocks libthr does not accept in pthread_condattr_setclock #9500
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/9500"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by GitamarT045T3R on 2026-10-21T23:33:16Z.
What
pthread_condattr_setclockandscePthreadCondattrSetclockstored any clock id. FreeBSD 11 libthr's_pthread_condattr_setclockaccepts onlyCLOCK_REALTIME,CLOCK_VIRTUAL,CLOCK_PROFandCLOCK_MONOTONICand returnsEINVALfor anything else.scePthreadCondattrSetclocknow answersSCE_KERNEL_ERROR_EINVALfor other ids, andpthread_condattr_setclock, which goes through it, answersEINVAL.guest_pthread_condattrchecked that ids 5 and 12 were accepted. That was the old behaviour ("the clock id is still stored as given" in62ac8d655), 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
main0c6a5bd59:guest_pthread_condattraccepts 0, 1, 2 and 4, and refuses -1, 3, 5, 12, 13, 14 and 15 through both calls. It fails withmain'sCond.cppand passes with this change.guest_cond_timedwaitstill passes.python tools/check_conventions.py --base origin/mainpasses.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)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. Heada4339207cmerged ontomaina6dcea927(the merge touches onlyCond.cppandGuestPthreadCondattr.cpp).guest_pthread_condattrpasses with the change: ids 0, 1, 2 and 4 accepted; -1, 3, 5, 12, 13, 14 and 15 refused through both calls.libkernel/Pthread/src/Cond.cpptomainand keeping the test abortsguest_pthread_condattr, sincemainstill stores ids 5 and 12 (returns 0) where the updated test expectsEINVAL. 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.
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
EINVALfor 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).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 ontomain; its merge-base is0c6a5bd59).ctest -R '^guest_pthread_condattr$'passes 3 of 3.libkernel/Pthread/src/Cond.cpprestored to the merge-base (the PR's tests kept): fails (Subprocess aborted).Not tested: macOS, Windows, a title run.
AI-assisted (Claude Code).
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 declareDepends onif needed, then update the second PR’s test consistently. This branch/test base is0c6a5bd593, behind current upstream mainab347d144d; rebase and rerun the focused condition-attribute and timed-wait tests plus conventions. Hosted product jobs are skipped. I did not run local tests.Imported from boykopovar/AnyPS5. Originally posted by GitamarT045T3R on 2026-10-22T08:05:59Z.
Rebased onto
maind6eafa54d(89031ca7b).guest_pthread_condattrandguest_cond_timedwaitpass on Windows, andcheck_conventionspasses.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}:CheckClock(&attr, clock)in the loop, drop 5 and 12 from the list, and check that a refused clock leaves the stored one unchanged.setclockrefuses them, as FreeBSD 11 libthr does.So
Depends onstays none for both. @Piyush-Sagar, does that order work for you?Imported from boykopovar/AnyPS5. Originally posted by fogydes on 2026-10-22T09:09:18Z.
Verified against the cited FreeBSD 11 source (
thr_condattr.cat34bd3475):_pthread_condattr_setclockis exactly attr-check-first, then an allowlist ofCLOCK_REALTIME,CLOCK_VIRTUAL,CLOCK_PROF,CLOCK_MONOTONIC,EINVALotherwise — the diff's{0, 1, 2, 4}constexpr allowlist mirrors it constant by constant, andpthread_condattr_setclock_nid_postfixinherits 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}from62ac8d655'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 withSceEinval/GuestEinval) replaced it without weakening the attr-null and getpshared coverage. Pre-registeredguest_pthread_condattr_teststarget, milliseconds of runtime.Two notes, neither blocking:
{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.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.