Chromium Code Reviews| 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 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 170 | 170 |
| 171 bool SharedMemoryHandle::MapAt(off_t offset, | 171 bool SharedMemoryHandle::MapAt(off_t offset, |
| 172 size_t bytes, | 172 size_t bytes, |
| 173 void** memory, | 173 void** memory, |
| 174 bool read_only) { | 174 bool read_only) { |
| 175 DCHECK(IsValid()); | 175 DCHECK(IsValid()); |
| 176 switch (type_) { | 176 switch (type_) { |
| 177 case SharedMemoryHandle::POSIX: | 177 case SharedMemoryHandle::POSIX: |
| 178 *memory = mmap(nullptr, bytes, PROT_READ | (read_only ? 0 : PROT_WRITE), | 178 *memory = mmap(nullptr, bytes, PROT_READ | (read_only ? 0 : PROT_WRITE), |
| 179 MAP_SHARED, file_descriptor_.fd, offset); | 179 MAP_SHARED, file_descriptor_.fd, offset); |
| 180 | |
|
Alexei Svitkine (slow)
2016/12/09 22:23:41
Nit: Remove extra diff here.
| |
| 181 return *memory && *memory != reinterpret_cast<void*>(-1); | 180 return *memory && *memory != reinterpret_cast<void*>(-1); |
| 182 case SharedMemoryHandle::MACH: | 181 case SharedMemoryHandle::MACH: |
| 183 DCHECK_EQ(pid_, GetCurrentProcId()); | 182 DCHECK_EQ(pid_, GetCurrentProcId()); |
| 184 kern_return_t kr = mach_vm_map( | 183 kern_return_t kr = mach_vm_map( |
| 185 mach_task_self(), | 184 mach_task_self(), |
| 186 reinterpret_cast<mach_vm_address_t*>(memory), // Output parameter | 185 reinterpret_cast<mach_vm_address_t*>(memory), // Output parameter |
| 187 bytes, | 186 bytes, |
| 188 0, // Alignment mask | 187 0, // Alignment mask |
| 189 VM_FLAGS_ANYWHERE, memory_object_, offset, | 188 VM_FLAGS_ANYWHERE, memory_object_, offset, |
| 190 FALSE, // Copy | 189 FALSE, // Copy |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 230 case MACH: | 229 case MACH: |
| 231 memory_object_ = handle.memory_object_; | 230 memory_object_ = handle.memory_object_; |
| 232 size_ = handle.size_; | 231 size_ = handle.size_; |
| 233 pid_ = handle.pid_; | 232 pid_ = handle.pid_; |
| 234 ownership_passes_to_ipc_ = handle.ownership_passes_to_ipc_; | 233 ownership_passes_to_ipc_ = handle.ownership_passes_to_ipc_; |
| 235 break; | 234 break; |
| 236 } | 235 } |
| 237 } | 236 } |
| 238 | 237 |
| 239 } // namespace base | 238 } // namespace base |
| OLD | NEW |