| 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/memory/shared_memory.h" | 5 #include "base/memory/shared_memory.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
| 9 | 9 |
| 10 namespace { | 10 namespace { |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 157 return false; | 157 return false; |
| 158 } | 158 } |
| 159 | 159 |
| 160 bool SharedMemory::MapAt(off_t offset, size_t bytes) { | 160 bool SharedMemory::MapAt(off_t offset, size_t bytes) { |
| 161 if (mapped_file_ == NULL) | 161 if (mapped_file_ == NULL) |
| 162 return false; | 162 return false; |
| 163 | 163 |
| 164 if (bytes > static_cast<size_t>(std::numeric_limits<int>::max())) | 164 if (bytes > static_cast<size_t>(std::numeric_limits<int>::max())) |
| 165 return false; | 165 return false; |
| 166 | 166 |
| 167 if (memory_) |
| 168 return false; |
| 169 |
| 167 memory_ = MapViewOfFile(mapped_file_, | 170 memory_ = MapViewOfFile(mapped_file_, |
| 168 read_only_ ? FILE_MAP_READ : FILE_MAP_READ | | 171 read_only_ ? FILE_MAP_READ : FILE_MAP_READ | |
| 169 FILE_MAP_WRITE, | 172 FILE_MAP_WRITE, |
| 170 static_cast<uint64>(offset) >> 32, | 173 static_cast<uint64>(offset) >> 32, |
| 171 static_cast<DWORD>(offset), | 174 static_cast<DWORD>(offset), |
| 172 bytes); | 175 bytes); |
| 173 if (memory_ != NULL) { | 176 if (memory_ != NULL) { |
| 174 DCHECK_EQ(0U, reinterpret_cast<uintptr_t>(memory_) & | 177 DCHECK_EQ(0U, reinterpret_cast<uintptr_t>(memory_) & |
| 175 (SharedMemory::MAP_MINIMUM_ALIGNMENT - 1)); | 178 (SharedMemory::MAP_MINIMUM_ALIGNMENT - 1)); |
| 176 mapped_size_ = GetMemorySectionSize(memory_); | 179 mapped_size_ = GetMemorySectionSize(memory_); |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 249 void SharedMemory::UnlockDeprecated() { | 252 void SharedMemory::UnlockDeprecated() { |
| 250 DCHECK(lock_ != NULL); | 253 DCHECK(lock_ != NULL); |
| 251 ReleaseMutex(lock_); | 254 ReleaseMutex(lock_); |
| 252 } | 255 } |
| 253 | 256 |
| 254 SharedMemoryHandle SharedMemory::handle() const { | 257 SharedMemoryHandle SharedMemory::handle() const { |
| 255 return mapped_file_; | 258 return mapped_file_; |
| 256 } | 259 } |
| 257 | 260 |
| 258 } // namespace base | 261 } // namespace base |
| OLD | NEW |