feat(libSceNKWebKit): implement WTF::Mutex and WTF::ThreadCondition #14923

Closed
w4rc0n wants to merge 1 commit from upstream-pr/14923 into main
w4rc0n commented 2026-11-02 01:32:07 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by w4rc0n on 2026-11-02T01:32:07Z.


What

WTF::Mutex and WTF::ThreadCondition were NotImplemented stubs, so guest WebKit code stopped at the first construction, lock or wait. All 13 exports now follow the pinned PS5 WebKit 11.x ThreadingPOSIX.cpp. PlatformPlayStation.cmake builds that file for the PS5, so it is the pthread implementation, not the Windows one.

  • Mutex: Mutex() and ~Mutex() (both variants), lock, tryLock and unlock. It is a normal, non-recursive mutex:
    • locking it again on the owning thread blocks;
    • tryLock returns false while the mutex is held, including from the owner;
    • an unlock from a thread that doesn't own it throws, where the source leaves it undefined.
  • ThreadCondition: ~ThreadCondition() (both variants), wait, timedWait, signal and broadcast. timedWait follows the source's order:
    • minus infinity and a past deadline return false;
    • plus infinity, and a deadline beyond the largest 64-bit time_t, wait without a timeout;
    • any other deadline waits on the absolute wall time, so a clock change is seen.

On the PS5, pthread_mutex_t and pthread_cond_t are one pointer each, and their static initializers are null. Each object is therefore one 8-byte word, which holds a host object created on first use. Two threads racing on first use agree on one object, and the loser frees its own copy. ThreadCondition has no exported constructor, because the guest initializes it inline, so it always starts from that null word.

The debt entry records what remains:

  • the layouts and scheduling aren't verified against console binaries;
  • the guest kernel doesn't see the mutex names;
  • a NaN deadline and an unlock by a thread that isn't the owner throw;
  • destroying a primitive while it is in use isn't supported, as with pthread.

A wait by a thread that doesn't own the mutex also throws, where the source asserts.

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 and #15866 change nearby lines in the same files; whichever merges later keeps both sides.

Tested

Debian 12, GCC 12.2, Linux 6.18, Release, at the head a6e114efc62450eb8bf33a00dab7c18ab9ae31dc, 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. At an earlier commit with the same patch, nkwebkit_wtf also passed 20 repeated runs.
  • The new nkwebkit_wtf cases cover:
    • first use from a zero word by several threads at once, and a counter they contend for;
    • tryLock from the owner, from another thread and on a free mutex;
    • both constructor and destructor variants, and destroying a primitive that was never used;
    • signal waking one waiter and broadcast waking all of them;
    • past, minus-infinity, finite, infinite and very large deadlines;
    • the mutex still held by the caller after every wait returns.
  • tools/progress.py: the 13 exports count as implemented (libSceNKWebKit 1325, 1312 on main).
  • tools/check_conventions.py passes.
  • Windows (GitHub-hosted CI in the author's fork): run 41378226468 built this branch's previous head 0e1fe1e7a62ff0fe1459309bebc6772fe2dd9284. It is AnyPS5's Build workflow, dispatched in the author's fork with select=true: the branch merged into main at 93dbd0f82aea684e95f15f06e7d42c0064af18cf, 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. A wall-clock jump during a wait was not tested. 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:5113584636 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/14923). Originally posted by [w4rc0n](https://github.com/w4rc0n) on 2026-11-02T01:32:07Z. --- ### What `WTF::Mutex` and `WTF::ThreadCondition` were `NotImplemented` stubs, so guest WebKit code stopped at the first construction, lock or wait. All 13 exports now follow the pinned PS5 WebKit 11.x [`ThreadingPOSIX.cpp`](https://github.com/neonmodder123/PS5-WebKit-11.x/blob/80f77e94c63ee7202eec3d4b5b1a021dd89011ba/Source/WTF/wtf/posix/ThreadingPOSIX.cpp#L573-L670). [`PlatformPlayStation.cmake`](https://github.com/neonmodder123/PS5-WebKit-11.x/blob/80f77e94c63ee7202eec3d4b5b1a021dd89011ba/Source/WTF/wtf/PlatformPlayStation.cmake#L18) builds that file for the PS5, so it is the pthread implementation, not the Windows one. - `Mutex`: `Mutex()` and `~Mutex()` (both variants), `lock`, `tryLock` and `unlock`. It is a normal, non-recursive mutex: - locking it again on the owning thread blocks; - `tryLock` returns false while the mutex is held, including from the owner; - an unlock from a thread that doesn't own it throws, where the source leaves it undefined. - `ThreadCondition`: `~ThreadCondition()` (both variants), `wait`, `timedWait`, `signal` and `broadcast`. `timedWait` follows the source's order: - minus infinity and a past deadline return false; - plus infinity, and a deadline beyond the largest 64-bit `time_t`, wait without a timeout; - any other deadline waits on the absolute wall time, so a clock change is seen. On the PS5, `pthread_mutex_t` and `pthread_cond_t` are one pointer each, and their static initializers are null. Each object is therefore one 8-byte word, which holds a host object created on first use. Two threads racing on first use agree on one object, and the loser frees its own copy. `ThreadCondition` has no exported constructor, because the guest initializes it inline, so it always starts from that null word. The debt entry records what remains: - the layouts and scheduling aren't verified against console binaries; - the guest kernel doesn't see the mutex names; - a NaN deadline and an unlock by a thread that isn't the owner throw; - destroying a primitive while it is in use isn't supported, as with pthread. A wait by a thread that doesn't own the mutex also throws, where the source asserts. `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 and #15866 change nearby lines in the same files; whichever merges later keeps both sides. ### 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 `a6e114efc62450eb8bf33a00dab7c18ab9ae31dc`, 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. At an earlier commit with the same patch, `nkwebkit_wtf` also passed 20 repeated runs. - The new `nkwebkit_wtf` cases cover: - first use from a zero word by several threads at once, and a counter they contend for; - `tryLock` from the owner, from another thread and on a free mutex; - both constructor and destructor variants, and destroying a primitive that was never used; - `signal` waking one waiter and `broadcast` waking all of them; - past, minus-infinity, finite, infinite and very large deadlines; - the mutex still held by the caller after every wait returns. - `tools/progress.py`: the 13 exports count as implemented (libSceNKWebKit 1325, 1312 on `main`). - `tools/check_conventions.py` passes. - **Windows (GitHub-hosted CI in the author's fork):** [run 41378226468](https://github.com/w4rc0n/AnyPS5/actions/runs/41378226468) built this branch's previous head `0e1fe1e7a62ff0fe1459309bebc6772fe2dd9284`. It is AnyPS5's `Build` workflow, dispatched in the author's fork with `select=true`: the branch merged into `main` at `93dbd0f82aea684e95f15f06e7d42c0064af18cf`, 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. A wall-clock jump during a wait was not tested. 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!14923
No description provided.