Due to a Windows kernel bug, calling FlushFileBuffers is necessary to ensure that subsequent processes can correctly read the data we write. More information is available in this connect issue. The Windows Kernel team is also aware and from my understanding they are investigating. Until we have more clear guidance about what versions of Windows this affects, I'm adding this call to FlushFileBuffers for all readwrite mappings on all versions of Windows.
Details
Diff Detail
- Repository
- rL LLVM
Event Timeline
llvm/lib/Support/Windows/Path.inc | ||
---|---|---|
900 ↗ | (On Diff #132872) | How about including the URL from the patch description directly in the comment? |
llvm/lib/Support/Windows/Path.inc | ||
---|---|---|
900 ↗ | (On Diff #132872) | I thought about it, but it would wrap past 80 characters (not a huge deal, admittedly). More importantly though, it doesn't contain any kind of workaround or acknowledgement from Microsoft other than "we did the same thing in link.exe". I was hoping that if / when we get more concrete information from someone on the kernel team that I could update it with that, since that would actually be some additional info besides what's in this comment. That said, if anyone feels strongly, I can add it here in the meantime (although it doesn't really say much that this comment doesn't already say). |
llvm/lib/Support/Windows/Path.inc | ||
---|---|---|
900 ↗ | (On Diff #132872) | SGTM. |
One concern I have is that this is a common pattern on Linux:
int fd = open(...); void *mem = mmap(fd, ...); close(fd); // use mem
Are we reasonably confident that LLVM doesn't have this pattern anywhere in it? i.e. we never store the FD and then try to use it after closing it?
We don't do that anywhere *at the moment* that I can find, but I suppose it's a concern for future proofing this code. Someone could come along and add code like this after the fact. Currently the only place where we open a mapped_file_region for readwrite is in OnDiskBuffer, which stores a TempFile and then renames it atomically to the final path. We could put the flush logic inside of TempFile::keep() so that it flushes it before renaming. That might be a better option, although it wouldn't catch the case where someone comes along later and tries to use a mapped_file_region for something else. Perhaps it's ok for the time being though?
It's probably fine. I tried to look for this pattern, but got lazy and punted it to you.