Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(218)

Unified Diff: base/allocator/allocator_shim_default_dispatch_to_mac_zoned_malloc.cc

Issue 2703803004: macOS: Shim all malloc zones. (Closed)
Patch Set: Add a memory barrier. Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..be78fc175a175c59b5b3eb35bcda1a4930dc9fd0 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
@@ -13,49 +13,47 @@
namespace base {
namespace allocator {
-namespace {
+// This aggregator holds all relevant information about the original malloc
+// zones. Avoid using a LeakyInstance since performance is very important, and
Mark Mentovai 2017/02/21 22:52:50 Did you mean LazyInstance (or perhaps a leaky Lazy
erikchen 2017/02/21 23:44:33 created a static member instead.
+// we want to avoid an extra pointer dereference.
Mark Mentovai 2017/02/21 22:52:50 Hmm. This isn’t wonderful. We don’t want to have a
erikchen 2017/02/21 23:44:33 created a static member instead.
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wexit-time-destructors"
+MallocZoneAggregator g_aggregator;
+#pragma clang diagnostic pop
-// 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;
+namespace {
void* MallocImpl(const AllocatorDispatch*, size_t size, void* context) {
- return g_default_zone.malloc(
- reinterpret_cast<struct _malloc_zone_t*>(context), size);
+ return g_aggregator.DispatchMallocToZone(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);
+ return g_aggregator.DispatchCallocToZone(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);
+ return g_aggregator.DispatchMemalignToZone(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);
+ return g_aggregator.DispatchReallocToZone(context, ptr, size);
}
void FreeImpl(const AllocatorDispatch*, void* ptr, void* context) {
- g_default_zone.free(reinterpret_cast<struct _malloc_zone_t*>(context), ptr);
+ g_aggregator.DispatchFreeToZone(context, ptr);
}
size_t GetSizeEstimateImpl(const AllocatorDispatch*, void* ptr, void* context) {
- return g_default_zone.size(reinterpret_cast<struct _malloc_zone_t*>(context),
- ptr);
+ return g_aggregator.DispatchGetSizeEstimateToZone(context, ptr);
}
unsigned BatchMallocImpl(const AllocatorDispatch* self,
@@ -63,31 +61,28 @@ unsigned BatchMallocImpl(const AllocatorDispatch* self,
void** results,
unsigned num_requested,
void* context) {
- return g_default_zone.batch_malloc(
- reinterpret_cast<struct _malloc_zone_t*>(context), size, results,
- num_requested);
+ return g_aggregator.DispatchBatchMallocToZone(context, size, results,
+ num_requested);
}
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);
+ g_aggregator.DispatchBatchFreeToZone(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(
- reinterpret_cast<struct _malloc_zone_t*>(context), ptr, size);
+ g_aggregator.DispatchFreeDefiniteSizeToZone(context, ptr, size);
}
} // namespace
void InitializeDefaultDispatchToMacAllocator() {
- StoreFunctionsForDefaultZone(&g_default_zone);
+ StoreFunctionsForAllZones(&g_aggregator);
}
const AllocatorDispatch AllocatorDispatch::default_dispatch = {

Powered by Google App Engine
This is Rietveld 408576698