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

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

Issue 1675143004: Allocator shim skeleton + Linux impl behind a build flag (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@shim_exp_flag
Patch Set: Make self the 1st arg Created 4 years, 9 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
(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"
18
19 namespace {
20
21 using base::allocator::AllocatorDispatch;
22
23 void* GlibcMalloc(const AllocatorDispatch*, size_t size) {
24 return __libc_malloc(size);
25 }
26
27 void* GlibcCalloc(const AllocatorDispatch*, size_t n, size_t size) {
28 return __libc_calloc(n, size);
29 }
30
31 void* GlibcRealloc(const AllocatorDispatch*, void* address, size_t size) {
32 return __libc_realloc(address, size);
33 }
34
35 void* GlibcMemalign(const AllocatorDispatch*, size_t alignment, size_t size) {
36 return __libc_memalign(alignment, size);
37 }
38
39 void GlibcFree(const AllocatorDispatch*, void* address) {
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 };
OLDNEW
« no previous file with comments | « base/allocator/allocator_shim.cc ('k') | base/allocator/allocator_shim_default_dispatch_to_tcmalloc.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698