fix(libSceNKWebKit): read WTF::WallTime and MonotonicTime from the guest clocks #20125
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/20125"
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 MatteoSid on 2026-11-14T17:05:07Z.
What
In libSceNKWebKit,
WTF::WallTime::now()(_ZN3WTF8WallTime3nowEv, NID2lgqM74hGv4) andWTF::MonotonicTime::now()(_ZN3WTF13MonotonicTime3nowEv, NIDgWLXqFf+5uI) read the host'sstd::chrono::system_clockandstd::chrono::steady_clock. The PS5 11.x tree reads the platformclock_gettimeinstead, in CurrentTime.cpp:WallTime::nowreadsCLOCK_REALTIMEand returnstv_sec + tv_nsec / 1e9.MonotonicTime::nowreadsCLOCK_MONOTONICthrough theOS(FREEBSD)branch, which__FreeBSD__selects (PlatformOS.h).PLATFORM(PLAYSTATION) && HAVE_CLOCK_GETTIME_NPbranch above it is never taken: the tree definesHAVE_CLOCK_GETTIME_NPnowhere, and that file and libpas only test it.CLOCK_MONOTONIC. Here libScePosixForWebKit'sclock_gettime_npforwards toclock_gettime.timespecand ignore the return value, so a failed read gives 0.WebKit c55364d53f97 has the same
OS(FREEBSD)CLOCK_MONOTONICpath, but reads the wall clock withgettimeofday. This PR follows the pinned PS5 tree'sCLOCK_REALTIME.Changes:
WtfTime.cppnow forward to the newsrc/WtfCurrentTime.cpp. It asks guest libkernelclock_gettimefor clock 0 (CLOCK_REALTIME) and clock 4 (CLOCK_MONOTONIC), with a zeroedKernelTimespecand WebKit's conversion. The file starts with aDerived fromline and the CurrentTime.cpp notice copied verbatim, likeWtfNumberOfCores.cppandWtfRamSize.cpp.WallTime::nowandMonotonicTime::now;TimeWithDynamicClockType::nowandnowWithSameClock;hasElapsedandsleep;MonotonicTime::approximateWallTimeandWallTime::approximateMonotonicTime.WtfTime.cpponly loses thestd::chronoreads and gains two declarations, below the includes that #19380 and #14478 edit.CurrentTimeClockForTest_nid_no_patch, followsNumberOfProcessorCoresSysconfForTest_nid_no_patchfrom #20053 andRamSizeSysconfForTest_nid_no_patchfrom #20100.CPUTime::forCurrentThread, the local time zone and random values. A new "WTF clocks" entry lists what remains:TimeWithDynamicClockType::now(ClockType::Approximate)still reads clock 4. The tree'sApproximateTime::nowreadsCLOCK_MONOTONIC_FAST(12), which the guest maps to the same host clock. Following it would also change theApproximateconversions, so that is left for a separate change.Reachability: neither export takes an argument or needs an object, so any module that imports them from libSceNKWebKit reaches them directly. In the pinned PS5 tree, a web view calls them on these paths:
Date.now()andnew Date()go throughjsCurrentTimetoWallTime::now(DateConstructor.cpp).performance.now()isPerformance::nowInReducedResolutionSeconds, which subtracts the time origin fromMonotonicTime::now.MonotonicTime::nowon every iteration (RunLoopGeneric.cpp), and schedules them from it at L72-L80. DOM timers and the web process's main loop run on it.Which console modules import these NIDs has not been checked against a dump.
Tested
Linux (Ubuntu 24.04 container, GCC 13.3), Release,
-DBUILD_TESTING=ON, on headfded49eac9based onmain98fbd092b6. BuiltlibSceNKWebKit, the patchedcore/libs/libs/libSceNKWebKit.prxand every libSceNKWebKit test target.ctest -R 'nkwebkit|^public_headers$'passes 82 of 82.nkwebkit_wtfdrives the clocks throughCurrentTimeClockForTest_nid_no_patch. The hook replaces theclock_gettimequery, andnullptrrestores guestclock_gettime_nid_postfix. The test checks:WallTime::nowandMonotonicTime::nowreturn those values, after one query each of clocks 0 and 4;TimeWithDynamicClockType::nowforWallandMonotonicreturns the same values;approximateWallTimeandapproximateMonotonicTimeconvert exactly between the two.clock_gettimereads of the same clock.No check depends on how long anything takes.
Negative controls on
fded49eac9, one at a time, in the Docker build. Each makesnkwebkit_wtffail (no build failures), and the restored tree passes:WtfTime.cpp(hoststd::chronoclocks);nm -Don the patchedlibSceNKWebKit.prxlists the hook under its_nid_no_patchname.tools/check_conventions.py --base origin/main --head HEADpasses, andgit diff --check origin/mainis clean.Overlap:
WallTime::now,MonotonicTime::nowor the two helpers. #19103 and #19719 only call them, in their tests.tools/pr_overlap.py --branchrun reported #14478 and #17272 ontests/Wtf.cppL204-205. The second commit moves the checks belowTestTime, and the rerun reports no overlap.tests/Wtf.cppfor #19103 and #19106), which I checked by hand:WTF::ramSizeor clock entries;git merge-treeof this branch with #19103, #19106, #14478, #17272 and #19380 gives no conflict inWtfTime.cpp,tests/Wtf.cppor the debt file. The conflicts #19103 and #19106 have withmainare in other files.No title tested.
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-14T17:14:41Z.
Review: APPROVED
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against
fded49eac9:tools/check_conventions.pypassed;git diff --checkclean.nkwebkit_wtf_testsbuilt cleanly.nkwebkit_wtf):core/libs/prx/libSceNKWebKit/src/WtfTime.cppreverted tomainand the new tests kept, the suite fails: Restoring the change makes it pass again.Looks Good To Me
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-14T17:42:53Z.
Review: COMMENTED
Reviewed — no blocking findings
Nothing blocks this change; one changed file was excluded from the review folder, so approval is not justified.
What I ran
Reviewed head
f6074111d849327a5e1fb1c956a894bdba77c152. No commands or tests were run.Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
The full text of
docs/dev/debt/libSceNKWebKit.mdwas excluded because it was too large for the review folder; its changed lines were visible in the diff. No build, tests, console behavior, or author-reported test results were independently verified.To get this to a good state
Nothing is required.
Continued review (pass 2)
The two previously unread additions have been checked in context and introduce no defect requiring a change.
What I ran
Read the specified additions at head
f6074111d849327a5e1fb1c956a894bdba77c152and their local context usingrepo_read.py; no tests or commands were run.Results
TestSystemFindings
Blocking
None.
Non-blocking
None.
Not verified
No runtime or console behavior was verified. Only the requested additions and their immediate context were reviewed; no other changed lines were assessed in this continuation.
To get this to a good state
Nothing is required.