| 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 "base/allocator/allocator_shim.h" | 5 #include "base/allocator/allocator_shim.h" |
| 6 | 6 |
| 7 #include <malloc.h> |
| 8 |
| 7 // This translation unit defines a default dispatch for the allocator shim which | 9 // This translation unit defines a default dispatch for the allocator shim which |
| 8 // routes allocations to libc functions. | 10 // routes allocations to libc functions. |
| 9 // The code here is strongly inspired from tcmalloc's libc_override_glibc.h. | 11 // The code here is strongly inspired from tcmalloc's libc_override_glibc.h. |
| 10 | 12 |
| 11 extern "C" { | 13 extern "C" { |
| 12 void* __libc_malloc(size_t size); | 14 void* __libc_malloc(size_t size); |
| 13 void* __libc_calloc(size_t n, size_t size); | 15 void* __libc_calloc(size_t n, size_t size); |
| 14 void* __libc_realloc(void* address, size_t size); | 16 void* __libc_realloc(void* address, size_t size); |
| 15 void* __libc_memalign(size_t alignment, size_t size); | 17 void* __libc_memalign(size_t alignment, size_t size); |
| 16 void __libc_free(void* ptr); | 18 void __libc_free(void* ptr); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 33 } | 35 } |
| 34 | 36 |
| 35 void* GlibcMemalign(const AllocatorDispatch*, size_t alignment, size_t size) { | 37 void* GlibcMemalign(const AllocatorDispatch*, size_t alignment, size_t size) { |
| 36 return __libc_memalign(alignment, size); | 38 return __libc_memalign(alignment, size); |
| 37 } | 39 } |
| 38 | 40 |
| 39 void GlibcFree(const AllocatorDispatch*, void* address) { | 41 void GlibcFree(const AllocatorDispatch*, void* address) { |
| 40 __libc_free(address); | 42 __libc_free(address); |
| 41 } | 43 } |
| 42 | 44 |
| 45 size_t GlibcGetSizeEstimate(const AllocatorDispatch*, void* address) { |
| 46 // TODO(siggi, primiano): malloc_usable_size may need redirection in the |
| 47 // presence of interposing shims that divert allocations. |
| 48 return malloc_usable_size(address); |
| 49 } |
| 50 |
| 43 } // namespace | 51 } // namespace |
| 44 | 52 |
| 45 const AllocatorDispatch AllocatorDispatch::default_dispatch = { | 53 const AllocatorDispatch AllocatorDispatch::default_dispatch = { |
| 46 &GlibcMalloc, /* alloc_function */ | 54 &GlibcMalloc, /* alloc_function */ |
| 47 &GlibcCalloc, /* alloc_zero_initialized_function */ | 55 &GlibcCalloc, /* alloc_zero_initialized_function */ |
| 48 &GlibcMemalign, /* alloc_aligned_function */ | 56 &GlibcMemalign, /* alloc_aligned_function */ |
| 49 &GlibcRealloc, /* realloc_function */ | 57 &GlibcRealloc, /* realloc_function */ |
| 50 &GlibcFree, /* free_function */ | 58 &GlibcFree, /* free_function */ |
| 51 nullptr, /* next */ | 59 &GlibcGetSizeEstimate, /* get_size_estimate_function */ |
| 60 nullptr, /* next */ |
| 52 }; | 61 }; |
| OLD | NEW |