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 "build/build_config.h" | 8 #include "build/build_config.h" |
9 | 9 |
10 #if defined(OS_WIN) | 10 #if defined(OS_WIN) |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
149 | 149 |
150 // The SharedMemoryHandle must be valid. | 150 // The SharedMemoryHandle must be valid. |
151 // Returns whether the SharedMemoryHandle was successfully mapped into memory. | 151 // Returns whether the SharedMemoryHandle was successfully mapped into memory. |
152 // On success, |memory| is an output variable that contains the start of the | 152 // On success, |memory| is an output variable that contains the start of the |
153 // mapped memory. | 153 // mapped memory. |
154 bool MapAt(off_t offset, size_t bytes, void** memory, bool read_only); | 154 bool MapAt(off_t offset, size_t bytes, void** memory, bool read_only); |
155 | 155 |
156 // Closes the underlying OS primitive. | 156 // Closes the underlying OS primitive. |
157 void Close() const; | 157 void Close() const; |
158 | 158 |
159 void SetOwnershipPassesToIPC(bool ownership_passes); | |
160 bool OwnershipPassesToIPC() const; | |
161 | |
162 private: | 159 private: |
163 // Shared code between copy constructor and operator=. | 160 // Shared code between copy constructor and operator=. |
164 void CopyRelevantData(const SharedMemoryHandle& handle); | 161 void CopyRelevantData(const SharedMemoryHandle& handle); |
165 | 162 |
166 Type type_; | 163 Type type_; |
167 | 164 |
168 // Each instance of a SharedMemoryHandle is backed either by a POSIX fd or a | 165 // Each instance of a SharedMemoryHandle is backed either by a POSIX fd or a |
169 // mach port. |type_| determines the backing member. | 166 // mach port. |type_| determines the backing member. |
170 union { | 167 union { |
171 FileDescriptor file_descriptor_; | 168 FileDescriptor file_descriptor_; |
172 | 169 |
173 struct { | 170 struct { |
174 mach_port_t memory_object_; | 171 mach_port_t memory_object_; |
175 | 172 |
176 // The size of the shared memory region when |type_| is MACH. Only | 173 // The size of the shared memory region when |type_| is MACH. Only |
177 // relevant if |memory_object_| is not |MACH_PORT_NULL|. | 174 // relevant if |memory_object_| is not |MACH_PORT_NULL|. |
178 mach_vm_size_t size_; | 175 mach_vm_size_t size_; |
179 | 176 |
180 // The pid of the process in which |memory_object_| is usable. Only | 177 // The pid of the process in which |memory_object_| is usable. Only |
181 // relevant if |memory_object_| is not |MACH_PORT_NULL|. | 178 // relevant if |memory_object_| is not |MACH_PORT_NULL|. |
182 base::ProcessId pid_; | 179 base::ProcessId pid_; |
183 | |
184 // Whether passing this object as a parameter to an IPC message passes | |
185 // ownership of |memory_object_| to the IPC stack. This is meant to mimic | |
186 // the behavior of the |auto_close| parameter of FileDescriptor. | |
187 // Defaults to |false|. | |
188 bool ownership_passes_to_ipc_; | |
189 }; | 180 }; |
190 }; | 181 }; |
191 }; | 182 }; |
192 #endif | 183 #endif |
193 | 184 |
194 } // namespace base | 185 } // namespace base |
195 | 186 |
196 #endif // BASE_MEMORY_SHARED_MEMORY_HANDLE_H_ | 187 #endif // BASE_MEMORY_SHARED_MEMORY_HANDLE_H_ |
OLD | NEW |