OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2017 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 #ifdef BASE_ALLOCATOR_ALLOCATOR_SHIM_OVERRIDE_MAC_SYMBOLS_H_ | |
6 #error This header is meant to be included only once by allocator_shim.cc | |
7 #endif | |
8 #define BASE_ALLOCATOR_ALLOCATOR_SHIM_OVERRIDE_MAC_SYMBOLS_H_ | |
9 | |
10 #include "base/allocator/allocator_interception_mac.h" | |
11 #include "base/allocator/allocator_shim_default_dispatch_to_zoned_malloc.h" | |
12 #include "third_party/apple_apsl/malloc.h" | |
13 | |
14 namespace base { | |
15 namespace allocator { | |
16 | |
17 void InitializeAllocatorShim() { | |
Primiano Tucci (use gerrit)
2017/01/28 05:10:02
I'd rename this to OverrideMacSymbols, which will
erikchen
2017/01/31 02:21:22
Done.
| |
18 MallocZoneFunctions functions; | |
Primiano Tucci (use gerrit)
2017/01/28 05:10:02
As said above, these 3 lines are really unnecessar
erikchen
2017/01/31 02:21:22
Done.
| |
19 base::allocator::StoreDefaultZoneFunctions(&functions); | |
20 base::allocator::SetDefaultDispatchMallocZoneFunctions(&functions); | |
21 | |
22 MallocZoneFunctions new_functions; | |
23 new_functions.size = [](malloc_zone_t* zone, const void* ptr) -> size_t { | |
24 return ShimGetSizeEstimate(ptr); | |
25 }; | |
26 new_functions.malloc = [](malloc_zone_t* zone, size_t size) -> void* { | |
27 return ShimMalloc(size); | |
28 }; | |
29 new_functions.calloc = [](malloc_zone_t* zone, size_t n, | |
30 size_t size) -> void* { | |
31 return ShimCalloc(n, size); | |
32 }; | |
33 new_functions.valloc = [](malloc_zone_t* zone, size_t size) -> void* { | |
34 return ShimValloc(size); | |
35 }; | |
36 new_functions.free = [](malloc_zone_t* zone, void* ptr) { ShimFree(ptr); }; | |
37 new_functions.realloc = [](malloc_zone_t* zone, void* ptr, | |
38 size_t size) -> void* { | |
39 return ShimRealloc(ptr, size); | |
40 }; | |
41 new_functions.batch_malloc = [](struct _malloc_zone_t* zone, size_t size, | |
42 void** results, | |
43 unsigned num_requested) -> unsigned { | |
44 return ShimBatchMalloc(size, results, num_requested); | |
45 }; | |
46 new_functions.batch_free = [](struct _malloc_zone_t* zone, void** to_be_freed, | |
47 unsigned num_to_be_freed) -> void { | |
48 ShimBatchFree(to_be_freed, num_to_be_freed); | |
49 }; | |
50 new_functions.memalign = [](malloc_zone_t* zone, size_t alignment, | |
51 size_t size) -> void* { | |
52 return ShimMemalign(alignment, size); | |
53 }; | |
54 new_functions.free_definite_size = [](malloc_zone_t* zone, void* ptr, | |
55 size_t size) { ShimFree(ptr); }; | |
56 | |
57 base::allocator::ReplaceDefaultZoneFunctions(&new_functions); | |
58 } | |
59 | |
60 } // namespace allocator | |
61 } // namespace base | |
OLD | NEW |