fix(libc): share delete access on a stream reopened with freopen on Windows #5033
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/5033"
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 milescoviello on 2026-10-13T09:04:51Z.
What
Fixes #5031. Carries @DavidSamir's fix branch from that issue (
DavidSamir:fix/libc-freopen-delete-sharing-windows,9203b42ba, three commits), keeping the commits and their authorship. The fix and the test cherry-pick onto currentmainwithout changes; the debt commit needed one conflict resolved, because #4918's_Unwind_Contextentry landed next to the line it edits, and both entries are kept as they are.On Windows, while a stream that went through
freopenheld a file,renameof that file failed withEIOandremovewithEBUSY, andsceKernelRenameon it failed too. With a stream fromfopenor a descriptor fromsceKernelOpenboth work, as on the console and in the Linux build.fopenopens the file itself withFILE_SHARE_DELETE(#4090), butfreopenhands the name to_wfreopen, which opens it without that share mode.docs/dev/debt/libc.mdrecorded the gap. A title that reopens its log or save file withfreopenand then rotates or replaces it gets the error._wfreopenstill does the reopening, so the stream object, its buffer, its mode and its descriptor number stay as they are. After it succeeds,ShareReopenedFileopens the same file again with read, write and delete sharing and the access the mode asks for, asOpenNativedoes forfopen. It then moves the stream's descriptor onto that handle with_dup2, which closes the handle_wfreopenmade. Theamodes keep_O_APPEND, and descriptors 0 to 2 keep their Win32 standard handle (#4640). If the second open fails,freopencloses the stream and returns null with that error, as when the reopening itself fails. Linux is unchanged.The commits are:
FileAndHeap.cpp;file_streams:fopeninwb,freopeninab, thenfreopeninr+b, after whichrenameandremoveon the name succeed while the stream is open and the stream still reads back both writes;Tested
main'sFileAndHeap.cpp,file_streamsfails. With the fix it passes 5/5, and the related stream, file and descriptor tests pass 3/3.mainexcept for the renames and removes. It matches the Linux build on 125 lines; the two that differ differ the same way withmain's libraries.flock, pipe andfdopenfunctions are unchanged.freopencosts about 40 µs more, because it opens the file twice.ctest: 1037/1039. The two failures are GPU tests that fail the same way onmainon that machine.main2a2a3dc65:file_streamspasses 20/20, and all 334guest_*tests pass in two runs.-fsyntax-only -Wall -Wextracompile ofFileAndHeap.cppandFileStreams.cppis clean.tools/check_conventions.py --base upstream/mainpasses.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 (attach them to this PR)🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-13T09:26:36Z.
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)docs/dev/debt/libc.mdL47Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-14T02:34:14Z.
Closing: no title is known to reach this. With the queue at 700+ open PRs, please hold off on new PRs that don't name a title needing the change until it's down. If a title stops on this on current main, reopen with the title ID and the log line.
Pull request closed