fix(libc): avoid time conversion races #1107
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1107"
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 Sanjaysrinivas on 2026-10-07T12:27:30Z.
What
On Linux/glibc, concurrent guest
gmtimeandlocaltimecalls can return another thread's date. The wrappers copy from the host's sharedtmafter its conversion has returned, so their thread-local destination does not protect the copy.Reuse
gmtime_s_nid_postfixandlocaltime_s_nid_postfixto convert directly into the existing thread-local storage. These helpers already usegmtime_r/localtime_ron Linux and secure CRT calls on Windows. Add an eight-thread behavioral regression for both libc-prefixed and plain aliases, UTC/local conversion, and unrepresentable timestamps.The shared host buffer is visible in glibc's gmtime and localtime implementations. The reproduced race is Linux-specific; UCRT documents per-thread conversion storage.
Tested
Earlier focused validation of the unchanged contribution patch:
Ubuntu 24.04 under WSL2, GCC 13.3.0, x86-64:
Time.cppfails the new concurrent regression on four consecutive runs:Concurrent libc_gmtime returned another thread's date.Time.cppand regression compile and pass with-O2 -Wall -Wextra -Werror -pthread.CMakeLists.txt, builds the complete libc shared library andguest_time_conversion_tests, and passesctest -R '^guest_time_conversion$' --output-on-failure --repeat until-fail:3(0.72 seconds total).Reproduce the focused test from the repository root:
With the full repository configured and built with
BUILD_TESTING=ON, run:The local validation harness, tooling and investigation report are excluded from the patch. Full-build results and remaining platform limits are recorded below.
PR overlap (earlier checks)
Direct per-file three-way merge checks confirm a conflict with the whole-tree formatting PR #1128 in
core/libs/prx/libc/src/Time.cpp. That PR does not implement this bug fix. #1128 currently conflicts with upstream inStdioExtras.cpp, so the repository overlap tool skips its pairwise conflict check; its empty result does not clear this overlap. This PR merges cleanly into upstream1e5bb880; merging it and #1128 will require rebasing whichever lands second.Earlier local validation after rebase
Rebased onto upstream
mainatcea1ef13. Tested head:732849d5b7e7128e635d3e140a613f0cb9700596.Ubuntu 24.04 under WSL2, GCC 13.3, Release; the contribution patch is preserved and its tree matches the checked merge result.
git diff --checkpassed.BUILD_TESTING=ON.guest_accesswith its working directory on the Windows-mounted filesystem. The identical rebuilt executable passed from an ext4/tmpdirectory. That local full-suite run is not reported as green.ANYPS5_REQUIRE_VULKAN=1,ANYPS5_NO_SHADER_CACHE=1andGALLIUM_OVERRIDE_CPU_CAPS=avx;agc_driver_flat_storepassed in this run.Title/homebrew execution remains untested. The GitHub-hosted fork checks below are separate from these local results.
Independent fork CI
Build run 37676594070 passed on exact PR head
69901c9ac889ac817c09e3d97c81c21cb6c4d172.Rebased onto upstream
mainat4764e59c37b1fc6c89284fdecaef5a5718b6119e. The unchanged contribution's source tree matches the checked automatic merge result; conventions andgit diff --checkpassed.Both jobs completed the full Release CMake build with
BUILD_TESTING=ON, thelibstarget and the full CTest suite with--timeout 120 --repeat until-fail:3.guest_force_tls_destructorregression passed in all three Linux repetitions.guest_accesspassed on both hosted runners; the Windows-mounted WSL failure described above was not reproduced there.These fork checks do not replace upstream workflow approval or maintainer review. No title/homebrew execution or RDNA hardware measurement is claimed.
Checklist
mainat4764e59c; no other inspected open PR implements these functions' fix.mdfiles or images added to the tracked repositoryImported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-08T06:45:59Z.
Checked build + full ctest on Linux (423/423,
guest_time_conversionpasses) and that the new test fails onmain'sTime.cpp(reverted the fix: concurrent conversion test aborts). Linux and Windows CI green on this head; merging.