OLD | NEW |
---|---|
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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_HANDLE_H_ | 5 #ifndef BASE_MEMORY_SHARED_MEMORY_HANDLE_H_ |
6 #define BASE_MEMORY_SHARED_MEMORY_HANDLE_H_ | 6 #define BASE_MEMORY_SHARED_MEMORY_HANDLE_H_ |
7 | 7 |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 | 9 |
10 #include "build/build_config.h" | 10 #include "build/build_config.h" |
11 | 11 |
12 #if defined(OS_WIN) | 12 #if defined(OS_WIN) |
13 #include <windows.h> | 13 #include <windows.h> |
14 #include "base/process/process_handle.h" | 14 #include "base/process/process_handle.h" |
15 #elif defined(OS_MACOSX) && !defined(OS_IOS) | 15 #elif defined(OS_MACOSX) && !defined(OS_IOS) |
16 #include <mach/mach.h> | 16 #include <mach/mach.h> |
17 #include "base/base_export.h" | 17 #include "base/base_export.h" |
18 #include "base/file_descriptor_posix.h" | 18 #include "base/file_descriptor_posix.h" |
19 #include "base/macros.h" | 19 #include "base/macros.h" |
20 #include "base/process/process_handle.h" | 20 #include "base/process/process_handle.h" |
21 #elif defined(OS_POSIX) | 21 #elif defined(OS_POSIX) |
22 #include <sys/types.h> | 22 #include <sys/types.h> |
23 #include "base/file_descriptor_posix.h" | 23 #include "base/file_descriptor_posix.h" |
24 #endif | 24 #endif |
25 | 25 |
26 namespace base { | 26 namespace base { |
27 | 27 |
28 class SharedMemory; | |
29 | |
28 // SharedMemoryHandle is a platform specific type which represents | 30 // SharedMemoryHandle is a platform specific type which represents |
29 // the underlying OS handle to a shared memory segment. | 31 // the underlying OS handle to a shared memory segment. |
30 class BASE_EXPORT SharedMemoryHandle { | 32 class BASE_EXPORT SharedMemoryHandle { |
31 public: | 33 public: |
32 // The default constructor returns an invalid SharedMemoryHandle. | 34 // The default constructor returns an invalid SharedMemoryHandle. |
33 SharedMemoryHandle(); | 35 SharedMemoryHandle(); |
34 | 36 |
35 // Standard copy constructor. The new instance shares the underlying OS | 37 // Standard copy constructor. The new instance shares the underlying OS |
36 // primitives. | 38 // primitives. |
37 SharedMemoryHandle(const SharedMemoryHandle& handle); | 39 SharedMemoryHandle(const SharedMemoryHandle& handle); |
(...skipping 55 matching lines...) Loading... | |
93 // Returns false on a failure to determine the size. On success, populates the | 95 // Returns false on a failure to determine the size. On success, populates the |
94 // output variable |size|. | 96 // output variable |size|. |
95 bool GetSize(size_t* size) const; | 97 bool GetSize(size_t* size) const; |
96 | 98 |
97 // The SharedMemoryHandle must be valid. | 99 // The SharedMemoryHandle must be valid. |
98 // Returns whether the SharedMemoryHandle was successfully mapped into memory. | 100 // Returns whether the SharedMemoryHandle was successfully mapped into memory. |
99 // On success, |memory| is an output variable that contains the start of the | 101 // On success, |memory| is an output variable that contains the start of the |
100 // mapped memory. | 102 // mapped memory. |
101 bool MapAt(off_t offset, size_t bytes, void** memory, bool read_only); | 103 bool MapAt(off_t offset, size_t bytes, void** memory, bool read_only); |
102 #elif defined(OS_WIN) | 104 #elif defined(OS_WIN) |
103 SharedMemoryHandle(HANDLE h); | |
104 | |
105 HANDLE GetHandle() const; | 105 HANDLE GetHandle() const; |
106 #else | 106 #else |
107 // This constructor is deprecated, as it fails to propagate the GUID, which | 107 // This constructor is deprecated, as it fails to propagate the GUID, which |
108 // will be added in the near future. | 108 // will be added in the near future. |
109 // TODO(rockot): Remove this constructor once Mojo supports GUIDs. | 109 // TODO(rockot): Remove this constructor once Mojo supports GUIDs. |
110 // https://crbug.com/713763. | 110 // https://crbug.com/713763. |
111 explicit SharedMemoryHandle(const base::FileDescriptor& file_descriptor); | 111 explicit SharedMemoryHandle(const base::FileDescriptor& file_descriptor); |
112 | 112 |
113 // Creates a SharedMemoryHandle from an |fd| supplied from an external | 113 // Creates a SharedMemoryHandle from an |fd| supplied from an external |
114 // service. | 114 // service. |
(...skipping 32 matching lines...) Loading... | |
147 mach_vm_size_t size_; | 147 mach_vm_size_t size_; |
148 | 148 |
149 // Whether passing this object as a parameter to an IPC message passes | 149 // Whether passing this object as a parameter to an IPC message passes |
150 // ownership of |memory_object_| to the IPC stack. This is meant to mimic | 150 // ownership of |memory_object_| to the IPC stack. This is meant to mimic |
151 // the behavior of the |auto_close| parameter of FileDescriptor. | 151 // the behavior of the |auto_close| parameter of FileDescriptor. |
152 // Defaults to |false|. | 152 // Defaults to |false|. |
153 bool ownership_passes_to_ipc_; | 153 bool ownership_passes_to_ipc_; |
154 }; | 154 }; |
155 }; | 155 }; |
156 #elif defined(OS_WIN) | 156 #elif defined(OS_WIN) |
157 friend class SharedMemory; | |
Nico
2017/05/02 20:37:52
:-(
| |
158 // Takes implicit ownership of |h|. | |
159 SharedMemoryHandle(HANDLE h); | |
160 | |
157 HANDLE handle_; | 161 HANDLE handle_; |
158 | 162 |
159 // Whether passing this object as a parameter to an IPC message passes | 163 // Whether passing this object as a parameter to an IPC message passes |
160 // ownership of |handle_| to the IPC stack. This is meant to mimic the | 164 // ownership of |handle_| to the IPC stack. This is meant to mimic the |
161 // behavior of the |auto_close| parameter of FileDescriptor. This member only | 165 // behavior of the |auto_close| parameter of FileDescriptor. This member only |
162 // affects attachment-brokered SharedMemoryHandles. | 166 // affects attachment-brokered SharedMemoryHandles. |
163 // Defaults to |false|. | 167 // Defaults to |false|. |
164 bool ownership_passes_to_ipc_; | 168 bool ownership_passes_to_ipc_; |
165 #else | 169 #else |
166 FileDescriptor file_descriptor_; | 170 FileDescriptor file_descriptor_; |
167 #endif | 171 #endif |
168 }; | 172 }; |
169 | 173 |
170 } // namespace base | 174 } // namespace base |
171 | 175 |
172 #endif // BASE_MEMORY_SHARED_MEMORY_HANDLE_H_ | 176 #endif // BASE_MEMORY_SHARED_MEMORY_HANDLE_H_ |
OLD | NEW |