feat(libSceNKWebKit): implement WTF::PrintStream and StringPrintStream #14946

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

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


What

WTF's printing layer was all NotImplemented stubs, so guest code that printed through a PrintStream threw: dataLog, out.print(...), and toString() on a StringPrintStream. 34 exports now follow the pinned PS5 WebKit 11.x PrintStream.cpp and StringPrintStream.cpp:

  • StringPrintStream:
    • the constructors and destructors (C1, C2, D0, D1 and D2);
    • vprintf, which measures the formatted length first and grows the buffer once to fit, starting from the 128-byte inline buffer;
    • reset, toCString, toString, toStringWithLatin1Fallback and tryToString.
  • PrintStream::printf, printfVariableFormat and begin.
  • printInternal for const char*, String, CString, StringImpl*, RawPointer, ClockType, bool and every integer and floating-point type, and dumpCharacter.

Guest code reaches these through the object's vtable, so the layout follows PrintStream.h and StringPrintStream.h:

  • Vtable: StringPrintStream gets a vtable in Itanium order (D1, D0, vprintf, flush, begin, end).
    • It has a zero offset-to-top and a null RTTI slot, since WebKit builds with -fno-rtti (WebKitCompilerFlags.cmake).
    • Every slot is a APS5_VABI function.
  • Layout: the object is 160 bytes (pinned with static_assert).
  • Dispatch: printf and printInternal call the stream's own vprintf slot with a System V va_list, so a guest subclass of PrintStream works too.
    • bool and ClockType go through out.print, so they also call begin and end, as in the source.
    • Formatting goes through libc's existing vsnprintf export (vsnprintf_nid_postfix) on every host, so conversions follow libc's guest rules, not the host's. %p prints bare lowercase hex with no 0x, as measured on a PS5 (#7549, recorded in docs/dev/debt/libc.md).
  • tryToString: returns an Expected<String, …>, 16 bytes through the return buffer. It fails only above String::MaxLength. Invalid UTF-8 is a success holding a null String, as in the source.

The internal vtable functions end in _nid_no_patch, so tools/progress.py counts only the 34 exports. PrintStream::end is left as it is, because #13930 implements it. The dump(PrintStream&) methods of other classes are a follow-up.

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 and #15241 change nearby lines in the same files; whichever merges later keeps both sides. The only exports it shares are with #14947 and #14948, in the same stack.

Tested

Debian 12, GCC 12.2, Linux 6.18, Release, at the head 59a53bbfcbd5eadd60fe1711a5157d57ca5bb3b2, no local changes:

  • 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 cover:
    • every printInternal type;
    • variadic arguments split between registers and the stack;
    • growth past the inline buffer, reset, and a CString copy that outlives the stream;
    • RawPointer printing as bare hex (1234), including after growth past the inline buffer within one call;
    • a second long append that replaces a heap buffer and keeps the earlier output;
    • virtual destructor calls;
    • tryToString succeeding on invalid UTF-8 and failing when oversized, and the Latin-1 fallback;
    • a guest-style subclass whose own vprintf, begin and end are called, including a redirected begin.
  • tools/progress.py: the 34 exports count as implemented (libSceNKWebKit 1346, 1312 on main).
  • tools/check_conventions.py passes.
  • Windows (GitHub-hosted CI in the author's fork): run 41385234882 built feat/nkwebkit-wtf-dumps at its previous head ce247d6dbe042c0616a02eb8117efe060b1cda2f and run 41385242010 built feat/nkwebkit-utf8-for-characters at its previous head a3b0234339d1e891d111f410cf9a3e7dd30d9ca6, 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 926f7dd492b0b432d9287f4d6faaaf1c9d3c86c5, 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, #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.

Not built or run: macOS. The stream layouts and the vtable without RTTI come from the pinned source and build flags, not from console binaries. 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:5114385832 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/14946). Originally posted by [w4rc0n](https://github.com/w4rc0n) on 2026-11-02T03:14:48Z. --- ### What WTF's printing layer was all `NotImplemented` stubs, so guest code that printed through a `PrintStream` threw: `dataLog`, `out.print(...)`, and `toString()` on a `StringPrintStream`. 34 exports now follow the pinned PS5 WebKit 11.x [`PrintStream.cpp`](https://github.com/neonmodder123/PS5-WebKit-11.x/blob/80f77e94c63ee7202eec3d4b5b1a021dd89011ba/Source/WTF/wtf/PrintStream.cpp) and [`StringPrintStream.cpp`](https://github.com/neonmodder123/PS5-WebKit-11.x/blob/80f77e94c63ee7202eec3d4b5b1a021dd89011ba/Source/WTF/wtf/StringPrintStream.cpp): - `StringPrintStream`: - the constructors and destructors (C1, C2, D0, D1 and D2); - `vprintf`, which measures the formatted length first and grows the buffer once to fit, starting from the 128-byte inline buffer; - `reset`, `toCString`, `toString`, `toStringWithLatin1Fallback` and `tryToString`. - `PrintStream::printf`, `printfVariableFormat` and `begin`. - `printInternal` for `const char*`, `String`, `CString`, `StringImpl*`, `RawPointer`, `ClockType`, `bool` and every integer and floating-point type, and `dumpCharacter`. Guest code reaches these through the object's vtable, so the layout follows [`PrintStream.h`](https://github.com/neonmodder123/PS5-WebKit-11.x/blob/80f77e94c63ee7202eec3d4b5b1a021dd89011ba/Source/WTF/wtf/PrintStream.h) and [`StringPrintStream.h`](https://github.com/neonmodder123/PS5-WebKit-11.x/blob/80f77e94c63ee7202eec3d4b5b1a021dd89011ba/Source/WTF/wtf/StringPrintStream.h): - **Vtable:** `StringPrintStream` gets a vtable in Itanium order (D1, D0, `vprintf`, `flush`, `begin`, `end`). - It has a zero offset-to-top and a null RTTI slot, since WebKit builds with `-fno-rtti` ([`WebKitCompilerFlags.cmake`](https://github.com/neonmodder123/PS5-WebKit-11.x/blob/80f77e94c63ee7202eec3d4b5b1a021dd89011ba/Source/cmake/WebKitCompilerFlags.cmake#L119)). - Every slot is a `APS5_VABI` function. - **Layout:** the object is 160 bytes (pinned with `static_assert`). - **Dispatch:** `printf` and `printInternal` call the stream's own `vprintf` slot with a System V `va_list`, so a guest subclass of `PrintStream` works too. - `bool` and `ClockType` go through `out.print`, so they also call `begin` and `end`, as in the source. - Formatting goes through libc's existing `vsnprintf` export (`vsnprintf_nid_postfix`) on every host, so conversions follow libc's guest rules, not the host's. `%p` prints bare lowercase hex with no `0x`, as measured on a PS5 ([#7549](https://github.com/boykopovar/AnyPS5/issues/7549), recorded in `docs/dev/debt/libc.md`). - **`tryToString`:** returns an `Expected<String, …>`, 16 bytes through the return buffer. It fails only above `String::MaxLength`. Invalid UTF-8 is a success holding a null `String`, as in the source. The internal vtable functions end in `_nid_no_patch`, so `tools/progress.py` counts only the 34 exports. `PrintStream::end` is left as it is, because #13930 implements it. The `dump(PrintStream&)` methods of other classes are a follow-up. `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 and #15241 change nearby lines in the same files; whichever merges later keeps both sides. The only exports it shares are with #14947 and #14948, 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 `59a53bbfcbd5eadd60fe1711a5157d57ca5bb3b2`, no local changes: - `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 cover: - every `printInternal` type; - variadic arguments split between registers and the stack; - growth past the inline buffer, `reset`, and a `CString` copy that outlives the stream; - `RawPointer` printing as bare hex (`1234`), including after growth past the inline buffer within one call; - a second long append that replaces a heap buffer and keeps the earlier output; - virtual destructor calls; - `tryToString` succeeding on invalid UTF-8 and failing when oversized, and the Latin-1 fallback; - a guest-style subclass whose own `vprintf`, `begin` and `end` are called, including a redirected `begin`. - `tools/progress.py`: the 34 exports count as implemented (libSceNKWebKit 1346, 1312 on `main`). - `tools/check_conventions.py` passes. - **Windows (GitHub-hosted CI in the author's fork):** [run 41385234882](https://github.com/w4rc0n/AnyPS5/actions/runs/41385234882) built `feat/nkwebkit-wtf-dumps` at its previous head `ce247d6dbe042c0616a02eb8117efe060b1cda2f` and [run 41385242010](https://github.com/w4rc0n/AnyPS5/actions/runs/41385242010) built `feat/nkwebkit-utf8-for-characters` at its previous head `a3b0234339d1e891d111f410cf9a3e7dd30d9ca6`, 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 `926f7dd492b0b432d9287f4d6faaaf1c9d3c86c5`, 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, #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. Not built or run: macOS. The stream layouts and the vtable without RTTI come from the pinned source and build flags, not from console binaries. 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

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