feat(libkernel): add pthread_rwlockattr_settype_np and scePthreadMutexattrSetkind #9632
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/9632"
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 EagleBearerYS on 2026-10-22T05:19:01Z.
What
This moves three libkernel_sys stubs into libkernel, the way
mainplaces the libkernel_sys functions that libkernel already implements.pthread_rwlockattr_settype_npstores types 1 and 2 through its SCE twinscePthreadRwlockattrSettype, and converts the result as the other POSIX rwlock calls do. Any other type, 0 included, and a null attribute or object returnEINVALand store nothing, as BunnyFl measured on firmware 13.42's libkernel. The stored type isn't applied, sincescePthreadRwlockInitignores its attribute, so the debt entry is under Silent stubs.scePthreadMutexattrSetkindaccepts kindsMutexType::ErrorCheck(1) toMutexType::Adaptive(4) and sets them throughscePthreadMutexattrSettype, as FreeBSD 11 libthr'spthread_mutexattr_setkind_npstores the kind as the type. The bounds are the tree's existingMutexTypeconstants. A null or uninitialized attribute returns 0x8001FFFF,sceKernelError(-1), as BunnyFl measured. Other kinds throw throughNotImplemented_nid_no_patch: the firmware stores any kind as 16 bits of the type field unchecked, but what a mutex does with such a kind isn't measured.scePthreadMutexattrGetkindtakes the attribute itself and returnssceKernelErrorof its kind, 0x80020000 plus the kind, or 0x8001FFFF for a null one, as measured. The firmware returns 0 for kind 0, which no setter here stores, so that case is untested.Still throwing:
pthread_mutex_setname_np,pthread_cond_setname_np,pthread_rwlock_setname_np,pthread_barrier_setname_npandsem_setname: a silent stub needs a title that calls them.scePthreadMutexIsowned: two conventions are on record, FreeBSD's 1/0 boolean and shadPS4's wrapped0x80020001.scePthreadMain: waits on #9160's main-thread helper.pthread_timedjoin_npandscePthreadTimedjoin: wait on #8890.Related:
pthread_mutexattr_setkind_np/getkind_npand merges cleanly with this PR.MutexTypevalues, and both throw for other kinds.errnoEINVAL. The SCE form here returns 0x8001FFFF, as measured.scePthreadMutexattrSetkindcan keep its attribute check and forward topthread_mutexattr_setkind_npthroughPosixThread::ToSce.Export.Discovery.cpp.GuestKernelSysPthread.cpp, which is why this PR's test file has a separate name.Tested
guest_kernel_sys_pthread_np_rwlockattrandguest_kernel_sys_pthread_np_kindfail ×2 on both runners withmain's stubs and pass ×5 on both.precise_wait, a timing test that fails in that run withmain's code too.check_test_registration.pyand MinGW-fsyntax-onlyof the changed files are clean.fa3cbbe32b, after harisibrar1's review (run):guest_kernel_sys_pthread_np_rwlockattrgains types 3 and -1, which must throw. With the previous head'sRwlock.cppit fails on both runners, since both types returned 0; with the change both tests pass 10 runs in a row on both. The libc and libkernel suites pass on Windows (142, 207) and libkernel on Linux (197); libc's timing testprecise_waitfailed on Linux with and without the change.mainatd6eafa54d0(b23cbb5bb8, run): one conflict, inlibkernel_sys/Export.Discovery.cpp, wheremainhad removed thepthread_set_defaultstacksize_npdiscovery stub (now inlibkernel_sys/Export.cpp) next to the two stubs this PR removes. The merge keeps all three removals, and this PR's diff againstmainis unchanged.guest_kernel_sys_pthread_np_rwlockattr,guest_kernel_sys_pthread_np_kindandmain'sguest_kernel_sys_thread_defaultspass 10 runs in a row on both runners. The libc and libkernel suites pass on Windows (143, 207) and libkernel on Linux (197); libc'sprecise_waitfailed once on Linux.e8172f8078, after fogydes's review (run):scePthreadMutexattrSetkind's null or uninitialized attribute and its kinds outside 1 to 4 go throughNotImplemented_nid_no_patchinstead ofstd::invalid_argument. With the previous head'sMutex.cpp,guest_kernel_sys_pthread_np_kindfails on both runners with the old throw ("Mutex kind 0 is not a mutex type"). With the change both tests pass 10 runs in a row on both. The libc and libkernel suites pass on both (116 and 197 on Linux, 143 and 207 on Windows).b801b76e2f,main3ca07d086dmerged in (clean; the PR's own diff is unchanged), on GitHub's runners (run):guest_kernel_sys_pthread_np_kind,guest_kernel_sys_pthread_np_rwlockattrandguest_kernel_sys_thread_defaultspass 10 of 10 on Linux and Windows, none skipped. On its one run withmain's implementation,guest_kernel_sys_pthread_np_kindandguest_kernel_sys_pthread_np_rwlockattrfail on both runners andguest_kernel_sys_thread_defaultspasses. The libc and libkernel suites pass on both.ca39134f27, BunnyFl's measured cases (comment): the rwlock types, the null attribute inscePthreadMutexattrSetkindand the newscePthreadMutexattrGetkind. Red, the commit's tests on 96c21c0d09's code (run): on both runners_rwlockattrand_kindfail on exactly the three changed cases (type 0 is stored; the null attribute throws;Getkindis a stub), andguest_kernel_sys_thread_defaultspasses. Green (run): the three tests pass 10 runs in a row on Linux and on Windows, none skipped, and the libc and libkernel suites pass on both, run withAPS5_SKIP_TIMING_TESTS=1, which relaxesprecise_wait's median bounds on GitHub's hosted runners.7b6c3aae83,maina145c6a468merged in, on GitHub's runners (run). One conflict, indocs/dev/debt/libkernel.md, wheremain's newsceCoredumpSetUserDataTypeentry (#8906) and this PR'spthread_rwlockattr_settype_npentry are added at the same place. The merge keeps both,main's first. The PR's changed lines are the same as before the merge (git diff -U0); only their context in the debt file moved.guest_kernel_sys_pthread_np_kind,guest_kernel_sys_pthread_np_rwlockattrandguest_kernel_sys_thread_defaultspass 10 of 10 on Linux and Windows, none skipped, and the two new tests fail withmain's implementation on both. The libc and libkernel suites pass on both. The libc and libkernel suites ran withAPS5_SKIP_TIMING_TESTS=1, which relaxesprecise_wait's median bounds on GitHub's hosted runners.96c21c0d09,main9a030c2d50merged in, on GitHub's runners (run). One conflict, incore/libs/CMakeLists.txt, wheremain's newguest_kernel_sys_module_internalregistration and this PR'sguest_kernel_sys_pthread_npregistrations are added at the same place. The merge keeps both, this PR's first. The PR's other files are unchanged by patch-id, and its changed lines are the same as before the merge; only their context inCMakeLists.txtmoved.guest_kernel_sys_pthread_np_kind,guest_kernel_sys_pthread_np_rwlockattr,guest_kernel_sys_thread_defaultsandmain'sguest_kernel_sys_module_internalpass 10 of 10 on Linux and Windows, none skipped, and the two new tests fail withmain's implementation on both. The libc and libkernel suites pass on both (117 and 198 on Linux, 144 and 208 on Windows). They ran withAPS5_SKIP_TIMING_TESTS=1, which relaxesprecise_wait's median bounds on GitHub's hosted runners.3a47ea6ea4,main50bc72bbbcmerged in, on GitHub's runners (run). One conflict, inlibkernel_sys/Export.Discovery.cpp, wheremainhad removed thescePthreadResumediscovery stub, which it now implements, next to the stubs this PR removes. The merge keeps both removals.main's rule that each export is declared once, in its library'sinclude/Api.hpp. libkernel'sApi.hppdeclares the three exports with their real signatures, and libkernel_sys's drops its(void)declarations of them.Mutex.cpptakessceKernelErrorfrom libkernel'sApi.hppinstead of declaring it, and the test includes the headers instead of its ownextern "C"block. The code's behaviour is unchanged.public_headersand the^guest_kernel_systests, 10 runs in a row. Linux: 19 run, 19 pass, 0 skip, 0 fail. Windows: 17 run, 15 pass, 0 skip, 2 fail. This PR's two tests pass on both.main'sguest_kernel_sys_threads_mainandguest_kernel_sys_threads_main_patched, not this PR's tests. In this verify's Windows job they fail withLoadLibraryExW D:/a/AnyPS5/AnyPS5/build/core/libs/libs/unpatched\libkernel_sys.prx failed: 127.main88f99678bf, with only a line added that prints that error, fails them the same way there (run). A local Windows build of this merge passes both, built clean and incrementally.APS5_SKIP_TIMING_TESTS=1, which relaxesprecise_wait's median bounds on GitHub's hosted runners.check_conventions.pypasses, with no comment lines added.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)docs/dev/debt/libkernel.md): whichever merges second keeps bothImported from boykopovar/AnyPS5. Originally posted by harisibrar1 on 2026-10-22T05:47:52Z.
Review: COMMENTED
Checked against main
4a17c7175, shadPS4 rwlock.cpp@e0a4667 (L258-289), FreeBSD releng/11.0 thr_mutexattr.c/pthread.h, and ps5-payload-dev/sdk sce_stubs:scePthreadMutexattrSetkindlooks right to me. Kinds 1..4 map to FreeBSD's ERRORCHECK/RECURSIVE/NORMAL/ADAPTIVE_NP, are stored as the type the way_pthread_mutexattr_setkind_npdoes it, and actually change locking. Throwing for other kinds and for a null attribute is the conservative choice.pthread_rwlockattr_settype_np(Posix/Rwlock.cpp:60) returns 0 for any int, for examplesettype_np(&attr, 3)or-1. That is becausescePthreadRwlockattrSettypestores anything andscePthreadRwlockInitignores the attribute. The shadPS4 source you cite treats only 0..2 as valid: its gettype_np and settype_np both returnPOSIX_EINVALwhen the stored type is> 2. Since the console result for other values is unknown, could types outside 0..2 throw instead of reporting success?type > 2check. And since 0..2 are stored but never applied, the entry probably belongs under "Silent stubs" rather than "Unknown function info".sce_stubs/libkernel.c, so moving them out of libkernel_sys's discovery stubs is supported.Reviewed with AI assistance (Claude Code); the checks above were run locally on my machine.
Imported from boykopovar/AnyPS5. Originally posted by EagleBearerYS on 2026-10-22T06:54:16Z.
Thanks, @harisibrar1, agreed on all three. In
fa3cbbe32b:pthread_rwlockattr_settype_npstores only types 0 to 2; another type, such as 3 or -1, throws throughNotImplemented_nid_no_patchinstead of returning 0. The test checks both.settype_npandgettype_npdo: they returnEINVALonce the stored type is above 2, and for a null or uninitialized attribute.On GitHub's runners (run) the extended test fails with the previous head's code and passes 10 runs in a row on Linux and Windows.
Imported from boykopovar/AnyPS5. Originally posted by fogydes on 2026-10-22T08:13:26Z.
Consistency question; otherwise clean.
scePthreadMutexattrSetkindthrowsstd::invalid_argumentfor a null/uninitialized attribute and for out-of-range kinds, while its SCE twins in the same file answer the same conditions withSCE_KERNEL_ERROR_EINVAL(scePthreadMutexattrSettype,scePthreadMutexattrSetprotocol). Since the new function delegates the value toSettypeanyway, andSettypealready redirects every bad input (null attr, unknown value) toEINVAL, the wrappers body could simply bereturn scePthreadMutexattrSettype(attr, kind);— same observable behavior as far as the siblings go, and no new throw-style the family doesn't share. The debt entry records the throw as unmeasured console behavior, so this is a choice worth an explicit decision rather than an accident.Verified from the diff and from main: the delegate chain (
Setkind→Settype/MutexType), the 1..4-bound match against theMutexTypeenum and the SCE twin's own switch, and the test'sLocksTwice/GUEST_EDEADLKexpectations.pthread_rwlockattr_settype_np's throw-on-out-of-range is consistent with the existingscePthreadRwlockattrSettypeinsrc/Rwlock.cpp:177, which the reworked test already covers for the destroyed-attr case.Imported from boykopovar/AnyPS5. Originally posted by EagleBearerYS on 2026-10-22T09:02:05Z.
@fogydes thanks for checking the delegate chain.
scePthreadMutexattrSetkinddoesn't takescePthreadMutexattrSettype's answers for those inputs, because FreeBSD 11 libthr's_pthread_mutexattr_setkind_np, which the debt entry cites, gives neither: it stores an unknown kind unchecked, and for a null attribute it returns -1 witherrnoEINVAL. The SCE result isn't measured. You're right thatstd::invalid_argumentwas a throw style of its own, though. Ine8172f8078both cases go throughNotImplemented_nid_no_patch, aspthread_rwlockattr_settype_np's unmeasured types do in this PR, and the test expects that (run). If a console measurement showsscePthreadMutexattrSetkindreturningSCE_KERNEL_ERROR_EINVAL, it can take that answer.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-22T09:22:08Z.
Review: CHANGES_REQUESTED
The current changes address the earlier review findings: rwlock type 3/-1 are no longer silently accepted, the debt entry was corrected and moved under Silent stubs, and mutex attribute invalid inputs now use
NotImplemented_nid_no_patchrather than introducing a newstd::invalid_argumentconvention. The body reports focused Windows/Linux failure controls and 10/10 passes on both platforms after the recent changes; the earlier Linuxprecise_waitfailure reproduces on unchanged main. Latest hosted eligibility, conventions and labels checks pass, but product build/test jobs are skipped on this head; the platform run evidence in the body is from the earliere8172f8078run and should be refreshed after this push before merge. I did not rerun locally in this environment.I’ve noticed that holding this PR because of #5239 isn’t necessary. It’s fine for PRs to keep coming in; they’ll be handled in due course. Please disregard my earlier request to hold or defer it.
Imported from boykopovar/AnyPS5. Originally posted by EagleBearerYS on 2026-10-22T09:29:56Z.
@MarcZX10 run 39750076438 (run) is on
e8172f8078, the current head, so the Windows and Linux evidence in Tested is for this head. Nothing has been pushed since.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-22T12:54:59Z.
Review: DISMISSED
I confirmed the author’s clarification: the focused Windows/Linux runs are on current head
e8172f8, so my earlier concern that they were stale was mistaken. I independently rangit diff --check,tools/check_conventions.pyagainst currentmain, andtools/check_test_registration.py --scripts; all pass (171 scripts registered). The reported focused tests exercise both new entry points and compare against failing stubs; the one Linuxprecise_waitfailure reproduces on unchangedmain.I am withdrawing my earlier #5239 intake hold as a reason to defer this PR. One repository requirement remains: the PR targets
d6eafa5, while currentmainis 15 commits ahead at8b3a6ba; CONTRIBUTING.md requires a current-main base. The changed pthread and debt files themselves have no intervening main changes, so the rebase appears straightforward. Please update the base before merge and refresh the overlap/conventions check. Hosted product jobs are skipped by path filters; I did not run the full project test suite locally.Imported from boykopovar/AnyPS5. Originally posted by harisibrar1 on 2026-10-22T12:55:00Z.
Review: APPROVED
Rechecked at
e8172f8078:pthread_rwlockattr_settype_np(Posix/Rwlock.cpp:61) now throws throughNotImplemented_nid_no_patchfor types outside 0..2, sosettype_np(&attr, 3)and-1no longer report success. The test covers both.> 2EINVAL and sits under Silent stubs. It matches the code: 0..2 are stored butscePthreadRwlockInitignores them, and a null or uninitialized attribute throws, asscePthreadRwlockattrSettypedoes.scePthreadMutexattrSetkind's bad inputs toNotImplemented_nid_no_patch(Mutex.cpp:142-144) keeps it consistent with the rest of the PR, and its debt entry says so.Reviewed with AI assistance (Claude Code); the checks above were run locally on my machine.
Imported from boykopovar/AnyPS5. Originally posted by EagleBearerYS on 2026-10-22T13:57:51Z.
Thanks, @MarcZX10 and @harisibrar1. The branch now has
mainat3ca07d086dmerged in (b801b76e2f), with the PR's own diff unchanged. On GitHub's runners (run) the three pthread tests pass 10 of 10 on Linux and Windows and fail withmain's implementation, and the libc and libkernel suites pass. It's in Tested.Imported from boykopovar/AnyPS5. Originally posted by THEMANnt on 2026-10-23T13:30:53Z.
Review: APPROVED
Reviewed PR #9632 (head
96c21c0d09).Environment: Windows (win32), Python 3.11.9, MinGW64 toolchain.
Checks:
guest_kernel_sys_pthread_npprofile).Verification:
scePthreadMutexattrSetkindandpthread_rwlockattr_settype_npcorrectly replace stubs.No actionable findings. Local-only tests; no GPU or game execution performed.