OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "base/allocator/allocator_shim.h" | |
6 | |
7 // This translation unit defines a default dispatch for the allocator shim which | |
8 // routes allocations to libc functions. | |
9 // The code here is strongly inspired from tcmalloc's libc_override_glibc.h. | |
10 | |
11 extern "C" { | |
12 void* __libc_malloc(size_t size); | |
13 void* __libc_calloc(size_t n, size_t size); | |
14 void* __libc_realloc(void* address, size_t size); | |
15 void* __libc_memalign(size_t alignment, size_t size); | |
16 void __libc_free(void* ptr); | |
17 } // extern "C" | |
Nico
2016/03/08 03:08:42
do we ever want to call glibc instead of tcmalloc?
Primiano Tucci (use gerrit)
2016/03/08 20:54:05
That's the case for use_allocator=none.
I am prett
| |
18 | |
19 namespace { | |
20 | |
21 using base::allocator::AllocatorDispatch; | |
22 | |
23 void* GlibcMalloc(size_t size, const AllocatorDispatch*) { | |
24 return __libc_malloc(size); | |
25 } | |
26 | |
27 void* GlibcCalloc(size_t n, size_t size, const AllocatorDispatch*) { | |
28 return __libc_calloc(n, size); | |
29 } | |
30 | |
31 void* GlibcRealloc(void* address, size_t size, const AllocatorDispatch*) { | |
32 return __libc_realloc(address, size); | |
33 } | |
34 | |
35 void* GlibcMemalign(size_t alignment, size_t size, const AllocatorDispatch*) { | |
36 return __libc_memalign(alignment, size); | |
37 } | |
38 | |
39 void GlibcFree(void* address, const AllocatorDispatch*) { | |
40 __libc_free(address); | |
41 } | |
42 | |
43 } // namespace | |
44 | |
45 const AllocatorDispatch AllocatorDispatch::default_dispatch = { | |
46 &GlibcMalloc, /* alloc_function */ | |
47 &GlibcCalloc, /* alloc_zero_initialized_function */ | |
48 &GlibcMemalign, /* alloc_aligned_function */ | |
49 &GlibcRealloc, /* realloc_function */ | |
50 &GlibcFree, /* free_function */ | |
51 nullptr, /* next */ | |
52 }; | |
OLD | NEW |