Chromium Code Reviews| 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 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 56 // When opening an existing object, this has no effect. | 56 // When opening an existing object, this has no effect. |
| 57 size_t size = 0; | 57 size_t size = 0; |
| 58 | 58 |
| 59 // If true, mappings might need to be made executable later. | 59 // If true, mappings might need to be made executable later. |
| 60 bool executable = false; | 60 bool executable = false; |
| 61 | 61 |
| 62 // If true, the file can be shared read-only to a process. | 62 // If true, the file can be shared read-only to a process. |
| 63 bool share_read_only = false; | 63 bool share_read_only = false; |
| 64 }; | 64 }; |
| 65 | 65 |
| 66 // Enumeration of different shared memory error types. Note: Currently only | |
| 67 // errors from Mac POSIX shared memory implementation are fully instrumented. | |
| 68 // TODO(asvitkine): Evaluate whether we want to keep this ability after | |
| 69 // crbug.com/703649 is fixed and expand to all platforms or remove. | |
| 70 enum class SharedMemoryError { | |
| 71 NO_ERRORS, | |
| 72 NO_FILE, | |
| 73 BAD_PARAMS, | |
| 74 STAT_FAILED, | |
| 75 TRUNCATE_FAILED, | |
| 76 NO_TEMP_DIR, | |
| 77 MAKE_READONLY_FAILED, | |
| 78 INODE_MISMATCH, | |
| 79 MMAP_FAILED, | |
| 80 }; | |
| 81 | |
| 66 // Platform abstraction for shared memory. | 82 // Platform abstraction for shared memory. |
| 67 // SharedMemory consumes a SharedMemoryHandle [potentially one that it created] | 83 // SharedMemory consumes a SharedMemoryHandle [potentially one that it created] |
| 68 // to map a shared memory OS resource into the virtual address space of the | 84 // to map a shared memory OS resource into the virtual address space of the |
| 69 // current process. | 85 // current process. |
| 70 class BASE_EXPORT SharedMemory { | 86 class BASE_EXPORT SharedMemory { |
| 71 public: | 87 public: |
| 72 SharedMemory(); | 88 SharedMemory(); |
| 73 | 89 |
| 74 #if defined(OS_WIN) | 90 #if defined(OS_WIN) |
| 75 // Similar to the default constructor, except that this allows for | 91 // Similar to the default constructor, except that this allows for |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 225 size_t operator()(const UniqueId& id) const { | 241 size_t operator()(const UniqueId& id) const { |
| 226 return HashInts(id.first, id.second); | 242 return HashInts(id.first, id.second); |
| 227 } | 243 } |
| 228 }; | 244 }; |
| 229 | 245 |
| 230 // Returns a unique ID for this shared memory's handle. Note this function may | 246 // Returns a unique ID for this shared memory's handle. Note this function may |
| 231 // access file system and be slow. | 247 // access file system and be slow. |
| 232 bool GetUniqueId(UniqueId* id) const; | 248 bool GetUniqueId(UniqueId* id) const; |
| 233 #endif | 249 #endif |
| 234 | 250 |
| 251 // Returns the last error encountered as a result of a call to Create() or | |
| 252 // Map(). Note: Currently only errors from Mac POSIX shared memory | |
| 253 // implementation are fully instrumented. | |
| 254 // TODO(asvitkine): Evaluate whether we want to keep this ability after | |
| 255 // crbug.com/703649 is fixed and expand to all platforms or remove. | |
| 256 SharedMemoryError get_last_error() const { return last_error_; } | |
| 257 | |
| 235 private: | 258 private: |
| 236 #if defined(OS_POSIX) && !defined(OS_NACL) && !defined(OS_ANDROID) && \ | 259 #if defined(OS_POSIX) && !defined(OS_NACL) && !defined(OS_ANDROID) && \ |
| 237 (!defined(OS_MACOSX) || defined(OS_IOS)) | 260 (!defined(OS_MACOSX) || defined(OS_IOS)) |
| 238 bool FilePathForMemoryName(const std::string& mem_name, FilePath* path); | 261 bool FilePathForMemoryName(const std::string& mem_name, FilePath* path); |
| 239 #endif | 262 #endif |
| 240 | 263 |
| 241 #if defined(OS_WIN) | 264 #if defined(OS_WIN) |
| 242 // If true indicates this came from an external source so needs extra checks | 265 // If true indicates this came from an external source so needs extra checks |
| 243 // before being mapped. | 266 // before being mapped. |
| 244 bool external_section_; | 267 bool external_section_; |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 256 SharedMemoryHandle::Type mapped_memory_mechanism_; | 279 SharedMemoryHandle::Type mapped_memory_mechanism_; |
| 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_; | 285 size_t mapped_size_; |
| 263 void* memory_; | 286 void* memory_; |
| 264 bool read_only_; | 287 bool read_only_; |
| 265 size_t requested_size_; | 288 size_t requested_size_; |
| 289 SharedMemoryError last_error_ = SharedMemoryError::NO_ERRORS; | |
|
Nico
2017/05/10 15:12:22
nit: please init in ctor, like for all other membe
Alexei Svitkine (slow)
2017/05/10 15:22:39
Unfortunately, it's not a single ctor - it's 7 dif
| |
| 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 |