feat(libSceJsc): implement WTF object identifiers and random numbers #19313

Merged
B-Howell merged 3 commits from upstream-pr/19313 into main 2026-11-14 02:11:16 +00:00
B-Howell commented 2026-11-13 03:03:11 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by B-Howell on 2026-11-13T03:03:11Z.


What

Implements five libSceJsc WTF exports that threw: ObjectIdentifierBase::generateIdentifierInternal, ObjectIdentifierBase::generateThreadSafeIdentifierInternal, cryptographicallyRandomNumber, randomNumber and weakRandomUint32. They follow the WebKit revision the library's debt file already pins:

  • ObjectIdentifier.cpp: each generator returns 1, 2, 3 and so on from its own counter. Both counters are std::atomic here.
  • RandomNumber.cpp: randomNumber divides one cryptographicallyRandomNumber word by 2^32, giving [0, 1). weakRandomUint32 advances one shared xorshift128+ generator, written as WeakRandom.h does and seeded from cryptographicallyRandomNumber. A mutex guards that state, which WebKit leaves racy.
  • cryptographicallyRandomNumber reuses the existing HostEntropy_nid_no_patch instead of WebKit's ARC4 generator.

The typed prototypes move from InventoryExports.hpp to a new WtfRandomExports.hpp. The five inventory rows are removed, the table count goes from main's stated 330 to 325, and a debt entry records that none of this has been compared with a console module. createCanonicalUUIDString is left out, because it returns a WTF::String.

Tested

Ubuntu WSL2, GCC, Release, Ninja.

  • Red control (on b72a0cd5201): with the new test and typed header but the Export.cpp stubs still in place, jsc_wtf_random fails 3/3: Subprocess aborted, _ZN3WTF20ObjectIdentifierBase26generateIdentifierInternalEv not implemented.
  • With this change, on dac63a20c52 (the PR head 9c896c566be differs only in the debt entry wording): jsc_wtf_random passes 3/3. It checks that both counters start at 1, are independent and step by one; that 4 threads x 2000 thread-safe calls give unique, dense values; that randomNumber stays in [0, 1); and that the three random sources vary, with cryptographicallyRandomNumber setting and clearing all 32 bits across 256 calls.
  • jsc_wtf_url, jsc_wtf_string_search, jsc_placement_new and guest_jsc_string pass, and public_headers passes 65/65.
  • tools/progress.py: libraries done goes from 15578 on main 7a6183485f7 to 15583 (+5) out of 39251; libSceJsc goes from 64 to 69.
  • Overlap: pr_overlap against 1492 open PRs on main a6606d5bab7 found #18951 editing neighbouring Export.cpp lines (a text conflict only, with no shared exports). It could not compare #18430 and #18442, so they were checked by hand; neither touches these five exports.
  • On 28a3bb1fe67, an ordinary merge of main at e90cbbc086f after #19188, #19193 and #19271, whose libSceJsc changes landed within 50 lines of ours. The callable-exports count is main's stated 330 minus these five (325). Rebuilt on WSL Ubuntu, GCC, Release: jsc_wtf_random, jsc_wtf_sha1 and jsc_wtf_bit_vector passed. Conventions passed.

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:5289204992 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/19313). Originally posted by [B-Howell](https://github.com/B-Howell) on 2026-11-13T03:03:11Z. --- ### What Implements five `libSceJsc` WTF exports that threw: `ObjectIdentifierBase::generateIdentifierInternal`, `ObjectIdentifierBase::generateThreadSafeIdentifierInternal`, `cryptographicallyRandomNumber`, `randomNumber` and `weakRandomUint32`. They follow the WebKit revision the library's debt file already pins: - [ObjectIdentifier.cpp](https://github.com/WebKit/WebKit/blob/c55364d53f97/Source/WTF/wtf/ObjectIdentifier.cpp#L32-L46): each generator returns 1, 2, 3 and so on from its own counter. Both counters are `std::atomic` here. - [RandomNumber.cpp](https://github.com/WebKit/WebKit/blob/c55364d53f97/Source/WTF/wtf/RandomNumber.cpp#L38-L50): `randomNumber` divides one `cryptographicallyRandomNumber` word by 2^32, giving [0, 1). `weakRandomUint32` advances one shared xorshift128+ generator, written as [WeakRandom.h](https://github.com/WebKit/WebKit/blob/c55364d53f97/Source/WTF/wtf/WeakRandom.h#L44-L117) does and seeded from `cryptographicallyRandomNumber`. A mutex guards that state, which WebKit leaves racy. - `cryptographicallyRandomNumber` reuses the existing `HostEntropy_nid_no_patch` instead of WebKit's [ARC4 generator](https://github.com/WebKit/WebKit/blob/c55364d53f97/Source/WTF/wtf/CryptographicallyRandomNumber.cpp#L139-L179). The typed prototypes move from `InventoryExports.hpp` to a new `WtfRandomExports.hpp`. The five inventory rows are removed, the table count goes from main's stated 330 to 325, and a debt entry records that none of this has been compared with a console module. `createCanonicalUUIDString` is left out, because it returns a `WTF::String`. ### 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. --> Ubuntu WSL2, GCC, Release, Ninja. - Red control (on `b72a0cd5201`): with the new test and typed header but the `Export.cpp` stubs still in place, `jsc_wtf_random` fails 3/3: `Subprocess aborted`, `_ZN3WTF20ObjectIdentifierBase26generateIdentifierInternalEv not implemented`. - With this change, on `dac63a20c52` (the PR head `9c896c566be` differs only in the debt entry wording): `jsc_wtf_random` passes 3/3. It checks that both counters start at 1, are independent and step by one; that 4 threads x 2000 thread-safe calls give unique, dense values; that `randomNumber` stays in [0, 1); and that the three random sources vary, with `cryptographicallyRandomNumber` setting and clearing all 32 bits across 256 calls. - `jsc_wtf_url`, `jsc_wtf_string_search`, `jsc_placement_new` and `guest_jsc_string` pass, and `public_headers` passes 65/65. - `tools/progress.py`: libraries done goes from 15578 on main `7a6183485f7` to 15583 (+5) out of 39251; `libSceJsc` goes from 64 to 69. - Overlap: `pr_overlap` against 1492 open PRs on main `a6606d5bab7` found #18951 editing neighbouring `Export.cpp` lines (a text conflict only, with no shared exports). It could not compare #18430 and #18442, so they were checked by hand; neither touches these five exports. - On `28a3bb1fe67`, an ordinary merge of `main` at `e90cbbc086f` after #19188, #19193 and #19271, whose `libSceJsc` changes landed within 50 lines of ours. The callable-exports count is main's stated 330 minus these five (325). Rebuilt on WSL Ubuntu, GCC, Release: `jsc_wtf_random`, `jsc_wtf_sha1` and `jsc_wtf_bit_vector` passed. Conventions passed. ### 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-13 12:43:51 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-13T12:43:51Z.

Review: APPROVED


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

  • Conventions: tools/check_conventions.py passed; git diff --check clean.
  • Build: jsc_wtf_random_tests built cleanly.
  • CTest (jsc_wtf_random):
    1/1 Test #3383: jsc_wtf_random ...................   Passed    0.03 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 core/libs/prx/libSceJsc/src/WtfRandom.cpp xorshift128+ implementation (NextState, Advance, GetUint32) and seed handling in WeakRandom matches WebKit WeakRandom.h, with thread safety ensured via std::mutex in _ZN3WTF16weakRandomUint32Ev.
    • Verified _ZN3WTF12randomNumberEv in core/libs/prx/libSceJsc/src/WtfRandom.cpp divides 32-bit entropy by 2^32 (std::numeric_limitsstd::uint32_t::max() + 1.0), correctly producing values in [0.0, 1.0) without loss of precision.
    • Verified _ZN3WTF20ObjectIdentifierBase26generateIdentifierInternalEv and _ZN3WTF20ObjectIdentifierBase36generateThreadSafeIdentifierInternalEv in core/libs/prx/libSceJsc/src/WtfRandom.cpp use independent std::atomicstd::uint64_t counters starting from 0 and returning dense 1-based IDs via pre-increment.
    • Verified all five exports in core/libs/prx/libSceJsc/include/WtfRandomExports.hpp and core/libs/prx/libSceJsc/src/WtfRandom.cpp are declared extern "C" with APS5_VABI calling convention and correct return types (double, unsigned int, uint64_t, uint32_t).
    • Verified strict compliance with AGENTS.md rules: zero code comments (only namespace end comment in WtfRandom.cpp:47), technical debt accurately recorded in docs/dev/debt/libSceJsc.md, and unimplemented inventory count reduced from 331 to 326.
    • Verified test coverage in core/libs/prx/libSceJsc/tests/WtfRandom.cpp rigorously validates initial counter values, multi-threaded uniqueness and density across 4 threads x 2000 iterations, random range [0, 1), and full 32-bit entropy coverage.
  • Minor: please drop the Generated with footer from the description; the AI-assisted checkbox can stay.

Looks Good To Me

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5891211356 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/19313#pullrequestreview-5891211356). Originally posted by [PrivacyOnion](https://github.com/PrivacyOnion) on 2026-11-13T12:43:51Z. **Review:** APPROVED --- Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against `9c896c566b`: - **Conventions**: `tools/check_conventions.py` passed; `git diff --check` clean. - **Build**: `jsc_wtf_random_tests` built cleanly. - **CTest** (`jsc_wtf_random`): ``` 1/1 Test #3383: jsc_wtf_random ................... Passed 0.03 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 core/libs/prx/libSceJsc/src/WtfRandom.cpp xorshift128+ implementation (NextState, Advance, GetUint32) and seed handling in WeakRandom matches WebKit WeakRandom.h, with thread safety ensured via std::mutex in _ZN3WTF16weakRandomUint32Ev. - Verified _ZN3WTF12randomNumberEv in core/libs/prx/libSceJsc/src/WtfRandom.cpp divides 32-bit entropy by 2^32 (std::numeric_limits<std::uint32_t>::max() + 1.0), correctly producing values in [0.0, 1.0) without loss of precision. - Verified _ZN3WTF20ObjectIdentifierBase26generateIdentifierInternalEv and _ZN3WTF20ObjectIdentifierBase36generateThreadSafeIdentifierInternalEv in core/libs/prx/libSceJsc/src/WtfRandom.cpp use independent std::atomic<std::uint64_t> counters starting from 0 and returning dense 1-based IDs via pre-increment. - Verified all five exports in core/libs/prx/libSceJsc/include/WtfRandomExports.hpp and core/libs/prx/libSceJsc/src/WtfRandom.cpp are declared extern "C" with APS5_VABI calling convention and correct return types (double, unsigned int, uint64_t, uint32_t). - Verified strict compliance with AGENTS.md rules: zero code comments (only namespace end comment in WtfRandom.cpp:47), technical debt accurately recorded in docs/dev/debt/libSceJsc.md, and unimplemented inventory count reduced from 331 to 326. - Verified test coverage in core/libs/prx/libSceJsc/tests/WtfRandom.cpp rigorously validates initial counter values, multi-threaded uniqueness and density across 4 threads x 2000 iterations, random range [0, 1), and full 32-bit entropy coverage. - Minor: please drop the `Generated with` footer from the description; the AI-assisted checkbox can stay. Looks Good To Me
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!19313
No description provided.