feat(libc): implement C11 timespec_get (PPSA34015) #6084

Merged
notaxeltv merged 4 commits from upstream-pr/6084 into main 2026-11-09 12:33:50 +00:00
notaxeltv commented 2026-10-14 21:29:53 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by notaxeltv on 2026-10-14T21:29:53Z.


What

tools/import_audit.py on PPSA34015 lists absent libc.prx import yrx+40YKqiI (timespec_get). Implements C11 timespec_get for TIME_UTC using 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_get passes. tools/check_conventions.py --base upstream/main passes.

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 (none)
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Unblocks: PPSA34015 (absent libc import)
  • GPUs tested: n/a
  • AI-assisted: yes

Made with Cursor

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4864803465 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6084). Originally posted by [notaxeltv](https://github.com/notaxeltv) on 2026-10-14T21:29:53Z. --- ### What `tools/import_audit.py` on PPSA34015 lists absent `libc.prx` import `yrx+40YKqiI` (`timespec_get`). Implements C11 `timespec_get` for `TIME_UTC` using 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_get` passes. `tools/check_conventions.py --base upstream/main` passes. ### Checklist - [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 - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's technical 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 (none) - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] Unblocks: PPSA34015 (absent libc import) - [x] GPUs tested: n/a - [x] AI-assisted: yes Made with [Cursor](https://cursor.com)
isnisk commented 2026-10-16 00:13:58 +00:00 (Migrated from github.com)

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 onto main 489466d3f (clean merge).

  • With the change: guest_timespec_get and guest_time_conversion pass, 3 rounds; no compiler warnings.
  • Without it (main's Time.cpp): the test does not link (undefined reference to timespec_get_nid_postfix).
  • check_conventions.py --base origin/main passes.

Not checked: macOS, the title.

AI-assisted: yes (Claude Code).

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6205013201 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6084#issuecomment-6205013201). Originally posted by [isnisk](https://github.com/isnisk) on 2026-10-16T00:13:58Z. --- Checked on Linux: Ubuntu 26.04 (WSL2), GCC 15.2.0, Release, this head (`35bf02274`) merged onto `main` `489466d3f` (clean merge). - With the change: `guest_timespec_get` and `guest_time_conversion` pass, 3 rounds; no compiler warnings. - Without it (`main`'s `Time.cpp`): the test does not link (`undefined reference to timespec_get_nid_postfix`). - `check_conventions.py --base origin/main` passes. Not checked: macOS, the title. AI-assisted: yes (Claude Code).
adriadam10 commented 2026-10-16 22:41:22 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-16T22:41:22Z.


Checked build and the scoped ctest on Linux (guest_timespec_get passes; without the change the test fails to link), return values for null pointer and unsupported base, and no overlap with open PRs on timespec_get; merging once the full Build is green.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6226055960 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6084#issuecomment-6226055960). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-16T22:41:22Z. --- Checked build and the scoped ctest on Linux (`guest_timespec_get` passes; without the change the test fails to link), return values for null pointer and unsupported base, and no overlap with open PRs on `timespec_get`; merging once the full Build is green.
oneandonlydean commented 2026-10-18 15:22:47 +00:00 (Migrated from github.com)

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_get writes through the host timespec, but the guest's timespec is two 64-bit fields (main declares it as KernelTimespec { 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 host tv_nsec is a 32-bit long, 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 host timespec.

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?

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6251627490 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6084#issuecomment-6251627490). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-18T15:22:47Z. --- Thanks for this. One layout problem before it can merge: `timespec_get` writes through the host `timespec`, but the guest's `timespec` is two 64-bit fields (main declares it as `KernelTimespec { 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 host `tv_nsec` is a 32-bit `long`, 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 host `timespec`. 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?
xXPBSXx commented 2026-10-20 20:06:13 +00:00 (Migrated from github.com)

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 commit c9ef5a2134 on top, branch xXPBSXx:fix/timespec-get-guest-layout:

  • The follow-up takes KernelTimespec* (two 64-bit fields) and writes both. The test declares the guest layout and pre-fills it with -1.
  • With the follow-up: guest_timespec_get passes 3 of 3 runs; guest_time_conversion and guest_mktime pass.
  • Without it (this head's Time.cpp, new test): guest_timespec_get fails 3 of 3 (0xc0000409): the host tv_nsec is 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 current main: clean. Not tested: Linux/macOS, and no title run.

AI-assisted (Claude Code).

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6300338060 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6084#issuecomment-6300338060). Originally posted by [xXPBSXx](https://github.com/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 commit `c9ef5a2134` on top, branch `xXPBSXx:fix/timespec-get-guest-layout`: - The follow-up takes `KernelTimespec*` (two 64-bit fields) and writes both. The test declares the guest layout and pre-fills it with -1. - With the follow-up: `guest_timespec_get` passes 3 of 3 runs; `guest_time_conversion` and `guest_mktime` pass. - Without it (this head's `Time.cpp`, new test): `guest_timespec_get` fails 3 of 3 (`0xc0000409`): the host `tv_nsec` is 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 current `main`: clean. Not tested: Linux/macOS, and no title run. AI-assisted (Claude Code).
oneandonlydean commented 2026-10-20 20:23:09 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-20T20:23:09Z.


@notaxeltv thanks for this. @xXPBSXx's follow-up c9ef5a2134 (branch xXPBSXx:fix/timespec-get-guest-layout) fixes the guest layout point from the review: timespec_get now writes the guest's two 64-bit fields instead of the host timespec, whose tv_nsec is 32 bits on MinGW. With it, guest_timespec_get passes 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_get passing on Linux and Windows.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6300664660 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6084#issuecomment-6300664660). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-20T20:23:09Z. --- @notaxeltv thanks for this. @xXPBSXx's follow-up `c9ef5a2134` (branch `xXPBSXx:fix/timespec-get-guest-layout`) fixes the guest layout point from the review: `timespec_get` now writes the guest's two 64-bit fields instead of the host `timespec`, whose `tv_nsec` is 32 bits on MinGW. With it, `guest_timespec_get` passes 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_get` passing on Linux and Windows.
THEMANnt commented 2026-10-26 13:51:32 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by THEMANnt on 2026-10-26T13:51:32Z.

Review: APPROVED


Reviewed 35bf022741ee against 4808d9c20321. Recommend approval for the focused Windows implementation and API behavior.

Null pointers and unsupported bases return zero before writing. The supported TIME_UTC path 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_get passes. 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 _WIN32 under MinGW failed in host headers and is not a valid POSIX test or a PR defect. Hosted libc product jobs were skipped.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5653018002 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6084#pullrequestreview-5653018002). Originally posted by [THEMANnt](https://github.com/THEMANnt) on 2026-10-26T13:51:32Z. **Review:** APPROVED --- Reviewed `35bf022741ee` against `4808d9c20321`. Recommend approval for the focused Windows implementation and API behavior. Null pointers and unsupported bases return zero before writing. The supported `TIME_UTC` path 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_get` passes. 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 `_WIN32` under MinGW failed in host headers and is not a valid POSIX test or a PR defect. Hosted libc product jobs were skipped.
XairRrR commented 2026-11-02 22:00:02 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by XairRrR on 2026-11-02T22:00:02Z.

Review: APPROVED


Reviewed — approved

timespec_get is 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 6951e39255a218dfa66dfb86eea22bdc340bc890 merged into main 9090972b7e91fd266819cbd77a8b058e177b5682 with --no-ff (merged tree b638125b4891752ff2d87580d030f51be0cc5952). The machine was Debian 13 (VM, 32 vCPU Xeon Gold 6136) with GCC 14.2.0, a Release build with Ninja and BUILD_TESTING=ON.

git diff --check 9090972b7e91fd266819cbd77a8b058e177b5682...6951e39255a218dfa66dfb86eea22bdc340bc890
python3 tools/check_conventions.py --base 9090972b7e91fd266819cbd77a8b058e177b5682
ctest --test-dir build -j8 --test-load 32 --output-on-failure -R "^(guest_timespec_get|guest_time_conversion|guest_mktime|public_headers)$" --repeat until-fail:3
# negative control 1: Time.cpp and Api.hpp from main
git show 9090972b7e91fd266819cbd77a8b058e177b5682:core/libs/prx/libc/src/Time.cpp > core/libs/prx/libc/src/Time.cpp
git show 9090972b7e91fd266819cbd77a8b058e177b5682:core/libs/prx/libc/include/Api.hpp > core/libs/prx/libc/include/Api.hpp
ninja -C build -j32 -l32 guest_timespec_get_tests
# negative control 2: merged files, with the POSIX branch writing only the low 32 bits of tv_nsec
ninja -C build -j32 -l32 guest_timespec_get_tests libc
ctest --test-dir build -R "^guest_timespec_get$"
# restore the merged files
git show b638125b4891752ff2d87580d030f51be0cc5952:<path> > <path>
ninja -C build -j32 -l32 guest_timespec_get_tests libc
ctest --test-dir build -R "^guest_timespec_get$"
git status --porcelain

Results

Check Result
git diff --check clean
check_conventions.py All conventions checks passed.
Configure, build, libs (script) OK
Script test run no new failures and no timeouts; the 9 known failures also fail on main
guest_timespec_get passed 3/3 (about 0.01 s each)
guest_time_conversion, guest_mktime passed 3/3
public_headers (exactly one declaration per export) passed 3/3
Vulkan validation not applicable: no AGC, shader or VideoOut files changed

public_headers takes about 60 s on this machine. This happens on existing main code and has nothing to do with this PR.

Negative control

  • Time.cpp and Api.hpp from main: the test does not compile ('timespec_get_nid_postfix' was not declared in this scope).
  • Merged files, but the POSIX branch writes only the low 32 bits of tv_nsec: this reproduces the MinGW layout bug that oneandonlydean reported. guest_timespec_get fails (Subprocess aborted), so the {-1, -1} pre-fill catches a partial write as intended.
  • Cleanup: I restored the merged files and rebuilt. The test passes again, and git status --porcelain is empty.

Findings

Blocking

None.

Non-blocking

  • The description still lacks the template's Fixes: line. fogydes (10-30) and oneandonlydean (11-01) already asked for it, and I confirm it is still missing. CONTRIBUTING requires none when no issue is fixed. Fix: add - [x] Fixes: none to the checklist.
  • The time source is the host clock, not the libkernel clock. B-Howell already noted this: the console's libc forwards timespec_get to sceKernelClockGettime(0, ts). I agree it is not a blocker. The implementation (Time.cpp L469-L483 at head, core/libs/prx/libc/src/Time.cpp:535 in the merged tree) uses the same source as the existing _Xtime_get_ticks and time. 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

  • Windows/MinGW: I could only run Linux here. My 32-bit mutation exercised the same failure mode on Linux, and others report Windows runs in the discussion.
  • macOS, and running the title PPSA34015.
<!-- greyfinch-sync:boykopovar/AnyPS5:review:5743999666 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6084#pullrequestreview-5743999666). Originally posted by [XairRrR](https://github.com/XairRrR) on 2026-11-02T22:00:02Z. **Review:** APPROVED --- # Reviewed — approved `timespec_get` is 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 `6951e39255a218dfa66dfb86eea22bdc340bc890` merged into `main` `9090972b7e91fd266819cbd77a8b058e177b5682` with `--no-ff` (merged tree `b638125b4891752ff2d87580d030f51be0cc5952`). The machine was Debian 13 (VM, 32 vCPU Xeon Gold 6136) with GCC 14.2.0, a Release build with Ninja and `BUILD_TESTING=ON`. ``` git diff --check 9090972b7e91fd266819cbd77a8b058e177b5682...6951e39255a218dfa66dfb86eea22bdc340bc890 python3 tools/check_conventions.py --base 9090972b7e91fd266819cbd77a8b058e177b5682 ctest --test-dir build -j8 --test-load 32 --output-on-failure -R "^(guest_timespec_get|guest_time_conversion|guest_mktime|public_headers)$" --repeat until-fail:3 # negative control 1: Time.cpp and Api.hpp from main git show 9090972b7e91fd266819cbd77a8b058e177b5682:core/libs/prx/libc/src/Time.cpp > core/libs/prx/libc/src/Time.cpp git show 9090972b7e91fd266819cbd77a8b058e177b5682:core/libs/prx/libc/include/Api.hpp > core/libs/prx/libc/include/Api.hpp ninja -C build -j32 -l32 guest_timespec_get_tests # negative control 2: merged files, with the POSIX branch writing only the low 32 bits of tv_nsec ninja -C build -j32 -l32 guest_timespec_get_tests libc ctest --test-dir build -R "^guest_timespec_get$" # restore the merged files git show b638125b4891752ff2d87580d030f51be0cc5952:<path> > <path> ninja -C build -j32 -l32 guest_timespec_get_tests libc ctest --test-dir build -R "^guest_timespec_get$" git status --porcelain ``` ## Results | Check | Result | |---|---| | `git diff --check` | clean | | `check_conventions.py` | `All conventions checks passed.` | | Configure, build, `libs` (script) | OK | | Script test run | no new failures and no timeouts; the 9 known failures also fail on `main` | | `guest_timespec_get` | passed 3/3 (about 0.01 s each) | | `guest_time_conversion`, `guest_mktime` | passed 3/3 | | `public_headers` (exactly one declaration per export) | passed 3/3 | | Vulkan validation | not applicable: no AGC, shader or VideoOut files changed | `public_headers` takes about 60 s on this machine. This happens on existing `main` code and has nothing to do with this PR. ## Negative control - **`Time.cpp` and `Api.hpp` from `main`:** the test does not compile (`'timespec_get_nid_postfix' was not declared in this scope`). - **Merged files, but the POSIX branch writes only the low 32 bits of `tv_nsec`:** this reproduces the MinGW layout bug that oneandonlydean reported. `guest_timespec_get` fails (`Subprocess aborted`), so the `{-1, -1}` pre-fill catches a partial write as intended. - **Cleanup:** I restored the merged files and rebuilt. The test passes again, and `git status --porcelain` is empty. ## Findings ### Blocking None. ### Non-blocking - **The description still lacks the template's `Fixes:` line.** fogydes (10-30) and oneandonlydean (11-01) already asked for it, and I confirm it is still missing. CONTRIBUTING requires `none` when no issue is fixed. Fix: add `- [x] Fixes: none` to the checklist. - **The time source is the host clock, not the libkernel clock.** B-Howell already noted this: the console's libc forwards `timespec_get` to `sceKernelClockGettime(0, ts)`. I agree it is not a blocker. The implementation ([Time.cpp L469-L483 at head](https://github.com/boykopovar/AnyPS5/blob/6951e39255a218dfa66dfb86eea22bdc340bc890/core/libs/prx/libc/src/Time.cpp#L469-L483), `core/libs/prx/libc/src/Time.cpp:535` in the merged tree) uses the same source as the existing `_Xtime_get_ticks` and `time`. 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 - Windows/MinGW: I could only run Linux here. My 32-bit mutation exercised the same failure mode on Linux, and others report Windows runs in the discussion. - macOS, and running the title PPSA34015. <!-- anyps5-bots job=2545 head=6951e39255a218dfa66dfb86eea22bdc340bc890 -->
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!6084
No description provided.