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_MEMORY_SHARED_MEMORY_H_ | 5 #ifndef BASE_MEMORY_SHARED_MEMORY_H_ |
6 #define BASE_MEMORY_SHARED_MEMORY_H_ | 6 #define BASE_MEMORY_SHARED_MEMORY_H_ |
7 | 7 |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 | 9 |
10 #include <string> | 10 #include <string> |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
57 // When opening an existing object, this has no effect. | 57 // When opening an existing object, this has no effect. |
58 size_t size = 0; | 58 size_t size = 0; |
59 | 59 |
60 // If true, mappings might need to be made executable later. | 60 // If true, mappings might need to be made executable later. |
61 bool executable = false; | 61 bool executable = false; |
62 | 62 |
63 // If true, the file can be shared read-only to a process. | 63 // If true, the file can be shared read-only to a process. |
64 bool share_read_only = false; | 64 bool share_read_only = false; |
65 }; | 65 }; |
66 | 66 |
67 // Enumeration of different shared memory error types. Note: Currently only | |
68 // errors from Mac POSIX shared memory implementation are fully instrumented. | |
69 // TODO(asvitkine): Evaluate whether we want to keep this ability after | |
70 // crbug.com/703649 is fixed and expand to all platforms or remove. | |
71 enum class SharedMemoryError { | |
72 NO_ERRORS, | |
73 NO_FILE, | |
74 BAD_PARAMS, | |
75 STAT_FAILED, | |
76 TRUNCATE_FAILED, | |
77 NO_TEMP_DIR, | |
78 MAKE_READONLY_FAILED, | |
79 INODE_MISMATCH, | |
80 MMAP_FAILED, | |
81 }; | |
82 | |
83 // Platform abstraction for shared memory. | 67 // Platform abstraction for shared memory. |
84 // SharedMemory consumes a SharedMemoryHandle [potentially one that it created] | 68 // SharedMemory consumes a SharedMemoryHandle [potentially one that it created] |
85 // to map a shared memory OS resource into the virtual address space of the | 69 // to map a shared memory OS resource into the virtual address space of the |
86 // current process. | 70 // current process. |
87 class BASE_EXPORT SharedMemory { | 71 class BASE_EXPORT SharedMemory { |
88 public: | 72 public: |
89 SharedMemory(); | 73 SharedMemory(); |
90 | 74 |
91 #if defined(OS_WIN) | 75 #if defined(OS_WIN) |
92 // Similar to the default constructor, except that this allows for | 76 // Similar to the default constructor, except that this allows for |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
219 | 203 |
220 // Returns a read-only handle to this shared memory region. The caller takes | 204 // Returns a read-only handle to this shared memory region. The caller takes |
221 // ownership of the handle. For POSIX handles, CHECK-fails if the region | 205 // ownership of the handle. For POSIX handles, CHECK-fails if the region |
222 // wasn't Created or Opened with share_read_only=true, which is required to | 206 // wasn't Created or Opened with share_read_only=true, which is required to |
223 // make the handle read-only. When the handle is passed to the IPC subsystem, | 207 // make the handle read-only. When the handle is passed to the IPC subsystem, |
224 // that takes ownership of the handle. As such, it's not valid to pass the | 208 // that takes ownership of the handle. As such, it's not valid to pass the |
225 // sample handle to the IPC subsystem twice. Returns an invalid handle on | 209 // sample handle to the IPC subsystem twice. Returns an invalid handle on |
226 // failure. | 210 // failure. |
227 SharedMemoryHandle GetReadOnlyHandle(); | 211 SharedMemoryHandle GetReadOnlyHandle(); |
228 | 212 |
229 // Returns the last error encountered as a result of a call to Create() or | |
230 // Map(). Note: Currently only errors from Mac POSIX shared memory | |
231 // implementation are fully instrumented. | |
232 // TODO(asvitkine): Evaluate whether we want to keep this ability after | |
233 // crbug.com/703649 is fixed and expand to all platforms or remove. | |
234 SharedMemoryError get_last_error() const { return last_error_; } | |
235 | |
236 private: | 213 private: |
237 #if defined(OS_POSIX) && !defined(OS_NACL) && !defined(OS_ANDROID) && \ | 214 #if defined(OS_POSIX) && !defined(OS_NACL) && !defined(OS_ANDROID) && \ |
238 (!defined(OS_MACOSX) || defined(OS_IOS)) | 215 (!defined(OS_MACOSX) || defined(OS_IOS)) |
239 bool FilePathForMemoryName(const std::string& mem_name, FilePath* path); | 216 bool FilePathForMemoryName(const std::string& mem_name, FilePath* path); |
240 #endif | 217 #endif |
241 | 218 |
242 #if defined(OS_WIN) | 219 #if defined(OS_WIN) |
243 // If true indicates this came from an external source so needs extra checks | 220 // If true indicates this came from an external source so needs extra checks |
244 // before being mapped. | 221 // before being mapped. |
245 bool external_section_ = false; | 222 bool external_section_ = false; |
(...skipping 10 matching lines...) Expand all Loading... |
256 SharedMemoryHandle::Type mapped_memory_mechanism_ = SharedMemoryHandle::MACH; | 233 SharedMemoryHandle::Type mapped_memory_mechanism_ = SharedMemoryHandle::MACH; |
257 #endif | 234 #endif |
258 | 235 |
259 // The OS primitive that backs the shared memory region. | 236 // The OS primitive that backs the shared memory region. |
260 SharedMemoryHandle shm_; | 237 SharedMemoryHandle shm_; |
261 | 238 |
262 size_t mapped_size_ = 0; | 239 size_t mapped_size_ = 0; |
263 void* memory_ = nullptr; | 240 void* memory_ = nullptr; |
264 bool read_only_ = false; | 241 bool read_only_ = false; |
265 size_t requested_size_ = 0; | 242 size_t requested_size_ = 0; |
266 SharedMemoryError last_error_ = SharedMemoryError::NO_ERRORS; | |
267 | 243 |
268 DISALLOW_COPY_AND_ASSIGN(SharedMemory); | 244 DISALLOW_COPY_AND_ASSIGN(SharedMemory); |
269 }; | 245 }; |
270 | 246 |
271 } // namespace base | 247 } // namespace base |
272 | 248 |
273 #endif // BASE_MEMORY_SHARED_MEMORY_H_ | 249 #endif // BASE_MEMORY_SHARED_MEMORY_H_ |
OLD | NEW |