Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(994)

Side by Side Diff: base/memory/shared_memory.h

Issue 2555483002: Add POSIX shared memory support for Mac (Closed)
Patch Set: Remove GetType(). Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | base/memory/shared_memory_handle.h » ('j') | base/memory/shared_memory_handle.h » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 16 matching lines...) Expand all
27 #if defined(OS_WIN) 27 #if defined(OS_WIN)
28 #include "base/win/scoped_handle.h" 28 #include "base/win/scoped_handle.h"
29 #endif 29 #endif
30 30
31 namespace base { 31 namespace base {
32 32
33 class FilePath; 33 class FilePath;
34 34
35 // Options for creating a shared memory object. 35 // Options for creating a shared memory object.
36 struct BASE_EXPORT SharedMemoryCreateOptions { 36 struct BASE_EXPORT SharedMemoryCreateOptions {
37 #if !(defined(OS_MACOSX) && !defined(OS_IOS)) 37 #if defined(OS_MACOSX) && !defined(OS_IOS)
38 // The type of OS primitive that should back the SharedMemory object.
39 SharedMemoryHandle::Type type = SharedMemoryHandle::MACH;
40 #else
38 // DEPRECATED (crbug.com/345734): 41 // DEPRECATED (crbug.com/345734):
39 // If NULL, the object is anonymous. This pointer is owned by the caller 42 // If NULL, the object is anonymous. This pointer is owned by the caller
40 // and must live through the call to Create(). 43 // and must live through the call to Create().
41 const std::string* name_deprecated = nullptr; 44 const std::string* name_deprecated = nullptr;
42 45
43 // DEPRECATED (crbug.com/345734): 46 // DEPRECATED (crbug.com/345734):
44 // If true, and the shared memory already exists, Create() will open the 47 // If true, and the shared memory already exists, Create() will open the
45 // existing shared memory and ignore the size parameter. If false, 48 // existing shared memory and ignore the size parameter. If false,
46 // shared memory must not exist. This flag is meaningless unless 49 // shared memory must not exist. This flag is meaningless unless
47 // name_deprecated is non-NULL. 50 // name_deprecated is non-NULL.
48 bool open_existing_deprecated = false; 51 bool open_existing_deprecated = false;
49 #endif // !(defined(OS_MACOSX) && !defined(OS_IOS)) 52 #endif // defined(OS_MACOSX) && !defined(OS_IOS)
50 53
51 // Size of the shared memory object to be created. 54 // Size of the shared memory object to be created.
52 // When opening an existing object, this has no effect. 55 // When opening an existing object, this has no effect.
53 size_t size = 0; 56 size_t size = 0;
54 57
55 // If true, mappings might need to be made executable later. 58 // If true, mappings might need to be made executable later.
56 bool executable = false; 59 bool executable = false;
57 60
58 // If true, the file can be shared read-only to a process. 61 // If true, the file can be shared read-only to a process.
59 bool share_read_only = false; 62 bool share_read_only = false;
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 // Closes a shared memory handle. 97 // Closes a shared memory handle.
95 static void CloseHandle(const SharedMemoryHandle& handle); 98 static void CloseHandle(const SharedMemoryHandle& handle);
96 99
97 // Returns the maximum number of handles that can be open at once per process. 100 // Returns the maximum number of handles that can be open at once per process.
98 static size_t GetHandleLimit(); 101 static size_t GetHandleLimit();
99 102
100 // Duplicates The underlying OS primitive. Returns NULLHandle() on failure. 103 // Duplicates The underlying OS primitive. Returns NULLHandle() on failure.
101 // The caller is responsible for destroying the duplicated OS primitive. 104 // The caller is responsible for destroying the duplicated OS primitive.
102 static SharedMemoryHandle DuplicateHandle(const SharedMemoryHandle& handle); 105 static SharedMemoryHandle DuplicateHandle(const SharedMemoryHandle& handle);
103 106
104 #if defined(OS_POSIX) && !(defined(OS_MACOSX) && !defined(OS_IOS)) 107 #if defined(OS_POSIX)
105 // This method requires that the SharedMemoryHandle is backed by a POSIX fd. 108 // This method requires that the SharedMemoryHandle is backed by a POSIX fd.
106 static int GetFdFromSharedMemoryHandle(const SharedMemoryHandle& handle); 109 static int GetFdFromSharedMemoryHandle(const SharedMemoryHandle& handle);
107 #endif 110 #endif
108 111
109 #if defined(OS_POSIX) && !defined(OS_ANDROID) 112 #if defined(OS_POSIX) && !defined(OS_ANDROID)
110 // Gets the size of the shared memory region referred to by |handle|. 113 // Gets the size of the shared memory region referred to by |handle|.
111 // Returns false on a failure to determine the size. On success, populates the 114 // Returns false on a failure to determine the size. On success, populates the
112 // output variable |size|. 115 // output variable |size|.
113 static bool GetSizeFromSharedMemoryHandle(const SharedMemoryHandle& handle, 116 static bool GetSizeFromSharedMemoryHandle(const SharedMemoryHandle& handle,
114 size_t* size); 117 size_t* size);
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
246 // Close(); 249 // Close();
247 // return ok; 250 // return ok;
248 // Note that the memory is unmapped by calling this method, regardless of the 251 // Note that the memory is unmapped by calling this method, regardless of the
249 // return value. 252 // return value.
250 bool GiveToProcess(ProcessHandle process, 253 bool GiveToProcess(ProcessHandle process,
251 SharedMemoryHandle* new_handle) { 254 SharedMemoryHandle* new_handle) {
252 return ShareToProcessCommon(process, new_handle, true, SHARE_CURRENT_MODE); 255 return ShareToProcessCommon(process, new_handle, true, SHARE_CURRENT_MODE);
253 } 256 }
254 257
255 private: 258 private:
256 #if defined(OS_POSIX) && !defined(OS_NACL) && !defined(OS_ANDROID) && \ 259 #if defined(OS_POSIX) && !defined(OS_NACL) && !defined(OS_ANDROID)
257 !(defined(OS_MACOSX) && !defined(OS_IOS))
258 bool PrepareMapFile(ScopedFILE fp, ScopedFD readonly); 260 bool PrepareMapFile(ScopedFILE fp, ScopedFD readonly);
261 #if !(defined(OS_MACOSX) && !defined(OS_IOS))
259 bool FilePathForMemoryName(const std::string& mem_name, FilePath* path); 262 bool FilePathForMemoryName(const std::string& mem_name, FilePath* path);
260 #endif 263 #endif
264 #endif // defined(OS_POSIX) && !defined(OS_NACL) && !defined(OS_ANDROID)
261 enum ShareMode { 265 enum ShareMode {
262 SHARE_READONLY, 266 SHARE_READONLY,
263 SHARE_CURRENT_MODE, 267 SHARE_CURRENT_MODE,
264 }; 268 };
265 bool ShareToProcessCommon(ProcessHandle process, 269 bool ShareToProcessCommon(ProcessHandle process,
266 SharedMemoryHandle* new_handle, 270 SharedMemoryHandle* new_handle,
267 bool close_self, 271 bool close_self,
268 ShareMode); 272 ShareMode);
269 273
270 #if defined(OS_WIN) 274 #if defined(OS_WIN)
271 // If true indicates this came from an external source so needs extra checks 275 // If true indicates this came from an external source so needs extra checks
272 // before being mapped. 276 // before being mapped.
273 bool external_section_; 277 bool external_section_;
274 std::wstring name_; 278 std::wstring name_;
275 win::ScopedHandle mapped_file_; 279 win::ScopedHandle mapped_file_;
276 #elif defined(OS_MACOSX) && !defined(OS_IOS) 280 #elif defined(OS_MACOSX) && !defined(OS_IOS)
277 // The OS primitive that backs the shared memory region. 281 // The OS primitive that backs the shared memory region.
278 SharedMemoryHandle shm_; 282 SharedMemoryHandle shm_;
283
284 // The mechanism by which the memory is mapped. Only valid if |memory_| is not
285 // |nullptr|.
286 SharedMemoryHandle::Type mapped_memory_mechanism_;
287
288 int readonly_mapped_file_;
279 #elif defined(OS_POSIX) 289 #elif defined(OS_POSIX)
280 int mapped_file_; 290 int mapped_file_;
281 int readonly_mapped_file_; 291 int readonly_mapped_file_;
282 #endif 292 #endif
283 size_t mapped_size_; 293 size_t mapped_size_;
284 void* memory_; 294 void* memory_;
285 bool read_only_; 295 bool read_only_;
286 size_t requested_size_; 296 size_t requested_size_;
287 297
288 DISALLOW_COPY_AND_ASSIGN(SharedMemory); 298 DISALLOW_COPY_AND_ASSIGN(SharedMemory);
289 }; 299 };
290 } // namespace base 300 } // namespace base
291 301
292 #endif // BASE_MEMORY_SHARED_MEMORY_H_ 302 #endif // BASE_MEMORY_SHARED_MEMORY_H_
OLDNEW
« no previous file with comments | « no previous file | base/memory/shared_memory_handle.h » ('j') | base/memory/shared_memory_handle.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698