From: Lucian Grijincu <lucian@fb.com>
Date: Wed, 8 Apr 2015 18:14:17 +0000 (-0700)
Subject: folly: MemoryMapping: respect writable when opening the file
X-Git-Tag: v0.35.0~6
X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=d2eda017c492baf468ea9cd51d5618d56b6ca900;p=folly.git

folly: MemoryMapping: respect writable when opening the file

Summary: the file needs to be opened with write-permissions before it can be mmaped with PROT_WRITE.

Test Plan: n/a

Reviewed By: philipp@fb.com

Subscribers: folly-diffs@, yfeldblum, chalfant

FB internal diff: D1974895

Signature: t1:1974895:1428451664:1106019abf02b9de659ce0d305e3d788ae7d60bc
---

diff --git a/folly/MemoryMapping.cpp b/folly/MemoryMapping.cpp
index 3750ef61..43889257 100644
--- a/folly/MemoryMapping.cpp
+++ b/folly/MemoryMapping.cpp
@@ -52,7 +52,10 @@ MemoryMapping::MemoryMapping(File file, off_t offset, off_t length,
 
 MemoryMapping::MemoryMapping(const char* name, off_t offset, off_t length,
                              Options options)
-  : MemoryMapping(File(name), offset, length, options) { }
+    : MemoryMapping(File(name, options.writable ? O_RDWR : O_RDONLY),
+                    offset,
+                    length,
+                    options) { }
 
 MemoryMapping::MemoryMapping(int fd, off_t offset, off_t length,
                              Options options)