Repository navigation
fix(libc): share delete access on a stream reopened with freopen on Windows - #5033
Closed
milescoviello wants to merge 3 commits into
Closed
milescoviello wants to merge 3 commits into
milescoviello wants to merge 3 commits into
Conversation
10 tasks done
11 tasks done
Collaborator
|
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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.main2a2a3dc: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