1 // Copyright 2017 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifdef PARTITION_ALLOC_SHIM_ALLOCATOR_SHIM_OVERRIDE_APPLE_SYMBOLS_H_
6 #error This header is meant to be included only once by allocator_shim.cc
7 #endif
8
9 #ifndef PARTITION_ALLOC_SHIM_ALLOCATOR_SHIM_OVERRIDE_APPLE_SYMBOLS_H_
10 #define PARTITION_ALLOC_SHIM_ALLOCATOR_SHIM_OVERRIDE_APPLE_SYMBOLS_H_
11
12 #include "partition_alloc/partition_alloc_buildflags.h"
13
14 #if BUILDFLAG(USE_ALLOCATOR_SHIM)
15 #include "partition_alloc/shim/malloc_zone_functions_apple.h"
16 #include "partition_alloc/third_party/apple_apsl/malloc.h"
17
18 namespace allocator_shim {
19
MallocZoneFunctionsToReplaceDefault()20 MallocZoneFunctions MallocZoneFunctionsToReplaceDefault() {
21 MallocZoneFunctions new_functions;
22 memset(&new_functions, 0, sizeof(MallocZoneFunctions));
23 new_functions.size = [](malloc_zone_t* zone, const void* ptr) -> size_t {
24 return ShimGetSizeEstimate(ptr, zone);
25 };
26 new_functions.good_size = [](malloc_zone_t* zone, size_t size) -> size_t {
27 return ShimGoodSize(size, zone);
28 };
29 new_functions.claimed_address = [](malloc_zone_t* zone,
30 void* ptr) -> boolean_t {
31 return ShimClaimedAddress(ptr, zone);
32 };
33 new_functions.malloc = [](malloc_zone_t* zone, size_t size) -> void* {
34 return ShimMalloc(size, zone);
35 };
36 new_functions.calloc = [](malloc_zone_t* zone, size_t n,
37 size_t size) -> void* {
38 return ShimCalloc(n, size, zone);
39 };
40 new_functions.valloc = [](malloc_zone_t* zone, size_t size) -> void* {
41 return ShimValloc(size, zone);
42 };
43 new_functions.free = [](malloc_zone_t* zone, void* ptr) {
44 ShimFree(ptr, zone);
45 };
46 new_functions.realloc = [](malloc_zone_t* zone, void* ptr,
47 size_t size) -> void* {
48 return ShimRealloc(ptr, size, zone);
49 };
50 new_functions.batch_malloc = [](struct _malloc_zone_t* zone, size_t size,
51 void** results,
52 unsigned num_requested) -> unsigned {
53 return ShimBatchMalloc(size, results, num_requested, zone);
54 };
55 new_functions.batch_free = [](struct _malloc_zone_t* zone, void** to_be_freed,
56 unsigned num_to_be_freed) -> void {
57 ShimBatchFree(to_be_freed, num_to_be_freed, zone);
58 };
59 new_functions.memalign = [](malloc_zone_t* zone, size_t alignment,
60 size_t size) -> void* {
61 return ShimMemalign(alignment, size, zone);
62 };
63 new_functions.free_definite_size = [](malloc_zone_t* zone, void* ptr,
64 size_t size) {
65 ShimFreeDefiniteSize(ptr, size, zone);
66 };
67 new_functions.try_free_default = [](malloc_zone_t* zone, void* ptr) {
68 ShimTryFreeDefault(ptr, zone);
69 };
70 return new_functions;
71 }
72
73 } // namespace allocator_shim
74
75 #endif // BUILDFLAG(USE_ALLOCATOR_SHIM)
76
77 #endif // PARTITION_ALLOC_SHIM_ALLOCATOR_SHIM_OVERRIDE_APPLE_SYMBOLS_H_
78