| 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 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 return memory_info.RegionSize - (static_cast<char*>(address) - | 22 return memory_info.RegionSize - (static_cast<char*>(address) - |
| 23 static_cast<char*>(memory_info.AllocationBase)); | 23 static_cast<char*>(memory_info.AllocationBase)); |
| 24 } | 24 } |
| 25 | 25 |
| 26 } // namespace. | 26 } // namespace. |
| 27 | 27 |
| 28 namespace base { | 28 namespace base { |
| 29 | 29 |
| 30 SharedMemory::SharedMemory() | 30 SharedMemory::SharedMemory() |
| 31 : mapped_file_(NULL), | 31 : mapped_file_(NULL), |
| 32 mapped_size_(0), |
| 32 memory_(NULL), | 33 memory_(NULL), |
| 33 read_only_(false), | 34 read_only_(false), |
| 34 mapped_size_(0), | |
| 35 requested_size_(0) { | 35 requested_size_(0) { |
| 36 } | 36 } |
| 37 | 37 |
| 38 SharedMemory::SharedMemory(const std::wstring& name) | 38 SharedMemory::SharedMemory(const std::wstring& name) |
| 39 : mapped_file_(NULL), | 39 : name_(name), |
| 40 mapped_file_(NULL), |
| 41 mapped_size_(0), |
| 40 memory_(NULL), | 42 memory_(NULL), |
| 41 read_only_(false), | 43 read_only_(false), |
| 42 requested_size_(0), | 44 requested_size_(0) { |
| 43 mapped_size_(0), | |
| 44 name_(name) { | |
| 45 } | 45 } |
| 46 | 46 |
| 47 SharedMemory::SharedMemory(const SharedMemoryHandle& handle, bool read_only) | 47 SharedMemory::SharedMemory(const SharedMemoryHandle& handle, bool read_only) |
| 48 : mapped_file_(handle), | 48 : mapped_file_(handle), |
| 49 mapped_size_(0), |
| 49 memory_(NULL), | 50 memory_(NULL), |
| 50 read_only_(read_only), | 51 read_only_(read_only), |
| 51 requested_size_(0), | 52 requested_size_(0) { |
| 52 mapped_size_(0) { | |
| 53 } | 53 } |
| 54 | 54 |
| 55 SharedMemory::SharedMemory(const SharedMemoryHandle& handle, | 55 SharedMemory::SharedMemory(const SharedMemoryHandle& handle, |
| 56 bool read_only, | 56 bool read_only, |
| 57 ProcessHandle process) | 57 ProcessHandle process) |
| 58 : mapped_file_(NULL), | 58 : mapped_file_(NULL), |
| 59 mapped_size_(0), |
| 59 memory_(NULL), | 60 memory_(NULL), |
| 60 read_only_(read_only), | 61 read_only_(read_only), |
| 61 requested_size_(0), | 62 requested_size_(0) { |
| 62 mapped_size_(0) { | |
| 63 ::DuplicateHandle(process, handle, | 63 ::DuplicateHandle(process, handle, |
| 64 GetCurrentProcess(), &mapped_file_, | 64 GetCurrentProcess(), &mapped_file_, |
| 65 read_only_ ? FILE_MAP_READ : FILE_MAP_READ | | 65 read_only_ ? FILE_MAP_READ : FILE_MAP_READ | |
| 66 FILE_MAP_WRITE, | 66 FILE_MAP_WRITE, |
| 67 FALSE, 0); | 67 FALSE, 0); |
| 68 } | 68 } |
| 69 | 69 |
| 70 SharedMemory::~SharedMemory() { | 70 SharedMemory::~SharedMemory() { |
| 71 Unmap(); | 71 Unmap(); |
| 72 Close(); | 72 Close(); |
| (...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 263 CloseHandle(mapped_file_); | 263 CloseHandle(mapped_file_); |
| 264 mapped_file_ = NULL; | 264 mapped_file_ = NULL; |
| 265 } | 265 } |
| 266 } | 266 } |
| 267 | 267 |
| 268 SharedMemoryHandle SharedMemory::handle() const { | 268 SharedMemoryHandle SharedMemory::handle() const { |
| 269 return mapped_file_; | 269 return mapped_file_; |
| 270 } | 270 } |
| 271 | 271 |
| 272 } // namespace base | 272 } // namespace base |
| OLD | NEW |