1 // Copyright 2022 The Chromium Authors 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef BASE_ALLOCATOR_DISPATCHER_INTERNAL_DISPATCH_DATA_H_ 6 #define BASE_ALLOCATOR_DISPATCHER_INTERNAL_DISPATCH_DATA_H_ 7 8 #include "base/base_export.h" 9 #include "build/build_config.h" 10 #include "partition_alloc/partition_alloc_buildflags.h" 11 12 #if BUILDFLAG(USE_PARTITION_ALLOC) 13 #include "partition_alloc/partition_alloc_hooks.h" 14 #endif 15 16 #if BUILDFLAG(USE_ALLOCATOR_SHIM) 17 #include "partition_alloc/shim/allocator_shim.h" 18 #endif 19 20 namespace base::allocator::dispatcher::internal { 21 22 #if BUILDFLAG(USE_ALLOCATOR_SHIM) 23 using allocator_shim::AllocatorDispatch; 24 #endif 25 26 // A simple utility class to pass all the information required to properly hook 27 // into the memory allocation subsystems from DispatcherImpl to the Dispatcher. 28 struct BASE_EXPORT DispatchData { 29 #if BUILDFLAG(USE_PARTITION_ALLOC) 30 using AllocationObserverHook = 31 partition_alloc::PartitionAllocHooks::AllocationObserverHook; 32 using FreeObserverHook = 33 partition_alloc::PartitionAllocHooks::FreeObserverHook; 34 35 DispatchData& SetAllocationObserverHooks(AllocationObserverHook*, 36 FreeObserverHook*); 37 AllocationObserverHook* GetAllocationObserverHook() const; 38 FreeObserverHook* GetFreeObserverHook() const; 39 40 private: 41 AllocationObserverHook* allocation_observer_hook_ = nullptr; 42 FreeObserverHook* free_observer_hook_ = nullptr; 43 44 public: 45 #endif 46 47 #if BUILDFLAG(USE_ALLOCATOR_SHIM) 48 DispatchData& SetAllocatorDispatch(AllocatorDispatch* allocator_dispatch); 49 AllocatorDispatch* GetAllocatorDispatch() const; 50 51 private: 52 AllocatorDispatch* allocator_dispatch_ = nullptr; 53 #endif 54 }; 55 56 } // namespace base::allocator::dispatcher::internal 57 58 #endif // BASE_ALLOCATOR_DISPATCHER_INTERNAL_DISPATCH_DATA_H_ 59