We hook the memory related APIs with ourselves' functions, like below:
if ((malloc_get_all_zones(0, nullptr, reinterpret_cast<vm_address_t**>(&allZones), &numZones) == KERN_SUCCESS) && (numZones > 0) && (numZones > 0)) { if (allZones[0] == nullptr ) { return false; } trackZone = allZones[0] trackZone->malloc = &my_malloc; trackZone->calloc = &my_calloc; trackZone->valloc = &my_valloc; trackZone->memalign = &my_memalign; trackZone->free = &my_free; trackZone->free_definite_size = &my_free_definite_size; trackZone->try_free_default = &my_try_free_default; trackZone->realloc = &scf_realloc; }
our functions are called when allocate memory with XCode15+MacOS14.6, but when we upgrade the compiling env to XCode16+MacOS15, it won't work any more.