feat(libc): implement _Thrd_detach #8636

Merged
cadenasynyster merged 2 commits from upstream-pr/8636 into main 2026-10-21 00:11:55 +00:00
cadenasynyster commented 2026-10-20 19:34:52 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by cadenasynyster on 2026-10-20T19:34:52Z.


What

Implements _Thrd_detach in libc. Like _Thrd_join, it calls the pthread_detach that libkernel registers on load (RegisterPthreadDetach_nid_no_patch, set from RegisterPthreadOnLoad), so libc still does not link libkernel. It returns _Thrd_success (0) on success and _Thrd_error (4) when pthread_detach fails, and throws std::runtime_error if none is registered. _Thrd_id is left as the existing throwing stub.

The debt note for [std::_Pad, _Thrd_join, _Thrd_detach, _Thrd_id] in docs/dev/debt/libc.md is updated to cover _Thrd_detach.

Tested

  • Windows 11, WinLibs GCC 15.2.0 r7, Release, base main 434e965d4.
  • guest_libc_threads passes with a new PadDetach case: unregistered throws; registered, a launched pad detaches with success and nullptr returns 4.
  • ctest -R "thread|Thrd|ampr|pthread|libc_": 60/60 pass.
  • python tools\check_conventions.py --base origin/main passes.
  • Animal Well (PPSA22520 01.000.011, plain ELF eboot.bin), relinked with --windows and run with APS5_PLAYGO_UNLISTED_CHUNKS=installed: on main the only unresolved import is L7f7zYwBvZA (_Thrd_detach) from libc.prx (FAIL: unresolved ELF import). With this PR there are no unresolved imports and the title runs until _Thrd_id_nid_postfix not implemented.
  • _Thrd_id is deliberately not touched: its return type and width on the console are not known.
  • Not run: Linux, macOS. The GPU was not exercised (RTX 5070 Ti). One unrelated AGC test target fails to compile in my full build; this patch touches no AGC file, and I did not check it on clean main.

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
  • New third-party code is a submodule built from source (none added)
  • Generic behaviour, not specific to one title
  • Depends on: none (#8148 is merged)
  • Fixes: none
  • Unblocks: Animal Well PPSA22520 (loader)
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4941344083 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8636). Originally posted by [cadenasynyster](https://github.com/cadenasynyster) on 2026-10-20T19:34:52Z. --- ### What Implements `_Thrd_detach` in libc. Like `_Thrd_join`, it calls the `pthread_detach` that libkernel registers on load (`RegisterPthreadDetach_nid_no_patch`, set from `RegisterPthreadOnLoad`), so libc still does not link libkernel. It returns `_Thrd_success` (0) on success and `_Thrd_error` (4) when `pthread_detach` fails, and throws `std::runtime_error` if none is registered. `_Thrd_id` is left as the existing throwing stub. The debt note for `[std::_Pad, _Thrd_join, _Thrd_detach, _Thrd_id]` in `docs/dev/debt/libc.md` is updated to cover `_Thrd_detach`. ### Tested - Windows 11, WinLibs GCC 15.2.0 r7, Release, base main `434e965d4`. - `guest_libc_threads` passes with a new `PadDetach` case: unregistered throws; registered, a launched pad detaches with success and `nullptr` returns 4. - `ctest -R "thread|Thrd|ampr|pthread|libc_"`: 60/60 pass. - `python tools\check_conventions.py --base origin/main` passes. - Animal Well (PPSA22520 01.000.011, plain ELF `eboot.bin`), relinked with `--windows` and run with `APS5_PLAYGO_UNLISTED_CHUNKS=installed`: on main the only unresolved import is `L7f7zYwBvZA` (`_Thrd_detach`) from libc.prx (`FAIL: unresolved ELF import`). With this PR there are no unresolved imports and the title runs until `_Thrd_id_nid_postfix not implemented`. - `_Thrd_id` is deliberately not touched: its return type and width on the console are not known. - Not run: Linux, macOS. The GPU was not exercised (RTX 5070 Ti). One unrelated AGC test target fails to compile in my full build; this patch touches no AGC file, and I did not check it on clean main. ### 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 (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's technical debt file - [x] No notes, investigation `.md` files or images added to the repository - [x] New third-party code is a submodule built from source (none added) - [x] Generic behaviour, not specific to one title - [x] Depends on: none (#8148 is merged) - [x] Fixes: none - [x] Unblocks: Animal Well PPSA22520 (loader) - [x] GPUs tested: n/a - [x] AI-assisted: yes
MarcZX10 commented 2026-10-20 19:35:29 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-20T19:35:29Z.

Review: COMMENTED


The first trusted conventions run on head a8b6d1c reports three concrete issues: it cannot find the required ### What, ### Tested, and ### Checklist sections (the body uses ## headings), and the updated std::_Pad debt entry is 1136 characters, over the 1000-character limit. Please use the exact headings from .github/pull_request_template.md and shorten the debt entry while retaining the newly documented detach behavior. The author-reported Windows tests are useful, but the current Linux/macOS hosted jobs are still running; I have not independently run this patch.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5590620258 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8636#pullrequestreview-5590620258). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-20T19:35:29Z. **Review:** COMMENTED --- The first trusted conventions run on head `a8b6d1c` reports three concrete issues: it cannot find the required `### What`, `### Tested`, and `### Checklist` sections (the body uses `##` headings), and the updated `std::_Pad` debt entry is 1136 characters, over the 1000-character limit. Please use the exact headings from `.github/pull_request_template.md` and shorten the debt entry while retaining the newly documented detach behavior. The author-reported Windows tests are useful, but the current Linux/macOS hosted jobs are still running; I have not independently run this patch.
github-actions[bot] commented 2026-10-20 19:35:42 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-20T19:35:42Z.


Progress report (2185dbf → 9e6544f)

📈 System libraries: 64.47% (+0.01%, +1 implemented functions)

✅ 1 implemented
Library Name
libc _Thrd_detach_nid_postfix
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6299630836 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8636#issuecomment-6299630836). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-20T19:35:42Z. --- <!-- progress-report --> ### Progress report (2185dbf → 9e6544f) 📈 **System libraries**: 64.47% (+0.01%, +1 implemented functions) <details> <summary>✅ 1 implemented</summary> | Library | Name | | - | - | | libc | `_Thrd_detach_nid_postfix` | </details>
Filip722 commented 2026-10-20 19:49:32 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Filip722 on 2026-10-20T19:49:32Z.


Independent Linux testing of head 9e6544fbab366d5c83a197d4279c7a693c8a620c:

  • Debian 13.7 x86-64, Linux 7.2.9-x64v3-xanmod1, AMD Ryzen 5 7640HS, GCC 15.2.0.
  • Release, BUILD_TESTING=ON, ANYPS5_RELINKER_ONLY=OFF, bundled dependencies. Built libc, libkernel and the seven focused test targets successfully.
  • 7/7 passed: guest_libc_threads (including the new PadDetach case), guest_ampr_threads, guest_pthread_join_detach, guest_pthread_second_join, guest_pthread_stack, guest_thread_self, and guest_thread_callback_abi.
ctest --test-dir build -R '^guest_(libc_threads|ampr_threads|pthread_join_detach|pthread_second_join|pthread_stack|thread_self|thread_callback_abi)$' -V

I also ran a standalone integration check against the freshly built, unpatched Linux libc/libkernel libraries, without replacing or manually registering the callbacks. It created a real guest thread with scePthreadCreate, kept it alive while checking the results, then released it:

_Thrd_detach(thread)                    = 0
_Thrd_detach(already_detached_thread)   = 4
_Thrd_join(detached_thread, nullptr)    = 4
_Thrd_detach(nullptr)                  = 4
detached worker completed

This additionally exercises libkernel's load-time registration of pthread_detach, which the new PadDetach test replaces with its host helper. python3 tools/check_conventions.py --base origin/main also passed.

Focused Linux runtime testing only; the full test suite and Animal Well were not run, and console ABI behavior was not verified.

AI-assisted: yes.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6299991837 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8636#issuecomment-6299991837). Originally posted by [Filip722](https://github.com/Filip722) on 2026-10-20T19:49:32Z. --- Independent Linux testing of head `9e6544fbab366d5c83a197d4279c7a693c8a620c`: - Debian 13.7 x86-64, Linux `7.2.9-x64v3-xanmod1`, AMD Ryzen 5 7640HS, GCC 15.2.0. - Release, `BUILD_TESTING=ON`, `ANYPS5_RELINKER_ONLY=OFF`, bundled dependencies. Built libc, libkernel and the seven focused test targets successfully. - **7/7 passed**: `guest_libc_threads` (including the new `PadDetach` case), `guest_ampr_threads`, `guest_pthread_join_detach`, `guest_pthread_second_join`, `guest_pthread_stack`, `guest_thread_self`, and `guest_thread_callback_abi`. ```sh ctest --test-dir build -R '^guest_(libc_threads|ampr_threads|pthread_join_detach|pthread_second_join|pthread_stack|thread_self|thread_callback_abi)$' -V ``` I also ran a standalone integration check against the freshly built, unpatched Linux libc/libkernel libraries, without replacing or manually registering the callbacks. It created a real guest thread with `scePthreadCreate`, kept it alive while checking the results, then released it: ```text _Thrd_detach(thread) = 0 _Thrd_detach(already_detached_thread) = 4 _Thrd_join(detached_thread, nullptr) = 4 _Thrd_detach(nullptr) = 4 detached worker completed ``` This additionally exercises libkernel's load-time registration of `pthread_detach`, which the new `PadDetach` test replaces with its host helper. `python3 tools/check_conventions.py --base origin/main` also passed. Focused Linux runtime testing only; the full test suite and Animal Well were not run, and console ABI behavior was not verified. AI-assisted: yes.
github-actions[bot] commented 2026-10-20 19:51:53 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-20T19:51:53Z.


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 6565 docs/dev/debt/libc.md L130
PR 8352 core/libs/tests/GuestLibcThreads.cpp L34, L271, L278

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 1835 core/libs/prx/libc/src/Threads.cpp
PR 5021 core/libs/prx/libc/src/Threads.cpp
docs/dev/debt/libc.md
PR 6044 core/libs/tests/GuestLibcThreads.cpp
PR 6226 docs/dev/debt/libc.md
PR 6469 docs/dev/debt/libc.md
PR 6819 docs/dev/debt/libc.md
PR 7081 docs/dev/debt/libc.md
PR 7201 core/libs/prx/libc/src/Threads.cpp
PR 7648 docs/dev/debt/libc.md
PR 7715 docs/dev/debt/libc.md
PR 8150 docs/dev/debt/libc.md
PR 8520 docs/dev/debt/libc.md
PR 8550 docs/dev/debt/libc.md
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6300044584 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8636#issuecomment-6300044584). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-20T19:51:53Z. --- <!-- 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 6565](https://www.github.com/boykopovar/AnyPS5/pull/6565) | `docs/dev/debt/libc.md` [L130](https://github.com/boykopovar/AnyPS5/blob/5b59fbc5539b6c6db7a26972f6069f1c6cc179ac/docs/dev/debt/libc.md#L130) | | | | [PR 8352](https://www.github.com/boykopovar/AnyPS5/pull/8352) | `core/libs/tests/GuestLibcThreads.cpp` [L34](https://github.com/boykopovar/AnyPS5/blob/5b59fbc5539b6c6db7a26972f6069f1c6cc179ac/core/libs/tests/GuestLibcThreads.cpp#L34), [L271](https://github.com/boykopovar/AnyPS5/blob/5b59fbc5539b6c6db7a26972f6069f1c6cc179ac/core/libs/tests/GuestLibcThreads.cpp#L271), [L278](https://github.com/boykopovar/AnyPS5/blob/5b59fbc5539b6c6db7a26972f6069f1c6cc179ac/core/libs/tests/GuestLibcThreads.cpp#L278) | | | 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 1835](https://www.github.com/boykopovar/AnyPS5/pull/1835) | `core/libs/prx/libc/src/Threads.cpp` | | [PR 5021](https://www.github.com/boykopovar/AnyPS5/pull/5021) | `core/libs/prx/libc/src/Threads.cpp`<br>`docs/dev/debt/libc.md` | | [PR 6044](https://www.github.com/boykopovar/AnyPS5/pull/6044) | `core/libs/tests/GuestLibcThreads.cpp` | | [PR 6226](https://www.github.com/boykopovar/AnyPS5/pull/6226) | `docs/dev/debt/libc.md` | | [PR 6469](https://www.github.com/boykopovar/AnyPS5/pull/6469) | `docs/dev/debt/libc.md` | | [PR 6819](https://www.github.com/boykopovar/AnyPS5/pull/6819) | `docs/dev/debt/libc.md` | | [PR 7081](https://www.github.com/boykopovar/AnyPS5/pull/7081) | `docs/dev/debt/libc.md` | | [PR 7201](https://www.github.com/boykopovar/AnyPS5/pull/7201) | `core/libs/prx/libc/src/Threads.cpp` | | [PR 7648](https://www.github.com/boykopovar/AnyPS5/pull/7648) | `docs/dev/debt/libc.md` | | [PR 7715](https://www.github.com/boykopovar/AnyPS5/pull/7715) | `docs/dev/debt/libc.md` | | [PR 8150](https://www.github.com/boykopovar/AnyPS5/pull/8150) | `docs/dev/debt/libc.md` | | [PR 8520](https://www.github.com/boykopovar/AnyPS5/pull/8520) | `docs/dev/debt/libc.md` | | [PR 8550](https://www.github.com/boykopovar/AnyPS5/pull/8550) | `docs/dev/debt/libc.md` |
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!8636
No description provided.