OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/shared_memory.h" | 5 #include "base/shared_memory.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/utf_string_conversions.h" | 8 #include "base/utf_string_conversions.h" |
9 | 9 |
10 namespace base { | 10 namespace base { |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
127 mapped_file_ = OpenFileMapping( | 127 mapped_file_ = OpenFileMapping( |
128 read_only_ ? FILE_MAP_READ : FILE_MAP_ALL_ACCESS, false, | 128 read_only_ ? FILE_MAP_READ : FILE_MAP_ALL_ACCESS, false, |
129 name_.empty() ? NULL : name_.c_str()); | 129 name_.empty() ? NULL : name_.c_str()); |
130 if (mapped_file_ != NULL) { | 130 if (mapped_file_ != NULL) { |
131 // Note: size_ is not set in this case. | 131 // Note: size_ is not set in this case. |
132 return true; | 132 return true; |
133 } | 133 } |
134 return false; | 134 return false; |
135 } | 135 } |
136 | 136 |
137 bool SharedMemory::Map(size_t bytes) { | 137 bool SharedMemory::MapAt(off_t offset, size_t bytes) { |
138 if (mapped_file_ == NULL) | 138 if (mapped_file_ == NULL) |
139 return false; | 139 return false; |
140 | 140 |
141 if (bytes > static_cast<size_t>(std::numeric_limits<int>::max())) | 141 if (bytes > static_cast<size_t>(std::numeric_limits<int>::max())) |
142 return false; | 142 return false; |
143 | 143 |
144 memory_ = MapViewOfFile(mapped_file_, | 144 memory_ = MapViewOfFile(mapped_file_, |
145 read_only_ ? FILE_MAP_READ : FILE_MAP_ALL_ACCESS, 0, 0, bytes); | 145 read_only_ ? FILE_MAP_READ : FILE_MAP_ALL_ACCESS, |
| 146 static_cast<uint64>(offset) >> 32, |
| 147 static_cast<DWORD>(offset), |
| 148 bytes); |
146 if (memory_ != NULL) { | 149 if (memory_ != NULL) { |
147 DCHECK_EQ(0U, reinterpret_cast<uintptr_t>(memory_) & | 150 DCHECK_EQ(0U, reinterpret_cast<uintptr_t>(memory_) & |
148 (SharedMemory::MAP_MINIMUM_ALIGNMENT - 1)); | 151 (SharedMemory::MAP_MINIMUM_ALIGNMENT - 1)); |
149 return true; | 152 return true; |
150 } | 153 } |
151 return false; | 154 return false; |
152 } | 155 } |
153 | 156 |
154 bool SharedMemory::Unmap() { | 157 bool SharedMemory::Unmap() { |
155 if (memory_ == NULL) | 158 if (memory_ == NULL) |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
225 void SharedMemory::Unlock() { | 228 void SharedMemory::Unlock() { |
226 DCHECK(lock_ != NULL); | 229 DCHECK(lock_ != NULL); |
227 ReleaseMutex(lock_); | 230 ReleaseMutex(lock_); |
228 } | 231 } |
229 | 232 |
230 SharedMemoryHandle SharedMemory::handle() const { | 233 SharedMemoryHandle SharedMemory::handle() const { |
231 return mapped_file_; | 234 return mapped_file_; |
232 } | 235 } |
233 | 236 |
234 } // namespace base | 237 } // namespace base |
OLD | NEW |