ELUD: Replace a raw function pointer with base::RepeatingCallback
Uses a base::RepeatingCallback in order to resolve a layering violation instead of using a raw function pointer to the callback. Bug: 40944045 Change-Id: I6d36bb9186dbfda61b48f92f4b544df9bf69acdc Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5501158 Reviewed-by: Matthew Denton <mpdenton@chromium.org> Commit-Queue: Yuki Shiino <yukishiino@chromium.org> Reviewed-by: Siddhartha S <ssid@chromium.org> Cr-Commit-Position: refs/heads/main@{#1295354}
This commit is contained in:

committed by
Chromium LUCI CQ

parent
3039ef6d9c
commit
b94fcd30f1
base/trace_event
components/gwp_asan/client
@ -41,6 +41,7 @@
|
||||
#endif
|
||||
|
||||
#if PA_BUILDFLAG(USE_PARTITION_ALLOC_AS_MALLOC)
|
||||
#include "base/no_destructor.h"
|
||||
#include "partition_alloc/shim/allocator_shim_default_dispatch_to_partition_alloc.h"
|
||||
#endif
|
||||
|
||||
@ -317,16 +318,21 @@ MallocDumpProvider* MallocDumpProvider::GetInstance() {
|
||||
}
|
||||
|
||||
#if PA_BUILDFLAG(USE_PARTITION_ALLOC_AS_MALLOC)
|
||||
// static
|
||||
MallocDumpProvider::ExtremeLUDGetStatsCallback
|
||||
MallocDumpProvider::extreme_lud_get_stats_callback_ = nullptr;
|
||||
|
||||
// static
|
||||
void MallocDumpProvider::SetExtremeLUDGetStatsCallback(
|
||||
ExtremeLUDGetStatsCallback callback) {
|
||||
DCHECK(callback);
|
||||
DCHECK(!extreme_lud_get_stats_callback_);
|
||||
extreme_lud_get_stats_callback_ = callback;
|
||||
DCHECK(!callback.is_null());
|
||||
auto& extreme_lud_get_stats_callback = GetExtremeLUDGetStatsCallback();
|
||||
DCHECK(extreme_lud_get_stats_callback.is_null());
|
||||
extreme_lud_get_stats_callback = std::move(callback);
|
||||
}
|
||||
|
||||
// static
|
||||
MallocDumpProvider::ExtremeLUDGetStatsCallback&
|
||||
MallocDumpProvider::GetExtremeLUDGetStatsCallback() {
|
||||
static NoDestructor<MallocDumpProvider::ExtremeLUDGetStatsCallback>
|
||||
extreme_lud_get_stats_callback;
|
||||
return *extreme_lud_get_stats_callback;
|
||||
}
|
||||
#endif // PA_BUILDFLAG(USE_PARTITION_ALLOC_AS_MALLOC)
|
||||
|
||||
@ -438,9 +444,11 @@ bool MallocDumpProvider::OnMemoryDump(const MemoryDumpArgs& args,
|
||||
partitions_dump = pmd->CreateAllocatorDump("malloc/partitions");
|
||||
pmd->AddOwnershipEdge(inner_dump->guid(), partitions_dump->guid());
|
||||
|
||||
if (extreme_lud_get_stats_callback_) { // The Extreme LUD is enabled.
|
||||
auto& extreme_lud_get_stats_callback = GetExtremeLUDGetStatsCallback();
|
||||
if (!extreme_lud_get_stats_callback.is_null()) {
|
||||
// The Extreme LUD is enabled.
|
||||
elud_dump = pmd->CreateAllocatorDump("malloc/extreme_lud");
|
||||
elud_stats = extreme_lud_get_stats_callback_();
|
||||
elud_stats = extreme_lud_get_stats_callback.Run();
|
||||
ReportPartitionAllocLightweightQuarantineStats(elud_dump,
|
||||
elud_stats.lq_stats);
|
||||
}
|
||||
|
@ -7,6 +7,7 @@
|
||||
|
||||
#include "base/allocator/buildflags.h"
|
||||
#include "base/base_export.h"
|
||||
#include "base/functional/callback.h"
|
||||
#include "base/memory/raw_ptr.h"
|
||||
#include "base/memory/singleton.h"
|
||||
#include "base/synchronization/lock.h"
|
||||
@ -44,7 +45,7 @@ class BASE_EXPORT MallocDumpProvider : public MemoryDumpProvider {
|
||||
size_t capacity_in_bytes = 0;
|
||||
};
|
||||
#if PA_BUILDFLAG(USE_PARTITION_ALLOC_AS_MALLOC)
|
||||
using ExtremeLUDGetStatsCallback = ExtremeLUDStats (*)();
|
||||
using ExtremeLUDGetStatsCallback = RepeatingCallback<ExtremeLUDStats()>;
|
||||
static void SetExtremeLUDGetStatsCallback(
|
||||
ExtremeLUDGetStatsCallback callback);
|
||||
#endif // PA_BUILDFLAG(USE_PARTITION_ALLOC_AS_MALLOC)
|
||||
@ -75,9 +76,9 @@ class BASE_EXPORT MallocDumpProvider : public MemoryDumpProvider {
|
||||
base::Lock emit_metrics_on_memory_dump_lock_;
|
||||
|
||||
#if PA_BUILDFLAG(USE_PARTITION_ALLOC_AS_MALLOC)
|
||||
// The injected stats-report function of the Extreme LUD. Non-null iff the
|
||||
// Extreme LUD is enabled.
|
||||
static ExtremeLUDGetStatsCallback extreme_lud_get_stats_callback_;
|
||||
// Returns a reference to the injected stats-report function of the Extreme
|
||||
// LUD. The returned callback is_null() if the Extreme LUD is not enabled.
|
||||
static ExtremeLUDGetStatsCallback& GetExtremeLUDGetStatsCallback();
|
||||
// To be accurate, this requires the dump provider to be created very early,
|
||||
// which is the case. The alternative would be to drop the first data point,
|
||||
// which is not desirable as early process activity is highly relevant.
|
||||
@ -88,7 +89,7 @@ class BASE_EXPORT MallocDumpProvider : public MemoryDumpProvider {
|
||||
size_t last_cumulative_elud_quarantined_bytes_ = 0;
|
||||
size_t last_cumulative_elud_quarantined_count_ = 0;
|
||||
size_t last_cumulative_elud_miss_count_ = 0;
|
||||
#endif
|
||||
#endif // PA_BUILDFLAG(USE_PARTITION_ALLOC_AS_MALLOC)
|
||||
};
|
||||
|
||||
#if PA_BUILDFLAG(USE_PARTITION_ALLOC)
|
||||
|
@ -6,6 +6,7 @@
|
||||
|
||||
#include <atomic>
|
||||
|
||||
#include "base/functional/bind.h"
|
||||
#include "base/no_destructor.h"
|
||||
#include "base/trace_event/malloc_dump_provider.h"
|
||||
#include "components/gwp_asan/client/sampling_state.h"
|
||||
@ -242,7 +243,7 @@ void InstallExtremeLightweightDetectorHooks(
|
||||
|
||||
#if PA_BUILDFLAG(USE_PARTITION_ALLOC_AS_MALLOC)
|
||||
base::trace_event::MallocDumpProvider::SetExtremeLUDGetStatsCallback(
|
||||
GetStats);
|
||||
base::BindRepeating(GetStats));
|
||||
#endif // PA_BUILDFLAG(USE_PARTITION_ALLOC_AS_MALLOC)
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user