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

Unified Diff: base/files/memory_mapped_file_posix.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_posix.cc
diff --git a/base/files/memory_mapped_file_posix.cc b/base/files/memory_mapped_file_posix.cc
index 5d7e0079992d835d32aad565d4836600257cb4b5..d04a1ff1c61fe20371e91a9b5dafbf10acf41f34 100644
--- a/base/files/memory_mapped_file_posix.cc
+++ b/base/files/memory_mapped_file_posix.cc
@@ -16,18 +16,28 @@ namespace base {
MemoryMappedFile::MemoryMappedFile() : data_(NULL), length_(0) {
}
-bool MemoryMappedFile::MapFileToMemory() {
+bool MemoryMappedFile::MapFileToMemory(const base::File::Region& region) {
ThreadRestrictions::AssertIOAllowed();
- struct stat file_stat;
- if (fstat(file_.GetPlatformFile(), &file_stat) == -1 ) {
+ int64 file_len = file_.GetLength();
+
+ if (file_len == -1) {
DPLOG(ERROR) << "fstat " << file_.GetPlatformFile();
return false;
}
- length_ = file_stat.st_size;
- data_ = static_cast<uint8*>(
- mmap(NULL, length_, PROT_READ, MAP_SHARED, file_.GetPlatformFile(), 0));
+ if (region.offset + region.size > file_.GetLength()) {
+ DLOG(ERROR) << "Region bounds invalid";
+ return false;
+ }
+
+ length_ = static_cast<size_t>(region.size);
+ data_ = static_cast<uint8*>(mmap(NULL,
+ length_,
+ PROT_READ,
+ MAP_SHARED,
+ file_.GetPlatformFile(),
+ region.offset));
if (data_ == MAP_FAILED)
DPLOG(ERROR) << "mmap " << file_.GetPlatformFile();

Powered by Google App Engine
This is Rietveld 408576698