feat(libc): export the std::__sce_v2 _Timespec64_get_sys and _Timespec64_diff_to_ts clock helpers #15834
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/15834"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by Danigamer05 on 2026-11-04T18:34:08Z.
What
Export the versioned
std::__sce_v2_Timespec64_get_sysand_Timespec64_diff_to_tsfrom libc._ZNSt8__sce_v219_Timespec64_get_sysEP8timespec0+cFCv7GzGk0xC99E0_ZNSt8__sce_v222_Timespec64_diff_to_tsEPK8timespecTdRnoqlXhOA0xC9B80The behavior comes from the
libc.prxbundled with PPSA03671 v01.001.005 (J03848509, SHA-256483961e086b8a1fffa8138b3c0badf798987fb5f35ec908d828946408be2d8a6).Both read the current time in microseconds, as the module does with
sceKernelGettimeofday, and split it into seconds and nanoseconds:_Timespec64_get_sysstores that time through the pointer, with the nanoseconds a multiple of 1,000;_Timespec64_diff_to_tsreturns 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 ofINT64_MINseconds gives a huge positive time, not zero.They sit in
Threads.cppbeside the existing_Timespec64_diff_to_usecondsand 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, main9ab6a281ea6. Exact tested commit:3846c96f10a.Built libc, libkernel, their NID-patched production libraries and the related tests. The new
guest_sce_v2_timespec64passes, along withguest_libc_shared_mutex,guest_time_extrasandpublic_headers.The new test checks that
_Timespec64_get_syshas microsecond resolution, does not go back and matches_Xtime_get_ticks. For_Timespec64_diff_to_tsit 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 theINT64_MINwraparound, 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_tscalls, 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, anderrnonever 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:
_Timespec64_get_sysstored hundreds instead of thousands of nanoseconds per microsecond;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 --checkpass.tools/pr_overlap.pyread 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 usinggit merge-treegives 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
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)🤖 Generated with Claude Code