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

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

Issue 1896443002: Revert of mac: Remove POSIX shared memory. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@temp50_base
Patch Set: Created 4 years, 8 months 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') | no next file with comments »
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 14 matching lines...) Expand all
25 #endif 25 #endif
26 26
27 namespace base { 27 namespace base {
28 28
29 class FilePath; 29 class FilePath;
30 30
31 // Options for creating a shared memory object. 31 // Options for creating a shared memory object.
32 struct BASE_EXPORT SharedMemoryCreateOptions { 32 struct BASE_EXPORT SharedMemoryCreateOptions {
33 SharedMemoryCreateOptions(); 33 SharedMemoryCreateOptions();
34 34
35 #if !(defined(OS_MACOSX) && !defined(OS_IOS)) 35 #if defined(OS_MACOSX) && !defined(OS_IOS)
36 // The type of OS primitive that should back the SharedMemory object.
37 SharedMemoryHandle::Type type;
38 #else
36 // DEPRECATED (crbug.com/345734): 39 // DEPRECATED (crbug.com/345734):
37 // If NULL, the object is anonymous. This pointer is owned by the caller 40 // If NULL, the object is anonymous. This pointer is owned by the caller
38 // and must live through the call to Create(). 41 // and must live through the call to Create().
39 const std::string* name_deprecated; 42 const std::string* name_deprecated;
40 43
41 // DEPRECATED (crbug.com/345734): 44 // DEPRECATED (crbug.com/345734):
42 // If true, and the shared memory already exists, Create() will open the 45 // If true, and the shared memory already exists, Create() will open the
43 // existing shared memory and ignore the size parameter. If false, 46 // existing shared memory and ignore the size parameter. If false,
44 // shared memory must not exist. This flag is meaningless unless 47 // shared memory must not exist. This flag is meaningless unless
45 // name_deprecated is non-NULL. 48 // name_deprecated is non-NULL.
46 bool open_existing_deprecated; 49 bool open_existing_deprecated;
47 #endif // !(defined(OS_MACOSX) && !defined(OS_IOS)) 50 #endif // defined(OS_MACOSX) && !defined(OS_IOS)
48 51
49 // Size of the shared memory object to be created. 52 // Size of the shared memory object to be created.
50 // When opening an existing object, this has no effect. 53 // When opening an existing object, this has no effect.
51 size_t size; 54 size_t size;
52 55
53 // If true, mappings might need to be made executable later. 56 // If true, mappings might need to be made executable later.
54 bool executable; 57 bool executable;
55 58
56 // If true, the file can be shared read-only to a process. 59 // If true, the file can be shared read-only to a process.
57 bool share_read_only; 60 bool share_read_only;
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 // Closes a shared memory handle. 95 // Closes a shared memory handle.
93 static void CloseHandle(const SharedMemoryHandle& handle); 96 static void CloseHandle(const SharedMemoryHandle& handle);
94 97
95 // Returns the maximum number of handles that can be open at once per process. 98 // Returns the maximum number of handles that can be open at once per process.
96 static size_t GetHandleLimit(); 99 static size_t GetHandleLimit();
97 100
98 // Duplicates The underlying OS primitive. Returns NULLHandle() on failure. 101 // Duplicates The underlying OS primitive. Returns NULLHandle() on failure.
99 // The caller is responsible for destroying the duplicated OS primitive. 102 // The caller is responsible for destroying the duplicated OS primitive.
100 static SharedMemoryHandle DuplicateHandle(const SharedMemoryHandle& handle); 103 static SharedMemoryHandle DuplicateHandle(const SharedMemoryHandle& handle);
101 104
102 #if defined(OS_POSIX) && !(defined(OS_MACOSX) && !defined(OS_IOS)) 105 #if defined(OS_POSIX)
103 // This method requires that the SharedMemoryHandle is backed by a POSIX fd. 106 // This method requires that the SharedMemoryHandle is backed by a POSIX fd.
104 static int GetFdFromSharedMemoryHandle(const SharedMemoryHandle& handle); 107 static int GetFdFromSharedMemoryHandle(const SharedMemoryHandle& handle);
105 #endif 108 #endif
106 109
107 #if defined(OS_POSIX) && !defined(OS_ANDROID) 110 #if defined(OS_POSIX) && !defined(OS_ANDROID)
108 // Gets the size of the shared memory region referred to by |handle|. 111 // Gets the size of the shared memory region referred to by |handle|.
109 // Returns false on a failure to determine the size. On success, populates the 112 // Returns false on a failure to determine the size. On success, populates the
110 // output variable |size|. 113 // output variable |size|.
111 static bool GetSizeFromSharedMemoryHandle(const SharedMemoryHandle& handle, 114 static bool GetSizeFromSharedMemoryHandle(const SharedMemoryHandle& handle,
112 size_t* size); 115 size_t* size);
113 #endif // defined(OS_POSIX) && !defined(OS_ANDROID) 116 #endif // defined(OS_POSIX) && !defined(OS_ANDROID)
114 117
115 // Creates a shared memory object as described by the options struct. 118 // Creates a shared memory object as described by the options struct.
116 // Returns true on success and false on failure. 119 // Returns true on success and false on failure.
117 bool Create(const SharedMemoryCreateOptions& options); 120 bool Create(const SharedMemoryCreateOptions& options);
118 121
119 // Creates and maps an anonymous shared memory segment of size size. 122 // Creates and maps an anonymous shared memory segment of size size.
120 // Returns true on success and false on failure. 123 // Returns true on success and false on failure.
121 bool CreateAndMapAnonymous(size_t size); 124 bool CreateAndMapAnonymous(size_t size);
122 125
126 #if defined(OS_MACOSX) && !defined(OS_IOS)
127 // These two methods are analogs of CreateAndMapAnonymous and CreateAnonymous
128 // that force the underlying OS primitive to be a POSIX fd. Do not add new
129 // uses of these methods unless absolutely necessary, since constructing a
130 // fd-backed SharedMemory object frequently takes 100ms+.
131 // http://crbug.com/466437.
132 bool CreateAndMapAnonymousPosix(size_t size);
133 bool CreateAnonymousPosix(size_t size);
134 #endif // defined(OS_MACOSX) && !defined(OS_IOS)
135
123 // Creates an anonymous shared memory segment of size size. 136 // Creates an anonymous shared memory segment of size size.
124 // Returns true on success and false on failure. 137 // Returns true on success and false on failure.
125 bool CreateAnonymous(size_t size) { 138 bool CreateAnonymous(size_t size) {
126 SharedMemoryCreateOptions options; 139 SharedMemoryCreateOptions options;
127 options.size = size; 140 options.size = size;
128 return Create(options); 141 return Create(options);
129 } 142 }
130 143
131 #if !defined(OS_MACOSX) || defined(OS_IOS) 144 #if !defined(OS_MACOSX) || defined(OS_IOS)
132 // DEPRECATED (crbug.com/345734): 145 // DEPRECATED (crbug.com/345734):
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
237 // Close(); 250 // Close();
238 // return ok; 251 // return ok;
239 // Note that the memory is unmapped by calling this method, regardless of the 252 // Note that the memory is unmapped by calling this method, regardless of the
240 // return value. 253 // return value.
241 bool GiveToProcess(ProcessHandle process, 254 bool GiveToProcess(ProcessHandle process,
242 SharedMemoryHandle* new_handle) { 255 SharedMemoryHandle* new_handle) {
243 return ShareToProcessCommon(process, new_handle, true, SHARE_CURRENT_MODE); 256 return ShareToProcessCommon(process, new_handle, true, SHARE_CURRENT_MODE);
244 } 257 }
245 258
246 private: 259 private:
247 #if defined(OS_POSIX) && !defined(OS_NACL) && !defined(OS_ANDROID) && \ 260 #if defined(OS_POSIX) && !defined(OS_NACL) && !defined(OS_ANDROID)
248 !(defined(OS_MACOSX) && !defined(OS_IOS))
249 bool PrepareMapFile(ScopedFILE fp, ScopedFD readonly); 261 bool PrepareMapFile(ScopedFILE fp, ScopedFD readonly);
262 #if !(defined(OS_MACOSX) && !defined(OS_IOS))
250 bool FilePathForMemoryName(const std::string& mem_name, FilePath* path); 263 bool FilePathForMemoryName(const std::string& mem_name, FilePath* path);
251 #endif 264 #endif
265 #endif // defined(OS_POSIX) && !defined(OS_NACL) && !defined(OS_ANDROID)
252 enum ShareMode { 266 enum ShareMode {
253 SHARE_READONLY, 267 SHARE_READONLY,
254 SHARE_CURRENT_MODE, 268 SHARE_CURRENT_MODE,
255 }; 269 };
256 bool ShareToProcessCommon(ProcessHandle process, 270 bool ShareToProcessCommon(ProcessHandle process,
257 SharedMemoryHandle* new_handle, 271 SharedMemoryHandle* new_handle,
258 bool close_self, 272 bool close_self,
259 ShareMode); 273 ShareMode);
260 274
261 #if defined(OS_WIN) 275 #if defined(OS_WIN)
262 // If true indicates this came from an external source so needs extra checks 276 // If true indicates this came from an external source so needs extra checks
263 // before being mapped. 277 // before being mapped.
264 bool external_section_; 278 bool external_section_;
265 std::wstring name_; 279 std::wstring name_;
266 HANDLE mapped_file_; 280 HANDLE mapped_file_;
267 #elif defined(OS_MACOSX) && !defined(OS_IOS) 281 #elif defined(OS_MACOSX) && !defined(OS_IOS)
268 // The OS primitive that backs the shared memory region. 282 // The OS primitive that backs the shared memory region.
269 SharedMemoryHandle shm_; 283 SharedMemoryHandle shm_;
270 284
285 // The mechanism by which the memory is mapped. Only valid if |memory_| is not
286 // |nullptr|.
287 SharedMemoryHandle::Type mapped_memory_mechanism_;
288
271 int readonly_mapped_file_; 289 int readonly_mapped_file_;
272 #elif defined(OS_POSIX) 290 #elif defined(OS_POSIX)
273 int mapped_file_; 291 int mapped_file_;
274 int readonly_mapped_file_; 292 int readonly_mapped_file_;
275 #endif 293 #endif
276 size_t mapped_size_; 294 size_t mapped_size_;
277 void* memory_; 295 void* memory_;
278 bool read_only_; 296 bool read_only_;
279 size_t requested_size_; 297 size_t requested_size_;
280 298
281 DISALLOW_COPY_AND_ASSIGN(SharedMemory); 299 DISALLOW_COPY_AND_ASSIGN(SharedMemory);
282 }; 300 };
283 } // namespace base 301 } // namespace base
284 302
285 #endif // BASE_MEMORY_SHARED_MEMORY_H_ 303 #endif // BASE_MEMORY_SHARED_MEMORY_H_
OLDNEW
« no previous file with comments | « no previous file | base/memory/shared_memory_handle.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698