fix(libkernel): initialize the full local-time conversion state #2157

Merged
authurtabo-byte merged 1 commit from upstream-pr/2157 into main 2026-10-10 04:44:39 +00:00
authurtabo-byte commented 2026-10-09 10:14:52 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by authurtabo-byte on 2026-10-09T10:14:52Z.


What

sceKernelConvertLocaltimeToUtc writes an 8-byte KernelTimezone into an output that the PS5 guest libc uses as a 16-byte KernelTimesec. Its west_sec and dst_sec fields at offsets 8 and 12 remain uninitialized. In MiniGolf, IL2CPP's time-zone initialization repeatedly searches backward through dates and eventually spends a CPU core in calendar conversion, leaving startup black when loading an existing save.

Use KernelTimesec and initialize its timestamp and both offset fields. This keeps the existing UTC-only policy and matches the state returned by sceKernelConvertUtcToLocaltime.

Evidence comes from the title's converted SDK libc: its mktime passes the fourth argument at stack offset -0x40 and reads its offset fields at -0x38 and -0x34, comparing them with the corresponding state returned by UTC-to-local conversion. An 8-byte write cannot initialize those fields.

Tested

Rebased onto main f8c2f072. Fresh independent Windows Release build: guest_freebsd_clocks passes (0.45 seconds); conventions pass.

Windows 11, WinLibs GCC, Release. Extended guest_freebsd_clocks with poisoned conversion states, surrounding guards, epoch/negative/2026/post-2038 timestamps, round trips and optional null outputs. The test fails with the previous implementation and passes with this change.

MiniGolf previously remained on its initial black frame with its SaveData worker continuously running calendar conversion. With this change and the separate startup/rendering fixes in the integration build, the same saved data loads and startup advances to the publisher logo. No save files were removed or modified to bypass the issue.

Conventions and whitespace checks pass. Linux, other titles and hardware comparison were not run.

Checklist

  • Based on current main; no other open PR implements the same fix
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw; no silent stubs added
  • No notes, investigation files or images added to the repository
  • No third-party code added
  • Generic behaviour, not specific to one title
  • Depends on: none
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4799055079 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2157). Originally posted by [authurtabo-byte](https://github.com/authurtabo-byte) on 2026-10-09T10:14:52Z. --- ### What `sceKernelConvertLocaltimeToUtc` writes an 8-byte `KernelTimezone` into an output that the PS5 guest libc uses as a 16-byte `KernelTimesec`. Its `west_sec` and `dst_sec` fields at offsets 8 and 12 remain uninitialized. In MiniGolf, IL2CPP's time-zone initialization repeatedly searches backward through dates and eventually spends a CPU core in calendar conversion, leaving startup black when loading an existing save. Use `KernelTimesec` and initialize its timestamp and both offset fields. This keeps the existing UTC-only policy and matches the state returned by `sceKernelConvertUtcToLocaltime`. Evidence comes from the title's converted SDK libc: its `mktime` passes the fourth argument at stack offset -0x40 and reads its offset fields at -0x38 and -0x34, comparing them with the corresponding state returned by UTC-to-local conversion. An 8-byte write cannot initialize those fields. ### Tested Rebased onto main `f8c2f072`. Fresh independent Windows Release build: `guest_freebsd_clocks` passes (0.45 seconds); conventions pass. Windows 11, WinLibs GCC, Release. Extended `guest_freebsd_clocks` with poisoned conversion states, surrounding guards, epoch/negative/2026/post-2038 timestamps, round trips and optional null outputs. The test fails with the previous implementation and passes with this change. MiniGolf previously remained on its initial black frame with its SaveData worker continuously running calendar conversion. With this change and the separate startup/rendering fixes in the integration build, the same saved data loads and startup advances to the publisher logo. No save files were removed or modified to bypass the issue. Conventions and whitespace checks pass. Linux, other titles and hardware comparison were not run. ### Checklist - [x] Based on current `main`; no other open PR implements the same fix - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except technical debt - [x] Unimplemented paths throw; no silent stubs added - [x] No notes, investigation files or images added to the repository - [x] No third-party code added - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] AI-assisted: yes
github-actions[bot] commented 2026-10-10 04:20:06 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-10T04:20:06Z.


Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.

Pull request Conflicting files (lines on main) Same exports Same new files
#2545 sceKernelConvertLocaltimeToUtc
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6093702086 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2157#issuecomment-6093702086). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-10T04:20:06Z. --- <!-- pr-overlap --> Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in **Depends on**. | Pull request | Conflicting files (lines on `main`) | Same exports | Same new files | |---|---|---|---| | #2545 | | `sceKernelConvertLocaltimeToUtc` | |
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!2157
No description provided.