yvvan updated this revision to Diff 176318.
yvvan retitled this revision from "[MemoryBuffer] By default assume that all
files are volatile to prevent unintended file locks" to "[MemoryBuffer] Add the
setter to be able to force disabled mmap".
yvvan edited the summary of this revision.
yvvan added a comment.
Instead of forcing some default value let's give the client an ability to force
disabled mmap if one desires.
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D54995/new/
https://reviews.llvm.org/D54995
Files:
include/llvm/Support/MemoryBuffer.h
lib/Support/MemoryBuffer.cpp
Index: lib/Support/MemoryBuffer.cpp
===================================================================
--- lib/Support/MemoryBuffer.cpp
+++ lib/Support/MemoryBuffer.cpp
@@ -39,6 +39,12 @@
// MemoryBuffer implementation itself.
//===----------------------------------------------------------------------===//
+static bool MemoryMappingEnabled = true;
+
+void MemoryBuffer::enableMemoryMapping(bool enable) {
+ MemoryMappingEnabled = enable;
+}
+
MemoryBuffer::~MemoryBuffer() { }
/// init - Initialize this MemoryBuffer as a reference to externally allocated
@@ -312,6 +318,9 @@
bool RequiresNullTerminator,
int PageSize,
bool IsVolatile) {
+ if (!MemoryMappingEnabled)
+ return false;
+
// mmap may leave the buffer without null terminator if the file size changed
// by the time the last page is mapped in, so avoid it if the file size is
// likely to change.
Index: include/llvm/Support/MemoryBuffer.h
===================================================================
--- include/llvm/Support/MemoryBuffer.h
+++ include/llvm/Support/MemoryBuffer.h
@@ -132,6 +132,8 @@
getFileSlice(const Twine &Filename, uint64_t MapSize, uint64_t Offset,
bool IsVolatile = false);
+ static void enableMemoryMapping(bool enable);
+
//===--------------------------------------------------------------------===//
// Provided for performance analysis.
//===--------------------------------------------------------------------===//
Index: lib/Support/MemoryBuffer.cpp
===================================================================
--- lib/Support/MemoryBuffer.cpp
+++ lib/Support/MemoryBuffer.cpp
@@ -39,6 +39,12 @@
// MemoryBuffer implementation itself.
//===----------------------------------------------------------------------===//
+static bool MemoryMappingEnabled = true;
+
+void MemoryBuffer::enableMemoryMapping(bool enable) {
+ MemoryMappingEnabled = enable;
+}
+
MemoryBuffer::~MemoryBuffer() { }
/// init - Initialize this MemoryBuffer as a reference to externally allocated
@@ -312,6 +318,9 @@
bool RequiresNullTerminator,
int PageSize,
bool IsVolatile) {
+ if (!MemoryMappingEnabled)
+ return false;
+
// mmap may leave the buffer without null terminator if the file size changed
// by the time the last page is mapped in, so avoid it if the file size is
// likely to change.
Index: include/llvm/Support/MemoryBuffer.h
===================================================================
--- include/llvm/Support/MemoryBuffer.h
+++ include/llvm/Support/MemoryBuffer.h
@@ -132,6 +132,8 @@
getFileSlice(const Twine &Filename, uint64_t MapSize, uint64_t Offset,
bool IsVolatile = false);
+ static void enableMemoryMapping(bool enable);
+
//===--------------------------------------------------------------------===//
// Provided for performance analysis.
//===--------------------------------------------------------------------===//
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits