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

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

Issue 1180693002: Update from https://crrev.com/333737 (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: rebased Created 5 years, 6 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 | « base/memory/memory_pressure_monitor_win_unittest.cc ('k') | base/memory/shared_memory_nacl.cc » ('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 "build/build_config.h" 8 #include "build/build_config.h"
9 9
10 #include <string> 10 #include <string>
(...skipping 16 matching lines...) Expand all
27 27
28 namespace base { 28 namespace base {
29 29
30 class FilePath; 30 class FilePath;
31 31
32 // SharedMemoryHandle is a platform specific type which represents 32 // SharedMemoryHandle is a platform specific type which represents
33 // the underlying OS handle to a shared memory segment. 33 // the underlying OS handle to a shared memory segment.
34 #if defined(OS_WIN) 34 #if defined(OS_WIN)
35 typedef HANDLE SharedMemoryHandle; 35 typedef HANDLE SharedMemoryHandle;
36 #elif defined(OS_POSIX) 36 #elif defined(OS_POSIX)
37 // A SharedMemoryId is sufficient to identify a given shared memory segment on a
38 // system, but insufficient to map it.
39 typedef FileDescriptor SharedMemoryHandle; 37 typedef FileDescriptor SharedMemoryHandle;
40 typedef ino_t SharedMemoryId;
41 #endif 38 #endif
42 39
43 // Options for creating a shared memory object. 40 // Options for creating a shared memory object.
44 struct SharedMemoryCreateOptions { 41 struct SharedMemoryCreateOptions {
45 SharedMemoryCreateOptions() 42 SharedMemoryCreateOptions()
46 : name_deprecated(NULL), 43 : name_deprecated(NULL),
47 size(0), 44 size(0),
48 open_existing_deprecated(false), 45 open_existing_deprecated(false),
49 executable(false), 46 executable(false),
50 share_read_only(false) {} 47 share_read_only(false) {}
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 106
110 // Returns invalid handle (see comment above for exact definition). 107 // Returns invalid handle (see comment above for exact definition).
111 static SharedMemoryHandle NULLHandle(); 108 static SharedMemoryHandle NULLHandle();
112 109
113 // Closes a shared memory handle. 110 // Closes a shared memory handle.
114 static void CloseHandle(const SharedMemoryHandle& handle); 111 static void CloseHandle(const SharedMemoryHandle& handle);
115 112
116 // Returns the maximum number of handles that can be open at once per process. 113 // Returns the maximum number of handles that can be open at once per process.
117 static size_t GetHandleLimit(); 114 static size_t GetHandleLimit();
118 115
116 // Duplicates The underlying OS primitive. Returns NULLHandle() on failure.
117 // The caller is responsible for destroying the duplicated OS primitive.
118 static SharedMemoryHandle DuplicateHandle(const SharedMemoryHandle& handle);
119
120 #if defined(OS_POSIX)
121 // This method requires that the SharedMemoryHandle is backed by a POSIX fd.
122 static int GetFdFromSharedMemoryHandle(const SharedMemoryHandle& handle);
123 #endif
124
125 #if defined(OS_POSIX) && !defined(OS_ANDROID)
126 // Returns the size of the shared memory region referred to by |handle|.
127 // Returns '-1' on a failure to determine the size.
128 static int GetSizeFromSharedMemoryHandle(const SharedMemoryHandle& handle);
129 #endif // defined(OS_POSIX) && !defined(OS_ANDROID)
130
119 // Creates a shared memory object as described by the options struct. 131 // Creates a shared memory object as described by the options struct.
120 // Returns true on success and false on failure. 132 // Returns true on success and false on failure.
121 bool Create(const SharedMemoryCreateOptions& options); 133 bool Create(const SharedMemoryCreateOptions& options);
122 134
123 // Creates and maps an anonymous shared memory segment of size size. 135 // Creates and maps an anonymous shared memory segment of size size.
124 // Returns true on success and false on failure. 136 // Returns true on success and false on failure.
125 bool CreateAndMapAnonymous(size_t size); 137 bool CreateAndMapAnonymous(size_t size);
126 138
127 // Creates an anonymous shared memory segment of size size. 139 // Creates an anonymous shared memory segment of size size.
128 // Returns true on success and false on failure. 140 // Returns true on success and false on failure.
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
185 197
186 // Gets a pointer to the opened memory space if it has been 198 // Gets a pointer to the opened memory space if it has been
187 // Mapped via Map(). Returns NULL if it is not mapped. 199 // Mapped via Map(). Returns NULL if it is not mapped.
188 void *memory() const { return memory_; } 200 void *memory() const { return memory_; }
189 201
190 // Returns the underlying OS handle for this segment. 202 // Returns the underlying OS handle for this segment.
191 // Use of this handle for anything other than an opaque 203 // Use of this handle for anything other than an opaque
192 // identifier is not portable. 204 // identifier is not portable.
193 SharedMemoryHandle handle() const; 205 SharedMemoryHandle handle() const;
194 206
195 #if defined(OS_POSIX) && !defined(OS_NACL)
196 // Returns a unique identifier for this shared memory segment. Inode numbers
197 // are technically only unique to a single filesystem. However, we always
198 // allocate shared memory backing files from the same directory, so will end
199 // up on the same filesystem.
200 SharedMemoryId id() const { return inode_; }
201 #endif
202
203 // Closes the open shared memory segment. The memory will remain mapped if 207 // Closes the open shared memory segment. The memory will remain mapped if
204 // it was previously mapped. 208 // it was previously mapped.
205 // It is safe to call Close repeatedly. 209 // It is safe to call Close repeatedly.
206 void Close(); 210 void Close();
207 211
208 // Shares the shared memory to another process. Attempts to create a 212 // Shares the shared memory to another process. Attempts to create a
209 // platform-specific new_handle which can be used in a remote process to read 213 // platform-specific new_handle which can be used in a remote process to read
210 // the shared memory file. new_handle is an output parameter to receive the 214 // the shared memory file. new_handle is an output parameter to receive the
211 // handle for use in the remote process. 215 // handle for use in the remote process.
212 // 216 //
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
282 SharedMemoryHandle* new_handle, 286 SharedMemoryHandle* new_handle,
283 bool close_self, 287 bool close_self,
284 ShareMode); 288 ShareMode);
285 289
286 #if defined(OS_WIN) 290 #if defined(OS_WIN)
287 std::wstring name_; 291 std::wstring name_;
288 HANDLE mapped_file_; 292 HANDLE mapped_file_;
289 #elif defined(OS_POSIX) 293 #elif defined(OS_POSIX)
290 int mapped_file_; 294 int mapped_file_;
291 int readonly_mapped_file_; 295 int readonly_mapped_file_;
292 ino_t inode_;
293 #endif 296 #endif
294 size_t mapped_size_; 297 size_t mapped_size_;
295 void* memory_; 298 void* memory_;
296 bool read_only_; 299 bool read_only_;
297 size_t requested_size_; 300 size_t requested_size_;
298 #if !defined(OS_POSIX) 301 #if !defined(OS_POSIX)
299 HANDLE lock_; 302 HANDLE lock_;
300 #endif 303 #endif
301 304
302 DISALLOW_COPY_AND_ASSIGN(SharedMemory); 305 DISALLOW_COPY_AND_ASSIGN(SharedMemory);
(...skipping 14 matching lines...) Expand all
317 } 320 }
318 321
319 private: 322 private:
320 SharedMemory* shared_memory_; 323 SharedMemory* shared_memory_;
321 DISALLOW_COPY_AND_ASSIGN(SharedMemoryAutoLockDeprecated); 324 DISALLOW_COPY_AND_ASSIGN(SharedMemoryAutoLockDeprecated);
322 }; 325 };
323 326
324 } // namespace base 327 } // namespace base
325 328
326 #endif // BASE_MEMORY_SHARED_MEMORY_H_ 329 #endif // BASE_MEMORY_SHARED_MEMORY_H_
OLDNEW
« no previous file with comments | « base/memory/memory_pressure_monitor_win_unittest.cc ('k') | base/memory/shared_memory_nacl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698