diff options
author | Zachary Turner <zturner@google.com> | 2018-02-15 18:36:10 +0000 |
---|---|---|
committer | Zachary Turner <zturner@google.com> | 2018-02-15 18:36:10 +0000 |
commit | acd8791c2619f2afc0347c1bff073b32fbffb5d6 (patch) | |
tree | 684d8e4a19f64823a39d4a9f2db238c1c3db906e /llvm/lib/Support/Windows | |
parent | 49b44ad7c6225187a942f672a482060294c01ef5 (diff) | |
download | bcm5719-llvm-acd8791c2619f2afc0347c1bff073b32fbffb5d6.tar.gz bcm5719-llvm-acd8791c2619f2afc0347c1bff073b32fbffb5d6.zip |
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
llvm-svn: 325274
Diffstat (limited to 'llvm/lib/Support/Windows')
-rw-r--r-- | llvm/lib/Support/Windows/Path.inc | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/llvm/lib/Support/Windows/Path.inc b/llvm/lib/Support/Windows/Path.inc index f81790b17df..58c555daceb 100644 --- a/llvm/lib/Support/Windows/Path.inc +++ b/llvm/lib/Support/Windows/Path.inc @@ -822,6 +822,8 @@ std::error_code setLastModificationAndAccessTime(int FD, TimePoint<> Time) { 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(int fd, mapmode mode, size_t length, } 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 { |