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 "base/files/file_path.h" | 7 #include "base/files/file_path.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/sys_info.h" | 9 #include "base/sys_info.h" |
10 | 10 |
11 namespace base { | 11 namespace base { |
12 | 12 |
13 const MemoryMappedFile::Region MemoryMappedFile::Region::kWholeFile( | 13 const MemoryMappedFile::Region MemoryMappedFile::Region::kWholeFile( |
14 base::LINKER_INITIALIZED); | 14 base::LINKER_INITIALIZED); |
15 | 15 |
16 MemoryMappedFile::Region::Region(base::LinkerInitialized) : offset(0), size(0) { | 16 MemoryMappedFile::Region::Region(base::LinkerInitialized) : offset(0), size(0) { |
17 } | 17 } |
18 | 18 |
19 MemoryMappedFile::Region::Region() : offset(0), size(0) { | |
Lei Zhang
2015/05/28 18:55:53
Perhaps this one should be (-1, -1) to indicate in
agrieve
2015/05/28 19:13:24
sgtm (done)
| |
20 } | |
21 | |
19 MemoryMappedFile::Region::Region(int64 offset, int64 size) | 22 MemoryMappedFile::Region::Region(int64 offset, int64 size) |
20 : offset(offset), size(size) { | 23 : offset(offset), size(size) { |
21 DCHECK_GE(offset, 0); | |
Lei Zhang
2015/05/28 18:55:53
why remove the DCHECKs?
agrieve
2015/05/28 19:13:24
There are times (like when going through jni) wher
Lei Zhang
2015/05/29 21:14:09
Assuming we stick with -1 to indicate invalidness,
agrieve
2015/06/01 14:50:05
This wouldn't allow you to convert an invalid regi
| |
22 DCHECK_GT(size, 0); | |
23 } | 24 } |
24 | 25 |
25 bool MemoryMappedFile::Region::operator==( | 26 bool MemoryMappedFile::Region::operator==( |
26 const MemoryMappedFile::Region& other) const { | 27 const MemoryMappedFile::Region& other) const { |
27 return other.offset == offset && other.size == size; | 28 return other.offset == offset && other.size == size; |
28 } | 29 } |
29 | 30 |
30 MemoryMappedFile::~MemoryMappedFile() { | 31 MemoryMappedFile::~MemoryMappedFile() { |
31 CloseHandles(); | 32 CloseHandles(); |
32 } | 33 } |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
82 // Sadly, on Windows, the mmap alignment is not just equal to the page size. | 83 // Sadly, on Windows, the mmap alignment is not just equal to the page size. |
83 const int64 mask = static_cast<int64>(SysInfo::VMAllocationGranularity()) - 1; | 84 const int64 mask = static_cast<int64>(SysInfo::VMAllocationGranularity()) - 1; |
84 DCHECK_LT(mask, std::numeric_limits<int32>::max()); | 85 DCHECK_LT(mask, std::numeric_limits<int32>::max()); |
85 *offset = start & mask; | 86 *offset = start & mask; |
86 *aligned_start = start & ~mask; | 87 *aligned_start = start & ~mask; |
87 *aligned_size = (size + *offset + mask) & ~mask; | 88 *aligned_size = (size + *offset + mask) & ~mask; |
88 } | 89 } |
89 #endif | 90 #endif |
90 | 91 |
91 } // namespace base | 92 } // namespace base |
OLD | NEW |