#include "components/memory_system/memory_system.h"
#include "base/allocator/dispatcher/dispatcher.h"
#include "base/allocator/dispatcher/initializer.h"
#include "base/debug/crash_logging.h"
#include "base/debug/debugging_buildflags.h"
#include "build/build_config.h"
#include "components/gwp_asan/buildflags/buildflags.h"
#include "components/memory_system/buildflags.h"
#include "components/memory_system/memory_system_features.h"
#include "components/memory_system/parameters.h"
#include "partition_alloc/buildflags.h"
#include "third_party/abseil-cpp/absl/base/attributes.h"
#if BUILDFLAG(ENABLE_GWP_ASAN)
#include "components/gwp_asan/client/gwp_asan.h"
#if BUILDFLAG(IS_CHROMEOS)
#include "components/crash/core/app/crashpad.h"
#endif
#endif
#if BUILDFLAG(IS_IOS) && PA_BUILDFLAG(USE_ALLOCATOR_SHIM)
#include "base/ios/ios_util.h"
#include "base/metrics/histogram_functions.h"
#include "partition_alloc/shim/allocator_interception_apple.h"
#include "partition_alloc/shim/allocator_shim.h"
#endif
#if !BUILDFLAG(IS_IOS) || PA_BUILDFLAG(USE_ALLOCATOR_SHIM)
#define HEAP_PROFILING_SUPPORTED …
#else
#define HEAP_PROFILING_SUPPORTED …
#endif
#if HEAP_PROFILING_SUPPORTED
#include "components/heap_profiling/in_process/heap_profiler_controller.h"
#include "components/services/heap_profiling/public/cpp/profiling_client.h"
#endif
#if HEAP_PROFILING_SUPPORTED
#include "base/sampling_heap_profiler/poisson_allocation_sampler.h"
#endif
#if BUILDFLAG(ENABLE_ALLOCATION_STACK_TRACE_RECORDER)
#include "base/cpu.h"
#include "base/debug/allocation_trace.h"
#include "components/allocation_recorder/crash_client/client.h"
#if BUILDFLAG(ENABLE_ALLOCATION_TRACE_RECORDER_FULL_REPORTING)
#include "components/memory_system/allocation_trace_recorder_statistics_reporter.h"
#endif
#endif
namespace memory_system {
namespace {
#if BUILDFLAG(IS_IOS) && PA_BUILDFLAG(USE_ALLOCATOR_SHIM)
bool ShouldInstallAllocatorShim() {
return !base::ios::IsRunningOnOrLater(13, 4, 0) ||
base::ios::IsRunningOnOrLater(13, 5, 0);
}
#endif
}
struct MemorySystem::Impl { … };
MemorySystem::Impl::Impl() { … }
MemorySystem::Impl::~Impl() { … }
void MemorySystem::Impl::Initialize(
const std::optional<GwpAsanParameters>& gwp_asan_parameters,
const std::optional<ProfilingClientParameters>& profiling_client_parameters,
const std::optional<DispatcherParameters>& dispatcher_parameters) { … }
bool MemorySystem::Impl::IsAllocatorShimInitialized() { … }
void MemorySystem::Impl::InitializeGwpASan(
const GwpAsanParameters& gwp_asan_parameters,
InitializationData& initialization_data) { … }
void MemorySystem::Impl::InitializeHeapProfiler(
const ProfilingClientParameters& profiling_client_parameters,
InitializationData& initialization_data) { … }
#if HEAP_PROFILING_SUPPORTED
bool MemorySystem::Impl::DispatcherIncludesPoissonAllocationSampler(
const DispatcherParameters& dispatcher_parameters,
const InitializationData& initialization_data) { … }
#endif
#if BUILDFLAG(ENABLE_ALLOCATION_STACK_TRACE_RECORDER)
bool MemorySystem::Impl::DispatcherIncludesAllocationTraceRecorder(
const DispatcherParameters& dispatcher_parameters) {
#if BUILDFLAG(FORCE_ALLOCATION_TRACE_RECORDER)
return true;
#else
switch (dispatcher_parameters.allocation_trace_recorder_inclusion) {
case DispatcherParameters::AllocationTraceRecorderInclusion::kDynamic:
return base::CPU::GetInstanceNoAllocation().has_mte() &&
base::FeatureList::IsEnabled(features::kAllocationTraceRecorder);
case DispatcherParameters::AllocationTraceRecorderInclusion::kIgnore:
return false;
}
#endif
}
#endif
void MemorySystem::Impl::InitializeDispatcher(
const DispatcherParameters& dispatcher_parameters,
InitializationData& initialization_data) { … }
MemorySystem::MemorySystem() : … { … }
MemorySystem::~MemorySystem() = default;
void MemorySystem::Initialize(
const std::optional<GwpAsanParameters>& gwp_asan_parameters,
const std::optional<ProfilingClientParameters>& profiling_client_parameters,
const std::optional<DispatcherParameters>& dispatcher_parameters) { … }
}