fix(libkernel): scePthreadRename returns ENAMETOOLONG for a name of 32 or more characters #17091

Merged
xXPBSXx merged 6 commits from upstream-pr/17091 into main 2026-11-12 00:49:16 +00:00
xXPBSXx commented 2026-11-08 09:57:00 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-11-08T09:57:00Z.


What

scePthreadRename set any name on the thread, however long. On a PS5 a name of 40 characters returns SCE_KERNEL_ERROR_ENAMETOOLONG (0x8002003f, errno 63), while a name of 11 characters and an empty name return 0. This returns ENAMETOOLONG for a name of 32 or more bytes and leaves the thread's name as it was. A later probe run measured the limit on scePthreadRename itself, after a 20 character name: names of 5 and 31 characters are accepted, names of 32, 33, 40 and 64 characters return ENAMETOOLONG and the old name is kept, not cut to 31 characters. Whether it refuses before or after it looks up the thread is not measured. A test pins 32 and 40 characters and checks that the stored name stays, and the debt entry in docs/dev/debt/libkernel.md states the measurement. A title process was not measured.

A review point (gabichuuuuu) led to three follow-up commits: pthread_set_name_np ignored the result of scePthreadRename, so a name of 32 or more bytes left the old name and set no errno. It now sets errno from the result of the rename. The same run measured pthread_set_name_np on the payload process: names of 32, 33, 40 and 64 characters set errno 63 (ENAMETOOLONG) and keep the old name. A null name for scePthreadRename returned 0 and left an empty name in an earlier run, where this returns EINVAL; that is not changed here and is recorded in the debt entry.

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 03:58 UTC. A title process may differ. The calls renamed the probe's own thread; the cases are 1.3, 1.6 and 1.8, lines 6, 9 and 11 of the raw output in the first comment.

Call PS5, payload process, firmware 11.60 AnyPS5 main before here
scePthreadRename(self, name of 11 characters) 0 0 0
scePthreadRename(self, name of 40 characters) 0x8002003f (errno 63) 0, the name is stored 0x8002003f, the name stays
scePthreadRename(self, empty name) 0 0 0

Second run, for the follow-up and for the limit: on 2026-11-08 at 19:54 UTC, the same kind of payload process (firmware 11.60). The probe's own main thread was named with 20 times Z, then renamed with a request of 5, 31, 32, 33, 40 or 64 letters (an alphabet), and the name was read back with pthread_getname_np and scePthreadGetname; the cases are 2.1 to 3.6 of its raw output in the second comment.

Call PS5, payload process, firmware 11.60 here
scePthreadRename(self, request of 5 or 31 characters) 0, the name reads back as the request (3.1, 3.2) the same
scePthreadRename(self, request of 32, 33, 40 or 64 characters) 0x8002003f (errno 63), the old name stays (3.3-3.6) 0x8002003f, the old name stays
pthread_set_name_np(self, request of 5 or 31 characters) errno 0, the name reads back as the request (2.1, 2.2) the same
pthread_set_name_np(self, request of 32, 33, 40 or 64 characters) errno 63, the old name stays (2.3-2.6) errno 63, the old name stays

With only the follow-up test commit guest_pthread_rename fails in 3 of 3 runs and with the follow-up fix it passes in 3 of 3 runs (Linux, WSL, Release, on 8efd096c0aea). On this branch, Linux (WSL, Release) on main e6108f3d8e11: with only the test commit the pthread rename test fails in 3 of 3 runs, and with the fix it passes in 3 of 3 runs. tools/check_conventions.py --base upstream/main passes on head 261bdf1caa80. 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 (P2, 2026-11-08, list of open pull requests from 22:41 UTC, main 22ae9a397d, checked 22:41-22:46 UTC, head 261bdf1caa80): of the 112 open pull requests that change core/libs/prx/libkernel/Pthread/Posix/Thread.cpp, core/libs/prx/libkernel/Pthread/src/Thread.cpp, core/libs/tests/GuestPthreadRename.cpp or docs/dev/debt/libkernel.md, each was merged with and without this branch. #15567 (fail pthread_rename_np and scePthreadRename with EFAULT on an unreadable name) conflicts only with this branch, in core/libs/prx/libkernel/Pthread/src/Thread.cpp, where both change the name handling of scePthreadRename; it merges with main now, so whichever lands second needs a rebase. 42 conflict with main without this branch as well; the other 69 merge cleanly with and without it.

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 a host-independent thread name check only)
  • AI-assisted: yes

AI-assisted (Claude Code).

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5210379843 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/17091). Originally posted by [xXPBSXx](https://github.com/xXPBSXx) on 2026-11-08T09:57:00Z. --- ### What `scePthreadRename` set any name on the thread, however long. On a PS5 a name of 40 characters returns `SCE_KERNEL_ERROR_ENAMETOOLONG` (0x8002003f, errno 63), while a name of 11 characters and an empty name return 0. This returns `ENAMETOOLONG` for a name of 32 or more bytes and leaves the thread's name as it was. A later probe run measured the limit on `scePthreadRename` itself, after a 20 character name: names of 5 and 31 characters are accepted, names of 32, 33, 40 and 64 characters return `ENAMETOOLONG` and the old name is kept, not cut to 31 characters. Whether it refuses before or after it looks up the thread is not measured. A test pins 32 and 40 characters and checks that the stored name stays, and the debt entry in `docs/dev/debt/libkernel.md` states the measurement. A title process was not measured. A review point (gabichuuuuu) led to three follow-up commits: `pthread_set_name_np` ignored the result of `scePthreadRename`, so a name of 32 or more bytes left the old name and set no `errno`. It now sets `errno` from the result of the rename. The same run measured `pthread_set_name_np` on the payload process: names of 32, 33, 40 and 64 characters set `errno` 63 (`ENAMETOOLONG`) and keep the old name. A null name for `scePthreadRename` returned 0 and left an empty name in an earlier run, where this returns `EINVAL`; that is not changed here and is recorded in the debt entry. ### 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 03:58 UTC. A title process may differ. The calls renamed the probe's own thread; the cases are 1.3, 1.6 and 1.8, lines 6, 9 and 11 of the raw output in the first comment. | Call | PS5, payload process, firmware 11.60 | AnyPS5 `main` before | here | |---|---|---|---| | `scePthreadRename(self, name of 11 characters)` | 0 | 0 | 0 | | `scePthreadRename(self, name of 40 characters)` | 0x8002003f (errno 63) | 0, the name is stored | 0x8002003f, the name stays | | `scePthreadRename(self, empty name)` | 0 | 0 | 0 | Second run, for the follow-up and for the limit: on 2026-11-08 at 19:54 UTC, the same kind of payload process (firmware 11.60). The probe's own main thread was named with 20 times `Z`, then renamed with a request of 5, 31, 32, 33, 40 or 64 letters (an alphabet), and the name was read back with `pthread_getname_np` and `scePthreadGetname`; the cases are 2.1 to 3.6 of its raw output in the second comment. | Call | PS5, payload process, firmware 11.60 | here | |---|---|---| | `scePthreadRename(self, request of 5 or 31 characters)` | 0, the name reads back as the request (3.1, 3.2) | the same | | `scePthreadRename(self, request of 32, 33, 40 or 64 characters)` | 0x8002003f (errno 63), the old name stays (3.3-3.6) | 0x8002003f, the old name stays | | `pthread_set_name_np(self, request of 5 or 31 characters)` | `errno` 0, the name reads back as the request (2.1, 2.2) | the same | | `pthread_set_name_np(self, request of 32, 33, 40 or 64 characters)` | `errno` 63, the old name stays (2.3-2.6) | `errno` 63, the old name stays | With only the follow-up test commit `guest_pthread_rename` fails in 3 of 3 runs and with the follow-up fix it passes in 3 of 3 runs (Linux, WSL, Release, on `8efd096c0aea`). On this branch, Linux (WSL, Release) on `main` `e6108f3d8e11`: with only the test commit the pthread rename test fails in 3 of 3 runs, and with the fix it passes in 3 of 3 runs. `tools/check_conventions.py --base upstream/main` passes on head `261bdf1caa80`. 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 (P2, 2026-11-08, list of open pull requests from 22:41 UTC, `main` `22ae9a397d`, checked 22:41-22:46 UTC, head `261bdf1caa80`): of the 112 open pull requests that change `core/libs/prx/libkernel/Pthread/Posix/Thread.cpp`, `core/libs/prx/libkernel/Pthread/src/Thread.cpp`, `core/libs/tests/GuestPthreadRename.cpp` or `docs/dev/debt/libkernel.md`, each was merged with and without this branch. #15567 (`fail pthread_rename_np and scePthreadRename with EFAULT on an unreadable name`) conflicts only with this branch, in `core/libs/prx/libkernel/Pthread/src/Thread.cpp`, where both change the name handling of `scePthreadRename`; it merges with `main` now, so whichever lands second needs a rebase. 42 conflict with `main` without this branch as well; the other 69 merge cleanly with and without it. ### 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 a host-independent thread name check 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)
gabichuuuuu commented 2026-11-08 16:42:27 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by gabichuuuuu on 2026-11-08T16:42:27Z.

Review: COMMENTED


Windows run of head 8efd096c0a, merged onto main 828e44310e. To save builds, this ran in one local tree together with 13 other open PRs that touch different files. All 14 merged cleanly. Setup: Windows 11, WinLibs GCC 15.2 (x86_64-ucrt-posix-seh), Release, BUILD_TESTING=ON.

  • guest_pthread_rename with --repeat until-fail:10: 10 / 10 pass.
  • Negative control, with main's libkernel/Pthread/src/Thread.cpp and this PR's test: 5 / 5 runs fail. With the PR's file put back, it passes again.

pthread_set_name_np now drops long names silently. It calls scePthreadRename(thread, name) and ignores the result (Pthread/Posix/Thread.cpp:452-453). On main, a name of 32 or more characters was stored. With this PR it gets ENAMETOOLONG and the thread keeps its old name, with nothing reported to the caller. FreeBSD's pthread_set_name_np goes through thr_set_name, which truncates a long name and succeeds. The PS5 behaviour of pthread_set_name_np wasn't measured. Truncating to 31 characters there, or recording the open question in the debt entry, would keep this from becoming a silent no-op.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5818702200 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/17091#pullrequestreview-5818702200). Originally posted by [gabichuuuuu](https://github.com/gabichuuuuu) on 2026-11-08T16:42:27Z. **Review:** COMMENTED --- Windows run of head `8efd096c0a`, merged onto `main` `828e44310e`. To save builds, this ran in one local tree together with 13 other open PRs that touch different files. All 14 merged cleanly. Setup: Windows 11, WinLibs GCC 15.2 (`x86_64-ucrt-posix-seh`), Release, `BUILD_TESTING=ON`. - `guest_pthread_rename` with `--repeat until-fail:10`: 10 / 10 pass. - **Negative control,** with `main`'s `libkernel/Pthread/src/Thread.cpp` and this PR's test: 5 / 5 runs fail. With the PR's file put back, it passes again. **`pthread_set_name_np` now drops long names silently.** It calls `scePthreadRename(thread, name)` and ignores the result (`Pthread/Posix/Thread.cpp:452-453`). On `main`, a name of 32 or more characters was stored. With this PR it gets `ENAMETOOLONG` and the thread keeps its old name, with nothing reported to the caller. FreeBSD's `pthread_set_name_np` goes through `thr_set_name`, which truncates a long name and succeeds. The PS5 behaviour of `pthread_set_name_np` wasn't measured. Truncating to 31 characters there, or recording the open question in the debt entry, would keep this from becoming a silent no-op.
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!17091
No description provided.