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" |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
145 // On success, |memory| is an output variable that contains the start of the | 145 // On success, |memory| is an output variable that contains the start of the |
146 // mapped memory. | 146 // mapped memory. |
147 bool MapAt(off_t offset, size_t bytes, void** memory, bool read_only); | 147 bool MapAt(off_t offset, size_t bytes, void** memory, bool read_only); |
148 | 148 |
149 // Closes the underlying OS primitive. | 149 // Closes the underlying OS primitive. |
150 void Close() const; | 150 void Close() const; |
151 | 151 |
152 void SetOwnershipPassesToIPC(bool ownership_passes); | 152 void SetOwnershipPassesToIPC(bool ownership_passes); |
153 bool OwnershipPassesToIPC() const; | 153 bool OwnershipPassesToIPC() const; |
154 | 154 |
| 155 bool GetUniqueID(SharedMemoryHandleID* id) const; |
| 156 |
155 private: | 157 private: |
156 friend class SharedMemory; | 158 friend class SharedMemory; |
157 | 159 |
158 // Shared code between copy constructor and operator=. | 160 // Shared code between copy constructor and operator=. |
159 void CopyRelevantData(const SharedMemoryHandle& handle); | 161 void CopyRelevantData(const SharedMemoryHandle& handle); |
160 | 162 |
161 Type type_; | 163 Type type_; |
162 | 164 |
163 // 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 |
164 // mach port. |type_| determines the backing member. | 166 // mach port. |type_| determines the backing member. |
(...skipping 14 matching lines...) Expand all Loading... |
179 // Whether passing this object as a parameter to an IPC message passes | 181 // Whether passing this object as a parameter to an IPC message passes |
180 // ownership of |memory_object_| to the IPC stack. This is meant to mimic | 182 // ownership of |memory_object_| to the IPC stack. This is meant to mimic |
181 // the behavior of the |auto_close| parameter of FileDescriptor. | 183 // the behavior of the |auto_close| parameter of FileDescriptor. |
182 // Defaults to |false|. | 184 // Defaults to |false|. |
183 bool ownership_passes_to_ipc_; | 185 bool ownership_passes_to_ipc_; |
184 }; | 186 }; |
185 }; | 187 }; |
186 }; | 188 }; |
187 #endif | 189 #endif |
188 | 190 |
| 191 #if defined(OS_POSIX) && !(defined(OS_MACOSX) && !defined(OS_IOS)) |
| 192 struct SharedMemoryHandleID { |
| 193 dev_t device_id; |
| 194 ino_t file_id; |
| 195 }; |
| 196 #elif defined(OS_MACOSX) |
| 197 struct SharedMemoryHandleID { |
| 198 // TODO: On macOS, this might be mach_port_t. |
| 199 dev_t device_id; |
| 200 ino_t file_id; |
| 201 }; |
| 202 #elif defined(OS_WIN) |
| 203 struct SharedMemoryHandleID { |
| 204 DWORD device_id; // BY_HANDLE_FILE_INFORMATION.dwVolumeSerialNumber |
| 205 intt64_t file_id; // BY_HANDLE_FILE_INFORMATION.nFileIndexHigh and Low |
| 206 }; |
| 207 #endif |
| 208 |
| 209 bool GetIDFromSharedMemoryHandle(const SharedMemoryHandle& handle, |
| 210 SharedMemoryHandleID* id); |
| 211 |
| 212 std::string GetSharedMemoryHandleIDString(const SharedMemoryHandleID& id); |
| 213 |
| 214 struct SharedMemoryHandleIDHash { |
| 215 std::size_t operator()(const SharedMemoryHandleID& id) const { |
| 216 return std::hash<int64_t>()(static_cast<int64_t>(id.device_id)) ^ |
| 217 std::hash<int64_t>()(static_cast<int64_t>(id.file_id)); |
| 218 } |
| 219 }; |
| 220 |
| 221 struct SharedMemoryHandleIDEqual { |
| 222 bool operator()(const SharedMemoryHandleID& lhs, |
| 223 const SharedMemoryHandleID& rhs) const { |
| 224 return lhs.device_id == rhs.device_id && lhs.file_id == rhs.file_id; |
| 225 } |
| 226 }; |
| 227 |
189 } // namespace base | 228 } // namespace base |
190 | 229 |
191 #endif // BASE_MEMORY_SHARED_MEMORY_HANDLE_H_ | 230 #endif // BASE_MEMORY_SHARED_MEMORY_HANDLE_H_ |
OLD | NEW |