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