feat(libSceNKWebKit): implement WTF external strings #14920

Closed
w4rc0n wants to merge 4 commits from upstream-pr/14920 into main
w4rc0n commented 2026-11-02 01:31:48 +00:00 (Migrated from github.com)

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


What

WTF::ExternalStringImpl::create was a NotImplemented stub in both its 8-bit and 16-bit forms. The destruction from #14917, and the atom and symbol paths from #14918 and #14919, also threw for external buffers. WebKit wraps buffers it doesn't own this way, so those paths stopped. Both exports now follow the pinned PS5 WebKit 11.x source:

  • Creation follows ExternalStringImpl.cpp:31-55. The string keeps the caller's characters without copying them and marks them BufferExternal. It takes ownership of the caller's WTF::Function free function, a single pointer that is set to null in the caller.
  • The free function is Function<void(ExternalStringImpl*, void*, unsigned)> (ExternalStringImpl.h:35). Its wrapper and vtable belong to the guest.
    • Slot 2 is call, slot 1 is the deleting destructor (Function.h:37-103).
    • Both are called through APS5_VABI function pointers.
  • Destruction follows StringImpl.cpp:140-145:
    • the free function is called with the string, its buffer and sizeInBytes() (the 24-byte header plus length times character width, narrowed to unsigned);
    • then the guest's wrapper is destroyed, then the host header is freed.
  • Layout: ExternalStringImpl is 32 bytes, with the free function at offset 24, pinned with static_assert.
  • Ownership: substrings, atoms and symbols now hold external owners as they do any other owner, so "external" drops out of their debt entries.
  • Throws: null characters, zero length and a null free function throw, where the pinned constructors assert. The debt entry names this.

Registered symbols stay unsupported.

Adapted source: none in this PR's own code. Its change to AddAtom applies in src/WtfAtoms.cpp, where #14918's adapted code now is.

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. #13992, #14172, #14607, #15214, #15241 and #15867 change nearby lines in the same files; whichever merges later keeps both sides. The only exports it shares are with #14917, #14918 and #14919, in the same stack.

Tested

Debian 12, GCC 12.2, Linux 6.18, Release, at the head 3325e018c976b038901ce384414a5aaad2a73eab, with no local changes. It is on #14919's head 911bcec53185ff3d6d24d11b08789048bfbaa8c2.

  • guest_nkwebkit_dates, guest_nkwebkit_numbers, nkwebkit_base, nkwebkit_config, nkwebkit_constants, nkwebkit_fastbitvector, nkwebkit_jsc, nkwebkit_palsessionid, nkwebkit_preferences, nkwebkit_resourceresponse, nkwebkit_webcoregeometry, nkwebkit_wtf, guest_nkwebkit_urls and public_headers pass.
  • The new nkwebkit_wtf cases use a guest-style wrapper with its own vtable. They cover:
    • 8-bit and 16-bit creation, with the buffer pointer unchanged and the free function moved out of the caller;
    • the exact string, buffer and size the free function receives;
    • the free function running before the wrapper's deleting destructor;
    • destruction through both the guest export and host release;
    • delayed destruction through substrings and partial atoms;
    • an external atom keeping its identity, and being removed from the atom table before its free function runs;
    • symbols and atoms keeping a 16-bit external owner alive.
  • tools/progress.py: both exports count as implemented (libSceNKWebKit 1334, against 1332 with #14919).
  • tools/check_conventions.py passes.
  • Windows (GitHub-hosted CI in the author's fork): run 41816855710 built this branch's previous head 9d1e021975e6ecbdaf395584d055bc9653d825d2. It is AnyPS5's Build workflow, dispatched in the author's fork with select=true: the branch merged into main at b11c7bf84f5d2f636ff60166cc3371bd071e24d5, built on windows-latest with WinLibs GCC 15.2 (MinGW-w64, UCRT). All 1390 selected tests passed, none skipped, including the twelve NKWebKit tests, public_headers and patched_libraries. The run started before the fork had a test graph for this main, so it selected more tests than usual. A fork-internal pull request existed only to give the workflow a number. The rebase onto main at 0eba5db30d8a3d03789e52e5c1a9ff853e4e33e4 after #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.

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: #14919
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5113582384 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/14920). Originally posted by [w4rc0n](https://github.com/w4rc0n) on 2026-11-02T01:31:48Z. --- ### What `WTF::ExternalStringImpl::create` was a `NotImplemented` stub in both its 8-bit and 16-bit forms. The destruction from #14917, and the atom and symbol paths from #14918 and #14919, also threw for external buffers. WebKit wraps buffers it doesn't own this way, so those paths stopped. Both exports now follow the pinned PS5 WebKit 11.x source: - **Creation** follows [`ExternalStringImpl.cpp:31-55`](https://github.com/neonmodder123/PS5-WebKit-11.x/blob/80f77e94c63ee7202eec3d4b5b1a021dd89011ba/Source/WTF/wtf/text/ExternalStringImpl.cpp#L31-L55). The string keeps the caller's characters without copying them and marks them `BufferExternal`. It takes ownership of the caller's `WTF::Function` free function, a single pointer that is set to null in the caller. - **The free function** is `Function<void(ExternalStringImpl*, void*, unsigned)>` ([`ExternalStringImpl.h:35`](https://github.com/neonmodder123/PS5-WebKit-11.x/blob/80f77e94c63ee7202eec3d4b5b1a021dd89011ba/Source/WTF/wtf/text/ExternalStringImpl.h#L35)). Its wrapper and vtable belong to the guest. - Slot 2 is `call`, slot 1 is the deleting destructor ([`Function.h:37-103`](https://github.com/neonmodder123/PS5-WebKit-11.x/blob/80f77e94c63ee7202eec3d4b5b1a021dd89011ba/Source/WTF/wtf/Function.h#L37-L103)). - Both are called through `APS5_VABI` function pointers. - **Destruction** follows [`StringImpl.cpp:140-145`](https://github.com/neonmodder123/PS5-WebKit-11.x/blob/80f77e94c63ee7202eec3d4b5b1a021dd89011ba/Source/WTF/wtf/text/StringImpl.cpp#L140-L145): - the free function is called with the string, its buffer and [`sizeInBytes()`](https://github.com/neonmodder123/PS5-WebKit-11.x/blob/80f77e94c63ee7202eec3d4b5b1a021dd89011ba/Source/WTF/wtf/text/StringImpl.cpp#L1514-L1520) (the 24-byte header plus length times character width, narrowed to `unsigned`); - then the guest's wrapper is destroyed, then the host header is freed. - **Layout:** `ExternalStringImpl` is 32 bytes, with the free function at offset 24, pinned with `static_assert`. - **Ownership:** substrings, atoms and symbols now hold external owners as they do any other owner, so "external" drops out of their debt entries. - **Throws:** null characters, zero length and a null free function throw, where the pinned constructors assert. The debt entry names this. Registered symbols stay unsupported. **Adapted source:** none in this PR's own code. Its change to `AddAtom` applies in `src/WtfAtoms.cpp`, where #14918's adapted code now is. `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. #13992, #14172, #14607, #15214, #15241 and #15867 change nearby lines in the same files; whichever merges later keeps both sides. The only exports it shares are with #14917, #14918 and #14919, 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 `3325e018c976b038901ce384414a5aaad2a73eab`, with no local changes. It is on #14919's head `911bcec53185ff3d6d24d11b08789048bfbaa8c2`. - `guest_nkwebkit_dates`, `guest_nkwebkit_numbers`, `nkwebkit_base`, `nkwebkit_config`, `nkwebkit_constants`, `nkwebkit_fastbitvector`, `nkwebkit_jsc`, `nkwebkit_palsessionid`, `nkwebkit_preferences`, `nkwebkit_resourceresponse`, `nkwebkit_webcoregeometry`, `nkwebkit_wtf`, `guest_nkwebkit_urls` and `public_headers` pass. - The new `nkwebkit_wtf` cases use a guest-style wrapper with its own vtable. They cover: - 8-bit and 16-bit creation, with the buffer pointer unchanged and the free function moved out of the caller; - the exact string, buffer and size the free function receives; - the free function running before the wrapper's deleting destructor; - destruction through both the guest export and host release; - delayed destruction through substrings and partial atoms; - an external atom keeping its identity, and being removed from the atom table before its free function runs; - symbols and atoms keeping a 16-bit external owner alive. - `tools/progress.py`: both exports count as implemented (libSceNKWebKit 1334, against 1332 with #14919). - `tools/check_conventions.py` passes. - **Windows (GitHub-hosted CI in the author's fork):** [run 41816855710](https://github.com/w4rc0n/AnyPS5/actions/runs/41816855710) built this branch's previous head `9d1e021975e6ecbdaf395584d055bc9653d825d2`. It is AnyPS5's `Build` workflow, dispatched in the author's fork with `select=true`: the branch merged into `main` at `b11c7bf84f5d2f636ff60166cc3371bd071e24d5`, built on `windows-latest` with WinLibs GCC 15.2 (MinGW-w64, UCRT). All 1390 selected tests passed, none skipped, including the twelve NKWebKit tests, `public_headers` and `patched_libraries`. The run started before the fork had a test graph for this `main`, so it selected more tests than usual. A fork-internal pull request existed only to give the workflow a number. The rebase onto `main` at `0eba5db30d8a3d03789e52e5c1a9ff853e4e33e4` after #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. 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: #14919 - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes

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!14920
No description provided.