void makeLargeMallocFailSilently() { malloc_zone_t* zone = malloc_default_zone(); #if __MAC_OS_X_VERSION_MIN_REQUIRED >= 1070 mach_vm_address_t pageStart = reinterpret_cast<vm_address_t>(zone) & static_cast<vm_size_t>(~(getpagesize() - 1)); vm_prot_t initialProtection = protectionOfRegion(pageStart); vm_size_t len = reinterpret_cast<vm_address_t>(zone) - pageStart + sizeof(malloc_zone_t); if (mach_vm_protect(mach_task_self(), pageStart, len, 0, initialProtection | VM_PROT_WRITE)) CRASH(); #endif savedMalloc = zone->malloc; savedRealloc = zone->realloc; zone->malloc = checkedMalloc; zone->realloc = checkedRealloc; #if __MAC_OS_X_VERSION_MIN_REQUIRED >= 1070 if (mach_vm_protect(mach_task_self(), pageStart, len, 0, initialProtection)) CRASH(); #endif }
void makeLargeMallocFailSilently() { malloc_zone_t* zone = malloc_default_zone(); #if !defined(BUILDING_ON_TIGER) && !defined(BUILDING_ON_LEOPARD) && !defined(BUILDING_ON_SNOW_LEOPARD) mach_vm_address_t pageStart = reinterpret_cast<vm_address_t>(zone) & static_cast<vm_size_t>(~(getpagesize() - 1)); vm_prot_t initialProtection = protectionOfRegion(pageStart); vm_size_t len = reinterpret_cast<vm_address_t>(zone) - pageStart + sizeof(malloc_zone_t); if (mach_vm_protect(mach_task_self(), pageStart, len, 0, initialProtection | VM_PROT_WRITE)) CRASH(); #endif savedMalloc = zone->malloc; savedRealloc = zone->realloc; zone->malloc = checkedMalloc; zone->realloc = checkedRealloc; #if !defined(BUILDING_ON_TIGER) && !defined(BUILDING_ON_LEOPARD) && !defined(BUILDING_ON_SNOW_LEOPARD) if (mach_vm_protect(mach_task_self(), pageStart, len, 0, initialProtection)) CRASH(); #endif }