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

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

Issue 2703803004: macOS: Shim all malloc zones. (Closed)
Patch Set: Rebase. 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
« no previous file with comments | « base/BUILD.gn ('k') | base/allocator/allocator_interception_mac.mm » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
11 #include "base/base_export.h" 10 #include "base/base_export.h"
12 #include "third_party/apple_apsl/malloc.h"
13 11
14 namespace base { 12 namespace base {
15 namespace allocator { 13 namespace allocator {
16 14
17 typedef void* (*malloc_type)(struct _malloc_zone_t* zone, size_t size); 15 struct MallocZoneFunctions;
18 typedef void* (*calloc_type)(struct _malloc_zone_t* zone,
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 16
41 struct MallocZoneFunctions { 17 // Saves the function pointers currently used by the default zone.
42 MallocZoneFunctions(); 18 void StoreFunctionsForDefaultZone();
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 19
55 // Saves the function pointers currently used by default zone into |functions|. 20 // Same as StoreFunctionsForDefaultZone, but for all malloc zones.
56 void StoreFunctionsForDefaultZone(MallocZoneFunctions* functions); 21 void StoreFunctionsForAllZones();
57 22
58 // Updates the default malloc zone to use the functions specified by 23 // For all malloc zones that have been stored, replace their functions with
59 // |functions|. 24 // |functions|.
60 void ReplaceFunctionsForDefaultZone(const MallocZoneFunctions* functions); 25 void ReplaceFunctionsForStoredZones(const MallocZoneFunctions* functions);
61 26
62 extern bool g_replaced_default_zone; 27 extern bool g_replaced_default_zone;
63 28
64 // Calls the original implementation of malloc/calloc prior to interception. 29 // Calls the original implementation of malloc/calloc prior to interception.
65 bool UncheckedMallocMac(size_t size, void** result); 30 bool UncheckedMallocMac(size_t size, void** result);
66 bool UncheckedCallocMac(size_t num_items, size_t size, void** result); 31 bool UncheckedCallocMac(size_t num_items, size_t size, void** result);
67 32
68 // Intercepts calls to default and purgeable malloc zones. Intercepts Core 33 // Intercepts calls to default and purgeable malloc zones. Intercepts Core
69 // Foundation and Objective-C allocations. 34 // Foundation and Objective-C allocations.
70 // Has no effect on the default malloc zone if the allocator shim already 35 // Has no effect on the default malloc zone if the allocator shim already
71 // performs that interception. 36 // performs that interception.
72 BASE_EXPORT void InterceptAllocationsMac(); 37 BASE_EXPORT void InterceptAllocationsMac();
73 } // namespace allocator 38 } // namespace allocator
74 } // namespace base 39 } // namespace base
75 40
76 #endif // BASE_ALLOCATOR_ALLOCATOR_INTERCEPTION_MAC_H_ 41 #endif // BASE_ALLOCATOR_ALLOCATOR_INTERCEPTION_MAC_H_
OLDNEW
« no previous file with comments | « base/BUILD.gn ('k') | base/allocator/allocator_interception_mac.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698