feat(libc): forward pthread attributes in _Pad::_Launch #10648

Merged
edubox merged 1 commit from upstream-pr/10648 into main 2026-10-25 21:42:59 +00:00
edubox commented 2026-10-24 15:02:05 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by edubox on 2026-10-24T15:02:05Z.


What

Export _ZNSt4_Pad7_LaunchEPP12pthread_attrPP7pthread (fLBZMOQh-3Y), the three-argument std::_Pad::_Launch(pthread_attr_t**, pthread_t**) overload.

Minecraft Legends (PPSA05510) imports it from libc.prx; libc only exported the two-argument form (_ZNSt4_Pad7_LaunchEPP7pthread, xZqiZvmcp9k), so the loader refused the title at this symbol.

Both forms now share LaunchPad_nid_no_patch: the existing two-argument entry passes nullptr for the attributes, and the new one forwards the caller's attribute pointer to the pthread_create registered by libkernel. The behaviour after creation is unchanged: a failed thread start throws the guest std::system_error, and the call waits for _Pad::_Release with _Cnd_wait.

The console's libc.prx shipped with PPSA02530 exports the same NID at 0x18090 and does the same: it forwards the caller's attribute pointer to the thread-create path and then waits for the pad's started flag. docs/dev/debt/libc.md records that the three-argument form is now checked against that library.

The console's three-argument _Pad::_Launch at 0x18090 forwards its second parameter untouched: 0x4be0 receives it in rcx and passes it as the fifth argument to 0x4a10, and 0x4a89 passes that same pointer as the second argument of the thread-create call at 0x116590 after 0x116580 reads the attribute slot. That slot address is what pthread_create expects: pthread_attr_t is a pointer typedef, so the source-level pthread_attr_t* has the machine type void**, and PthreadCreateFn's const void* is the same machine value. The test now names it attrSlot and asserts that the slot address reaches the callback.

#10615 (open) changes the same Threads.cpp block to add _Cnd_do_broadcast_at_thread_exit to the two-argument launch path. The changes are independent and the conflict is a textual hunk; no export is duplicated. pr_overlap reports only that shared hunk and docs/dev/debt/libc.md:161, which several PRs also edit. Preferred landing order is this PR first, then #10615 rebases onto it and keeps both the attribute forwarding and the thread-exit broadcast; if #10615 lands first instead, this PR rebases and keeps both. There is no code dependency either way.

Tested

CachyOS Linux 7.3.0-3, Ryzen 9 9900X, GCC 16.2.1, main 2fade7ef4e.

  • guest_libc_threads passes with the new PadLaunchWithAttributes case: the attribute pointer reaches the registered pthread_create, the two-argument form still passes nullptr, the pad is released, the worker runs, and _Thrd_join returns 42.
  • The patched libc.prx exports fLBZMOQh-3Y and still exports xZqiZvmcp9k (nm -D).
  • Not tested with a title. This removes one of the 24 libc imports PPSA05510 needs; the title still stops on the next one.

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 (landing order: this PR first, then #10615 rebases; both behaviours are kept either way)
  • Fixes: none
  • Unblocks: none (removes one of the 24 libc imports PPSA05510 needs; it still stops on the next one)
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4996482032 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10648). Originally posted by [edubox](https://github.com/edubox) on 2026-10-24T15:02:05Z. --- ### What Export `_ZNSt4_Pad7_LaunchEPP12pthread_attrPP7pthread` (`fLBZMOQh-3Y`), the three-argument `std::_Pad::_Launch(pthread_attr_t**, pthread_t**)` overload. Minecraft Legends (PPSA05510) imports it from `libc.prx`; libc only exported the two-argument form (`_ZNSt4_Pad7_LaunchEPP7pthread`, `xZqiZvmcp9k`), so the loader refused the title at this symbol. Both forms now share `LaunchPad_nid_no_patch`: the existing two-argument entry passes `nullptr` for the attributes, and the new one forwards the caller's attribute pointer to the `pthread_create` registered by libkernel. The behaviour after creation is unchanged: a failed thread start throws the guest `std::system_error`, and the call waits for `_Pad::_Release` with `_Cnd_wait`. The console's `libc.prx` shipped with PPSA02530 exports the same NID at `0x18090` and does the same: it forwards the caller's attribute pointer to the thread-create path and then waits for the pad's started flag. `docs/dev/debt/libc.md` records that the three-argument form is now checked against that library. The console's three-argument `_Pad::_Launch` at `0x18090` forwards its second parameter untouched: `0x4be0` receives it in `rcx` and passes it as the fifth argument to `0x4a10`, and `0x4a89` passes that same pointer as the second argument of the thread-create call at `0x116590` after `0x116580` reads the attribute slot. That slot address is what `pthread_create` expects: `pthread_attr_t` is a pointer typedef, so the source-level `pthread_attr_t*` has the machine type `void**`, and `PthreadCreateFn`'s `const void*` is the same machine value. The test now names it `attrSlot` and asserts that the slot address reaches the callback. `#10615` (open) changes the same `Threads.cpp` block to add `_Cnd_do_broadcast_at_thread_exit` to the two-argument launch path. The changes are independent and the conflict is a textual hunk; no export is duplicated. `pr_overlap` reports only that shared hunk and `docs/dev/debt/libc.md:161`, which several PRs also edit. Preferred landing order is this PR first, then `#10615` rebases onto it and keeps both the attribute forwarding and the thread-exit broadcast; if `#10615` lands first instead, this PR rebases and keeps both. There is no code dependency either way. ### Tested CachyOS Linux 7.3.0-3, Ryzen 9 9900X, GCC 16.2.1, `main` `2fade7ef4e`. - `guest_libc_threads` passes with the new `PadLaunchWithAttributes` case: the attribute pointer reaches the registered `pthread_create`, the two-argument form still passes `nullptr`, the pad is released, the worker runs, and `_Thrd_join` returns 42. - The patched `libc.prx` exports `fLBZMOQh-3Y` and still exports `xZqiZvmcp9k` (`nm -D`). - Not tested with a title. This removes one of the 24 libc imports PPSA05510 needs; the title still stops on the next one. ### 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](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 (landing order: this PR first, then #10615 rebases; both behaviours are kept either way) - [x] Fixes: none - [x] Unblocks: none (removes one of the 24 libc imports PPSA05510 needs; it still stops on the next one) - [x] GPUs tested: n/a - [x] AI-assisted: yes
MarcZX10 commented 2026-10-24 15:02:54 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-24T15:02:54Z.

Review: COMMENTED


Reviewed exact head 46e762462d4eb3320de86ded241f4ab2dbf49f6a. The shared helper preserves the existing two-argument launch behavior by passing nullptr, and the new overload forwards the attribute pointer to the registered pthread_create; the test checks both paths. The report also cites the matching three-argument export and forwarding behavior in PPSA02530. Hosted CI is still running, so I have not completed the review. One coordination detail remains: the PR body acknowledges overlapping hunks and the debt entry with #10615, but does not record which PR lands first or the corresponding Depends on: #N order required by the repository checklist. Please agree the order with the other PR (both are yours) and record it here; the combined change must retain both the thread-exit broadcast and attribute forwarding.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5638703366 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10648#pullrequestreview-5638703366). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-24T15:02:54Z. **Review:** COMMENTED --- Reviewed exact head `46e762462d4eb3320de86ded241f4ab2dbf49f6a`. The shared helper preserves the existing two-argument launch behavior by passing `nullptr`, and the new overload forwards the attribute pointer to the registered `pthread_create`; the test checks both paths. The report also cites the matching three-argument export and forwarding behavior in PPSA02530. Hosted CI is still running, so I have not completed the review. One coordination detail remains: the PR body acknowledges overlapping hunks and the debt entry with #10615, but does not record which PR lands first or the corresponding `Depends on: #N` order required by the repository checklist. Please agree the order with the other PR (both are yours) and record it here; the combined change must retain both the thread-exit broadcast and attribute forwarding.
MarcZX10 commented 2026-10-24 15:53:53 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-24T15:53:53Z.

Review: CHANGES_REQUESTED


The landing-order checklist is now clear and hosted checks have completed. I found one remaining ABI question in the new forwarding path. The export name demangles to _Pad::_Launch(pthread_attr_t**, pthread_t**), while PthreadCreateFn_nid_no_patch (and the registered pthread_create_nid_postfix) accepts const pthread_attr_t* by value. At line 479, attr is the address of the guest attribute-pointer slot, so passing attr forwards that slot address; ordinarily pthread_create needs the value stored in *attr (with null handling based on the console contract). The new test currently asserts lastCreateAttr == &attr, which confirms the slot address rather than the pointed-to attribute object. Could you verify the actual load/argument at PPSA02530 offset 0x18090 or another caller/disassembly and align implementation and test with it? If the console really passes the slot address to a non-POSIX intermediate wrapper, please include that intermediate signature/evidence so this mapping is justified.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5638856561 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10648#pullrequestreview-5638856561). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-24T15:53:53Z. **Review:** CHANGES_REQUESTED --- The landing-order checklist is now clear and hosted checks have completed. I found one remaining ABI question in the new forwarding path. The export name demangles to `_Pad::_Launch(pthread_attr_t**, pthread_t**)`, while `PthreadCreateFn_nid_no_patch` (and the registered `pthread_create_nid_postfix`) accepts `const pthread_attr_t*` by value. At line 479, `attr` is the address of the guest attribute-pointer slot, so passing `attr` forwards that slot address; ordinarily `pthread_create` needs the value stored in `*attr` (with null handling based on the console contract). The new test currently asserts `lastCreateAttr == &attr`, which confirms the slot address rather than the pointed-to attribute object. Could you verify the actual load/argument at PPSA02530 offset 0x18090 or another caller/disassembly and align implementation and test with it? If the console really passes the slot address to a non-POSIX intermediate wrapper, please include that intermediate signature/evidence so this mapping is justified.
MarcZX10 commented 2026-10-24 19:45:49 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-24T19:45:49Z.

Review: APPROVED


Reviewed exact head 769d628c6fab6e088d2ecc0553f61ea79069a22a. The added overload matches the console call sequence cited at libc.prx offset 0x18090: it forwards the attribute-slot address to the registered thread-create callback. The regression checks that forwarding and confirms the existing two-argument overload still passes null. The earlier ABI concern is resolved by the added disassembly evidence and the clarified test. Conventions and diff checks pass; hosted relinker, register-context, ASan and write-watch checks pass. I did not run the full library test locally because this review checkout has no initialized submodules; the author reports guest_libc_threads passing on the PR head.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5639687987 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10648#pullrequestreview-5639687987). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-24T19:45:49Z. **Review:** APPROVED --- Reviewed exact head `769d628c6fab6e088d2ecc0553f61ea79069a22a`. The added overload matches the console call sequence cited at `libc.prx` offset `0x18090`: it forwards the attribute-slot address to the registered thread-create callback. The regression checks that forwarding and confirms the existing two-argument overload still passes null. The earlier ABI concern is resolved by the added disassembly evidence and the clarified test. Conventions and diff checks pass; hosted relinker, register-context, ASan and write-watch checks pass. I did not run the full library test locally because this review checkout has no initialized submodules; the author reports `guest_libc_threads` passing on the PR head.
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!10648
No description provided.