Skip to content

feat(libc): export the std::__sce_v2 at-thread-exit registry calls - #15879

Open
Danigamer05 wants to merge 1 commit into
boykopovar:mainfrom
Danigamer05:feat/libc-sce-v2-at-thread-exit-20261104
Open

Danigamer05 wants to merge 1 commit into
boykopovar:mainfrom
Danigamer05:feat/libc-sce-v2-at-thread-exit-20261104

Conversation

@Danigamer05

Copy link
Copy Markdown
Contributor

What

Export the versioned std::__sce_v2 at-thread-exit calls from libc.

Export NID Original RVA
_ZNSt8__sce_v228_Cnd_register_at_thread_exitEPP12pthread_condPP13pthread_mutexPi +fAmL52-yfQ 0x10AE00
_ZNSt8__sce_v230_Cnd_unregister_at_thread_exitEPP13pthread_mutex SwcNvp-Af6c 0x10B110
_ZNSt8__sce_v232_Cnd_do_broadcast_at_thread_exitEv 2s6aLdPIA4I 0x10B1C0
_ZNSt8__sce_v226_Lock_at_thread_exit_mutexEv 2qvjaae0N-M 0x10ADB0
_ZNSt8__sce_v228_Unlock_at_thread_exit_mutexEv hx11Xia3FSY 0x10ADE0

The behavior comes from the libc.prx bundled with PPSA03671 v01.001.005 (J03848509, SHA-256 483961e086b8a1fffa8138b3c0badf798987fb5f35ec908d828946408be2d8a6).

These back std::notify_all_at_thread_exit and the promise ..._at_thread_exit calls. They take the versioned handles (pthread_cond**, pthread_mutex**) and use main's versioned _Mtx_*, _Cnd_broadcast, _Thrd_id and _Throw_Cpp_error. As in the module:

  • the entries (thread id, mutex, condition, flag) live in blocks of 20 with a count and a next pointer, laid out as the module's 0x290-byte block. A full block gets a new one from calloc, and an allocation failure drops the entry;
  • every call holds a recursive mutex named SceLibc_V2AtThreadExit (type 0x102), which _Lock_at_thread_exit_mutex and _Unlock_at_thread_exit_mutex take and release. A failed lock throws through _Throw_Cpp_error(5);
  • registering stores the entry in the first free slot and leaves the caller's mutex as it is;
  • unregistering removes every entry of the mutex;
  • a broadcast handles only the calling thread's entries. An entry with a flag relocks the mutex and sets the flag; every entry then broadcasts the condition, unlocks the mutex and is removed. An entry without a flag thus releases the lock that notify_all_at_thread_exit left held.

Nothing in the module calls the broadcast when a thread ends: as in Dinkumware's std::thread, the title's own thread code calls _Cnd_do_broadcast_at_thread_exit after the thread function returns, so nothing here adds a thread-exit hook. The module creates its mutex when it loads; here it is created on first use. The debt entry records both.

Tested

Windows x86-64, WinLibs GCC 15.2.0, Release, BUILD_TESTING=ON, main b611e634f7f. Exact tested commit: 5880453e377.

Not tested: Linux, macOS, another SDK, a game, GPU or console. No game compatibility claim. No original module, extracted bytes, harness or log is committed or uploaded.

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

🤖 Generated with Claude Code

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@JJenkx

JJenkx commented Nov 4, 2026

Copy link
Copy Markdown
Contributor

Windows check of head 5880453e37, merged onto main c3a5290c7d (fefc0bb918, clean merge).

Setup: Windows 11 Enterprise 22621, WinLibs GCC 15.2 UCRT, Release. The hosted Windows check does not run this test on pull requests.

  • guest_sce_v2_at_thread_exit passes in 3 of 3 runs.

AI-assisted: yes.

@github-actions

github-actions Bot commented Nov 4, 2026

Copy link
Copy Markdown

Progress report (b611e63 → 5880453)

📈 System libraries: 26.7% (+0.01%, +5 implemented functions)

✅ 5 implemented
Library Name
libc _ZNSt8__sce_v226_Lock_at_thread_exit_mutexEv_nid_postfix
libc _ZNSt8__sce_v228_Cnd_register_at_thread_exitEPP12pthread_condPP13pthread_mutexPi_nid_postfix
libc _ZNSt8__sce_v228_Unlock_at_thread_exit_mutexEv_nid_postfix
libc _ZNSt8__sce_v230_Cnd_unregister_at_thread_exitEPP13pthread_mutex_nid_postfix
libc _ZNSt8__sce_v232_Cnd_do_broadcast_at_thread_exitEv_nid_postfix

Changed libraries (implemented exports)

Library Before After Change
libc 1629/1648 (98.85%) 1634/1653 (98.85%) +0.0035%

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants