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 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
85 // that |read_only| matches the permissions of the handle. | 85 // that |read_only| matches the permissions of the handle. |
86 SharedMemory(const SharedMemoryHandle& handle, bool read_only); | 86 SharedMemory(const SharedMemoryHandle& handle, bool read_only); |
87 | 87 |
88 // Closes any open files. | 88 // Closes any open files. |
89 ~SharedMemory(); | 89 ~SharedMemory(); |
90 | 90 |
91 // Return true iff the given handle is valid (i.e. not the distingished | 91 // Return true iff the given handle is valid (i.e. not the distingished |
92 // invalid value; NULL for a HANDLE and -1 for a file descriptor) | 92 // invalid value; NULL for a HANDLE and -1 for a file descriptor) |
93 static bool IsHandleValid(const SharedMemoryHandle& handle); | 93 static bool IsHandleValid(const SharedMemoryHandle& handle); |
94 | 94 |
95 // Returns invalid handle (see comment above for exact definition). | |
96 static SharedMemoryHandle NULLHandle(); | |
97 | |
98 // Closes a shared memory handle. | 95 // Closes a shared memory handle. |
99 static void CloseHandle(const SharedMemoryHandle& handle); | 96 static void CloseHandle(const SharedMemoryHandle& handle); |
100 | 97 |
101 // 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. |
102 static size_t GetHandleLimit(); | 99 static size_t GetHandleLimit(); |
103 | 100 |
104 // Duplicates The underlying OS primitive. Returns NULLHandle() on failure. | 101 // Duplicates The underlying OS primitive. Returns an invalid handle on |
105 // The caller is responsible for destroying the duplicated OS primitive. | 102 // failure. The caller is responsible for destroying the duplicated OS |
| 103 // primitive. |
106 static SharedMemoryHandle DuplicateHandle(const SharedMemoryHandle& handle); | 104 static SharedMemoryHandle DuplicateHandle(const SharedMemoryHandle& handle); |
107 | 105 |
108 #if defined(OS_POSIX) | 106 #if defined(OS_POSIX) |
109 // This method requires that the SharedMemoryHandle is backed by a POSIX fd. | 107 // This method requires that the SharedMemoryHandle is backed by a POSIX fd. |
110 static int GetFdFromSharedMemoryHandle(const SharedMemoryHandle& handle); | 108 static int GetFdFromSharedMemoryHandle(const SharedMemoryHandle& handle); |
111 #endif | 109 #endif |
112 | 110 |
113 #if defined(OS_POSIX) && !defined(OS_ANDROID) | 111 #if defined(OS_POSIX) && !defined(OS_ANDROID) |
114 // Gets the size of the shared memory region referred to by |handle|. | 112 // Gets the size of the shared memory region referred to by |handle|. |
115 // Returns false on a failure to determine the size. On success, populates the | 113 // Returns false on a failure to determine the size. On success, populates the |
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
315 void* memory_; | 313 void* memory_; |
316 bool read_only_; | 314 bool read_only_; |
317 size_t requested_size_; | 315 size_t requested_size_; |
318 | 316 |
319 DISALLOW_COPY_AND_ASSIGN(SharedMemory); | 317 DISALLOW_COPY_AND_ASSIGN(SharedMemory); |
320 }; | 318 }; |
321 | 319 |
322 } // namespace base | 320 } // namespace base |
323 | 321 |
324 #endif // BASE_MEMORY_SHARED_MEMORY_H_ | 322 #endif // BASE_MEMORY_SHARED_MEMORY_H_ |
OLD | NEW |