fix(libkernel): clamp Windows birth time when setting earlier timestamps #8641

Merged
Danigamer05 merged 1 commit from upstream-pr/8641 into main 2026-10-23 08:49:22 +00:00
Danigamer05 commented 2026-10-20 19:53:17 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Danigamer05 on 2026-10-20T19:53:17Z.


What

On Windows, setting an mtime before a file's creation time left st_birthtim unchanged. FreeBSD 11.4's setutimes lowers birth time to the requested mtime in this case, including a current-time request when the existing birth time is in the future.

Read creation time in the shared Windows timestamp setter and pass the earlier mtime to SetFileTime as creation time only when it is smaller. Request read/write attribute access on its path and descriptor handles. An equal or later mtime retains the existing native creation time and its 100 ns precision. Timestamp conversion and validation still happen before any birth-time update.

Extend the existing runtime regression for utimes, lutimes, futimes, sceKernelUtimes and sceKernelFutimes, on both regular files and directories with read-only descriptors. It checks earlier/equal/later times, a difference below one microsecond, invalid-input preservation, native metadata, guest stat/fstat and NULL/current-time requests. Document the remaining concurrent-host-update and console-verification limits.

Tested

Windows 11, build 26200, AMD Ryzen 7 3700X, supported WinLibs MinGW-w64 GCC 15.2.0 r7; Release, bundled dependencies, BUILD_TESTING=ON, ANYPS5_RELINKER_ONLY=OFF.

Base: 2185dbf92e8d9013a1620d2dfc95de50494e19f8. Tested head: 3f8f81e1752ae4c830296d8c78624b25ce2274eb.

  • Full production build: cmake --build build --target libs relinker guest_file_timestamp_tests guest_filesystem_tests guest_posix_filesystem_tests kernel_error_tests --parallel 12 passed. This builds every production library and the relinker, plus the selected runtime executables.
  • Negative control on that main base: the new guest_file_timestamps regression fails at the native birth-time assertion with the original timestamp implementation. Rebuilding main with its original test then passes all four selected tests.
  • Restored this exact head, rebuilt production targets and ran ctest --test-dir build -R "^(guest_file_timestamps|guest_filesystem|guest_posix_filesystem|kernel_error)$" --repeat until-fail:3 -V: all four tests pass in all three runs (12 process runs, no skips).
  • python tools/check_conventions.py --base origin/main and whitespace checks pass. Ran python tools/pr_overlap.py --branch fix/libkernel-windows-birthtime --repo boykopovar/AnyPS5: no confirmed overlap. Its 21 stale shared-file PRs were inspected separately; none adds this birth-time adjustment. #6044 relocates the test file; it is not a duplicate implementation. These stale branches are not claimed merge-clean.

Not tested: Linux/macOS, a console, a title, GPU execution, coarse-resolution or network filesystems, host ACL denial and concurrent host timestamp writers. No compatibility or performance claim.

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
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4941589687 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8641). Originally posted by [Danigamer05](https://github.com/Danigamer05) on 2026-10-20T19:53:17Z. --- ### What On Windows, setting an mtime before a file's creation time left `st_birthtim` unchanged. FreeBSD 11.4's [`setutimes`](https://github.com/freebsd/freebsd-src/blob/release/11.4.0/sys/kern/vfs_syscalls.c#L2761-L2796) lowers birth time to the requested mtime in this case, including a current-time request when the existing birth time is in the future. Read creation time in the shared Windows timestamp setter and pass the earlier mtime to `SetFileTime` as creation time only when it is smaller. Request read/write attribute access on its path and descriptor handles. An equal or later mtime retains the existing native creation time and its 100 ns precision. Timestamp conversion and validation still happen before any birth-time update. Extend the existing runtime regression for `utimes`, `lutimes`, `futimes`, `sceKernelUtimes` and `sceKernelFutimes`, on both regular files and directories with read-only descriptors. It checks earlier/equal/later times, a difference below one microsecond, invalid-input preservation, native metadata, guest stat/fstat and NULL/current-time requests. Document the remaining concurrent-host-update and console-verification limits. ### Tested Windows 11, build 26200, AMD Ryzen 7 3700X, supported WinLibs MinGW-w64 GCC 15.2.0 r7; Release, bundled dependencies, `BUILD_TESTING=ON`, `ANYPS5_RELINKER_ONLY=OFF`. Base: `2185dbf92e8d9013a1620d2dfc95de50494e19f8`. Tested head: `3f8f81e1752ae4c830296d8c78624b25ce2274eb`. - Full production build: `cmake --build build --target libs relinker guest_file_timestamp_tests guest_filesystem_tests guest_posix_filesystem_tests kernel_error_tests --parallel 12` passed. This builds every production library and the relinker, plus the selected runtime executables. - Negative control on that main base: the new `guest_file_timestamps` regression fails at the native birth-time assertion with the original timestamp implementation. Rebuilding main with its original test then passes all four selected tests. - Restored this exact head, rebuilt production targets and ran `ctest --test-dir build -R "^(guest_file_timestamps|guest_filesystem|guest_posix_filesystem|kernel_error)$" --repeat until-fail:3 -V`: all four tests pass in all three runs (12 process runs, no skips). - `python tools/check_conventions.py --base origin/main` and whitespace checks pass. Ran `python tools/pr_overlap.py --branch fix/libkernel-windows-birthtime --repo boykopovar/AnyPS5`: no confirmed overlap. Its 21 stale shared-file PRs were inspected separately; none adds this birth-time adjustment. #6044 relocates the test file; it is not a duplicate implementation. These stale branches are not claimed merge-clean. Not tested: Linux/macOS, a console, a title, GPU execution, coarse-resolution or network filesystems, host ACL denial and concurrent host timestamp writers. No compatibility or performance claim. <!-- 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. --> ### 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 <!-- #PR, or none --> - [x] Fixes: none <!-- issue it closes as Fixes #N, or none --> - [x] Unblocks: none <!-- title ID and Game bring-up discussion, e.g. PPSA01325 #3232, or none --> - [x] GPUs tested: n/a <!-- for AGC, shader recompiler or VideoOut changes: vendor, model, driver and OS of each GPU the GPU tests ran on; otherwise n/a --> - [x] AI-assisted: yes <!-- yes / no -->
xXPBSXx commented 2026-10-20 22:38:41 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-20T22:38:41Z.


Independent Windows run of this PR (data only).

Environment: Windows 10 Pro 10.0.19045, Ryzen 7 5800X3D, WinLibs GCC 15.2.0 r7 (MinGW-w64 UCRT), Release, BUILD_TESTING=ON. Merge-tree of the PR head against main 339217ebc9 is clean. I built only guest_file_timestamp_tests; ctest -N -R guest_file_timestamps lists exactly one test.

Results (3 runs each):

  • PR head: guest_file_timestamps passes 3/3.
  • Baseline: I kept the PR's test and replaced only core/libs/prx/libkernel/File/src/Stdio.cpp with the version from the PR's merge base (2185dbf92e); current main does not compile against the PR tree here (ReadDirectoryDescriptor arity differs), then rebuilt. The test fails 3/3. I restored the PR's Stdio.cpp afterwards.

Not run: other platforms, the other file tests, the full repository CTest, and any title or console run.

AI-assisted (Claude Code).

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6303355981 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8641#issuecomment-6303355981). Originally posted by [xXPBSXx](https://github.com/xXPBSXx) on 2026-10-20T22:38:41Z. --- Independent Windows run of this PR (data only). **Environment:** Windows 10 Pro 10.0.19045, Ryzen 7 5800X3D, WinLibs GCC 15.2.0 r7 (MinGW-w64 UCRT), Release, BUILD_TESTING=ON. Merge-tree of the PR head against `main` 339217ebc9 is clean. I built only `guest_file_timestamp_tests`; `ctest -N -R guest_file_timestamps` lists exactly one test. **Results (3 runs each):** - PR head: `guest_file_timestamps` passes 3/3. - Baseline: I kept the PR's test and replaced only `core/libs/prx/libkernel/File/src/Stdio.cpp` with the version from the PR's merge base (`2185dbf92e`); current `main` does not compile against the PR tree here (`ReadDirectoryDescriptor` arity differs), then rebuilt. The test fails 3/3. I restored the PR's `Stdio.cpp` afterwards. **Not run:** other platforms, the other file tests, the full repository CTest, and any title or console run. AI-assisted (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!8641
No description provided.