Repository navigation
feat(libkernel_sys): implement fstat - #9008
Conversation
fstat was a NotImplemented stub in libkernel_sys. It now calls libkernel's _fstat, as fstatfs already calls _fstatfs, so it reports the same status, EFAULT for a null buffer and EBADF for a descriptor that is not open.
|
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.
Some 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.
|
|
Windows run of 29f1a34 merged onto Built I ported the description's probe to Windows: a program linked against the unpatched
Not run: the patched-NID form of the probe, a title. |
|
A public homebrew that reaches this stub on Windows today: LakeSnes from the ps5-payload-dev websrv v0.34 bundle (
Same search over the v0.1.3 Windows AI-assisted: yes (Claude Code). |
|
@mpratsaki I ran it on Windows: LakeSnes doesn't get as far as The fault is the SDK startup's first call through its entry argument: |
|
@ycbuzi Thanks for running it and for tracing the fault. You're right, and "reaches this stub" in my comment overstated a static result: the import binding I described happens at start-up, but LakeSnes is an SDK payload and stops in |
harisibrar1
left a comment
There was a problem hiding this comment.
Checked against main 6ef5a1c and FreeBSD 11.4 sys/sys/stat.h / ps5-payload-dev/sdk sce_stubs/libkernel_sys.c:
- The forwarder at libkernel_sys/Export.cpp:277-281 matches FreeBSD's
int fstat(int, struct stat *)and the existingfstatfs→_fstatfspattern above it. Errors come from libkernel'sfstat(Stdio.cpp:896-912): EFAULT for a null buffer on an open descriptor, EBADF otherwise. - The probe from the description isn't in the PR.
fstatfshas the same check in core/libs/tests/GuestKernelSys.cpp:278-285: same-descriptor comparison with_fstatfs,nullptr→ -1/14, and closed or -1 descriptor → -1/9. Adding thefstat/_fstatequivalent there would keep the forwarder covered if either side changes. - No debt entry looks needed, since the behaviour is libkernel's unchanged
fstat. - Builds on Windows (WinLibs GCC 15.2.0 r7, full
BUILD_TESTING=ONbuild) merged onto main 6ef5a1c; the only failing step is the existingImageArrayWindowPastLayerLimit.cppalignment error that #8310 fixes. Not run here: this machine's Smart App Control blocks freshly built test executables.
Reviewed with AI assistance (Claude Code); the checks above were run locally on my machine.
fstat must fill the same FileStat as _fstat for an open descriptor, return EFAULT for a null buffer and EBADF for a closed or invalid descriptor, as the fstatfs check beside it does for _fstatfs.
|
@harisibrar1 Thanks. Added in fa5fc8d beside the |
What
fstatin libkernel_sys was aNotImplemented_nid_no_patchstub from the discovery exports. It now calls libkernel's_fstat, asfstatfsin the same file already calls_fstatfs. It has FreeBSD'sint fstat(int, struct stat*)signature, and it gives the same status,EFAULTfor a null buffer andEBADFfor a descriptor that is not open as libkernel'sfstat.guest_kernel_syscompares it with_fstat, as it doesfstatfswith_fstatfs.Tested
Ubuntu 24.04 (WSL2) x86-64, GCC 13.3, Release, full build with
BUILD_TESTING=ON:ctest -R '^(patched_libraries|guest_kernel_sys|conventions_unknown_nids)$': 3/3 pass;patched_librariesreports 357 patched libraries loaded, 0 failed.libkernel_sys.prxexportsfstat(mqQMh1zPPT8) and imports_fstat(A0O5kF5x4LQ), which patchedlibkernel.prxexports.guest_kernel_sysgains anfstatcheck beside thefstatfsone:fstatand_fstaton the same descriptor give a byte-identicalFileStatwithst_size1; a null buffer gives -1/EFAULT; a closed descriptor and -1 give -1/EBADF. Making the forwarder return 0 fails the null-buffer check.fstatreturns 0 withst_size5 andS_IFREG, byte-identical to_fstat.tools/progress.py: libkernel_sys 13 → 14 done, 532 → 531 todo.python3 tools/check_conventions.py --base origin/main: passed.python3 tools/pr_overlap.py: feat(libkernel_sys): implement chown, lchown, fchownat and linkat #9103 and feat(libkernel_sys): implement statfs symlinkat and futimesat #9161 remove the stub next to thefstatstub inExport.Discovery.cpp, and feat(libkernel_sys): implement sceKernelGetModuleInfoInternal and sceKernelGetModuleListInternal #9294 adds functions wherefstatgoes inExport.cpp; none implementsfstat, and whichever lands second keeps both sides.Windows: built and tested by @ycbuzi in the comments. Not tested: macOS, titles.
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)