OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 #include <malloc.h> | 5 #include <malloc.h> |
6 | 6 |
7 #include "base/allocator/allocator_shim.h" | 7 #include "base/allocator/allocator_shim.h" |
8 #include "build/build_config.h" | 8 #include "build/build_config.h" |
9 | 9 |
10 #if defined(OS_ANDROID) && __ANDROID_API__ < 17 | 10 #if defined(OS_ANDROID) && __ANDROID_API__ < 17 |
(...skipping 14 matching lines...) Expand all Loading... |
25 void* __real_calloc(size_t, size_t); | 25 void* __real_calloc(size_t, size_t); |
26 void* __real_realloc(void*, size_t); | 26 void* __real_realloc(void*, size_t); |
27 void* __real_memalign(size_t, size_t); | 27 void* __real_memalign(size_t, size_t); |
28 void* __real_free(void*); | 28 void* __real_free(void*); |
29 } // extern "C" | 29 } // extern "C" |
30 | 30 |
31 namespace { | 31 namespace { |
32 | 32 |
33 using base::allocator::AllocatorDispatch; | 33 using base::allocator::AllocatorDispatch; |
34 | 34 |
35 void* RealMalloc(const AllocatorDispatch*, size_t size) { | 35 void* RealMalloc(const AllocatorDispatch*, size_t size, void* context) { |
36 return __real_malloc(size); | 36 return __real_malloc(size); |
37 } | 37 } |
38 | 38 |
39 void* RealCalloc(const AllocatorDispatch*, size_t n, size_t size) { | 39 void* RealCalloc(const AllocatorDispatch*, |
| 40 size_t n, |
| 41 size_t size, |
| 42 void* context) { |
40 return __real_calloc(n, size); | 43 return __real_calloc(n, size); |
41 } | 44 } |
42 | 45 |
43 void* RealRealloc(const AllocatorDispatch*, void* address, size_t size) { | 46 void* RealRealloc(const AllocatorDispatch*, |
| 47 void* address, |
| 48 size_t size, |
| 49 void* context) { |
44 return __real_realloc(address, size); | 50 return __real_realloc(address, size); |
45 } | 51 } |
46 | 52 |
47 void* RealMemalign(const AllocatorDispatch*, size_t alignment, size_t size) { | 53 void* RealMemalign(const AllocatorDispatch*, |
| 54 size_t alignment, |
| 55 size_t size, |
| 56 void* context) { |
48 return __real_memalign(alignment, size); | 57 return __real_memalign(alignment, size); |
49 } | 58 } |
50 | 59 |
51 void RealFree(const AllocatorDispatch*, void* address) { | 60 void RealFree(const AllocatorDispatch*, void* address, void* context) { |
52 __real_free(address); | 61 __real_free(address); |
53 } | 62 } |
54 | 63 |
55 #if defined(OS_ANDROID) && __ANDROID_API__ < 17 | 64 #if defined(OS_ANDROID) && __ANDROID_API__ < 17 |
56 size_t DummyMallocUsableSize(const void*) { return 0; } | 65 size_t DummyMallocUsableSize(const void*) { return 0; } |
57 #endif | 66 #endif |
58 | 67 |
59 size_t RealSizeEstimate(const AllocatorDispatch*, void* address) { | 68 size_t RealSizeEstimate(const AllocatorDispatch*, |
| 69 void* address, |
| 70 void* context) { |
60 #if defined(OS_ANDROID) | 71 #if defined(OS_ANDROID) |
61 #if __ANDROID_API__ < 17 | 72 #if __ANDROID_API__ < 17 |
62 // malloc_usable_size() is available only starting from API 17. | 73 // malloc_usable_size() is available only starting from API 17. |
63 // TODO(dskiba): remove once we start building against 17+. | 74 // TODO(dskiba): remove once we start building against 17+. |
64 using MallocUsableSizeFunction = decltype(malloc_usable_size)*; | 75 using MallocUsableSizeFunction = decltype(malloc_usable_size)*; |
65 static MallocUsableSizeFunction usable_size_function = nullptr; | 76 static MallocUsableSizeFunction usable_size_function = nullptr; |
66 if (!usable_size_function) { | 77 if (!usable_size_function) { |
67 void* function_ptr = dlsym(RTLD_DEFAULT, "malloc_usable_size"); | 78 void* function_ptr = dlsym(RTLD_DEFAULT, "malloc_usable_size"); |
68 if (function_ptr) { | 79 if (function_ptr) { |
69 usable_size_function = reinterpret_cast<MallocUsableSizeFunction>( | 80 usable_size_function = reinterpret_cast<MallocUsableSizeFunction>( |
(...skipping 20 matching lines...) Expand all Loading... |
90 &RealCalloc, /* alloc_zero_initialized_function */ | 101 &RealCalloc, /* alloc_zero_initialized_function */ |
91 &RealMemalign, /* alloc_aligned_function */ | 102 &RealMemalign, /* alloc_aligned_function */ |
92 &RealRealloc, /* realloc_function */ | 103 &RealRealloc, /* realloc_function */ |
93 &RealFree, /* free_function */ | 104 &RealFree, /* free_function */ |
94 &RealSizeEstimate, /* get_size_estimate_function */ | 105 &RealSizeEstimate, /* get_size_estimate_function */ |
95 nullptr, /* batch_malloc_function */ | 106 nullptr, /* batch_malloc_function */ |
96 nullptr, /* batch_free_function */ | 107 nullptr, /* batch_free_function */ |
97 nullptr, /* free_definite_size_function */ | 108 nullptr, /* free_definite_size_function */ |
98 nullptr, /* next */ | 109 nullptr, /* next */ |
99 }; | 110 }; |
OLD | NEW |