| 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 "base/base_export.h" |
| 11 #include "third_party/apple_apsl/malloc.h" | 12 #include "third_party/apple_apsl/malloc.h" |
| 12 | 13 |
| 13 namespace base { | 14 namespace base { |
| 14 namespace allocator { | 15 namespace allocator { |
| 15 | 16 |
| 16 typedef void* (*malloc_type)(struct _malloc_zone_t* zone, size_t size); | 17 typedef void* (*malloc_type)(struct _malloc_zone_t* zone, size_t size); |
| 17 typedef void* (*calloc_type)(struct _malloc_zone_t* zone, | 18 typedef void* (*calloc_type)(struct _malloc_zone_t* zone, |
| 18 size_t num_items, | 19 size_t num_items, |
| 19 size_t size); | 20 size_t size); |
| 20 typedef void* (*valloc_type)(struct _malloc_zone_t* zone, size_t size); | 21 typedef void* (*valloc_type)(struct _malloc_zone_t* zone, size_t size); |
| (...skipping 30 matching lines...) Expand all Loading... |
| 51 size_fn_type size = nullptr; | 52 size_fn_type size = nullptr; |
| 52 }; | 53 }; |
| 53 | 54 |
| 54 // Saves the function pointers currently used by default zone into |functions|. | 55 // Saves the function pointers currently used by default zone into |functions|. |
| 55 void StoreFunctionsForDefaultZone(MallocZoneFunctions* functions); | 56 void StoreFunctionsForDefaultZone(MallocZoneFunctions* functions); |
| 56 | 57 |
| 57 // Updates the default malloc zone to use the functions specified by | 58 // Updates the default malloc zone to use the functions specified by |
| 58 // |functions|. | 59 // |functions|. |
| 59 void ReplaceFunctionsForDefaultZone(const MallocZoneFunctions* functions); | 60 void ReplaceFunctionsForDefaultZone(const MallocZoneFunctions* functions); |
| 60 | 61 |
| 62 extern bool g_replaced_default_zone; |
| 63 |
| 61 // Calls the original implementation of malloc/calloc prior to interception. | 64 // Calls the original implementation of malloc/calloc prior to interception. |
| 62 bool UncheckedMallocMac(size_t size, void** result); | 65 bool UncheckedMallocMac(size_t size, void** result); |
| 63 bool UncheckedCallocMac(size_t num_items, size_t size, void** result); | 66 bool UncheckedCallocMac(size_t num_items, size_t size, void** result); |
| 64 | 67 |
| 65 // Intercepts calls to default and purgeable malloc zones. Intercepts Core | 68 // Intercepts calls to default and purgeable malloc zones. Intercepts Core |
| 66 // Foundation and Objective-C allocations. | 69 // Foundation and Objective-C allocations. |
| 67 // Has no effect on the default malloc zone if the allocator shim already | 70 // Has no effect on the default malloc zone if the allocator shim already |
| 68 // performs that interception. | 71 // performs that interception. |
| 69 void InterceptAllocationsMac(); | 72 BASE_EXPORT void InterceptAllocationsMac(); |
| 70 } // namespace allocator | 73 } // namespace allocator |
| 71 } // namespace base | 74 } // namespace base |
| 72 | 75 |
| 73 #endif // BASE_ALLOCATOR_ALLOCATOR_INTERCEPTION_MAC_H_ | 76 #endif // BASE_ALLOCATOR_ALLOCATOR_INTERCEPTION_MAC_H_ |
| OLD | NEW |