Index: base/allocator/allocator_shim_default_dispatch_to_mac_zoned_malloc.cc |
diff --git a/base/allocator/allocator_shim_default_dispatch_to_mac_zoned_malloc.cc b/base/allocator/allocator_shim_default_dispatch_to_mac_zoned_malloc.cc |
index aabda1950cb290a5b2659e7a370551aea9613f1a..32898ef373395a826378a21fa705e8b5db621943 100644 |
--- a/base/allocator/allocator_shim_default_dispatch_to_mac_zoned_malloc.cc |
+++ b/base/allocator/allocator_shim_default_dispatch_to_mac_zoned_malloc.cc |
@@ -8,54 +8,53 @@ |
#include "base/allocator/allocator_interception_mac.h" |
#include "base/allocator/allocator_shim.h" |
-#include "base/logging.h" |
+#include "base/allocator/malloc_zone_functions_mac.h" |
namespace base { |
namespace allocator { |
- |
namespace { |
-// This is the zone that the allocator shim will call to actually perform heap |
-// allocations. It should be populated with the original, unintercepted default |
-// malloc zone. |
-MallocZoneFunctions g_default_zone; |
- |
void* MallocImpl(const AllocatorDispatch*, size_t size, void* context) { |
- return g_default_zone.malloc( |
- reinterpret_cast<struct _malloc_zone_t*>(context), size); |
+ MallocZoneFunctions& functions = GetFunctionsForZone(context); |
+ return functions.malloc(reinterpret_cast<struct _malloc_zone_t*>(context), |
+ size); |
} |
void* CallocImpl(const AllocatorDispatch*, |
size_t n, |
size_t size, |
void* context) { |
- return g_default_zone.calloc( |
- reinterpret_cast<struct _malloc_zone_t*>(context), n, size); |
+ MallocZoneFunctions& functions = GetFunctionsForZone(context); |
+ return functions.calloc(reinterpret_cast<struct _malloc_zone_t*>(context), n, |
+ size); |
} |
void* MemalignImpl(const AllocatorDispatch*, |
size_t alignment, |
size_t size, |
void* context) { |
- return g_default_zone.memalign( |
- reinterpret_cast<struct _malloc_zone_t*>(context), alignment, size); |
+ MallocZoneFunctions& functions = GetFunctionsForZone(context); |
+ return functions.memalign(reinterpret_cast<struct _malloc_zone_t*>(context), |
+ alignment, size); |
} |
void* ReallocImpl(const AllocatorDispatch*, |
void* ptr, |
size_t size, |
void* context) { |
- return g_default_zone.realloc( |
- reinterpret_cast<struct _malloc_zone_t*>(context), ptr, size); |
+ MallocZoneFunctions& functions = GetFunctionsForZone(context); |
+ return functions.realloc(reinterpret_cast<struct _malloc_zone_t*>(context), |
+ ptr, size); |
} |
void FreeImpl(const AllocatorDispatch*, void* ptr, void* context) { |
- g_default_zone.free(reinterpret_cast<struct _malloc_zone_t*>(context), ptr); |
+ MallocZoneFunctions& functions = GetFunctionsForZone(context); |
+ functions.free(reinterpret_cast<struct _malloc_zone_t*>(context), ptr); |
} |
size_t GetSizeEstimateImpl(const AllocatorDispatch*, void* ptr, void* context) { |
- return g_default_zone.size(reinterpret_cast<struct _malloc_zone_t*>(context), |
- ptr); |
+ MallocZoneFunctions& functions = GetFunctionsForZone(context); |
+ return functions.size(reinterpret_cast<struct _malloc_zone_t*>(context), ptr); |
} |
unsigned BatchMallocImpl(const AllocatorDispatch* self, |
@@ -63,7 +62,8 @@ unsigned BatchMallocImpl(const AllocatorDispatch* self, |
void** results, |
unsigned num_requested, |
void* context) { |
- return g_default_zone.batch_malloc( |
+ MallocZoneFunctions& functions = GetFunctionsForZone(context); |
+ return functions.batch_malloc( |
reinterpret_cast<struct _malloc_zone_t*>(context), size, results, |
num_requested); |
} |
@@ -72,22 +72,24 @@ void BatchFreeImpl(const AllocatorDispatch* self, |
void** to_be_freed, |
unsigned num_to_be_freed, |
void* context) { |
- g_default_zone.batch_free(reinterpret_cast<struct _malloc_zone_t*>(context), |
- to_be_freed, num_to_be_freed); |
+ MallocZoneFunctions& functions = GetFunctionsForZone(context); |
+ functions.batch_free(reinterpret_cast<struct _malloc_zone_t*>(context), |
+ to_be_freed, num_to_be_freed); |
} |
void FreeDefiniteSizeImpl(const AllocatorDispatch* self, |
void* ptr, |
size_t size, |
void* context) { |
- g_default_zone.free_definite_size( |
+ MallocZoneFunctions& functions = GetFunctionsForZone(context); |
+ functions.free_definite_size( |
reinterpret_cast<struct _malloc_zone_t*>(context), ptr, size); |
} |
} // namespace |
void InitializeDefaultDispatchToMacAllocator() { |
- StoreFunctionsForDefaultZone(&g_default_zone); |
+ StoreFunctionsForAllZones(); |
} |
const AllocatorDispatch AllocatorDispatch::default_dispatch = { |