fix(libSceNKWebKit): take WTF::pageSize from the guest sysconf #19993

Merged
MatteoSid merged 1 commit from upstream-pr/19993 into main 2026-11-14 13:46:22 +00:00
MatteoSid commented 2026-11-14 10:32:31 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MatteoSid on 2026-11-14T10:32:31Z.


What

WTF::pageSize() in libSceNKWebKit (_ZN3WTF8pageSizeEv, NID ZopRN-OA-qs) returned a fixed 4096. Nothing recorded a reason for that value: it arrived in 1383e29dac with no debt entry, and the PS5 11.x WebKit tree the library follows does not hardcode it. That tree's PageBlock.cpp takes the page size from sysconf(_SC_PAGESIZE) on OS(UNIX). The PS5 compiler defines __FreeBSD__, which gives OS(FREEBSD) and so OS(UNIX) (PlatformOS.h). Its PageBlock.h sets a 16 KiB CeilingOnPageSize for PLATFORM(PLAYSTATION). The console's hw.pagesize is 16384: the entry in docs/dev/debt/libkernel.md records it as read on a PS5 (firmware 13.60) and found as a constant in firmware 10.01 kernel data.

Changes:

  • pageSize() now asks guest libkernel sysconf(47) (_SC_PAGESIZE), which returns PS5_PAGE_SIZE, 16384. libSceNKWebKit already links libkernel.
  • WebKit's RELEASE_ASSERTs that the size is a power of two and not above CeilingOnPageSize throw std::runtime_error where WebKit crashes. The third assertion, that the ceiling is a multiple of the page size, always holds after those two and is not repeated. The value is computed once, as WebKit caches it.
  • The code is in the new src/WtfPageBlock.cpp, which starts with a Derived from line and the PageBlock notice copied verbatim. WtfSystem.cpp only changes the export's body and declares the helper.
  • New debt entry next to "WTF host services". It matches WTF::pageMask in libSceJsc (#19989), which uses the same sysconf call.

Reachability: pageSize() takes no arguments and needs no object, so any module that imports it from libSceNKWebKit reaches it directly. JSC and WebKit use it for page-aligned sizes, such as PageBlock and isPageAligned.

Tested

Linux (Ubuntu 24.04 container, GCC 13.3), Release, -DBUILD_TESTING=ON, on head ab5e25cfcd based on main 18eac5d896: built libSceNKWebKit, the patched core/libs/libs/libSceNKWebKit.prx and every libSceNKWebKit test target. ctest -R 'nkwebkit|^public_headers$' passes 80 of 80.

nkwebkit_wtf now checks that pageSize() is exactly 16384, where it pinned 4096 before, and that a second call returns the same value. All 5 mutations, applied one at a time, make it fail:

  • sysconf(48) instead of 47;
  • a 4 KiB ceiling (WebKit's x86-64 value);
  • an inverted power-of-two check;
  • a 4096-byte system page;
  • a returned size off by one.

nm -D on the patched libSceNKWebKit.prx lists ZopRN-OA-qs at the address of _ZN3WTF8pageSizeEv. tools/check_conventions.py --base origin/main --head HEAD passes and git diff --check origin/main is clean.

Overlap: no open PR mentions pageSize in libSceNKWebKit or its NID. tools/pr_overlap.py --branch merged 110 PRs without overlap. I checked the 9 it could not compare by hand:

  • #19103 and #19106 edit tests/Wtf.cpp around lines 6, 562-573, 1132 and 1424, far from TestSystem (line 280);
  • none of the 9 touches pageSize or the "WTF host services" entry.

git merge-tree --write-tree merges this branch cleanly with #19302, #19523, #19380 and #19823. #19380 and #19823 also edit WtfSystem.cpp, but their hunks are separated from this one by unchanged lines. No title tested.

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:5310284302 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/19993). Originally posted by [MatteoSid](https://github.com/MatteoSid) on 2026-11-14T10:32:31Z. --- ### What `WTF::pageSize()` in libSceNKWebKit (`_ZN3WTF8pageSizeEv`, NID `ZopRN-OA-qs`) returned a fixed 4096. Nothing recorded a reason for that value: it arrived in 1383e29dac with no debt entry, and the PS5 11.x WebKit tree the library follows does not hardcode it. That tree's [PageBlock.cpp](https://github.com/neonmodder123/PS5-WebKit-11.x/blob/80f77e94c63ee7202eec3d4b5b1a021dd89011ba/Source/WTF/wtf/PageBlock.cpp#L42-L69) takes the page size from `sysconf(_SC_PAGESIZE)` on `OS(UNIX)`. The PS5 compiler defines `__FreeBSD__`, which gives `OS(FREEBSD)` and so `OS(UNIX)` ([PlatformOS.h](https://github.com/neonmodder123/PS5-WebKit-11.x/blob/80f77e94c63ee7202eec3d4b5b1a021dd89011ba/Source/WTF/wtf/PlatformOS.h#L85-L88)). Its [PageBlock.h](https://github.com/neonmodder123/PS5-WebKit-11.x/blob/80f77e94c63ee7202eec3d4b5b1a021dd89011ba/Source/WTF/wtf/PageBlock.h#L52-L53) sets a 16 KiB `CeilingOnPageSize` for `PLATFORM(PLAYSTATION)`. The console's `hw.pagesize` is 16384: the entry in `docs/dev/debt/libkernel.md` records it as read on a PS5 (firmware 13.60) and found as a constant in firmware 10.01 kernel data. Changes: - `pageSize()` now asks guest libkernel `sysconf(47)` (`_SC_PAGESIZE`), which returns `PS5_PAGE_SIZE`, 16384. libSceNKWebKit already links libkernel. - WebKit's `RELEASE_ASSERT`s that the size is a power of two and not above `CeilingOnPageSize` throw `std::runtime_error` where WebKit crashes. The third assertion, that the ceiling is a multiple of the page size, always holds after those two and is not repeated. The value is computed once, as WebKit caches it. - The code is in the new `src/WtfPageBlock.cpp`, which starts with a `Derived from` line and the PageBlock notice copied verbatim. `WtfSystem.cpp` only changes the export's body and declares the helper. - New debt entry next to "WTF host services". It matches `WTF::pageMask` in libSceJsc (#19989), which uses the same sysconf call. Reachability: `pageSize()` takes no arguments and needs no object, so any module that imports it from libSceNKWebKit reaches it directly. JSC and WebKit use it for page-aligned sizes, such as `PageBlock` and `isPageAligned`. ### Tested Linux (Ubuntu 24.04 container, GCC 13.3), Release, `-DBUILD_TESTING=ON`, on head `ab5e25cfcd` based on `main` `18eac5d896`: built `libSceNKWebKit`, the patched `core/libs/libs/libSceNKWebKit.prx` and every libSceNKWebKit test target. `ctest -R 'nkwebkit|^public_headers$'` passes 80 of 80. `nkwebkit_wtf` now checks that `pageSize()` is exactly 16384, where it pinned 4096 before, and that a second call returns the same value. All 5 mutations, applied one at a time, make it fail: - `sysconf(48)` instead of 47; - a 4 KiB ceiling (WebKit's x86-64 value); - an inverted power-of-two check; - a 4096-byte system page; - a returned size off by one. `nm -D` on the patched `libSceNKWebKit.prx` lists `ZopRN-OA-qs` at the address of `_ZN3WTF8pageSizeEv`. `tools/check_conventions.py --base origin/main --head HEAD` passes and `git diff --check origin/main` is clean. Overlap: no open PR mentions `pageSize` in libSceNKWebKit or its NID. `tools/pr_overlap.py --branch` merged 110 PRs without overlap. I checked the 9 it could not compare by hand: - #19103 and #19106 edit `tests/Wtf.cpp` around lines 6, 562-573, 1132 and 1424, far from `TestSystem` (line 280); - none of the 9 touches `pageSize` or the "WTF host services" entry. `git merge-tree --write-tree` merges this branch cleanly with #19302, #19523, #19380 and #19823. #19380 and #19823 also edit `WtfSystem.cpp`, but their hunks are separated from this one by unchanged lines. No title tested. ### 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
PrivacyOnion commented 2026-11-14 10:46:52 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-14T10:46:52Z.

Review: APPROVED


Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against ab5e25cfcd:

  • Conventions: tools/check_conventions.py passed; git diff --check clean.
  • Build: nkwebkit_wtf_tests built cleanly.
  • CTest (nkwebkit_wtf):
    1/1 Test #4024: nkwebkit_wtf .....................   Passed    0.02 sec
    100% tests passed, 0 tests failed out of 1
    
  • Negative control: with core/libs/prx/libSceNKWebKit/src/WtfSystem.cpp reverted to main and the new tests kept, the suite fails:
    1/1 Test #4024: nkwebkit_wtf .....................Subprocess aborted***Exception:   0.23 sec
    0% tests passed, 1 tests failed out of 1
    
    Restoring the change makes it pass again.
  • Code reading:
    • core/libs/prx/libSceNKWebKit/src/WtfPageBlock.cpp: Verified SystemPageSize() queries ScPageSize = 47 (_SC_PAGESIZE in FreeBSD / Orbis OS) via sysconf_nid_postfix, properly obtaining the guest 16384 page size.
    • core/libs/prx/libSceNKWebKit/src/WtfPageBlock.cpp: Verified NKWebKit::PageSize() constraint checks (IsPowerOfTwo and size > CeilingOnPageSize with CeilingOnPageSize = 16 * 1024), confirming invalid, zero, or oversized sizes throw std::runtime_error without undefined behavior.
    • core/libs/prx/libSceNKWebKit/src/WtfPageBlock.cpp: Verified thread safety of static local initialization (static const std::size_t pageSize), ensuring thread-safe one-time computation under C++ magic statics semantics.
    • core/libs/prx/libSceNKWebKit/src/WtfSystem.cpp: Verified _ZN3WTF8pageSizeEv preserves APS5_VABI calling convention and extern "C" linkage while dispatching to NKWebKit::PageSize().
    • core/libs/prx/libSceNKWebKit/tests/Wtf.cpp: Verified TestSystem() asserts that _ZN3WTF8pageSizeEv() returns 16384 and produces consistent results across repeated invocations.
    • docs/dev/debt/libSceNKWebKit.md: Verified the debt entry accurately documents WTF::pageSize alignment with PS5 11.x PageBlock.cpp, sysconf(47), and assertion conversion.
  • Note: the AI-assisted checkbox can stay.

Looks Good To Me

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5903915565 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/19993#pullrequestreview-5903915565). Originally posted by [PrivacyOnion](https://github.com/PrivacyOnion) on 2026-11-14T10:46:52Z. **Review:** APPROVED --- Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against `ab5e25cfcd`: - **Conventions**: `tools/check_conventions.py` passed; `git diff --check` clean. - **Build**: `nkwebkit_wtf_tests` built cleanly. - **CTest** (`nkwebkit_wtf`): ``` 1/1 Test #4024: nkwebkit_wtf ..................... Passed 0.02 sec 100% tests passed, 0 tests failed out of 1 ``` - **Negative control**: with `core/libs/prx/libSceNKWebKit/src/WtfSystem.cpp` reverted to `main` and the new tests kept, the suite fails: ``` 1/1 Test #4024: nkwebkit_wtf .....................Subprocess aborted***Exception: 0.23 sec 0% tests passed, 1 tests failed out of 1 ``` Restoring the change makes it pass again. - **Code reading**: - core/libs/prx/libSceNKWebKit/src/WtfPageBlock.cpp: Verified SystemPageSize() queries ScPageSize = 47 (_SC_PAGESIZE in FreeBSD / Orbis OS) via sysconf_nid_postfix, properly obtaining the guest 16384 page size. - core/libs/prx/libSceNKWebKit/src/WtfPageBlock.cpp: Verified NKWebKit::PageSize() constraint checks (IsPowerOfTwo and size > CeilingOnPageSize with CeilingOnPageSize = 16 * 1024), confirming invalid, zero, or oversized sizes throw std::runtime_error without undefined behavior. - core/libs/prx/libSceNKWebKit/src/WtfPageBlock.cpp: Verified thread safety of static local initialization (static const std::size_t pageSize), ensuring thread-safe one-time computation under C++ magic statics semantics. - core/libs/prx/libSceNKWebKit/src/WtfSystem.cpp: Verified _ZN3WTF8pageSizeEv preserves APS5_VABI calling convention and extern "C" linkage while dispatching to NKWebKit::PageSize(). - core/libs/prx/libSceNKWebKit/tests/Wtf.cpp: Verified TestSystem() asserts that _ZN3WTF8pageSizeEv() returns 16384 and produces consistent results across repeated invocations. - docs/dev/debt/libSceNKWebKit.md: Verified the debt entry accurately documents WTF::pageSize alignment with PS5 11.x PageBlock.cpp, sysconf(47), and assertion conversion. - Note: the AI-assisted checkbox can stay. Looks Good To Me
MarcZX10 commented 2026-11-14 13:08:54 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-14T13:08:54Z.

Review: APPROVED


Reviewed — looks good

The changed export delegates to a cached guest page-size query with power-of-two and upper-bound checks; the inspected implementation and test support the stated behavior, though the new helper’s full source was excluded from review.

What I ran

No build or test commands were run. The author reports Linux build and test results in the PR description; these were not independently verified.

Results

Check Result Note
Source review passed Changed export, test, helper, and debt entry inspected
Build and tests not run Author-reported results only
Console behavior not run No console measurement performed in this review

Findings

Blocking

None.

Non-blocking

None.

Not verified

The full WtfPageBlock.cpp text was available through the pinned repository reader and inspected, but the PR description says that file was excluded from the prepared diff by rule. No files were excluded from manifest.json’s reviewed list. The PR’s claimed build, test, mutation, ABI, and console results were not run or independently verified. docs/dev/debt/libSceNKWebKit.md was read at the changed entry only; its remaining contents were not read.

To get this to a good state

Nothing is required.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5904465214 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/19993#pullrequestreview-5904465214). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-14T13:08:54Z. **Review:** APPROVED --- # Reviewed — looks good The changed export delegates to a cached guest page-size query with power-of-two and upper-bound checks; the inspected implementation and test support the stated behavior, though the new helper’s full source was excluded from review. ## What I ran No build or test commands were run. The author reports Linux build and test results in the PR description; these were not independently verified. ## Results | Check | Result | Note | |---|---|---| | Source review | passed | Changed export, test, helper, and debt entry inspected | | Build and tests | not run | Author-reported results only | | Console behavior | not run | No console measurement performed in this review | ## Findings ### Blocking None. ### Non-blocking None. ## Not verified The full `WtfPageBlock.cpp` text was available through the pinned repository reader and inspected, but the PR description says that file was excluded from the prepared diff by rule. No files were excluded from `manifest.json`’s reviewed list. The PR’s claimed build, test, mutation, ABI, and console results were not run or independently verified. `docs/dev/debt/libSceNKWebKit.md` was read at the changed entry only; its remaining contents were not read. ## To get this to a good state Nothing is required.
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!19993
No description provided.