Repository navigation
fix(libkernel): serialize Windows ftruncate with file transfers - #6302
Conversation
|
Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.
|
|
Windows run of head
Titles. In the relinked titles I have, Notes on the diff, none blocking:
Not checked: Linux, macOS, and any title that resizes a file while reading it. Written with Claude Code assistance (validation by a subagent, reviewed in this session). |
The guest VFS does not map absolute host paths on Linux, so sceKernelOpen failed there.
b062366 to
135ae36
Compare
What
Concurrent positioned reads and
ftruncatecan permanently overwrite existing file data on Windows. The resize path calls_chsize_soutside the position lock used by the read's save/transfer/restore sequence, although both operate on the same native file pointer. In the new regression, every resize requests either 8 MiB or 8 MiB + 4096, yet an independent host read after both descriptors are closed finds 8,355,051 changed bytes inside the protected original 8 MiB.Hold the existing
File::LockPositionedTransferwhile resizing an ordinary Windows file. The lock is already shared across duplicated descriptors and used by positioned transfers, scalar transfers and seeks. The shared-memory resize path returns before this lock is acquired, preserving its existing locking order.guest_truncate_raceexercises kernel APIs on one descriptor and POSIX APIs through adupalias. Each case performs four rounds, with 32 full-prefix reads and 256 alternating resizes per round. It checks transfer results, read contents, both aliases' cursor, the following ordinary read, final file size and the persisted prefix throughstd::ifstreamafter close. Descriptor lifetime stays outside the race. The test has a 20-second timeout.Tested
I tested on Windows 11 Pro 10.0.26300, WinLibs MinGW-w64 GCC 15.2.0 r7, Release/Ninja, with
BUILD_TESTING=ON, outside the sandbox.Hardware: AMD Ryzen 9 7900X, 32 GB RAM, NVIDIA GeForce RTX 4070 Ti SUPER.
The following are my captured runs of the same registered regression against main
a08de6827f217115078660b9f47201edae59668band this fix. I subsequently rebased onto maine49ec591dc93c9e4dfaad8b6dbc0b995dd7830a0; all libkernel/libc and regression Git blobs are identical to the measured fixed tree. Final head:b062366e5022798c256ae02377588e5b82807557.Each cell lists kernel/direct; POSIX/dup. Both runs attempt 128 reads and 1,024 resizes per case. These are correctness observations, not performance measurements.
I checked the complete file inventories of 576 open PRs on the final refresh, including pinned-head diffs for all 29 sharing
Stdio.cpp. The 19 older AOT diffs are identical in this file and change other platform paths. I compared the implementations, tests and discussions of #5980 (invalid descriptors), #5938 (close lifetime), #5833 (whole-vector serialization), #5831 (kernel append), #6287 (stream append), #6228 (directory identity) and #6234 (GPU write coherence). None adds ordinary-file resize serialization. #5835's archive rejection is in the public wrapper and does not implement this fix.The official overlap check flags one adjacent insertion with my #6228. This change inserts the position lock after the shared-memory return, while #6228 inserts the directory-descriptor rejection there. Both lines must remain when the second PR is rebased: keep the position lock before native handle access and retain the directory check. The fixes are independent; neither needs the other to function. The checker reports no other overlap.
Limits: the existing
guest_kernel_syssymbolic-link success branches reported that links were unavailable and were not covered. No retail title, Linux runtime, console or GPU execution was tested for this change. Full hosted Windows/Linux builds require collaborator dispatch underCONTRIBUTING.md; skipped jobs are not validation passes.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository