fix(libkernel): serialize positioned file transfers on Windows #4973
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/4973"
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 ducloc080202 on 2026-10-13T06:58:07Z.
What
Rebases #3861 (open but conflicting since Oct 12) onto current
main. Serializes Windows file-position transfers with a mutex per descriptor, shared across duplicated descriptors: positioned transfers (NativePositioned_nid_no_patch), plain transfers (NativeTransfer,NativeRead,NativeWrite) and seeks (NativeLseek) of one descriptor can no longer interleaveSetFilePointerExpositioning. Entries persist per descriptor number; a lock is only ever held alone, so no new lock order.Supersedes #3861; that PR can be closed if this one is accepted.
Tested
guest_positioned_race(concurrentpreadagainstread+lseekon one descriptor, verifying both sides) fails onmainon the first run and passes 10/10 with the fix;file_position,guest_posix_filesystem,guest_filesystem,guest_file_vector,file_streams,guest_aioall pass (7/7). Linux/macOS rely on CI.Checklist
main; no other open PR implements the same functions (rebases conflicting #3861; supersedes it)NotImplemented_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)Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-13T08:05:03Z.
Taking this one over #3861. Three things before it can go in:
e2e4ba2a0); please rebase the original commit onto main instead, keeping its author.Open.cpp:46-48:NativeLseekcan still run between the save and the restore inNativePositioned_nid_no_patch(Stdio.cpp:186-197), and the restore then overwrites the seek. Take the same lock there.preadagainstreadandlseekon one descriptor from two threads and fails on main.A lock per descriptor instead of one for all files would be better, as asked on #3861.
Imported from boykopovar/AnyPS5. Originally posted by ducloc080202 on 2026-10-13T08:37:51Z.
Done, pushed as 31bcf985a..e69306fee (branch rebased, no merge commit): 1) original commit cherry-picked with its author kept; 2) the same per-descriptor lock now covers NativeLseek, so a seek between the positioned save and restore can no longer clobber either side; 3) new guest_positioned_race test (pread vs read+lseek on one descriptor, both sides verified) fails on main first run, passes 10/10 with the fix; 4) one mutex per descriptor number, shared across dup, entries persist so close/reuse cannot strand a waiter. The debt entry for the Windows positioned race now describes the serialized behavior.
Imported from boykopovar/AnyPS5. Originally posted by nicolasfalesy on 2026-10-13T09:04:48Z.
Linux build (Arch, GCC 16.2.1, Release,
BUILD_TESTING=ON), headf9881adaamerged alone ontomain4bb2c7f39: 592 targets fail to link, everything that linkslibkernel.prx:File::SharePositionedTransferis defined inFile/src/Stdio.cppinside the#ifdef _WIN32block that starts at line 50, butShareDescriptorinFile/src/DescriptorControl.cppnow calls it on every platform (the call sits before that function's own#ifdef _WIN32). Either guarding the call with#ifdef _WIN32like theGuestFileLockShare_nid_no_patchline below it, or giving Linux an empty definition, should fix it. The CIlinuxjob is skipped for this PR, so it would not show there.Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-13T12:00:21Z.
Windows counter-test (follow-up): Windows 10 (19045), MinGW-w64 GCC 15.2.0 (WinLibs r7), Release, this PR merged onto
main2a2a3dc65.guest_positioned_racepasses with the PR; with the PR's source files replaced bymain's, same test, it aborts at line 74.Not tested: Linux, a console, a title run.
AI-assisted (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by p3n1cillin on 2026-10-13T21:03:01Z.
Data point from a third Unity title, for scope: Cult of the Lamb (PPSA06465) also faults intermittently on
Loading.PreloadManagerat start-up on Windows. This PR merged ontomaina0f5916a2doesn't change its rate: in 8 alternated 40 s runs per side, there were 5 faults with the PR and 4 without. So its fault is a different race from the one fixed here; details in https://github.com/boykopovar/AnyPS5/issues/5490. This says nothing against the PR for Hotline Miami or Cat Quest III.Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-13T22:20:04Z.
Rebased onto main (
bf8dc610e6) and force-pushed. The only conflict was the include list inFile/src/Stdio.cpp, which now keeps both<unordered_map>and<utility>. Your three commits keep their authors.Added one commit:
DescriptorControl.cpp:568now callsFile::SharePositionedTransferunder_WIN32, next toGuestFileLockShare_nid_no_patch. The lock is only defined in the Windows part ofStdio.cpp, so libkernel didn't link on Linux. Windows behaviour is unchanged.