From 88b7b2835b948349fa9c3d69f068a0448e26679b Mon Sep 17 00:00:00 2001 From: Andrew Au Date: Thu, 24 Nov 2022 13:16:54 -0800 Subject: [PATCH] Make sure s_currentGenerationTable is safe for profiler attach --- src/coreclr/vm/proftoeeinterfaceimpl.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/coreclr/vm/proftoeeinterfaceimpl.cpp b/src/coreclr/vm/proftoeeinterfaceimpl.cpp index 79167f7dc706b5..a7961985d4b6e6 100644 --- a/src/coreclr/vm/proftoeeinterfaceimpl.cpp +++ b/src/coreclr/vm/proftoeeinterfaceimpl.cpp @@ -901,7 +901,7 @@ void GenerationTable::Refresh() // This is the table of generation bounds updated by the gc // and read by the profiler. -static GenerationTable *s_currentGenerationTable; +static GenerationTable *s_currentGenerationTable = nullptr; // This is just so we can assert there's a single writer #ifdef ENABLE_CONTRACTS @@ -931,7 +931,6 @@ void __stdcall UpdateGenerationBounds() // Notify the profiler of start of the collection if (CORProfilerTrackGC() || CORProfilerTrackBasicGC()) { - if (s_currentGenerationTable == nullptr) { EX_TRY @@ -965,7 +964,10 @@ void __stdcall ProfilerAddNewRegion(int generation, uint8_t* rangeStart, uint8_t #ifdef PROFILING_SUPPORTED if (CORProfilerTrackGC() || CORProfilerTrackBasicGC()) { - s_currentGenerationTable->AddRecord(generation, rangeStart, rangeEnd, rangeEndReserved); + if (s_currentGenerationTable != nullptr) + { + s_currentGenerationTable->AddRecord(generation, rangeStart, rangeEnd, rangeEndReserved); + } } #endif // PROFILING_SUPPORTED RETURN;