Add check for unloaded types in GetAppDomainStaticAddress (#34677)
authorDavid Mason <davmason@microsoft.com>
Fri, 10 Apr 2020 18:26:00 +0000 (11:26 -0700)
committerGitHub <noreply@github.com>
Fri, 10 Apr 2020 18:26:00 +0000 (11:26 -0700)
commit1ae617bc8f3644cd51faf124e399fb01c952be45
tree86a64d02b3e394e5d0aeb253456a2cc588440155
parentc0daac174be49fab065631f40ebc2cfd3f2c9525
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.
13 files changed:
src/coreclr/src/vm/proftoeeinterfaceimpl.cpp
src/coreclr/tests/src/profiler/native/CMakeLists.txt
src/coreclr/tests/src/profiler/native/classfactory.cpp
src/coreclr/tests/src/profiler/native/getappdomainstaticaddress/getappdomainstaticaddress.cpp [new file with mode: 0644]
src/coreclr/tests/src/profiler/native/getappdomainstaticaddress/getappdomainstaticaddress.h [new file with mode: 0644]
src/coreclr/tests/src/profiler/native/metadatagetdispenser/metadatagetdispenser.cpp [moved from src/coreclr/tests/src/profiler/native/unittestprofiler/unittestprofiler.cpp with 90% similarity]
src/coreclr/tests/src/profiler/native/metadatagetdispenser/metadatagetdispenser.h [moved from src/coreclr/tests/src/profiler/native/unittestprofiler/unittestprofiler.h with 87% similarity]
src/coreclr/tests/src/profiler/native/profilerstring.h
src/coreclr/tests/src/profiler/unittest/getappdomainstaticaddress.cs [new file with mode: 0644]
src/coreclr/tests/src/profiler/unittest/getappdomainstaticaddress.csproj [new file with mode: 0644]
src/coreclr/tests/src/profiler/unittest/metadatagetdispenser.cs
src/coreclr/tests/src/profiler/unittest/unloadlibrary.cs [new file with mode: 0644]
src/coreclr/tests/src/profiler/unittest/unloadlibrary.csproj [new file with mode: 0644]