fix(libSceNKWebKit): read the local time zone offset from the guest #20152
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/20152"
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-14T18:22:39Z.
What
In libSceNKWebKit,
WTF::calculateLocalTimeOffset(double, TimeType)(_ZN3WTF24calculateLocalTimeOffsetEdNS_8TimeTypeE) andWTF::GregorianDateTime::setToCurrentLocalTime()(_ZN3WTF17GregorianDateTime21setToCurrentLocalTimeEv) call hostlocaltime_randmktime, and on Windows the host time zone API. So they read the host process's zone, not theTZthe guest set in its environment.The PS5 11.x tree calls libc for both:
calculateLocalTimeOffsettakes itsHAVE(TM_GMTOFF)path:localtime_randtm_gmtoff.equivalentYearForDSTreturns the year unchanged underPLATFORM(PLAYSTATION)(L178-L190), so there is no year shift.calculateUTCOffsetcallsmktime.setToCurrentLocalTimecallstimeandlocaltime_r.Changes:
WtfTime.cppnow call guest libctime_nid_postfix,localtime_r_nid_postfixandmktime_nid_postfixwith aGuestTm. Guest libc applies the guestTZunder its zone lock before it converts (Time.cpp). Hostlocaltime_rreads whatever zone guest libc last applied.invalid_argument, and a failed conversion still throwsoverflow_error.setToCurrentLocalTimenow also throws whenlocaltime_rfails, where WebKit reads an unsettm._WIN32branches go, along with the!HAVE(TM_GMTOFF)fallback (calculateDSTOffset,msToHours,msToMinutes).GuestTmalways hastm_gmtoff, and guest libc fills it on every host.dayInYearstays because #14478 uses it.mktimebranch. It does not take the tree'sHAVE(TIMEGM)branch, so that choice is unchanged by this PR.TZ, guest libc reads the host zone, not the console's time zone setting;Reachability:
Datelocal-time operation reachescalculateLocalTimeOffset. OnPLATFORM(PLAYSTATION),DateCache::calculateLocalTimeOffsetreturnsWTF::calculateLocalTimeOffsetinstead of using ICU.DSTCache::localTimeOffset(L266-L372) calls it. Its callers include:msToGregorianDateTime(L412-L420), used bygetHours,toStringand the other local getters;gregorianDateTimeToMS(L374-L390), used bynew Date(y, m, d)and the local setters;Date.parseof a local date (L455-L466).parseDateFromNullTerminatedCharacters(const char*)calls it for local dates (DateParsing.cpp).setToCurrentLocalTimein the pinned files I read. It changes here because it reads the same zone.Tested
Linux (Ubuntu 24.04 container
anyps5-dev:24.04, GCC 13.3), Release,-DBUILD_TESTING=ON, headac406bbf5b04e5faa3e3dff3e6369e0c4461b443onmain80b0bdf26456ffe10b48529c9e4420ec3814684f.libSceNKWebKit,core/libs/libs/libSceNKWebKit.prxand every libSceNKWebKit test target.ctest -R 'nkwebkit|^public_headers$': 83 of 83 pass.guest_nkwebkit_dates:ScopedTimeZoneset the hostTZ. It is replaced byScopedGuestTimeZone(applied, pending). That helper sets guestTZtoJST-9, applies it with guesttzset, then sets guestTZtoEST5EDT,M3.2.0/2,M11.1.0/2withouttzset. Afterwards it restores the guestTZ.LocalTimeOffsetFollowsGuestZone, each case the first call in a fresh scope:CurrentLocalTime: callssetToCurrentLocalTimebetween two guesttimereads. When both reads agree, it checks that every field equals guestlocaltime_rof that second and that the offset is -300 or -240 minutes. It retries otherwise, at most 100 times. No check depends on how long anything takes.Negative controls on
ac406bbf5b04e5faa3e3dff3e6369e0c4461b443, one at a time, in the Docker build. Each makesguest_nkwebkit_datesfail (no build failures), and the restored tree passes:WtfTime.cpp;localtime_rincalculateLocalTimeOffsetonly;localtime_rinsetToCurrentLocalTimeonly;mktimein the UTC offset;tm_gmtoff / 61form_utcOffsetInMinute;tm_isdst >= 0forisDST.Checks:
tools/check_conventions.py --base origin/main --head HEADpasses.git diff --check origin/mainis clean.Overlap:
GregorianDateTimeconstructors next tosetToCurrentLocalTime. #19380 and #20139 edit other parts ofWtfTime.cpp.git merge-treeof this branch with each of the three gives no conflict.tools/pr_overlap.py --branchreports no line overlap. It could not compare 23 PRs on the debt file. None of them edits the "WTF host services" or "WTF clocks" entries, andgit merge-treewith each shows only the conflicts it already has withmain.CPUTime::forCurrentThreadfrom the same "WTF host services" sentence. Debt files merge withmerge=union, so merging both would keep two versions of that line. Whichever lands second will be rebased to: "... and random values come from the host".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 MarcZX10 on 2026-11-14T18:31:47Z.
Review: APPROVED
Reviewed — looks good
Nothing blocks this; the points below are optional.
What I ran
Reviewed head
ac406bbf5b04e5faa3e3dff3e6369e0c4461b443usingrepo_read.pyto inspect the prepared diff and targeted source ranges. No commands or tests were run. The description reports Linux build and test results; these were not independently verified.Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
The full text of
docs/dev/debt/libSceNKWebKit.mdwas excluded from the prepared folder; I read only its changed lines through the pinned reader. I read every changed line inWtfTime.cpp,GuestNKWebKitDates.cpp, and the debt file. I did not run the reported build, tests, negative controls, convention check, or diff check, and did not verify console behavior or the PR’s merge-base state.To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by PrivacyOnion on 2026-11-14T18:36:49Z.
Review: APPROVED
Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against
ac406bbf5b:tools/check_conventions.pypassed;git diff --checkclean.guest_nkwebkit_dates_testsbuilt cleanly.guest_nkwebkit_dates):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