allocator_interception_mac.h 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. // Returns true if allocations are successfully being intercepted for all malloc
  36. // zones.
  37. bool AreMallocZonesIntercepted();
  38. // Periodically checks for, and shims new malloc zones. Stops checking after 1
  39. // minute.
  40. BASE_EXPORT void PeriodicallyShimNewMallocZones();
  41. // Exposed for testing.
  42. BASE_EXPORT void ShimNewMallocZones();
  43. BASE_EXPORT void ReplaceZoneFunctions(ChromeMallocZone* zone,
  44. const MallocZoneFunctions* functions);
  45. } // namespace allocator
  46. } // namespace base
  47. #endif // BASE_ALLOCATOR_ALLOCATOR_INTERCEPTION_MAC_H_