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 BASE_ALLOCATOR_PARTITION_ALLOCATOR_SHIM_ALLOCATOR_SHIM_OVERRIDE_MAC_SYMBOLS_H_
6 #error This header is meant to be included only once by allocator_shim.cc
7 #endif
8
9 #ifndef BASE_ALLOCATOR_PARTITION_ALLOCATOR_SHIM_ALLOCATOR_SHIM_OVERRIDE_MAC_SYMBOLS_H_
10 #define BASE_ALLOCATOR_PARTITION_ALLOCATOR_SHIM_ALLOCATOR_SHIM_OVERRIDE_MAC_SYMBOLS_H_
11
12 #include "base/allocator/partition_allocator/shim/malloc_zone_functions_mac.h"
13 #include "third_party/apple_apsl/malloc.h"
14
15 namespace allocator_shim {
16
MallocZoneFunctionsToReplaceDefault()17 MallocZoneFunctions MallocZoneFunctionsToReplaceDefault() {
18 MallocZoneFunctions new_functions;
19 memset(&new_functions, 0, sizeof(MallocZoneFunctions));
20 new_functions.size = [](malloc_zone_t* zone, const void* ptr) -> size_t {
21 return ShimGetSizeEstimate(ptr, zone);
22 };
23 new_functions.claimed_address = [](malloc_zone_t* zone,
24 void* ptr) -> boolean_t {
25 return ShimClaimedAddress(ptr, zone);
26 };
27 new_functions.malloc = [](malloc_zone_t* zone, size_t size) -> void* {
28 return ShimMalloc(size, zone);
29 };
30 new_functions.calloc = [](malloc_zone_t* zone, size_t n,
31 size_t size) -> void* {
32 return ShimCalloc(n, size, zone);
33 };
34 new_functions.valloc = [](malloc_zone_t* zone, size_t size) -> void* {
35 return ShimValloc(size, zone);
36 };
37 new_functions.free = [](malloc_zone_t* zone, void* ptr) {
38 ShimFree(ptr, zone);
39 };
40 new_functions.realloc = [](malloc_zone_t* zone, void* ptr,
41 size_t size) -> void* {
42 return ShimRealloc(ptr, size, zone);
43 };
44 new_functions.batch_malloc = [](struct _malloc_zone_t* zone, size_t size,
45 void** results,
46 unsigned num_requested) -> unsigned {
47 return ShimBatchMalloc(size, results, num_requested, zone);
48 };
49 new_functions.batch_free = [](struct _malloc_zone_t* zone, void** to_be_freed,
50 unsigned num_to_be_freed) -> void {
51 ShimBatchFree(to_be_freed, num_to_be_freed, zone);
52 };
53 new_functions.memalign = [](malloc_zone_t* zone, size_t alignment,
54 size_t size) -> void* {
55 return ShimMemalign(alignment, size, zone);
56 };
57 new_functions.free_definite_size = [](malloc_zone_t* zone, void* ptr,
58 size_t size) {
59 ShimFreeDefiniteSize(ptr, size, zone);
60 };
61 new_functions.try_free_default = [](malloc_zone_t* zone, void* ptr) {
62 ShimTryFreeDefault(ptr, zone);
63 };
64 return new_functions;
65 }
66
67 } // namespace allocator_shim
68
69 #endif // BASE_ALLOCATOR_PARTITION_ALLOCATOR_SHIM_ALLOCATOR_SHIM_OVERRIDE_MAC_SYMBOLS_H_
70