Skip to content

Commit 1ae617b

Browse files
authored
Add check for unloaded types in GetAppDomainStaticAddress (#34677)
Fixes #33367 When a module is unloaded, the managed objectref is collected during a GC before the profiler is notified that the module is unloading. That means if you call in to GetAppDomainStaticAddress between when the object is collected and when you are notified about the module unload (GarbageCollectionFinished is a place that will hit this every time) it will cause an AV from trying to use the null objectref. This fix prevents this AV by checking to see if the object's loaderheap or managed loaderheap object ref are invalid first.
1 parent c0daac1 commit 1ae617b

File tree

13 files changed

+830
-26
lines changed

13 files changed

+830
-26
lines changed

src/coreclr/src/vm/proftoeeinterfaceimpl.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3145,6 +3145,12 @@ HRESULT ProfToEEInterfaceImpl::GetAppDomainStaticAddress(ClassID classId,
31453145
return CORPROF_E_DATAINCOMPLETE;
31463146
}
31473147

3148+
if (typeHandle.GetModule()->GetLoaderAllocator() == NULL ||
3149+
typeHandle.GetModule()->GetLoaderAllocator()->GetExposedObject() == NULL)
3150+
{
3151+
return CORPROF_E_DATAINCOMPLETE;
3152+
}
3153+
31483154
//
31493155
// Get the field descriptor object
31503156
//

src/coreclr/tests/src/profiler/native/CMakeLists.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@ project(Profiler)
55
set(GCBASIC_SOURCES gcbasicprofiler/gcbasicprofiler.cpp)
66
set(REJIT_SOURCES rejitprofiler/rejitprofiler.cpp rejitprofiler/ilrewriter.cpp rejitprofiler/sigparse.cpp)
77
set(EVENTPIPE_SOURCES eventpipeprofiler/eventpipeprofiler.cpp)
8-
set(UNITTEST_SOURCES unittestprofiler/unittestprofiler.cpp)
8+
set(METADATAGETDISPENSER_SOURCES metadatagetdispenser/metadatagetdispenser.cpp)
9+
set(GETAPPDOMAINSTATICADDRESS_SOURCES getappdomainstaticaddress/getappdomainstaticaddress.cpp)
910

10-
set(SOURCES ${GCBASIC_SOURCES} ${REJIT_SOURCES} ${EVENTPIPE_SOURCES} ${UNITTEST_SOURCES} profiler.def profiler.cpp classfactory.cpp dllmain.cpp guids.cpp)
11+
set(SOURCES ${GCBASIC_SOURCES} ${REJIT_SOURCES} ${EVENTPIPE_SOURCES} ${METADATAGETDISPENSER_SOURCES} ${GETAPPDOMAINSTATICADDRESS_SOURCES} profiler.def profiler.cpp classfactory.cpp dllmain.cpp guids.cpp)
1112

1213
include_directories(../../../../src/pal/prebuilt/inc)
1314

src/coreclr/tests/src/profiler/native/classfactory.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
#include "gcbasicprofiler/gcbasicprofiler.h"
77
#include "rejitprofiler/rejitprofiler.h"
88
#include "eventpipeprofiler/eventpipeprofiler.h"
9-
#include "unittestprofiler/unittestprofiler.h"
9+
#include "metadatagetdispenser/metadatagetdispenser.h"
10+
#include "getappdomainstaticaddress/getappdomainstaticaddress.h"
1011

1112
ClassFactory::ClassFactory(REFCLSID clsid) : refCount(0), clsid(clsid)
1213
{
@@ -58,7 +59,8 @@ HRESULT STDMETHODCALLTYPE ClassFactory::CreateInstance(IUnknown *pUnkOuter, REFI
5859
new GCBasicProfiler(),
5960
new ReJITProfiler(),
6061
new EventPipeProfiler(),
61-
new UnitTestProfiler()
62+
new MetaDataGetDispenser(),
63+
new GetAppDomainStaticAddress()
6264
// add new profilers here
6365
};
6466

0 commit comments

Comments
 (0)