feat(libkernel_sys): implement the scePthreadBarrier, cpuclockid, concurrency and msync forms #8987
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/8987"
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 simonbronk on 2026-10-21T08:40:43Z.
What
Implements 10 libkernel_sys exports that were discovery stubs, as wrappers over libkernel's existing POSIX implementations:
scePthreadBarrierInit,scePthreadBarrierWait,scePthreadBarrierDestroyscePthreadBarrierattrInit,scePthreadBarrierattrDestroy,scePthreadBarrierattrGetpshared,scePthreadBarrierattrSetpsharedscePthreadGetcpuclockid,scePthreadGetconcurrencysceKernelMsyncA POSIX error is returned as
0x80020000 | errno(SceKernelError).scePthreadBarrierWaitreturns -1 (PTHREAD_BARRIER_SERIAL_THREAD) to the serial thread, andscePthreadBarrierInitignores its name, as shadPS4 (PS4) does. Signatures follow the Orbital type database. Neither is measured on a PS5; this is recorded indocs/dev/debt/libkernel_sys.md.sceKernelMlockallis left throwing: libkernel'smlockallthrows for every valid flag, so wrapping it would only move the throw.scePthreadCondattrGetclockis left to #8373. libkernel_sys goes from 13 to 23 of 545 intools/progress.py.Tested
macOS 27 (Apple silicon), clang, C++20. The new
guest_kernel_sys_barriertest (core/libs/tests/GuestKernelSysBarrier.cpp, registered next toguest_kernel_sys) was built againstlibkernel_sys/Export.Discovery.cppand libkernel's realPthread/Posix/Barrier.cpp, with minimal stand-ins for thread creation,pthread_getcpuclockid,pthread_*concurrencyandmsync, since the full build does not run on macOS. It passes: attribute errors, two rounds of a 4-thread barrier with exactly one serial thread, a 1-count barrier, destroy errors, the cpuclock id against the POSIX call, the concurrency level, andmsyncEINVAL/ENOMEM.The CMake/ctest build on Linux and Windows was not run locally.
check_conventions.pyis clean andpr_overlap.pyreports no overlap. No title tested.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
Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-21T08:41:31Z.
Progress report (
7e2ba73→106e736)📈 System libraries: 43.32% (+0.09%, +10 implemented functions)
✅ 10 implemented
sceKernelMsyncscePthreadBarrierDestroyscePthreadBarrierInitscePthreadBarrierWaitscePthreadBarrierattrDestroyscePthreadBarrierattrGetpsharedscePthreadBarrierattrInitscePthreadBarrierattrSetpsharedscePthreadGetconcurrencyscePthreadGetcpuclockidImported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-21T14:43:38Z.
Independent Windows run of this PR (data only).
Environment: Windows 10 Pro 10.0.19045, Ryzen 7 5800X3D, WinLibs GCC 15.2.0 r7 (MinGW-w64 UCRT), Release, BUILD_TESTING=ON. Merge-tree of the PR head against
mainis clean. I built onlyguest_kernel_sys_barrier_tests;ctest -N -R guest_kernel_sys_barrierlists exactly one test.PR head tested:
6131ec265d3269b130185cd7a2cf26929d304de8.Results (3 runs each):
guest_kernel_sys_barrierpasses 3/3.core/libs/prx/libkernel_sys/Export.Discovery.cppwith the version from the PR's merge base (27c88a8d75), then rebuilt. The test fails 3/3 (exit 0xc0000409). I restored the PR's files afterwards.Not run: other platforms, the other tests in the same family, the full repository CTest, and any title or console run.
AI-assisted (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by simonbronk on 2026-10-21T18:16:58Z.
Linux run of
6131ec265merged ontomain99844c7ee(clean merge).Environment: Ubuntu 24.04 x86-64 container under Rosetta on Apple Silicon (Colima), GCC 13,
RelWithDebInfo,BUILD_TESTING=ON,ANYPS5_ENABLE_ASAN=ON. ASan builds dynamic executables, so this is not the CI configuration.Results: the full build has no errors. the 2 tests matching
kernel_sys, includingguest_kernel_sys_barrier: all pass, with no AddressSanitizer report.Not run: the static CI configuration, native x86-64 hardware, GPU tests, a title.
AI-assisted (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by harisibrar1 on 2026-10-22T05:47:40Z.
Review: COMMENTED
Checked against main
4a17c7175and FreeBSD 11.4 lib/libthr/thread/thr_barrier.c and thr_barrierattr.c:0x80020000|errno,scePthreadBarrierWaitpasses -1 to the serial thread, andsceKernelMsyncreads the errno that libkernel'sSetErrorstores through__error. Nothing reports success without doing the work.scePthreadBarrierattrSetpshared(&attr, 1 /* PTHREAD_PROCESS_SHARED */)returns 0x80020016, because libkernel's Barrier.cpp:56 rejects anything but PROCESS_PRIVATE. That is the FreeBSD 9 behaviour. FreeBSD 11.4's_pthread_barrierattr_setpsharedaccepts both PRIVATE and SHARED and returns 0, and the PS5 is 11-based. GuestKernelSysBarrier.cpp:62 now asserts the EINVAL for the sce form too.count == 0. FreeBSD 11.4's_pthread_barrier_initalso returns EINVAL forcount > INT_MAX, soscePthreadBarrierInit(&b, nullptr, 0x80000000u, nullptr)succeeds here and fails on FreeBSD.Reviewed with AI assistance (Claude Code); the checks above were run locally on my machine.
Imported from boykopovar/AnyPS5. Originally posted by simonbronk on 2026-10-22T09:07:13Z.
@harisibrar1 thanks for checking it against libthr.
setpshared(PTHREAD_PROCESS_SHARED): the PS5 differs from FreeBSD 11.4 here. On firmware 12.70,pthread_barrierattr_setpshared,pthread_mutexattr_setpsharedandpthread_spin_initaccept onlyPTHREAD_PROCESS_PRIVATE, and 1, 2 and -1 returnEINVAL. That is whatdb504f6b9onmainmeasured and implemented. So line 62 asserts the console's behaviour, and the sce form passes it through as 0x80020016.count > INT_MAX:mainhas rejected it since669455d1f. I rebased ontod6eafa54dand addedscePthreadBarrierInit(&b, &attr, 0x80000000u, ...) == 0x80020016with the barrier left null, so the sce form covers it too.Tested: Linux, Ubuntu 24.04 x86-64 container (Colima/Rosetta), GCC 13, RelWithDebInfo with ASan, merged onto
maind6eafa54d:guest_kernel_sys,guest_kernel_sys_barrier,guest_kernel_sys_thread_defaultsandguest_pthread_barrierpass, no ASan reports.AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by harisibrar1 on 2026-10-22T12:47:33Z.
@simonbronk you're right on both points, and I'm sorry for the noise. My check read
Barrier.cppfrom this branch's older base instead of main. On main4a17c7175,db504f6b9already rejectsPTHREAD_PROCESS_SHAREDfrom the 12.70 measurement, and669455d1falready rejects counts aboveINT_MAX(Barrier.cpp:57and:64). So line 62 asserts measured console behaviour and is correct, and the new0x80000000usce case is a good addition. Please disregard that part of my review; the rest still stands.Reviewed with AI assistance (Claude Code).