feat(libc): forward time resolution queries to the kernel #14620

Merged
Danigamer05 merged 3 commits from upstream-pr/14620 into main 2026-11-05 04:27:47 +00:00
Danigamer05 commented 2026-11-01 16:29:37 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Danigamer05 on 2026-11-01T16:29:37Z.


What

Implement timespec_getres (libc, NID ZvRHHCfA4HA) by forwarding base 1 to libkernel's sceKernelClockGetres with clock ID 0. Return 1 only when that provider succeeds; other bases return 0 without calling it or changing memory/errno. An absent provider throws instead of fabricating a resolution.

The contract comes from PPSA03671 v01.001.005's bundled libc.prx, SHA-256 483961e086b8a1fffa8138b3c0badf798987fb5f35ec908d828946408be2d8a6, at RVA 0x6D9E0: the original wrapper calls its imported sceKernelClockGetres. libc keeps an atomic registered callback, and libkernel registers its existing implementation when it loads. Memory validation, clock resolution and errno therefore come from the same provider as direct kernel calls.

#13273 proposes a parameterless throwing libSceLibcInternal inventory placeholder for the same name/NID, with unverified arguments and behavior. That is not an implementation and is not a dependency of this change. This PR supplies the typed libc behavior; it does not add the inventory placeholder. #6084 concerns the different timespec_get export.

Tested

Windows x86-64, WinLibs GCC 15.2.0, Release, BUILD_TESTING=ON, main f2d874c1fdccf781c0fa5d86619bb5dd8894b958. Exact tested head: 906bf667bc94bf797b73579c08203610a9b5ba46.

  • Built libc, libkernel, their patched production files and guest_timespec_getres_tests.
  • Five selected CTests pass without skips: public_headers and all four guest_timespec_getres_{unsupported,forwarding,errors,integration} cases. They cover unsupported bases with inaccessible output, forwarded pointer/clock ID, signed provider errors and errno, null output, surrounding sentinels and extreme 64-bit fields, and calls through the actually loaded kernel.
  • 1,572,984 differential vectors against the original wrapper, with its clock import explicitly replaced by a controlled callee: zero differences in return values, output, call selection and errno; independent expected outputs also agree. This checks the wrapper contract, not console clock precision. Original module initializers are not run.
  • Following review, removed the missing-provider exception test and its CTest registration. Production code and the missing-provider guard are unchanged. Rebuilt the test and patched production libraries and repeated the selected tests and differential comparison at the head above.
  • Conventions and committed diff whitespace checks pass.
  • Initial pre-publication official overlap scan: 1,823 open PRs, no confirmed overlap or duplicate implementation. It retains exit 2 for 35 branches already conflicting with main. Their added library/test/shared-file diffs were checked against all merge bases for this function and NID, without matches; no claim that those branches merge cleanly.

Not tested: Linux, macOS, another SDK, a game, GPU or console. No speed or game compatibility claim. No original binary or extracted bytes, notes or logs are committed.

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:5109285953 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/14620). Originally posted by [Danigamer05](https://github.com/Danigamer05) on 2026-11-01T16:29:37Z. --- ### What Implement `timespec_getres` (libc, NID `ZvRHHCfA4HA`) by forwarding base 1 to libkernel's `sceKernelClockGetres` with clock ID 0. Return 1 only when that provider succeeds; other bases return 0 without calling it or changing memory/errno. An absent provider throws instead of fabricating a resolution. The contract comes from PPSA03671 v01.001.005's bundled `libc.prx`, SHA-256 `483961e086b8a1fffa8138b3c0badf798987fb5f35ec908d828946408be2d8a6`, at RVA `0x6D9E0`: the original wrapper calls its imported `sceKernelClockGetres`. libc keeps an atomic registered callback, and libkernel registers its existing implementation when it loads. Memory validation, clock resolution and errno therefore come from the same provider as direct kernel calls. #13273 proposes a parameterless throwing `libSceLibcInternal` inventory placeholder for the same name/NID, with unverified arguments and behavior. That is not an implementation and is not a dependency of this change. This PR supplies the typed libc behavior; it does not add the inventory placeholder. #6084 concerns the different `timespec_get` export. ### Tested <!-- OS, title or homebrew, what was checked. "Not tested" is a valid answer. A performance change: the summary lines of main and of this PR from the same machine and scene, with the traces attached, captured as the Performance report issue form describes. --> Windows x86-64, WinLibs GCC 15.2.0, Release, `BUILD_TESTING=ON`, main `f2d874c1fdccf781c0fa5d86619bb5dd8894b958`. Exact tested head: `906bf667bc94bf797b73579c08203610a9b5ba46`. - Built libc, libkernel, their patched production files and `guest_timespec_getres_tests`. - Five selected CTests pass without skips: `public_headers` and all four `guest_timespec_getres_{unsupported,forwarding,errors,integration}` cases. They cover unsupported bases with inaccessible output, forwarded pointer/clock ID, signed provider errors and errno, null output, surrounding sentinels and extreme 64-bit fields, and calls through the actually loaded kernel. - 1,572,984 differential vectors against the original wrapper, with its clock import explicitly replaced by a controlled callee: zero differences in return values, output, call selection and errno; independent expected outputs also agree. This checks the wrapper contract, not console clock precision. Original module initializers are not run. - Following review, removed the missing-provider exception test and its CTest registration. Production code and the missing-provider guard are unchanged. Rebuilt the test and patched production libraries and repeated the selected tests and differential comparison at the head above. - Conventions and committed diff whitespace checks pass. - Initial pre-publication official overlap scan: 1,823 open PRs, no confirmed overlap or duplicate implementation. It retains exit 2 for 35 branches already conflicting with main. Their added library/test/shared-file diffs were checked against all merge bases for this function and NID, without matches; no claim that those branches merge cleanly. Not tested: Linux, macOS, another SDK, a game, GPU or console. No speed or game compatibility claim. No original binary or extracted bytes, notes or logs are committed. ### 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
CnRJay commented 2026-11-01 19:48:51 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by CnRJay on 2026-11-01T19:48:51Z.

Review: COMMENTED


Withdrawn. This review applied a title-ID/log requirement that is not in CONTRIBUTING (Unblocks: none is allowed), and it contained no code review.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5729920369 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/14620#pullrequestreview-5729920369). Originally posted by [CnRJay](https://github.com/CnRJay) on 2026-11-01T19:48:51Z. **Review:** COMMENTED --- Withdrawn. This review applied a title-ID/log requirement that is not in CONTRIBUTING (`Unblocks: none` is allowed), and it contained no code review.
MarcZX10 commented 2026-11-02 04:55:34 +00:00 (Migrated from github.com)

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

Review: COMMENTED


Reviewed — no blocking findings

timespec_getres follows the bundled wrapper as its debt entry describes: base 1 forwards to sceKernelClockGetres with clock 0, and the result is 1 exactly when that call returns 0; any other base returns 0. The NID is ZvRHHCfA4HA, which matches the repo's NID tool. The four guest test modes (unsupported, forwarding, errors, integration) all passed in the hosted Windows CTest run. The console behaviour is not measured, as the debt entry says.

What I ran

  • Head 906bf667bc94bf797b73579c08203610a9b5ba46; base f2d874c1fdccf781c0fa5d86619bb5dd8894b958. 7 files, +174/-0: libc/src/Time.cpp (the function and registration), libc/include/Api.hpp and General.hpp (declarations), libkernel/Time/Time.cpp (the registration at static initialisation), libc/CMakeLists.txt (four test modes), the new tests/GuestTimespecGetres.cpp, and docs/dev/debt/libc.md.
  • Read the full production diff. The registered pointer is an atomic that is constant-initialised to null, and the function raises NotImplemented_nid_no_patch when nothing is registered.
  • NID: tools/nid_names.py compute_nid('timespec_getres') returns ZvRHHCfA4HA, the NID in the debt entry.
  • Read the test's main and the modes' assertions (lines 52-121 at head).
  • Read-only checks from the trusted main checkout (precheck not run: no PR-head code is run here): diff check, conventions and the stack check passed. The ABI audit reported passed_with_warnings with three findings (definition-not-found and nid-alias-differs-from-symbol-hash), none about timespec.
  • Hosted: the windows CTest run passed 2598 of 2598 cases, including guest_timespec_getres_unsupported, _forwarding, _errors and _integration (all Passed).
  • No MarcZX10 review at this head.

Results

Check Result Note
Diff check passed
Conventions and PR template passed conventions check from the main checkout
Mergeability and dependencies passed depends on none; the stack check passed
Base 1 forwards to clock 0; result 1 on success passed read in libc/src/Time.cpp
Other bases return 0 passed read in libc/src/Time.cpp
NID ZvRHHCfA4HA passed computed with tools/nid_names.py
Unregistered forwarder passed raises NotImplemented_nid_no_patch; covered by the unsupported mode
Guest test modes (hosted) passed all four guest_timespec_getres_* cases passed
ABI audit (main-checkout tool) passed with warnings 3 findings, none about timespec
Console behaviour not verified the debt entry says the console clock behaviour is unverified
Build and runtime tests (Linux) not run the hosted Windows run covers the tests
Negative controls not run no local build
Hosted CI passed windows passed (2598/2598); linux and relinkers skipped
Read-only check output

Precheck was not run: no PR-head code is run here. ABI audit: passed_with_warnings (1448 symbols; 3 findings, none about timespec). Hosted: gh api repos/boykopovar/AnyPS5/commits/906bf667bc94bf797b73579c08203610a9b5ba46/check-runs.

Negative control

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

Findings

Blocking

None.

Non-blocking

None.

Sources

Not verified

  • The console's clock behaviour (as the debt entry says).
  • The bundled wrapper's behaviour was not repeated here; the debt entry cites a CPU-only execution of it.

To get this to a good state

  • Nothing to change.
<!-- greyfinch-sync:boykopovar/AnyPS5:review:5732238529 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/14620#pullrequestreview-5732238529). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-02T04:55:34Z. **Review:** COMMENTED --- # Reviewed — no blocking findings `timespec_getres` follows the bundled wrapper as its debt entry describes: base 1 forwards to `sceKernelClockGetres` with clock 0, and the result is 1 exactly when that call returns 0; any other base returns 0. The NID is `ZvRHHCfA4HA`, which matches the repo's NID tool. The four guest test modes (`unsupported`, `forwarding`, `errors`, `integration`) all passed in the hosted Windows CTest run. The console behaviour is not measured, as the debt entry says. ## What I ran - Head `906bf667bc94bf797b73579c08203610a9b5ba46`; base `f2d874c1fdccf781c0fa5d86619bb5dd8894b958`. 7 files, +174/-0: `libc/src/Time.cpp` (the function and registration), `libc/include/Api.hpp` and `General.hpp` (declarations), `libkernel/Time/Time.cpp` (the registration at static initialisation), `libc/CMakeLists.txt` (four test modes), the new `tests/GuestTimespecGetres.cpp`, and `docs/dev/debt/libc.md`. - Read the full production diff. The registered pointer is an atomic that is constant-initialised to null, and the function raises `NotImplemented_nid_no_patch` when nothing is registered. - NID: `tools/nid_names.py` `compute_nid('timespec_getres')` returns `ZvRHHCfA4HA`, the NID in the debt entry. - Read the test's `main` and the modes' assertions (lines 52-121 at head). - Read-only checks from the trusted main checkout (precheck not run: no PR-head code is run here): diff check, conventions and the stack check passed. The ABI audit reported `passed_with_warnings` with three findings (`definition-not-found` and `nid-alias-differs-from-symbol-hash`), none about `timespec`. - Hosted: the windows CTest run passed 2598 of 2598 cases, including `guest_timespec_getres_unsupported`, `_forwarding`, `_errors` and `_integration` (all Passed). - No MarcZX10 review at this head. ## Results | Check | Result | Note | | --- | --- | --- | | Diff check | passed | | | Conventions and PR template | passed | conventions check from the main checkout | | Mergeability and dependencies | passed | depends on none; the stack check passed | | Base 1 forwards to clock 0; result 1 on success | passed | read in `libc/src/Time.cpp` | | Other bases return 0 | passed | read in `libc/src/Time.cpp` | | NID `ZvRHHCfA4HA` | passed | computed with `tools/nid_names.py` | | Unregistered forwarder | passed | raises `NotImplemented_nid_no_patch`; covered by the `unsupported` mode | | Guest test modes (hosted) | passed | all four `guest_timespec_getres_*` cases passed | | ABI audit (main-checkout tool) | passed with warnings | 3 findings, none about `timespec` | | Console behaviour | not verified | the debt entry says the console clock behaviour is unverified | | Build and runtime tests (Linux) | not run | the hosted Windows run covers the tests | | Negative controls | not run | no local build | | Hosted CI | passed | windows passed (2598/2598); linux and relinkers skipped | <details><summary>Read-only check output</summary> Precheck was not run: no PR-head code is run here. ABI audit: `passed_with_warnings` (1448 symbols; 3 findings, none about `timespec`). Hosted: `gh api repos/boykopovar/AnyPS5/commits/906bf667bc94bf797b73579c08203610a9b5ba46/check-runs`. </details> ## Negative control Not run here. A negative control needs a build, and code from this head is not run here. ## Findings **Blocking** None. **Non-blocking** None. ## Sources - Function and forwarder: https://github.com/boykopovar/AnyPS5/blob/906bf667bc94bf797b73579c08203610a9b5ba46/core/libs/prx/libc/src/Time.cpp - Registration: https://github.com/boykopovar/AnyPS5/blob/906bf667bc94bf797b73579c08203610a9b5ba46/core/libs/prx/libkernel/Time/Time.cpp - Debt entry: https://github.com/boykopovar/AnyPS5/blob/906bf667bc94bf797b73579c08203610a9b5ba46/docs/dev/debt/libc.md ## Not verified - The console's clock behaviour (as the debt entry says). - The bundled wrapper's behaviour was not repeated here; the debt entry cites a CPU-only execution of it. ## To get this to a good state - Nothing to change.
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!14620
No description provided.