| 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 #include "base/memory/shared_memory_handle.h" | 5 #include "base/memory/shared_memory_handle.h" |
| 6 | 6 |
| 7 #include <mach/mach_vm.h> | 7 #include <mach/mach_vm.h> |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 #include <sys/mman.h> | 9 #include <sys/mman.h> |
| 10 #include <unistd.h> | 10 #include <unistd.h> |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 84 kern_return_t kr = mach_port_mod_refs(mach_task_self(), memory_object_, | 84 kern_return_t kr = mach_port_mod_refs(mach_task_self(), memory_object_, |
| 85 MACH_PORT_RIGHT_SEND, 1); | 85 MACH_PORT_RIGHT_SEND, 1); |
| 86 DCHECK_EQ(kr, KERN_SUCCESS); | 86 DCHECK_EQ(kr, KERN_SUCCESS); |
| 87 SharedMemoryHandle handle(*this); | 87 SharedMemoryHandle handle(*this); |
| 88 handle.SetOwnershipPassesToIPC(true); | 88 handle.SetOwnershipPassesToIPC(true); |
| 89 return handle; | 89 return handle; |
| 90 } | 90 } |
| 91 } | 91 } |
| 92 } | 92 } |
| 93 | 93 |
| 94 bool SharedMemoryHandle::operator==(const SharedMemoryHandle& handle) const { | |
| 95 if (!IsValid() && !handle.IsValid()) | |
| 96 return true; | |
| 97 | |
| 98 if (type_ != handle.type_) | |
| 99 return false; | |
| 100 | |
| 101 switch (type_) { | |
| 102 case POSIX: | |
| 103 return file_descriptor_.fd == handle.file_descriptor_.fd; | |
| 104 case MACH: | |
| 105 return memory_object_ == handle.memory_object_ && size_ == handle.size_ && | |
| 106 pid_ == handle.pid_; | |
| 107 } | |
| 108 } | |
| 109 | |
| 110 bool SharedMemoryHandle::operator!=(const SharedMemoryHandle& handle) const { | |
| 111 return !(*this == handle); | |
| 112 } | |
| 113 | |
| 114 bool SharedMemoryHandle::IsValid() const { | 94 bool SharedMemoryHandle::IsValid() const { |
| 115 switch (type_) { | 95 switch (type_) { |
| 116 case POSIX: | 96 case POSIX: |
| 117 return file_descriptor_.fd >= 0; | 97 return file_descriptor_.fd >= 0; |
| 118 case MACH: | 98 case MACH: |
| 119 return memory_object_ != MACH_PORT_NULL; | 99 return memory_object_ != MACH_PORT_NULL; |
| 120 } | 100 } |
| 121 } | 101 } |
| 122 | 102 |
| 123 mach_port_t SharedMemoryHandle::GetMemoryObject() const { | 103 mach_port_t SharedMemoryHandle::GetMemoryObject() const { |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 210 case MACH: | 190 case MACH: |
| 211 memory_object_ = handle.memory_object_; | 191 memory_object_ = handle.memory_object_; |
| 212 size_ = handle.size_; | 192 size_ = handle.size_; |
| 213 pid_ = handle.pid_; | 193 pid_ = handle.pid_; |
| 214 ownership_passes_to_ipc_ = handle.ownership_passes_to_ipc_; | 194 ownership_passes_to_ipc_ = handle.ownership_passes_to_ipc_; |
| 215 break; | 195 break; |
| 216 } | 196 } |
| 217 } | 197 } |
| 218 | 198 |
| 219 } // namespace base | 199 } // namespace base |
| OLD | NEW |