feat(libSceNKWebKit): implement the WTF file-handle operations #14931
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/14931"
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 w4rc0n on 2026-11-02T01:33:03Z.
What
WTF::FileSystemImpl's file-handle functions wereNotImplementedstubs. Guest WebKit code that opened, sought in, truncated or closed a file threw. Six of them now follow the pinned PS5 WebKit 11.xFileSystemPOSIX.cpp:57-129andFileSystem.cpp:371-394:openFile,closeFile,seekFile,truncateFile,openAndLockFileandunlockAndCloseFile.open,close,lseekandftruncateexports with the guest flag values and guesterrno, aslibScePosixForWebKitalready does. The handles are ordinary guest descriptors, so they work withsceKernel*calls in both directions.PlatformFileHandleis anint(-1 when invalid) on every host (FileSystem.h:62).String::utf8.Read=O_RDONLY,Truncate=O_WRONLY|O_CREAT|O_TRUNCandReadWrite=O_RDWR|O_CREAT.failIfFileExistsaddsO_CREAT|O_EXCL.closeFilesets the caller's handle to -1.seekFilemaps the three origins, andtruncateFilereturns whetherftruncatesucceeded.openAndLockFileandunlockAndCloseFileonly open and close.USE_FILE_LOCKis off for PlayStation (PlatformUse.h:93), so the source takes no lock.libSceNKWebKitnow linkslibkernel(PRIVATE) and calls these exports by NID. It adds no new cross-library helper and no host descriptor bypass.Paths, directories, links,
realPath,MappedFileDataandfilesHaveSameVolumeare later work.filesHaveSameVolumedepends on a question about how volume identity is reported, recorded indocs/dev/debt/libkernel.md.Adapted source. oneandonlydean's commit
6a73e56e1emoved the six functions, unchanged, intosrc/WtfFileSystem.cpp, under a "Derived from" line and the verbatim notice of each pinned source file, the form the rest of this series uses:posix/FileSystemPOSIX.cppforopenFile,closeFile,seekFileandtruncateFile, andFileSystem.cppforopenAndLockFileandunlockAndCloseFile.tools/pr_overlap.pyon this head, withmainat0eba5db30d: no other open PR changes these exports or adds the same files. For the PRs it couldn't compare because they no longer merge withmain, GitHub's file lists show none of them changing these exports either. #13947, #13992, #14981, #15011, #15215 and #15498 change nearby lines in the same files; whichever merges later keeps both sides. The only exports it shares are with #14932 and #14949, in the same stack.Tested
Debian 12, GCC 12.2, Linux 6.18, Release, at the head
6a73e56e1ea36b4e77ebb3a8d30a5bb13498af68: oneandonlydean's commit that moves these functions intosrc/WtfFileSystem.cpp, on top of0efdf47930434f6317c4a572ea0af7cf501e0095. The selection was the thirteen NKWebKit tests (nkwebkit_constantsand upstream's newernkwebkit_fastbitvector,nkwebkit_resourceresponse,guest_nkwebkit_urlsandnkwebkit_palsessionidincluded),public_headersandpatched_libraries. The fulllibstarget was built so thatpatched_librariescould run.patched_libraries.nkwebkit_wtfaborts withguest path: process_vm_readv failed with errno 38. The kernel of this machine has noprocess_vm_readv, and libc's guest path copy uses it, so this run never reaches the file behaviour. The Linux CI run below reaches it.nkwebkit_wtfcases cover:closeFileinvalidating the handle, and failures returning -1 or false;openFileused with the guestreadandwriteexports, and one from the guestopenexport closed bycloseFile.libSceNKWebKit.prxlistslibkernel.prxas needed, andLD_LIBRARY_PATH=build/core/libs/libs ldd -rreports no undefined symbols.tools/progress.py: the six exports count as implemented (libSceNKWebKit 1318, 1312 onmain).tools/check_conventions.pypasses.feat/nkwebkit-filesystem-pathsat its previous headd82592c45b330f97325194d1223c930fb41e1ab9and run 41376721923 builtfeat/nkwebkit-filesystem-mappedat its previous head597d4921755bc7184edc292d2fd80210f030af69, which both contain this PR's commit. It is AnyPS5'sBuildworkflow, dispatched in the author's fork withselect=true: the branch merged intomainat93dbd0f82aea684e95f15f06e7d42c0064af18cf, built onwindows-latestwith WinLibs GCC 15.2 (MinGW-w64, UCRT). None of the 672 selected tests failed; 6 AGC tests were skipped, whichcheck_skips.pyaccepts. That includes the nine NKWebKit tests,public_headersandpatched_libraries. The first attempt of run 41376713519 timed out two unrelatedcheck_compile_modes_test_clang_*tool tests at 30 s, which pass in 2-3 s in every other run; the failed job was rerun and passed. The later rebases ontomain(now0eba5db30d8a3d03789e52e5c1a9ff853e4e33e4, after #14479, #15228, #13766, #14925 and #15911) changed onlydocs/dev/debt/libSceNKWebKit.md, sogit range-diffshows the code and tests under test are the same as at that run. A fork-internal pull request existed only to give the workflow a number. The commit added since,6a73e56e1e, only moves these functions intosrc/WtfFileSystem.cppwith their notices.4179fef3b47aed47e6ace92a1178c9b8cb69948cwith the fulllibstarget onubuntu-latest(Ubuntu 24.04, kernel 7.0, GCC 13.3). 13 of 13 pass, includingnkwebkit_wtfandpatched_libraries. The later rebases ontomain(now0eba5db30d8a3d03789e52e5c1a9ff853e4e33e4, after #13766, #14925 and #15911) changed onlydocs/dev/debt/libSceNKWebKit.md, sogit range-diffshows the code and tests under test are the same as at that run. The commit added since,6a73e56e1e, only moves these functions intosrc/WtfFileSystem.cppwith their notices.Local fallback used for the second run (not in this PR)
Not built or run: macOS. No title or homebrew was run.
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 XairRrR on 2026-11-03T10:07:09Z.
Review: APPROVED
Reviewed — approved
The six
WTF::FileSystemImplfile-handle exports follow the cited PS5 WebKit 11.x source and run through the existing guest libkernel exports. The newnkwebkit_wtfcases pass, and they fail when the open flags are changed.What I ran
Head
4179fef3b47aed47e6ace92a1178c9b8cb69948c, merged with--no-ffintomain4f41f4c375f5abb487dbd184fbc150f31994d762(merged tree628dc6ce6da18b2d2c905ddf6e67b43c180fe1bc). Debian 13 VM, 2× Xeon Gold 6136, GCC 14.2.0, Release, Ninja.I also recounted the inventory stubs on
mainand on the merged tree with a small Python script overInventoryExports.hpp,Api.hppandExport.cpp.Results
git diff --checkcheck_conventions.pylibs(script)check_skips.py), 1 known failure onmain(unwrap_self_UnwrapTest_test_new_output_inherits_the_destination_directory_group); no new failures, no timeoutsnkwebkit_wtf,patched_libraries,public_headers(my rerun)nkwebkit_wtfin 0.01 sApi.hppstubs and 7421 inventory stubs, the same as the new text. Onmainthe prose said 7437, but the real count was 7426, so the PR also fixes a stale number.This machine has a normal kernel.
nkwebkit_wtfreaches the file cases without the localprocess_vm_readvfallback described in the PR, which agrees with the author's Linux CI run.Negative control
Full revert. Restoring all six production files from
mainwould only break compilation of the test, becausemaindeclares the exports with no parameters. RestoringCMakeLists.txtalso starts a CMake reconfigure, and that reconfigure fails in this sandbox (configure_file: Operation not permittedin SDL2). So I used a mutation instead.Mutation. In
src/WtfSystem.cppI removedSCE_KERNEL_O_TRUNCfrom theTruncatemode. Then I rebuiltWtfSystem.cpp.oandlibSceNKWebKit.prxwith ninja's recorded commands:nkwebkit_wtf_testsaborts (exit 134) right after theflags=0x201open (O_WRONLY|O_CREATwith no trunc), the case that expects the file to be emptied.git status --porcelainis empty afterwards.Because
CMakeLists.txtwas rewritten with the same content, the build directory will rerun CMake on its nextninjacall.Findings
Blocking
None.
Non-blocking
core/libs/prx/libSceNKWebKit/src/WtfSystem.cpp:76).ToUTF8always returns a buffer: it ends withCopyCString(bytes.data(), bytes.size()), andstd::string::data()is never null. Soif (!representation.buffer) return -1;never runs. ThenullPathtest case (tests/Wtf.cpp:403-404) returns -1 only because the guestopen("")fails withENOENT. Upstream'sisNull()check is just as unreachable on POSIX, and the visible result is the same, so nothing needs to change. Just be aware that this case doesn't test the branch it seems to test.3rdparty/rule, and the author is waiting for an answer on #14921. I found nothing new to add. The functions are each a few lines, and the upstream contract fixes their flag, permission and return values. This is a maintainer decision, and I am not counting it against the PR.What I checked in the code:
(String const&, FileOpenMode, FileAccessPermission, bool),(int&),(int, long long, FileSeekOrigin),(int, long long),(String const&, FileOpenMode, OptionSet<FileLockMode>),(int). They agree with the declared parameter types.failIfFileExistshandling, the-1invalidation incloseFile, the seek origins and the!ftruncateresult all matchFileSystemPOSIX.cpp:57-129.openAndLockFileuses the defaultFileAccessPermission::Alland passesfailIfFileExists=false, as inFileSystem.cpp:371-394.CStringis released by its destructor.Not verified
libSceNKWebKit.Pull request closed