OLD | NEW |
(Empty) | |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "base/allocator/allocator_shim_default_dispatch_to_mac_zoned_malloc.h" |
| 6 |
| 7 #include <utility> |
| 8 |
| 9 #include "base/allocator/allocator_interception_mac.h" |
| 10 #include "base/allocator/allocator_shim.h" |
| 11 #include "base/logging.h" |
| 12 |
| 13 namespace base { |
| 14 namespace allocator { |
| 15 |
| 16 namespace { |
| 17 |
| 18 // This is the zone that the allocator shim will call to actually perform heap |
| 19 // allocations. It should be populated with the original, unintercepted default |
| 20 // malloc zone. |
| 21 MallocZoneFunctions g_default_zone; |
| 22 |
| 23 void* MallocImpl(const AllocatorDispatch*, size_t size) { |
| 24 return g_default_zone.malloc(malloc_default_zone(), size); |
| 25 } |
| 26 |
| 27 void* CallocImpl(const AllocatorDispatch*, size_t n, size_t size) { |
| 28 return g_default_zone.calloc(malloc_default_zone(), n, size); |
| 29 } |
| 30 |
| 31 void* MemalignImpl(const AllocatorDispatch*, size_t alignment, size_t size) { |
| 32 return g_default_zone.memalign(malloc_default_zone(), alignment, size); |
| 33 } |
| 34 |
| 35 void* ReallocImpl(const AllocatorDispatch*, void* ptr, size_t size) { |
| 36 return g_default_zone.realloc(malloc_default_zone(), ptr, size); |
| 37 } |
| 38 |
| 39 void FreeImpl(const AllocatorDispatch*, void* ptr) { |
| 40 g_default_zone.free(malloc_default_zone(), ptr); |
| 41 } |
| 42 |
| 43 size_t GetSizeEstimateImpl(const AllocatorDispatch*, void* ptr) { |
| 44 return g_default_zone.size(malloc_default_zone(), ptr); |
| 45 } |
| 46 |
| 47 unsigned BatchMallocImpl(const AllocatorDispatch* self, |
| 48 size_t size, |
| 49 void** results, |
| 50 unsigned num_requested) { |
| 51 return g_default_zone.batch_malloc(malloc_default_zone(), size, results, |
| 52 num_requested); |
| 53 } |
| 54 |
| 55 void BatchFreeImpl(const AllocatorDispatch* self, |
| 56 void** to_be_freed, |
| 57 unsigned num_to_be_freed) { |
| 58 g_default_zone.batch_free(malloc_default_zone(), to_be_freed, |
| 59 num_to_be_freed); |
| 60 } |
| 61 |
| 62 void FreeDefiniteSizeImpl(const AllocatorDispatch* self, |
| 63 void* ptr, |
| 64 size_t size) { |
| 65 g_default_zone.free_definite_size(malloc_default_zone(), ptr, size); |
| 66 } |
| 67 |
| 68 } // namespace |
| 69 |
| 70 void InitializeDefaultDispatchToMacAllocator() { |
| 71 StoreFunctionsForDefaultZone(&g_default_zone); |
| 72 } |
| 73 |
| 74 const AllocatorDispatch AllocatorDispatch::default_dispatch = { |
| 75 &MallocImpl, /* alloc_function */ |
| 76 &CallocImpl, /* alloc_zero_initialized_function */ |
| 77 &MemalignImpl, /* alloc_aligned_function */ |
| 78 &ReallocImpl, /* realloc_function */ |
| 79 &FreeImpl, /* free_function */ |
| 80 &GetSizeEstimateImpl, /* get_size_estimate_function */ |
| 81 &BatchMallocImpl, /* batch_malloc_function */ |
| 82 &BatchFreeImpl, /* batch_free_function */ |
| 83 &FreeDefiniteSizeImpl, /* free_definite_size_function */ |
| 84 nullptr, /* next */ |
| 85 }; |
| 86 |
| 87 } // namespace allocator |
| 88 } // namespace base |
OLD | NEW |