Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(33)

Side by Side Diff: base/allocator/allocator_shim_default_dispatch_to_glibc.cc

Issue 2697123007: base: Add support for malloc zones to the allocator shim (Closed)
Patch Set: Windows compile error. Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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> 7 #include <malloc.h>
8 8
9 // 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
10 // routes allocations to libc functions. 10 // routes allocations to libc functions.
11 // 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.
12 12
13 extern "C" { 13 extern "C" {
14 void* __libc_malloc(size_t size); 14 void* __libc_malloc(size_t size);
15 void* __libc_calloc(size_t n, size_t size); 15 void* __libc_calloc(size_t n, size_t size);
16 void* __libc_realloc(void* address, size_t size); 16 void* __libc_realloc(void* address, size_t size);
17 void* __libc_memalign(size_t alignment, size_t size); 17 void* __libc_memalign(size_t alignment, size_t size);
18 void __libc_free(void* ptr); 18 void __libc_free(void* ptr);
19 } // extern "C" 19 } // extern "C"
20 20
21 namespace { 21 namespace {
22 22
23 using base::allocator::AllocatorDispatch; 23 using base::allocator::AllocatorDispatch;
24 24
25 void* GlibcMalloc(const AllocatorDispatch*, size_t size) { 25 void* GlibcMalloc(const AllocatorDispatch*, size_t size, void* context) {
26 return __libc_malloc(size); 26 return __libc_malloc(size);
27 } 27 }
28 28
29 void* GlibcCalloc(const AllocatorDispatch*, size_t n, size_t size) { 29 void* GlibcCalloc(const AllocatorDispatch*,
30 size_t n,
31 size_t size,
32 void* context) {
30 return __libc_calloc(n, size); 33 return __libc_calloc(n, size);
31 } 34 }
32 35
33 void* GlibcRealloc(const AllocatorDispatch*, void* address, size_t size) { 36 void* GlibcRealloc(const AllocatorDispatch*,
37 void* address,
38 size_t size,
39 void* context) {
34 return __libc_realloc(address, size); 40 return __libc_realloc(address, size);
35 } 41 }
36 42
37 void* GlibcMemalign(const AllocatorDispatch*, size_t alignment, size_t size) { 43 void* GlibcMemalign(const AllocatorDispatch*,
44 size_t alignment,
45 size_t size,
46 void* context) {
38 return __libc_memalign(alignment, size); 47 return __libc_memalign(alignment, size);
39 } 48 }
40 49
41 void GlibcFree(const AllocatorDispatch*, void* address) { 50 void GlibcFree(const AllocatorDispatch*, void* address, void* context) {
42 __libc_free(address); 51 __libc_free(address);
43 } 52 }
44 53
45 size_t GlibcGetSizeEstimate(const AllocatorDispatch*, void* address) { 54 size_t GlibcGetSizeEstimate(const AllocatorDispatch*,
55 void* address,
56 void* context) {
46 // TODO(siggi, primiano): malloc_usable_size may need redirection in the 57 // TODO(siggi, primiano): malloc_usable_size may need redirection in the
47 // presence of interposing shims that divert allocations. 58 // presence of interposing shims that divert allocations.
48 return malloc_usable_size(address); 59 return malloc_usable_size(address);
49 } 60 }
50 61
51 } // namespace 62 } // namespace
52 63
53 const AllocatorDispatch AllocatorDispatch::default_dispatch = { 64 const AllocatorDispatch AllocatorDispatch::default_dispatch = {
54 &GlibcMalloc, /* alloc_function */ 65 &GlibcMalloc, /* alloc_function */
55 &GlibcCalloc, /* alloc_zero_initialized_function */ 66 &GlibcCalloc, /* alloc_zero_initialized_function */
56 &GlibcMemalign, /* alloc_aligned_function */ 67 &GlibcMemalign, /* alloc_aligned_function */
57 &GlibcRealloc, /* realloc_function */ 68 &GlibcRealloc, /* realloc_function */
58 &GlibcFree, /* free_function */ 69 &GlibcFree, /* free_function */
59 &GlibcGetSizeEstimate, /* get_size_estimate_function */ 70 &GlibcGetSizeEstimate, /* get_size_estimate_function */
60 nullptr, /* batch_malloc_function */ 71 nullptr, /* batch_malloc_function */
61 nullptr, /* batch_free_function */ 72 nullptr, /* batch_free_function */
62 nullptr, /* free_definite_size_function */ 73 nullptr, /* free_definite_size_function */
63 nullptr, /* next */ 74 nullptr, /* next */
64 }; 75 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698