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 // Its purpose is to preempt the Libc symbols for malloc/new so they call the
6 // shim layer entry points.
7 
8 #ifdef BASE_ALLOCATOR_ALLOCATOR_SHIM_OVERRIDE_LIBC_SYMBOLS_H_
9 #error This header is meant to be included only once by allocator_shim.cc
10 #endif
11 #define BASE_ALLOCATOR_ALLOCATOR_SHIM_OVERRIDE_LIBC_SYMBOLS_H_
12 
13 #include <malloc.h>
14 
15 #include "base/allocator/allocator_shim_internals.h"
16 
17 extern "C" {
18 
malloc(size_t size)19 SHIM_ALWAYS_EXPORT void* malloc(size_t size) __THROW {
20   return ShimMalloc(size, nullptr);
21 }
22 
free(void * ptr)23 SHIM_ALWAYS_EXPORT void free(void* ptr) __THROW {
24   ShimFree(ptr, nullptr);
25 }
26 
realloc(void * ptr,size_t size)27 SHIM_ALWAYS_EXPORT void* realloc(void* ptr, size_t size) __THROW {
28   return ShimRealloc(ptr, size, nullptr);
29 }
30 
calloc(size_t n,size_t size)31 SHIM_ALWAYS_EXPORT void* calloc(size_t n, size_t size) __THROW {
32   return ShimCalloc(n, size, nullptr);
33 }
34 
cfree(void * ptr)35 SHIM_ALWAYS_EXPORT void cfree(void* ptr) __THROW {
36   ShimFree(ptr, nullptr);
37 }
38 
memalign(size_t align,size_t s)39 SHIM_ALWAYS_EXPORT void* memalign(size_t align, size_t s) __THROW {
40   return ShimMemalign(align, s, nullptr);
41 }
42 
valloc(size_t size)43 SHIM_ALWAYS_EXPORT void* valloc(size_t size) __THROW {
44   return ShimValloc(size, nullptr);
45 }
46 
pvalloc(size_t size)47 SHIM_ALWAYS_EXPORT void* pvalloc(size_t size) __THROW {
48   return ShimPvalloc(size);
49 }
50 
posix_memalign(void ** r,size_t a,size_t s)51 SHIM_ALWAYS_EXPORT int posix_memalign(void** r, size_t a, size_t s) __THROW {
52   return ShimPosixMemalign(r, a, s);
53 }
54 
55 // The default dispatch translation unit has to define also the following
56 // symbols (unless they are ultimately routed to the system symbols):
57 //   void malloc_stats(void);
58 //   int mallopt(int, int);
59 //   struct mallinfo mallinfo(void);
60 //   size_t malloc_size(void*);
61 //   size_t malloc_usable_size(const void*);
62 
63 }  // extern "C"
64