SharedMemory::~SharedMemory() { if (m_data) { kern_return_t kr = mach_vm_deallocate(mach_task_self(), toVMAddress(m_data), round_page(m_size)); #if RELEASE_LOG_DISABLED ASSERT_UNUSED(kr, kr == KERN_SUCCESS); #else if (kr != KERN_SUCCESS) { RELEASE_LOG_ERROR(VirtualMemory, "%p - SharedMemory::~SharedMemory: Failed to deallocate shared memory. %{public}s (%x)", this, mach_error_string(kr), kr); ASSERT_NOT_REACHED(); } #endif } if (m_port) { kern_return_t kr = mach_port_deallocate(mach_task_self(), m_port); #if RELEASE_LOG_DISABLED ASSERT_UNUSED(kr, kr == KERN_SUCCESS); #else if (kr != KERN_SUCCESS) { RELEASE_LOG_ERROR(VirtualMemory, "%p - SharedMemory::~SharedMemory: Failed to deallocate port. %{public}s (%x)", this, mach_error_string(kr), kr); ASSERT_NOT_REACHED(); } #endif } }
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); }
void WebLoaderStrategy::networkProcessCrashed() { RELEASE_LOG_ERROR(Network, "WebLoaderStrategy::networkProcessCrashed: failing all pending resource loaders"); for (auto& loader : m_webResourceLoaders) scheduleInternallyFailedLoad(*loader.value->resourceLoader()); m_webResourceLoaders.clear(); }
static void didCloseOnConnectionWorkQueue(IPC::Connection*) { // If the connection has been closed and we haven't responded in the main thread for 10 seconds // the process will exit forcibly. auto watchdogDelay = std::chrono::seconds(10); WorkQueue::create("com.apple.WebKit.ChildProcess.WatchDogQueue")->dispatchAfter(watchdogDelay, [] { // We use _exit here since the watchdog callback is called from another thread and we don't want // global destructors or atexit handlers to be called from this thread while the main thread is busy // doing its thing. RELEASE_LOG_ERROR("Exiting process early due to unacknowledged closed-connection"); _exit(EXIT_FAILURE); }); }
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) { #if RELEASE_LOG_DISABLED LOG_ERROR("Failed to create a mach port for shared memory. %s (%x)", mach_error_string(kr), kr); #else RELEASE_LOG_ERROR(VirtualMemory, "%p - SharedMemory::makeMemoryEntry: Failed to create a mach port for shared memory. %{public}s (%x)", nullptr, mach_error_string(kr), kr); #endif return { }; } RELEASE_ASSERT(memoryObjectSize >= size); return WebCore::MachSendRight::adopt(port); }
RefPtr<SharedMemory> SharedMemory::allocate(size_t size) { ASSERT(size); mach_vm_address_t address; kern_return_t kr = mach_vm_allocate(mach_task_self(), &address, round_page(size), VM_FLAGS_ANYWHERE); if (kr != KERN_SUCCESS) { #if RELEASE_LOG_DISABLED LOG_ERROR("Failed to allocate mach_vm_allocate shared memory (%zu bytes). %s (%x)", size, mach_error_string(kr), kr); #else RELEASE_LOG_ERROR(VirtualMemory, "%p - SharedMemory::allocate: Failed to allocate mach_vm_allocate shared memory (%zu bytes). %{public}s (%x)", nullptr, size, mach_error_string(kr), kr); #endif return nullptr; } auto sharedMemory = adoptRef(*new SharedMemory); sharedMemory->m_size = size; sharedMemory->m_data = toPointer(address); sharedMemory->m_port = MACH_PORT_NULL; sharedMemory->m_protection = Protection::ReadWrite; return WTFMove(sharedMemory); }