feat(libkernel_sys): implement settimeofday #9682

Merged
Gruzzberry merged 1 commit from upstream-pr/9682 into main 2026-10-25 22:04:12 +00:00
Gruzzberry commented 2026-10-22 08:23:34 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Gruzzberry on 2026-10-22T08:23:34Z.


What

settimeofday was a throwing stub in libkernel_sys. FreeBSD 11.4's kern_settimeofday (called by sys_settimeofday, which treats a null pointer as not given) rejects a time with a negative second count or a microsecond count outside 0 to 999999 with EINVAL before changing anything, sets the clock from a valid time, and only then stores the time zone, which sys_gettimeofday reports.

SetTimeOfDay_nid_no_patch in Time.cpp, next to clock_settime, does the same checks. A valid time throws, naming it, as clock_settime does for CLOCK_REALTIME, because the host clock is never set; the time zone is then not stored. A time zone given without a time is kept for the process, and gettimeofday now reports it instead of 0 and 0 (which it still reports until one is set). settimeofday in libkernel_sys forwards to the helper. sceKernelGettimezone is unchanged and still reports 0 and 0: whether the console's reads the same value is not known. The debt entry next to clock_settime records the throw, the zone and the unverified privilege check.

Tested

Windows 11 (10.0.26200), WinLibs MinGW-w64 GCC 15.2.0 r7, Ninja, Release, -DBUILD_TESTING=ON, on main d6eafa54d0.

  • guest_kernel_sys: new CheckSettimeofday cases: null time and zone return 0; {0, 1000000}, {0, -1} and {-1, 0} fail with EINVAL and store nothing; a valid time throws with settimeofday: setting the time to 1000000000.000000 and stores no zone; a zone alone is stored and read back by gettimeofday, which still returns the time; the zone is reset to 0 and 0 at the end. On main the test aborts with settimeofday_nid_postfix not implemented; with this PR it passes.
  • guest_freebsd_clocks, guest_time_conversion, guest_time_extras, guest_mktime, guest_strftime, guest_utime, guest_utime_forwarding, guest_system_service_time_zone, guest_cpu_time_clocks, guest_nanosleep: pass.
  • Full suite on main d6eafa54d0 and on main with this PR merged together with #9442, #9469, #9474, #9487, #9496 and #9661, same machine: 1890 tests each, identical results (1869 passed, 18 skipped; on both, the 3 agc_driver_sample_order* tests fail and agc_driver_image_array_window_past_layer_limit is not built, as its 64 KiB alignas is rejected by this MinGW toolchain).
  • python tools/check_conventions.py --base upstream/main: passes.
  • Not tested: Linux (the change is host independent), a console, a title run.

Overlaps

  • tools/pr_overlap.py --branch lists #9389 (sigqueue), which removes the stub next to settimeofday in Export.Discovery.cpp: text only, whichever lands second rebases.
  • Trial merges with #7464, #9131, #9097 and #9336, which edit nearby lines of libkernel.md and GuestKernelSys.cpp, are clean. #9103 does not merge with main itself (libkernel_sys.md, a file this PR does not touch) and merges cleanly here otherwise.
  • Of the pull requests the scan could not compare, none changes gettimeofday, clock_settime or the time zone.

Checklist

  • Based on current main; no other open PR implements the same functions
  • 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); no silent stubs added
  • No notes, investigation .md files or images added to the repository
  • New third-party code is a submodule built from source: none added
  • Generic behaviour, not specific to one title
  • Depends on: none. Merge order: after #9389 (neighbouring stub in Export.Discovery.cpp); this PR then rebases.
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes

AI-assisted (Claude Code).

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4964366088 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9682). Originally posted by [Gruzzberry](https://github.com/Gruzzberry) on 2026-10-22T08:23:34Z. --- ### What `settimeofday` was a throwing stub in libkernel_sys. FreeBSD 11.4's [`kern_settimeofday`](https://github.com/freebsd/freebsd-src/blob/release/11.4.0/sys/kern/kern_time.c#L688-L707) (called by [`sys_settimeofday`](https://github.com/freebsd/freebsd-src/blob/release/11.4.0/sys/kern/kern_time.c#L664-L685), which treats a null pointer as not given) rejects a time with a negative second count or a microsecond count outside 0 to 999999 with `EINVAL` before changing anything, sets the clock from a valid time, and only then stores the time zone, which [`sys_gettimeofday`](https://github.com/freebsd/freebsd-src/blob/release/11.4.0/sys/kern/kern_time.c#L638-L654) reports. `SetTimeOfDay_nid_no_patch` in `Time.cpp`, next to `clock_settime`, does the same checks. A valid time throws, naming it, as `clock_settime` does for `CLOCK_REALTIME`, because the host clock is never set; the time zone is then not stored. A time zone given without a time is kept for the process, and `gettimeofday` now reports it instead of 0 and 0 (which it still reports until one is set). `settimeofday` in libkernel_sys forwards to the helper. `sceKernelGettimezone` is unchanged and still reports 0 and 0: whether the console's reads the same value is not known. The debt entry next to `clock_settime` records the throw, the zone and the unverified privilege check. ### Tested Windows 11 (10.0.26200), WinLibs MinGW-w64 GCC 15.2.0 r7, Ninja, Release, `-DBUILD_TESTING=ON`, on `main` d6eafa54d0. - `guest_kernel_sys`: new `CheckSettimeofday` cases: null time and zone return 0; `{0, 1000000}`, `{0, -1}` and `{-1, 0}` fail with `EINVAL` and store nothing; a valid time throws with `settimeofday: setting the time to 1000000000.000000` and stores no zone; a zone alone is stored and read back by `gettimeofday`, which still returns the time; the zone is reset to 0 and 0 at the end. On `main` the test aborts with `settimeofday_nid_postfix not implemented`; with this PR it passes. - `guest_freebsd_clocks`, `guest_time_conversion`, `guest_time_extras`, `guest_mktime`, `guest_strftime`, `guest_utime`, `guest_utime_forwarding`, `guest_system_service_time_zone`, `guest_cpu_time_clocks`, `guest_nanosleep`: pass. - Full suite on `main` d6eafa54d0 and on `main` with this PR merged together with #9442, #9469, #9474, #9487, #9496 and #9661, same machine: 1890 tests each, identical results (1869 passed, 18 skipped; on both, the 3 `agc_driver_sample_order*` tests fail and `agc_driver_image_array_window_past_layer_limit` is not built, as its 64 KiB `alignas` is rejected by this MinGW toolchain). - `python tools/check_conventions.py --base upstream/main`: passes. - Not tested: Linux (the change is host independent), a console, a title run. ### Overlaps - `tools/pr_overlap.py --branch` lists #9389 (`sigqueue`), which removes the stub next to `settimeofday` in `Export.Discovery.cpp`: text only, whichever lands second rebases. - Trial merges with #7464, #9131, #9097 and #9336, which edit nearby lines of `libkernel.md` and `GuestKernelSys.cpp`, are clean. #9103 does not merge with `main` itself (`libkernel_sys.md`, a file this PR does not touch) and merges cleanly here otherwise. - Of the pull requests the scan could not compare, none changes `gettimeofday`, `clock_settime` or the time zone. ### Checklist - [x] Based on current `main`; no other open PR implements the same functions - [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`); no silent stubs added - [x] No notes, investigation `.md` files or images added to the repository - [x] New third-party code is a submodule built from source: none added - [x] Generic behaviour, not specific to one title - [x] Depends on: none. Merge order: after #9389 (neighbouring stub in `Export.Discovery.cpp`); this PR then rebases. - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes AI-assisted (Claude Code). 🤖 Generated with [Claude Code](https://claude.com/claude-code)
MarcZX10 commented 2026-10-22 08:47:22 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-22T08:47:22Z.

Review: DISMISSED


The implementation and current-main conventions check look consistent with the documented host-clock limitation; I did not independently reproduce the author-reported Windows test run, and this checkout has no build configured for this head. I found one repository-readiness issue before this can proceed: 1. The current open #9389 changes the adjacent sigqueue stub in Export.Discovery.cpp; a pairwise merge check reports a conflict in that file. The PR body notes that one side will need rebasing, but the contribution rule asks authors to agree on the order and put the dependency on the checklist when one must wait. Please coordinate with #9389 and update the checklist accordingly. This head is also two commits behind current main; refresh it and rerun the relevant checks after the #9389 overlap order is resolved. The existing Windows test report and the passing conventions/eligibility checks are noted; product test jobs are skipped automatically on this PR.

I’ve noticed that holding this PR because of #5239 isn’t necessary. It’s fine for PRs to keep coming in; they’ll be handled in due course. Please disregard my earlier request to hold or defer it.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5611540286 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9682#pullrequestreview-5611540286). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-22T08:47:22Z. **Review:** DISMISSED --- The implementation and current-main conventions check look consistent with the documented host-clock limitation; I did not independently reproduce the author-reported Windows test run, and this checkout has no build configured for this head. I found one repository-readiness issue before this can proceed: 1. The current open #9389 changes the adjacent `sigqueue` stub in `Export.Discovery.cpp`; a pairwise merge check reports a conflict in that file. The PR body notes that one side will need rebasing, but the contribution rule asks authors to agree on the order and put the dependency on the checklist when one must wait. Please coordinate with #9389 and update the checklist accordingly. This head is also two commits behind current `main`; refresh it and rerun the relevant checks after the #9389 overlap order is resolved. The existing Windows test report and the passing conventions/eligibility checks are noted; product test jobs are skipped automatically on this PR. I’ve noticed that holding this PR because of #5239 isn’t necessary. It’s fine for PRs to keep coming in; they’ll be handled in due course. Please disregard my earlier request to hold or defer it.
Gruzzberry commented 2026-10-22 11:41:09 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Gruzzberry on 2026-10-22T11:41:09Z.


Holding this as a draft, following the direction on #5239: the open queue is above 700 and no named title needs this change on current main. I will only mark it ready again with a current-main title ID, its Game bring-up discussion and the log line where it stops on this, or once the queue is below 700. Thanks for the reviews so far; the requested fixes are being made on the branch in the meantime.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6339859748 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9682#issuecomment-6339859748). Originally posted by [Gruzzberry](https://github.com/Gruzzberry) on 2026-10-22T11:41:09Z. --- Holding this as a draft, following the direction on #5239: the open queue is above 700 and no named title needs this change on current `main`. I will only mark it ready again with a current-main title ID, its Game bring-up discussion and the log line where it stops on this, or once the queue is below 700. Thanks for the reviews so far; the requested fixes are being made on the branch in the meantime.
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!9682
No description provided.