Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1936)

Unified Diff: base/files/memory_mapped_file_posix.cc

Issue 1798203002: Support read/write memory-mapped files. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebased Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/files/memory_mapped_file.cc ('k') | base/files/memory_mapped_file_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
Mark Mentovai 2016/05/19 14:57:06 What kinds of sizes are we talking about here? HFS
bcwhite 2016/05/19 15:40:25 That's annoying. For my immediate use (sharing Sy
+ // be explicitly extended to the maximum size. Zeros will fill the new
+ // space.
+ file_.SetLength(std::max(file_.GetLength(), region.offset + region.size));
+ 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();
« no previous file with comments | « base/files/memory_mapped_file.cc ('k') | base/files/memory_mapped_file_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698