From 07eb95df510dd0e01377ccb8479d44c4d70b6194 Mon Sep 17 00:00:00 2001 From: Ivan Basov Date: Fri, 2 Feb 2018 11:57:09 -0800 Subject: [PATCH] fixing AccessViolationException on ReadMetadataHeader (#24464) --- .../Core/Source/ExpressionCompiler/DkmUtilities.cs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/ExpressionEvaluator/Core/Source/ExpressionCompiler/DkmUtilities.cs b/src/ExpressionEvaluator/Core/Source/ExpressionCompiler/DkmUtilities.cs index 2916d8fe014..77a980064c5 100644 --- a/src/ExpressionEvaluator/Core/Source/ExpressionCompiler/DkmUtilities.cs +++ b/src/ExpressionEvaluator/Core/Source/ExpressionCompiler/DkmUtilities.cs @@ -49,6 +49,13 @@ private static IEnumerable GetModulesInAppDomain(this DkmC DkmClrAppDomain appDomain, ImmutableArray previousMetadataBlocks) { + // Add a dummy data item to the appdomain to add it to the disposal queue when the debugged process is shutting down. + // This should prevent from attempts to use the Metadata pointer for dead debugged processes. + if (appDomain.GetDataItem() == null) + { + appDomain.SetDataItem(DkmDataCreationDisposition.CreateNew, new AppDomainLifetimeDataItem()); + } + var builder = ArrayBuilder.GetInstance(); IntPtr ptr; uint size; @@ -324,5 +331,7 @@ internal MetadataContextItem(TMetadataContext metadataContext) this.MetadataContext = metadataContext; } } + + private sealed class AppDomainLifetimeDataItem : DkmDataItem { } } } -- GitLab