feat(libc): implement C11 timespec_get for PPSA34015 #9388

Closed
xXPBSXx wants to merge 2 commits from upstream-pr/9388 into main
xXPBSXx commented 2026-10-21 20:11:56 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-21T20:11:56Z.


What

Carries #6084 (@notaxeltv) onto current main, as @oneandonlydean announced there on 20.10. (24 h without a reply from the author, keeping both commits and crediting both). #6084's commit implements C11 timespec_get for TIME_UTC (import yrx+40YKqiI of PPSA34015, listed by tools/import_audit.py) with the realtime source of _Xtime_get_ticks, returning 0 for a null pointer or an unsupported base. The second commit resolves the review point on #6084: it writes the guest's 16-byte timespec (two 64-bit fields, KernelTimespec), not the host timespec, whose tv_nsec is 32 bits on MinGW, and the test pre-fills a guest struct with a non-zero pattern so a 32-bit write fails. Based on the heads of #6084 and xXPBSXx:fix/timespec-get-guest-layout.

Tested

Windows 10 19045, WinLibs GCC 15.2.0 r7, Release, BUILD_TESTING=ON, on main ea241c01b3 with both commits merged (the rebased head only differs by its newer base):

  • ctest -R '^guest_timespec_get$' passes 3 of 3; guest_time_conversion and guest_mktime pass (3 of 3 together).
  • With libc/src/Time.cpp restored to main the test does not link (undefined reference to timespec_get_nid_postfix). On #6084's head alone the layout case fails 3 of 3 (0xc0000409), as @xXPBSXx posted there on 20.10.
  • python tools/check_conventions.py --base upstream/main passes; git merge-tree against main is clean.
  • Title run (reported by @klosixgaming-arch on this PR, not run by me): EA SPORTS FC 27 (PPSA34015, 01.000.004), Windows 11 (build 26200), RTX 5090, APS5_PLAYGO_UNLISTED_CHUNKS=absent, main 1a745ae38e plus #9439 (to record calls) plus this PR's head d9d01fa01, merged. The title reaches timespec_get and keeps running: libc.prx yrx+40YKqiI is called 19,588 times in a 2-minute run that ends only because it was stopped (no crash, no NotImplemented). That reporter did not run main without this PR past an unrelated keyboard abort, so what the missing import does there is not shown; and the run needed a local-only revert of sceConvertKeycodeGetImeKeyboardType (not part of this PR), because current main aborts that title 1.8 s in.
  • Not tested: Linux/macOS. Linux: #6084 has an independent Linux run by @isnisk on its own head (not repeated on this head).

Checklist

  • Based on current main; no other open PR implements the same functions (#6084 is the one this carries; it can be closed as superseded once this merges)
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw; silent stubs are listed in technical debt (none added)
  • No notes, investigation .md files or images added to the repository
  • New third-party code is a submodule built from source (none)
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Fixes: none
  • Unblocks: PPSA34015 (absent libc import timespec_get)
  • GPUs tested: n/a
  • AI-assisted: yes

AI-assisted (Claude Code).

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4957712361 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9388). Originally posted by [xXPBSXx](https://github.com/xXPBSXx) on 2026-10-21T20:11:56Z. --- ### What Carries #6084 (@notaxeltv) onto current `main`, as @oneandonlydean announced there on 20.10. (24 h without a reply from the author, keeping both commits and crediting both). #6084's commit implements C11 `timespec_get` for `TIME_UTC` (import `yrx+40YKqiI` of PPSA34015, listed by `tools/import_audit.py`) with the realtime source of `_Xtime_get_ticks`, returning 0 for a null pointer or an unsupported base. The second commit resolves the review point on #6084: it writes the guest's 16-byte `timespec` (two 64-bit fields, `KernelTimespec`), not the host `timespec`, whose `tv_nsec` is 32 bits on MinGW, and the test pre-fills a guest struct with a non-zero pattern so a 32-bit write fails. Based on the heads of #6084 and `xXPBSXx:fix/timespec-get-guest-layout`. ### Tested Windows 10 19045, WinLibs GCC 15.2.0 r7, Release, `BUILD_TESTING=ON`, on `main` ea241c01b3 with both commits merged (the rebased head only differs by its newer base): - `ctest -R '^guest_timespec_get$'` passes 3 of 3; `guest_time_conversion` and `guest_mktime` pass (3 of 3 together). - With `libc/src/Time.cpp` restored to `main` the test does not link (`undefined reference to timespec_get_nid_postfix`). On #6084's head alone the layout case fails 3 of 3 (`0xc0000409`), as @xXPBSXx posted there on 20.10. - `python tools/check_conventions.py --base upstream/main` passes; `git merge-tree` against `main` is clean. - Title run (reported by @klosixgaming-arch on this PR, not run by me): EA SPORTS FC 27 (PPSA34015, 01.000.004), Windows 11 (build 26200), RTX 5090, `APS5_PLAYGO_UNLISTED_CHUNKS=absent`, `main` `1a745ae38e` plus #9439 (to record calls) plus this PR's head `d9d01fa01`, merged. The title reaches `timespec_get` and keeps running: `libc.prx yrx+40YKqiI` is called 19,588 times in a 2-minute run that ends only because it was stopped (no crash, no `NotImplemented`). That reporter did not run `main` without this PR past an unrelated keyboard abort, so what the missing import does there is not shown; and the run needed a local-only revert of `sceConvertKeycodeGetImeKeyboardType` (not part of this PR), because current `main` aborts that title 1.8 s in. - Not tested: Linux/macOS. Linux: #6084 has an independent Linux run by @isnisk on its own head (not repeated on this head). ### Checklist - [x] Based on current `main`; no other open PR implements the same functions (#6084 is the one this carries; it can be closed as superseded once this merges) - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except technical debt - [x] Unimplemented paths throw; silent stubs are listed in technical debt (none added) - [x] No notes, investigation `.md` files or images added to the repository - [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] Fixes: none - [x] Unblocks: PPSA34015 (absent libc import `timespec_get`) - [x] GPUs tested: n/a - [x] AI-assisted: yes AI-assisted (Claude Code).
github-actions[bot] commented 2026-10-21 20:12:47 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-21T20:12:47Z.


Progress report (0c6a5bd → d9d01fa)

📈 System libraries: 42.11% (+0.01%, +1 implemented functions)

✅ 1 implemented
Library Name
libc timespec_get_nid_postfix
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6325528685 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9388#issuecomment-6325528685). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-21T20:12:47Z. --- <!-- progress-report --> ### Progress report (0c6a5bd → d9d01fa) 📈 **System libraries**: 42.11% (+0.01%, +1 implemented functions) <details> <summary>✅ 1 implemented</summary> | Library | Name | | - | - | | libc | `timespec_get_nid_postfix` | </details>
MarcZX10 commented 2026-10-21 22:44:01 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-21T22:44:01Z.

Code review location: core/libs/tests/GuestTimespecGet.cpp; line 26

@@ -0,0 +1,28 @@
+#include "prx/libc/include/general/VabiMacros.hpp"
+#include <cstdint>
+#include <ctime>
+#include <cstdlib>
+
+struct GuestTimespec {
+    std::int64_t tv_sec;
+    std::int64_t tv_nsec;
+};
+
+extern "C" int APS5_VABI timespec_get_nid_postfix(GuestTimespec* ts, int base);
+
+static void Require(bool value) { if (!value) std::abort(); }
+
+int main() {
+    Require(timespec_get_nid_postfix(nullptr, TIME_UTC) == 0);
+    GuestTimespec ts{};
+    Require(timespec_get_nid_postfix(&ts, 0) == 0);
+    GuestTimespec filled{-1, -1};
+    Require(timespec_get_nid_postfix(&filled, TIME_UTC) == TIME_UTC);
+    Require(filled.tv_sec > 0);
+    Require(filled.tv_nsec >= 0 && filled.tv_nsec < 1000000000LL);
+    GuestTimespec later{-1, -1};
+    Require(timespec_get_nid_postfix(&later, TIME_UTC) == TIME_UTC);
+    Require(later.tv_nsec >= 0 && later.tv_nsec < 1000000000LL);
+    Require(later.tv_sec > filled.tv_sec || (later.tv_sec == filled.tv_sec && later.tv_nsec >= filled.tv_nsec));

This second-read ordering check assumes UTC wall-clock time is monotonic. Both clock_gettime(CLOCK_REALTIME) and GetSystemTimePreciseAsFileTime can move backward after an administrator/NTP clock correction, so the test can fail even when timespec_get correctly returns UTC. Please avoid comparing two wall-clock reads, or bound the result against an independently sampled wall clock with an allowance that does not require monotonicity.

<!-- greyfinch-sync:boykopovar/AnyPS5:review-comment:4342730375 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9388#discussion_r4342730375). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-21T22:44:01Z. **Code review location:** `core/libs/tests/GuestTimespecGet.cpp`; line 26 ~~~~diff @@ -0,0 +1,28 @@ +#include "prx/libc/include/general/VabiMacros.hpp" +#include <cstdint> +#include <ctime> +#include <cstdlib> + +struct GuestTimespec { + std::int64_t tv_sec; + std::int64_t tv_nsec; +}; + +extern "C" int APS5_VABI timespec_get_nid_postfix(GuestTimespec* ts, int base); + +static void Require(bool value) { if (!value) std::abort(); } + +int main() { + Require(timespec_get_nid_postfix(nullptr, TIME_UTC) == 0); + GuestTimespec ts{}; + Require(timespec_get_nid_postfix(&ts, 0) == 0); + GuestTimespec filled{-1, -1}; + Require(timespec_get_nid_postfix(&filled, TIME_UTC) == TIME_UTC); + Require(filled.tv_sec > 0); + Require(filled.tv_nsec >= 0 && filled.tv_nsec < 1000000000LL); + GuestTimespec later{-1, -1}; + Require(timespec_get_nid_postfix(&later, TIME_UTC) == TIME_UTC); + Require(later.tv_nsec >= 0 && later.tv_nsec < 1000000000LL); + Require(later.tv_sec > filled.tv_sec || (later.tv_sec == filled.tv_sec && later.tv_nsec >= filled.tv_nsec)); ~~~~ --- This second-read ordering check assumes UTC wall-clock time is monotonic. Both `clock_gettime(CLOCK_REALTIME)` and `GetSystemTimePreciseAsFileTime` can move backward after an administrator/NTP clock correction, so the test can fail even when `timespec_get` correctly returns UTC. Please avoid comparing two wall-clock reads, or bound the result against an independently sampled wall clock with an allowance that does not require monotonicity.
MarcZX10 commented 2026-10-21 22:44:08 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-21T22:44:08Z.

Review: APPROVED


Reviewed both retained commits and the guest-layout fix. The KernelTimespec fields are written explicitly, and the test now pre-fills the 16-byte guest layout so the MinGW-width regression is observable. The commits retain their original contributor authorship, and the PR describes the superseding relationship to #6084. Hosted eligibility, intake, conventions, relinker and test-support checks are green. I left a non-blocking inline note about the test comparing two UTC wall-clock reads, which can move backward after clock correction.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5607132805 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9388#pullrequestreview-5607132805). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-21T22:44:08Z. **Review:** APPROVED --- Reviewed both retained commits and the guest-layout fix. The `KernelTimespec` fields are written explicitly, and the test now pre-fills the 16-byte guest layout so the MinGW-width regression is observable. The commits retain their original contributor authorship, and the PR describes the superseding relationship to #6084. Hosted eligibility, intake, conventions, relinker and test-support checks are green. I left a non-blocking inline note about the test comparing two UTC wall-clock reads, which can move backward after clock correction.
wachi35676 commented 2026-10-21 23:40:21 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by wachi35676 on 2026-10-21T23:40:21Z.


Linux run of the current head (the Linux run on #6084 predates the KernelTimespec commit).

Head d9d01fa018 merged onto main a6dcea927 (clean). WSL2 Ubuntu 24.04, GCC 13.3.0, Release.

  • guest_timespec_get, guest_time_conversion, guest_mktime: 3/3, 3 runs.
  • With libc/src/Time.cpp from main the test does not link (timespec_get_nid_postfix), as on Windows.
  • yrx+40YKqiI is timespec_get by the repo's NID algorithm.

AI-assisted: yes (Claude Code); results above were run on this machine.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6329020949 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9388#issuecomment-6329020949). Originally posted by [wachi35676](https://github.com/wachi35676) on 2026-10-21T23:40:21Z. --- Linux run of the current head (the Linux run on #6084 predates the `KernelTimespec` commit). Head `d9d01fa018` merged onto main `a6dcea927` (clean). WSL2 Ubuntu 24.04, GCC 13.3.0, Release. - `guest_timespec_get`, `guest_time_conversion`, `guest_mktime`: 3/3, 3 runs. - With `libc/src/Time.cpp` from main the test does not link (`timespec_get_nid_postfix`), as on Windows. - `yrx+40YKqiI` is `timespec_get` by the repo's NID algorithm. AI-assisted: yes (Claude Code); results above were run on this machine.
MarcZX10 commented 2026-10-22 06:17:59 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-22T06:17:59Z.


I rechecked this head against current main (d6732b51a64f4322799af89b876b224d3aed6efc). The focused Linux target built successfully and guest_timespec_get passed 3/3 locally; check_conventions.py --base upstream/main and git diff --check also pass. The independent Windows and WSL2 reports in the PR provide complementary runtime coverage.

One coordination item surfaced since the prior review: open #9447 also changes core/libs/prx/libc/src/Time.cpp, and a merge-tree of the two PR heads reports a content conflict in that file. Please coordinate merge order with its author and make sure both changes are retained (for example, rebase the later PR after the first lands). #6084 remains the intentional superseded source of the first commit and should continue to be credited as already described. The current main merge-tree for this PR alone is clean, but its base is 481 commits behind; please refresh it before merge.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6334173439 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9388#issuecomment-6334173439). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-22T06:17:59Z. --- I rechecked this head against current `main` (`d6732b51a64f4322799af89b876b224d3aed6efc`). The focused Linux target built successfully and `guest_timespec_get` passed 3/3 locally; `check_conventions.py --base upstream/main` and `git diff --check` also pass. The independent Windows and WSL2 reports in the PR provide complementary runtime coverage. One coordination item surfaced since the prior review: open #9447 also changes `core/libs/prx/libc/src/Time.cpp`, and a merge-tree of the two PR heads reports a content conflict in that file. Please coordinate merge order with its author and make sure both changes are retained (for example, rebase the later PR after the first lands). #6084 remains the intentional superseded source of the first commit and should continue to be credited as already described. The current main merge-tree for this PR alone is clean, but its base is 481 commits behind; please refresh it before merge.

Pull request closed

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!9388
No description provided.