feat(libc): forward the C11 thread and TSS calls to libkernel #8859
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/8859"
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 hypermoist on 2026-10-21T03:31:34Z.
What
Adds the Dinkumware C11 thread and thread-specific-storage entry points that libc still lacked. The evidence is the decrypted
libSceLibcInternal.sprx(PS5 12.00). Each export there is an 11-byte frame that calls one libkernel function and returns its result unchanged:_Call_once(fttiF7rDdak)scePthreadOnce_Tss_create(amHyU7v8f-A)scePthreadKeyCreate_Tss_delete(g5cG7QtKLTA)scePthreadKeyDelete_Tss_set(ibyFt0bPyTk)scePthreadSetspecific_Tss_get(lOVQnEJEzvY)scePthreadGetspecific_Thrd_equal(BnV7WrHdPLU)scePthreadEqual_Thrd_current(n2-b3O8qvqk)scePthreadSelf_Thrd_exit(cFsD9R4iY50)scePthreadExitwith the exit code zero-extended to a pointer_Mtx_current_owns(VYQwFs4CC4Y, 0x1b040) returns 1 whatever its argument, so it does the same here.The results are not translated to
thrd_*codes: the console returns the libkernel value as it is, for example0x80020016from_Tss_create. libc can't link libkernel, so libkernel hands libc a table of these eight functions at load, in the same constructor that #8148 added forpthread_create/pthread_join/pthread_detach. Each libc entry throws if nothing is registered.Not included:
_Thrd_yield: #8352 adds it._Mtx_timedlock: the console callsscePthreadMutexTimedlockon its own mutex objects, but this libc's_Mtx_*use their own mutex type._Thrd_create,_Thrd_start,_Thrd_abortand the_Cnd_*_at_thread_exitfamily: these have real bodies, not one-call forwards.Tested
Linux (CachyOS, GCC, Release): full build. All 539
guest_*, kernel and Ampr tests pass.guest_libc_threadsgains two parts:_Tss_create,_Tss_get,_Tss_set,_Tss_delete);_Mtx_current_owns, and the throw once the table is cleared._Thrd_exitis not called in the test because it does not return.tools/check_conventions.pyis clean, and there is no overlap with open pull requests.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)🤖 Generated with Claude Code
https://claude.ai/code/session_01RbLgECLQ2bpDM7oe2urGZK
Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-21T03:32:17Z.
Progress report (
27fabb6→58c9254)📈 System libraries: 48.95% (+0.05%, +9 implemented functions)
✅ 9 implemented
_Call_once_nid_postfix_Mtx_current_owns_nid_postfix_Thrd_current_nid_postfix_Thrd_equal_nid_postfix_Thrd_exit_nid_postfix_Tss_create_nid_postfix_Tss_delete_nid_postfix_Tss_get_nid_postfix_Tss_set_nid_postfix⚪ 1 behaviourally empty (constant return or throw)
_Mtx_current_owns_nid_postfixImported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-21T03:42:42Z.
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.
main)core/libs/tests/GuestLibcThreads.cppL36, L301-302Some 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.
core/libs/prx/libc/src/Threads.cppcore/libs/prx/libc/src/Threads.cppcore/libs/tests/GuestLibcThreads.cppcore/libs/prx/libc/src/Threads.cppImported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-21T10:42:21Z.
@hypermoist thanks. The thread test fails on Windows in CI run 39581680886 (Linux passes):
0xc0000409is a fail-fast abort (anabort(), an invalid-parameter handler or a stack-buffer check). Since this PR changesThreads.cppandThread.cppalong withGuestLibcThreads.cpp, it's likely in the newthrd/tssforwarding on Windows. Could you runguest_libc_threadson Windows and take a look?Imported from boykopovar/AnyPS5. Originally posted by hypermoist on 2026-10-21T10:47:36Z.
Thanks @oneandonlydean. The abort was
_Tss_create_nid_postfix: libkernel threads are not registered: on Windows a DLL is only loaded when the executable imports from it, andguest_libc_threads_testsimported nothing from libkernel, so its load-time registration never ran (Linux loads every linked library, hence the pass there).02bf457027makesKernelKeyscompare_Thrd_currentwithscePthreadSelf, which imports libkernel and checks the forward at the same time.