[llvm] r325274 - Call FlushFileBuffers on output files.
Zachary Turner via llvm-commits
llvm-commits at lists.llvm.org
Thu Feb 15 10:36:10 PST 2018
Author: zturner
Date: Thu Feb 15 10:36:10 2018
New Revision: 325274
URL: http://llvm.org/viewvc/llvm-project?rev=325274&view=rev
Log:
Call FlushFileBuffers on output files.
There is a latent Windows kernel bug, the exact trigger
conditions are not well understood, which can cause a file
to be correctly written, but unable to be correctly read.
The workaround appears to be simply calling FlushFileBuffers.
Differential Revision: https://reviews.llvm.org/D42925
Modified:
llvm/trunk/include/llvm/Support/FileSystem.h
llvm/trunk/lib/Support/Windows/Path.inc
Modified: llvm/trunk/include/llvm/Support/FileSystem.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/FileSystem.h?rev=325274&r1=325273&r2=325274&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Support/FileSystem.h (original)
+++ llvm/trunk/include/llvm/Support/FileSystem.h Thu Feb 15 10:36:10 2018
@@ -819,6 +819,8 @@ private:
/// Platform-specific mapping state.
size_t Size;
void *Mapping;
+ int FD;
+ mapmode Mode;
std::error_code init(int FD, uint64_t Offset, mapmode Mode);
Modified: llvm/trunk/lib/Support/Windows/Path.inc
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/Windows/Path.inc?rev=325274&r1=325273&r2=325274&view=diff
==============================================================================
--- llvm/trunk/lib/Support/Windows/Path.inc (original)
+++ llvm/trunk/lib/Support/Windows/Path.inc Thu Feb 15 10:36:10 2018
@@ -822,6 +822,8 @@ std::error_code setLastModificationAndAc
std::error_code mapped_file_region::init(int FD, uint64_t Offset,
mapmode Mode) {
+ this->FD = FD;
+ this->Mode = Mode;
HANDLE FileHandle = reinterpret_cast<HANDLE>(_get_osfhandle(FD));
if (FileHandle == INVALID_HANDLE_VALUE)
return make_error_code(errc::bad_file_descriptor);
@@ -887,8 +889,20 @@ mapped_file_region::mapped_file_region(i
}
mapped_file_region::~mapped_file_region() {
- if (Mapping)
+ if (Mapping) {
::UnmapViewOfFile(Mapping);
+
+ if (Mode == mapmode::readwrite) {
+ // There is a Windows kernel bug, the exact trigger conditions of which
+ // are not well understood. When triggered, dirty pages are not properly
+ // flushed and subsequent process's attempts to read a file can return
+ // invalid data. Calling FlushFileBuffers on the write handle is
+ // sufficient to ensure that this bug is not triggered.
+ HANDLE FileHandle = reinterpret_cast<HANDLE>(_get_osfhandle(FD));
+ if (FileHandle != INVALID_HANDLE_VALUE)
+ ::FlushFileBuffers(FileHandle);
+ }
+ }
}
size_t mapped_file_region::size() const {
More information about the llvm-commits
mailing list