| 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 |
| 67 // Platform abstraction for shared memory. | 83 // Platform abstraction for shared memory. |
| 68 // SharedMemory consumes a SharedMemoryHandle [potentially one that it created] | 84 // SharedMemory consumes a SharedMemoryHandle [potentially one that it created] |
| 69 // to map a shared memory OS resource into the virtual address space of the | 85 // to map a shared memory OS resource into the virtual address space of the |
| 70 // current process. | 86 // current process. |
| 71 class BASE_EXPORT SharedMemory { | 87 class BASE_EXPORT SharedMemory { |
| 72 public: | 88 public: |
| 73 SharedMemory(); | 89 SharedMemory(); |
| 74 | 90 |
| 75 #if defined(OS_WIN) | 91 #if defined(OS_WIN) |
| 76 // Similar to the default constructor, except that this allows for | 92 // Similar to the default constructor, except that this allows for |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 226 size_t operator()(const UniqueId& id) const { | 242 size_t operator()(const UniqueId& id) const { |
| 227 return HashInts(id.first, id.second); | 243 return HashInts(id.first, id.second); |
| 228 } | 244 } |
| 229 }; | 245 }; |
| 230 | 246 |
| 231 // Returns a unique ID for this shared memory's handle. Note this function may | 247 // Returns a unique ID for this shared memory's handle. Note this function may |
| 232 // access file system and be slow. | 248 // access file system and be slow. |
| 233 bool GetUniqueId(UniqueId* id) const; | 249 bool GetUniqueId(UniqueId* id) const; |
| 234 #endif | 250 #endif |
| 235 | 251 |
| 252 // Returns the last error encountered as a result of a call to Create() or |
| 253 // Map(). Note: Currently only errors from Mac POSIX shared memory |
| 254 // implementation are fully instrumented. |
| 255 // TODO(asvitkine): Evaluate whether we want to keep this ability after |
| 256 // crbug.com/703649 is fixed and expand to all platforms or remove. |
| 257 SharedMemoryError get_last_error() const { return last_error_; } |
| 258 |
| 236 private: | 259 private: |
| 237 #if defined(OS_POSIX) && !defined(OS_NACL) && !defined(OS_ANDROID) && \ | 260 #if defined(OS_POSIX) && !defined(OS_NACL) && !defined(OS_ANDROID) && \ |
| 238 (!defined(OS_MACOSX) || defined(OS_IOS)) | 261 (!defined(OS_MACOSX) || defined(OS_IOS)) |
| 239 bool FilePathForMemoryName(const std::string& mem_name, FilePath* path); | 262 bool FilePathForMemoryName(const std::string& mem_name, FilePath* path); |
| 240 #endif | 263 #endif |
| 241 | 264 |
| 242 #if defined(OS_WIN) | 265 #if defined(OS_WIN) |
| 243 // If true indicates this came from an external source so needs extra checks | 266 // If true indicates this came from an external source so needs extra checks |
| 244 // before being mapped. | 267 // before being mapped. |
| 245 bool external_section_ = false; | 268 bool external_section_ = false; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 256 SharedMemoryHandle::Type mapped_memory_mechanism_ = SharedMemoryHandle::MACH; | 279 SharedMemoryHandle::Type mapped_memory_mechanism_ = SharedMemoryHandle::MACH; |
| 257 #endif | 280 #endif |
| 258 | 281 |
| 259 // The OS primitive that backs the shared memory region. | 282 // The OS primitive that backs the shared memory region. |
| 260 SharedMemoryHandle shm_; | 283 SharedMemoryHandle shm_; |
| 261 | 284 |
| 262 size_t mapped_size_ = 0; | 285 size_t mapped_size_ = 0; |
| 263 void* memory_ = nullptr; | 286 void* memory_ = nullptr; |
| 264 bool read_only_ = false; | 287 bool read_only_ = false; |
| 265 size_t requested_size_ = 0; | 288 size_t requested_size_ = 0; |
| 289 SharedMemoryError last_error_ = SharedMemoryError::NO_ERRORS; |
| 266 | 290 |
| 267 DISALLOW_COPY_AND_ASSIGN(SharedMemory); | 291 DISALLOW_COPY_AND_ASSIGN(SharedMemory); |
| 268 }; | 292 }; |
| 269 | 293 |
| 270 } // namespace base | 294 } // namespace base |
| 271 | 295 |
| 272 #endif // BASE_MEMORY_SHARED_MEMORY_H_ | 296 #endif // BASE_MEMORY_SHARED_MEMORY_H_ |
| OLD | NEW |