fix(libkernel): return EINVAL for invalid non-CPU clock ID in clock_getres #14557

Merged
slopgobblercobbler merged 2 commits from upstream-pr/14557 into main 2026-11-14 11:38:28 +00:00
slopgobblercobbler commented 2026-11-01 15:39:22 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by slopgobblercobbler on 2026-11-01T15:39:22Z.


What

Return EINVAL (SCE_KERNEL_ERROR_EINVAL) in clock_getres_nid_postfix and sceKernelClockGetres for non-CPU clock IDs outside 0..31 (clockId >= 32) without touching the CPU-clock path (bit 31 CPU_CLOCK_BIT set, including negative IDs), aligning fallback semantics with FreeBSD 11.4 kern_clock_getres. Add test coverage in core/libs/tests/GuestKernelSysTime.cpp for invalid non-CPU clock IDs rejecting with EINVAL and encoded CPU-clock IDs succeeding.

Tested

Ran python tools/check_conventions.py --base upstream/main --head HEAD with 0 findings.

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
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5108858596 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/14557). Originally posted by [slopgobblercobbler](https://github.com/slopgobblercobbler) on 2026-11-01T15:39:22Z. --- ### What Return `EINVAL` (`SCE_KERNEL_ERROR_EINVAL`) in `clock_getres_nid_postfix` and `sceKernelClockGetres` for non-CPU clock IDs outside 0..31 (`clockId >= 32`) without touching the CPU-clock path (bit 31 `CPU_CLOCK_BIT` set, including negative IDs), aligning fallback semantics with FreeBSD 11.4 `kern_clock_getres`. Add test coverage in `core/libs/tests/GuestKernelSysTime.cpp` for invalid non-CPU clock IDs rejecting with `EINVAL` and encoded CPU-clock IDs succeeding. ### Tested Ran `python tools/check_conventions.py --base upstream/main --head HEAD` with 0 findings. ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [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 - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes
MarcZX10 commented 2026-11-02 04:41:07 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-02T04:41:07Z.

Review: COMMENTED


Changes requested — the PR's own test fails on the hosted Windows job

The hosted Windows CTest fails on the new test guest_kernel_sys_time (Test #2818, exit code 0xc0000409, 0.12 s), the code UCRT's abort() reports, so a Require in the test failed. By reading the code, the cause is the CPU-clock encoding. IsCpuClock tests bit 31 (CPU_CLOCK_BIT = 0x80000000, Pthread/include/Pthread.hpp line 98). The test's IDs -2 and -100 have that bit set, so the new range check is skipped and they reach the CPU-clock path, which returns success. The test expects -1 and EINVAL. The same expectation fails on any platform, not only Windows. Please reconcile the check with the CPU-clock encoding, and fix or replace those IDs. The test was not run here; this comes from reading the code and the Windows log.

What I ran

  • Head 80eb1aa0b6051428d9c8889fb1bdde910e507aee; base f2d874c1fdccf781c0fa5d86619bb5dd8894b958. 3 files, +37/-0: core/libs/prx/libkernel/CMakeLists.txt (test registration), core/libs/prx/libkernel/Time/Time.cpp (+4) and the new core/libs/tests/GuestKernelSysTime.cpp.
  • Read the diff; the base clock_getres_nid_postfix (Time/Time.cpp lines 639-660 and the Windows path that throws unsupported clock_id); IsCpuClock (line 80) and CPU_CLOCK_BIT (Pthread.hpp line 98); the sceKernelClockGetres wrapper (lines 808-812); and the test's loop over -2, -100, 32, 100 and INT32_MAX.
  • Hosted: the windows check failed. The CTest summary is 99% tests passed, 1 tests failed out of 2595, and the failing case is guest_kernel_sys_time (exit code 0xc0000409).
  • Precheck was not run: this session does not run code from PR heads, and precheck runs head-tree tooling. The read-only checks below were run from the trusted main checkout.
  • No MarcZX10 review at this head.

Results

Check Result Note
Diff check passed read-only
Conventions and PR template passed conventions check from the main checkout
Mergeability and dependencies passed depends on none; the stack check passed
ABI audit (main-checkout tool) passed 24 symbols; no findings
Negative IDs -2 and -100 in the new check failed bit 31 set, so the check is skipped (Time.cpp IsCpuClock); the CPU path returns success (by reading)
guest_kernel_sys_time (hosted Windows) failed exit code 0xc0000409 at 0.12 s; 2 of the 2595 CTest cases failed in the run only if counted, 1 here
Test-quality heuristic (main-checkout tool) flagged "possibly unregistered"; the test is registered in libkernel/CMakeLists.txt (line 920), so this is a false positive
Build and runtime tests (Linux) not run no local build; code from PR heads is not run here
Negative controls not run no local build
Hosted CI failed windows failed on guest_kernel_sys_time; linux and relinkers skipped
Read-only check output (verbatim)
base=f2d874c1fdccf781c0fa5d86619bb5dd8894b958 head=80eb1aa0b6051428d9c8889fb1bdde910e507aee
## diff_check
passed
## changed files
core/libs/prx/libkernel/CMakeLists.txt core/libs/prx/libkernel/Time/Time.cpp core/libs/tests/GuestKernelSysTime.cpp
## conventions
All conventions checks passed.
rc=0
## abi
passed 24
## stack
rc=0
## test quality (main-checkout helper on archived test files)
findings 1
  core/libs/tests/GuestKernelSysTime.cpp possible-unregistered-cpp-test (registered at libkernel/CMakeLists.txt line 920)

Hosted: gh api repos/boykopovar/AnyPS5/commits/80eb1aa0b6051428d9c8889fb1bdde910e507aee/check-runs; the windows job log shows 2818 - guest_kernel_sys_time (Exit code 0xc0000409).

Negative control

Not run here. A negative control needs a build, and running code from this head is not permitted here.

Findings

Blocking

  1. guest_kernel_sys_time fails on the hosted Windows job. By reading, the cause is that IsCpuClock tests bit 31, so -2 and -100 are treated as CPU clocks, skip the new range check, and succeed through the CPU-clock path (Time.cpp line 635). The test expects -1 and EINVAL for them. Please reconcile the check with the CPU-clock encoding, and fix or replace the IDs in the test.

Non-blocking

  • The title is "test(libkernel): cover invalid clock ID in clock_getres", but the diff changes behaviour. On the Windows path, base clock_getres throws unsupported clock_id for IDs it does not handle; the new check returns EINVAL for non-CPU IDs outside 0..31. Please retitle the PR and state the behaviour change.

Sources

Not verified

  • The failing assertion was not identified beyond the exit code and the test's abort(); the reasoning about -2 and -100 is by reading, not by running.
  • The Linux behaviour was not checked.

To get this to a good state

  • Make the range check and the test agree with the CPU-clock encoding, rerun the Windows job, and retitle the PR to state the behaviour change.
<!-- greyfinch-sync:boykopovar/AnyPS5:review:5732151889 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/14557#pullrequestreview-5732151889). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-02T04:41:07Z. **Review:** COMMENTED --- # Changes requested — the PR's own test fails on the hosted Windows job The hosted Windows CTest fails on the new test `guest_kernel_sys_time` (Test #2818, exit code 0xc0000409, 0.12 s), the code UCRT's `abort()` reports, so a `Require` in the test failed. By reading the code, the cause is the CPU-clock encoding. `IsCpuClock` tests bit 31 (`CPU_CLOCK_BIT` = 0x80000000, `Pthread/include/Pthread.hpp` line 98). The test's IDs -2 and -100 have that bit set, so the new range check is skipped and they reach the CPU-clock path, which returns success. The test expects -1 and EINVAL. The same expectation fails on any platform, not only Windows. Please reconcile the check with the CPU-clock encoding, and fix or replace those IDs. The test was not run here; this comes from reading the code and the Windows log. ## What I ran - Head `80eb1aa0b6051428d9c8889fb1bdde910e507aee`; base `f2d874c1fdccf781c0fa5d86619bb5dd8894b958`. 3 files, +37/-0: `core/libs/prx/libkernel/CMakeLists.txt` (test registration), `core/libs/prx/libkernel/Time/Time.cpp` (+4) and the new `core/libs/tests/GuestKernelSysTime.cpp`. - Read the diff; the base `clock_getres_nid_postfix` (`Time/Time.cpp` lines 639-660 and the Windows path that throws `unsupported clock_id`); `IsCpuClock` (line 80) and `CPU_CLOCK_BIT` (`Pthread.hpp` line 98); the `sceKernelClockGetres` wrapper (lines 808-812); and the test's loop over -2, -100, 32, 100 and INT32_MAX. - Hosted: the windows check failed. The CTest summary is `99% tests passed, 1 tests failed out of 2595`, and the failing case is `guest_kernel_sys_time` (exit code 0xc0000409). - Precheck was not run: this session does not run code from PR heads, and precheck runs head-tree tooling. The read-only checks below were run from the trusted main checkout. - No MarcZX10 review at this head. ## Results | Check | Result | Note | | --- | --- | --- | | Diff check | passed | read-only | | Conventions and PR template | passed | conventions check from the main checkout | | Mergeability and dependencies | passed | depends on none; the stack check passed | | ABI audit (main-checkout tool) | passed | 24 symbols; no findings | | Negative IDs -2 and -100 in the new check | failed | bit 31 set, so the check is skipped (`Time.cpp` `IsCpuClock`); the CPU path returns success (by reading) | | `guest_kernel_sys_time` (hosted Windows) | failed | exit code 0xc0000409 at 0.12 s; 2 of the 2595 CTest cases failed in the run only if counted, 1 here | | Test-quality heuristic (main-checkout tool) | flagged | "possibly unregistered"; the test is registered in `libkernel/CMakeLists.txt` (line 920), so this is a false positive | | Build and runtime tests (Linux) | not run | no local build; code from PR heads is not run here | | Negative controls | not run | no local build | | Hosted CI | failed | windows failed on `guest_kernel_sys_time`; linux and relinkers skipped | <details><summary>Read-only check output (verbatim)</summary> ``` base=f2d874c1fdccf781c0fa5d86619bb5dd8894b958 head=80eb1aa0b6051428d9c8889fb1bdde910e507aee ## diff_check passed ## changed files core/libs/prx/libkernel/CMakeLists.txt core/libs/prx/libkernel/Time/Time.cpp core/libs/tests/GuestKernelSysTime.cpp ## conventions All conventions checks passed. rc=0 ## abi passed 24 ## stack rc=0 ## test quality (main-checkout helper on archived test files) findings 1 core/libs/tests/GuestKernelSysTime.cpp possible-unregistered-cpp-test (registered at libkernel/CMakeLists.txt line 920) ``` Hosted: `gh api repos/boykopovar/AnyPS5/commits/80eb1aa0b6051428d9c8889fb1bdde910e507aee/check-runs`; the windows job log shows `2818 - guest_kernel_sys_time (Exit code 0xc0000409)`. </details> ## Negative control Not run here. A negative control needs a build, and running code from this head is not permitted here. ## Findings **Blocking** 1. `guest_kernel_sys_time` fails on the hosted Windows job. By reading, the cause is that `IsCpuClock` tests bit 31, so -2 and -100 are treated as CPU clocks, skip the new range check, and succeed through the CPU-clock path (`Time.cpp` line 635). The test expects -1 and EINVAL for them. Please reconcile the check with the CPU-clock encoding, and fix or replace the IDs in the test. **Non-blocking** - The title is "test(libkernel): cover invalid clock ID in clock_getres", but the diff changes behaviour. On the Windows path, base `clock_getres` throws `unsupported clock_id` for IDs it does not handle; the new check returns EINVAL for non-CPU IDs outside 0..31. Please retitle the PR and state the behaviour change. ## Sources - New check and CPU-clock branch: https://github.com/boykopovar/AnyPS5/blob/80eb1aa0b6051428d9c8889fb1bdde910e507aee/core/libs/prx/libkernel/Time/Time.cpp#L632-L640 - `IsCpuClock` and `CPU_CLOCK_BIT`: https://github.com/boykopovar/AnyPS5/blob/80eb1aa0b6051428d9c8889fb1bdde910e507aee/core/libs/prx/libkernel/Time/Time.cpp#L80-L82 and https://github.com/boykopovar/AnyPS5/blob/80eb1aa0b6051428d9c8889fb1bdde910e507aee/core/libs/prx/libkernel/Pthread/include/Pthread.hpp#L98 - Test loop: https://github.com/boykopovar/AnyPS5/blob/80eb1aa0b6051428d9c8889fb1bdde910e507aee/core/libs/tests/GuestKernelSysTime.cpp - Windows run: https://github.com/boykopovar/AnyPS5/actions (job for head 80eb1aa0b6) ## Not verified - The failing assertion was not identified beyond the exit code and the test's `abort()`; the reasoning about -2 and -100 is by reading, not by running. - The Linux behaviour was not checked. ## To get this to a good state - Make the range check and the test agree with the CPU-clock encoding, rerun the Windows job, and retitle the PR to state the behaviour change.
MarcZX10 commented 2026-11-14 04:32:05 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-14T04:32:05Z.

Review: APPROVED


Reviewed — looks good

The reviewed diff adds the requested invalid non-CPU clock ID check and focused tests; I found no verified blocking defect in the files reviewed.

What I ran

Reviewed head 60fe3aedd6a380061a6569a202ab4dee6c4dd3b2. I read the prepared description, commit list, manifest, diff, and all three changed files. I did not run commands or tests; the description reports a convention check, which I did not independently verify.

Results

Check Result Note
Diff and changed files passed All three listed files read
Tests and convention check not run Only author-reported convention check

Findings

Blocking

None.

Non-blocking

None.

Not verified

No tests or builds were run. The author-reported convention check was not independently verified. No files were excluded according to the manifest; files.json was not available through the reader.

To get this to a good state

Nothing is required.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5901632246 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/14557#pullrequestreview-5901632246). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-14T04:32:05Z. **Review:** APPROVED --- # Reviewed — looks good The reviewed diff adds the requested invalid non-CPU clock ID check and focused tests; I found no verified blocking defect in the files reviewed. ## What I ran Reviewed head `60fe3aedd6a380061a6569a202ab4dee6c4dd3b2`. I read the prepared description, commit list, manifest, diff, and all three changed files. I did not run commands or tests; the description reports a convention check, which I did not independently verify. ## Results | Check | Result | Note | |---|---|---| | Diff and changed files | passed | All three listed files read | | Tests and convention check | not run | Only author-reported convention check | ## Findings ### Blocking None. ### Non-blocking None. ## Not verified No tests or builds were run. The author-reported convention check was not independently verified. No files were excluded according to the manifest; `files.json` was not available through the reader. ## To get this to a good state Nothing is required.
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!14557
No description provided.