Index: base/files/memory_mapped_file_win.cc |
diff --git a/base/files/memory_mapped_file_win.cc b/base/files/memory_mapped_file_win.cc |
index 5b397eed093e960827c4a4f1993e29b4001c6c91..84e09de20ba490051889c5533d16a07558d5cd2f 100644 |
--- a/base/files/memory_mapped_file_win.cc |
+++ b/base/files/memory_mapped_file_win.cc |
@@ -24,16 +24,32 @@ bool MemoryMappedFile::InitializeAsImageSection(const FilePath& file_name) { |
} |
bool MemoryMappedFile::MapFileRegionToMemory( |
- const MemoryMappedFile::Region& region) { |
+ const MemoryMappedFile::Region& region, |
+ Access access) { |
ThreadRestrictions::AssertIOAllowed(); |
if (!file_.IsValid()) |
return false; |
- int flags = image_ ? SEC_IMAGE | PAGE_READONLY : PAGE_READONLY; |
+ int flags = image_ ? SEC_IMAGE : 0; |
forshaw
2016/05/09 21:23:19
While we're changing this I'd highly recommend we
bcwhite
2016/05/10 00:44:41
Hmmm.... How about I work towards that in a diffe
forshaw
2016/05/10 07:04:30
Well we could do it in another CL, sure. I'd argue
bcwhite
2016/05/10 21:00:54
Since it's not actually in-use anywhere, I guess t
|
+ uint32_t size_low = 0; |
+ uint32_t size_high = 0; |
+ switch (access) { |
+ case READ_ONLY: |
+ flags |= PAGE_READONLY; |
+ break; |
+ case READ_WRITE: |
+ flags |= PAGE_READWRITE; |
+ break; |
+ case READ_WRITE_EXTEND: |
+ flags |= PAGE_READWRITE; |
+ size_high = static_cast<uint32_t>(region.size >> 32); |
+ size_low = static_cast<uint32_t>(region.size & 0xFFFFFFFF); |
+ break; |
+ } |
- file_mapping_.Set(::CreateFileMapping(file_.GetPlatformFile(), NULL, |
- flags, 0, 0, NULL)); |
+ file_mapping_.Set(::CreateFileMapping(file_.GetPlatformFile(), NULL, flags, |
+ size_high, size_low, NULL)); |
erikchen
2016/05/10 02:21:51
A question, mostly for forshaw:
Should we be remo
forshaw
2016/05/10 07:04:30
I don't believe so, at least as far as I can tell
|
if (!file_mapping_.IsValid()) |
return false; |
@@ -42,6 +58,7 @@ bool MemoryMappedFile::MapFileRegionToMemory( |
int32_t data_offset = 0; |
if (region == MemoryMappedFile::Region::kWholeFile) { |
+ DCHECK_NE(READ_WRITE_EXTEND, access); |
int64_t file_len = file_.GetLength(); |
if (file_len <= 0 || file_len > std::numeric_limits<int32_t>::max()) |
return false; |
@@ -72,8 +89,9 @@ bool MemoryMappedFile::MapFileRegionToMemory( |
} |
data_ = static_cast<uint8_t*>( |
- ::MapViewOfFile(file_mapping_.Get(), FILE_MAP_READ, map_start.HighPart, |
- map_start.LowPart, map_size)); |
+ ::MapViewOfFile(file_mapping_.Get(), |
+ (flags & PAGE_READONLY) ? FILE_MAP_READ : FILE_MAP_WRITE, |
+ map_start.HighPart, map_start.LowPart, map_size)); |
if (data_ == NULL) |
return false; |
data_ += data_offset; |