fix(libkernel): answer pthread_getname_np for a joined thread with ESRCH #4533

Merged
Roojool merged 2 commits from upstream-pr/4533 into main 2026-10-17 00:05:39 +00:00
Roojool commented 2026-10-12 14:53:10 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Roojool on 2026-10-12T14:53:10Z.


What

pthread_getname_np on a thread that has already been joined returns ESRCH (3) and leaves the output buffer untouched, as measured on a PS5 (firmware 13.60) and recorded in TechnicalDebt by the entry's author: "a thread that has already been joined returns ESRCH (3) on a PS5 (firmware 13.60)". Before, the freed object could not be told apart from a live thread, so its name was read as for a live one.

Depends on: #4481 — that change keeps a joined thread's object alive in a JOINED state, which is what makes the console's answer implementable here at all. This PR is the small follow-up it enables:

  • pthread_getname_np_nid_postfix returns the posix ESRCH (the same GUEST_ESRCH it already answers for a null thread) when the thread is already joined; the output buffer is not written.
  • A null name buffer is still answered with EFAULT first; the console table does not measure that order (noted in TechnicalDebt).
  • The SCE sibling scePthreadGetname has no measured joined-thread behaviour and still reads the retained object's name; unchanged and pinned in the test.
  • Unchanged and documented: the pre-existing dangling case of a thread that ended detached (its object is released at exit).

Tested

  • Restack validation (2026-10-13): head c3faf114e on #4481 a2dfbfd34 / main d53960612; debt entry moved to docs/dev/debt/libkernel.md. Eight focused tests (guest_pthread_getname, guest_pthread_second_join, guest_pthread_join_self, guest_thread_self, guest_pthread_start, guest_pthread_rename, guest_filesystem, guest_dup) pass on native Windows and WSL Linux after rebuilding; conventions and whitespace checks pass. Full suite was not re-run for this restack.
  • Extended guest_pthread_getname: create a named thread -> scePthreadJoin 0 -> pthread_getname_np returns 3 with a 0xAA sentinel buffer untouched -> scePthreadGetname pinned to today's behaviour (0, retained name); all previous cases kept.
  • Without this change, on the #4481 base (dc30882e1): the extended test fails 3/3 on Windows (returns 0 and reads the retained name; abort 0xc0000409).
  • With the change: Windows (WinLibs GCC 15.2.0, Release) extended test 3/3; neighbors guest_pthread_second_join, guest_pthread_join_self, guest_thread_self, guest_pthread_start, guest_pthread_rename pass, and a 21-test pthread/thread sweep passes; WSL2 Linux (g++ 15.2.0, Release) extended test and 6 neighbors pass.
  • python tools/check_conventions.py --base dc30882e1 passes (re-run at the final commit).

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; silent stubs are listed in TechnicalDebt
  • No notes, investigation .md files or images added to the repository
  • No new third-party code
  • Generic behaviour, not specific to one title
  • Depends on: #4481
  • AI-assisted: yes

Console semantics are the TechnicalDebt entry author's PS5 firmware 13.60 measurements (merged #1798's table); no console was run for this change.

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4831118685 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4533). Originally posted by [Roojool](https://github.com/Roojool) on 2026-10-12T14:53:10Z. --- ### What `pthread_getname_np` on a thread that has already been joined returns `ESRCH` (3) and leaves the output buffer untouched, as measured on a PS5 (firmware 13.60) and recorded in TechnicalDebt by the entry's author: "a thread that has already been joined returns `ESRCH` (3) on a PS5 (firmware 13.60)". Before, the freed object could not be told apart from a live thread, so its name was read as for a live one. Depends on: #4481 — that change keeps a joined thread's object alive in a JOINED state, which is what makes the console's answer implementable here at all. This PR is the small follow-up it enables: - `pthread_getname_np_nid_postfix` returns the posix `ESRCH` (the same `GUEST_ESRCH` it already answers for a null thread) when the thread is already joined; the output buffer is not written. - A null name buffer is still answered with `EFAULT` first; the console table does not measure that order (noted in TechnicalDebt). - The SCE sibling `scePthreadGetname` has no measured joined-thread behaviour and still reads the retained object's name; unchanged and pinned in the test. - Unchanged and documented: the pre-existing dangling case of a thread that ended detached (its object is released at exit). ### Tested - Restack validation (2026-10-13): head `c3faf114e` on #4481 `a2dfbfd34` / `main` `d53960612`; debt entry moved to `docs/dev/debt/libkernel.md`. Eight focused tests (`guest_pthread_getname`, `guest_pthread_second_join`, `guest_pthread_join_self`, `guest_thread_self`, `guest_pthread_start`, `guest_pthread_rename`, `guest_filesystem`, `guest_dup`) pass on native Windows and WSL Linux after rebuilding; conventions and whitespace checks pass. Full suite was not re-run for this restack. - Extended `guest_pthread_getname`: create a named thread -> `scePthreadJoin` 0 -> `pthread_getname_np` returns 3 with a `0xAA` sentinel buffer untouched -> `scePthreadGetname` pinned to today's behaviour (0, retained name); all previous cases kept. - Without this change, on the #4481 base (`dc30882e1`): the extended test fails 3/3 on Windows (returns 0 and reads the retained name; abort `0xc0000409`). - With the change: Windows (WinLibs GCC 15.2.0, Release) extended test 3/3; neighbors `guest_pthread_second_join`, `guest_pthread_join_self`, `guest_thread_self`, `guest_pthread_start`, `guest_pthread_rename` pass, and a 21-test pthread/thread sweep passes; WSL2 Linux (g++ 15.2.0, Release) extended test and 6 neighbors pass. - `python tools/check_conventions.py --base dc30882e1` passes (re-run at the final commit). ### Checklist - [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 - [x] Unimplemented paths throw; silent stubs are listed in TechnicalDebt - [x] No notes, investigation `.md` files or images added to the repository - [x] No new third-party code - [x] Generic behaviour, not specific to one title - [x] Depends on: #4481 - [x] AI-assisted: yes Console semantics are the TechnicalDebt entry author's PS5 firmware 13.60 measurements (merged #1798's table); no console was run for this change.
copilot-pull-request-reviewer[bot] commented 2026-10-12 14:53:18 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by copilot-pull-request-reviewer[bot] on 2026-10-12T14:53:18Z.

Review: COMMENTED


Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5492441357 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4533#pullrequestreview-5492441357). Originally posted by [copilot-pull-request-reviewer[bot]](https://github.com/apps/copilot-pull-request-reviewer) on 2026-10-12T14:53:18Z. **Review:** COMMENTED --- Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.
copilot-pull-request-reviewer[bot] commented 2026-10-12 16:33:38 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by copilot-pull-request-reviewer[bot] on 2026-10-12T16:33:38Z.

Review: COMMENTED


Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5493585949 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4533#pullrequestreview-5493585949). Originally posted by [copilot-pull-request-reviewer[bot]](https://github.com/apps/copilot-pull-request-reviewer) on 2026-10-12T16:33:38Z. **Review:** COMMENTED --- Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.
xXPBSXx commented 2026-10-12 17:05:55 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-12T17:05:55Z.


Windows test: head 52416455c merged onto current main 2a5eca11c (clean merge, no conflicts). Windows 10, MinGW GCC (WinLibs), Ninja Release, -j2: full build 0 errors; ctest with the filter guest_pthread_getname|guest_pthread_second_join: guest_pthread_getname passed, guest_pthread_second_join passed (2 test(s), 0 failed); python tools/check_conventions.py --base upstream/main passed. I did not run the new tests against main without the change.

AI-assisted (Claude Code).

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6128918761 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4533#issuecomment-6128918761). Originally posted by [xXPBSXx](https://github.com/xXPBSXx) on 2026-10-12T17:05:55Z. --- Windows test: head `52416455c` merged onto current `main` `2a5eca11c` (clean merge, no conflicts). Windows 10, MinGW GCC (WinLibs), Ninja Release, `-j2`: full build 0 errors; ctest with the filter `guest_pthread_getname|guest_pthread_second_join`: guest_pthread_getname passed, guest_pthread_second_join passed (2 test(s), 0 failed); `python tools/check_conventions.py --base upstream/main` passed. I did not run the new tests against `main` without the change. AI-assisted (Claude Code).
copilot-pull-request-reviewer[bot] commented 2026-10-12 20:24:08 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by copilot-pull-request-reviewer[bot] on 2026-10-12T20:24:08Z.

Review: COMMENTED


Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5495609794 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4533#pullrequestreview-5495609794). Originally posted by [copilot-pull-request-reviewer[bot]](https://github.com/apps/copilot-pull-request-reviewer) on 2026-10-12T20:24:08Z. **Review:** COMMENTED --- Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.
copilot-pull-request-reviewer[bot] commented 2026-10-14 05:35:13 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by copilot-pull-request-reviewer[bot] on 2026-10-14T05:35:13Z.

Review: COMMENTED


Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5513494938 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4533#pullrequestreview-5513494938). Originally posted by [copilot-pull-request-reviewer[bot]](https://github.com/apps/copilot-pull-request-reviewer) on 2026-10-14T05:35:13Z. **Review:** COMMENTED --- Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.
Roojool commented 2026-10-15 05:19:12 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Roojool on 2026-10-15T05:19:12Z.


Thanks for the independent Windows run — full build clean, both tests green, conventions green on the same head. That validation is on the record now.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6185029789 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4533#issuecomment-6185029789). Originally posted by [Roojool](https://github.com/Roojool) on 2026-10-15T05:19:12Z. --- Thanks for the independent Windows run — full build clean, both tests green, conventions green on the same head. That validation is on the record now.
github-actions[bot] commented 2026-10-15 12:06:38 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-15T12:06:38Z.


Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.

Pull request Conflicting files (lines on main) Same exports Same new files
PR 6487 core/libs/prx/libkernel/Pthread/include/Pthread.hpp L142
core/libs/prx/libkernel/Pthread/src/Thread.cpp L792-793, L811-812
docs/dev/debt/libkernel.md L146

Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.

Pull request Shared files not compared
PR 3986 core/libs/prx/libkernel/Pthread/src/Thread.cpp
PR 4972 core/libs/prx/libkernel/CMakeLists.txt
PR 5021 core/libs/prx/libkernel/CMakeLists.txt
core/libs/prx/libkernel/Pthread/include/Pthread.hpp
core/libs/prx/libkernel/Pthread/src/Thread.cpp
docs/dev/debt/libkernel.md
PR 5280 core/libs/prx/libkernel/CMakeLists.txt
docs/dev/debt/libkernel.md
PR 5993 core/libs/prx/libkernel/CMakeLists.txt
docs/dev/debt/libkernel.md
PR 6044 core/libs/prx/libkernel/CMakeLists.txt
core/libs/tests/GuestPthreadGetname.cpp
PR 6222 core/libs/prx/libkernel/CMakeLists.txt
core/libs/prx/libkernel/Pthread/include/Pthread.hpp
core/libs/prx/libkernel/Pthread/src/Thread.cpp
docs/dev/debt/libkernel.md
PR 6228 docs/dev/debt/libkernel.md
PR 6447 core/libs/prx/libkernel/Pthread/Posix/Thread.cpp
PR 6510 docs/dev/debt/libkernel.md
PR 6519 docs/dev/debt/libkernel.md
PR 6658 core/libs/prx/libkernel/CMakeLists.txt
docs/dev/debt/libkernel.md
PR 6710 docs/dev/debt/libkernel.md
PR 6836 docs/dev/debt/libkernel.md
PR 6879 core/libs/prx/libkernel/Pthread/src/Thread.cpp
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6191649536 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4533#issuecomment-6191649536). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-15T12:06:38Z. --- <!-- pr-overlap --> Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in **Depends on**. | Pull request | Conflicting files (lines on `main`) | Same exports | Same new files | |---|---|---|---| | [PR 6487](https://www.github.com/boykopovar/AnyPS5/pull/6487) | `core/libs/prx/libkernel/Pthread/include/Pthread.hpp` [L142](https://github.com/boykopovar/AnyPS5/blob/ea4cc112a04e6144740756bcd6494bbab5377331/core/libs/prx/libkernel/Pthread/include/Pthread.hpp#L142)<br>`core/libs/prx/libkernel/Pthread/src/Thread.cpp` [L792-793](https://github.com/boykopovar/AnyPS5/blob/ea4cc112a04e6144740756bcd6494bbab5377331/core/libs/prx/libkernel/Pthread/src/Thread.cpp#L792-L793), [L811-812](https://github.com/boykopovar/AnyPS5/blob/ea4cc112a04e6144740756bcd6494bbab5377331/core/libs/prx/libkernel/Pthread/src/Thread.cpp#L811-L812)<br>`docs/dev/debt/libkernel.md` [L146](https://github.com/boykopovar/AnyPS5/blob/ea4cc112a04e6144740756bcd6494bbab5377331/docs/dev/debt/libkernel.md#L146) | | | Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap. | Pull request | Shared files not compared | |---|---| | [PR 3986](https://www.github.com/boykopovar/AnyPS5/pull/3986) | `core/libs/prx/libkernel/Pthread/src/Thread.cpp` | | [PR 4972](https://www.github.com/boykopovar/AnyPS5/pull/4972) | `core/libs/prx/libkernel/CMakeLists.txt` | | [PR 5021](https://www.github.com/boykopovar/AnyPS5/pull/5021) | `core/libs/prx/libkernel/CMakeLists.txt`<br>`core/libs/prx/libkernel/Pthread/include/Pthread.hpp`<br>`core/libs/prx/libkernel/Pthread/src/Thread.cpp`<br>`docs/dev/debt/libkernel.md` | | [PR 5280](https://www.github.com/boykopovar/AnyPS5/pull/5280) | `core/libs/prx/libkernel/CMakeLists.txt`<br>`docs/dev/debt/libkernel.md` | | [PR 5993](https://www.github.com/boykopovar/AnyPS5/pull/5993) | `core/libs/prx/libkernel/CMakeLists.txt`<br>`docs/dev/debt/libkernel.md` | | [PR 6044](https://www.github.com/boykopovar/AnyPS5/pull/6044) | `core/libs/prx/libkernel/CMakeLists.txt`<br>`core/libs/tests/GuestPthreadGetname.cpp` | | [PR 6222](https://www.github.com/boykopovar/AnyPS5/pull/6222) | `core/libs/prx/libkernel/CMakeLists.txt`<br>`core/libs/prx/libkernel/Pthread/include/Pthread.hpp`<br>`core/libs/prx/libkernel/Pthread/src/Thread.cpp`<br>`docs/dev/debt/libkernel.md` | | [PR 6228](https://www.github.com/boykopovar/AnyPS5/pull/6228) | `docs/dev/debt/libkernel.md` | | [PR 6447](https://www.github.com/boykopovar/AnyPS5/pull/6447) | `core/libs/prx/libkernel/Pthread/Posix/Thread.cpp` | | [PR 6510](https://www.github.com/boykopovar/AnyPS5/pull/6510) | `docs/dev/debt/libkernel.md` | | [PR 6519](https://www.github.com/boykopovar/AnyPS5/pull/6519) | `docs/dev/debt/libkernel.md` | | [PR 6658](https://www.github.com/boykopovar/AnyPS5/pull/6658) | `core/libs/prx/libkernel/CMakeLists.txt`<br>`docs/dev/debt/libkernel.md` | | [PR 6710](https://www.github.com/boykopovar/AnyPS5/pull/6710) | `docs/dev/debt/libkernel.md` | | [PR 6836](https://www.github.com/boykopovar/AnyPS5/pull/6836) | `docs/dev/debt/libkernel.md` | | [PR 6879](https://www.github.com/boykopovar/AnyPS5/pull/6879) | `core/libs/prx/libkernel/Pthread/src/Thread.cpp` |
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!4533
No description provided.