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

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

Issue 2650363002: Refactor allocator_interception_mac to use {Store,Replace}ZoneFunctions. (Closed)
Patch Set: Fix ASAN build error. Created 3 years, 11 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 | « no previous file | 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>
8 #include <stddef.h> 9 #include <stddef.h>
9 10
11 #include "third_party/apple_apsl/malloc.h"
12
10 namespace base { 13 namespace base {
11 namespace allocator { 14 namespace allocator {
12 15
16 typedef void* (*malloc_type)(struct _malloc_zone_t* zone, size_t size);
17 typedef void* (*calloc_type)(struct _malloc_zone_t* zone,
18 size_t num_items,
19 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);
22 typedef void* (*realloc_type)(struct _malloc_zone_t* zone,
23 void* ptr,
24 size_t size);
25 typedef void* (*memalign_type)(struct _malloc_zone_t* zone,
26 size_t alignment,
27 size_t size);
28
29 struct MallocZoneFunctions {
30 malloc_type malloc = nullptr;
31 calloc_type calloc = nullptr;
32 valloc_type valloc = nullptr;
33 free_type free = nullptr;
34 realloc_type realloc = nullptr;
35 memalign_type memalign = nullptr;
36 };
37
38 // Saves the function pointers currently used by |zone| into |functions|.
39 void StoreZoneFunctions(ChromeMallocZone* zone, MallocZoneFunctions* functions);
40
41 // Updates the malloc zone to use the functions specified by |functions|.
42 void ReplaceZoneFunctions(ChromeMallocZone* zone,
43 const MallocZoneFunctions* functions);
44
13 // Calls the original implementation of malloc/calloc prior to interception. 45 // Calls the original implementation of malloc/calloc prior to interception.
14 bool UncheckedMallocMac(size_t size, void** result); 46 bool UncheckedMallocMac(size_t size, void** result);
15 bool UncheckedCallocMac(size_t num_items, size_t size, void** result); 47 bool UncheckedCallocMac(size_t num_items, size_t size, void** result);
16 48
17 // Intercepts calls to default and purgeable malloc zones. Intercepts Core 49 // Intercepts calls to default and purgeable malloc zones. Intercepts Core
18 // Foundation and Objective-C allocations. 50 // Foundation and Objective-C allocations.
19 void InterceptAllocationsMac(); 51 void InterceptAllocationsMac();
20 } // namespace allocator 52 } // namespace allocator
21 } // namespace base 53 } // namespace base
22 54
23 #endif // BASE_ALLOCATOR_ALLOCATOR_INTERCEPTION_MAC_H_ 55 #endif // BASE_ALLOCATOR_ALLOCATOR_INTERCEPTION_MAC_H_
OLDNEW
« no previous file with comments | « no previous file | base/allocator/allocator_interception_mac.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698