fix(libkernel): report the host zone's standard offset and daylight saving amount from sceKernelGettimezone #10499

Merged
frankea merged 3 commits from upstream-pr/10499 into main 2026-10-26 18:51:45 +00:00
frankea commented 2026-10-24 04:32:03 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by frankea on 2026-10-24T04:32:03Z.


What

sceKernelGettimezone wrote {0, 0} for every zone, a silent stub that the debt entry for the calendar conversions mentions ("sceKernelGettimezone and the gettimeofday time zone still report no offset and no daylight saving"). It now fills both fields from the host zone, with the HostZoneAt and HostDaylightAmount helpers the calendar conversions in the same file already use:

  • tz_minuteswest: the standard offset in minutes east of UTC, despite its name, without the daylight saving in effect.
  • tz_dsttime: the zone's daylight saving amount in minutes, 0 for a zone without daylight saving.
  • A null pointer still returns 0x8002000E.

Measurement: PS5 on firmware 13.40 set to US Eastern, 2026-10-19, from an elfldr payload process: sceKernelGettimezone returned 0 with tz_minuteswest -300 and tz_dsttime 60. Summer time was in effect on the run date, so -300 is the standard offset, not the current one, and 60 is the daylight saving amount, not a flag. What the console returns outside summer time, or for a zone without daylight saving, was not measured; this console is the only sample.

The probe resolves sceKernelGettimezone from libkernel in the payload process and calls it on a buffer filled with 0x55, the equivalent of:

int32_t tz[2] = {0x55555555, 0x55555555};
int r = sceKernelGettimezone(tz);
printf("0x%08x minuteswest=%d dsttime=%d\n", (unsigned)r, tz[0], tz[1]);

Its output: sceKernelGettimezone(&tz) -> 0x00000000 minuteswest=-300 dsttime=60. In the same run sceKernelConvertUtcToLocaltime gave local minus UTC of -14400 for 2024-07-01 12:00Z and -18000 for 2024-01-15 12:00Z, with the daylight amount 3600, so the console was on US Eastern. Anyone with a payload loader can repeat it in a zone without daylight saving or in winter.

The debt entry moves out of the long calendar conversion entry into one of its own, which says the values follow the host zone rather than the console's time zone setting and what was not measured. The gettimeofday time zone is unchanged; #9682 touches that one.

Tested

Windows 11 (build 26200), MinGW GCC (WinLibs 15.2) Release build with BUILD_TESTING=ON, each run three times (ctest --repeat until-fail:3).

  • Refreshed onto main ca6e29e83 after #10198 merged (head 02eb8256d; the libkernel debt conflict resolved by keeping both PRs' entries): guest_freebsd_clocks passes, and so does main ca6e29e83.
  • guest_freebsd_clocks gets a case that sets TZ and reads sceKernelGettimezone: UTC0 gives 0 and 0, IST-5:30 330 and 0, BRT+3 -180 and 0, EST5EDT -300 and 60, CET-1CEST 60 and 60; and a null pointer returns 0x8002000E. On Windows the expected daylight amount comes from the C runtime's _get_dstbias, as the test's existing zone cases already do, since a TZ variable does not set it.
  • This PR (4db6ed763, fabe44851 with main 97d33464c merged in): guest_freebsd_clocks passes.
  • Control: main 97d33464c with only this PR's GuestFreebsdClocks.cpp: guest_freebsd_clocks aborts on the new case.
  • main 97d33464c with its own test: passes.
  • Linux: @Dom3005's run in the comments (Ubuntu 26.04, GCC 15, glibc 2.43): this PR merged onto main 39a36bbec passes 3 of 3, including the TZ cases, where the daylight amount comes from glibc's zone data; the control aborts as on Windows. @TechLevelZero's fleet run (Linux, validation layer on) of 4db6ed763 merged onto main 5b85225ef: no PR-only failures in the 1941 tests tools/select_tests.py selects, on a Ryzen 7 9700X iGPU (RDNA2), an RX 9070 XT (RDNA4), Iris Xe, lavapipe on two CPUs and an NVIDIA A800.
  • tools/check_conventions.py --base origin/main reports no errors; its one warning is the length of the calendar conversion debt entry, which was already over the limit before this PR shortened it.

Overlap

#10198 (orezraey), which added a measured calendar conversion entry right after the debt entry this PR edits, merged first; this branch merges main after it and keeps both entries. #10975 (xXPBSXx) changes the same sceKernelGettimezone body to write {0, 0} through GuestCopyOut_nid_no_patch, so an unusable pointer returns EFAULT; whichever of the two lands second writes this PR's values through that copy.

Checklist

  • Based on current main; no other open PR implements the same functions. #10975 changes how sceKernelGettimezone writes its result, not what it writes (see Overlap); #9682 changes gettimeofday's time zone output in the same file.
  • 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 (#10198 has merged; see Overlap)
  • Fixes: none
  • Unblocks: none known; no title on this machine stops on it
  • GPUs tested: n/a (no GPU code)
  • AI-assisted: yes (Claude Code)
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4992488320 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10499). Originally posted by [frankea](https://github.com/frankea) on 2026-10-24T04:32:03Z. --- ### What `sceKernelGettimezone` wrote `{0, 0}` for every zone, a silent stub that the debt entry for the calendar conversions mentions ("`sceKernelGettimezone` and the `gettimeofday` time zone still report no offset and no daylight saving"). It now fills both fields from the host zone, with the `HostZoneAt` and `HostDaylightAmount` helpers the calendar conversions in the same file already use: - `tz_minuteswest`: the standard offset in minutes east of UTC, despite its name, without the daylight saving in effect. - `tz_dsttime`: the zone's daylight saving amount in minutes, 0 for a zone without daylight saving. - A null pointer still returns `0x8002000E`. Measurement: PS5 on firmware 13.40 set to US Eastern, 2026-10-19, from an elfldr payload process: `sceKernelGettimezone` returned 0 with `tz_minuteswest` -300 and `tz_dsttime` 60. Summer time was in effect on the run date, so -300 is the standard offset, not the current one, and 60 is the daylight saving amount, not a flag. What the console returns outside summer time, or for a zone without daylight saving, was not measured; this console is the only sample. The probe resolves `sceKernelGettimezone` from `libkernel` in the payload process and calls it on a buffer filled with 0x55, the equivalent of: ```c int32_t tz[2] = {0x55555555, 0x55555555}; int r = sceKernelGettimezone(tz); printf("0x%08x minuteswest=%d dsttime=%d\n", (unsigned)r, tz[0], tz[1]); ``` Its output: `sceKernelGettimezone(&tz) -> 0x00000000 minuteswest=-300 dsttime=60`. In the same run `sceKernelConvertUtcToLocaltime` gave local minus UTC of -14400 for 2024-07-01 12:00Z and -18000 for 2024-01-15 12:00Z, with the daylight amount 3600, so the console was on US Eastern. Anyone with a payload loader can repeat it in a zone without daylight saving or in winter. The debt entry moves out of the long calendar conversion entry into one of its own, which says the values follow the host zone rather than the console's time zone setting and what was not measured. The `gettimeofday` time zone is unchanged; #9682 touches that one. ### Tested Windows 11 (build 26200), MinGW GCC (WinLibs 15.2) Release build with `BUILD_TESTING=ON`, each run three times (`ctest --repeat until-fail:3`). - Refreshed onto `main` ca6e29e83 after #10198 merged (head 02eb8256d; the libkernel debt conflict resolved by keeping both PRs' entries): `guest_freebsd_clocks` passes, and so does `main` ca6e29e83. - `guest_freebsd_clocks` gets a case that sets `TZ` and reads `sceKernelGettimezone`: `UTC0` gives 0 and 0, `IST-5:30` 330 and 0, `BRT+3` -180 and 0, `EST5EDT` -300 and 60, `CET-1CEST` 60 and 60; and a null pointer returns `0x8002000E`. On Windows the expected daylight amount comes from the C runtime's `_get_dstbias`, as the test's existing zone cases already do, since a `TZ` variable does not set it. - This PR (4db6ed763, fabe44851 with `main` 97d33464c merged in): `guest_freebsd_clocks` passes. - Control: `main` 97d33464c with only this PR's `GuestFreebsdClocks.cpp`: `guest_freebsd_clocks` aborts on the new case. - `main` 97d33464c with its own test: passes. - Linux: @Dom3005's run in the comments (Ubuntu 26.04, GCC 15, glibc 2.43): this PR merged onto `main` 39a36bbec passes 3 of 3, including the `TZ` cases, where the daylight amount comes from glibc's zone data; the control aborts as on Windows. @TechLevelZero's fleet run (Linux, validation layer on) of `4db6ed763` merged onto `main` `5b85225ef`: no PR-only failures in the 1941 tests `tools/select_tests.py` selects, on a Ryzen 7 9700X iGPU (RDNA2), an RX 9070 XT (RDNA4), Iris Xe, lavapipe on two CPUs and an NVIDIA A800. - `tools/check_conventions.py --base origin/main` reports no errors; its one warning is the length of the calendar conversion debt entry, which was already over the limit before this PR shortened it. ### Overlap #10198 (orezraey), which added a measured calendar conversion entry right after the debt entry this PR edits, merged first; this branch merges `main` after it and keeps both entries. #10975 (xXPBSXx) changes the same `sceKernelGettimezone` body to write `{0, 0}` through `GuestCopyOut_nid_no_patch`, so an unusable pointer returns `EFAULT`; whichever of the two lands second writes this PR's values through that copy. ### Checklist - [x] Based on current `main`; no other open PR implements the same functions. #10975 changes how `sceKernelGettimezone` writes its result, not what it writes (see Overlap); #9682 changes `gettimeofday`'s time zone output in the same file. - [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 (#10198 has merged; see Overlap) - [x] Fixes: none - [x] Unblocks: none known; no title on this machine stops on it - [x] GPUs tested: n/a (no GPU code) - [x] AI-assisted: yes (Claude Code)
harisibrar1 commented 2026-10-24 04:58:44 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by harisibrar1 on 2026-10-24T04:58:44Z.

Review: APPROVED


Checked against main 6c52b649e7, FreeBSD 11.4 sys/sys/time.h / kern_time.c, and shadPS4 23c41333 kernel/time.cpp:

  • This merges cleanly. Main still writes {0, 0} here, and the change reuses the HostZoneAt/HostDaylightAmount helpers already on main. Reading them, the signs look right on both paths: on Windows -_get_timezone and -_get_dstbias give east and a positive DST amount, and on POSIX tm_gmtoff + timezone is the DST amount. I couldn't run the Windows path myself.
  • Worth stating plainly: this departs from FreeBSD's struct timezone, which is "minutes west" plus a DST_* type (DST_USA = 1), so US Eastern would be 300/1 rather than -300/60. shadPS4 returns _timezone/60 and _daylight on Windows, which also differs. So the console run is the only basis here, and it does fit main's existing ConvertUtcToLocaltime entry (seconds east). Could you attach the payload source or its output to the PR, so others can repeat it in a zone without DST or in winter?
  • Minor: once this lands, gettimeofday's tz still reports {0, 0}, while on FreeBSD both come from the same kernel globals. The PR already notes this, so it's fine as a follow-up.

Reviewed with AI assistance (Claude Code); the checks above were run locally on my machine.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5636916795 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10499#pullrequestreview-5636916795). Originally posted by [harisibrar1](https://github.com/harisibrar1) on 2026-10-24T04:58:44Z. **Review:** APPROVED --- Checked against main 6c52b649e7, FreeBSD 11.4 `sys/sys/time.h` / `kern_time.c`, and shadPS4 23c41333 `kernel/time.cpp`: - This merges cleanly. Main still writes `{0, 0}` here, and the change reuses the `HostZoneAt`/`HostDaylightAmount` helpers already on main. Reading them, the signs look right on both paths: on Windows `-_get_timezone` and `-_get_dstbias` give east and a positive DST amount, and on POSIX `tm_gmtoff + timezone` is the DST amount. I couldn't run the Windows path myself. - Worth stating plainly: this departs from FreeBSD's `struct timezone`, which is "minutes west" plus a `DST_*` type (`DST_USA` = 1), so US Eastern would be 300/1 rather than -300/60. shadPS4 returns `_timezone/60` and `_daylight` on Windows, which also differs. So the console run is the only basis here, and it does fit main's existing `ConvertUtcToLocaltime` entry (seconds east). Could you attach the payload source or its output to the PR, so others can repeat it in a zone without DST or in winter? - Minor: once this lands, `gettimeofday`'s `tz` still reports `{0, 0}`, while on FreeBSD both come from the same kernel globals. The PR already notes this, so it's fine as a follow-up. Reviewed with AI assistance (Claude Code); the checks above were run locally on my machine.
MarcZX10 commented 2026-10-24 11:21:09 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-24T11:21:09Z.

Review: DISMISSED


The code and boundary tests look consistent with the measured console result and with the existing host-zone helpers. The author reports the focused Windows test and negative control; Linux and hosted build jobs did not run, and I did not rerun tests locally.

One overlap item needs an agreed order before approval: #10198 is still open, and the overlap report identifies a conflict on the same libkernel debt line this PR edits. Please coordinate with that author and declare which change lands first under Depends on (or update the other PR's checklist to establish the reverse order). #9682 is separately scoped to gettimeofday and is already called out accurately in the description.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5638061319 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/10499#pullrequestreview-5638061319). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-24T11:21:09Z. **Review:** DISMISSED --- The code and boundary tests look consistent with the measured console result and with the existing host-zone helpers. The author reports the focused Windows test and negative control; Linux and hosted build jobs did not run, and I did not rerun tests locally. One overlap item needs an agreed order before approval: #10198 is still open, and the overlap report identifies a conflict on the same libkernel debt line this PR edits. Please coordinate with that author and declare which change lands first under Depends on (or update the other PR's checklist to establish the reverse order). #9682 is separately scoped to gettimeofday and is already called out accurately in the description.
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!10499
No description provided.