feat(libc): implement std::_Execute_once #735
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/735"
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 adriadam10 on 2026-10-05T18:23:28Z.
What
Implements
std::_Execute_once(std::once_flag&, int (*)(void*, void*, void**), void*)(DiGVep5yB5w,_ZSt13_Execute_onceRSt9once_flagPFiPvS1_PS1_ES1_). It replaces the unnamedlibcCyberUnknown01stub inlibc/Export.cpp. The NID was checked against the mangled name withtools/nid_names.py's hash.No emulator reference has a body for it, so the behaviour comes from the disassembly of the real
sce_module/libc.prxthat a title ships (export at0x81590, 157 bytes). It has the same Dinkumware lineage as Microsoft STL'sxonce.cpp, but MS STL wrapsInitOnceExecuteOnceinstead:SCE_PTHREAD_MUTEX_RECURSIVE(init helper called with flag0x100→settype(2)), held for the whole call*flag != 0→ return 1 without calling the callbackcallback(nullptr, arg, nullptr); a non-zero result sets*flag = 1and returns 1, zero leaves the flag at 0 and returns 0 (a later call retries)_Unwind_Resume); the flag stays 0Here: a static
std::recursive_mutexheld by alock_guard, with the same flag/return logic.The existing
std_execute_once_nid_postfix(NID of the literal namestd_execute_once, so no title can bind it) is left as it is.Removing the stub sits next to the
Export.cppstubs #492 deletes. #492 already conflicts withmain, and the extra hunk is a trivial delete/delete.Tested
Linux (GCC Release, same as CI). New
guest_execute_oncetest (core/libs/tests/GuestExecuteOnce.cpp, registered in libc's CMakeLists):(nullptr, arg, nullptr), and a nested_Execute_onceon another flag from inside the callback works (recursive mutex).On
mainthe test doesn't link (only the unnamed throwing stub exists). Negative checks, each one makes the test fail: not setting the flag, returning 1 on failure, wrong argument order, no lock, a non-recursive mutex,== 1instead of!= 0. The fullguest_|libcctest set passes (96).Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt.mdfiles or images added to the repository (attach them to this PR)Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-05T18:23:54Z.
Progress report (
bc24783→948d3cd)📈 System libraries: 79.57% (+0.03%, +1 implemented, -1 removed functions)
✅ 1 implemented
_ZSt13_Execute_onceRSt9once_flagPFiPvS1_PS1_ES1__nid_postfix🗑️ 1 removed
libcCyberUnknown01Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-05T20:30:11Z.
Thanks for this. It needs a rebase:
core/libs/prx/libc/Export.cppconflicts with currentmain. #718 removed the neighbouringlibcCyberUnknown00stub (2gbcltk3swE, nowdiv), and this PR removeslibcCyberUnknown01right after it, so the resolution is to drop both stubs.The rest checks out. The NID
DiGVep5yB5wmatches the name, and the behaviour matches the_Execute_oncein thelibc.prxthat PPSA21564 bundles: one global lock around the flag check, the callback called with(nullptr, arg, nullptr), and the flag set to 1 only when the callback returns non-zero.guest_execute_oncefails to link on main's code and passes with the change, also 20 times in a row (Linux, GCC).Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-05T22:29:03Z.
Rebased on current
main: both neighbouring stubs (2gbcltk3swE,DiGVep5yB5w) are gone now.guest_execute_oncepasses.