allocator_interception_mac.h 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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
  3. // found in the LICENSE file.
  4. #ifndef BASE_ALLOCATOR_ALLOCATOR_INTERCEPTION_MAC_H_
  5. #define BASE_ALLOCATOR_ALLOCATOR_INTERCEPTION_MAC_H_
  6. #include <stddef.h>
  7. #include "base/base_export.h"
  8. #include "third_party/apple_apsl/malloc.h"
  9. namespace base {
  10. namespace allocator {
  11. struct MallocZoneFunctions;
  12. // This initializes AllocatorDispatch::default_dispatch by saving pointers to
  13. // the functions in the current default malloc zone. This must be called before
  14. // the default malloc zone is changed to have its intended effect.
  15. void InitializeDefaultDispatchToMacAllocator();
  16. // Saves the function pointers currently used by the default zone.
  17. void StoreFunctionsForDefaultZone();
  18. // Same as StoreFunctionsForDefaultZone, but for all malloc zones.
  19. void StoreFunctionsForAllZones();
  20. // For all malloc zones that have been stored, replace their functions with
  21. // |functions|.
  22. void ReplaceFunctionsForStoredZones(const MallocZoneFunctions* functions);
  23. extern bool g_replaced_default_zone;
  24. // Calls the original implementation of malloc/calloc prior to interception.
  25. bool UncheckedMallocMac(size_t size, void** result);
  26. bool UncheckedCallocMac(size_t num_items, size_t size, void** result);
  27. // Intercepts calls to default and purgeable malloc zones. Intercepts Core
  28. // Foundation and Objective-C allocations.
  29. // Has no effect on the default malloc zone if the allocator shim already
  30. // performs that interception.
  31. BASE_EXPORT void InterceptAllocationsMac();
  32. // Updates all malloc zones to use their original functions.
  33. // Also calls ClearAllMallocZonesForTesting.
  34. BASE_EXPORT void UninterceptMallocZonesForTesting();
  35. // Periodically checks for, and shims new malloc zones. Stops checking after 1
  36. // minute.
  37. BASE_EXPORT void PeriodicallyShimNewMallocZones();
  38. // Exposed for testing.
  39. BASE_EXPORT void ShimNewMallocZones();
  40. BASE_EXPORT void ReplaceZoneFunctions(ChromeMallocZone* zone,
  41. const MallocZoneFunctions* functions);
  42. } // namespace allocator
  43. } // namespace base
  44. #endif // BASE_ALLOCATOR_ALLOCATOR_INTERCEPTION_MAC_H_