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(-1), size(-1) { | |
20 } | |
Primiano Tucci (use gerrit)
2015/05/29 10:44:34
Not sure I get what is the use case for the empty
agrieve
2015/05/29 19:16:39
There's two parts to this:
1. Why have a default c
Primiano Tucci (use gerrit)
2015/06/01 09:14:53
Oh, I see the point, makes sense.
| |
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); | |
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 |