feat(libSceNKWebKit): implement WTF::BinarySemaphore #14922

Closed
w4rc0n wants to merge 2 commits from upstream-pr/14922 into main
w4rc0n commented 2026-11-02 01:32:01 +00:00 (Migrated from github.com)

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


What

WTF::BinarySemaphore::signal() and waitUntil(const TimeWithDynamicClockType&) were NotImplemented stubs. WebKit uses BinarySemaphore to hand work from one thread to another, so those paths threw. Both now behave as the pinned PS5 WebKit 11.x BinarySemaphore.cpp does. They are written independently on #14921's ParkingLot, not as a port of its Lock and Condition sequence:

  • Layout: three bytes, as in the guest's inline constructor: m_isSet at 0, the Lock byte at 1 and Condition's byte at 2, pinned with static_assert. The lock and condition bytes stay zero and unused: BinarySemaphore.h has only the constructor and inline wait forwarding to the exported waitUntil, so no guest inline code touches them.
  • signal: sets the flag while waking one waiter under the queue lock. Repeated signals collapse into one.
  • waitUntil: consumes the flag during the park validation, and parks directly on the flag while it is unset. A timeout makes one last attempt to consume it. Success consumes the signal.

It calls the parent's ParkingLot functions directly, with no new exports or cross-library helpers. The debt entry records that layouts and scheduling aren't verified against a console.

Adapted source: none in this PR. BinarySemaphore is written independently on #14921's ParkingLot, whose adapted lock code is in src/WtfLock.cpp under its notice.

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. #13947, #13992, #14172, #14981, #15011, #15215 and #15866 change nearby lines in the same files; whichever merges later keeps both sides. The only exports it shares are with #14921, in the same stack.

Tested

Debian 12, GCC 12.2, Linux 6.18, Release, at the head 0e54a3edd9f430785c0201831364bcd8f7f56c76, which is on #14921's head 43e5f65b65b95b14fcc2a5f6a75fe26880525385. 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 the pre-rebase commit with the same patch, the semaphore suite also passed 50 consecutive repetitions (3.2 s in total).
  • The new nkwebkit_wtf cases check public behaviour only:
    • a signal before the wait, consumed once;
    • a past deadline with no signal returning false, and finite timeouts on three clocks;
    • a waiting thread woken by signal from another thread, with a handshake rather than sleeps;
    • repeated signals not stacking, and two consumers needing two signals.
  • tools/progress.py: both exports count as implemented (libSceNKWebKit 1322, against 1320 with #14921).
  • tools/check_conventions.py passes.
  • Windows (GitHub-hosted CI in the author's fork): run 41822639868 built this branch's previous head f54a49c07fd92fbc915bd64bd9a8241ad532f2ca. It is AnyPS5's Build workflow, dispatched in the author's fork with select=true: the branch merged into main at b11c7bf84f5d2f636ff60166cc3371bd071e24d5, built on windows-latest with WinLibs GCC 15.2 (MinGW-w64, UCRT). All 809 selected tests passed, none skipped, including the twelve NKWebKit tests, public_headers and patched_libraries. A fork-internal pull request existed only to give the workflow a number. The rebase onto main at 0eba5db30d8a3d03789e52e5c1a9ff853e4e33e4 after #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.

Not built or run: macOS. 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: #14921
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5113583970 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/14922). Originally posted by [w4rc0n](https://github.com/w4rc0n) on 2026-11-02T01:32:01Z. --- ### What `WTF::BinarySemaphore::signal()` and `waitUntil(const TimeWithDynamicClockType&)` were `NotImplemented` stubs. WebKit uses `BinarySemaphore` to hand work from one thread to another, so those paths threw. Both now behave as the pinned PS5 WebKit 11.x [`BinarySemaphore.cpp`](https://github.com/neonmodder123/PS5-WebKit-11.x/blob/80f77e94c63ee7202eec3d4b5b1a021dd89011ba/Source/WTF/wtf/threads/BinarySemaphore.cpp#L31-L48) does. They are written independently on #14921's `ParkingLot`, not as a port of its `Lock` and `Condition` sequence: - **Layout:** three bytes, as in the guest's inline constructor: `m_isSet` at 0, the `Lock` byte at 1 and `Condition`'s byte at 2, pinned with `static_assert`. The lock and condition bytes stay zero and unused: [`BinarySemaphore.h`](https://github.com/neonmodder123/PS5-WebKit-11.x/blob/80f77e94c63ee7202eec3d4b5b1a021dd89011ba/Source/WTF/wtf/threads/BinarySemaphore.h) has only the constructor and inline `wait` forwarding to the exported `waitUntil`, so no guest inline code touches them. - **`signal`:** sets the flag while waking one waiter under the queue lock. Repeated signals collapse into one. - **`waitUntil`:** consumes the flag during the park validation, and parks directly on the flag while it is unset. A timeout makes one last attempt to consume it. Success consumes the signal. It calls the parent's `ParkingLot` functions directly, with no new exports or cross-library helpers. The debt entry records that layouts and scheduling aren't verified against a console. **Adapted source:** none in this PR. `BinarySemaphore` is written independently on #14921's `ParkingLot`, whose adapted lock code is in `src/WtfLock.cpp` under its notice. `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. #13947, #13992, #14172, #14981, #15011, #15215 and #15866 change nearby lines in the same files; whichever merges later keeps both sides. The only exports it shares are with #14921, in the same stack. ### 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 `0e54a3edd9f430785c0201831364bcd8f7f56c76`, which is on #14921's head `43e5f65b65b95b14fcc2a5f6a75fe26880525385`. 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 the pre-rebase commit with the same patch, the semaphore suite also passed 50 consecutive repetitions (3.2 s in total). - The new `nkwebkit_wtf` cases check public behaviour only: - a signal before the wait, consumed once; - a past deadline with no signal returning false, and finite timeouts on three clocks; - a waiting thread woken by `signal` from another thread, with a handshake rather than sleeps; - repeated signals not stacking, and two consumers needing two signals. - `tools/progress.py`: both exports count as implemented (libSceNKWebKit 1322, against 1320 with #14921). - `tools/check_conventions.py` passes. - **Windows (GitHub-hosted CI in the author's fork):** [run 41822639868](https://github.com/w4rc0n/AnyPS5/actions/runs/41822639868) built this branch's previous head `f54a49c07fd92fbc915bd64bd9a8241ad532f2ca`. It is AnyPS5's `Build` workflow, dispatched in the author's fork with `select=true`: the branch merged into `main` at `b11c7bf84f5d2f636ff60166cc3371bd071e24d5`, built on `windows-latest` with WinLibs GCC 15.2 (MinGW-w64, UCRT). All 809 selected tests passed, none skipped, including the twelve NKWebKit tests, `public_headers` and `patched_libraries`. A fork-internal pull request existed only to give the workflow a number. The rebase onto `main` at `0eba5db30d8a3d03789e52e5c1a9ff853e4e33e4` after #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. Not built or run: macOS. 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: #14921 - [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!14922
No description provided.