| Index: base/files/memory_mapped_file.cc
|
| diff --git a/base/files/memory_mapped_file.cc b/base/files/memory_mapped_file.cc
|
| index ace4e112628519137e7f56fbfb36f6176c2e8e83..4fecd8f873e0b651520a1cc8c4c94f65490b4ff2 100644
|
| --- a/base/files/memory_mapped_file.cc
|
| +++ b/base/files/memory_mapped_file.cc
|
| @@ -6,6 +6,7 @@
|
|
|
| #include "base/files/file_path.h"
|
| #include "base/logging.h"
|
| +#include "base/sys_info.h"
|
|
|
| namespace base {
|
|
|
| @@ -24,7 +25,7 @@ bool MemoryMappedFile::Initialize(const FilePath& file_name) {
|
| return false;
|
| }
|
|
|
| - if (!MapFileToMemory()) {
|
| + if (!MapFileRegionToMemory(File::Region::WholeFile())) {
|
| CloseHandles();
|
| return false;
|
| }
|
| @@ -33,12 +34,16 @@ bool MemoryMappedFile::Initialize(const FilePath& file_name) {
|
| }
|
|
|
| bool MemoryMappedFile::Initialize(File file) {
|
| + return Initialize(file.Pass(), base::File::Region::WholeFile());
|
| +}
|
| +
|
| +bool MemoryMappedFile::Initialize(File file, const base::File::Region& region) {
|
| if (IsValid())
|
| return false;
|
|
|
| file_ = file.Pass();
|
|
|
| - if (!MapFileToMemory()) {
|
| + if (!MapFileRegionToMemory(region)) {
|
| CloseHandles();
|
| return false;
|
| }
|
| @@ -50,4 +55,17 @@ bool MemoryMappedFile::IsValid() const {
|
| return data_ != NULL;
|
| }
|
|
|
| +// static
|
| +void MemoryMappedFile::CalculateVMAlignedBoundaries(int64 start,
|
| + int64 size,
|
| + int64* aligned_start,
|
| + int64* aligned_size,
|
| + int32* offset) {
|
| + // Sadly, on Windows, the mmap alignment is not just equal to the page size.
|
| + const int64 mask = static_cast<int64>(SysInfo::VMAllocationGranularity()) - 1;
|
| + *offset = start & mask;
|
| + *aligned_start = start & ~mask;
|
| + *aligned_size = (size + *offset + mask) & ~mask;
|
| +}
|
| +
|
| } // namespace base
|
|
|