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

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

Issue 2163783003: Implement a ScopedThreadHeapUsage class to allow profiling per-thread heap usage. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@shim-default
Patch Set: Fix a brain****, may even compile now. Created 4 years, 4 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 // This translation unit defines a default dispatch for the allocator shim which 7 // This translation unit defines a default dispatch for the allocator shim which
8 // routes allocations to libc functions. 8 // routes allocations to libc functions.
9 // The code here is strongly inspired from tcmalloc's libc_override_glibc.h. 9 // The code here is strongly inspired from tcmalloc's libc_override_glibc.h.
10 10
11 extern "C" { 11 extern "C" {
12 void* __libc_malloc(size_t size); 12 void* __libc_malloc(size_t size);
13 void* __libc_calloc(size_t n, size_t size); 13 void* __libc_calloc(size_t n, size_t size);
14 void* __libc_realloc(void* address, size_t size); 14 void* __libc_realloc(void* address, size_t size);
15 void* __libc_memalign(size_t alignment, size_t size); 15 void* __libc_memalign(size_t alignment, size_t size);
16 void __libc_free(void* ptr); 16 void __libc_free(void* ptr);
17 size_t __malloc_usable_size(void* ptr);
Primiano Tucci (use gerrit) 2016/08/24 15:28:46 not sure you ned this fwd declaration
Sigurður Ásgeirsson 2016/09/01 15:18:17 Done.
17 } // extern "C" 18 } // extern "C"
18 19
19 namespace { 20 namespace {
20 21
21 using base::allocator::AllocatorDispatch; 22 using base::allocator::AllocatorDispatch;
22 23
23 void* GlibcMalloc(const AllocatorDispatch*, size_t size) { 24 void* GlibcMalloc(const AllocatorDispatch*, size_t size) {
24 return __libc_malloc(size); 25 return __libc_malloc(size);
25 } 26 }
26 27
27 void* GlibcCalloc(const AllocatorDispatch*, size_t n, size_t size) { 28 void* GlibcCalloc(const AllocatorDispatch*, size_t n, size_t size) {
28 return __libc_calloc(n, size); 29 return __libc_calloc(n, size);
29 } 30 }
30 31
31 void* GlibcRealloc(const AllocatorDispatch*, void* address, size_t size) { 32 void* GlibcRealloc(const AllocatorDispatch*, void* address, size_t size) {
32 return __libc_realloc(address, size); 33 return __libc_realloc(address, size);
33 } 34 }
34 35
35 void* GlibcMemalign(const AllocatorDispatch*, size_t alignment, size_t size) { 36 void* GlibcMemalign(const AllocatorDispatch*, size_t alignment, size_t size) {
36 return __libc_memalign(alignment, size); 37 return __libc_memalign(alignment, size);
37 } 38 }
38 39
39 void GlibcFree(const AllocatorDispatch*, void* address) { 40 void GlibcFree(const AllocatorDispatch*, void* address) {
40 __libc_free(address); 41 __libc_free(address);
41 } 42 }
43 }
44 void GlibcFree(const AllocatorDispatch*, void* address) {
Primiano Tucci (use gerrit) 2016/08/24 14:11:46 seems like you accidentally copy/pasted this twice
Sigurður Ásgeirsson 2016/09/01 15:18:18 Ooops, I wonder how this even compiled. Fixed :/.
45 __libc_free(address);
46 }
47
48 size_t GlibcGetSizeEstimate(const AllocatorDispatch*, void* address) {
49 return __libc_usable_size(address);
Primiano Tucci (use gerrit) 2016/08/24 14:11:46 I don't think you need to go down into __libc inte
Primiano Tucci (use gerrit) 2016/08/24 15:28:46 I think you mean __malloc_usable_size here. The n
Sigurður Ásgeirsson 2016/09/01 15:18:18 Thanks, added a TODO.
Sigurður Ásgeirsson 2016/09/01 15:18:18 Done.
50 }
42 51
43 } // namespace 52 } // namespace
44 53
45 const AllocatorDispatch AllocatorDispatch::default_dispatch = { 54 const AllocatorDispatch AllocatorDispatch::default_dispatch = {
46 &GlibcMalloc, /* alloc_function */ 55 &GlibcMalloc, /* alloc_function */
47 &GlibcCalloc, /* alloc_zero_initialized_function */ 56 &GlibcCalloc, /* alloc_zero_initialized_function */
48 &GlibcMemalign, /* alloc_aligned_function */ 57 &GlibcMemalign, /* alloc_aligned_function */
49 &GlibcRealloc, /* realloc_function */ 58 &GlibcRealloc, /* realloc_function */
50 &GlibcFree, /* free_function */ 59 &GlibcFree, /* free_function */
51 nullptr, /* next */ 60 &GlibcGetSizeEstimate, /* get_size_estimate_function */
61 nullptr, /* next */
52 }; 62 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698