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

Unified Diff: base/files/memory_mapped_file_win.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
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..03c0f975f94d47fa84a05dfeb8b90a318d344a40 100644
--- a/base/files/memory_mapped_file_win.cc
+++ b/base/files/memory_mapped_file_win.cc
@@ -15,25 +15,36 @@
namespace base {
-MemoryMappedFile::MemoryMappedFile() : data_(NULL), length_(0), image_(false) {
-}
-
-bool MemoryMappedFile::InitializeAsImageSection(const FilePath& file_name) {
- image_ = true;
- return Initialize(file_name);
+MemoryMappedFile::MemoryMappedFile() : data_(NULL), length_(0) {
}
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 = 0;
+ 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));
if (!file_mapping_.IsValid())
return false;
@@ -42,6 +53,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 +84,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;
« base/files/memory_mapped_file_posix.cc ('K') | « base/files/memory_mapped_file_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698