RefPtr<SharedMemory> SharedMemory::map(const Handle& handle, Protection protection) { if (handle.isNull()) return 0; ASSERT(round_page(handle.m_size) == handle.m_size); vm_prot_t vmProtection = machProtection(protection); mach_vm_address_t mappedAddress = 0; kern_return_t kr = mach_vm_map(mach_task_self(), &mappedAddress, round_page(handle.m_size), 0, VM_FLAGS_ANYWHERE, handle.m_port, 0, false, vmProtection, vmProtection, VM_INHERIT_NONE); #if RELEASE_LOG_DISABLED if (kr != KERN_SUCCESS) return nullptr; #else if (kr != KERN_SUCCESS) { RELEASE_LOG_ERROR(VirtualMemory, "%p - SharedMemory::map: Failed to map shared memory. %{public}s (%x)", nullptr, mach_error_string(kr), kr); return nullptr; } #endif auto sharedMemory(adoptRef(*new SharedMemory)); sharedMemory->m_size = handle.m_size; sharedMemory->m_data = toPointer(mappedAddress); sharedMemory->m_port = MACH_PORT_NULL; sharedMemory->m_protection = protection; return WTFMove(sharedMemory); }
PassRefPtr<SharedMemory> SharedMemory::create(const Handle& handle, Protection protection) { if (handle.isNull()) return 0; // Map the memory. vm_prot_t vmProtection = machProtection(protection); mach_vm_address_t mappedAddress = 0; kern_return_t kr = mach_vm_map(mach_task_self(), &mappedAddress, handle.m_size, 0, VM_FLAGS_ANYWHERE, handle.m_port, 0, false, vmProtection, vmProtection, VM_INHERIT_NONE); if (kr != KERN_SUCCESS) return 0; RefPtr<SharedMemory> sharedMemory(adoptRef(new SharedMemory)); sharedMemory->m_size = handle.m_size; sharedMemory->m_data = toPointer(mappedAddress); return sharedMemory.release(); }
bool SharedMemory::createHandle(Handle& handle, Protection protection) { ASSERT(!handle.m_port); ASSERT(!handle.m_size); mach_vm_address_t address = toVMAddress(m_data); memory_object_size_t size = round_page(m_size); // Create a mach port that represents the shared memory. mach_port_t port; kern_return_t kr = mach_make_memory_entry_64(mach_task_self(), &size, address, machProtection(protection), &port, MACH_PORT_NULL); if (kr != KERN_SUCCESS) return false; handle.m_port = port; handle.m_size = size; return true; }
RefPtr<SharedMemory> SharedMemory::map(const Handle& handle, Protection protection) { if (handle.isNull()) return 0; ASSERT(round_page(handle.m_size) == handle.m_size); vm_prot_t vmProtection = machProtection(protection); mach_vm_address_t mappedAddress = 0; kern_return_t kr = mach_vm_map(mach_task_self(), &mappedAddress, round_page(handle.m_size), 0, VM_FLAGS_ANYWHERE, handle.m_port, 0, false, vmProtection, vmProtection, VM_INHERIT_NONE); if (kr != KERN_SUCCESS) return nullptr; auto sharedMemory(adoptRef(*new SharedMemory)); sharedMemory->m_size = handle.m_size; sharedMemory->m_data = toPointer(mappedAddress); sharedMemory->m_port = MACH_PORT_NULL; sharedMemory->m_protection = protection; return WTFMove(sharedMemory); }
bool SharedMemory::createHandle(Handle& handle, Protection protection) { ASSERT(!handle.m_port); ASSERT(!handle.m_size); mach_vm_address_t address = toVMAddress(m_data); memory_object_size_t size = round_page(m_size); mach_port_t port; if (protection == ReadWrite && m_port) { // Just re-use the port we have. port = m_port; if (mach_port_mod_refs(mach_task_self(), port, MACH_PORT_RIGHT_SEND, 1) != KERN_SUCCESS) return false; } else { // Create a mach port that represents the shared memory. kern_return_t kr = mach_make_memory_entry_64(mach_task_self(), &size, address, machProtection(protection), &port, MACH_PORT_NULL); if (kr != KERN_SUCCESS) return false; ASSERT(size >= round_page(m_size)); } handle.m_port = port; handle.m_size = size; return true; }
static WebCore::MachSendRight makeMemoryEntry(size_t size, vm_offset_t offset, SharedMemory::Protection protection, mach_port_t parentEntry) { memory_object_size_t memoryObjectSize = round_page(size); mach_port_t port; kern_return_t kr = mach_make_memory_entry_64(mach_task_self(), &memoryObjectSize, offset, machProtection(protection) | VM_PROT_IS_MASK | MAP_MEM_VM_SHARE, &port, parentEntry); if (kr != KERN_SUCCESS) { LOG_ERROR("Failed to create a mach port for shared memory. %s (%x)", mach_error_string(kr), kr); return { }; } RELEASE_ASSERT(memoryObjectSize >= size); return WebCore::MachSendRight::adopt(port); }