OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/files/memory_mapped_file.h" | 5 #include "base/files/memory_mapped_file.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/files/file_path.h" | 9 #include "base/files/file_path.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
64 bool MemoryMappedFile::Initialize(File file, Access access) { | 64 bool MemoryMappedFile::Initialize(File file, Access access) { |
65 DCHECK_NE(READ_WRITE_EXTEND, access); | 65 DCHECK_NE(READ_WRITE_EXTEND, access); |
66 return Initialize(std::move(file), Region::kWholeFile, access); | 66 return Initialize(std::move(file), Region::kWholeFile, access); |
67 } | 67 } |
68 | 68 |
69 bool MemoryMappedFile::Initialize(File file, | 69 bool MemoryMappedFile::Initialize(File file, |
70 const Region& region, | 70 const Region& region, |
71 Access access) { | 71 Access access) { |
72 switch (access) { | 72 switch (access) { |
73 case READ_WRITE_EXTEND: | 73 case READ_WRITE_EXTEND: |
| 74 DCHECK(Region::kWholeFile != region); |
74 // Ensure that the extended size is within limits of File. | 75 // Ensure that the extended size is within limits of File. |
75 if (region.size > std::numeric_limits<int64_t>::max() - region.offset) { | 76 if (region.size > std::numeric_limits<int64_t>::max() - region.offset) { |
76 DLOG(ERROR) << "Region bounds exceed maximum for base::File."; | 77 DLOG(ERROR) << "Region bounds exceed maximum for base::File."; |
77 return false; | 78 return false; |
78 } | 79 } |
79 // Fall through. | 80 // Fall through. |
80 case READ_ONLY: | 81 case READ_ONLY: |
81 case READ_WRITE: | 82 case READ_WRITE: |
82 // Ensure that the region values are valid. | 83 // Ensure that the region values are valid. |
83 if (region.offset < 0 || region.size < 0) { | 84 if (region.offset < 0 || region.size < 0) { |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
119 const int64_t mask = | 120 const int64_t mask = |
120 static_cast<int64_t>(SysInfo::VMAllocationGranularity()) - 1; | 121 static_cast<int64_t>(SysInfo::VMAllocationGranularity()) - 1; |
121 DCHECK_LT(mask, std::numeric_limits<int32_t>::max()); | 122 DCHECK_LT(mask, std::numeric_limits<int32_t>::max()); |
122 *offset = start & mask; | 123 *offset = start & mask; |
123 *aligned_start = start & ~mask; | 124 *aligned_start = start & ~mask; |
124 *aligned_size = (size + *offset + mask) & ~mask; | 125 *aligned_size = (size + *offset + mask) & ~mask; |
125 } | 126 } |
126 #endif | 127 #endif |
127 | 128 |
128 } // namespace base | 129 } // namespace base |
OLD | NEW |