feat(libSceNKWebKit): implement WTF::RunLoop and RunLoop::TimerBase on the generic event loop #23847
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/23847"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by opxdelwin on 2026-11-19T19:16:18Z.
What
Implements 16
WTF::RunLoopexports from the 11.x inventory:main,current,dispatch,dispatchAfter,run,stop,cycle,setWakeUpCallback,suspendFunctionDispatchForCurrentCycle, plusRunLoop::TimerBase(C2 constructor, D1/D2 destructors,start,stop,isActive,secondsUntilFire). They are ported from the generic event loop the PlayStation port builds (RunLoop.cpp,generic/RunLoopGeneric.cpp,MainThread.cpp,playstation/WKRunLoop.cppatneonmodder123/PS5-WebKit-11.x@80f77e94c63ee7202eec3d4b5b1a021dd89011ba). Each derived file carries its upstream licence notice and aDerived fromline.The
WKRunLoop*C API (src/RunLoop.cpp) andcallOnMainThread/callOnMainRunLoopwith theirAndWaitforms (src/WtfMainThread.cpp) now run onRunLoop::main(), the same way they do upstream. Guest code that usesRunLoop, timers orcallOnMainThreadnow shares one ordered main queue.The guest-visible layout is pinned with
static_asserts:TimerBaseis 24 bytes,DispatchTimeris 40 (refcount at 24, function at 32) and theRunLooprefcount is at 8. I checked these with a probe built under g++ and clang++.Behaviour change:
WKRunLoopStopMain()with no loop running is now a no-op, because upstream'sstop()returns when no loop is running. So theStopMain(); RunMain();sequence intests/Base.cppwould block, and I removed thatWKRunLoopRunMain()line.TestStopWithoutRunningLoopcovers the new behaviour, and the debt entry records it.These stay throwing: the libSceJsc copies of
WTF::RunLoopandTimerBase(a separate module with its own WTF). The debt fragmentdocs/dev/debt/changes/feat-libscenkwebkit-wtf-run-loop.mdrecords them, together with the unverified console layout of private members,AndWaitblocking when no loop runs, and the leak of a stoppeddispatchAftertimer.Tested
Homebrew/unit tests only, no title. Linux (Docker, Ubuntu image), targets
libSceNKWebKit nkwebkit_wtfrunloop_tests nkwebkit_wtfcallonmain_tests nkwebkit_base_tests nkwebkit_mainthread_tests nkwebkit_forwarding_tests nkwebkit_symbolset_tests,ctest -R '^(nkwebkit_wtfrunloop|nkwebkit_wtfcallonmain|nkwebkit_base|nkwebkit_mainthread|nkwebkit_forwarding|nkwebkit_symbolset|public_headers.*)$':4a22d71, after rebasing onto main23786c4e4f.735a3163fd. Every nkwebkit test passed. The 5 failures arepublic_headers_compile_*batches failing on-Winvalid-offsetofforRegioninRegionExports.hpp. Main fails the same 5 batches with the same errors in the same container, so they are pre-existing.tools/check_conventions.pyandtools/debt_fold.py --checkpass.On
fada67ccbb(exceptions thrown from run loop callbacks, plus new tests), Windows 11, MSYS2 UCRT64, GCC, Release,-DBUILD_TESTING=ON:nkwebkit_wtfrunloopandnkwebkit_basepassed;nkwebkit_wtfrunlooppassed 100/100 repeated runs.RunImplchange,TestThrowingFunctionLeavesRunhangs in the secondrun().tools/check_conventions.pypasses.fada67ccbb.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-19T19:43:54Z.
Review: APPROVED
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against
eb4667a936:tools/check_conventions.pypassed.nkwebkit_base_tests,nkwebkit_wtfrunloop_testsbuilt cleanly.nkwebkit_base,nkwebkit_wtfrunloop):core/libs/prx/libSceNKWebKit/Export.cpp,core/libs/prx/libSceNKWebKit/include/InventoryExports.hpp,core/libs/prx/libSceNKWebKit/libSceNKWebKit.hpp,core/libs/prx/libSceNKWebKit/src/RunLoop.cpp,core/libs/prx/libSceNKWebKit/src/WtfFunctionAbi.hpp,core/libs/prx/libSceNKWebKit/src/WtfMainThread.cpp,core/libs/prx/libSceNKWebKit/src/WtfRunLoop.cppreverted tomain, the new tests do not build/link without the change; restoring it makes them build and pass.Looks Good To Me
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-21T07:34:28Z.
Review: DISMISSED
Reviewed — changes requested
Changes are required before merge: remove the loop’s stack-local status from
mainLoopson every exit, including normal returns and callback exceptions.What I ran
Reviewed head
eb4667a93619ebc4d386acedd8c82f1318384074. This was a source review only; no test commands were run. The author reports GCC tests passed after rebasing and Clang tests ran before the rebase.Results
Findings
Blocking
core/libs/prx/libSceNKWebKit/src/WtfRunLoop.cpp:414:RunImplstores the address of stack-localstatusOfThisLoopinmainLoops, but only removes it whenPopulateTasksreturns false or in the catch handler. If a dispatched function or timer callback throws, a laterstop()can dereference the stale pointer atWtfRunLoop.cpp:600, causing undefined behavior. Ensure the status is removed on every exit, for example with scope-based cleanup, and add a regression test that throws from a callback and then exercises the loop again.Non-blocking
core/libs/prx/libSceNKWebKit/src/WtfRunLoop.cpp:580: the internaldispatchAftercallback holds a timer reference until it runs. Stopping the timer before it fires prevents that callback from running and leaves the captured reference alive. The debt entry explicitly documents this limitation.Not verified
Export.cppandinclude/InventoryExports.hppwere excluded from the bundle and read only around the affected export entries through the pinned reader. No other changed files were excluded.To get this to a good state
RunImplremove its status frommainLoopson every exit and add a regression test for a throwing callback. Rerun the reported GCC and Clang test selections on the resulting head.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-22T06:28:21Z.
Review: COMMENTED
Reviewed — comments
Nothing is required; the points below are optional.
What I ran
Reviewed head
4a22d71db8376c82ffa2337b696b2bd31c2dbc45using the prepared diff andrepo_read.pyfor targeted source context. No commands or tests were run by me.Results
Findings
Blocking
None.
Non-blocking
InitializeMainRunLoop()usescompare_exchange_strongand throws if initialization has already occurred, but it is called insidestd::call_oncein_ZN3WTF20initializeMainThreadEv. A repeated call to the public initialization entry point therefore throws even though the previous implementation andstd::call_onceindicate initialization should be idempotent. Consider making the run loop initialization idempotent as well. Evidence:core/libs/prx/libSceNKWebKit/src/WtfRunLoop.cpp:538andcore/libs/prx/libSceNKWebKit/src/WtfMainThread.cpp:97.Not verified
WtfRunLoop.cpp, its ABI and ownership helpers, and the test source.Export.cppandInventoryExports.hppare listed as excluded because they are too large; their deletions are visible in the prepared diff, but their complete contents were not read.To get this to a good state
Nothing is required. Optionally, make repeated main-thread initialization idempotent and add coverage for calling it more than once.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-24T22:56:12Z.
Review: COMMENTED
Reviewed — comments
The run loop implementation and its tests were reviewed at head
fada67ccbb17c795ebbccfc8679b6d0b0baea1b6; a verified timer lifetime defect remains, while the declared test runs were author-reported and not rerun here.What I ran
No commands or tests were run. I inspected the prepared diff and selected changed files through the pinned repository reader.
Results
Findings
Blocking
None.
Non-blocking
core/libs/prx/libSceNKWebKit/src/WtfRunLoop.cpp:410: A repeating timer’s callback can destroy its ownTimerBase.RunLoopScheduledTaskremains alive throughScheduledTaskRef, but itstimerpointer then refers to the destroyed object. After the callback returns, the loop can reinsert that task, and the next firing dereferences the dangling pointer at line 92. Ensure the scheduled task is deactivated when its owner is destroyed, and prevent reinsertion after destruction; add a regression test where a repeating timer destroys itself fromfired.Not verified
The full text and changed lines of
Export.cppandinclude/InventoryExports.hppwere excluded from the review folder and not read through the reader. I did not inspect every changed line in the included files, the build configuration/callers, or run any checks. The author reports GCC tests and Windows tests, but those results were not independently verified.To get this to a good state
Nothing is required for this comment-only verdict. The timer lifetime issue is an optional point for the author to address before relying on self-destroying repeating timers.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-25T03:59:37Z.
Review: COMMENTED
Reviewed — no blocking findings
Nothing blocks this change; the points below are optional.
What I ran
Reviewed head
c59713f9136a8e36e67ad21c67d4afd5b63ac3dd. No commands or tests were run in this review session. I read the prepared description, commits, diff, manifest, and the complete head text of all changed files exceptExport.cppandinclude/InventoryExports.hpp, whose full text was excluded as too large. I read targeted ranges ofWtfRunLoop.cpp,WtfMainThread.cpp,RunLoop.cpp, andWtfFunctionAbi.hppthroughrepo_read.py.Results
Findings
Blocking
None identified in the code read.
Non-blocking
WKRunLoopCallOnMainThreadpackages its callback inOwnedFunctionand passes it intocallOnMainThread(core/libs/prx/libSceNKWebKit/src/RunLoop.cpp:50). If theRunLoop::main()lookup or dispatch throws before taking ownership, the local owner releases the wrapper while the captured raw pointer remains incallback; this path is worth covering or making ownership transfer exception safe.Not verified
core/libs/prx/libSceNKWebKit/Export.cppandcore/libs/prx/libSceNKWebKit/include/InventoryExports.hppwere excluded by the prepared review folder; only their diff hunks were read.To get this to a good state
Nothing is required. Optional: add coverage for callback ownership when main-loop lookup or dispatch fails before consuming the function.
Imported from boykopovar/AnyPS5. Originally posted by ligmaSec on 2026-12-03T12:52:06Z.
Review: COMMENTED
Built the branch’s RunLoop changes and ran the focused WtfRunLoop fixture on Linux against the existing runtime libraries. It passed. The broader Base fixture also built but aborted in this standalone setup, so its coverage remains unresolved.
AI-assisted: yes.
Pull request closed