Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(120)

Side by Side Diff: base/allocator/allocator_interception_mac.h

Issue 2703803004: macOS: Shim all malloc zones. (Closed)
Patch Set: Minor formatting. Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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>
9 #include <stddef.h> 8 #include <stddef.h>
10 9
10 #include "base/allocator/malloc_zone_aggregator_mac.h"
11 #include "base/base_export.h" 11 #include "base/base_export.h"
12 #include "third_party/apple_apsl/malloc.h"
13 12
14 namespace base { 13 namespace base {
15 namespace allocator { 14 namespace allocator {
16 15
17 typedef void* (*malloc_type)(struct _malloc_zone_t* zone, size_t size); 16 // Saves the function pointers currently used by default zone into |aggregator|.
18 typedef void* (*calloc_type)(struct _malloc_zone_t* zone, 17 void StoreFunctionsForDefaultZone(MallocZoneAggregator* aggregator);
19 size_t num_items,
20 size_t size);
21 typedef void* (*valloc_type)(struct _malloc_zone_t* zone, size_t size);
22 typedef void (*free_type)(struct _malloc_zone_t* zone, void* ptr);
23 typedef void* (*realloc_type)(struct _malloc_zone_t* zone,
24 void* ptr,
25 size_t size);
26 typedef void* (*memalign_type)(struct _malloc_zone_t* zone,
27 size_t alignment,
28 size_t size);
29 typedef unsigned (*batch_malloc_type)(struct _malloc_zone_t* zone,
30 size_t size,
31 void** results,
32 unsigned num_requested);
33 typedef void (*batch_free_type)(struct _malloc_zone_t* zone,
34 void** to_be_freed,
35 unsigned num_to_be_freed);
36 typedef void (*free_definite_size_type)(struct _malloc_zone_t* zone,
37 void* ptr,
38 size_t size);
39 typedef size_t (*size_fn_type)(struct _malloc_zone_t* zone, const void* ptr);
40 18
41 struct MallocZoneFunctions { 19 // Same as StoreFunctionsForDefaultZone, but for all malloc zones.
42 MallocZoneFunctions(); 20 void StoreFunctionsForAllZones(MallocZoneAggregator* aggregator);
43 malloc_type malloc = nullptr;
44 calloc_type calloc = nullptr;
45 valloc_type valloc = nullptr;
46 free_type free = nullptr;
47 realloc_type realloc = nullptr;
48 memalign_type memalign = nullptr;
49 batch_malloc_type batch_malloc = nullptr;
50 batch_free_type batch_free = nullptr;
51 free_definite_size_type free_definite_size = nullptr;
52 size_fn_type size = nullptr;
53 };
54 21
55 // Saves the function pointers currently used by default zone into |functions|. 22 // For all malloc zones that have been stored, replace their functions with
56 void StoreFunctionsForDefaultZone(MallocZoneFunctions* functions);
57
58 // Updates the default malloc zone to use the functions specified by
59 // |functions|. 23 // |functions|.
60 void ReplaceFunctionsForDefaultZone(const MallocZoneFunctions* functions); 24 void ReplaceFunctionsForStoredZones(const MallocZoneFunctions* functions);
61 25
62 extern bool g_replaced_default_zone; 26 extern bool g_replaced_default_zone;
63 27
64 // Calls the original implementation of malloc/calloc prior to interception. 28 // Calls the original implementation of malloc/calloc prior to interception.
65 bool UncheckedMallocMac(size_t size, void** result); 29 bool UncheckedMallocMac(size_t size, void** result);
66 bool UncheckedCallocMac(size_t num_items, size_t size, void** result); 30 bool UncheckedCallocMac(size_t num_items, size_t size, void** result);
67 31
68 // Intercepts calls to default and purgeable malloc zones. Intercepts Core 32 // Intercepts calls to default and purgeable malloc zones. Intercepts Core
69 // Foundation and Objective-C allocations. 33 // Foundation and Objective-C allocations.
70 // Has no effect on the default malloc zone if the allocator shim already 34 // Has no effect on the default malloc zone if the allocator shim already
71 // performs that interception. 35 // performs that interception.
72 BASE_EXPORT void InterceptAllocationsMac(); 36 BASE_EXPORT void InterceptAllocationsMac();
73 } // namespace allocator 37 } // namespace allocator
74 } // namespace base 38 } // namespace base
75 39
76 #endif // BASE_ALLOCATOR_ALLOCATOR_INTERCEPTION_MAC_H_ 40 #endif // BASE_ALLOCATOR_ALLOCATOR_INTERCEPTION_MAC_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698