aboutsummaryrefslogtreecommitdiff
path: root/contrib/llvm-project/llvm/lib/Support/MemoryBuffer.cpp
diff options
context:
space:
mode:
authorDimitry Andric <dim@FreeBSD.org>2025-12-27 23:23:22 +0000
committerDimitry Andric <dim@FreeBSD.org>2026-04-25 14:14:02 +0000
commite64bea71c21eb42e97aa615188ba91f6cce0d36d (patch)
tree62aa9d1dc27620bdcc0128f6f1ed30a5eac88b54 /contrib/llvm-project/llvm/lib/Support/MemoryBuffer.cpp
parent770cf0a5f02dc8983a89c6568d741fbc25baa999 (diff)
parent294ba569803972323a64670451a82af53c660541 (diff)
Diffstat (limited to 'contrib/llvm-project/llvm/lib/Support/MemoryBuffer.cpp')
-rw-r--r--contrib/llvm-project/llvm/lib/Support/MemoryBuffer.cpp10
1 files changed, 8 insertions, 2 deletions
diff --git a/contrib/llvm-project/llvm/lib/Support/MemoryBuffer.cpp b/contrib/llvm-project/llvm/lib/Support/MemoryBuffer.cpp
index 601f11f6d23c..1c4645ad8364 100644
--- a/contrib/llvm-project/llvm/lib/Support/MemoryBuffer.cpp
+++ b/contrib/llvm-project/llvm/lib/Support/MemoryBuffer.cpp
@@ -501,8 +501,14 @@ getOpenFileImpl(sys::fs::file_t FD, const Twine &Filename, uint64_t FileSize,
std::unique_ptr<MB> Result(
new (NamedBufferAlloc(Filename)) MemoryBufferMMapFile<MB>(
RequiresNullTerminator, FD, MapSize, Offset, EC));
- if (!EC)
- return std::move(Result);
+ if (!EC) {
+ // On at least Linux, and possibly on other systems, mmap may return pages
+ // from the page cache that are not properly filled with trailing zeroes,
+ // if some prior user of the page wrote non-zero bytes. Detect this and
+ // don't use mmap in that case.
+ if (!RequiresNullTerminator || *Result->getBufferEnd() == '\0')
+ return std::move(Result);
+ }
}
#ifdef __MVS__