From d2eda017c492baf468ea9cd51d5618d56b6ca900 Mon Sep 17 00:00:00 2001 From: Lucian Grijincu Date: Wed, 8 Apr 2015 11:14:17 -0700 Subject: [PATCH] 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 --- folly/MemoryMapping.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) 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) -- 2.34.1