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 #ifdef BASE_ALLOCATOR_ALLOCATOR_SHIM_OVERRIDE_MAC_SYMBOLS_H_ |
| 6 #error This header is meant to be included only once by allocator_shim.cc |
| 7 #endif |
| 8 #define BASE_ALLOCATOR_ALLOCATOR_SHIM_OVERRIDE_MAC_SYMBOLS_H_ |
| 9 |
| 10 #include "base/allocator/allocator_interception_mac.h" |
| 11 #include "third_party/apple_apsl/malloc.h" |
| 12 |
| 13 namespace base { |
| 14 namespace allocator { |
| 15 |
| 16 void OverrideMacSymbols() { |
| 17 MallocZoneFunctions new_functions; |
| 18 new_functions.size = [](malloc_zone_t* zone, const void* ptr) -> size_t { |
| 19 return ShimGetSizeEstimate(ptr); |
| 20 }; |
| 21 new_functions.malloc = [](malloc_zone_t* zone, size_t size) -> void* { |
| 22 return ShimMalloc(size); |
| 23 }; |
| 24 new_functions.calloc = [](malloc_zone_t* zone, size_t n, |
| 25 size_t size) -> void* { |
| 26 return ShimCalloc(n, size); |
| 27 }; |
| 28 new_functions.valloc = [](malloc_zone_t* zone, size_t size) -> void* { |
| 29 return ShimValloc(size); |
| 30 }; |
| 31 new_functions.free = [](malloc_zone_t* zone, void* ptr) { ShimFree(ptr); }; |
| 32 new_functions.realloc = [](malloc_zone_t* zone, void* ptr, |
| 33 size_t size) -> void* { |
| 34 return ShimRealloc(ptr, size); |
| 35 }; |
| 36 new_functions.batch_malloc = [](struct _malloc_zone_t* zone, size_t size, |
| 37 void** results, |
| 38 unsigned num_requested) -> unsigned { |
| 39 return ShimBatchMalloc(size, results, num_requested); |
| 40 }; |
| 41 new_functions.batch_free = [](struct _malloc_zone_t* zone, void** to_be_freed, |
| 42 unsigned num_to_be_freed) -> void { |
| 43 ShimBatchFree(to_be_freed, num_to_be_freed); |
| 44 }; |
| 45 new_functions.memalign = [](malloc_zone_t* zone, size_t alignment, |
| 46 size_t size) -> void* { |
| 47 return ShimMemalign(alignment, size); |
| 48 }; |
| 49 new_functions.free_definite_size = [](malloc_zone_t* zone, void* ptr, |
| 50 size_t size) { |
| 51 ShimFreeDefiniteSize(ptr, size); |
| 52 }; |
| 53 |
| 54 base::allocator::ReplaceFunctionsForDefaultZone(&new_functions); |
| 55 } |
| 56 |
| 57 } // namespace allocator |
| 58 } // namespace base |
OLD | NEW |