Index: base/files/memory_mapped_file_posix.cc |
diff --git a/base/files/memory_mapped_file_posix.cc b/base/files/memory_mapped_file_posix.cc |
index 1067fdc9ac34a31f208dda69c0484341b42a63c3..4899cf0cda67172491fecf1db6d4df67a7927a9d 100644 |
--- a/base/files/memory_mapped_file_posix.cc |
+++ b/base/files/memory_mapped_file_posix.cc |
@@ -21,7 +21,8 @@ MemoryMappedFile::MemoryMappedFile() : data_(NULL), length_(0) { |
#if !defined(OS_NACL) |
bool MemoryMappedFile::MapFileRegionToMemory( |
- const MemoryMappedFile::Region& region) { |
+ const MemoryMappedFile::Region& region, |
+ Access access) { |
ThreadRestrictions::AssertIOAllowed(); |
off_t map_start = 0; |
@@ -65,7 +66,23 @@ bool MemoryMappedFile::MapFileRegionToMemory( |
length_ = static_cast<size_t>(region.size); |
} |
- data_ = static_cast<uint8_t*>(mmap(NULL, map_size, PROT_READ, MAP_SHARED, |
+ int flags = 0; |
+ switch (access) { |
+ case READ_ONLY: |
+ flags |= PROT_READ; |
+ break; |
+ case READ_WRITE: |
+ flags |= PROT_READ | PROT_WRITE; |
+ break; |
+ case READ_WRITE_EXTEND: |
+ // POSIX won't auto-extend the file when it is written so it must first |
+ // be explicitly extended to the maximum size. Zeros will fill the new |
+ // space. |
+ file_.SetLength(std::max(file_.GetLength(), region.offset + region.size)); |
danakj
2016/04/25 21:26:17
possible integer overflow, use checked math
bcwhite
2016/04/26 00:08:46
Done for all platforms in memory_mapped_file.cc.
|
+ flags |= PROT_READ | PROT_WRITE; |
+ break; |
+ } |
+ data_ = static_cast<uint8_t*>(mmap(NULL, map_size, flags, MAP_SHARED, |
file_.GetPlatformFile(), map_start)); |
if (data_ == MAP_FAILED) { |
DPLOG(ERROR) << "mmap " << file_.GetPlatformFile(); |