You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[Support] Always call FlushFileBuffers() when unmapping memory on Windows
This reverts the functional parts of commit
3b9b4d2.
The conditional call to FlushFileBuffers was added to work around
a rare kernel bug, see acd8791
and 3b9b4d2.
However, closing a memory mapping that has been written to, can
also need a call to FlushFileBuffers in other cases. When operating
on a VirtualBox Shared Folder file system, the output file ends
up unwritten/unflushed (with the right size but all zeros), if
written via a memory mapping, then the file is renamed before
the output handle is closed (this is what is done in lld-link).
The sequence to trigger the issue on the VirtualBox Shared Folders
is this, summarized:
file = CreateFile()
mapping = CreateFileMapping(file)
mem = MapViewOfFile()
CloseHandle(mapping)
write(mem)
UnmapViewOfFile(mem)
SetFileInformationByHandle(file, FileRenameInfo)
CloseHandle(file)
With this sequence, the output file always ends up with all zeros.
See mstorsjo/llvm-mingw#393 (comment)
for a full reproduction example.
The issue can seem elusive, as we conditionally do the call to
FlushFileBuffers() to work around the rare kernel bug, whenever
running on versions of Windows older than 10.0.0.17763.
This fixes downstream bug
mstorsjo/llvm-mingw#393.
0 commit comments