OLD | NEW |
---|---|
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef BASE_ALLOCATOR_ALLOCATOR_INTERCEPTION_MAC_H_ | 5 #ifndef BASE_ALLOCATOR_ALLOCATOR_INTERCEPTION_MAC_H_ |
6 #define BASE_ALLOCATOR_ALLOCATOR_INTERCEPTION_MAC_H_ | 6 #define BASE_ALLOCATOR_ALLOCATOR_INTERCEPTION_MAC_H_ |
7 | 7 |
8 #include <malloc/malloc.h> | 8 #include <malloc/malloc.h> |
9 #include <stddef.h> | 9 #include <stddef.h> |
10 | 10 |
11 #include "third_party/apple_apsl/malloc.h" | 11 #include "third_party/apple_apsl/malloc.h" |
12 | 12 |
13 namespace base { | 13 namespace base { |
14 namespace allocator { | 14 namespace allocator { |
15 | 15 |
16 typedef void* (*malloc_type)(struct _malloc_zone_t* zone, size_t size); | 16 typedef void* (*malloc_type)(struct _malloc_zone_t* zone, size_t size); |
17 typedef void* (*calloc_type)(struct _malloc_zone_t* zone, | 17 typedef void* (*calloc_type)(struct _malloc_zone_t* zone, |
18 size_t num_items, | 18 size_t num_items, |
19 size_t size); | 19 size_t size); |
20 typedef void* (*valloc_type)(struct _malloc_zone_t* zone, size_t size); | 20 typedef void* (*valloc_type)(struct _malloc_zone_t* zone, size_t size); |
21 typedef void (*free_type)(struct _malloc_zone_t* zone, void* ptr); | 21 typedef void (*free_type)(struct _malloc_zone_t* zone, void* ptr); |
22 typedef void* (*realloc_type)(struct _malloc_zone_t* zone, | 22 typedef void* (*realloc_type)(struct _malloc_zone_t* zone, |
23 void* ptr, | 23 void* ptr, |
24 size_t size); | 24 size_t size); |
25 typedef void* (*memalign_type)(struct _malloc_zone_t* zone, | 25 typedef void* (*memalign_type)(struct _malloc_zone_t* zone, |
26 size_t alignment, | 26 size_t alignment, |
27 size_t size); | 27 size_t size); |
28 typedef unsigned (*batch_malloc_type)(struct _malloc_zone_t* zone, | |
29 size_t size, | |
30 void** results, | |
31 unsigned num_requested); | |
32 typedef void (*batch_free_type)(struct _malloc_zone_t* zone, | |
33 void** to_be_freed, | |
34 unsigned num_to_be_freed); | |
35 typedef void (*free_definite_size_type)(struct _malloc_zone_t* zone, | |
36 void* ptr, | |
37 size_t size); | |
38 typedef size_t (*size_fn_type)(struct _malloc_zone_t* zone, const void* ptr); | |
28 | 39 |
29 struct MallocZoneFunctions { | 40 struct MallocZoneFunctions { |
41 MallocZoneFunctions(); | |
30 malloc_type malloc = nullptr; | 42 malloc_type malloc = nullptr; |
31 calloc_type calloc = nullptr; | 43 calloc_type calloc = nullptr; |
32 valloc_type valloc = nullptr; | 44 valloc_type valloc = nullptr; |
33 free_type free = nullptr; | 45 free_type free = nullptr; |
34 realloc_type realloc = nullptr; | 46 realloc_type realloc = nullptr; |
35 memalign_type memalign = nullptr; | 47 memalign_type memalign = nullptr; |
48 batch_malloc_type batch_malloc = nullptr; | |
49 batch_free_type batch_free = nullptr; | |
50 free_definite_size_type free_definite_size = nullptr; | |
51 size_fn_type size = nullptr; | |
36 }; | 52 }; |
37 | 53 |
38 // Saves the function pointers currently used by |zone| into |functions|. | 54 // Saves the function pointers currently used by default zone into |functions|. |
39 void StoreZoneFunctions(ChromeMallocZone* zone, MallocZoneFunctions* functions); | 55 void StoreDefaultZoneFunctions(MallocZoneFunctions* functions); |
40 | 56 |
41 // Updates the malloc zone to use the functions specified by |functions|. | 57 // Updates the default malloc zone to use the functions specified by |
42 void ReplaceZoneFunctions(ChromeMallocZone* zone, | 58 // |functions|. |
43 const MallocZoneFunctions* functions); | 59 void ReplaceDefaultZoneFunctions(const MallocZoneFunctions* functions); |
44 | 60 |
45 // Calls the original implementation of malloc/calloc prior to interception. | 61 // Calls the original implementation of malloc/calloc prior to interception. |
46 bool UncheckedMallocMac(size_t size, void** result); | 62 bool UncheckedMallocMac(size_t size, void** result); |
47 bool UncheckedCallocMac(size_t num_items, size_t size, void** result); | 63 bool UncheckedCallocMac(size_t num_items, size_t size, void** result); |
48 | 64 |
49 // Intercepts calls to default and purgeable malloc zones. Intercepts Core | 65 // Intercepts calls to default and purgeable malloc zones. Intercepts Core |
50 // Foundation and Objective-C allocations. | 66 // Foundation and Objective-C allocations. |
67 // Has no effect on the default malloc zone if the allocator shim already | |
68 // performs that interception. | |
51 void InterceptAllocationsMac(); | 69 void InterceptAllocationsMac(); |
Primiano Tucci (use gerrit)
2017/01/28 05:10:02
in a follow up CL we should sort out a bit these n
erikchen
2017/01/31 02:21:22
Noted.
| |
52 } // namespace allocator | 70 } // namespace allocator |
53 } // namespace base | 71 } // namespace base |
54 | 72 |
55 #endif // BASE_ALLOCATOR_ALLOCATOR_INTERCEPTION_MAC_H_ | 73 #endif // BASE_ALLOCATOR_ALLOCATOR_INTERCEPTION_MAC_H_ |
OLD | NEW |