fix(libkernel): setname on a condition variable, mutex, rwlock and barrier checks the name like the console #17638
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/17638"
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 xXPBSXx on 2026-11-09T05:58:16Z.
What
pthread_cond_setname_np,pthread_mutex_setname_np,pthread_rwlock_setname_npandpthread_barrier_setname_npdid not check the name like the console. The condition variable kept no name and threw for a null name, the mutex and the barrier returned 0 for a null name without naming the object, and only the barrier limited the length (to 1024). On a PS5 all four behave the same: a second call on a named object returns 35, a null name returns 22, a name of 31 characters returns 0, and names of 32 and 1024 characters return 63 (ENAMETOOLONG). This does the same: the condition variable now keeps its name, a null name returns 22, and the limit is 32 for all four. A name that cannot be read still returnsEFAULT. The tests pin the five results for each object, and the four debt entries indocs/dev/debt/libkernel.mdstate the measurement. On the console a statically initialised or a destroyed object faults, and the order of the checks (named, null, length) was not measured; both stay open in the entries. A title process was not measured.Tested
Measured on a PS5 with firmware 11.60 (
kernel_get_fw_version0x11600005), from a homebrew payload process (ps5-payload-sdk v0.45, elfldr), on 2026-11-08 at 04:33 UTC. A title process may differ. Each object was created with its init function; the cases are x.2 to x.6 of the raw output for the condition variable, mutex, rwlock and barrier (lines 4 to 8, 12 to 16, 20 to 24 and 28 to 32 of the first comment).setnamea second time on a named objectsetnamewith a null namesetnamewith a name of 31 characterssetnamewith a name of 32 characterssetnamewith a name of 1024 charactersOn this branch, Linux (WSL, Release) on
maindf088d6df507: with only the test commit 2 of the 11 affected tests fail (guest_pthread_setnameandguest_pthread_cond_setname), the other 9 pass; with the fix all 11 pass in 3 of 3 runs. Each test stops at its first failing check, so the rwlock and barrier checks are not reached in the run without the fix; they pass with it.tools/check_conventions.py --base upstream/mainpasses. The probe source and its raw output are in the first comment. Not tested: Windows, macOS, the CI runner, a title process and any other firmware.Overlap: checked at 05:37 UTC against
main0ef447da3cand the 112 open pull requests that touch one of these files (mostlydocs/dev/debt/libkernel.mdandPthread.hpp). With this head, 110 merge cleanly or conflict withmainalready; #17222 (pthread_mutex_setname_npandpthread_rwlock_setname_npwithEFAULT) and #17220 (pthread_cond_setname_npwithEFAULT) merge withmainbut conflict with this head, inMutex.cpp,Rwlock.cpp,Cond.cpp,GuestPthreadSetname.cpp,GuestPthreadCondSetname.cppandlibkernel.md. They harden the same functions against unreadable pointers, a different change from the name checks here; #17222 keeps a 1024-byte limit for the mutex name and 0 for a null name, which the console measurement above does not support (31 characters is the longest name taken, a null name returns 22). Whichever lands second rebases.tools/check_conventions.py --base upstream/mainreports 0 errors and 4debt-lengthwarnings, for thepthread_cond_setname_np,pthread_mutex_setname_np,pthread_rwlock_setname_npandpthread_barrier_setname_npentries, which are over 1000 characters.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)AI-assisted (Claude Code).
🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by milescoviello on 2026-11-09T08:13:19Z.
Review: APPROVED
Read
505a2601a7againstmaindf088d6df5.CopyGuestString_nid_no_patch(libc/src/General.cpp:547) needs the NUL withinmaximumbytes. With 32, a 31-character name copies and a 32-character one returns 63, which is the boundary in your table. Unreadable bytes still return 14.SetNamereturns SCE codes, andpthread_cond_setname_nppasses them throughtoPosix(Posix/Cond.cpp:63), so 35, 22, 63 and 14 come out as the POSIX values the other three return directly.SceKernelError(error)on the copy result keeps that path inside the0x8002xxxxrangetoPosixaccepts.One question, not a blocker:
scePthreadMutexInitandscePthreadCondInittake a name and still ignore it (Mutex.cpp:215,Cond.cpp:237), so an object created with a name reports_named == false, and its firstsetnamereturns 0 here. Did the probe create the objects with a name, or with the POSIX*_init? If it's easy to add, one more row (init with a name, thensetname) would show whether an init name counts as already named (35) on the console.AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-21T04:54:47Z.
Review: APPROVED
Reviewed — looks good
Nothing blocks this change; the inspected implementation matches the reported console results.
What I ran
Reviewed head
29b749995ae2dcf8ef2272744f4d00f79e2985f5. I ran no commands; the reader is read-only. The description reports 11 tests passing in three runs andtools/check_conventions.py --base upstream/mainpassing; these were author-reported, not run during this review.Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
The review folder’s
files/directory was empty, so I read the eight changed files directly through the pinned reader.Rwlock.cppwas excluded by the review rules; its setname implementation was inspected directly, but its full diff was not available. Console behavior in title processes and on other firmware, and behavior on Windows and macOS, was not verified.To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-25T12:31:31Z.
Review: APPROVED
Reviewed — looks good
Nothing blocks this change; the optional documentation correction below would make the recorded console evidence more precise.
What I ran
Reviewed head
6e5e46f9a8ff49f0430420cbf3e100390f6a6c1busingrepo_read.pyfor the prepared diff and targeted source context. No commands or tests were run in this review.Results
Findings
Blocking
None.
Non-blocking
docs/dev/debt/libkernel.md:380says the console rwlock setname call faults on a null lock, static lock, or destroyed lock. The description says those console behaviors were not measured and are left open. Please mark these outcomes unmeasured, consistent with the adjacent mutex and barrier notes.Not verified
Tests were not run.
core/libs/prx/libkernel/Pthread/src/Rwlock.cppwas excluded from the prepared diff by rule and was only read at the setname function for context; other parts of that file were not reviewed. No other repository files were read beyond targeted context.files.jsonwas unavailable; the manifest lists eight included changed files, all of which were read at least at their changed lines. No changed files listed in the manifest were excluded.To get this to a good state
Nothing is required. Optionally clarify the unmeasured rwlock fault behavior in the debt entry above.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-26T10:41:45Z.
Review: COMMENTED
Reviewed — no blocking findings
Nothing blocks this; the point below is optional.
What I ran
Reviewed head
3a53b06e6cf1ccf0d7e15487b3a2376c9da5a45fusingrepo_read.pyto inspect the prepared description, commits, manifest, diff, and changed source files. I did not run tests or other checks; no test runner was available through the read-only tools.Results
Rwlock.cppexcluded by ruleFindings
Blocking
None.
Non-blocking
pthread_cond_setname_npcan initialize a lazy condition variable before returningEINVALfor a null name or an error for an unreadable/too-long name. InCond.cpp:202-207, the newly allocated object is stored and released before the name is validated atCond.cpp:211-215. Consider validating/copying the name before creating or publishing the condition variable, so a failed call does not change its state.Not verified
Tests, convention checks, and console behavior were not independently run or confirmed. Read all included changed files listed in the manifest:
Barrier.cpp,Pthread.hpp,Cond.cpp,Mutex.cpp,GuestKernelBarrierInitBounds.cpp,GuestKernelPthreadCondNpBounds.cpp,GuestPthreadCondSetname.cpp,GuestPthreadSetname.cpp, andlibkernel.md.Rwlock.cppwas excluded by rule and not reviewed; the repository reader did not provide afiles.jsondocument.To get this to a good state
Nothing is required. Optionally, avoid publishing a newly created condition variable when
setnamereturns an error.