feat(libc): add the std::__sce_v2 mutex, condition and thread calls #8885
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/8885"
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-21T04:29:59Z.
What
Adds 16
std::__sce_v2thread entry points fromlibSceLibcInternalthat libc does not export yet. Titles import them:kitt-ps5-shipping.prxandkitt_support-ps5-shipping.prxmodules import_Mtx_init,_Mtx_lock,_Mtx_unlockand_Mtx_destroy;kitt-ps5-shipping.prxalso imports_Thrd_yield. Itskitt_webkit-ps5-shipping.prxmodule also imports the_Cnd_*calls._Cnd_*calls in itseboot, and_Thrd_idin two bundled middleware modules.The upstream
_Mtx_*/_Cnd_*work on this libc's own mutex type. These versioned forms are different: in the decryptedlibSceLibcInternal.sprx(PS5 13.60) they take libkernel's mutex, condition and thread handles and call thescePthread*functions directly. So they forward the same way, and translate the results into Dinkumware'sthrd_*codes as the console does:_Mtx_init_with_name(b6I1MMimJXA)*mtx, creates an attribute, sets the recursive type when bit0x100is set, and creates the mutex with the given name (none if null or empty). It returns 1 forENOMEMand 4 for any other failure; if destroying the attribute fails, the new mutex is destroyed and 4 returned._Mtx_init(TdAc0h4iomU)_Mtx_init_with_namewith the nameSceLibcI_Mtx_Mtx_destroy(XP6c8M4G+fc)scePthreadMutexDestroy, result returned as is_Mtx_lock(5qXct3c1skg)EDEADLK, otherwise 4_Mtx_trylock(S0FJ-HONta8)EBUSY, otherwise 4_Mtx_unlock(4bp9gcNLwMI)_Cnd_init(bL2UrZ-G0Hk) /_Cnd_init_with_name(bXdNk0ZHk00)scePthreadCondInitwith no attribute and the nameSceLibcI_Cndor the given one; 0, 1 forENOMEM, otherwise 4_Cnd_destroy(KSs6Q1X5ABk)_Cnd_wait/_Cnd_signal/_Cnd_broadcast(fUs4X3mpTi4,enG9-gUJp70,8Y9ARRfgQc4)_Thrd_detach(CfO+zWMbJJQ)_Thrd_join(qnYxp6VUtbI)_Thrd_yield(919aYFGRv-k) /_Thrd_id(2ozFS9GCs+A)scePthreadYield/scePthreadSelfThe bodies are written from this observed behaviour; nothing from the module is copied. libkernel registers a second table of
scePthread*functions with libc at load, next to the table #8859 adds.Not included:
_Throw_Cpp_error(ShHKOkWgZRM, 0x11b780): the console raises astd::__sce_v2::system_error, a type libc does not have yet. It follows in a separate PR together with the versioned exception types; an earlier revision of this PR wrongly forwarded it to the unversioned call._Mtx_timedlock,_Cnd_timedwaitand_Thrd_sleep: they convert theirtimespecthrough an internal clock helper whose behaviour is not pinned down yet._Thrd_start*family and the_Cnd_*_at_thread_exitcalls: these have real bodies, not one-call forwards._Thrd_hardware_concurrency: it returns a value computed at module start.Tested
Linux (CachyOS, GCC, Release): full build. All 539
guest_*, kernel and Ampr tests pass.guest_libc_threadsgainsVersionedSync, which runs against the real libkernel:_Mtx_trylockfrom a second thread returning 3 while the mutex is held;_Thrd_joinreturning the exit code, and 4 on a second join;_Thrd_detach,_Thrd_yieldand_Thrd_id;It passed 10 runs in a row. Mapping
EDEADLKto 4 instead of 3 makes the test fail.tools/check_conventions.pyis clean. None of these names or NIDs appear in any of the 816 open pull requests, and there is no line overlap with them.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 MarcZX10 on 2026-10-21T04:37:45Z.
The new
_Mtx_unlock,_Cnd_wait,_Cnd_signal, and_Cnd_broadcastwrappers currently discard the libkernel return code and unconditionally report success. The underlyingscePthreadMutexUnlockcan returnSCE_KERNEL_ERROR_EPERMfor a non-owner, and condition wait can returnEINVAL/EPERMfor destroyed or unowned objects (Pthread/src/Mutex.cpp,Cond.cpp). Could these wrappers translate nonzero kernel results to the CRT error/throw convention, as the existing libc_Cnd_waitand mutex wrappers do, and add fake-forward tests for each failure path? As written, callers can believe a failed unlock/wait/signal completed normally.Imported from boykopovar/AnyPS5. Originally posted by hypermoist on 2026-10-21T04:47:46Z.
Thanks. I checked this against the decrypted
libSceLibcInternal.sprx(12.00) before changing anything. All four versioned calls drop the kernel result on the console:_Mtx_unlock(0xe0340),_Cnd_wait(0xdf3b0),_Cnd_signal(0xdf410) and_Cnd_broadcast(0xdf420) each make thescePthread*call and then return 0. The unversioned_Mtx_unlock,_Cnd_waitand_Cnd_signalin the same module do the same. Upstream's own unversioned_Mtx_unlockand_Cnd_waitalso return success for a non-owner (Threads.cpp, theIsOwnedByCallerearly returns). Translating the errors would make these differ from the console and from the existing wrappers, so I've kept them returning 0.What I did add (
ae4d607a54):VersionedSyncnow unlocks and waits with a mutex the caller does not own. It shows libkernel itself failing both calls (EPERM), and both wrappers returning 0. So the behaviour is pinned by a test, not left implicit. Replacing the wait assertion with!= successmakes the test abort.That commit also removes the versioned
_Throw_Cpp_error: the console raises astd::__sce_v2::system_errorthere, not the unversioned type this forwarded to. It will come back with the versioned exception types in a separate PR.Imported from boykopovar/AnyPS5. Originally posted by tkcm01 on 2026-10-21T18:12:37Z.
Windows data point for
8e08acba70, merged ontomain99844c7ee(clean merge). GitHub Actionswindows-latestrunning this repo's Build workflow (full Windows build, WinLibs GCC, Release,BUILD_TESTING=ON) on my fork.guest_libc_threadsincluded (run).mainplus only this PR's test changes:guest_libc_threads_testsdoes not link (thestd::__sce_v2_Mtx_*,_Cnd_*and_Thrd_*exports are undefined), as expected for new exports (run).Not tested: Linux, macOS, a title.
AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by harisibrar1 on 2026-10-22T05:47:37Z.
Review: APPROVED
Checked against main
4a17c7175and ps5-payload-dev/sdksce_stubs/libSceLibcInternal.c:std::__sce_v2symbols, so whether these exports exist depends on the 12.00 module and title imports you cite. I computed the NIDs from the 16 mangled names and all of them match your table (for example,_ZNSt8__sce_v29_Mtx_initEPP13pthread_mutexigives TdAc0h4iomU and_ZNSt8__sce_v28_Thrd_idEvgives 2ozFS9GCs+A).PP13pthread_mutex,PP12pthread_cond,P7pthread) agree with the pointer-to-handle and by-value pthread_t forwards. The kernel error constants (0x8002000b/0c/10) and recursive type 2 agree with libkernel's Mutex.cpp:141 and Pthread.hpp:28._Thrd_join/_Thrd_detachmatch main's unversioned implementations. The always-0 unlock/wait/signal/broadcast matches the existing debt entry for the unversioned calls, and the unowned-mutex test now pins it.scePthreadYielddeclaration; the one at line 50 already exists._Thrd_idthrows because the return type is unknown. The 0xdb630scePthreadSelfobservation could settle that for the unversioned export too.Reviewed with AI assistance (Claude Code); the checks above were run locally on my machine.
Imported from boykopovar/AnyPS5. Originally posted by hypermoist on 2026-10-22T09:08:01Z.
@harisibrar1 thanks for checking the NIDs and the mangled types. Fixed the nit in
f465759bcf: the secondscePthreadYielddeclaration is gone (I also merged currentmain);guest_libc_threadsand theguest_pthread*tests still pass on Linux.Agreed on the follow-up. The unversioned
_Thrd_iddebt line can be settled the same way, and I'll do it in a separate PR so this one stays on the__sce_v2exports.@tkcm01 thanks for the Windows run and the negative control.