| 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> |
| 11 | 11 |
| 12 #include "base/logging.h" |
| 12 #include "base/mac/mac_util.h" | 13 #include "base/mac/mac_util.h" |
| 13 #include "base/mac/mach_logging.h" | 14 #include "base/mac/mach_logging.h" |
| 14 #include "base/posix/eintr_wrapper.h" | 15 #include "base/posix/eintr_wrapper.h" |
| 15 | 16 |
| 16 namespace base { | 17 namespace base { |
| 17 | 18 |
| 18 SharedMemoryHandle::SharedMemoryHandle() | 19 SharedMemoryHandle::SharedMemoryHandle() |
| 19 : type_(MACH), memory_object_(MACH_PORT_NULL) {} | 20 : type_(MACH), memory_object_(MACH_PORT_NULL) {} |
| 20 | 21 |
| 21 SharedMemoryHandle::SharedMemoryHandle( | 22 SharedMemoryHandle::SharedMemoryHandle( |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 62 CopyRelevantData(handle); | 63 CopyRelevantData(handle); |
| 63 return *this; | 64 return *this; |
| 64 } | 65 } |
| 65 | 66 |
| 66 SharedMemoryHandle SharedMemoryHandle::Duplicate() const { | 67 SharedMemoryHandle SharedMemoryHandle::Duplicate() const { |
| 67 switch (type_) { | 68 switch (type_) { |
| 68 case POSIX: { | 69 case POSIX: { |
| 69 if (!IsValid()) | 70 if (!IsValid()) |
| 70 return SharedMemoryHandle(); | 71 return SharedMemoryHandle(); |
| 71 int duped_fd = HANDLE_EINTR(dup(file_descriptor_.fd)); | 72 int duped_fd = HANDLE_EINTR(dup(file_descriptor_.fd)); |
| 72 if (duped_fd < 0) | 73 if (duped_fd < 0) { |
| 74 DPLOG(ERROR) << "dup() failed."; |
| 73 return SharedMemoryHandle(); | 75 return SharedMemoryHandle(); |
| 76 } |
| 74 return SharedMemoryHandle(FileDescriptor(duped_fd, true)); | 77 return SharedMemoryHandle(FileDescriptor(duped_fd, true)); |
| 75 } | 78 } |
| 76 case MACH: { | 79 case MACH: { |
| 77 if (!IsValid()) | 80 if (!IsValid()) |
| 78 return SharedMemoryHandle(); | 81 return SharedMemoryHandle(); |
| 79 | 82 |
| 80 // Increment the ref count. | 83 // Increment the ref count. |
| 81 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_, |
| 82 MACH_PORT_RIGHT_SEND, 1); | 85 MACH_PORT_RIGHT_SEND, 1); |
| 83 DCHECK_EQ(kr, KERN_SUCCESS); | 86 DCHECK_EQ(kr, KERN_SUCCESS); |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 185 break; | 188 break; |
| 186 case MACH: | 189 case MACH: |
| 187 memory_object_ = handle.memory_object_; | 190 memory_object_ = handle.memory_object_; |
| 188 size_ = handle.size_; | 191 size_ = handle.size_; |
| 189 ownership_passes_to_ipc_ = handle.ownership_passes_to_ipc_; | 192 ownership_passes_to_ipc_ = handle.ownership_passes_to_ipc_; |
| 190 break; | 193 break; |
| 191 } | 194 } |
| 192 } | 195 } |
| 193 | 196 |
| 194 } // namespace base | 197 } // namespace base |
| OLD | NEW |