feat(libkernel): fail unknown clock ids 16 to 31 with EINVAL on request #15656

Closed
XatiX wants to merge 1 commit from upstream-pr/15656 into main
XatiX commented 2026-11-04 00:24:51 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by XatiX on 2026-11-04T00:24:51Z.


What

clock_gettime and clock_getres throw for the clock ids 16 to 31 that are not implemented, since a PS5 may define them (#14618 kept that range throwing). APS5_FAIL_UNKNOWN_CLOCKS makes them fail with EINVAL instead, as FreeBSD's kern_clock_gettime does for an unknown id, so a caller with a fallback can go on. Without it nothing changes.

PlayFab Party (Party.prx, shipped by PPSA18653) reads clock 20 for a timestamp (0x29be26) and falls back to gettimeofday, then time, when the call fails. Its sibling function reads clock 0, so clock 20 is a wall clock that the SDK lets fail, like the PS4 network clocks 16 to 19. No public source names id 20. A measurement on a PS5 (what clock_gettime(20) and clock_getres(20) return there, and for 16 to 19) would settle it; it is recorded in technical debt.

guest_freebsd_clocks checks that ids 16, 20 and 31 still throw by default, fail with EINVAL (0x80020016 from sceKernelClockGettime) for both calls with the variable set, leave the result untouched, and that id 3 still throws and clock 0 still reads.

Tested

  • Windows 11 Pro 26300, MinGW-w64 GCC.
  • guest_freebsd_clocks: 3/3 pass with the change, 3/3 fail on main. ctest -R "clock|time": 130/130 pass.
  • Rebased onto main 1c8c0efc8c (head c100fdc57c): guest_freebsd_clocks passes again, including UnknownClocksFailOnlyWhenRequested.
  • PPSA18653 with #15327 and clock 20 failing with EINVAL: Party takes its gettimeofday fallback, the clock_gettime: unsupported clock_id 20 abort at about 50 s is gone, and the title reaches its first-run preferences screen (at about 0.14 FPS, the next blocker).
  • Linux: not run.
  • tools/check_conventions.py passes. tools/pr_overlap.py --branch reports neighbouring edits only, and a merge keeps both: #12418 (EFAULT for an unwritable result) at Time.cpp L637-638, and #12544 and #15064 at ENVIRONMENT.md L661.

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 (PPSA18653 reaches this call only with #15327)
  • Fixes: none
  • Unblocks: PPSA18653 #15328 (with APS5_FAIL_UNKNOWN_CLOCKS=1)
  • GPUs tested: n/a
  • AI-assisted: yes

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5146674579 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/15656). Originally posted by [XatiX](https://github.com/XatiX) on 2026-11-04T00:24:51Z. --- ### What `clock_gettime` and `clock_getres` throw for the clock ids 16 to 31 that are not implemented, since a PS5 may define them (#14618 kept that range throwing). `APS5_FAIL_UNKNOWN_CLOCKS` makes them fail with `EINVAL` instead, as FreeBSD's `kern_clock_gettime` does for an unknown id, so a caller with a fallback can go on. Without it nothing changes. PlayFab Party (`Party.prx`, shipped by PPSA18653) reads clock 20 for a timestamp (`0x29be26`) and falls back to `gettimeofday`, then `time`, when the call fails. Its sibling function reads clock 0, so clock 20 is a wall clock that the SDK lets fail, like the PS4 network clocks 16 to 19. No public source names id 20. A measurement on a PS5 (what `clock_gettime(20)` and `clock_getres(20)` return there, and for 16 to 19) would settle it; it is recorded in technical debt. `guest_freebsd_clocks` checks that ids 16, 20 and 31 still throw by default, fail with `EINVAL` (`0x80020016` from `sceKernelClockGettime`) for both calls with the variable set, leave the result untouched, and that id 3 still throws and clock 0 still reads. ### Tested - Windows 11 Pro 26300, MinGW-w64 GCC. - `guest_freebsd_clocks`: 3/3 pass with the change, 3/3 fail on `main`. `ctest -R "clock|time"`: 130/130 pass. - Rebased onto `main` `1c8c0efc8c` (head `c100fdc57c`): `guest_freebsd_clocks` passes again, including `UnknownClocksFailOnlyWhenRequested`. - PPSA18653 with #15327 and clock 20 failing with `EINVAL`: Party takes its `gettimeofday` fallback, the `clock_gettime: unsupported clock_id 20` abort at about 50 s is gone, and the title reaches its first-run preferences screen (at about 0.14 FPS, the next blocker). - Linux: not run. - `tools/check_conventions.py` passes. `tools/pr_overlap.py --branch` reports neighbouring edits only, and a merge keeps both: #12418 (EFAULT for an unwritable result) at `Time.cpp` L637-638, and #12544 and #15064 at `ENVIRONMENT.md` L661. ### 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 (PPSA18653 reaches this call only with #15327) - [x] Fixes: none - [x] Unblocks: PPSA18653 #15328 (with `APS5_FAIL_UNKNOWN_CLOCKS=1`) - [x] GPUs tested: n/a - [x] AI-assisted: yes 🤖 Generated with [Claude Code](https://claude.com/claude-code)
BunnyFl commented 2026-11-04 01:35:35 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by BunnyFl on 2026-11-04T01:35:35Z.

Review: APPROVED


@XatiX thanks. The default is unchanged: ids 16 to 31 still throw unless APS5_FAIL_UNKNOWN_CLOCKS is set (Time.cpp:84-86). The opt-in failure is FreeBSD's EINVAL for an unknown id, returned before the result is written. The debt entry states plainly that the PS5's answer for ids 16 to 20 isn't measured. clock_getres with a null result still returns 0 before the new check (Time.cpp:642), which matches FreeBSD 11.4's sys_clock_getres returning 0 for a null tp before it validates the id (kern_time.c).

What I ran: head c100fdc57c (it fast-forwards onto main 1c8c0efc8c), Windows 11, WinLibs GCC, Release:

  • the 7 tests matching clock pass (7 of 7), guest_freebsd_clocks included;
  • negative control, Time.cpp taken from main with the new test kept: guest_freebsd_clocks aborts (0xc0000409), 6 of 7 pass;
  • tools/check_conventions.py --base upstream/main on the head: all checks passed;
  • tools/pr_overlap.py --branch: only neighbouring lines in docs/dev/ENVIRONMENT.md and docs/dev/debt/libkernel.md. #15035 couldn't be compared (it conflicts with main); it changes settimeofday and clock_settime, not these two calls.

Approving.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5761980002 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/15656#pullrequestreview-5761980002). Originally posted by [BunnyFl](https://github.com/BunnyFl) on 2026-11-04T01:35:35Z. **Review:** APPROVED --- @XatiX thanks. The default is unchanged: ids 16 to 31 still throw unless `APS5_FAIL_UNKNOWN_CLOCKS` is set (`Time.cpp:84-86`). The opt-in failure is FreeBSD's `EINVAL` for an unknown id, returned before the result is written. The debt entry states plainly that the PS5's answer for ids 16 to 20 isn't measured. `clock_getres` with a null result still returns 0 before the new check (`Time.cpp:642`), which matches FreeBSD 11.4's `sys_clock_getres` returning 0 for a null `tp` before it validates the id ([kern_time.c](https://github.com/freebsd/freebsd-src/blob/release/11.4.0/sys/kern/kern_time.c#L420-L433)). **What I ran:** head `c100fdc57c` (it fast-forwards onto `main` `1c8c0efc8c`), Windows 11, WinLibs GCC, Release: - the 7 tests matching `clock` pass (7 of 7), `guest_freebsd_clocks` included; - negative control, `Time.cpp` taken from `main` with the new test kept: `guest_freebsd_clocks` aborts (`0xc0000409`), 6 of 7 pass; - `tools/check_conventions.py --base upstream/main` on the head: all checks passed; - `tools/pr_overlap.py --branch`: only neighbouring lines in `docs/dev/ENVIRONMENT.md` and `docs/dev/debt/libkernel.md`. #15035 couldn't be compared (it conflicts with `main`); it changes `settimeofday` and `clock_settime`, not these two calls. Approving.

Pull request closed

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!15656
No description provided.