feat(libc): export the std::__sce_v2 _Timespec64_get_sys and _Timespec64_diff_to_ts clock helpers #15834

Merged
Danigamer05 merged 1 commit from upstream-pr/15834 into main 2026-11-08 03:45:59 +00:00
Danigamer05 commented 2026-11-04 18:34:08 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Danigamer05 on 2026-11-04T18:34:08Z.


What

Export the versioned std::__sce_v2 _Timespec64_get_sys and _Timespec64_diff_to_ts from libc.

Export NID Original RVA
_ZNSt8__sce_v219_Timespec64_get_sysEP8timespec 0+cFCv7GzGk 0xC99E0
_ZNSt8__sce_v222_Timespec64_diff_to_tsEPK8timespec TdRnoqlXhOA 0xC9B80

The behavior comes from the libc.prx bundled with PPSA03671 v01.001.005 (J03848509, SHA-256 483961e086b8a1fffa8138b3c0badf798987fb5f35ec908d828946408be2d8a6).

Both read the current time in microseconds, as the module does with sceKernelGettimeofday, and split it into seconds and nanoseconds:

  • _Timespec64_get_sys stores that time through the pointer, with the nanoseconds a multiple of 1,000;
  • _Timespec64_diff_to_ts returns the time left until the target, in two registers. As in the module, it first normalizes the target's nanoseconds into [0, 10^9) with the module's closed-form division, then subtracts the current time with a borrow, and returns zero when the seconds are negative, or zero with non-positive nanoseconds. Out-of-range fields wrap on 64 bits as in the module: a target of INT64_MIN seconds gives a huge positive time, not zero.

They sit in Threads.cpp beside the existing _Timespec64_diff_to_useconds and read the time through the same _Xtime_get_ticks. The debt entry records that, and that a null argument throws where the console faults.

Tested

Windows x86-64, WinLibs GCC 15.2.0, Release, BUILD_TESTING=ON, main 9ab6a281ea6. Exact tested commit: 3846c96f10a.

  • Built libc, libkernel, their NID-patched production libraries and the related tests. The new guest_sce_v2_timespec64 passes, along with guest_libc_shared_mutex, guest_time_extras and public_headers.

  • The new test checks that _Timespec64_get_sys has microsecond resolution, does not go back and matches _Xtime_get_ticks. For _Timespec64_diff_to_ts it checks 13 future targets, set from the current second with nanoseconds from -5 to +7 seconds, against their normalized value, and 6 past targets that must give zero. It also checks the INT64_MIN wraparound, that the target is not changed and that null arguments throw. The normalized values and the zero and wraparound cases were first checked against the original module.

  • The original functions were loaded from the bundled module with their relocations applied. Their imports were bound by NID to this branch's libc and libkernel, so the module read the time through this branch's sceKernelGettimeofday.

  • The result depends on the clock, so each call was placed between two calls to the original: the result must lie between the module's two results. When both module calls returned the same value, which happened in about two thirds of the _Timespec64_diff_to_ts calls, the result had to be identical. Over 5,000,000 calls per function and two seeds, no result fell outside, none of the equal pairs differed, and errno never changed. The targets mixed edge values, random 64-bit fields and times within seconds, microseconds and days of now.

  • Negative control: five lines were altered one at a time:

    • negative nanoseconds were normalized one second short;
    • the borrow from the current second was dropped;
    • a negative remaining time was no longer clamped to zero;
    • _Timespec64_get_sys stored hundreds instead of thousands of nanoseconds per microsecond;
    • the positive normalization no longer carried its last second.

    The new CTest failed on each, and the side-by-side run put results outside the module's bracket each time. A sixth alteration, a threshold one nanosecond off in the positive normalization, turned out to be equivalent, since subtracting the current nanoseconds brings the result back into range, and it was replaced by the fifth. The source was then restored byte for byte (SHA-256 checked) and rebuilt, and the test and side-by-side run passed again.

  • Code conventions and git diff --check pass.

  • tools/pr_overlap.py read 1,862 open PRs at the tested commit and reports no overlap. It keeps exit 2 for 53 branches that already conflict with main. None of them adds a line naming these exports. Merging each of the 53 with this branch and with main using git merge-tree gives the same conflict blocks. The branch also merges cleanly with #15336, #15471, #15484, #15490, #15501, #15519, #15552, #15561, #15602, #15614, #15667, #15683, #15791, #15796 and #15809.

Not tested: Linux, macOS, another SDK, a game, GPU or console. No game compatibility claim. No original module, extracted bytes, harness or log is committed or uploaded.

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

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5159553221 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/15834). Originally posted by [Danigamer05](https://github.com/Danigamer05) on 2026-11-04T18:34:08Z. --- ### What Export the versioned `std::__sce_v2` `_Timespec64_get_sys` and `_Timespec64_diff_to_ts` from libc. | Export | NID | Original RVA | | --- | --- | --- | | `_ZNSt8__sce_v219_Timespec64_get_sysEP8timespec` | `0+cFCv7GzGk` | `0xC99E0` | | `_ZNSt8__sce_v222_Timespec64_diff_to_tsEPK8timespec` | `TdRnoqlXhOA` | `0xC9B80` | The behavior comes from the `libc.prx` bundled with PPSA03671 v01.001.005 (J03848509, SHA-256 `483961e086b8a1fffa8138b3c0badf798987fb5f35ec908d828946408be2d8a6`). Both read the current time in microseconds, as the module does with `sceKernelGettimeofday`, and split it into seconds and nanoseconds: - `_Timespec64_get_sys` stores that time through the pointer, with the nanoseconds a multiple of 1,000; - `_Timespec64_diff_to_ts` returns the time left until the target, in two registers. As in the module, it first normalizes the target's nanoseconds into [0, 10^9) with the module's closed-form division, then subtracts the current time with a borrow, and returns zero when the seconds are negative, or zero with non-positive nanoseconds. Out-of-range fields wrap on 64 bits as in the module: a target of `INT64_MIN` seconds gives a huge positive time, not zero. They sit in `Threads.cpp` beside the existing `_Timespec64_diff_to_useconds` and read the time through the same `_Xtime_get_ticks`. The debt entry records that, and that a null argument throws where the console faults. ### 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 `9ab6a281ea6`. Exact tested commit: `3846c96f10a`. - Built libc, libkernel, their NID-patched production libraries and the related tests. The new `guest_sce_v2_timespec64` passes, along with `guest_libc_shared_mutex`, `guest_time_extras` and `public_headers`. - The new test checks that `_Timespec64_get_sys` has microsecond resolution, does not go back and matches `_Xtime_get_ticks`. For `_Timespec64_diff_to_ts` it checks 13 future targets, set from the current second with nanoseconds from -5 to +7 seconds, against their normalized value, and 6 past targets that must give zero. It also checks the `INT64_MIN` wraparound, that the target is not changed and that null arguments throw. The normalized values and the zero and wraparound cases were first checked against the original module. - The original functions were loaded from the bundled module with their relocations applied. Their imports were bound by NID to this branch's libc and libkernel, so the module read the time through this branch's `sceKernelGettimeofday`. - The result depends on the clock, so each call was placed between two calls to the original: the result must lie between the module's two results. When both module calls returned the same value, which happened in about two thirds of the `_Timespec64_diff_to_ts` calls, the result had to be identical. Over 5,000,000 calls per function and two seeds, no result fell outside, none of the equal pairs differed, and `errno` never changed. The targets mixed edge values, random 64-bit fields and times within seconds, microseconds and days of now. - Negative control: five lines were altered one at a time: - negative nanoseconds were normalized one second short; - the borrow from the current second was dropped; - a negative remaining time was no longer clamped to zero; - `_Timespec64_get_sys` stored hundreds instead of thousands of nanoseconds per microsecond; - the positive normalization no longer carried its last second. The new CTest failed on each, and the side-by-side run put results outside the module's bracket each time. A sixth alteration, a threshold one nanosecond off in the positive normalization, turned out to be equivalent, since subtracting the current nanoseconds brings the result back into range, and it was replaced by the fifth. The source was then restored byte for byte (SHA-256 checked) and rebuilt, and the test and side-by-side run passed again. - Code conventions and `git diff --check` pass. - `tools/pr_overlap.py` read 1,862 open PRs at the tested commit and reports no overlap. It keeps exit 2 for 53 branches that already conflict with main. None of them adds a line naming these exports. Merging each of the 53 with this branch and with main using `git merge-tree` gives the same conflict blocks. The branch also merges cleanly with #15336, #15471, #15484, #15490, #15501, #15519, #15552, #15561, #15602, #15614, #15667, #15683, #15791, #15796 and #15809. Not tested: Linux, macOS, another SDK, a game, GPU or console. No game compatibility claim. No original module, extracted bytes, harness or log is committed or uploaded. ### 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 🤖 Generated with [Claude Code](https://claude.com/claude-code)
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!15834
No description provided.