feat(libSceJsc): implement WTF::pageMask #19989

Merged
MatteoSid merged 1 commit from upstream-pr/19989 into main 2026-11-14 13:41:45 +00:00
MatteoSid commented 2026-11-14 10:23:43 +00:00 (Migrated from github.com)

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


What

Implements WTF::pageMask() in libSceJsc (_ZN3WTF8pageMaskEv, NID rIKEui9oRJg), until now a NotImplemented_nid_no_patch stub. It follows pinned WebKit c55364d53f97, the revision the other libSceJsc WTF code already pins.

  • The pinned PageBlock.cpp returns ~(pageSize() - 1). On OS(UNIX), pageSize() is sysconf(_SC_PAGESIZE). The PS5 compiler defines __FreeBSD__, which gives OS(FREEBSD) and so OS(UNIX) (PlatformOS.h, L124-L136).
  • The implementation asks guest libkernel sysconf(47) (_SC_PAGESIZE). It returns PS5_PAGE_SIZE, 16384, the value the hw.pagesize entry in docs/dev/debt/libkernel.md measured on a PS5 (firmware 13.60, by name and by MIB) and found as a constant in firmware 10.01 kernel data. So pageMask() is 0xFFFFFFFFFFFFC000. libSceJsc now links libkernel privately, as libSceNKWebKit already does.
  • WebKit RELEASE_ASSERTs that the page size is a power of two and not above CeilingOnPageSize, which PageBlock.h sets to 16 KiB for PLATFORM(PLAYSTATION). Both checks throw std::runtime_error where WebKit crashes. The page size and mask are computed once, as WebKit caches them.

src/WtfPageBlock.cpp follows that control flow, so it starts with the PageBlock notice copied verbatim, plus a Derived from line, as the other libSceJsc WTF files do.

Reachability: pageMask() takes no arguments and needs no object, so any module that imports it from libSceJsc reaches it directly. JSC and WebKit code use it, through PageBlock and page-rounding helpers, to align allocation sizes and addresses.

Gaps, in a new debt entry: not compared with a console module, and the console WTF version is unverified. libSceNKWebKit's own WTF::pageSize() (src/WtfSystem.cpp) returns 4096, which does not match this 16 KiB mask; that export is outside this PR. The "Additional callable exports" count goes from main's 322 to 321.

Tested

Linux (Ubuntu 24.04 container, GCC 13.3), Release, -DBUILD_TESTING=ON, on head fa8461e12b based on main b96058f793: built libSceJsc, the patched core/libs/libs/libSceJsc.prx and every libSceJsc test target. ctest -R '^(guest_jsc_string|jsc_placement_new|jsc_wtf_string_search|jsc_wtf_random|jsc_wtf_url|guest_jsc_trivial_returns|jsc_wtf_helpers|jsc_wtf_page_block|guest_jsc_register_sets_and_constructors|jsc_wtf_sha1|guest_jsc_script_value|jsc_wtf_bit_vector|public_headers)$' passes 13 of 13.

The new jsc_wtf_page_block checks exact values:

  • pageMask() is 0xFFFFFFFFFFFFC000;
  • ~mask + 1 is 16384;
  • a second call returns the same mask;
  • 0x12345678 & mask is 0x12344000.

All 6 mutations, applied one at a time, make it fail:

  • sysconf(48) instead of 47;
  • ~pageSize();
  • pageSize() - 1 without the ~;
  • a 4 KiB ceiling (WebKit's x86-64 value), which throws;
  • an inverted power-of-two check;
  • a 4096-byte page.

nm -D on the patched libSceJsc.prx lists rIKEui9oRJg at the address of _ZN3WTF8pageMaskEv. tools/check_conventions.py --base origin/main --head HEAD passes and git diff --check is clean.

tools/pr_overlap.py --branch merged the open PRs it could and found no overlap. It could not compare #18430, #18442 and #19772, which conflict with main, so I checked them by hand:

  • #18442 deletes the two WTF::Unicode declarations and table rows two lines above pageMask, with JSONImpl::Value::escapeString unchanged in between;
  • #18430 and #19772 have no hunk near it.

None of them touches pageMask, and no open PR mentions pageMask or rIKEui9oRJg. 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:5310204841 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/19989). Originally posted by [MatteoSid](https://github.com/MatteoSid) on 2026-11-14T10:23:43Z. --- ### What Implements `WTF::pageMask()` in libSceJsc (`_ZN3WTF8pageMaskEv`, NID `rIKEui9oRJg`), until now a `NotImplemented_nid_no_patch` stub. It follows pinned WebKit [`c55364d53f97`](https://github.com/WebKit/WebKit/commit/c55364d53f971f63a709976f168d932d558b8909), the revision the other libSceJsc WTF code already pins. - The pinned [PageBlock.cpp](https://github.com/WebKit/WebKit/blob/c55364d53f971f63a709976f168d932d558b8909/Source/WTF/wtf/PageBlock.cpp#L43-L78) returns `~(pageSize() - 1)`. On `OS(UNIX)`, `pageSize()` is `sysconf(_SC_PAGESIZE)`. The PS5 compiler defines `__FreeBSD__`, which gives `OS(FREEBSD)` and so `OS(UNIX)` ([PlatformOS.h](https://github.com/WebKit/WebKit/blob/c55364d53f971f63a709976f168d932d558b8909/Source/WTF/wtf/PlatformOS.h#L87-L90), [L124-L136](https://github.com/WebKit/WebKit/blob/c55364d53f971f63a709976f168d932d558b8909/Source/WTF/wtf/PlatformOS.h#L124-L136)). - The implementation asks guest libkernel `sysconf(47)` (`_SC_PAGESIZE`). It returns `PS5_PAGE_SIZE`, 16384, the value the `hw.pagesize` entry in `docs/dev/debt/libkernel.md` measured on a PS5 (firmware 13.60, by name and by MIB) and found as a constant in firmware 10.01 kernel data. So `pageMask()` is `0xFFFFFFFFFFFFC000`. libSceJsc now links libkernel privately, as libSceNKWebKit already does. - WebKit `RELEASE_ASSERT`s that the page size is a power of two and not above `CeilingOnPageSize`, which [PageBlock.h](https://github.com/WebKit/WebKit/blob/c55364d53f971f63a709976f168d932d558b8909/Source/WTF/wtf/PageBlock.h#L50-L51) sets to 16 KiB for `PLATFORM(PLAYSTATION)`. Both checks throw `std::runtime_error` where WebKit crashes. The page size and mask are computed once, as WebKit caches them. `src/WtfPageBlock.cpp` follows that control flow, so it starts with the PageBlock notice copied verbatim, plus a `Derived from` line, as the other libSceJsc WTF files do. Reachability: `pageMask()` takes no arguments and needs no object, so any module that imports it from libSceJsc reaches it directly. JSC and WebKit code use it, through `PageBlock` and page-rounding helpers, to align allocation sizes and addresses. Gaps, in a new debt entry: not compared with a console module, and the console WTF version is unverified. libSceNKWebKit's own `WTF::pageSize()` (`src/WtfSystem.cpp`) returns 4096, which does not match this 16 KiB mask; that export is outside this PR. The "Additional callable exports" count goes from main's 322 to 321. ### Tested Linux (Ubuntu 24.04 container, GCC 13.3), Release, `-DBUILD_TESTING=ON`, on head `fa8461e12b` based on `main` `b96058f793`: built `libSceJsc`, the patched `core/libs/libs/libSceJsc.prx` and every libSceJsc test target. `ctest -R '^(guest_jsc_string|jsc_placement_new|jsc_wtf_string_search|jsc_wtf_random|jsc_wtf_url|guest_jsc_trivial_returns|jsc_wtf_helpers|jsc_wtf_page_block|guest_jsc_register_sets_and_constructors|jsc_wtf_sha1|guest_jsc_script_value|jsc_wtf_bit_vector|public_headers)$'` passes 13 of 13. The new `jsc_wtf_page_block` checks exact values: - `pageMask()` is `0xFFFFFFFFFFFFC000`; - `~mask + 1` is 16384; - a second call returns the same mask; - `0x12345678 & mask` is `0x12344000`. All 6 mutations, applied one at a time, make it fail: - `sysconf(48)` instead of 47; - `~pageSize()`; - `pageSize() - 1` without the `~`; - a 4 KiB ceiling (WebKit's x86-64 value), which throws; - an inverted power-of-two check; - a 4096-byte page. `nm -D` on the patched `libSceJsc.prx` lists `rIKEui9oRJg` at the address of `_ZN3WTF8pageMaskEv`. `tools/check_conventions.py --base origin/main --head HEAD` passes and `git diff --check` is clean. `tools/pr_overlap.py --branch` merged the open PRs it could and found no overlap. It could not compare #18430, #18442 and #19772, which conflict with `main`, so I checked them by hand: - #18442 deletes the two `WTF::Unicode` declarations and table rows two lines above `pageMask`, with `JSONImpl::Value::escapeString` unchanged in between; - #18430 and #19772 have no hunk near it. None of them touches `pageMask`, and no open PR mentions `pageMask` or `rIKEui9oRJg`. 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:48 +00:00 (Migrated from github.com)

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

Review: APPROVED


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

  • Conventions: tools/check_conventions.py passed; git diff --check clean.
  • Build: jsc_wtf_page_block_tests built cleanly.
  • CTest (jsc_wtf_page_block):
    1/1 Test #3496: jsc_wtf_page_block ...............   Passed    0.00 sec
    100% tests passed, 0 tests failed out of 1
    
  • Negative control: with core/libs/prx/libSceJsc/Export.cpp, core/libs/prx/libSceJsc/include/InventoryExports.hpp, core/libs/prx/libSceJsc/libSceJsc.hpp reverted to main, the new tests do not build/link without the change; restoring it makes them build and pass.
  • Code reading:
    • Verified src/WtfPageBlock.cpp correctly implements _ZN3WTF8pageMaskEv() (WTF::pageMask()) returning ~(PageSize() - 1), computing a 64-bit page mask of 0xFFFFFFFFFFFFC000 for the PS5 16 KiB page size.
    • Verified SystemPageSize() and PageSize() in src/WtfPageBlock.cpp query guest libkernel sysconf_nid_postfix(47) (_SC_PAGESIZE), validate that the page size is a non-zero power of two and does not exceed CeilingOnPageSize (16 * 1024), throwing std::runtime_error on failure matching WebKit's assertions.
    • Verified thread safety of PageSize() and _ZN3WTF8pageMaskEv() in src/WtfPageBlock.cpp via C++ function-local static constants (pageSize and pageMask), ensuring thread-safe initialization without data races.
    • Verified export definitions and linkage: include/WtfPageBlockExports.hpp and src/WtfPageBlock.cpp declare and define std::size_t APS5_VABI _ZN3WTF8pageMaskEv() with extern "C", while Export.cpp and InventoryExports.hpp correctly remove the old NotImplemented_nid_no_patch stub.
    • Verified CMake build configuration and cross-platform tests in CMakeLists.txt and tests/WtfPageBlock.cpp: libSceJsc links libkernel privately, jsc_wtf_page_block_tests verifies the mask value 0xFFFFFFFFFFFFC000ull, inverse arithmetic, idempotency, and address masking, with correct Windows test environment PATH configuration.
    • Verified AGENTS.md rules compliance: zero comments in code except standard namespace ends and WebKit notice, no made-up success stubs, no hardcoded title IDs, debt correctly recorded in docs/dev/debt/libSceJsc.md, and callable exports count decremented from 322 to 321.
  • Note: the AI-assisted checkbox can stay.

Looks Good To Me

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5903915357 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/19989#pullrequestreview-5903915357). Originally posted by [PrivacyOnion](https://github.com/PrivacyOnion) on 2026-11-14T10:46:48Z. **Review:** APPROVED --- Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against `fa8461e12b`: - **Conventions**: `tools/check_conventions.py` passed; `git diff --check` clean. - **Build**: `jsc_wtf_page_block_tests` built cleanly. - **CTest** (`jsc_wtf_page_block`): ``` 1/1 Test #3496: jsc_wtf_page_block ............... Passed 0.00 sec 100% tests passed, 0 tests failed out of 1 ``` - **Negative control**: with `core/libs/prx/libSceJsc/Export.cpp`, `core/libs/prx/libSceJsc/include/InventoryExports.hpp`, `core/libs/prx/libSceJsc/libSceJsc.hpp` reverted to `main`, the new tests do not build/link without the change; restoring it makes them build and pass. - **Code reading**: - Verified src/WtfPageBlock.cpp correctly implements _ZN3WTF8pageMaskEv() (WTF::pageMask()) returning ~(PageSize() - 1), computing a 64-bit page mask of 0xFFFFFFFFFFFFC000 for the PS5 16 KiB page size. - Verified SystemPageSize() and PageSize() in src/WtfPageBlock.cpp query guest libkernel sysconf_nid_postfix(47) (_SC_PAGESIZE), validate that the page size is a non-zero power of two and does not exceed CeilingOnPageSize (16 * 1024), throwing std::runtime_error on failure matching WebKit's assertions. - Verified thread safety of PageSize() and _ZN3WTF8pageMaskEv() in src/WtfPageBlock.cpp via C++ function-local static constants (pageSize and pageMask), ensuring thread-safe initialization without data races. - Verified export definitions and linkage: include/WtfPageBlockExports.hpp and src/WtfPageBlock.cpp declare and define std::size_t APS5_VABI _ZN3WTF8pageMaskEv() with extern "C", while Export.cpp and InventoryExports.hpp correctly remove the old NotImplemented_nid_no_patch stub. - Verified CMake build configuration and cross-platform tests in CMakeLists.txt and tests/WtfPageBlock.cpp: libSceJsc links libkernel privately, jsc_wtf_page_block_tests verifies the mask value 0xFFFFFFFFFFFFC000ull, inverse arithmetic, idempotency, and address masking, with correct Windows test environment PATH configuration. - Verified AGENTS.md rules compliance: zero comments in code except standard namespace ends and WebKit notice, no made-up success stubs, no hardcoded title IDs, debt correctly recorded in docs/dev/debt/libSceJsc.md, and callable exports count decremented from 322 to 321. - Note: the AI-assisted checkbox can stay. Looks Good To Me
MarcZX10 commented 2026-11-14 13:19:50 +00:00 (Migrated from github.com)

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

Review: COMMENTED


Reviewed — no blocking findings

No blocking defect was found in the inspected implementation; approval is not justified because the reported checks were not run in this review and console behavior remains unverified.

What I ran

Inspected the prepared diff and targeted source at head fa8461e12b74f12539fa4765b9d31b1337a036cd using repo_read.py reader tools. No build or tests were run here; test results in the PR description are author-reported.

Results

Check Result Note
Diff and targeted source review passed Implementation and wiring inspected
Build and tests not run Results reported by author only
Console behavior not run Console WTF version unverified

Findings

Blocking

None.

Non-blocking

None.

Sources

Not verified

No build, test, or console run was performed during this review. The reported Linux build and 13 passing tests are author-reported. The changed source, header, and test files excluded from the prepared diff by rule were read through the reader; other repository files were not exhaustively read.

To get this to a good state

Nothing is required. Optional: confirm the behavior against a console module or console WTF implementation.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5904500765 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/19989#pullrequestreview-5904500765). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-14T13:19:50Z. **Review:** COMMENTED --- # Reviewed — no blocking findings No blocking defect was found in the inspected implementation; approval is not justified because the reported checks were not run in this review and console behavior remains unverified. ## What I ran Inspected the prepared diff and targeted source at head `fa8461e12b74f12539fa4765b9d31b1337a036cd` using `repo_read.py` reader tools. No build or tests were run here; test results in the PR description are author-reported. ## Results | Check | Result | Note | | --- | --- | --- | | Diff and targeted source review | passed | Implementation and wiring inspected | | Build and tests | not run | Results reported by author only | | Console behavior | not run | Console WTF version unverified | ## Findings ### Blocking None. ### Non-blocking None. ## Sources - [WtfPageBlock.cpp](https://github.com/boykopovar/AnyPS5/blob/fa8461e12b74f12539fa4765b9d31b1337a036cd/core/libs/prx/libSceJsc/src/WtfPageBlock.cpp) queries guest `sysconf(47)`, checks the page size, and caches the mask. - [SystemConfiguration.cpp](https://github.com/boykopovar/AnyPS5/blob/fa8461e12b74f12539fa4765b9d31b1337a036cd/core/libs/prx/libkernel/System/src/SystemConfiguration.cpp) maps option 47 to `PS5_PAGE_SIZE`. ## Not verified No build, test, or console run was performed during this review. The reported Linux build and 13 passing tests are author-reported. The changed source, header, and test files excluded from the prepared diff by rule were read through the reader; other repository files were not exhaustively read. ## To get this to a good state Nothing is required. Optional: confirm the behavior against a console module or console WTF implementation.
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!19989
No description provided.