feat(libkernel_sys): implement sceKernelFlock over flock #9097
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/9097"
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 DavidSamir on 2026-10-21T12:10:45Z.
What
sceKernelFlockwas a discovery stub inlibkernel_sys(Export.Discovery.cpp) that threwNotImplemented. It now wraps libkernel'sflock, which already implements FreeBSD 11flock(2): shared and exclusive locks,LOCK_NB,LOCK_UN,EBADFfor a bad descriptor andEOPNOTSUPPfor sockets and pipes.The SCE form returns 0 on success, or
SceKernelErrorof the guesterrnothatflockset. This is the mapping the othersceKernel*wrappers of guest POSIX calls use, for examplesceKernelCloseover a socket (Open.cpp) and the wrapper atStdio.cpp:1290.Stdio.cpp'sSceErrorFromErrnotakes a hosterrno, which would turn the guestEWOULDBLOCK(35) intoEIOon Windows, so it isn't used here.Tested
Windows 11 Pro 26200, WinLibs GCC 15.2.0 r7, Release.
guest_kernel_sysgainsSceKernelFlock:0x80020023(EWOULDBLOCK);LOCK_UNon the first, the second descriptor's lock succeeds, then unlocks;0x80020009(EBADF).On
mainthe test aborts withsceKernelFlock not implemented. On this branch it passes.tools/check_conventions.py --base origin/mainpasses.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)Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-21T14:18:04Z.
Linux data point (WSL2 Ubuntu 24.04, virtualised kernel, not bare-metal; GCC 13.3, Release): at head
41ab6b4c1guest_kernel_sysaborts withKernel sys check failed at line 264 (guest errno 2), which isRequire(first >= 0 && second >= 0)inSceKernelFlock; at the merge base927076049the same test passes 10 of 10 runs. The cause is the path:std::filesystem::temp_directory_path() / "anyps5-sce-flock.bin"is an absolute host path, and on Linux the guest resolver does not map it, soopen_nid_postfix(path, 0x602, 0644)answers ENOENT (a standalone probe shows the same for flags 0x602, 0x202, 0x2 and 0x201 on that path; it never reachessceKernelFlock). With only that line changed to a relative name,const std::string path = "anyps5-sce-flock.bin";,guest_kernel_syspasses 10 of 10 runs on Linux, so thesceKernelFlockexpectations themselves (EWOULDBLOCKfor the second descriptor, the unlock hand-over,EBADFfor -1) hold there. Not tested: macOS, a console, Windows.AI-assisted (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-21T16:14:43Z.
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_tests;ctest -N -R guest_kernel_syslists exactly one test.PR head tested:
41ab6b4c15bd6d97cdf5ef62f2f1df402c8deb5e.Results (3 runs each):
guest_kernel_syspasses 3/3.core/libs/prx/libkernel_sys/Export.Discovery.cpp,core/libs/prx/libkernel_sys/Export.cppwith the version from the PR's merge base (aed67d7e55), then rebuilt. The test fails 3/3 (exit 0xc0000409). I restored the PR's files afterwards.GPU: the run output has no
Selected GPUline; no GPU claim is made.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 DavidSamir on 2026-10-21T20:38:54Z.
Thanks @xXPBSXx, you're right. The test gave a guest call an absolute host temp path (
temp_directory_path()), which the Linux guest resolver doesn't map.a9a749b99now opens a guest-relative name (anyps5-sce-flock-<steady clock>.bin, in the working directory), as the rest ofGuestKernelSys.cppdoes.guest_kernel_syspasses on Windows; I don't have a Linux machine here, so I haven't run it there.AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by DavidSamir on 2026-10-22T02:06:12Z.
Linux: Ubuntu 24.04.1 LTS (WSL2), GCC 13.3.0, Release; head
a9a749b99merged ontomain8c26eac3c.guest_kernel_sys(with the flock test) passes 3/3.Run from the PC (Windows host, Linux in WSL2), not from the PR author's machine.
Imported from boykopovar/AnyPS5. Originally posted by Gruzzberry on 2026-10-22T06:49:15Z.
#9442 adds
lchflagscases inGuestKernelSys.cppnext to the lines this PR changes there; text only, whichever lands second rebases.Imported from boykopovar/AnyPS5. Originally posted by harisibrar1 on 2026-10-24T13:25:47Z.
Review: COMMENTED
Checked against main
6cd36e6517:Export.cpp's includes, main addedgetpid_nid_postfixthere, and inGuestKernelSys.cpp, main addedCheckProcessQueries()whereSceKernelFlock()goes. A rebase should fix both.#include "prx/libkernel/KernelErrors.hpp"can go: main'slibkernel_sys/Export.cppalready includes it (lines 24 and 26).GuestKernelSys.cppnow includesKernelErrors.hppand uses theSCE_KERNEL_ERROR_*names, soSCE_KERNEL_ERROR_EAGAINandSCE_KERNEL_ERROR_EBADFwould read better than the hex literals.flock_nid_postfixsets the guest errno throughPosixFailure(Stdio.cpp:489-492), soSceKernelError(*__error_nid_postfix())gives0x80020023/0x80020009as your test expects.Reviewed with AI assistance (Claude Code); the checks above were run locally on my machine.