feat(libc): register conditions for broadcast at thread exit #10615

Merged
edubox merged 4 commits from upstream-pr/10615 into main 2026-11-02 10:23:19 +00:00
edubox commented 2026-10-24 13:04:55 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by edubox on 2026-10-24T13:04:55Z.


What

Export _Cnd_register_at_thread_exit (DV2AdZFFEh8), _Cnd_unregister_at_thread_exit (wpuIiVoCWcM) and _Cnd_do_broadcast_at_thread_exit (vyLotuB6AS4), which implement std::notify_all_at_thread_exit.

Minecraft Legends (PPSA05510) and Rayman 30th (PPSA33016) import the first two from libc.prx; libc exported neither and the loader refused them.

Registrations live in a process-wide list keyed by the host thread id, following Microsoft's xnotify.cpp: registering validates both handles and allocates the registrant's node, unregistering drops every slot that holds the mutex, and the broadcast of the current thread sets the supplied flag to 1, broadcasts the condition and unlocks the mutex, in that order. The exit path splices the current thread's nodes out of the shared list, so it neither allocates nor throws, and the export is noexcept, as Microsoft's is. The broadcast runs when a std::thread exits through _Pad::_Launch and when a title calls _Thrd_exit; threads created directly with scePthreadCreate are recorded in the debt file.

The handles are passed by value, following the modern UCRT signature. docs/dev/debt/libc.md keeps the gaps that remain: that signature is not verified against the console, and a direct scePthreadCreate thread that returns without _Thrd_exit never broadcasts. The same entry previously listed the broadcast as missing from _Pad::_Launch; that sentence is removed.

#9498 declares the same three names as throwing stubs in libSceLibcInternal, which is a separate library kept for titles that import from it, so neither change replaces the other. This one implements them in libc.prx, the library these two titles import from.

#10648 adds the three-argument _Pad::_Launch overload in the same Threads.cpp block and touches the same debt entry. Preferred landing order is #10648 first, then this PR rebases onto it and keeps both the attribute forwarding and the thread-exit broadcast; if this PR lands first instead, #10648 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 0ea0f25e1b.

  • guest_cnd_at_thread_exit passes: a null condition, mutex or unregister handle throws; a registration that is unregistered does not set the flag and does not unlock the mutex; a registered worker wakes a waiting thread and sets the flag; and the _Pad::_Launch exit path wakes the waiter of a thread that registered and returned.
  • BroadcastDoesNotAllocate passes with the test's global operator new failing during the broadcast, so the thread-exit path neither allocates nor throws.
  • guest_libc_threads still passes.
  • The patched libc.prx exports DV2AdZFFEh8, wpuIiVoCWcM and vyLotuB6AS4 (nm -D).
  • Not tested with a title.

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
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4995631758 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10615). Originally posted by [edubox](https://github.com/edubox) on 2026-10-24T13:04:55Z. --- ### What Export `_Cnd_register_at_thread_exit` (`DV2AdZFFEh8`), `_Cnd_unregister_at_thread_exit` (`wpuIiVoCWcM`) and `_Cnd_do_broadcast_at_thread_exit` (`vyLotuB6AS4`), which implement `std::notify_all_at_thread_exit`. Minecraft Legends (PPSA05510) and Rayman 30th (PPSA33016) import the first two from `libc.prx`; libc exported neither and the loader refused them. Registrations live in a process-wide list keyed by the host thread id, following Microsoft's `xnotify.cpp`: registering validates both handles and allocates the registrant's node, unregistering drops every slot that holds the mutex, and the broadcast of the current thread sets the supplied flag to 1, broadcasts the condition and unlocks the mutex, in that order. The exit path splices the current thread's nodes out of the shared list, so it neither allocates nor throws, and the export is `noexcept`, as Microsoft's is. The broadcast runs when a `std::thread` exits through `_Pad::_Launch` and when a title calls `_Thrd_exit`; threads created directly with `scePthreadCreate` are recorded in the debt file. The handles are passed by value, following the modern UCRT signature. `docs/dev/debt/libc.md` keeps the gaps that remain: that signature is not verified against the console, and a direct `scePthreadCreate` thread that returns without `_Thrd_exit` never broadcasts. The same entry previously listed the broadcast as missing from `_Pad::_Launch`; that sentence is removed. `#9498` declares the same three names as throwing stubs in `libSceLibcInternal`, which is a separate library kept for titles that import from it, so neither change replaces the other. This one implements them in `libc.prx`, the library these two titles import from. `#10648` adds the three-argument `_Pad::_Launch` overload in the same `Threads.cpp` block and touches the same debt entry. Preferred landing order is `#10648` first, then this PR rebases onto it and keeps both the attribute forwarding and the thread-exit broadcast; if this PR lands first instead, `#10648` 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` `0ea0f25e1b`. - `guest_cnd_at_thread_exit` passes: a null condition, mutex or unregister handle throws; a registration that is unregistered does not set the flag and does not unlock the mutex; a registered worker wakes a waiting thread and sets the flag; and the `_Pad::_Launch` exit path wakes the waiter of a thread that registered and returned. - `BroadcastDoesNotAllocate` passes with the test's global `operator new` failing during the broadcast, so the thread-exit path neither allocates nor throws. - `guest_libc_threads` still passes. - The patched `libc.prx` exports `DV2AdZFFEh8`, `wpuIiVoCWcM` and `vyLotuB6AS4` (`nm -D`). - Not tested with a title. ### 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 - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes
MarcZX10 commented 2026-10-24 13:08:55 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-24T13:08:55Z.

Review: CHANGES_REQUESTED


The focused source and test translation units compile cleanly with GCC 12.2 (-std=c++20 -Wall -Wextra -fsyntax-only). I found one blocking allocation-failure path in the thread-exit cleanup; see the inline comment.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5638358003 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10615#pullrequestreview-5638358003). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-24T13:08:55Z. **Review:** CHANGES_REQUESTED --- The focused source and test translation units compile cleanly with GCC 12.2 (`-std=c++20 -Wall -Wextra -fsyntax-only`). I found one blocking allocation-failure path in the thread-exit cleanup; see the inline comment.
MarcZX10 commented 2026-10-24 19:47:30 +00:00 (Migrated from github.com)

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

Review: APPROVED


Re-reviewed exact head f281dbe807ef32f7566c9a2205d69c2620ad1d41. The previous thread-exit blocker is resolved: broadcast splices the current thread's nodes into a local list while holding the lock, then performs the notifications without allocating. The regression forces allocation failure during broadcast, and the new _Pad::_Launch test covers the exit path. The current implementation also matches Microsoft's xnotify.cpp behavior of unregistering all pending entries for the supplied mutex. Local syntax compilation, diff-check and conventions pass; hosted checks pass. I did not run the focused library tests locally because this checkout lacks initialized submodules; the author reports both focused tests passing on the updated branch. The stated landing order with the companion _Pad::_Launch change is clear.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5639693001 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10615#pullrequestreview-5639693001). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-24T19:47:30Z. **Review:** APPROVED --- Re-reviewed exact head `f281dbe807ef32f7566c9a2205d69c2620ad1d41`. The previous thread-exit blocker is resolved: broadcast splices the current thread's nodes into a local list while holding the lock, then performs the notifications without allocating. The regression forces allocation failure during broadcast, and the new `_Pad::_Launch` test covers the exit path. The current implementation also matches Microsoft's `xnotify.cpp` behavior of unregistering all pending entries for the supplied mutex. Local syntax compilation, diff-check and conventions pass; hosted checks pass. I did not run the focused library tests locally because this checkout lacks initialized submodules; the author reports both focused tests passing on the updated branch. The stated landing order with the companion `_Pad::_Launch` change is clear.
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!10615
No description provided.