feat(libSceNKWebKit): implement WTF callOnMainThread and callOnMainRunLoop, with their AndWait forms #19363

Merged
B-Howell merged 17 commits from upstream-pr/19363 into main 2026-11-15 05:09:30 +00:00
B-Howell commented 2026-11-13 06:21:14 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by B-Howell on 2026-11-13T06:21:14Z.


What

Implements four existing throwing libSceNKWebKit stubs: WTF::callOnMainThread, WTF::callOnMainRunLoop, WTF::callOnMainThreadAndWait and WTF::callOnMainRunLoopAndWait.

They follow the pinned MainThread.cpp with USE(WEB_THREAD) off, where both forms call RunLoop::main().dispatch(WTFMove(function)). The pinned WKRunLoop.cpp shows that WKRunLoopCallOnMainThread and WKRunLoopRunMain use that same main run loop. So these four reuse the queue that already exists in src/RunLoop.cpp and the isMainThread/isMainRunLoop that already exist in src/WtfMainThread.cpp, instead of adding a second queue.

  • The call takes ownership of the WTF::Function callable and sets the caller's Function to null, as WTFMove does. The callable runs on the main loop and is then destroyed through its deleting destructor. If the call throws, it is still destroyed.

  • On the main thread the AndWait forms run the callable inline and leave it owned by the caller, as upstream's function() does. From any other thread they queue it and block on a host semaphore until it has run. The order is call, then signal, then destroy, as in upstream.

  • The ABI follows the pinned Function.h: Function is one std::unique_ptr<Impl> (8 bytes), and CallableWrapperBase has the Itanium vtable [D1, D0, call]. Both are pinned with static_assert in src/WtfFunctionAbi.hpp.

  • A null or empty Function throws std::invalid_argument, where upstream would call through a null pointer.

  • The debt entry is added, and the four implemented rows are removed from the inventory table.

The wait uses a host-internal std::promise that nothing exports, so this does not overlap #14922 (WTF::BinarySemaphore).

tools/progress.py --compare against main: +5 implemented functions (libSceNKWebKit 2986/11258 → 2991/11259). Four of them are the exports. The fifth is the internal APS5_VABI trampoline that the run-loop callback type requires.

Tested

All runs are on Linux (WSL2 Ubuntu 22.04, GCC 11, Release, Ninja).

  • New nkwebkit_WtfCallOnMain. It checks dispatch to the main loop from the main thread and from a worker, that ownership is taken, that exactly one deleting destructor runs and no complete destructor runs, that the AndWait forms run inline on the main thread with the caller keeping ownership, and that a worker's AndWait stays blocked until the main thread pumps the loop. It also checks that null or empty Functions throw and that a throwing callable is still destroyed.

    • Red control: with the four exports as throwing stubs, the test fails with Subprocess aborted and what(): _ZN3WTF16callOnMainThreadEONS_8FunctionIFvvEEE not implemented. Against main's original int f() stubs, the test does not compile: conflicting declaration of C function.

    • With this change: nkwebkit_wtfcallonmain ... Passed 0.11 sec, 3/3 runs.

  • ctest -R '^public_headers': 100% of 65 passed.

  • After review 5887093870, on a52ff1d6d1a: a worker's AndWait with a throwing callable now catches the exception after the callable is destroyed, the loop keeps running, and an inline throw keeps the caller's Function; nkwebkit_wtfcallonmain passes 3/3, and with the previous WtfMainThread.cpp the same test hangs (Timeout, 30 s).

  • nkwebkit_base and nkwebkit_mainthread: both pass.

  • Not tested against a console module or a title.

  • On 3b9f0587e6a, an ordinary merge of main at 82160bba912 after #18538, conventions passed; doc-only conflict on the count line; count is main's stated 5949 minus this change's 4 removed stubs (5945). Main's code changes since the last merge are over 1,000 lines from this PR's hunks, so the earlier test results stand. 0000b5409a2 then adds the shared main-thread assumption to the debt entry (doc only).

  • On 117faeb7cbc, an ordinary merge of main at f86ca3fa559 after #19322 and #17764: Export.cpp and InventoryExports.hpp conflicted only on adjacent stub removals (ours callOnMainRunLoopAndWait, main's currentTextBreakLocaleID), resolved by keeping both removals; count is main's stated 5940 minus this change's 4 removed stubs (5936). Windows 11, WinLibs GCC 15.2.0 r7 UCRT, Release: nkwebkit_wtfcallonmain 3/3; conventions passed.

  • On 2cf39cc0eb4, an ordinary merge of main at c612c4c9e89 after #19460; doc-only union merge of the count line; count is main's stated 5939 minus this change's 4 removed stubs (5935). Windows 11, WinLibs GCC 15.2.0 r7 UCRT, Release: nkwebkit_wtfcallonmain 3/3; conventions passed.

  • On 2af4ff41a3e: merged main after #19603; count line removed. Ordinary merge of main at 9b22c40f49a, conventions passed. The debt diff against main is now only this PR's entry and its 4 removed table rows. No code conflict and main changed none of this PR's other files, so not rebuilt.

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:5291120461 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/19363). Originally posted by [B-Howell](https://github.com/B-Howell) on 2026-11-13T06:21:14Z. --- ### What Implements four existing throwing `libSceNKWebKit` stubs: `WTF::callOnMainThread`, `WTF::callOnMainRunLoop`, `WTF::callOnMainThreadAndWait` and `WTF::callOnMainRunLoopAndWait`. They follow the pinned [MainThread.cpp](https://github.com/neonmodder123/PS5-WebKit-11.x/blob/80f77e94c63ee7202eec3d4b5b1a021dd89011ba/Source/WTF/wtf/MainThread.cpp#L66-L145) with `USE(WEB_THREAD)` off, where both forms call `RunLoop::main().dispatch(WTFMove(function))`. The pinned [WKRunLoop.cpp](https://github.com/neonmodder123/PS5-WebKit-11.x/blob/80f77e94c63ee7202eec3d4b5b1a021dd89011ba/Source/WebKit/UIProcess/API/C/playstation/WKRunLoop.cpp) shows that `WKRunLoopCallOnMainThread` and `WKRunLoopRunMain` use that same main run loop. So these four reuse the queue that already exists in `src/RunLoop.cpp` and the `isMainThread`/`isMainRunLoop` that already exist in `src/WtfMainThread.cpp`, instead of adding a second queue. - The call takes ownership of the `WTF::Function` callable and sets the caller's `Function` to null, as `WTFMove` does. The callable runs on the main loop and is then destroyed through its deleting destructor. If the call throws, it is still destroyed. - On the main thread the `AndWait` forms run the callable inline and leave it owned by the caller, as upstream's `function()` does. From any other thread they queue it and block on a host semaphore until it has run. The order is call, then signal, then destroy, as in upstream. - The ABI follows the pinned [Function.h](https://github.com/neonmodder123/PS5-WebKit-11.x/blob/80f77e94c63ee7202eec3d4b5b1a021dd89011ba/Source/WTF/wtf/Function.h#L37-L121): `Function` is one `std::unique_ptr<Impl>` (8 bytes), and `CallableWrapperBase` has the Itanium vtable `[D1, D0, call]`. Both are pinned with `static_assert` in `src/WtfFunctionAbi.hpp`. - A null or empty `Function` throws `std::invalid_argument`, where upstream would call through a null pointer. - The debt entry is added, and the four implemented rows are removed from the inventory table. The wait uses a host-internal `std::promise` that nothing exports, so this does not overlap #14922 (`WTF::BinarySemaphore`). `tools/progress.py --compare` against main: +5 implemented functions (libSceNKWebKit 2986/11258 → 2991/11259). Four of them are the exports. The fifth is the internal `APS5_VABI` trampoline that the run-loop callback type requires. ### Tested All runs are on Linux (WSL2 Ubuntu 22.04, GCC 11, Release, Ninja). - New `nkwebkit_WtfCallOnMain`. It checks dispatch to the main loop from the main thread and from a worker, that ownership is taken, that exactly one deleting destructor runs and no complete destructor runs, that the `AndWait` forms run inline on the main thread with the caller keeping ownership, and that a worker's `AndWait` stays blocked until the main thread pumps the loop. It also checks that null or empty `Function`s throw and that a throwing callable is still destroyed. - Red control: with the four exports as throwing stubs, the test fails with `Subprocess aborted` and `what(): _ZN3WTF16callOnMainThreadEONS_8FunctionIFvvEEE not implemented`. Against main's original `int f()` stubs, the test does not compile: `conflicting declaration of C function`. - With this change: `nkwebkit_wtfcallonmain ... Passed 0.11 sec`, 3/3 runs. - `ctest -R '^public_headers'`: 100% of 65 passed. - After review 5887093870, on `a52ff1d6d1a`: a worker's `AndWait` with a throwing callable now catches the exception after the callable is destroyed, the loop keeps running, and an inline throw keeps the caller's `Function`; `nkwebkit_wtfcallonmain` passes 3/3, and with the previous `WtfMainThread.cpp` the same test hangs (`Timeout`, 30 s). - `nkwebkit_base` and `nkwebkit_mainthread`: both pass. - Not tested against a console module or a title. - On `3b9f0587e6a`, an ordinary merge of `main` at `82160bba912` after #18538, conventions passed; doc-only conflict on the count line; count is main's stated 5949 minus this change's 4 removed stubs (5945). Main's code changes since the last merge are over 1,000 lines from this PR's hunks, so the earlier test results stand. `0000b5409a2` then adds the shared main-thread assumption to the debt entry (doc only). - On `117faeb7cbc`, an ordinary merge of `main` at `f86ca3fa559` after #19322 and #17764: Export.cpp and InventoryExports.hpp conflicted only on adjacent stub removals (ours `callOnMainRunLoopAndWait`, main's `currentTextBreakLocaleID`), resolved by keeping both removals; count is main's stated 5940 minus this change's 4 removed stubs (5936). Windows 11, WinLibs GCC 15.2.0 r7 UCRT, Release: `nkwebkit_wtfcallonmain` 3/3; conventions passed. - On `2cf39cc0eb4`, an ordinary merge of `main` at `c612c4c9e89` after #19460; doc-only union merge of the count line; count is main's stated 5939 minus this change's 4 removed stubs (5935). Windows 11, WinLibs GCC 15.2.0 r7 UCRT, Release: `nkwebkit_wtfcallonmain` 3/3; conventions passed. - On `2af4ff41a3e`: merged main after #19603; count line removed. Ordinary merge of `main` at `9b22c40f49a`, conventions passed. The debt diff against main is now only this PR's entry and its 4 removed table rows. No code conflict and main changed none of this PR's other files, so not rebuilt. ### 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 06:32:15 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-13T06:32:15Z.

Review: CHANGES_REQUESTED


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

  • Conventions: tools/check_conventions.py passed; git diff --check clean.
  • Build: nkwebkit_wtfcallonmain_tests built cleanly.
  • CTest (nkwebkit_wtfcallonmain):
    1/1 Test #3890: nkwebkit_wtfcallonmain ...........   Passed    0.11 sec
    100% tests passed, 0 tests failed out of 1
    
  • Negative control: with core/libs/prx/libSceNKWebKit/Export.cpp, core/libs/prx/libSceNKWebKit/include/InventoryExports.hpp, core/libs/prx/libSceNKWebKit/include/WtfExports.hpp, core/libs/prx/libSceNKWebKit/src/WtfMainThread.cpp reverted to main, the new tests do not build/link without the change; restoring it makes them build and pass.
  • Code reading:
    • Verified ABI layout and static assertions in core/libs/prx/libSceNKWebKit/src/WtfFunctionAbi.hpp, confirming VoidCallableWrapperVtable offsets (completeDestructor at 0, deletingDestructor at 8, call at 16, total size 24) and VoidFunction size (8 bytes) match the Itanium ABI for WTF::Function.
    • Verified null-pointer checks in core/libs/prx/libSceNKWebKit/src/WtfMainThread.cpp:RequireCallable, confirming both null VoidFunction* pointers and null callableWrapper members throw std::invalid_argument as documented in docs/dev/debt/libSceNKWebKit.md.
    • Verified export signatures and replacement of throwing stubs across core/libs/prx/libSceNKWebKit/Export.cpp, core/libs/prx/libSceNKWebKit/include/InventoryExports.hpp, and core/libs/prx/libSceNKWebKit/include/WtfExports.hpp for WTF::callOnMainThread, WTF::callOnMainRunLoop, WTF::callOnMainThreadAndWait, and WTF::callOnMainRunLoopAndWait.
    • Verified technical debt inventory updates in docs/dev/debt/libSceNKWebKit.md, confirming the callable exports table count decremented by 4 (5950 to 5946) and matching NIDs were removed.
    • Verified exception propagation and semaphore signaling paths in core/libs/prx/libSceNKWebKit/src/WtfMainThread.cpp:RunMainTask when executing callables dispatched via CallOnMainAndWait from worker threads.
    • Verified synchronization and object lifetimes between worker-thread semaphore.acquire() in core/libs/prx/libSceNKWebKit/src/WtfMainThread.cpp:CallOnMainAndWait and main-thread task execution in RunMainTask.
  • Concerns:
    • core/libs/prx/libSceNKWebKit/src/WtfMainThread.cpp:51-56: In RunMainTask, task->callableWrapper->vtable->call(task->callableWrapper) is executed on line 52 without an RAII guard or try/catch block ensuring semaphore release. When a callable dispatched synchronously from a worker thread via _ZN3WTF23callOnMainThreadAndWaitEONS_8FunctionIFvvEEE or _ZN3WTF24callOnMainRunLoopAndWaitEONS_8FunctionIFvvEEE throws an exception (as supported and tested for asynchronous dispatch in TestThrowingCallableIsDestroyed), stack unwinding bypasses line 54 (task->semaphore->release()). The calling worker thread waiting at semaphore.acquire() on line 76 is never signaled and remains permanently deadlocked.
    • core/libs/prx/libSceNKWebKit/src/WtfMainThread.cpp:53-56: In CallOnMainAndWait, std::binary_semaphore semaphore{0} is allocated on the worker thread's local stack. In RunMainTask, task->semaphore->release() signals the semaphore on line 54 before the MainTask context is destroyed. The worker thread immediately unblocks from semaphore.acquire() on line 76 and returns from CallOnMainAndWait, destroying the stack-allocated semaphore object while RunMainTask is still in flight on the main thread executing ~MainTask() and calling callableWrapper->vtable->deletingDestructor(callableWrapper). This introduces a data race on the stack semaphore and causes the callable's destructor to execute concurrently on the main thread while the caller on the worker thread has already resumed execution.
    • core/libs/prx/libSceNKWebKit/src/WtfMainThread.cpp:68-76: CallOnMainAndWait introduces inconsistent, caller-mutating ownership semantics depending on which thread executes it. When called on the main thread (isMain == true), line 69 obtains the callable wrapper via RequireCallable without clearing function->callableWrapper or executing deletingDestructor. When called from any worker thread (isMain == false), line 75 routes through DispatchToMain, which invokes TakeCallable on line 62 and nullifies function->callableWrapper while delegating destruction to MainTask on the main thread. In upstream WebKit (MainThread.cpp), callOnMainThreadAndWait captures &function by reference without transferring ownership or clearing the caller's Function on either thread; conditionally stealing ownership and mutating caller state on worker threads while leaving it intact on the main thread violates the calling convention and corrupts caller state.
  • Minor: please drop the Generated with footer from the description; the AI-assisted checkbox can stay.

Requesting changes for the points above.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5887093870 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/19363#pullrequestreview-5887093870). Originally posted by [PrivacyOnion](https://github.com/PrivacyOnion) on 2026-11-13T06:32:15Z. **Review:** CHANGES_REQUESTED --- Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against `c7b3bec7ba`: - **Conventions**: `tools/check_conventions.py` passed; `git diff --check` clean. - **Build**: `nkwebkit_wtfcallonmain_tests` built cleanly. - **CTest** (`nkwebkit_wtfcallonmain`): ``` 1/1 Test #3890: nkwebkit_wtfcallonmain ........... Passed 0.11 sec 100% tests passed, 0 tests failed out of 1 ``` - **Negative control**: with `core/libs/prx/libSceNKWebKit/Export.cpp`, `core/libs/prx/libSceNKWebKit/include/InventoryExports.hpp`, `core/libs/prx/libSceNKWebKit/include/WtfExports.hpp`, `core/libs/prx/libSceNKWebKit/src/WtfMainThread.cpp` reverted to `main`, the new tests do not build/link without the change; restoring it makes them build and pass. - **Code reading**: - Verified ABI layout and static assertions in core/libs/prx/libSceNKWebKit/src/WtfFunctionAbi.hpp, confirming VoidCallableWrapperVtable offsets (completeDestructor at 0, deletingDestructor at 8, call at 16, total size 24) and VoidFunction size (8 bytes) match the Itanium ABI for WTF::Function. - Verified null-pointer checks in core/libs/prx/libSceNKWebKit/src/WtfMainThread.cpp:RequireCallable, confirming both null VoidFunction* pointers and null callableWrapper members throw std::invalid_argument as documented in docs/dev/debt/libSceNKWebKit.md. - Verified export signatures and replacement of throwing stubs across core/libs/prx/libSceNKWebKit/Export.cpp, core/libs/prx/libSceNKWebKit/include/InventoryExports.hpp, and core/libs/prx/libSceNKWebKit/include/WtfExports.hpp for WTF::callOnMainThread, WTF::callOnMainRunLoop, WTF::callOnMainThreadAndWait, and WTF::callOnMainRunLoopAndWait. - Verified technical debt inventory updates in docs/dev/debt/libSceNKWebKit.md, confirming the callable exports table count decremented by 4 (5950 to 5946) and matching NIDs were removed. - Verified exception propagation and semaphore signaling paths in core/libs/prx/libSceNKWebKit/src/WtfMainThread.cpp:RunMainTask when executing callables dispatched via CallOnMainAndWait from worker threads. - Verified synchronization and object lifetimes between worker-thread semaphore.acquire() in core/libs/prx/libSceNKWebKit/src/WtfMainThread.cpp:CallOnMainAndWait and main-thread task execution in RunMainTask. - **Concerns**: - core/libs/prx/libSceNKWebKit/src/WtfMainThread.cpp:51-56: In RunMainTask, task->callableWrapper->vtable->call(task->callableWrapper) is executed on line 52 without an RAII guard or try/catch block ensuring semaphore release. When a callable dispatched synchronously from a worker thread via _ZN3WTF23callOnMainThreadAndWaitEONS_8FunctionIFvvEEE or _ZN3WTF24callOnMainRunLoopAndWaitEONS_8FunctionIFvvEEE throws an exception (as supported and tested for asynchronous dispatch in TestThrowingCallableIsDestroyed), stack unwinding bypasses line 54 (task->semaphore->release()). The calling worker thread waiting at semaphore.acquire() on line 76 is never signaled and remains permanently deadlocked. - core/libs/prx/libSceNKWebKit/src/WtfMainThread.cpp:53-56: In CallOnMainAndWait, std::binary_semaphore semaphore{0} is allocated on the worker thread's local stack. In RunMainTask, task->semaphore->release() signals the semaphore on line 54 before the MainTask context is destroyed. The worker thread immediately unblocks from semaphore.acquire() on line 76 and returns from CallOnMainAndWait, destroying the stack-allocated semaphore object while RunMainTask is still in flight on the main thread executing ~MainTask() and calling callableWrapper->vtable->deletingDestructor(callableWrapper). This introduces a data race on the stack semaphore and causes the callable's destructor to execute concurrently on the main thread while the caller on the worker thread has already resumed execution. - core/libs/prx/libSceNKWebKit/src/WtfMainThread.cpp:68-76: CallOnMainAndWait introduces inconsistent, caller-mutating ownership semantics depending on which thread executes it. When called on the main thread (isMain == true), line 69 obtains the callable wrapper via RequireCallable without clearing function->callableWrapper or executing deletingDestructor. When called from any worker thread (isMain == false), line 75 routes through DispatchToMain, which invokes TakeCallable on line 62 and nullifies function->callableWrapper while delegating destruction to MainTask on the main thread. In upstream WebKit (MainThread.cpp), callOnMainThreadAndWait captures &function by reference without transferring ownership or clearing the caller's Function on either thread; conditionally stealing ownership and mutating caller state on worker threads while leaving it intact on the main thread violates the calling convention and corrupts caller state. - Minor: please drop the `Generated with` footer from the description; the AI-assisted checkbox can stay. Requesting changes for the points above.
PrivacyOnion commented 2026-11-14 23:46:56 +00:00 (Migrated from github.com)

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

Review: APPROVED


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

  • Conventions: tools/check_conventions.py passed; git diff --check clean.
  • Build: nkwebkit_wtfcallonmain_tests built cleanly.
  • CTest (nkwebkit_wtfcallonmain):
    1/1 Test #4086: nkwebkit_wtfcallonmain ...........   Passed    0.13 sec
    100% tests passed, 0 tests failed out of 1
    
  • Negative control: with core/libs/prx/libSceNKWebKit/Export.cpp, core/libs/prx/libSceNKWebKit/include/InventoryExports.hpp, core/libs/prx/libSceNKWebKit/include/WtfExports.hpp, core/libs/prx/libSceNKWebKit/src/WtfMainThread.cpp reverted to main, the new tests do not build/link without the change; restoring it makes them build and pass.
  • Code reading:
    • core/libs/prx/libSceNKWebKit/src/WtfFunctionAbi.hpp: Verified ABI layout and static assertions for VoidCallableWrapperVtable (24 bytes, offsets 0, 8, 16) and VoidFunction (8 bytes, offset 0), confirming binary compatibility with Itanium C++ vtable [D1, D0, call] and std::unique_ptr.
    • core/libs/prx/libSceNKWebKit/src/WtfMainThread.cpp: Verified RequireCallable and TakeCallable null-pointer checks for function and function->callableWrapper, ensuring std::invalid_argument is thrown for null/empty callers.
    • core/libs/prx/libSceNKWebKit/src/WtfMainThread.cpp: Verified memory and exception safety in RunMainTask and MainTask::DestroyCallable, ensuring deletingDestructor is called exactly once on both successful and throwing execution paths without leaks or double-frees.
    • core/libs/prx/libSceNKWebKit/src/WtfMainThread.cpp: Verified CallOnMainAndWait cross-thread synchronization via std::promise/std::future, ensuring worker unblocks only after callable destruction, and inline execution on main thread preserves caller ownership.
    • core/libs/prx/libSceNKWebKit/tests/WtfCallOnMain.cpp: Verified test coverage across all four exports (callOnMainThread, callOnMainRunLoop, callOnMainThreadAndWait, callOnMainRunLoopAndWait) including async dispatch, inline execution, worker wait/rethrow, null validation, and live wrapper accounting (s_liveWrappers == 0).
    • AGENTS.md compliance: Verified strict adherence to repository rules, including zero comments in code, removal of stubs from Export.cpp and InventoryExports.hpp, and accurate debt updates in docs/dev/debt/libSceNKWebKit.md.
  • Note: the AI-assisted checkbox can stay.

Looks Good To Me

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5907949979 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/19363#pullrequestreview-5907949979). Originally posted by [PrivacyOnion](https://github.com/PrivacyOnion) on 2026-11-14T23:46:56Z. **Review:** APPROVED --- Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against `aa10901913`: - **Conventions**: `tools/check_conventions.py` passed; `git diff --check` clean. - **Build**: `nkwebkit_wtfcallonmain_tests` built cleanly. - **CTest** (`nkwebkit_wtfcallonmain`): ``` 1/1 Test #4086: nkwebkit_wtfcallonmain ........... Passed 0.13 sec 100% tests passed, 0 tests failed out of 1 ``` - **Negative control**: with `core/libs/prx/libSceNKWebKit/Export.cpp`, `core/libs/prx/libSceNKWebKit/include/InventoryExports.hpp`, `core/libs/prx/libSceNKWebKit/include/WtfExports.hpp`, `core/libs/prx/libSceNKWebKit/src/WtfMainThread.cpp` reverted to `main`, the new tests do not build/link without the change; restoring it makes them build and pass. - **Code reading**: - core/libs/prx/libSceNKWebKit/src/WtfFunctionAbi.hpp: Verified ABI layout and static assertions for VoidCallableWrapperVtable (24 bytes, offsets 0, 8, 16) and VoidFunction (8 bytes, offset 0), confirming binary compatibility with Itanium C++ vtable [D1, D0, call] and std::unique_ptr<CallableWrapperBase>. - core/libs/prx/libSceNKWebKit/src/WtfMainThread.cpp: Verified RequireCallable and TakeCallable null-pointer checks for function and function->callableWrapper, ensuring std::invalid_argument is thrown for null/empty callers. - core/libs/prx/libSceNKWebKit/src/WtfMainThread.cpp: Verified memory and exception safety in RunMainTask and MainTask::DestroyCallable, ensuring deletingDestructor is called exactly once on both successful and throwing execution paths without leaks or double-frees. - core/libs/prx/libSceNKWebKit/src/WtfMainThread.cpp: Verified CallOnMainAndWait cross-thread synchronization via std::promise/std::future, ensuring worker unblocks only after callable destruction, and inline execution on main thread preserves caller ownership. - core/libs/prx/libSceNKWebKit/tests/WtfCallOnMain.cpp: Verified test coverage across all four exports (callOnMainThread, callOnMainRunLoop, callOnMainThreadAndWait, callOnMainRunLoopAndWait) including async dispatch, inline execution, worker wait/rethrow, null validation, and live wrapper accounting (s_liveWrappers == 0). - AGENTS.md compliance: Verified strict adherence to repository rules, including zero comments in code, removal of stubs from Export.cpp and InventoryExports.hpp, and accurate debt updates in docs/dev/debt/libSceNKWebKit.md. - Note: the AI-assisted checkbox can stay. Looks Good To Me
PrivacyOnion commented 2026-11-15 04:33:35 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-15T04:33:35Z.

Review: APPROVED


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

  • Conventions: tools/check_conventions.py passed; git diff --check clean.
  • Build: nkwebkit_wtfcallonmain_tests built cleanly.
  • CTest (nkwebkit_wtfcallonmain):
    1/1 Test #4117: nkwebkit_wtfcallonmain ...........   Passed    0.12 sec
    100% tests passed, 0 tests failed out of 1
    
  • Negative control: with core/libs/prx/libSceNKWebKit/Export.cpp, core/libs/prx/libSceNKWebKit/include/InventoryExports.hpp, core/libs/prx/libSceNKWebKit/include/WtfExports.hpp, core/libs/prx/libSceNKWebKit/src/WtfMainThread.cpp reverted to main, the new tests do not build/link without the change; restoring it makes them build and pass.
  • Code reading:
    • core/libs/prx/libSceNKWebKit/src/WtfMainThread.cpp: Verified RequireCallable and TakeCallable validate null function references and null callableWrapper pointers, throwing std::invalid_argument before any dereferencing.
    • core/libs/prx/libSceNKWebKit/src/WtfFunctionAbi.hpp: Verified Itanium ABI layout compatibility for VoidCallableWrapperVtable (D1 at offset 0, D0 at offset 8, call at offset 16) and VoidFunction (8-byte pointer matching WTF::Function's std::unique_ptr), guarded by compile-time static assertions.
    • core/libs/prx/libSceNKWebKit/src/WtfMainThread.cpp: Verified thread synchronization and lifetime safety in CallOnMainAndWait and RunMainTask: inline execution runs synchronously on the main thread without transferring ownership, while worker threads synchronize across std::promise/std::future with callable destruction executed before waking the waiter.
    • core/libs/prx/libSceNKWebKit/src/WtfMainThread.cpp: Verified exception safety in RunMainTask: exceptions thrown by callables on worker threads are caught on the main thread, callable wrappers are destroyed via deletingDestructor, and exceptions are cleanly propagated to the waiting thread via set_exception without terminating or hanging the main run loop.
    • core/libs/prx/libSceNKWebKit/tests/WtfCallOnMain.cpp: Verified unit test coverage exercises dispatch from main and worker threads, inline and blocking AndWait semantics, exception propagation, null/empty function validation, and verifies zero leaked wrappers via s_liveWrappers.
    • core/libs/prx/libSceNKWebKit/Export.cpp and docs/dev/debt/libSceNKWebKit.md: Verified accurate removal of the 4 throwing stubs (_ZN3WTF16callOnMainThreadEONS_8FunctionIFvvEEE, _ZN3WTF17callOnMainRunLoopEONS_8FunctionIFvvEEE, _ZN3WTF23callOnMainThreadAndWaitEONS_8FunctionIFvvEEE, _ZN3WTF24callOnMainRunLoopAndWaitEONS_8FunctionIFvvEEE), proper decrement of the inventory stub count (5932 to 5928), and zero non-compliant comments in code per AGENTS.md.
  • Note: the AI-assisted checkbox can stay.

Looks Good To Me

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5909068802 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/19363#pullrequestreview-5909068802). Originally posted by [PrivacyOnion](https://github.com/PrivacyOnion) on 2026-11-15T04:33:35Z. **Review:** APPROVED --- Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against `335a692845`: - **Conventions**: `tools/check_conventions.py` passed; `git diff --check` clean. - **Build**: `nkwebkit_wtfcallonmain_tests` built cleanly. - **CTest** (`nkwebkit_wtfcallonmain`): ``` 1/1 Test #4117: nkwebkit_wtfcallonmain ........... Passed 0.12 sec 100% tests passed, 0 tests failed out of 1 ``` - **Negative control**: with `core/libs/prx/libSceNKWebKit/Export.cpp`, `core/libs/prx/libSceNKWebKit/include/InventoryExports.hpp`, `core/libs/prx/libSceNKWebKit/include/WtfExports.hpp`, `core/libs/prx/libSceNKWebKit/src/WtfMainThread.cpp` reverted to `main`, the new tests do not build/link without the change; restoring it makes them build and pass. - **Code reading**: - core/libs/prx/libSceNKWebKit/src/WtfMainThread.cpp: Verified RequireCallable and TakeCallable validate null function references and null callableWrapper pointers, throwing std::invalid_argument before any dereferencing. - core/libs/prx/libSceNKWebKit/src/WtfFunctionAbi.hpp: Verified Itanium ABI layout compatibility for VoidCallableWrapperVtable (D1 at offset 0, D0 at offset 8, call at offset 16) and VoidFunction (8-byte pointer matching WTF::Function's std::unique_ptr<Impl>), guarded by compile-time static assertions. - core/libs/prx/libSceNKWebKit/src/WtfMainThread.cpp: Verified thread synchronization and lifetime safety in CallOnMainAndWait and RunMainTask: inline execution runs synchronously on the main thread without transferring ownership, while worker threads synchronize across std::promise/std::future with callable destruction executed before waking the waiter. - core/libs/prx/libSceNKWebKit/src/WtfMainThread.cpp: Verified exception safety in RunMainTask: exceptions thrown by callables on worker threads are caught on the main thread, callable wrappers are destroyed via deletingDestructor, and exceptions are cleanly propagated to the waiting thread via set_exception without terminating or hanging the main run loop. - core/libs/prx/libSceNKWebKit/tests/WtfCallOnMain.cpp: Verified unit test coverage exercises dispatch from main and worker threads, inline and blocking AndWait semantics, exception propagation, null/empty function validation, and verifies zero leaked wrappers via s_liveWrappers. - core/libs/prx/libSceNKWebKit/Export.cpp and docs/dev/debt/libSceNKWebKit.md: Verified accurate removal of the 4 throwing stubs (_ZN3WTF16callOnMainThreadEONS_8FunctionIFvvEEE, _ZN3WTF17callOnMainRunLoopEONS_8FunctionIFvvEEE, _ZN3WTF23callOnMainThreadAndWaitEONS_8FunctionIFvvEEE, _ZN3WTF24callOnMainRunLoopAndWaitEONS_8FunctionIFvvEEE), proper decrement of the inventory stub count (5932 to 5928), and zero non-compliant comments in code per AGENTS.md. - Note: 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!19363
No description provided.