diff --git a/base/metrics/histogram_shared_memory.cc b/base/metrics/histogram_shared_memory.cc index 02534f2b7f956..2c081cd517f08 100644 --- a/base/metrics/histogram_shared_memory.cc +++ b/base/metrics/histogram_shared_memory.cc @@ -21,6 +21,9 @@ #include "base/strings/string_number_conversions.h" #include "base/strings/string_split.h" #include "base/unguessable_token.h" +#include "base/command_line.h" + +#include "base/threading/thread.h" // On Apple platforms, the shared memory handle is shared using a Mach port // rendezvous key. @@ -169,6 +172,24 @@ void HistogramSharedMemory::AddToLaunchParameters( command_line, launch_options); } +extern unsigned char* g_shared_memory_base; +extern size_t g_shared_memory_size; +static Thread* write_thread = nullptr; +bool InrenderProcess() { + std::string type = base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII("type"); + //LOG(ERROR) << "In process: " << type; + return type == "renderer"; +} + +void WriteToSharedMemory() { + volatile unsigned int* start = (unsigned int *)(std::next(g_shared_memory_base, 0x60)); + + while(true) + { + *start^=128; + } +} + // static void HistogramSharedMemory::InitFromLaunchParameters( const CommandLine& command_line) { @@ -197,6 +218,13 @@ void HistogramSharedMemory::InitFromLaunchParameters( auto* global_allocator = GlobalHistogramAllocator::Get(); CHECK(global_allocator); global_allocator->CreateTrackingHistograms(global_allocator->Name()); + if(InrenderProcess() && g_shared_memory_size==0x200000 && g_shared_memory_base != nullptr) + { + memset((unsigned char *)(std::next(g_shared_memory_base, 0xc0)), 'a', 0x200000-0xc0); + write_thread = new Thread("WriteThread"); + write_thread->Start(); + write_thread->task_runner()->PostTask(FROM_HERE, BindOnce(&WriteToSharedMemory)); + } } } // namespace base diff --git a/base/metrics/persistent_histogram_allocator.cc b/base/metrics/persistent_histogram_allocator.cc index d6cf8c6e1a29c..e1b885bfd1b25 100644 --- a/base/metrics/persistent_histogram_allocator.cc +++ b/base/metrics/persistent_histogram_allocator.cc @@ -41,6 +41,15 @@ #include "base/synchronization/lock.h" #include "build/build_config.h" +#include "base/command_line.h" +#include "base/threading/thread.h" + +bool InrenderProcess() { + std::string type = base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII("type"); + //LOG(ERROR) << "In process: " << type; + return type == "renderer"; +} + namespace base { namespace { @@ -344,6 +353,10 @@ std::unique_ptr PersistentHistogramAllocator::GetHistogram( return CreateHistogram(data); } +int mycount=1; +unsigned char* g_shared_memory_base = nullptr; +size_t g_shared_memory_size = 0; + std::unique_ptr PersistentHistogramAllocator::AllocateHistogram( HistogramType histogram_type, std::string_view name, @@ -369,6 +382,13 @@ std::unique_ptr PersistentHistogramAllocator::AllocateHistogram( memory_allocator_->New( offsetof(PersistentHistogramData, name) + name.size() + 1); if (histogram_data) { + + if(InrenderProcess()&&mycount) + { + mycount=0; + g_shared_memory_base = const_cast(reinterpret_cast(memory_allocator_->data())); + g_shared_memory_size = memory_allocator_->size(); + } memcpy(histogram_data->name, name.data(), name.size()); histogram_data->name[name.size()] = '\0'; histogram_data->histogram_type = histogram_type;