[PATCH] D54995: [MemoryBuffer] Add the setter to be able to force disabled mmap

Ivan Donchevskii via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Dec 3 01:19:21 PST 2018


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.
   //===--------------------------------------------------------------------===//


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D54995.176318.patch
Type: text/x-patch
Size: 1550 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20181203/f18e97cc/attachment.bin>


More information about the cfe-commits mailing list