feat(libSceNKWebKit): implement WTF StackBounds, TimingScope::scopeDidEnd and PrintStream::end #19380

Merged
B-Howell merged 10 commits from upstream-pr/19380 into main 2026-11-16 21:25:58 +00:00
B-Howell commented 2026-11-13 07:21:46 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by B-Howell on 2026-11-13T07:21:46Z.


What

Implements three WTF exports that threw through NotImplemented_nid_no_patch, following WebKit at the pinned PS5-WebKit-11.x@80f77e9:

  • WTF::StackBounds::currentThreadStackBoundsInternal (ycxHHEa11OI): the OS(UNIX) branch of StackBounds.cpp. It runs pthread_attr_init, then pthread_attr_get_np(pthread_self()), pthread_attr_getstack and pthread_attr_destroy, and returns {bound + size, bound}. The calls go through libkernel's own pthread_*_nid_postfix exports; NKWebKit already links libkernel. libkernel exports pthread_attr_get_np and not pthread_getattr_np, and both branches return the same thing. The Linux-only main-thread rlimit fix-up does not apply to PlayStation. The return type is a 16-byte {m_origin, m_bound}, as in StackBounds.h L152-153. It is trivially copyable, so it comes back in RAX:RDX; static_asserts pin the layout. Where WebKit ignores a failed attribute call, this throws.
  • WTF::TimingScope::scopeDidEnd (vNFWwy493LY): TimingScope.cpp. Totals are process-wide, keyed by the name pointer and held under a lock. Every m_logIterationInterval calls it logs the same WTFLogAlways line. It reuses the existing MonotonicTime::now and WTFLogAlways. The layout is {MonotonicTime m_startTime; const char* m_name; unsigned m_logIterationInterval;} at offsets 0, 8 and 16, size 24, pinned with static_assert. A null scope, a null name or a zero interval throws; WebKit would dereference null there or divide by zero.
  • WTF::PrintStream::end (FyOMUdXa5Tc): its body is empty. It goes with the other empty bodies in src/NoOpExports.cpp. Its sibling PrintStream::begin is already implemented.

The technical-debt inventory drops the three rows. The StackBounds, TimingScope and end notes are recorded. tools/progress.py libraries done goes from 15615 to 15618 (+3).

Tested

WSL2 Ubuntu, Release, Ninja. The new checks are in tests/Wtf.cpp and tests/NoOps.cpp:

  • StackBounds, on the main thread and on a std::thread: origin > bound, and a local's address lies between them. The bound equals libkernel's pthread_attr_getstack address, and origin equals that address plus the stack size.
  • TimingScope: two calls with interval 2 log exactly one <name>: 2 calls line. A second name pointer counts separately, interval 1 logs on every call, and interval 0 throws. stdout and stderr are both captured, because WTFLogAlways writes through the guest stdout on Windows.
  • PrintStream::end: is called in the NoOps test, which requires the not-implemented counter to stay unchanged.

Red control: the same tests with main's stubs restored, ctest -R '^nkwebkit_(wtf|noops)$':

  • nkwebkit_noops ... Subprocess aborted, what(): _ZN3WTF11PrintStream3endEv not implemented
  • nkwebkit_wtf ... Subprocess aborted, what(): _ZN3WTF11StackBounds32currentThreadStackBoundsInternalEv not implemented
  • With only StackBounds implemented, nkwebkit_wtf ... Subprocess aborted, what(): _ZN3WTF11TimingScope11scopeDidEndEv not implemented

Green: 100% tests passed, 0 tests failed out of 2 (nkwebkit_noops and nkwebkit_wtf), 3 of 3 runs. ctest -R '^public_headers': 100% tests passed, 0 tests failed out of 65. Nothing was checked against a console.

Overlap: 106 open PRs touch NKWebKit, Jsc or WTF paths. None adds or removes these three symbols. #14946, #14947 and #14948 have PrintStream3endEv only in context lines next to their printf and printfVariableFormat stubs, so this PR leaves those two alone. Removing end from Export.cpp may cause a textual conflict in that hunk.

  • On 458ed2d9dbb, an ordinary merge of main at 82160bba912 after #18538, conventions passed; doc-only conflict on the count line; count is main's stated 5949 minus this change's 3 removed stubs (5946). Main's code changes since the last merge are over 1,000 lines from this PR's hunks, so the earlier test results stand.
  • On a54945fbc6f: the WebKit notices from TimingScope.cpp and StackBounds.cpp (80f77e94c6) added verbatim to src/WtfTime.cpp and src/WtfSystem.cpp (comment only), then an ordinary merge of main at c612c4c9e89 after #19322, #17764 and #19460; doc-only union merge of the count line; count is main's stated 5939 minus this change's 3 removed stubs (5936). Main removed stubs about 20 lines from ours, so rebuilt: Windows 11, WinLibs GCC 15.2.0 r7 UCRT, Release: nkwebkit_noops and nkwebkit_wtf 3/3; conventions passed.
  • On ca540352e0e: merged main after #19603; count line removed. Ordinary merge of main at 9b22c40f49a, conventions passed. The debt diff against main is now only this PR's entry and its 3 removed table rows. No code conflict and main changed none of this PR's other files, so not rebuilt.
  • 2026-11-14: comment-only commit 66653f0063b rewrites each Derived from line as Derived from <path>@<40-character revision>, one line per source file (maintainer ruling, #19819 comment). No code changed, so no rebuild; tools/check_conventions.py --base origin/main passes and git diff --check is clean.
  • Debt fragment e99e87a07c: 986447e551 moved this PR's debt edits into docs/dev/debt/changes/claude-nkwebkit-wtf-stackbounds-timingscope.md (debt files match main); e99e87a07c then merged main and kept both tests/Wtf.cpp groups, the same resolution as a local merge on 3ae84d01bd3 where nkwebkit_wtf_tests built on WSL2 Ubuntu and ctest -R ^nkwebkit_wtf$ passed 1/1. debt_fold.py --check and check_conventions.py --base origin/main pass.

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:5291748775 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/19380). Originally posted by [B-Howell](https://github.com/B-Howell) on 2026-11-13T07:21:46Z. --- ### What Implements three WTF exports that threw through `NotImplemented_nid_no_patch`, following WebKit at the pinned [PS5-WebKit-11.x@80f77e9](https://github.com/neonmodder123/PS5-WebKit-11.x/tree/80f77e94c63ee7202eec3d4b5b1a021dd89011ba/Source/WTF/wtf): - `WTF::StackBounds::currentThreadStackBoundsInternal` (`ycxHHEa11OI`): the OS(UNIX) branch of [StackBounds.cpp](https://github.com/neonmodder123/PS5-WebKit-11.x/blob/80f77e94c63ee7202eec3d4b5b1a021dd89011ba/Source/WTF/wtf/StackBounds.cpp#L89-L139). It runs `pthread_attr_init`, then `pthread_attr_get_np(pthread_self())`, `pthread_attr_getstack` and `pthread_attr_destroy`, and returns `{bound + size, bound}`. The calls go through libkernel's own `pthread_*_nid_postfix` exports; NKWebKit already links libkernel. libkernel exports `pthread_attr_get_np` and not `pthread_getattr_np`, and both branches return the same thing. The Linux-only main-thread rlimit fix-up does not apply to PlayStation. The return type is a 16-byte `{m_origin, m_bound}`, as in [StackBounds.h L152-153](https://github.com/neonmodder123/PS5-WebKit-11.x/blob/80f77e94c63ee7202eec3d4b5b1a021dd89011ba/Source/WTF/wtf/StackBounds.h#L152-L153). It is trivially copyable, so it comes back in RAX:RDX; `static_assert`s pin the layout. Where WebKit ignores a failed attribute call, this throws. - `WTF::TimingScope::scopeDidEnd` (`vNFWwy493LY`): [TimingScope.cpp](https://github.com/neonmodder123/PS5-WebKit-11.x/blob/80f77e94c63ee7202eec3d4b5b1a021dd89011ba/Source/WTF/wtf/TimingScope.cpp). Totals are process-wide, keyed by the name pointer and held under a lock. Every `m_logIterationInterval` calls it logs the same `WTFLogAlways` line. It reuses the existing `MonotonicTime::now` and `WTFLogAlways`. The layout is `{MonotonicTime m_startTime; const char* m_name; unsigned m_logIterationInterval;}` at offsets 0, 8 and 16, size 24, pinned with `static_assert`. A null scope, a null name or a zero interval throws; WebKit would dereference null there or divide by zero. - `WTF::PrintStream::end` (`FyOMUdXa5Tc`): its [body is empty](https://github.com/neonmodder123/PS5-WebKit-11.x/blob/80f77e94c63ee7202eec3d4b5b1a021dd89011ba/Source/WTF/wtf/PrintStream.cpp#L67-L69). It goes with the other empty bodies in `src/NoOpExports.cpp`. Its sibling `PrintStream::begin` is already implemented. The technical-debt inventory drops the three rows. The StackBounds, TimingScope and `end` notes are recorded. `tools/progress.py` libraries done goes from 15615 to 15618 (+3). ### Tested WSL2 Ubuntu, Release, Ninja. The new checks are in `tests/Wtf.cpp` and `tests/NoOps.cpp`: - StackBounds, on the main thread and on a `std::thread`: origin > bound, and a local's address lies between them. The bound equals libkernel's `pthread_attr_getstack` address, and origin equals that address plus the stack size. - TimingScope: two calls with interval 2 log exactly one `<name>: 2 calls` line. A second name pointer counts separately, interval 1 logs on every call, and interval 0 throws. stdout and stderr are both captured, because `WTFLogAlways` writes through the guest stdout on Windows. - `PrintStream::end`: is called in the NoOps test, which requires the not-implemented counter to stay unchanged. Red control: the same tests with main's stubs restored, `ctest -R '^nkwebkit_(wtf|noops)$'`: - `nkwebkit_noops ... Subprocess aborted`, `what(): _ZN3WTF11PrintStream3endEv not implemented` - `nkwebkit_wtf ... Subprocess aborted`, `what(): _ZN3WTF11StackBounds32currentThreadStackBoundsInternalEv not implemented` - With only StackBounds implemented, `nkwebkit_wtf ... Subprocess aborted`, `what(): _ZN3WTF11TimingScope11scopeDidEndEv not implemented` Green: `100% tests passed, 0 tests failed out of 2` (`nkwebkit_noops` and `nkwebkit_wtf`), 3 of 3 runs. `ctest -R '^public_headers'`: `100% tests passed, 0 tests failed out of 65`. Nothing was checked against a console. Overlap: 106 open PRs touch NKWebKit, Jsc or WTF paths. None adds or removes these three symbols. #14946, #14947 and #14948 have `PrintStream3endEv` only in context lines next to their `printf` and `printfVariableFormat` stubs, so this PR leaves those two alone. Removing `end` from `Export.cpp` may cause a textual conflict in that hunk. - On `458ed2d9dbb`, an ordinary merge of `main` at `82160bba912` after #18538, conventions passed; doc-only conflict on the count line; count is main's stated 5949 minus this change's 3 removed stubs (5946). Main's code changes since the last merge are over 1,000 lines from this PR's hunks, so the earlier test results stand. - On `a54945fbc6f`: the WebKit notices from TimingScope.cpp and StackBounds.cpp (80f77e94c6) added verbatim to `src/WtfTime.cpp` and `src/WtfSystem.cpp` (comment only), then an ordinary merge of `main` at `c612c4c9e89` after #19322, #17764 and #19460; doc-only union merge of the count line; count is main's stated 5939 minus this change's 3 removed stubs (5936). Main removed stubs about 20 lines from ours, so rebuilt: Windows 11, WinLibs GCC 15.2.0 r7 UCRT, Release: `nkwebkit_noops` and `nkwebkit_wtf` 3/3; conventions passed. - On `ca540352e0e`: merged main after #19603; count line removed. Ordinary merge of `main` at `9b22c40f49a`, conventions passed. The debt diff against main is now only this PR's entry and its 3 removed table rows. No code conflict and main changed none of this PR's other files, so not rebuilt. - 2026-11-14: comment-only commit `66653f0063b` rewrites each `Derived from` line as `Derived from <path>@<40-character revision>`, one line per source file (maintainer ruling, [#19819 comment](https://github.com/boykopovar/AnyPS5/pull/19819#issuecomment-6868889186)). No code changed, so no rebuild; `tools/check_conventions.py --base origin/main` passes and `git diff --check` is clean. - Debt fragment `e99e87a07c`: `986447e551` moved this PR's debt edits into `docs/dev/debt/changes/claude-nkwebkit-wtf-stackbounds-timingscope.md` (debt files match main); `e99e87a07c` then merged main and kept both `tests/Wtf.cpp` groups, the same resolution as a local merge on `3ae84d01bd3` where `nkwebkit_wtf_tests` built on WSL2 Ubuntu and `ctest -R ^nkwebkit_wtf$` passed 1/1. `debt_fold.py --check` and `check_conventions.py --base origin/main` pass. ### 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
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!19380
No description provided.