| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #ifndef BASE_SHARED_MEMORY_H_ | 5 #ifndef BASE_SHARED_MEMORY_H_ |
| 6 #define BASE_SHARED_MEMORY_H_ | 6 #define BASE_SHARED_MEMORY_H_ |
| 7 | 7 |
| 8 #include "build/build_config.h" | 8 #include "build/build_config.h" |
| 9 | 9 |
| 10 #include <string> | 10 #include <string> |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 152 // memory block to map. | 152 // memory block to map. |
| 153 // |offset| must be alignent to value of |SysInfo::VMAllocationGranularity()|. | 153 // |offset| must be alignent to value of |SysInfo::VMAllocationGranularity()|. |
| 154 bool MapAt(off_t offset, size_t bytes); | 154 bool MapAt(off_t offset, size_t bytes); |
| 155 enum { MAP_MINIMUM_ALIGNMENT = 32 }; | 155 enum { MAP_MINIMUM_ALIGNMENT = 32 }; |
| 156 | 156 |
| 157 // Unmaps the shared memory from the caller's address space. | 157 // Unmaps the shared memory from the caller's address space. |
| 158 // Returns true if successful; returns false on error or if the | 158 // Returns true if successful; returns false on error or if the |
| 159 // memory is not mapped. | 159 // memory is not mapped. |
| 160 bool Unmap(); | 160 bool Unmap(); |
| 161 | 161 |
| 162 // Get the size of the shared memory backing file. | 162 // The size requested when the map is first created. |
| 163 // Note: This size is only available to the creator of the | 163 size_t requested_size() const { return requested_size_; } |
| 164 // shared memory, and not to those that opened shared memory | 164 |
| 165 // created externally. | 165 // The actual size of the mapped memory (may be larger than requested). |
| 166 // Returns 0 if not created or unknown. | 166 size_t mapped_size() const { return mapped_size_; } |
| 167 // Deprecated method, please keep track of the size yourself if you created | |
| 168 // it. | |
| 169 // http://crbug.com/60821 | |
| 170 size_t created_size() const { return created_size_; } | |
| 171 | 167 |
| 172 // Gets a pointer to the opened memory space if it has been | 168 // Gets a pointer to the opened memory space if it has been |
| 173 // Mapped via Map(). Returns NULL if it is not mapped. | 169 // Mapped via Map(). Returns NULL if it is not mapped. |
| 174 void *memory() const { return memory_; } | 170 void *memory() const { return memory_; } |
| 175 | 171 |
| 176 // Returns the underlying OS handle for this segment. | 172 // Returns the underlying OS handle for this segment. |
| 177 // Use of this handle for anything other than an opaque | 173 // Use of this handle for anything other than an opaque |
| 178 // identifier is not portable. | 174 // identifier is not portable. |
| 179 SharedMemoryHandle handle() const; | 175 SharedMemoryHandle handle() const; |
| 180 | 176 |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 239 #endif | 235 #endif |
| 240 bool ShareToProcessCommon(ProcessHandle process, | 236 bool ShareToProcessCommon(ProcessHandle process, |
| 241 SharedMemoryHandle* new_handle, | 237 SharedMemoryHandle* new_handle, |
| 242 bool close_self); | 238 bool close_self); |
| 243 | 239 |
| 244 #if defined(OS_WIN) | 240 #if defined(OS_WIN) |
| 245 std::wstring name_; | 241 std::wstring name_; |
| 246 HANDLE mapped_file_; | 242 HANDLE mapped_file_; |
| 247 #elif defined(OS_POSIX) | 243 #elif defined(OS_POSIX) |
| 248 int mapped_file_; | 244 int mapped_file_; |
| 249 size_t mapped_size_; | |
| 250 ino_t inode_; | 245 ino_t inode_; |
| 251 #endif | 246 #endif |
| 247 size_t mapped_size_; |
| 252 void* memory_; | 248 void* memory_; |
| 253 bool read_only_; | 249 bool read_only_; |
| 254 size_t created_size_; | 250 size_t requested_size_; |
| 255 #if !defined(OS_POSIX) | 251 #if !defined(OS_POSIX) |
| 256 SharedMemoryLock lock_; | 252 SharedMemoryLock lock_; |
| 257 #endif | 253 #endif |
| 258 | 254 |
| 259 DISALLOW_COPY_AND_ASSIGN(SharedMemory); | 255 DISALLOW_COPY_AND_ASSIGN(SharedMemory); |
| 260 }; | 256 }; |
| 261 | 257 |
| 262 // A helper class that acquires the shared memory lock while | 258 // A helper class that acquires the shared memory lock while |
| 263 // the SharedMemoryAutoLock is in scope. | 259 // the SharedMemoryAutoLock is in scope. |
| 264 class SharedMemoryAutoLock { | 260 class SharedMemoryAutoLock { |
| 265 public: | 261 public: |
| 266 explicit SharedMemoryAutoLock(SharedMemory* shared_memory) | 262 explicit SharedMemoryAutoLock(SharedMemory* shared_memory) |
| 267 : shared_memory_(shared_memory) { | 263 : shared_memory_(shared_memory) { |
| 268 shared_memory_->Lock(); | 264 shared_memory_->Lock(); |
| 269 } | 265 } |
| 270 | 266 |
| 271 ~SharedMemoryAutoLock() { | 267 ~SharedMemoryAutoLock() { |
| 272 shared_memory_->Unlock(); | 268 shared_memory_->Unlock(); |
| 273 } | 269 } |
| 274 | 270 |
| 275 private: | 271 private: |
| 276 SharedMemory* shared_memory_; | 272 SharedMemory* shared_memory_; |
| 277 DISALLOW_COPY_AND_ASSIGN(SharedMemoryAutoLock); | 273 DISALLOW_COPY_AND_ASSIGN(SharedMemoryAutoLock); |
| 278 }; | 274 }; |
| 279 | 275 |
| 280 } // namespace base | 276 } // namespace base |
| 281 | 277 |
| 282 #endif // BASE_SHARED_MEMORY_H_ | 278 #endif // BASE_SHARED_MEMORY_H_ |
| OLD | NEW |