Hook up allocator shim on mac.

This CL should have no behavioral effect, since the relevant code is not enabled
yet.

allocator_shim_override_mac_symbols.h intercepts heap allocations using the
newly introduced APIs in allocator_interception_mac.h and redirects them to the
allocator shim. This eventually forwards to AllocatorDispatch::default_dispatch,
which in turns calls the original malloc zone functions..

BUG=665567

Review-Url: https://codereview.chromium.org/2658723007
Cr-Commit-Position: refs/heads/master@{#447705}
diff --git a/base/trace_event/malloc_dump_provider.cc b/base/trace_event/malloc_dump_provider.cc
index 4683694d..220b93e 100644
--- a/base/trace_event/malloc_dump_provider.cc
+++ b/base/trace_event/malloc_dump_provider.cc
@@ -82,14 +82,49 @@
   return next->get_size_estimate_function(next, address);
 }
 
+unsigned HookBatchMalloc(const AllocatorDispatch* self,
+                         size_t size,
+                         void** results,
+                         unsigned num_requested) {
+  const AllocatorDispatch* const next = self->next;
+  unsigned count =
+      next->batch_malloc_function(next, size, results, num_requested);
+  for (unsigned i = 0; i < count; ++i) {
+    MallocDumpProvider::GetInstance()->InsertAllocation(results[i], size);
+  }
+  return count;
+}
+
+void HookBatchFree(const AllocatorDispatch* self,
+                   void** to_be_freed,
+                   unsigned num_to_be_freed) {
+  const AllocatorDispatch* const next = self->next;
+  for (unsigned i = 0; i < num_to_be_freed; ++i) {
+    MallocDumpProvider::GetInstance()->RemoveAllocation(to_be_freed[i]);
+  }
+  next->batch_free_function(next, to_be_freed, num_to_be_freed);
+}
+
+void HookFreeDefiniteSize(const AllocatorDispatch* self,
+                          void* ptr,
+                          size_t size) {
+  if (ptr)
+    MallocDumpProvider::GetInstance()->RemoveAllocation(ptr);
+  const AllocatorDispatch* const next = self->next;
+  next->free_definite_size_function(next, ptr, size);
+}
+
 AllocatorDispatch g_allocator_hooks = {
-    &HookAlloc,           /* alloc_function */
-    &HookZeroInitAlloc,   /* alloc_zero_initialized_function */
-    &HookllocAligned,     /* alloc_aligned_function */
-    &HookRealloc,         /* realloc_function */
-    &HookFree,            /* free_function */
-    &HookGetSizeEstimate, /* get_size_estimate_function */
-    nullptr,              /* next */
+    &HookAlloc,            /* alloc_function */
+    &HookZeroInitAlloc,    /* alloc_zero_initialized_function */
+    &HookllocAligned,      /* alloc_aligned_function */
+    &HookRealloc,          /* realloc_function */
+    &HookFree,             /* free_function */
+    &HookGetSizeEstimate,  /* get_size_estimate_function */
+    &HookBatchMalloc,      /* batch_malloc_function */
+    &HookBatchFree,        /* batch_free_function */
+    &HookFreeDefiniteSize, /* free_definite_size_function */
+    nullptr,               /* next */
 };
 #endif  // BUILDFLAG(USE_EXPERIMENTAL_ALLOCATOR_SHIM)