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 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
208 | 208 |
209 // Returns a read-only handle to this shared memory region. The caller takes | 209 // Returns a read-only handle to this shared memory region. The caller takes |
210 // ownership of the handle. For POSIX handles, CHECK-fails if the region | 210 // ownership of the handle. For POSIX handles, CHECK-fails if the region |
211 // wasn't Created or Opened with share_read_only=true, which is required to | 211 // wasn't Created or Opened with share_read_only=true, which is required to |
212 // make the handle read-only. When the handle is passed to the IPC subsystem, | 212 // make the handle read-only. When the handle is passed to the IPC subsystem, |
213 // that takes ownership of the handle. As such, it's not valid to pass the | 213 // that takes ownership of the handle. As such, it's not valid to pass the |
214 // sample handle to the IPC subsystem twice. Returns an invalid handle on | 214 // sample handle to the IPC subsystem twice. Returns an invalid handle on |
215 // failure. | 215 // failure. |
216 SharedMemoryHandle GetReadOnlyHandle(); | 216 SharedMemoryHandle GetReadOnlyHandle(); |
217 | 217 |
218 // Shares the shared memory to another process. Attempts | |
219 // to create a platform-specific new_handle which can be | |
220 // used in a remote process to access the shared memory | |
221 // file. new_handle is an output parameter to receive | |
222 // the handle for use in the remote process. | |
223 // Returns true on success, false otherwise. | |
224 bool ShareToProcess(ProcessHandle process, | |
225 SharedMemoryHandle* new_handle) { | |
226 return ShareToProcessCommon(process, new_handle); | |
227 } | |
228 | |
229 #if defined(OS_POSIX) && (!defined(OS_MACOSX) || defined(OS_IOS)) && \ | 218 #if defined(OS_POSIX) && (!defined(OS_MACOSX) || defined(OS_IOS)) && \ |
230 !defined(OS_NACL) | 219 !defined(OS_NACL) |
231 using UniqueId = std::pair<dev_t, ino_t>; | 220 using UniqueId = std::pair<dev_t, ino_t>; |
232 | 221 |
233 struct UniqueIdHash { | 222 struct UniqueIdHash { |
234 size_t operator()(const UniqueId& id) const { | 223 size_t operator()(const UniqueId& id) const { |
235 return HashInts(id.first, id.second); | 224 return HashInts(id.first, id.second); |
236 } | 225 } |
237 }; | 226 }; |
238 | 227 |
239 // Returns a unique ID for this shared memory's handle. Note this function may | 228 // Returns a unique ID for this shared memory's handle. Note this function may |
240 // access file system and be slow. | 229 // access file system and be slow. |
241 bool GetUniqueId(UniqueId* id) const; | 230 bool GetUniqueId(UniqueId* id) const; |
242 #endif | 231 #endif |
243 | 232 |
244 private: | 233 private: |
245 #if defined(OS_POSIX) && !defined(OS_NACL) && !defined(OS_ANDROID) && \ | 234 #if defined(OS_POSIX) && !defined(OS_NACL) && !defined(OS_ANDROID) && \ |
246 (!defined(OS_MACOSX) || defined(OS_IOS)) | 235 (!defined(OS_MACOSX) || defined(OS_IOS)) |
247 bool FilePathForMemoryName(const std::string& mem_name, FilePath* path); | 236 bool FilePathForMemoryName(const std::string& mem_name, FilePath* path); |
248 #endif | 237 #endif |
249 | 238 |
250 #if defined(OS_MACOSX) | |
251 bool Share(SharedMemoryHandle* new_handle); | |
252 #endif | |
253 | |
254 bool ShareToProcessCommon(ProcessHandle process, | |
255 SharedMemoryHandle* new_handle); | |
256 | |
257 #if defined(OS_WIN) | 239 #if defined(OS_WIN) |
258 // If true indicates this came from an external source so needs extra checks | 240 // If true indicates this came from an external source so needs extra checks |
259 // before being mapped. | 241 // before being mapped. |
260 bool external_section_; | 242 bool external_section_; |
261 std::wstring name_; | 243 std::wstring name_; |
262 win::ScopedHandle mapped_file_; | 244 win::ScopedHandle mapped_file_; |
263 #else | 245 #else |
264 // The OS primitive that backs the shared memory region. | 246 // The OS primitive that backs the shared memory region. |
265 SharedMemoryHandle shm_; | 247 SharedMemoryHandle shm_; |
266 | 248 |
(...skipping 12 matching lines...) Expand all Loading... |
279 void* memory_; | 261 void* memory_; |
280 bool read_only_; | 262 bool read_only_; |
281 size_t requested_size_; | 263 size_t requested_size_; |
282 | 264 |
283 DISALLOW_COPY_AND_ASSIGN(SharedMemory); | 265 DISALLOW_COPY_AND_ASSIGN(SharedMemory); |
284 }; | 266 }; |
285 | 267 |
286 } // namespace base | 268 } // namespace base |
287 | 269 |
288 #endif // BASE_MEMORY_SHARED_MEMORY_H_ | 270 #endif // BASE_MEMORY_SHARED_MEMORY_H_ |
OLD | NEW |