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 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
76 // Makes a Mach-based SharedMemoryHandle of the given size. On error, | 76 // Makes a Mach-based SharedMemoryHandle of the given size. On error, |
77 // subsequent calls to IsValid() return false. | 77 // subsequent calls to IsValid() return false. |
78 explicit SharedMemoryHandle(mach_vm_size_t size); | 78 explicit SharedMemoryHandle(mach_vm_size_t size); |
79 | 79 |
80 // Makes a Mach-based SharedMemoryHandle from |memory_object|, a named entry | 80 // Makes a Mach-based SharedMemoryHandle from |memory_object|, a named entry |
81 // in the task with process id |pid|. The memory region has size |size|. | 81 // in the task with process id |pid|. The memory region has size |size|. |
82 SharedMemoryHandle(mach_port_t memory_object, | 82 SharedMemoryHandle(mach_port_t memory_object, |
83 mach_vm_size_t size, | 83 mach_vm_size_t size, |
84 base::ProcessId pid); | 84 base::ProcessId pid); |
85 | 85 |
86 // Comparison operators. | |
87 bool operator==(const SharedMemoryHandle& handle) const; | |
88 bool operator!=(const SharedMemoryHandle& handle) const; | |
89 | |
90 // Duplicates the underlying OS resources. | 86 // Duplicates the underlying OS resources. |
91 SharedMemoryHandle Duplicate() const; | 87 SharedMemoryHandle Duplicate() const; |
92 | 88 |
93 // Exposed so that the SharedMemoryHandle can be transported between | 89 // Exposed so that the SharedMemoryHandle can be transported between |
94 // processes. | 90 // processes. |
95 mach_port_t GetMemoryObject() const; | 91 mach_port_t GetMemoryObject() const; |
96 | 92 |
97 // Returns false on a failure to determine the size. On success, populates the | 93 // Returns false on a failure to determine the size. On success, populates the |
98 // output variable |size|. | 94 // output variable |size|. |
99 bool GetSize(size_t* size) const; | 95 bool GetSize(size_t* size) const; |
100 | 96 |
101 // The SharedMemoryHandle must be valid. | 97 // The SharedMemoryHandle must be valid. |
102 // Returns whether the SharedMemoryHandle was successfully mapped into memory. | 98 // Returns whether the SharedMemoryHandle was successfully mapped into memory. |
103 // On success, |memory| is an output variable that contains the start of the | 99 // On success, |memory| is an output variable that contains the start of the |
104 // mapped memory. | 100 // mapped memory. |
105 bool MapAt(off_t offset, size_t bytes, void** memory, bool read_only); | 101 bool MapAt(off_t offset, size_t bytes, void** memory, bool read_only); |
106 #elif defined(OS_WIN) | 102 #elif defined(OS_WIN) |
107 SharedMemoryHandle(HANDLE h, base::ProcessId pid); | 103 SharedMemoryHandle(HANDLE h, base::ProcessId pid); |
108 | 104 |
109 // Comparison operators. | |
110 bool operator==(const SharedMemoryHandle& handle) const; | |
111 bool operator!=(const SharedMemoryHandle& handle) const; | |
112 | |
113 // Whether |pid_| is the same as the current process's id. | 105 // Whether |pid_| is the same as the current process's id. |
114 bool BelongsToCurrentProcess() const; | 106 bool BelongsToCurrentProcess() const; |
115 | 107 |
116 // Whether handle_ needs to be duplicated into the destination process when | 108 // Whether handle_ needs to be duplicated into the destination process when |
117 // an instance of this class is passed over a Chrome IPC channel. | 109 // an instance of this class is passed over a Chrome IPC channel. |
118 bool NeedsBrokering() const; | 110 bool NeedsBrokering() const; |
119 | 111 |
120 HANDLE GetHandle() const; | 112 HANDLE GetHandle() const; |
121 base::ProcessId GetPID() const; | 113 base::ProcessId GetPID() const; |
122 #else | 114 #else |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
190 // Defaults to |false|. | 182 // Defaults to |false|. |
191 bool ownership_passes_to_ipc_; | 183 bool ownership_passes_to_ipc_; |
192 #else | 184 #else |
193 FileDescriptor file_descriptor_; | 185 FileDescriptor file_descriptor_; |
194 #endif | 186 #endif |
195 }; | 187 }; |
196 | 188 |
197 } // namespace base | 189 } // namespace base |
198 | 190 |
199 #endif // BASE_MEMORY_SHARED_MEMORY_HANDLE_H_ | 191 #endif // BASE_MEMORY_SHARED_MEMORY_HANDLE_H_ |
OLD | NEW |