feat(libc): implement C11 timespec_get (PPSA34015) #6084
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/6084"
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 notaxeltv on 2026-10-14T21:29:53Z.
What
tools/import_audit.pyon PPSA34015 lists absentlibc.prximportyrx+40YKqiI(timespec_get). Implements C11timespec_getforTIME_UTCusing the same realtime source as_Xtime_get_ticks(Windows precise FILETIME /clock_gettime(CLOCK_REALTIME)). Returns 0 for null or unsupported base.Tested
Windows 10, WinLibs GCC 15.2.0,
guest_timespec_getpasses.tools/check_conventions.py --base upstream/mainpasses.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)Made with Cursor
Imported from boykopovar/AnyPS5. Originally posted by isnisk on 2026-10-16T00:13:58Z.
Checked on Linux: Ubuntu 26.04 (WSL2), GCC 15.2.0, Release, this head (
35bf02274) merged ontomain489466d3f(clean merge).guest_timespec_getandguest_time_conversionpass, 3 rounds; no compiler warnings.main'sTime.cpp): the test does not link (undefined reference to timespec_get_nid_postfix).check_conventions.py --base origin/mainpasses.Not checked: macOS, the title.
AI-assisted: yes (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-16T22:41:22Z.
Checked build and the scoped ctest on Linux (
guest_timespec_getpasses; without the change the test fails to link), return values for null pointer and unsupported base, and no overlap with open PRs ontimespec_get; merging once the full Build is green.Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-18T15:22:47Z.
Thanks for this. One layout problem before it can merge:
timespec_getwrites through the hosttimespec, but the guest'stimespecis two 64-bit fields (main declares it asKernelTimespec { int64 tv_sec; int64 tv_nsec; }in SceTypes.hpp, and libkernel asserts its guest timespec at 16 bytes with nanoseconds at offset 8). On Windows/MinGW the hosttv_nsecis a 32-bitlong, so only the low 4 bytes of the guest's nanoseconds get written and the upper 4 keep whatever was on the guest stack. Linux is unaffected (LP64). The test can't see this because it zero-initializes a hosttimespec.Could you take
KernelTimespec*(or an equivalent 16-byte guest struct) and write both 64-bit fields, and in the test declare the guest layout and pre-fill it with a non-zero pattern so a 32-bit write would fail?Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-20T20:06:13Z.
Windows check of the layout point above, plus a follow-up based on this PR's head (the author has not touched it since 14.10., so this is offered in case it helps; happy to drop it if the author updates).
Windows 10 19045, WinLibs GCC 15.2.0, Release,
BUILD_TESTING=ON, this head (35bf02274) with the follow-up commitc9ef5a2134on top, branchxXPBSXx:fix/timespec-get-guest-layout:KernelTimespec*(two 64-bit fields) and writes both. The test declares the guest layout and pre-fills it with -1.guest_timespec_getpasses 3 of 3 runs;guest_time_conversionandguest_mktimepass.Time.cpp, new test):guest_timespec_getfails 3 of 3 (0xc0000409): the hosttv_nsecis 32 bits on MinGW, so the upper half of the guest nanoseconds keeps the pre-fill. That matches the review point.tools/check_conventions.py,pr_overlap, merge-tree against currentmain: clean. Not tested: Linux/macOS, and no title run.AI-assisted (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-20T20:23:09Z.
@notaxeltv thanks for this. @xXPBSXx's follow-up
c9ef5a2134(branchxXPBSXx:fix/timespec-get-guest-layout) fixes the guest layout point from the review:timespec_getnow writes the guest's two 64-bit fields instead of the hosttimespec, whosetv_nsecis 32 bits on MinGW. With it,guest_timespec_getpasses on Windows; without it, the test fails 3 of 3.Could you take that commit into this PR (cherry-pick it with its authorship, or apply the same change)? If we don't hear back in about 24 hours, we'll carry the change on in a new PR that keeps both your commits and @xXPBSXx's, with credit to both of you. The merge bar after that is full CI with
guest_timespec_getpassing on Linux and Windows.Imported from boykopovar/AnyPS5. Originally posted by THEMANnt on 2026-10-26T13:51:32Z.
Review: APPROVED
Reviewed
35bf022741eeagainst4808d9c20321. Recommend approval for the focused Windows implementation and API behavior.Null pointers and unsupported bases return zero before writing. The supported
TIME_UTCpath converts the realtime clock into seconds and normalized nanoseconds; CMake registers the test with the project's Windows unwind and runtime-path setup.Validation: Built the candidate target with Windows GCC 15.3;
guest_timespec_getpasses. A separate caller linked against candidate libc passes invalid-base boundaries, null inputs, unchanged sentinel fields on rejected calls, and valid output-shape checks. Baseline libc builds; linking the new test against it fails for the missing export. That is an expected missing-symbol control, not proof of runtime correctness.Scope: The POSIX path was source-inspected but not executed. Undefining
_WIN32under MinGW failed in host headers and is not a valid POSIX test or a PR defect. Hosted libc product jobs were skipped.Imported from boykopovar/AnyPS5. Originally posted by XairRrR on 2026-11-02T22:00:02Z.
Review: APPROVED
Reviewed — approved
timespec_getis implemented correctly for the 16-byte guest timespec. The test passes on Linux and fails both when the export is missing and when the nanoseconds are written as only 32 bits.What I ran
Head
6951e39255a218dfa66dfb86eea22bdc340bc890merged intomain9090972b7e91fd266819cbd77a8b058e177b5682with--no-ff(merged treeb638125b4891752ff2d87580d030f51be0cc5952). The machine was Debian 13 (VM, 32 vCPU Xeon Gold 6136) with GCC 14.2.0, a Release build with Ninja andBUILD_TESTING=ON.Results
git diff --checkcheck_conventions.pyAll conventions checks passed.libs(script)mainguest_timespec_getguest_time_conversion,guest_mktimepublic_headers(exactly one declaration per export)public_headerstakes about 60 s on this machine. This happens on existingmaincode and has nothing to do with this PR.Negative control
Time.cppandApi.hppfrommain: the test does not compile ('timespec_get_nid_postfix' was not declared in this scope).tv_nsec: this reproduces the MinGW layout bug that oneandonlydean reported.guest_timespec_getfails (Subprocess aborted), so the{-1, -1}pre-fill catches a partial write as intended.git status --porcelainis empty.Findings
Blocking
None.
Non-blocking
Fixes:line. fogydes (10-30) and oneandonlydean (11-01) already asked for it, and I confirm it is still missing. CONTRIBUTING requiresnonewhen no issue is fixed. Fix: add- [x] Fixes: noneto the checklist.timespec_gettosceKernelClockGettime(0, ts). I agree it is not a blocker. The implementation (Time.cpp L469-L483 at head,core/libs/prx/libc/src/Time.cpp:535in the merged tree) uses the same source as the existing_Xtime_get_ticksandtime. The return values agree with the disassembly B-Howell posted: 0 for a null pointer or another base, 1 (TIME_UTC) on success, and nothing written on rejection.Not verified