Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit 62422d7

Browse files
author
Victor "Nate" Graf
authored
Revert "Fix SIGSEGV in EventPipe on Shutdown (#14123) (#15765)" (#16084)
This reverts commit 381e6b1.
1 parent 381e6b1 commit 62422d7

File tree

5 files changed

+22
-72
lines changed

5 files changed

+22
-72
lines changed

src/vm/eventpipe.cpp

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -248,13 +248,7 @@ EventPipeProvider* EventPipe::CreateProvider(const GUID &providerID, EventPipeCa
248248
}
249249
CONTRACTL_END;
250250

251-
EventPipeProvider *pProvider = NULL;
252-
if (s_pConfig != NULL)
253-
{
254-
pProvider = s_pConfig->CreateProvider(providerID, pCallbackFunction, pCallbackData);
255-
}
256-
257-
return pProvider;
251+
return new EventPipeProvider(providerID, pCallbackFunction, pCallbackData);
258252
}
259253

260254
void EventPipe::DeleteProvider(EventPipeProvider *pProvider)
@@ -282,10 +276,8 @@ void EventPipe::DeleteProvider(EventPipeProvider *pProvider)
282276
else
283277
{
284278
// Delete the provider now.
285-
if (s_pConfig != NULL)
286-
{
287-
s_pConfig->DeleteProvider(pProvider);
288-
}
279+
// NOTE: This will remove it from all of the EventPipe data structures.
280+
delete(pProvider);
289281
}
290282
}
291283
}

src/vm/eventpipeconfiguration.cpp

Lines changed: 3 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,6 @@ EventPipeConfiguration::~EventPipeConfiguration()
3434
MODE_ANY;
3535
}
3636
CONTRACTL_END;
37-
38-
if(m_pConfigProvider != NULL)
39-
{
40-
DeleteProvider(m_pConfigProvider);
41-
}
4237

4338
if(m_pEnabledProviderList != NULL)
4439
{
@@ -64,7 +59,7 @@ void EventPipeConfiguration::Initialize()
6459
CONTRACTL_END;
6560

6661
// Create the configuration provider.
67-
m_pConfigProvider = CreateProvider(s_configurationProviderID, NULL, NULL);
62+
m_pConfigProvider = EventPipe::CreateProvider(s_configurationProviderID);
6863

6964
// Create the metadata event.
7065
m_pMetadataEvent = m_pConfigProvider->AddEvent(
@@ -75,49 +70,6 @@ void EventPipeConfiguration::Initialize()
7570
false); /* needStack */
7671
}
7772

78-
EventPipeProvider* EventPipeConfiguration::CreateProvider(const GUID &providerID, EventPipeCallback pCallbackFunction, void *pCallbackData)
79-
{
80-
CONTRACTL
81-
{
82-
THROWS;
83-
GC_NOTRIGGER;
84-
MODE_ANY;
85-
}
86-
CONTRACTL_END;
87-
88-
// Allocate a new provider.
89-
EventPipeProvider *pProvider = new EventPipeProvider(this, providerID, pCallbackFunction, pCallbackData);
90-
91-
// Register the provider with the configuration system.
92-
RegisterProvider(*pProvider);
93-
94-
return pProvider;
95-
}
96-
97-
void EventPipeConfiguration::DeleteProvider(EventPipeProvider *pProvider)
98-
{
99-
CONTRACTL
100-
{
101-
THROWS;
102-
GC_NOTRIGGER;
103-
MODE_ANY;
104-
PRECONDITION(pProvider != NULL);
105-
}
106-
CONTRACTL_END;
107-
108-
if (pProvider == NULL)
109-
{
110-
return;
111-
}
112-
113-
// Unregister the provider.
114-
UnregisterProvider(*pProvider);
115-
116-
// Free the provider itself.
117-
delete(pProvider);
118-
}
119-
120-
12173
bool EventPipeConfiguration::RegisterProvider(EventPipeProvider &provider)
12274
{
12375
CONTRACTL
@@ -448,7 +400,8 @@ void EventPipeConfiguration::DeleteDeferredProviders()
448400
EventPipeProvider *pProvider = pElem->GetValue();
449401
if(pProvider->GetDeleteDeferred())
450402
{
451-
DeleteProvider(pProvider);
403+
// The act of deleting the provider unregisters it and removes it from the list.
404+
delete(pProvider);
452405
}
453406

454407
pElem = m_pProviderList->GetNext(pElem);

src/vm/eventpipeconfiguration.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
#ifdef FEATURE_PERFTRACING
88

9-
#include "eventpipe.h"
109
#include "slist.h"
1110

1211
class EventPipeEnabledProvider;
@@ -36,12 +35,6 @@ class EventPipeConfiguration
3635
// Perform initialization that cannot be performed in the constructor.
3736
void Initialize();
3837

39-
// Create a new provider.
40-
EventPipeProvider* CreateProvider(const GUID &providerID, EventPipeCallback pCallbackFunction, void *pCallbackData);
41-
42-
// Delete a provider.
43-
void DeleteProvider(EventPipeProvider *pProvider);
44-
4538
// Register a provider.
4639
bool RegisterProvider(EventPipeProvider &provider);
4740

src/vm/eventpipeprovider.cpp

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,13 @@
1010

1111
#ifdef FEATURE_PERFTRACING
1212

13-
EventPipeProvider::EventPipeProvider(EventPipeConfiguration *pConfig, const GUID &providerID, EventPipeCallback pCallbackFunction, void *pCallbackData)
13+
EventPipeProvider::EventPipeProvider(const GUID &providerID, EventPipeCallback pCallbackFunction, void *pCallbackData)
1414
{
1515
CONTRACTL
1616
{
1717
THROWS;
1818
GC_NOTRIGGER;
1919
MODE_ANY;
20-
PRECONDITION(pConfig != NULL);
2120
}
2221
CONTRACTL_END;
2322

@@ -28,7 +27,11 @@ EventPipeProvider::EventPipeProvider(EventPipeConfiguration *pConfig, const GUID
2827
m_pEventList = new SList<SListElem<EventPipeEvent*>>();
2928
m_pCallbackFunction = pCallbackFunction;
3029
m_pCallbackData = pCallbackData;
31-
m_pConfig = pConfig;
30+
m_pConfig = EventPipe::GetConfiguration();
31+
_ASSERTE(m_pConfig != NULL);
32+
33+
// Register the provider.
34+
m_pConfig->RegisterProvider(*this);
3235
}
3336

3437
EventPipeProvider::~EventPipeProvider()
@@ -41,6 +44,15 @@ EventPipeProvider::~EventPipeProvider()
4144
}
4245
CONTRACTL_END;
4346

47+
// Unregister the provider.
48+
// This call is re-entrant.
49+
// NOTE: We don't use the cached event pipe configuration pointer
50+
// in case this runs during shutdown and the configuration has already
51+
// been freed.
52+
EventPipeConfiguration* pConfig = EventPipe::GetConfiguration();
53+
_ASSERTE(pConfig != NULL);
54+
pConfig->UnregisterProvider(*this);
55+
4456
// Free all of the events.
4557
if(m_pEventList != NULL)
4658
{

src/vm/eventpipeprovider.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ class EventPipeProvider
6161
bool m_deleteDeferred;
6262

6363
// Private constructor because all providers are created through EventPipe::CreateProvider.
64-
EventPipeProvider(EventPipeConfiguration *pConfig, const GUID &providerID, EventPipeCallback pCallbackFunction = NULL, void *pCallbackData = NULL);
64+
EventPipeProvider(const GUID &providerID, EventPipeCallback pCallbackFunction = NULL, void *pCallbackData = NULL);
6565

6666
public:
6767

0 commit comments

Comments
 (0)