feat(libSceNKWebKit): implement the WTF file-handle operations #14931

Closed
w4rc0n wants to merge 1 commit from upstream-pr/14931 into main
w4rc0n commented 2026-11-02 01:33:03 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by w4rc0n on 2026-11-02T01:33:03Z.


What

WTF::FileSystemImpl's file-handle functions were NotImplemented stubs. Guest WebKit code that opened, sought in, truncated or closed a file threw. Six of them now follow the pinned PS5 WebKit 11.x FileSystemPOSIX.cpp:57-129 and FileSystem.cpp:371-394: openFile, closeFile, seekFile, truncateFile, openAndLockFile and unlockAndCloseFile.

  • Real guest descriptors. Each function calls libkernel's existing guest open, close, lseek and ftruncate exports with the guest flag values and guest errno, as libScePosixForWebKit already does. The handles are ordinary guest descriptors, so they work with sceKernel* calls in both directions. PlatformFileHandle is an int (-1 when invalid) on every host (FileSystem.h:62).
    • The path goes through String::utf8.
    • The modes are Read = O_RDONLY, Truncate = O_WRONLY|O_CREAT|O_TRUNC and ReadWrite = O_RDWR|O_CREAT. failIfFileExists adds O_CREAT|O_EXCL.
    • The permissions are 0600 or 0666.
    • closeFile sets the caller's handle to -1. seekFile maps the three origins, and truncateFile returns whether ftruncate succeeded.
  • No locking. openAndLockFile and unlockAndCloseFile only open and close. USE_FILE_LOCK is off for PlayStation (PlatformUse.h:93), so the source takes no lock.
  • Linking. libSceNKWebKit now links libkernel (PRIVATE) and calls these exports by NID. It adds no new cross-library helper and no host descriptor bypass.

Paths, directories, links, realPath, MappedFileData and filesHaveSameVolume are later work. filesHaveSameVolume depends on a question about how volume identity is reported, recorded in docs/dev/debt/libkernel.md.

Adapted source. oneandonlydean's commit 6a73e56e1e moved the six functions, unchanged, into src/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.cpp for openFile, closeFile, seekFile and truncateFile, and FileSystem.cpp for openAndLockFile and unlockAndCloseFile.

tools/pr_overlap.py on this head, with main at 0eba5db30d: no other open PR changes these exports or adds the same files. For the PRs it couldn't compare because they no longer merge with main, 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 into src/WtfFileSystem.cpp, on top of 0efdf47930434f6317c4a572ea0af7cf501e0095. The selection was the thirteen NKWebKit tests (nkwebkit_constants and upstream's newer nkwebkit_fastbitvector, nkwebkit_resourceresponse, guest_nkwebkit_urls and nkwebkit_palsessionid included), public_headers and patched_libraries. The full libs target was built so that patched_libraries could run.

  • Unmodified: 14 of 15 pass, including patched_libraries. nkwebkit_wtf aborts with guest path: process_vm_readv failed with errno 38. The kernel of this machine has no process_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.
  • With a local fallback for that copy (below, not part of this PR): 15 of 15 pass. The new nkwebkit_wtf cases cover:
    • each open mode with the source's flags;
    • exclusive create on an existing file failing, and the two permission modes;
    • a Unicode path through a guest alias;
    • seeks from each origin, and truncation;
    • closeFile invalidating the handle, and failures returning -1 or false;
    • a descriptor from openFile used with the guest read and write exports, and one from the guest open export closed by closeFile.
  • At the head, the patched libSceNKWebKit.prx lists libkernel.prx as needed, and LD_LIBRARY_PATH=build/core/libs/libs ldd -r reports no undefined symbols.
  • tools/progress.py: the six exports count as implemented (libSceNKWebKit 1318, 1312 on main).
  • tools/check_conventions.py passes.
  • Windows (GitHub-hosted CI in the author's fork): run 41376713519 built feat/nkwebkit-filesystem-paths at its previous head d82592c45b330f97325194d1223c930fb41e1ab9 and run 41376721923 built feat/nkwebkit-filesystem-mapped at its previous head 597d4921755bc7184edc292d2fd80210f030af69, which both contain this PR's commit. It is AnyPS5's Build workflow, dispatched in the author's fork with select=true: the branch merged into main at 93dbd0f82aea684e95f15f06e7d42c0064af18cf, built on windows-latest with WinLibs GCC 15.2 (MinGW-w64, UCRT). None of the 672 selected tests failed; 6 AGC tests were skipped, which check_skips.py accepts. That includes the nine NKWebKit tests, public_headers and patched_libraries. The first attempt of run 41376713519 timed out two unrelated check_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 onto main (now 0eba5db30d8a3d03789e52e5c1a9ff853e4e33e4, after #14479, #15228, #13766, #14925 and #15911) changed only docs/dev/debt/libSceNKWebKit.md, so git range-diff shows 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 into src/WtfFileSystem.cpp with their notices.
  • Linux, unmodified, on a normal kernel (GitHub-hosted CI in the author's fork): a fork-only workflow, not part of this PR (run 41618954287), built this branch's previous head 4179fef3b47aed47e6ace92a1178c9b8cb69948c with the full libs target on ubuntu-latest (Ubuntu 24.04, kernel 7.0, GCC 13.3). 13 of 13 pass, including nkwebkit_wtf and patched_libraries. The later rebases onto main (now 0eba5db30d8a3d03789e52e5c1a9ff853e4e33e4, after #13766, #14925 and #15911) changed only docs/dev/debt/libSceNKWebKit.md, so git range-diff shows the code and tests under test are the same as at that run. The commit added since, 6a73e56e1e, only moves these functions into src/WtfFileSystem.cpp with their notices.
Local fallback used for the second run (not in this PR)
diff --git a/core/libs/prx/libc/src/General.cpp b/core/libs/prx/libc/src/General.cpp
index 9ed57a5fb0..dbb7e1201b 100644
--- a/core/libs/prx/libc/src/General.cpp
+++ b/core/libs/prx/libc/src/General.cpp
@@ -83,6 +83,23 @@ std::size_t HostPageSize() {
     return size;
 }
 
+static bool ReviewPipeCopy(void* destination, const void* source, std::size_t bytes) {
+    int fds[2];
+    if (::pipe(fds) != 0) throw std::runtime_error("review shim: pipe failed");
+    bool ok = true;
+    for (std::size_t done = 0; done < bytes;) {
+        const std::size_t chunk = std::min<std::size_t>(bytes - done, 4096);
+        const ssize_t written = ::write(fds[1], static_cast<const char*>(source) + done, chunk);
+        if (written <= 0) { ok = false; break; }
+        const ssize_t read = ::read(fds[0], static_cast<char*>(destination) + done, static_cast<std::size_t>(written));
+        if (read != written) { ok = false; break; }
+        done += static_cast<std::size_t>(written);
+    }
+    ::close(fds[0]);
+    ::close(fds[1]);
+    return ok;
+}
+
 bool CopyGuestBytes(void* destination, const void* source, std::size_t bytes) {
     GuestArena::GuestArenaPrepareHostRead_nid_no_patch(source, bytes);
 #ifdef _WIN32
@@ -92,6 +109,7 @@ bool CopyGuestBytes(void* destination, const void* source, std::size_t bytes) {
     iovec local{destination, bytes};
     iovec remote{const_cast<void*>(source), bytes};
     const auto copied = process_vm_readv(getpid(), &local, 1, &remote, 1, 0);
+    if (copied < 0 && errno == ENOSYS) return ReviewPipeCopy(destination, source, bytes);
     if (copied < 0 && errno != EFAULT) throw std::runtime_error("guest path: process_vm_readv failed with errno " + std::to_string(errno));
     return copied >= 0 && static_cast<std::size_t>(copied) == bytes;
 #elif defined(__APPLE__)
@@ -840,6 +858,7 @@ extern "C" bool GuestCopyOut_nid_no_patch(void* destination, const void* source,
     iovec local{const_cast<void*>(source), bytes};
     iovec remote{destination, bytes};
     const ssize_t copied = ::process_vm_writev(::getpid(), &local, 1, &remote, 1, 0);
+    if (copied < 0 && errno == ENOSYS) return ReviewPipeCopy(destination, source, bytes);
     if (copied < 0) {
         if (errno == EFAULT) return false;
         throw std::runtime_error("GuestCopyOut: process_vm_writev failed with errno " + std::to_string(errno));

Not built or run: macOS. No title or homebrew was run.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5113591442 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/14931). Originally posted by [w4rc0n](https://github.com/w4rc0n) on 2026-11-02T01:33:03Z. --- ### What `WTF::FileSystemImpl`'s file-handle functions were `NotImplemented` stubs. Guest WebKit code that opened, sought in, truncated or closed a file threw. Six of them now follow the pinned PS5 WebKit 11.x [`FileSystemPOSIX.cpp:57-129`](https://github.com/neonmodder123/PS5-WebKit-11.x/blob/80f77e94c63ee7202eec3d4b5b1a021dd89011ba/Source/WTF/wtf/posix/FileSystemPOSIX.cpp#L57-L129) and [`FileSystem.cpp:371-394`](https://github.com/neonmodder123/PS5-WebKit-11.x/blob/80f77e94c63ee7202eec3d4b5b1a021dd89011ba/Source/WTF/wtf/FileSystem.cpp#L371-L394): `openFile`, `closeFile`, `seekFile`, `truncateFile`, `openAndLockFile` and `unlockAndCloseFile`. - **Real guest descriptors.** Each function calls libkernel's existing guest `open`, `close`, `lseek` and `ftruncate` exports with the guest flag values and guest `errno`, as `libScePosixForWebKit` already does. The handles are ordinary guest descriptors, so they work with `sceKernel*` calls in both directions. `PlatformFileHandle` is an `int` (-1 when invalid) on every host ([`FileSystem.h:62`](https://github.com/neonmodder123/PS5-WebKit-11.x/blob/80f77e94c63ee7202eec3d4b5b1a021dd89011ba/Source/WTF/wtf/FileSystem.h#L62)). - The path goes through `String::utf8`. - The modes are `Read` = `O_RDONLY`, `Truncate` = `O_WRONLY|O_CREAT|O_TRUNC` and `ReadWrite` = `O_RDWR|O_CREAT`. `failIfFileExists` adds `O_CREAT|O_EXCL`. - The permissions are 0600 or 0666. - `closeFile` sets the caller's handle to -1. `seekFile` maps the three origins, and `truncateFile` returns whether `ftruncate` succeeded. - **No locking.** `openAndLockFile` and `unlockAndCloseFile` only open and close. `USE_FILE_LOCK` is off for PlayStation ([`PlatformUse.h:93`](https://github.com/neonmodder123/PS5-WebKit-11.x/blob/80f77e94c63ee7202eec3d4b5b1a021dd89011ba/Source/WTF/wtf/PlatformUse.h#L93)), so the source takes no lock. - **Linking.** `libSceNKWebKit` now links `libkernel` (PRIVATE) and calls these exports by NID. It adds no new cross-library helper and no host descriptor bypass. Paths, directories, links, `realPath`, `MappedFileData` and `filesHaveSameVolume` are later work. `filesHaveSameVolume` depends on a question about how volume identity is reported, recorded in `docs/dev/debt/libkernel.md`. **Adapted source.** oneandonlydean's commit `6a73e56e1e` moved the six functions, unchanged, into `src/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.cpp`](https://github.com/neonmodder123/PS5-WebKit-11.x/blob/80f77e94c63ee7202eec3d4b5b1a021dd89011ba/Source/WTF/wtf/posix/FileSystemPOSIX.cpp) for `openFile`, `closeFile`, `seekFile` and `truncateFile`, and [`FileSystem.cpp`](https://github.com/neonmodder123/PS5-WebKit-11.x/blob/80f77e94c63ee7202eec3d4b5b1a021dd89011ba/Source/WTF/wtf/FileSystem.cpp) for `openAndLockFile` and `unlockAndCloseFile`. `tools/pr_overlap.py` on this head, with `main` at `0eba5db30d`: no other open PR changes these exports or adds the same files. For the PRs it couldn't compare because they no longer merge with `main`, 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 <!-- OS, title or homebrew, what was checked. "Not tested" is a valid answer. A performance change: the summary lines of main and of this PR from the same machine and scene, with the traces attached, captured as the Performance report issue form describes. --> Debian 12, GCC 12.2, Linux 6.18, Release, at the head `6a73e56e1ea36b4e77ebb3a8d30a5bb13498af68`: oneandonlydean's commit that moves these functions into `src/WtfFileSystem.cpp`, on top of `0efdf47930434f6317c4a572ea0af7cf501e0095`. The selection was the thirteen NKWebKit tests (`nkwebkit_constants` and upstream's newer `nkwebkit_fastbitvector`, `nkwebkit_resourceresponse`, `guest_nkwebkit_urls` and `nkwebkit_palsessionid` included), `public_headers` and `patched_libraries`. The full `libs` target was built so that `patched_libraries` could run. - **Unmodified:** 14 of 15 pass, including `patched_libraries`. `nkwebkit_wtf` aborts with `guest path: process_vm_readv failed with errno 38`. The kernel of this machine has no `process_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. - **With a local fallback for that copy (below, not part of this PR):** 15 of 15 pass. The new `nkwebkit_wtf` cases cover: - each open mode with the source's flags; - exclusive create on an existing file failing, and the two permission modes; - a Unicode path through a guest alias; - seeks from each origin, and truncation; - `closeFile` invalidating the handle, and failures returning -1 or false; - a descriptor from `openFile` used with the guest `read` and `write` exports, and one from the guest `open` export closed by `closeFile`. - At the head, the patched `libSceNKWebKit.prx` lists `libkernel.prx` as needed, and `LD_LIBRARY_PATH=build/core/libs/libs ldd -r` reports no undefined symbols. - `tools/progress.py`: the six exports count as implemented (libSceNKWebKit 1318, 1312 on `main`). - `tools/check_conventions.py` passes. - **Windows (GitHub-hosted CI in the author's fork):** [run 41376713519](https://github.com/w4rc0n/AnyPS5/actions/runs/41376713519) built `feat/nkwebkit-filesystem-paths` at its previous head `d82592c45b330f97325194d1223c930fb41e1ab9` and [run 41376721923](https://github.com/w4rc0n/AnyPS5/actions/runs/41376721923) built `feat/nkwebkit-filesystem-mapped` at its previous head `597d4921755bc7184edc292d2fd80210f030af69`, which both contain this PR's commit. It is AnyPS5's `Build` workflow, dispatched in the author's fork with `select=true`: the branch merged into `main` at `93dbd0f82aea684e95f15f06e7d42c0064af18cf`, built on `windows-latest` with WinLibs GCC 15.2 (MinGW-w64, UCRT). None of the 672 selected tests failed; 6 AGC tests were skipped, which `check_skips.py` accepts. That includes the nine NKWebKit tests, `public_headers` and `patched_libraries`. The first attempt of run 41376713519 timed out two unrelated `check_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 onto `main` (now `0eba5db30d8a3d03789e52e5c1a9ff853e4e33e4`, after #14479, #15228, #13766, #14925 and #15911) changed only `docs/dev/debt/libSceNKWebKit.md`, so `git range-diff` shows 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 into `src/WtfFileSystem.cpp` with their notices. - **Linux, unmodified, on a normal kernel (GitHub-hosted CI in the author's fork):** a fork-only workflow, not part of this PR ([run 41618954287](https://github.com/w4rc0n/AnyPS5/actions/runs/41618954287)), built this branch's previous head `4179fef3b47aed47e6ace92a1178c9b8cb69948c` with the full `libs` target on `ubuntu-latest` (Ubuntu 24.04, kernel 7.0, GCC 13.3). 13 of 13 pass, including `nkwebkit_wtf` and `patched_libraries`. The later rebases onto `main` (now `0eba5db30d8a3d03789e52e5c1a9ff853e4e33e4`, after #13766, #14925 and #15911) changed only `docs/dev/debt/libSceNKWebKit.md`, so `git range-diff` shows the code and tests under test are the same as at that run. The commit added since, `6a73e56e1e`, only moves these functions into `src/WtfFileSystem.cpp` with their notices. <details><summary>Local fallback used for the second run (not in this PR)</summary> ```diff diff --git a/core/libs/prx/libc/src/General.cpp b/core/libs/prx/libc/src/General.cpp index 9ed57a5fb0..dbb7e1201b 100644 --- a/core/libs/prx/libc/src/General.cpp +++ b/core/libs/prx/libc/src/General.cpp @@ -83,6 +83,23 @@ std::size_t HostPageSize() { return size; } +static bool ReviewPipeCopy(void* destination, const void* source, std::size_t bytes) { + int fds[2]; + if (::pipe(fds) != 0) throw std::runtime_error("review shim: pipe failed"); + bool ok = true; + for (std::size_t done = 0; done < bytes;) { + const std::size_t chunk = std::min<std::size_t>(bytes - done, 4096); + const ssize_t written = ::write(fds[1], static_cast<const char*>(source) + done, chunk); + if (written <= 0) { ok = false; break; } + const ssize_t read = ::read(fds[0], static_cast<char*>(destination) + done, static_cast<std::size_t>(written)); + if (read != written) { ok = false; break; } + done += static_cast<std::size_t>(written); + } + ::close(fds[0]); + ::close(fds[1]); + return ok; +} + bool CopyGuestBytes(void* destination, const void* source, std::size_t bytes) { GuestArena::GuestArenaPrepareHostRead_nid_no_patch(source, bytes); #ifdef _WIN32 @@ -92,6 +109,7 @@ bool CopyGuestBytes(void* destination, const void* source, std::size_t bytes) { iovec local{destination, bytes}; iovec remote{const_cast<void*>(source), bytes}; const auto copied = process_vm_readv(getpid(), &local, 1, &remote, 1, 0); + if (copied < 0 && errno == ENOSYS) return ReviewPipeCopy(destination, source, bytes); if (copied < 0 && errno != EFAULT) throw std::runtime_error("guest path: process_vm_readv failed with errno " + std::to_string(errno)); return copied >= 0 && static_cast<std::size_t>(copied) == bytes; #elif defined(__APPLE__) @@ -840,6 +858,7 @@ extern "C" bool GuestCopyOut_nid_no_patch(void* destination, const void* source, iovec local{const_cast<void*>(source), bytes}; iovec remote{destination, bytes}; const ssize_t copied = ::process_vm_writev(::getpid(), &local, 1, &remote, 1, 0); + if (copied < 0 && errno == ENOSYS) return ReviewPipeCopy(destination, source, bytes); if (copied < 0) { if (errno == EFAULT) return false; throw std::runtime_error("GuestCopyOut: process_vm_writev failed with errno " + std::to_string(errno)); ``` </details> Not built or run: macOS. No title or homebrew was run. ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes
XairRrR commented 2026-11-03 10:07:09 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by XairRrR on 2026-11-03T10:07:09Z.

Review: APPROVED


Reviewed — approved

The six WTF::FileSystemImpl file-handle exports follow the cited PS5 WebKit 11.x source and run through the existing guest libkernel exports. The new nkwebkit_wtf cases pass, and they fail when the open flags are changed.

What I ran

Head 4179fef3b47aed47e6ace92a1178c9b8cb69948c, merged with --no-ff into main 4f41f4c375f5abb487dbd184fbc150f31994d762 (merged tree 628dc6ce6da18b2d2c905ddf6e67b43c180fe1bc). Debian 13 VM, 2× Xeon Gold 6136, GCC 14.2.0, Release, Ninja.

git diff --check 4f41f4c375f5abb487dbd184fbc150f31994d762...4179fef3b47aed47e6ace92a1178c9b8cb69948c
python3 tools/check_conventions.py --base 4f41f4c375f5abb487dbd184fbc150f31994d762
ctest --test-dir build -R "^nkwebkit_wtf$|^patched_libraries$|^public_headers$" --output-on-failure -j8 --test-load 32
# negative control (details below): rebuilt WtfSystem.cpp.o and libSceNKWebKit.prx with the commands from `ninja -t commands nkwebkit_wtf_tests`
build/tests/nkwebkit_wtf_tests
git status --porcelain

I also recounted the inventory stubs on main and on the merged tree with a small Python script over InventoryExports.hpp, Api.hpp and Export.cpp.

Results

Check Result
git diff --check clean
check_conventions.py All conventions checks passed
Configure, build, libs (script) ok
Selected tests (script) 831 ran: 828 passed, 2 skipped (accepted by check_skips.py), 1 known failure on main (unwrap_self_UnwrapTest_test_new_output_inherits_the_destination_directory_group); no new failures, no timeouts
nkwebkit_wtf, patched_libraries, public_headers (my rerun) 3/3 passed; nkwebkit_wtf in 0.01 s
Debt counts Merged tree: 126 Api.hpp stubs and 7421 inventory stubs, the same as the new text. On main the prose said 7437, but the real count was 7426, so the PR also fixes a stale number.

This machine has a normal kernel. nkwebkit_wtf reaches the file cases without the local process_vm_readv fallback described in the PR, which agrees with the author's Linux CI run.

Negative control

Full revert. Restoring all six production files from main would only break compilation of the test, because main declares the exports with no parameters. Restoring CMakeLists.txt also starts a CMake reconfigure, and that reconfigure fails in this sandbox (configure_file: Operation not permitted in SDL2). So I used a mutation instead.

Mutation. In src/WtfSystem.cpp I removed SCE_KERNEL_O_TRUNC from the Truncate mode. Then I rebuilt WtfSystem.cpp.o and libSceNKWebKit.prx with ninja's recorded commands:

  • With the mutation: nkwebkit_wtf_tests aborts (exit 134) right after the flags=0x201 open (O_WRONLY|O_CREAT with no trunc), the case that expects the file to be emptied.
  • With the merged file restored and rebuilt the same way: the test passes (exit 0).
  • git status --porcelain is empty afterwards.

Because CMakeLists.txt was rewritten with the same content, the build directory will rerun CMake on its next ninja call.

Findings

Blocking

None.

Non-blocking

  • Unreachable null check (core/libs/prx/libSceNKWebKit/src/WtfSystem.cpp:76). ToUTF8 always returns a buffer: it ends with CopyCString(bytes.data(), bytes.size()), and std::string::data() is never null. So if (!representation.buffer) return -1; never runs. The nullPath test case (tests/Wtf.cpp:403-404) returns -1 only because the guest open("") fails with ENOENT. Upstream's isNull() 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.
  • Placement question still open. oneandonlydean asked whether this code counts as adapted third-party code under the 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:

  • Mangled signatures: (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.
  • Behaviour: the mode flags, the 0600/0666 permissions, the failIfFileExists handling, the -1 invalidation in closeFile, the seek origins and the !ftruncate result all match FileSystemPOSIX.cpp:57-129. openAndLockFile uses the default FileAccessPermission::All and passes failIfFileExists=false, as in FileSystem.cpp:371-394.
  • Memory: the temporary UTF-8 CString is released by its destructor.
  • Rules: the functions hold no state, the PR adds no code comments, and the debt entries are reduced rather than rewritten.

Not verified

  • Windows and macOS. I relied on the author's fork CI runs for Windows.
  • I did not check behaviour against a real PS5 libSceNKWebKit.
  • I did not run a full revert of the production files, because the sandbox cannot reconfigure CMake (see "Negative control").
<!-- greyfinch-sync:boykopovar/AnyPS5:review:5750300150 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/14931#pullrequestreview-5750300150). Originally posted by [XairRrR](https://github.com/XairRrR) on 2026-11-03T10:07:09Z. **Review:** APPROVED --- # Reviewed — approved The six `WTF::FileSystemImpl` file-handle exports follow the cited PS5 WebKit 11.x source and run through the existing guest libkernel exports. The new `nkwebkit_wtf` cases pass, and they fail when the open flags are changed. ## What I ran Head `4179fef3b47aed47e6ace92a1178c9b8cb69948c`, merged with `--no-ff` into `main` `4f41f4c375f5abb487dbd184fbc150f31994d762` (merged tree `628dc6ce6da18b2d2c905ddf6e67b43c180fe1bc`). Debian 13 VM, 2× Xeon Gold 6136, GCC 14.2.0, Release, Ninja. ``` git diff --check 4f41f4c375f5abb487dbd184fbc150f31994d762...4179fef3b47aed47e6ace92a1178c9b8cb69948c python3 tools/check_conventions.py --base 4f41f4c375f5abb487dbd184fbc150f31994d762 ctest --test-dir build -R "^nkwebkit_wtf$|^patched_libraries$|^public_headers$" --output-on-failure -j8 --test-load 32 # negative control (details below): rebuilt WtfSystem.cpp.o and libSceNKWebKit.prx with the commands from `ninja -t commands nkwebkit_wtf_tests` build/tests/nkwebkit_wtf_tests git status --porcelain ``` I also recounted the inventory stubs on `main` and on the merged tree with a small Python script over `InventoryExports.hpp`, `Api.hpp` and `Export.cpp`. ## Results | Check | Result | |---|---| | `git diff --check` | clean | | `check_conventions.py` | All conventions checks passed | | Configure, build, `libs` (script) | ok | | Selected tests (script) | 831 ran: 828 passed, 2 skipped (accepted by `check_skips.py`), 1 known failure on `main` (`unwrap_self_UnwrapTest_test_new_output_inherits_the_destination_directory_group`); no new failures, no timeouts | | `nkwebkit_wtf`, `patched_libraries`, `public_headers` (my rerun) | 3/3 passed; `nkwebkit_wtf` in 0.01 s | | Debt counts | Merged tree: 126 `Api.hpp` stubs and 7421 inventory stubs, the same as the new text. On `main` the prose said 7437, but the real count was 7426, so the PR also fixes a stale number. | This machine has a normal kernel. `nkwebkit_wtf` reaches the file cases without the local `process_vm_readv` fallback described in the PR, which agrees with the author's Linux CI run. ## Negative control **Full revert.** Restoring all six production files from `main` would only break compilation of the test, because `main` declares the exports with no parameters. Restoring `CMakeLists.txt` also starts a CMake reconfigure, and that reconfigure fails in this sandbox (`configure_file: Operation not permitted` in SDL2). So I used a mutation instead. **Mutation.** In `src/WtfSystem.cpp` I removed `SCE_KERNEL_O_TRUNC` from the `Truncate` mode. Then I rebuilt `WtfSystem.cpp.o` and `libSceNKWebKit.prx` with ninja's recorded commands: - With the mutation: `nkwebkit_wtf_tests` **aborts** (exit 134) right after the `flags=0x201` open (`O_WRONLY|O_CREAT` with no trunc), the case that expects the file to be emptied. - With the merged file restored and rebuilt the same way: the test passes (exit 0). - `git status --porcelain` is empty afterwards. Because `CMakeLists.txt` was rewritten with the same content, the build directory will rerun CMake on its next `ninja` call. ## Findings ### Blocking None. ### Non-blocking - **Unreachable null check** (`core/libs/prx/libSceNKWebKit/src/WtfSystem.cpp:76`). `ToUTF8` always returns a buffer: it ends with `CopyCString(bytes.data(), bytes.size())`, and `std::string::data()` is never null. So `if (!representation.buffer) return -1;` never runs. The `nullPath` test case (`tests/Wtf.cpp:403-404`) returns -1 only because the guest `open("")` fails with `ENOENT`. Upstream's `isNull()` 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. - **Placement question still open.** oneandonlydean asked whether this code counts as adapted third-party code under the `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: - **Mangled signatures:** `(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. - **Behaviour:** the mode flags, the 0600/0666 permissions, the `failIfFileExists` handling, the `-1` invalidation in `closeFile`, the seek origins and the `!ftruncate` result all match `FileSystemPOSIX.cpp:57-129`. `openAndLockFile` uses the default `FileAccessPermission::All` and passes `failIfFileExists=false`, as in `FileSystem.cpp:371-394`. - **Memory:** the temporary UTF-8 `CString` is released by its destructor. - **Rules:** the functions hold no state, the PR adds no code comments, and the debt entries are reduced rather than rewritten. ## Not verified - Windows and macOS. I relied on the author's fork CI runs for Windows. - I did not check behaviour against a real PS5 `libSceNKWebKit`. - I did not run a full revert of the production files, because the sandbox cannot reconfigure CMake (see "Negative control"). <!-- anyps5-bots job=2749 head=4179fef3b47aed47e6ace92a1178c9b8cb69948c -->

Pull request closed

Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!14931
No description provided.