fix(libkernel): setname on a condition variable, mutex, rwlock and barrier checks the name like the console #17638

Merged
xXPBSXx merged 8 commits from upstream-pr/17638 into main 2026-11-27 12:03:38 +00:00
xXPBSXx commented 2026-11-09 05:58:16 +00:00 (Migrated from github.com)

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_np and pthread_barrier_setname_np did 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 returns EFAULT. The tests pin the five results for each object, and the four debt entries in docs/dev/debt/libkernel.md state 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_version 0x11600005), 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).

Call, on each of the four object types PS5, payload process, firmware 11.60 here
setname a second time on a named object 35 35
setname with a null name 22 22
setname with a name of 31 characters 0 0
setname with a name of 32 characters 63 63
setname with a name of 1024 characters 63 63

On this branch, Linux (WSL, Release) on main df088d6df507: with only the test commit 2 of the 11 affected tests fail (guest_pthread_setname and guest_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/main passes. 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 main 0ef447da3c and the 112 open pull requests that touch one of these files (mostly docs/dev/debt/libkernel.md and Pthread.hpp). With this head, 110 merge cleanly or conflict with main already; #17222 (pthread_mutex_setname_np and pthread_rwlock_setname_np with EFAULT) and #17220 (pthread_cond_setname_np with EFAULT) merge with main but conflict with this head, in Mutex.cpp, Rwlock.cpp, Cond.cpp, GuestPthreadSetname.cpp, GuestPthreadCondSetname.cpp and libkernel.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/main reports 0 errors and 4 debt-length warnings, for the pthread_cond_setname_np, pthread_mutex_setname_np, pthread_rwlock_setname_np and pthread_barrier_setname_np entries, which are over 1000 characters.

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 (documentation and host-independent thread object checks only)
  • AI-assisted: yes

AI-assisted (Claude Code).

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5219460232 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/17638). Originally posted by [xXPBSXx](https://github.com/xXPBSXx) on 2026-11-09T05:58:16Z. --- ### What `pthread_cond_setname_np`, `pthread_mutex_setname_np`, `pthread_rwlock_setname_np` and `pthread_barrier_setname_np` did 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 returns `EFAULT`. The tests pin the five results for each object, and the four debt entries in `docs/dev/debt/libkernel.md` state 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_version` 0x11600005), 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). | Call, on each of the four object types | PS5, payload process, firmware 11.60 | here | |---|---|---| | `setname` a second time on a named object | 35 | 35 | | `setname` with a null name | 22 | 22 | | `setname` with a name of 31 characters | 0 | 0 | | `setname` with a name of 32 characters | 63 | 63 | | `setname` with a name of 1024 characters | 63 | 63 | On this branch, Linux (WSL, Release) on `main` `df088d6df507`: with only the test commit 2 of the 11 affected tests fail (`guest_pthread_setname` and `guest_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/main` passes. 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 `main` `0ef447da3c` and the 112 open pull requests that touch one of these files (mostly `docs/dev/debt/libkernel.md` and `Pthread.hpp`). With this head, 110 merge cleanly or conflict with `main` already; #17222 (`pthread_mutex_setname_np` and `pthread_rwlock_setname_np` with `EFAULT`) and #17220 (`pthread_cond_setname_np` with `EFAULT`) merge with `main` but conflict with this head, in `Mutex.cpp`, `Rwlock.cpp`, `Cond.cpp`, `GuestPthreadSetname.cpp`, `GuestPthreadCondSetname.cpp` and `libkernel.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/main` reports 0 errors and 4 `debt-length` warnings, for the `pthread_cond_setname_np`, `pthread_mutex_setname_np`, `pthread_rwlock_setname_np` and `pthread_barrier_setname_np` entries, which are over 1000 characters. ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [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 <!-- #PR, or none --> - [x] Fixes: none <!-- issue it closes as Fixes #N, or none --> - [x] Unblocks: none <!-- title ID and Game bring-up discussion, e.g. PPSA01325 #3232, or none --> - [x] GPUs tested: n/a (documentation and host-independent thread object checks only) <!-- for AGC, shader recompiler or VideoOut changes: vendor, model, driver and OS of each GPU the GPU tests ran on; otherwise n/a --> - [x] AI-assisted: yes <!-- yes / no --> AI-assisted (Claude Code). 🤖 Generated with [Claude Code](https://claude.com/claude-code)
milescoviello commented 2026-11-09 08:13:19 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by milescoviello on 2026-11-09T08:13:19Z.

Review: APPROVED


Read 505a2601a7 against main df088d6df5.

  • Length limit: CopyGuestString_nid_no_patch (libc/src/General.cpp:547) needs the NUL within maximum bytes. 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.
  • Condition variable: SetName returns SCE codes, and pthread_cond_setname_np passes them through toPosix (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 the 0x8002xxxx range toPosix accepts.
  • Order: all four now check named, then null, then length, and the debt entries say the order wasn't measured.

One question, not a blocker: scePthreadMutexInit and scePthreadCondInit take a name and still ignore it (Mutex.cpp:215, Cond.cpp:237), so an object created with a name reports _named == false, and its first setname returns 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, then setname) would show whether an init name counts as already named (35) on the console.

AI-assisted: yes (Claude Code)

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5823176127 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/17638#pullrequestreview-5823176127). Originally posted by [milescoviello](https://github.com/milescoviello) on 2026-11-09T08:13:19Z. **Review:** APPROVED --- Read `505a2601a7` against `main` `df088d6df5`. - **Length limit:** `CopyGuestString_nid_no_patch` (`libc/src/General.cpp:547`) needs the NUL within `maximum` bytes. 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. - **Condition variable:** `SetName` returns SCE codes, and `pthread_cond_setname_np` passes them through `toPosix` (`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 the `0x8002xxxx` range `toPosix` accepts. - **Order:** all four now check named, then null, then length, and the debt entries say the order wasn't measured. One question, not a blocker: `scePthreadMutexInit` and `scePthreadCondInit` take a name and still ignore it (`Mutex.cpp:215`, `Cond.cpp:237`), so an object created with a name reports `_named == false`, and its first `setname` returns 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, then `setname`) would show whether an init name counts as already named (35) on the console. AI-assisted: yes (Claude Code)
MarcZX10 commented 2026-11-21 04:54:47 +00:00 (Migrated from github.com)

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 and tools/check_conventions.py --base upstream/main passing; these were author-reported, not run during this review.

Results

Check Result Note
Diff and changed code passed Inspected all eight listed changed files
Tests and conventions not run Results reported by the author

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.cpp was 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.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6002937046 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/17638#pullrequestreview-6002937046). Originally posted by [MarcZX10](https://github.com/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 and `tools/check_conventions.py --base upstream/main` passing; these were author-reported, not run during this review. ## Results | Check | Result | Note | |---|---|---| | Diff and changed code | passed | Inspected all eight listed changed files | | Tests and conventions | not run | Results reported by the author | ## 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.cpp` was 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.
MarcZX10 commented 2026-11-25 12:31:31 +00:00 (Migrated from github.com)

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 6e5e46f9a8ff49f0430420cbf3e100390f6a6c1b using repo_read.py for the prepared diff and targeted source context. No commands or tests were run in this review.

Results

Check Result Note
Changed code and tests passed Inspected all included changed files
Test execution not run No local test command was run
Prepared diff passed Reviewed all 313 lines

Findings

Blocking

None.

Non-blocking

  • docs/dev/debt/libkernel.md:380 says 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.cpp was 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.json was 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.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6057635825 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/17638#pullrequestreview-6057635825). Originally posted by [MarcZX10](https://github.com/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 `6e5e46f9a8ff49f0430420cbf3e100390f6a6c1b` using `repo_read.py` for the prepared diff and targeted source context. No commands or tests were run in this review. ## Results | Check | Result | Note | |---|---|---| | Changed code and tests | passed | Inspected all included changed files | | Test execution | not run | No local test command was run | | Prepared diff | passed | Reviewed all 313 lines | ## Findings ### Blocking None. ### Non-blocking - `docs/dev/debt/libkernel.md:380` says 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.cpp` was 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.json` was 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.
MarcZX10 commented 2026-11-26 10:41:45 +00:00 (Migrated from github.com)

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 3a53b06e6cf1ccf0d7e15487b3a2376c9da5a45f using repo_read.py to 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

Check Result Note
Change and source review passed Included changed files read
Tests and conventions not run Read-only review session
Excluded file review not run Rwlock.cpp excluded by rule

Findings

Blocking

None.

Non-blocking

  • pthread_cond_setname_np can initialize a lazy condition variable before returning EINVAL for a null name or an error for an unreadable/too-long name. In Cond.cpp:202-207, the newly allocated object is stored and released before the name is validated at Cond.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, and libkernel.md. Rwlock.cpp was excluded by rule and not reviewed; the repository reader did not provide a files.json document.

To get this to a good state

Nothing is required. Optionally, avoid publishing a newly created condition variable when setname returns an error.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6072655599 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/17638#pullrequestreview-6072655599). Originally posted by [MarcZX10](https://github.com/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 `3a53b06e6cf1ccf0d7e15487b3a2376c9da5a45f` using `repo_read.py` to 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 | Check | Result | Note | |---|---|---| | Change and source review | passed | Included changed files read | | Tests and conventions | not run | Read-only review session | | Excluded file review | not run | `Rwlock.cpp` excluded by rule | ## Findings ### Blocking None. ### Non-blocking - `pthread_cond_setname_np` can initialize a lazy condition variable before returning `EINVAL` for a null name or an error for an unreadable/too-long name. In `Cond.cpp:202-207`, the newly allocated object is stored and released before the name is validated at `Cond.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`, and `libkernel.md`. `Rwlock.cpp` was excluded by rule and not reviewed; the repository reader did not provide a `files.json` document. ## To get this to a good state Nothing is required. Optionally, avoid publishing a newly created condition variable when `setname` returns an error.
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!17638
No description provided.