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 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
216 SharedMemoryHandle GetReadOnlyHandle(); | 216 SharedMemoryHandle GetReadOnlyHandle(); |
217 | 217 |
218 // Shares the shared memory to another process. Attempts | 218 // Shares the shared memory to another process. Attempts |
219 // to create a platform-specific new_handle which can be | 219 // to create a platform-specific new_handle which can be |
220 // used in a remote process to access the shared memory | 220 // used in a remote process to access the shared memory |
221 // file. new_handle is an output parameter to receive | 221 // file. new_handle is an output parameter to receive |
222 // the handle for use in the remote process. | 222 // the handle for use in the remote process. |
223 // Returns true on success, false otherwise. | 223 // Returns true on success, false otherwise. |
224 bool ShareToProcess(ProcessHandle process, | 224 bool ShareToProcess(ProcessHandle process, |
225 SharedMemoryHandle* new_handle) { | 225 SharedMemoryHandle* new_handle) { |
226 return ShareToProcessCommon(process, new_handle, false); | 226 return ShareToProcessCommon(process, new_handle); |
227 } | |
228 | |
229 // Logically equivalent to: | |
230 // bool ok = ShareToProcess(process, new_handle); | |
231 // Close(); | |
232 // return ok; | |
233 // Note that the memory is unmapped by calling this method, regardless of the | |
234 // return value. | |
235 bool GiveToProcess(ProcessHandle process, | |
236 SharedMemoryHandle* new_handle) { | |
237 return ShareToProcessCommon(process, new_handle, true); | |
238 } | 227 } |
239 | 228 |
240 #if defined(OS_POSIX) && (!defined(OS_MACOSX) || defined(OS_IOS)) && \ | 229 #if defined(OS_POSIX) && (!defined(OS_MACOSX) || defined(OS_IOS)) && \ |
241 !defined(OS_NACL) | 230 !defined(OS_NACL) |
242 using UniqueId = std::pair<dev_t, ino_t>; | 231 using UniqueId = std::pair<dev_t, ino_t>; |
243 | 232 |
244 struct UniqueIdHash { | 233 struct UniqueIdHash { |
245 size_t operator()(const UniqueId& id) const { | 234 size_t operator()(const UniqueId& id) const { |
246 return HashInts(id.first, id.second); | 235 return HashInts(id.first, id.second); |
247 } | 236 } |
248 }; | 237 }; |
249 | 238 |
250 // Returns a unique ID for this shared memory's handle. Note this function may | 239 // Returns a unique ID for this shared memory's handle. Note this function may |
251 // access file system and be slow. | 240 // access file system and be slow. |
252 bool GetUniqueId(UniqueId* id) const; | 241 bool GetUniqueId(UniqueId* id) const; |
253 #endif | 242 #endif |
254 | 243 |
255 private: | 244 private: |
256 #if defined(OS_POSIX) && !defined(OS_NACL) && !defined(OS_ANDROID) && \ | 245 #if defined(OS_POSIX) && !defined(OS_NACL) && !defined(OS_ANDROID) && \ |
257 (!defined(OS_MACOSX) || defined(OS_IOS)) | 246 (!defined(OS_MACOSX) || defined(OS_IOS)) |
258 bool FilePathForMemoryName(const std::string& mem_name, FilePath* path); | 247 bool FilePathForMemoryName(const std::string& mem_name, FilePath* path); |
259 #endif | 248 #endif |
260 | 249 |
261 #if defined(OS_MACOSX) | 250 #if defined(OS_MACOSX) |
262 bool Share(SharedMemoryHandle* new_handle); | 251 bool Share(SharedMemoryHandle* new_handle); |
263 #endif | 252 #endif |
264 | 253 |
265 bool ShareToProcessCommon(ProcessHandle process, | 254 bool ShareToProcessCommon(ProcessHandle process, |
266 SharedMemoryHandle* new_handle, | 255 SharedMemoryHandle* new_handle); |
267 bool close_self); | |
268 | 256 |
269 #if defined(OS_WIN) | 257 #if defined(OS_WIN) |
270 // If true indicates this came from an external source so needs extra checks | 258 // If true indicates this came from an external source so needs extra checks |
271 // before being mapped. | 259 // before being mapped. |
272 bool external_section_; | 260 bool external_section_; |
273 std::wstring name_; | 261 std::wstring name_; |
274 win::ScopedHandle mapped_file_; | 262 win::ScopedHandle mapped_file_; |
275 #else | 263 #else |
276 // The OS primitive that backs the shared memory region. | 264 // The OS primitive that backs the shared memory region. |
277 SharedMemoryHandle shm_; | 265 SharedMemoryHandle shm_; |
(...skipping 13 matching lines...) Expand all Loading... |
291 void* memory_; | 279 void* memory_; |
292 bool read_only_; | 280 bool read_only_; |
293 size_t requested_size_; | 281 size_t requested_size_; |
294 | 282 |
295 DISALLOW_COPY_AND_ASSIGN(SharedMemory); | 283 DISALLOW_COPY_AND_ASSIGN(SharedMemory); |
296 }; | 284 }; |
297 | 285 |
298 } // namespace base | 286 } // namespace base |
299 | 287 |
300 #endif // BASE_MEMORY_SHARED_MEMORY_H_ | 288 #endif // BASE_MEMORY_SHARED_MEMORY_H_ |
OLD | NEW |