feat(libSceNKWebKit): implement WTF::FileSystemImpl::MappedFileData #14932

Merged
w4rc0n merged 3 commits from upstream-pr/14932 into main 2026-11-07 05:43:37 +00:00
w4rc0n commented 2026-11-02 01:33:10 +00:00 (Migrated from github.com)

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


What

WTF::FileSystemImpl::MappedFileData was a set of NotImplemented stubs, so guest WebKit code that memory-mapped a file threw. Its seven exports now follow the pinned PS5 WebKit 11.x FileSystem.cpp:313-368: mapFileHandle, the four constructors and both destructors.

  • Layout: the guest object is a pointer and an unsigned size, 16 bytes (FileSystem.h:270). It is pinned with static_assert and isn't a host handle.
  • Mapping: done through libkernel's guest fstat, mmap and munmap, so flags, alignment and bookkeeping follow the rest of the guest, as for #14931's handles.
    • A negative size, or one above UINT_MAX, fails.
    • A zero-length file succeeds without mapping anything.
    • Read, write and read-write protections follow the source, with shared or private mappings.
    • Fields are set only when the mapping succeeds.
  • Lifetime: the path constructors open and close the file with #14931's functions, and the mapping outlives the descriptor. The destructors unmap a non-null mapping.

The debt entry records two gaps:

  • Mapping a file inside the app archive terminates the process: guest mmap is noexcept, and libkernel's archive refusal throws through NotImplemented_nid_no_patch. The pinned source reports a failed mapping with success = false instead. #11625 adds archive-backed mapping.
  • The PS5 build routes mmap through an SDK wrapper (OptionsPlayStation.cmake). That wrapper isn't in the pinned source, so anything extra it does is unverified.

isSafeToUseMemoryMapForPath and makeSafeToUseMemoryMapForPath are left to #13930.

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, #14172, #14607, #14981, #15011, #15214, #15215, #15241 and #15498 change nearby lines in the same files; whichever merges later keeps both sides. The only exports it shares are with #14949, in the same stack.

Tested

Debian 12, GCC 12.2, Linux 6.18, Release, at the head 037877846880dfc8aba13ef6fd84bc1382189f2d, which is on #14931's head 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.

  • Unmodified: 14 of 15 pass, including patched_libraries. nkwebkit_wtf aborts with guest path: process_vm_readv failed with errno 38, because this machine's kernel has no process_vm_readv. The Linux CI run below reaches it.
  • With the local fallback below (not part of this PR): 15 of 15 pass. The new nkwebkit_wtf cases cover:
    • an invalid descriptor and a missing path;
    • an empty file;
    • a read-only mapping, and a mapping that outlives its descriptor;
    • the mapping being gone after the destructor, checked with a virtual-memory query;
    • shared writable mappings writing through to the file, and private mappings staying isolated;
    • write-only protection on a read-write descriptor, and a shared writable mapping refused on a read-only descriptor;
    • both path constructors, and a direct mapFileHandle;
    • a sparse file larger than unsigned being rejected (not run on Windows).
  • At the head, libSceNKWebKit.prx lists libkernel.prx as needed, and ldd -r reports no undefined symbols.
  • tools/progress.py: the seven exports count as implemented (libSceNKWebKit 1325, against 1318 with #14931).
  • tools/check_conventions.py passes.
  • Windows (GitHub-hosted CI in the author's fork): run 41376721923 built this branch's previous head 597d4921755bc7184edc292d2fd80210f030af69. 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 later rebases onto main (now 0eba5db30d8a3d03789e52e5c1a9ff853e4e33e4, after #14479, #15228, #13766, #14925 and #15911) and the debt wording change from review 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.
  • 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 e403b976014319fc79978786c071579efd2ee79a 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.
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: #14931
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5113592263 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/14932). Originally posted by [w4rc0n](https://github.com/w4rc0n) on 2026-11-02T01:33:10Z. --- ### What `WTF::FileSystemImpl::MappedFileData` was a set of `NotImplemented` stubs, so guest WebKit code that memory-mapped a file threw. Its seven exports now follow the pinned PS5 WebKit 11.x [`FileSystem.cpp:313-368`](https://github.com/neonmodder123/PS5-WebKit-11.x/blob/80f77e94c63ee7202eec3d4b5b1a021dd89011ba/Source/WTF/wtf/FileSystem.cpp#L313-L368): `mapFileHandle`, the four constructors and both destructors. - **Layout:** the guest object is a pointer and an `unsigned` size, 16 bytes ([`FileSystem.h:270`](https://github.com/neonmodder123/PS5-WebKit-11.x/blob/80f77e94c63ee7202eec3d4b5b1a021dd89011ba/Source/WTF/wtf/FileSystem.h#L243-L274)). It is pinned with `static_assert` and isn't a host handle. - **Mapping:** done through libkernel's guest `fstat`, `mmap` and `munmap`, so flags, alignment and bookkeeping follow the rest of the guest, as for #14931's handles. - A negative size, or one above `UINT_MAX`, fails. - A zero-length file succeeds without mapping anything. - Read, write and read-write protections follow the source, with shared or private mappings. - Fields are set only when the mapping succeeds. - **Lifetime:** the path constructors open and close the file with #14931's functions, and the mapping outlives the descriptor. The destructors unmap a non-null mapping. The debt entry records two gaps: - Mapping a file inside the app archive terminates the process: guest `mmap` is `noexcept`, and libkernel's archive refusal throws through `NotImplemented_nid_no_patch`. The pinned source reports a failed mapping with `success = false` instead. #11625 adds archive-backed mapping. - The PS5 build routes `mmap` through an SDK wrapper (`OptionsPlayStation.cmake`). That wrapper isn't in the pinned source, so anything extra it does is unverified. `isSafeToUseMemoryMapForPath` and `makeSafeToUseMemoryMapForPath` are left to #13930. `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, #14172, #14607, #14981, #15011, #15214, #15215, #15241 and #15498 change nearby lines in the same files; whichever merges later keeps both sides. The only exports it shares are with #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 `037877846880dfc8aba13ef6fd84bc1382189f2d`, which is on #14931's head `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. - **Unmodified:** 14 of 15 pass, including `patched_libraries`. `nkwebkit_wtf` aborts with `guest path: process_vm_readv failed with errno 38`, because this machine's kernel has no `process_vm_readv`. The Linux CI run below reaches it. - **With the local fallback below (not part of this PR):** 15 of 15 pass. The new `nkwebkit_wtf` cases cover: - an invalid descriptor and a missing path; - an empty file; - a read-only mapping, and a mapping that outlives its descriptor; - the mapping being gone after the destructor, checked with a virtual-memory query; - shared writable mappings writing through to the file, and private mappings staying isolated; - write-only protection on a read-write descriptor, and a shared writable mapping refused on a read-only descriptor; - both path constructors, and a direct `mapFileHandle`; - a sparse file larger than `unsigned` being rejected (not run on Windows). - At the head, `libSceNKWebKit.prx` lists `libkernel.prx` as needed, and `ldd -r` reports no undefined symbols. - `tools/progress.py`: the seven exports count as implemented (libSceNKWebKit 1325, against 1318 with #14931). - `tools/check_conventions.py` passes. - **Windows (GitHub-hosted CI in the author's fork):** [run 41376721923](https://github.com/w4rc0n/AnyPS5/actions/runs/41376721923) built this branch's previous head `597d4921755bc7184edc292d2fd80210f030af69`. 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 later rebases onto `main` (now `0eba5db30d8a3d03789e52e5c1a9ff853e4e33e4`, after #14479, #15228, #13766, #14925 and #15911) and the debt wording change from review 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. - **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 `e403b976014319fc79978786c071579efd2ee79a` 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. <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: #14931 - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes
XairRrR commented 2026-11-03 10:06:04 +00:00 (Migrated from github.com)

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

Review: APPROVED


Reviewed — approved

The seven MappedFileData exports follow WebKit's POSIX implementation step for step. They go through the guest fstat/mmap/munmap with the right protection and sharing constants, and the new nkwebkit_wtf cases pass here and fail when the shared and private flags are swapped.

What I ran

  • Head 5f9423c0bc35cd54027b2b13d9942870e05924b2 merged into main 4f41f4c375f5abb487dbd184fbc150f31994d762 with --no-ff, in a clean worktree.
  • Machine: Debian 13 (VM, 32 vCPU), GCC 14.2.0, Release, Ninja.
git diff --check 4f41f4c375f5abb487dbd184fbc150f31994d762...5f9423c0bc35cd54027b2b13d9942870e05924b2
python3 tools/check_conventions.py --base 4f41f4c375f5abb487dbd184fbc150f31994d762
ctest --test-dir build -j8 --test-load 32 --output-on-failure -R "^(nkwebkit_|guest_nkwebkit_|patched_libraries$)"
# negative control 1: production files of libSceNKWebKit restored from main
ninja -C build -j32 -l32 nkwebkit_wtf_tests
# negative control 2: merged tree, with only the MAP_SHARED/MAP_PRIVATE choice in mapFileHandle swapped
ninja -C build -j32 -l32 nkwebkit_wtf_tests libSceNKWebKit
ctest --test-dir build --output-on-failure -R "^nkwebkit_wtf$"
# restored merged files, rebuilt, reran, checked the tree
ninja -C build -j32 -l32 nkwebkit_wtf_tests libSceNKWebKit
ctest --test-dir build --output-on-failure -R "^nkwebkit_wtf$"
git status --porcelain

Results

Check Result
git diff --check clean
check_conventions.py All conventions checks passed
Configure, build, libs (script) ok
Script's selected tests 831 ran, 828 passed, 2 skipped (all expected), no new failures or timeouts. The one known failure (unwrap_self_UnwrapTest_test_new_output_inherits_the_destination_directory_group) also fails on main.
NKWebKit tests + patched_libraries (my run) 12/12 passed; nkwebkit_wtf took 0.02 s
Negative control 1 (production files from main) nkwebkit_wtf_tests doesn't compile ('MappedFileData' is not a member of 'WTF', missing signatures)
Negative control 2 (shared and private swapped) nkwebkit_wtf aborts
After restoring nkwebkit_wtf passes; git status --porcelain is empty; the test leaves no temporary directory behind
Vulkan validation not applicable (no AGC, shader or VideoOut file changed)
Negative control 2 output
[src/Open.cpp:359 sceKernelOpen] path=/nkwebkit-mapped/file.bin flags=0x202 nativeFlags=0x42 mode=0666
0% tests passed, 1 tests failed out of 1
	2867 - nkwebkit_wtf (Subprocess aborted)

Negative control

  • Full revert: I restored Export.cpp, Api.hpp, InventoryExports.hpp, WtfExports.hpp, WtfMemoryTypes.hpp and WtfSystem.cpp from main.
    • I kept the PR's CMakeLists.txt. Changing it makes ninja rerun configure, and SDL2's configure_file fails in the sandbox. Its only change is the extra libkernel link.
    • With these files the test doesn't compile, so it depends on the new code.
  • Mutation: on the merged tree I changed only the mmap flags in mapFileHandle (mapMode == 0 ? 2 : 1).
    • nkwebkit_wtf aborts. The shared write-through and private isolation checks do test the flag choice.
  • Restore: I put back the merged files, rebuilt, and the test passed again.

Findings

Blocking

None.

Non-blocking

  1. The debt entry could say how an archived file fails (docs/dev/debt/libSceNKWebKit.md, "WTF mapped files").
    • The entry says archive-backed mappings "remain unsupported".
    • In practice, mmap_nid_postfix is noexcept and calls File::RefuseArchivedFile (PosixMemory.cpp:145-146, 192 at the PR head). That function throws through NotImplemented_nid_no_patch.
    • So MappedFileData on an app0 file terminates the process. Upstream would return success = false there.
    • This is loud, which the rules accept. Saying "terminates" instead of "unsupported" would state the gap more exactly. This is wording only.
  2. openAndLockFile ignores lockMode (core/libs/prx/libSceNKWebKit/src/WtfSystem.cpp:150).
    • This code is in #14931's commit, which this PR's diff includes. I note it here only because it ships with this PR.
    • Upstream calls lockFile only under USE(FILE_LOCK). Ignoring the lock is correct only if the PlayStation build leaves USE(FILE_LOCK) off.
    • Neither the PR nor the debt file says which. If it is on, this is a silent stub and needs a debt entry or a throw. It is better settled on #14931.
  3. Code placement is still open. I don't repeat oneandonlydean's placement question (adapted source vs. a 3rdparty/ submodule). From reading mapFileHandle (WtfSystem.cpp:75-88), I agree with their description: the sequence matches upstream FileSystem.cpp step for step. The author has said they will apply the answer given on #14921, so this is waiting on a maintainer decision.

Checked and fine

  • Protection and flags: protection Read→1, Write→2, ReadWrite→3, and Shared→MAP_SHARED(1), Private→MAP_PRIVATE(2) match FreeBSD's values and the WebKit enum order.
  • Size checks: a negative size, or one above UINT_MAX, is rejected. This is the same as upstream's convertSafely.
  • Empty file: a zero-size file returns success without mapping.
  • Failed mapping: fields stay unset on MAP_FAILED. The constructors zero *self first, which matches the upstream member initializers.
  • Path constructor: opens read-only, maps, then closes. The test checks that the mapping outlives the descriptor.
  • Destructor: unmaps only a non-null mapping. The test checks this with sceKernelVirtualQuery.
  • openFile: the CString returned by utf8 is RAII (WtfStringAbi.hpp:67), so it doesn't leak.

Not verified

  • macOS and Windows: I built and tested on Linux only. The Windows CI run cited in the description is for an earlier head (597d4921…). I didn't check the claim that only the debt doc changed since then.
  • Pinned WebKit source: I had no network, so I couldn't open the pinned FileSystem.cpp. I compared the code with WebKit's POSIX FileSystem implementation as I know it.
  • USE(FILE_LOCK): I couldn't check whether the PlayStation build enables it (see non-blocking 2).
  • Console behaviour: I didn't check the MappedFileData layout or the __wrap_mmap behaviour against console binaries. The debt entry records both.
<!-- greyfinch-sync:boykopovar/AnyPS5:review:5750284523 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/14932#pullrequestreview-5750284523). Originally posted by [XairRrR](https://github.com/XairRrR) on 2026-11-03T10:06:04Z. **Review:** APPROVED --- # Reviewed — approved The seven `MappedFileData` exports follow WebKit's POSIX implementation step for step. They go through the guest `fstat`/`mmap`/`munmap` with the right protection and sharing constants, and the new `nkwebkit_wtf` cases pass here and fail when the shared and private flags are swapped. ## What I ran - Head `5f9423c0bc35cd54027b2b13d9942870e05924b2` merged into `main` `4f41f4c375f5abb487dbd184fbc150f31994d762` with `--no-ff`, in a clean worktree. - Machine: Debian 13 (VM, 32 vCPU), GCC 14.2.0, Release, Ninja. ``` git diff --check 4f41f4c375f5abb487dbd184fbc150f31994d762...5f9423c0bc35cd54027b2b13d9942870e05924b2 python3 tools/check_conventions.py --base 4f41f4c375f5abb487dbd184fbc150f31994d762 ctest --test-dir build -j8 --test-load 32 --output-on-failure -R "^(nkwebkit_|guest_nkwebkit_|patched_libraries$)" # negative control 1: production files of libSceNKWebKit restored from main ninja -C build -j32 -l32 nkwebkit_wtf_tests # negative control 2: merged tree, with only the MAP_SHARED/MAP_PRIVATE choice in mapFileHandle swapped ninja -C build -j32 -l32 nkwebkit_wtf_tests libSceNKWebKit ctest --test-dir build --output-on-failure -R "^nkwebkit_wtf$" # restored merged files, rebuilt, reran, checked the tree ninja -C build -j32 -l32 nkwebkit_wtf_tests libSceNKWebKit ctest --test-dir build --output-on-failure -R "^nkwebkit_wtf$" git status --porcelain ``` ## Results | Check | Result | |---|---| | `git diff --check` | clean | | `check_conventions.py` | All conventions checks passed | | Configure, build, `libs` (script) | ok | | Script's selected tests | 831 ran, 828 passed, 2 skipped (all expected), no new failures or timeouts. The one known failure (`unwrap_self_UnwrapTest_test_new_output_inherits_the_destination_directory_group`) also fails on `main`. | | NKWebKit tests + `patched_libraries` (my run) | 12/12 passed; `nkwebkit_wtf` took 0.02 s | | Negative control 1 (production files from `main`) | `nkwebkit_wtf_tests` doesn't compile (`'MappedFileData' is not a member of 'WTF'`, missing signatures) | | Negative control 2 (shared and private swapped) | `nkwebkit_wtf` aborts | | After restoring | `nkwebkit_wtf` passes; `git status --porcelain` is empty; the test leaves no temporary directory behind | | Vulkan validation | not applicable (no AGC, shader or VideoOut file changed) | <details><summary>Negative control 2 output</summary> ``` [src/Open.cpp:359 sceKernelOpen] path=/nkwebkit-mapped/file.bin flags=0x202 nativeFlags=0x42 mode=0666 0% tests passed, 1 tests failed out of 1 2867 - nkwebkit_wtf (Subprocess aborted) ``` </details> ## Negative control - **Full revert:** I restored `Export.cpp`, `Api.hpp`, `InventoryExports.hpp`, `WtfExports.hpp`, `WtfMemoryTypes.hpp` and `WtfSystem.cpp` from `main`. - I kept the PR's `CMakeLists.txt`. Changing it makes ninja rerun configure, and SDL2's `configure_file` fails in the sandbox. Its only change is the extra `libkernel` link. - With these files the test doesn't compile, so it depends on the new code. - **Mutation:** on the merged tree I changed only the `mmap` flags in `mapFileHandle` (`mapMode == 0 ? 2 : 1`). - `nkwebkit_wtf` aborts. The shared write-through and private isolation checks do test the flag choice. - **Restore:** I put back the merged files, rebuilt, and the test passed again. ## Findings ### Blocking None. ### Non-blocking 1. **The debt entry could say how an archived file fails** (`docs/dev/debt/libSceNKWebKit.md`, "WTF mapped files"). - The entry says archive-backed mappings "remain unsupported". - In practice, `mmap_nid_postfix` is `noexcept` and calls `File::RefuseArchivedFile` ([PosixMemory.cpp:145-146, 192 at the PR head](https://github.com/boykopovar/AnyPS5/blob/5f9423c0bc35cd54027b2b13d9942870e05924b2/core/libs/prx/libkernel/DirectMemory/PosixMemory.cpp#L145-L192)). That function throws through `NotImplemented_nid_no_patch`. - So `MappedFileData` on an app0 file terminates the process. Upstream would return `success = false` there. - This is loud, which the rules accept. Saying "terminates" instead of "unsupported" would state the gap more exactly. This is wording only. 2. **`openAndLockFile` ignores `lockMode`** (`core/libs/prx/libSceNKWebKit/src/WtfSystem.cpp:150`). - This code is in #14931's commit, which this PR's diff includes. I note it here only because it ships with this PR. - Upstream calls `lockFile` only under `USE(FILE_LOCK)`. Ignoring the lock is correct only if the PlayStation build leaves `USE(FILE_LOCK)` off. - Neither the PR nor the debt file says which. If it is on, this is a silent stub and needs a debt entry or a throw. It is better settled on #14931. 3. **Code placement is still open.** I don't repeat oneandonlydean's placement question (adapted source vs. a `3rdparty/` submodule). From reading `mapFileHandle` (`WtfSystem.cpp:75-88`), I agree with their description: the sequence matches upstream `FileSystem.cpp` step for step. The author has said they will apply the answer given on #14921, so this is waiting on a maintainer decision. ### Checked and fine - **Protection and flags:** protection `Read→1`, `Write→2`, `ReadWrite→3`, and `Shared→MAP_SHARED(1)`, `Private→MAP_PRIVATE(2)` match FreeBSD's values and the WebKit enum order. - **Size checks:** a negative size, or one above `UINT_MAX`, is rejected. This is the same as upstream's `convertSafely`. - **Empty file:** a zero-size file returns success without mapping. - **Failed mapping:** fields stay unset on `MAP_FAILED`. The constructors zero `*self` first, which matches the upstream member initializers. - **Path constructor:** opens read-only, maps, then closes. The test checks that the mapping outlives the descriptor. - **Destructor:** unmaps only a non-null mapping. The test checks this with `sceKernelVirtualQuery`. - **`openFile`:** the `CString` returned by `utf8` is RAII (`WtfStringAbi.hpp:67`), so it doesn't leak. ## Not verified - **macOS and Windows:** I built and tested on Linux only. The Windows CI run cited in the description is for an earlier head (`597d4921…`). I didn't check the claim that only the debt doc changed since then. - **Pinned WebKit source:** I had no network, so I couldn't open the pinned `FileSystem.cpp`. I compared the code with WebKit's POSIX `FileSystem` implementation as I know it. - **`USE(FILE_LOCK)`:** I couldn't check whether the PlayStation build enables it (see non-blocking 2). - **Console behaviour:** I didn't check the `MappedFileData` layout or the `__wrap_mmap` behaviour against console binaries. The debt entry records both. <!-- anyps5-bots job=2748 head=5f9423c0bc35cd54027b2b13d9942870e05924b2 -->
XairRrR commented 2026-11-03 10:51:21 +00:00 (Migrated from github.com)

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

Review: APPROVED


Re-checked — approved

The only change since 5f9423c0 is a one-line rewording of the "WTF mapped files" debt entry. It now says that mapping an archived file terminates the process, which matches libkernel's code.

What changed since my last review

  • git range-diff shows that commit 1 (4179fef3b4) is identical.
  • Commit 2 differs from 5f9423c0bc by one line in docs/dev/debt/libSceNKWebKit.md.
    • git diff --stat 5f9423c0bc35cd54027b2b13d9942870e05924b2 e403b976014319fc79978786c071579efd2ee79a shows only that file, 1 line added and 1 removed.
    • No code or test changed.
  • The author replied to my three findings (discussion, 2026-11-03).

What I ran

  • Head: e403b976014319fc79978786c071579efd2ee79a
  • main: 4f41f4c375f5abb487dbd184fbc150f31994d762
  • The script merged the head into main with --no-ff in a clean worktree, then built it and ran the selected tests.
git diff --check 4f41f4c375f5abb487dbd184fbc150f31994d762...e403b976014319fc79978786c071579efd2ee79a
python3 tools/check_conventions.py --base 4f41f4c375f5abb487dbd184fbc150f31994d762
git range-diff 4f41f4c375f5abb487dbd184fbc150f31994d762 5f9423c0bc35cd54027b2b13d9942870e05924b2 e403b976014319fc79978786c071579efd2ee79a
git diff --stat 5f9423c0bc35cd54027b2b13d9942870e05924b2 e403b976014319fc79978786c071579efd2ee79a
ctest --test-dir build -j8 --test-load 32 --output-on-failure -R "^(nkwebkit_|guest_nkwebkit_|patched_libraries$)"
git status --porcelain
Check Result
git diff --check clean
check_conventions.py All conventions checks passed
Configure, build, libs (script) ok
Script's selected tests 831 ran, 828 passed, 2 skipped (all expected). No new failures or timeouts. The one known failure, unwrap_self_UnwrapTest_test_new_output_inherits_the_destination_directory_group, also fails on main.
NKWebKit tests and patched_libraries (my run) 12/12 passed
git status --porcelain empty

Negative control: I didn't run it again. The tests and production code are byte-identical to 5f9423c0. In my previous review, nkwebkit_wtf failed both with the production files restored from main and with the shared and private flags swapped.

Previous findings

  1. Debt entry should say how an archived file fails: Resolved.
    • The entry now says the process terminates, because guest mmap_nid_postfix is noexcept and File::RefuseArchivedFile throws through NotImplemented_nid_no_patch.
    • The code at the head matches this:
  2. openAndLockFile ignores lockMode: No longer applies to this PR.
    • The author cites PlatformUse.h:93 in the pinned source: USE(FILE_LOCK) is off for PlayStation, so upstream takes no lock either.
    • I had no network and couldn't open that line, so I accept it as author-reported.
    • This code belongs to #14931's commit, where it is documented.
  3. Code placement (in-tree adapted source vs. a 3rdparty/ submodule): Still open, but not on the author.
    • The author has said they will apply the maintainer's answer from #14921. This remains a maintainer decision and doesn't block this review.

New findings

Blocking

None.

Non-blocking

None.

Not verified

  • Pinned source: with no network, I couldn't check the PlatformUse.h:93 citation for USE(FILE_LOCK).
  • Other platforms: I built and tested on Linux only, not macOS or Windows. The author's Windows CI run was at 597d4921. The range-diff above confirms that the code is unchanged between 5f9423c0 and this head. I didn't compare 597d4921 itself.
  • Console: the MappedFileData layout and the __wrap_mmap behaviour haven't been checked against console binaries. The debt entry records both.
<!-- greyfinch-sync:boykopovar/AnyPS5:review:5750871316 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/14932#pullrequestreview-5750871316). Originally posted by [XairRrR](https://github.com/XairRrR) on 2026-11-03T10:51:21Z. **Review:** APPROVED --- # Re-checked — approved The only change since `5f9423c0` is a one-line rewording of the "WTF mapped files" debt entry. It now says that mapping an archived file terminates the process, which matches libkernel's code. ## What changed since my last review - `git range-diff` shows that commit 1 (`4179fef3b4`) is identical. - Commit 2 differs from `5f9423c0bc` by one line in `docs/dev/debt/libSceNKWebKit.md`. - `git diff --stat 5f9423c0bc35cd54027b2b13d9942870e05924b2 e403b976014319fc79978786c071579efd2ee79a` shows only that file, 1 line added and 1 removed. - No code or test changed. - The author replied to my three findings (discussion, 2026-11-03). ## What I ran - Head: `e403b976014319fc79978786c071579efd2ee79a` - `main`: `4f41f4c375f5abb487dbd184fbc150f31994d762` - The script merged the head into `main` with `--no-ff` in a clean worktree, then built it and ran the selected tests. ``` git diff --check 4f41f4c375f5abb487dbd184fbc150f31994d762...e403b976014319fc79978786c071579efd2ee79a python3 tools/check_conventions.py --base 4f41f4c375f5abb487dbd184fbc150f31994d762 git range-diff 4f41f4c375f5abb487dbd184fbc150f31994d762 5f9423c0bc35cd54027b2b13d9942870e05924b2 e403b976014319fc79978786c071579efd2ee79a git diff --stat 5f9423c0bc35cd54027b2b13d9942870e05924b2 e403b976014319fc79978786c071579efd2ee79a ctest --test-dir build -j8 --test-load 32 --output-on-failure -R "^(nkwebkit_|guest_nkwebkit_|patched_libraries$)" git status --porcelain ``` | Check | Result | |---|---| | `git diff --check` | clean | | `check_conventions.py` | All conventions checks passed | | Configure, build, `libs` (script) | ok | | Script's selected tests | 831 ran, 828 passed, 2 skipped (all expected). No new failures or timeouts. The one known failure, `unwrap_self_UnwrapTest_test_new_output_inherits_the_destination_directory_group`, also fails on `main`. | | NKWebKit tests and `patched_libraries` (my run) | 12/12 passed | | `git status --porcelain` | empty | **Negative control:** I didn't run it again. The tests and production code are byte-identical to `5f9423c0`. In my previous review, `nkwebkit_wtf` failed both with the production files restored from `main` and with the shared and private flags swapped. ## Previous findings 1. **Debt entry should say how an archived file fails: Resolved.** - The entry now says the process terminates, because guest `mmap_nid_postfix` is `noexcept` and `File::RefuseArchivedFile` throws through `NotImplemented_nid_no_patch`. - The code at the head matches this: - [PosixMemory.cpp:145-146](https://github.com/boykopovar/AnyPS5/blob/e403b976014319fc79978786c071579efd2ee79a/core/libs/prx/libkernel/DirectMemory/PosixMemory.cpp#L145-L146) declares `mmap_nid_postfix ... noexcept`. - [PosixMemory.cpp:192](https://github.com/boykopovar/AnyPS5/blob/e403b976014319fc79978786c071579efd2ee79a/core/libs/prx/libkernel/DirectMemory/PosixMemory.cpp#L192) calls `File::RefuseArchivedFile(descriptor, "mmap")`. - [ArchivedFile.cpp:63-65](https://github.com/boykopovar/AnyPS5/blob/e403b976014319fc79978786c071579efd2ee79a/core/libs/prx/libkernel/File/src/ArchivedFile.cpp#L63-L65) calls `NotImplemented_nid_no_patch` for an archived descriptor. 2. **`openAndLockFile` ignores `lockMode`: No longer applies to this PR.** - The author cites [`PlatformUse.h:93`](https://github.com/neonmodder123/PS5-WebKit-11.x/blob/80f77e94c63ee7202eec3d4b5b1a021dd89011ba/Source/WTF/wtf/PlatformUse.h#L93) in the pinned source: `USE(FILE_LOCK)` is off for PlayStation, so upstream takes no lock either. - I had no network and couldn't open that line, so I accept it as author-reported. - This code belongs to #14931's commit, where it is documented. 3. **Code placement (in-tree adapted source vs. a `3rdparty/` submodule): Still open, but not on the author.** - The author has said they will apply the maintainer's answer from #14921. This remains a maintainer decision and doesn't block this review. ## New findings ### Blocking None. ### Non-blocking None. ## Not verified - **Pinned source:** with no network, I couldn't check the `PlatformUse.h:93` citation for `USE(FILE_LOCK)`. - **Other platforms:** I built and tested on Linux only, not macOS or Windows. The author's Windows CI run was at `597d4921`. The range-diff above confirms that the code is unchanged between `5f9423c0` and this head. I didn't compare `597d4921` itself. - **Console:** the `MappedFileData` layout and the `__wrap_mmap` behaviour haven't been checked against console binaries. The debt entry records both. <!-- anyps5-bots job=3290 head=e403b976014319fc79978786c071579efd2ee79a -->
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!14932
No description provided.