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 <aclapi.h> | 7 #include <aclapi.h> |
| 8 #include <stddef.h> |
| 9 #include <stdint.h> |
8 | 10 |
9 #include "base/logging.h" | 11 #include "base/logging.h" |
10 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
11 #include "base/rand_util.h" | 13 #include "base/rand_util.h" |
12 #include "base/strings/stringprintf.h" | 14 #include "base/strings/stringprintf.h" |
13 #include "base/strings/utf_string_conversions.h" | 15 #include "base/strings/utf_string_conversions.h" |
14 | 16 |
15 namespace { | 17 namespace { |
16 | 18 |
17 typedef enum _SECTION_INFORMATION_CLASS { | 19 typedef enum _SECTION_INFORMATION_CLASS { |
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
249 | 251 |
250 if (bytes > static_cast<size_t>(std::numeric_limits<int>::max())) | 252 if (bytes > static_cast<size_t>(std::numeric_limits<int>::max())) |
251 return false; | 253 return false; |
252 | 254 |
253 if (memory_) | 255 if (memory_) |
254 return false; | 256 return false; |
255 | 257 |
256 if (external_section_ && !IsSectionSafeToMap(mapped_file_)) | 258 if (external_section_ && !IsSectionSafeToMap(mapped_file_)) |
257 return false; | 259 return false; |
258 | 260 |
259 memory_ = MapViewOfFile(mapped_file_, | 261 memory_ = MapViewOfFile( |
260 read_only_ ? FILE_MAP_READ : FILE_MAP_READ | | 262 mapped_file_, read_only_ ? FILE_MAP_READ : FILE_MAP_READ | FILE_MAP_WRITE, |
261 FILE_MAP_WRITE, | 263 static_cast<uint64_t>(offset) >> 32, static_cast<DWORD>(offset), bytes); |
262 static_cast<uint64>(offset) >> 32, | |
263 static_cast<DWORD>(offset), | |
264 bytes); | |
265 if (memory_ != NULL) { | 264 if (memory_ != NULL) { |
266 DCHECK_EQ(0U, reinterpret_cast<uintptr_t>(memory_) & | 265 DCHECK_EQ(0U, reinterpret_cast<uintptr_t>(memory_) & |
267 (SharedMemory::MAP_MINIMUM_ALIGNMENT - 1)); | 266 (SharedMemory::MAP_MINIMUM_ALIGNMENT - 1)); |
268 mapped_size_ = GetMemorySectionSize(memory_); | 267 mapped_size_ = GetMemorySectionSize(memory_); |
269 return true; | 268 return true; |
270 } | 269 } |
271 return false; | 270 return false; |
272 } | 271 } |
273 | 272 |
274 bool SharedMemory::Unmap() { | 273 bool SharedMemory::Unmap() { |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
317 ::CloseHandle(mapped_file_); | 316 ::CloseHandle(mapped_file_); |
318 mapped_file_ = NULL; | 317 mapped_file_ = NULL; |
319 } | 318 } |
320 } | 319 } |
321 | 320 |
322 SharedMemoryHandle SharedMemory::handle() const { | 321 SharedMemoryHandle SharedMemory::handle() const { |
323 return SharedMemoryHandle(mapped_file_, base::GetCurrentProcId()); | 322 return SharedMemoryHandle(mapped_file_, base::GetCurrentProcId()); |
324 } | 323 } |
325 | 324 |
326 } // namespace base | 325 } // namespace base |
OLD | NEW |