feat(libc): register conditions for broadcast at thread exit #10615
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/10615"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
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 implementstd::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 isnoexcept, as Microsoft's is. The broadcast runs when astd::threadexits through_Pad::_Launchand when a title calls_Thrd_exit; threads created directly withscePthreadCreateare recorded in the debt file.The handles are passed by value, following the modern UCRT signature.
docs/dev/debt/libc.mdkeeps the gaps that remain: that signature is not verified against the console, and a directscePthreadCreatethread that returns without_Thrd_exitnever broadcasts. The same entry previously listed the broadcast as missing from_Pad::_Launch; that sentence is removed.#9498declares the same three names as throwing stubs inlibSceLibcInternal, which is a separate library kept for titles that import from it, so neither change replaces the other. This one implements them inlibc.prx, the library these two titles import from.#10648adds the three-argument_Pad::_Launchoverload in the sameThreads.cppblock and touches the same debt entry. Preferred landing order is#10648first, then this PR rebases onto it and keeps both the attribute forwarding and the thread-exit broadcast; if this PR lands first instead,#10648rebases and keeps both. There is no code dependency either way.Tested
CachyOS Linux 7.3.0-3, Ryzen 9 9900X, GCC 16.2.1,
main0ea0f25e1b.guest_cnd_at_thread_exitpasses: 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::_Launchexit path wakes the waiter of a thread that registered and returned.BroadcastDoesNotAllocatepasses with the test's globaloperator newfailing during the broadcast, so the thread-exit path neither allocates nor throws.guest_libc_threadsstill passes.libc.prxexportsDV2AdZFFEh8,wpuIiVoCWcMandvyLotuB6AS4(nm -D).Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)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.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::_Launchtest covers the exit path. The current implementation also matches Microsoft'sxnotify.cppbehavior 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::_Launchchange is clear.