fix(libkernel): answer the clock ids a PS5 measured invalid as it does #16437

Merged
XatiX merged 2 commits from upstream-pr/16437 into main 2026-11-09 13:47:57 +00:00
XatiX commented 2026-11-06 17:38:48 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by XatiX on 2026-11-06T17:38:48Z.


What

clock_gettime and sceKernelClockGettime threw for every clock id they do not map. This answers the ids that PS5 measurements of both exports settle, and leaves the rest throwing:

Clock id Measured on a PS5 Now
3, 6, 22 to 31 EINVAL from both exports, result left unwritten (firmware 11.60, a payload process, measured by xXPBSXx on this pull request); EINVAL from the raw clock_gettime system call too (CFI-1216A, firmware 12.00, a system and a title process, #15725) both exports fail with EINVAL before writing the result
16 to 19 EIO from both exports (errno 5, 0x80020005 from sceKernelClockGettime), result left unwritten both exports fail with EIO before writing the result
20 a time from both exports: 2033.63095 s in three reads while id 4 advanced 38 µs, 79,200 s below uptime still throws: what it counts is not known
21 a time from both exports: 0.195539 s, in microsecond steps like a CPU-time clock still throws: what it counts is not known

This follows #15656, which was closed because its EINVAL had not been measured. An earlier version of this pull request also failed 17, 18 and 20 with EINVAL from the system call alone; the export measurements contradict that, and the code now follows them.

The debt entry records what ids 20 and 21 read and closes when what they count is measured (and id 15, whose console reading left a doubt).

PlayFab Party (Party.prx in PPSA18653) reads clock 20 at 0x29be26 and falls back to gettimeofday when the call fails. With id 20 still throwing, the title still aborts there, so this pull request does not unblock it.

In guest_freebsd_clocks, InvalidClockIdFailsGettime checks ids -1, 999, 3, 6 and 22 to 31 through both exports (-1 with EINVAL, 0x80020016 from sceKernelClockGettime, result untouched); ClockIoErrorIds checks ids 16 to 19 through both exports (-1 with errno 5, 0x80020005, result untouched); OmittedTimeIsFaultAfterClockValidation checks that 3, 6, 22 and 31 with a null result give EINVAL and 16 and 19 give EIO from clock_gettime, and EFAULT from sceKernelClockGettime, which checks the pointer first.

Tested

  • Windows 11 Pro 26300, MinGW-w64 GCC 15, Release.
  • Head 90c86fb36a on main 1086833f9a: guest_freebsd_clocks, guest_cpu_time_clocks, guest_thread_cpu_clock, the guest_process_time* and guest_timespec_getres* tests, guest_time_conversion, guest_time_extras, guest_time_return, guest_np_common_clock, guest_nanosleep_timer_self_test, guest_mktime and guest_strftime pass (22 of 22); guest_freebsd_clocks alone 3 of 3.
  • PPSA18653: not rerun; it reaches id 20, which still throws here.
  • Linux: not run.
  • tools/check_conventions.py --base upstream/main: all checks pass.

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); 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
  • Fixes: none (#15725 stays open for ids 20 and 21 and for clock_getres)
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5192069771 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/16437). Originally posted by [XatiX](https://github.com/XatiX) on 2026-11-06T17:38:48Z. --- ### What `clock_gettime` and `sceKernelClockGettime` threw for every clock id they do not map. This answers the ids that PS5 measurements of both exports settle, and leaves the rest throwing: | Clock id | Measured on a PS5 | Now | |---|---|---| | 3, 6, 22 to 31 | `EINVAL` from both exports, result left unwritten (firmware 11.60, a payload process, measured by xXPBSXx on this pull request); `EINVAL` from the raw `clock_gettime` system call too (CFI-1216A, firmware 12.00, a system and a title process, #15725) | both exports fail with `EINVAL` before writing the result | | 16 to 19 | `EIO` from both exports (`errno` 5, `0x80020005` from `sceKernelClockGettime`), result left unwritten | both exports fail with `EIO` before writing the result | | 20 | a time from both exports: 2033.63095 s in three reads while id 4 advanced 38 µs, 79,200 s below uptime | still throws: what it counts is not known | | 21 | a time from both exports: 0.195539 s, in microsecond steps like a CPU-time clock | still throws: what it counts is not known | This follows #15656, which was closed because its `EINVAL` had not been measured. An earlier version of this pull request also failed 17, 18 and 20 with `EINVAL` from the system call alone; the export measurements contradict that, and the code now follows them. The debt entry records what ids 20 and 21 read and closes when what they count is measured (and id 15, whose console reading left a doubt). PlayFab Party (`Party.prx` in PPSA18653) reads clock 20 at `0x29be26` and falls back to `gettimeofday` when the call fails. With id 20 still throwing, the title still aborts there, so this pull request does not unblock it. In `guest_freebsd_clocks`, `InvalidClockIdFailsGettime` checks ids -1, 999, 3, 6 and 22 to 31 through both exports (-1 with `EINVAL`, `0x80020016` from `sceKernelClockGettime`, result untouched); `ClockIoErrorIds` checks ids 16 to 19 through both exports (-1 with `errno` 5, `0x80020005`, result untouched); `OmittedTimeIsFaultAfterClockValidation` checks that 3, 6, 22 and 31 with a null result give `EINVAL` and 16 and 19 give `EIO` from `clock_gettime`, and `EFAULT` from `sceKernelClockGettime`, which checks the pointer first. ### Tested - Windows 11 Pro 26300, MinGW-w64 GCC 15, Release. - Head `90c86fb36a` on `main` `1086833f9a`: `guest_freebsd_clocks`, `guest_cpu_time_clocks`, `guest_thread_cpu_clock`, the `guest_process_time*` and `guest_timespec_getres*` tests, `guest_time_conversion`, `guest_time_extras`, `guest_time_return`, `guest_np_common_clock`, `guest_nanosleep_timer_self_test`, `guest_mktime` and `guest_strftime` pass (22 of 22); `guest_freebsd_clocks` alone 3 of 3. - PPSA18653: not rerun; it reaches id 20, which still throws here. - Linux: not run. - `tools/check_conventions.py --base upstream/main`: all checks pass. ### 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`); 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 - [x] Fixes: none (#15725 stays open for ids 20 and 21 and for `clock_getres`) - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes 🤖 Generated with [Claude Code](https://claude.com/claude-code)
gabichuuuuu commented 2026-11-07 23:27:08 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by gabichuuuuu on 2026-11-07T23:27:08Z.

Review: COMMENTED


Read 41f70c5e1c against main.

Correctness. The new check runs before ReadClock and before the copy-out, so the result is never written and a null result gives EINVAL. FreeBSD 11.4 does the same: sys_clock_gettime copies out only when kern_clock_gettime succeeds (sys/kern/kern_time.c:237-239), and its default case fails unknown non-negative ids with EINVAL (:369-371). Ids 3 and 6 are unassigned in 11.4 (sys/sys/time.h:384-397), so for them the measurement and FreeBSD agree. IsCpuClock is checked first, so CPU-time clock ids are unaffected, and the id list matches the table on #15725 with nothing specific to one title. InvalidClockIdFailsGettime aborts on main at id 3.

Debt closing condition. docs/dev/debt/libkernel.md:372 says the probe didn't call libkernel's own export, so a mapping there isn't ruled out, but Closes when lists only ids 15, 16, 19 and 21, while the code now returns EINVAL from the export for 17, 18 and 20. "Closes when: ids 15, 16, 19 and 21 are measured, and libkernel's own clock_gettime export is measured for ids 16 to 21" would keep that gap open until it's measured.

Open question, not a defect. On #15725 the console's libkernel is read as mapping 17 to 20 before the syscall. If so, the export here gives the syscall's answer for 17, 18 and 20; Party falls back, so this title wouldn't notice, but another caller of those ids would. Whether 17, 18 and 20 go in now or wait for the export measurement already requested there, with 3, 6 and 22 to 31 going in now, is a maintainer call.

Not run here; this is from reading the code.

AI-assisted: yes.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5815554714 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/16437#pullrequestreview-5815554714). Originally posted by [gabichuuuuu](https://github.com/gabichuuuuu) on 2026-11-07T23:27:08Z. **Review:** COMMENTED --- Read `41f70c5e1c` against `main`. **Correctness.** The new check runs before `ReadClock` and before the copy-out, so the result is never written and a null result gives `EINVAL`. FreeBSD 11.4 does the same: `sys_clock_gettime` copies out only when `kern_clock_gettime` succeeds (sys/kern/kern_time.c:237-239), and its default case fails unknown non-negative ids with `EINVAL` (:369-371). Ids 3 and 6 are unassigned in 11.4 (sys/sys/time.h:384-397), so for them the measurement and FreeBSD agree. `IsCpuClock` is checked first, so CPU-time clock ids are unaffected, and the id list matches the table on #15725 with nothing specific to one title. `InvalidClockIdFailsGettime` aborts on `main` at id 3. **Debt closing condition.** `docs/dev/debt/libkernel.md:372` says the probe didn't call libkernel's own export, so a mapping there isn't ruled out, but `Closes when` lists only ids 15, 16, 19 and 21, while the code now returns `EINVAL` from the export for 17, 18 and 20. "Closes when: ids 15, 16, 19 and 21 are measured, and libkernel's own clock_gettime export is measured for ids 16 to 21" would keep that gap open until it's measured. **Open question, not a defect.** On #15725 the console's libkernel is read as mapping 17 to 20 before the syscall. If so, the export here gives the syscall's answer for 17, 18 and 20; Party falls back, so this title wouldn't notice, but another caller of those ids would. Whether 17, 18 and 20 go in now or wait for the export measurement already requested there, with 3, 6 and 22 to 31 going in now, is a maintainer call. Not run here; this is from reading the code. AI-assisted: yes.
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!16437
No description provided.