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

Unified Diff: base/files/memory_mapped_file_win.cc

Issue 394313002: Add support for loading pak files from arbitrary file regions. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Win implementation Created 6 years, 5 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 f3822873bfdddb877bd73afd9fa2548ca5cd83f2..74d8619e9a6a99592bbf30529c386066b80e738c 100644
--- a/base/files/memory_mapped_file_win.cc
+++ b/base/files/memory_mapped_file_win.cc
@@ -18,7 +18,7 @@ bool MemoryMappedFile::InitializeAsImageSection(const FilePath& file_name) {
return Initialize(file_name);
}
-bool MemoryMappedFile::MapFileToMemory() {
+bool MemoryMappedFile::MapFileToMemory(const base::File::Region& region) {
ThreadRestrictions::AssertIOAllowed();
if (!file_.IsValid())
@@ -27,6 +27,10 @@ bool MemoryMappedFile::MapFileToMemory() {
int64 len = file_.GetLength();
if (len <= 0 || len > kint32max)
mkosiba (inactive) 2014/07/17 00:38:01 do we want to apply the same check to offset? then
Primiano Tucci (use gerrit) 2014/07/17 01:15:17 Actually, now that I think more about this, we sh
return false;
+ if (region.offset + region.size > len) {
+ DLOG(ERROR) << "Region bounds invalid";
+ return false;
+ }
length_ = static_cast<size_t>(len);
int flags = image_ ? SEC_IMAGE | PAGE_READONLY : PAGE_READONLY;
@@ -36,8 +40,12 @@ bool MemoryMappedFile::MapFileToMemory() {
if (!file_mapping_.IsValid())
return false;
+ LARGE_INTEGER offset = {.QuadPart = region.offset};
data_ = static_cast<uint8*>(::MapViewOfFile(file_mapping_.Get(),
- FILE_MAP_READ, 0, 0, 0));
+ FILE_MAP_READ,
+ offset.HighPart,
+ offset.LowPart,
+ region.size));
return data_ != NULL;
}

Powered by Google App Engine
This is Rietveld 408576698