fix(libc): open fopen streams with delete sharing on Windows #4090
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/4090"
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 EagleBearerYS on 2026-10-11T23:01:49Z.
What
On Windows,
fopenopened its stream with_wfopen, which shares read and write access but not delete access. While the guest held a stream open,renameof its file failed withEIOandremovewithEBUSY. POSIXrenameandremovework on a file that is open, as on Linux and FreeBSD, and since #3677 the descriptorssceKernelOpenreturns share delete access, so a file opened withopencould be moved or removed but the same file opened withfopencould not.fopennow creates the handle the way #3677'sNativeOpendoes:CreateFileWsharing read, write and delete, an inheritable handle, and the access and creation disposition of the mode (ropens an existing file,wcreates or truncates,aopens or creates,xcreates a new file,+adds the other direction). The handle is wrapped with_open_osfhandle, with_O_APPENDforamodes, and_wfdopenwith the same mode minusx. WhenCreateFileWfails,errnocomes from #3677's error mapping, which moves from libkernel'sOpen.cppto libc asWindowsOpenError_nid_no_patch(declared inGeneral.hpp) so that both use the same table;Open.cppkeeps its behaviour. There is no_wfopenfallback.freopenstill reopens through_wfreopen, which does not share delete access; TechnicalDebt records it.Tested
Windows 11 (10.0.26300), WinLibs MinGW-w64 GCC 15.2.0 r7 (UCRT), Release,
-DBUILD_TESTING=ON, onmainat325e0a8bwith #4021 applied locally, sincemain's Windows build stops inSocket.cppwithout it:file_streamsnow opens a stream withw+b, renames and removes its file while the stream is open, and reads the data back through the stream; then checks thatabappends across two streams and thatwbxon an existing file fails withEEXIST. Withmain'sFileAndHeap.cpp,General.cpp,General.hppandOpen.cppthe test fails:renamereturns -1 witherrno5 (EIO) andremove-1 witherrno16 (EBUSY). With the change it passes, 20 runs in a row, as doesguest_filesystemwith #3677's delete-sharing checks forsceKernelOpen.core/libs/prx/libc/CMakeLists.txtandcore/libs/prx/libkernel/CMakeLists.txtthat build on Windows pass.tools/check_conventions.py --base origin/mainpasses.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt.mdfiles or images added to the repository (attach them to this PR)Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-12T08:34:59Z.
Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.
main)core/libs/tests/FileStreams.cppL21, L93