From 67af5834bf890632fe975fa27cae35c8404e726e Mon Sep 17 00:00:00 2001 From: Noah Falk Date: Fri, 22 Jun 2018 19:14:15 -0700 Subject: [PATCH] Fix incorrect usage of ILCodeVersion::AsNode (issue #18602) (#18606) When the debugger is querying the active rejit IL for an IL method that has not been rejitted it incorrectly creates a VMPTR_ILCodeVersionNode for a code version that shouldn't have one. --- src/debug/daccess/dacdbiimpl.cpp | 2 +- src/vm/codeversion.cpp | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/debug/daccess/dacdbiimpl.cpp b/src/debug/daccess/dacdbiimpl.cpp index e5cc45b..598fb2f 100644 --- a/src/debug/daccess/dacdbiimpl.cpp +++ b/src/debug/daccess/dacdbiimpl.cpp @@ -7169,7 +7169,7 @@ HRESULT DacDbiInterfaceImpl::GetActiveRejitILCodeVersionNode(VMPTR_Module vmModu // manager's active IL version hasn't yet asked the profiler for the IL body to use, in which case we want to filter it // out from the return in this method. ILCodeVersion activeILVersion = pCodeVersionManager->GetActiveILCodeVersion(pModule, methodTk); - if (activeILVersion.IsNull() || activeILVersion.GetRejitState() != ILCodeVersion::kStateActive) + if (activeILVersion.IsNull() || activeILVersion.IsDefaultVersion() || activeILVersion.GetRejitState() != ILCodeVersion::kStateActive) { pVmILCodeVersionNode->SetDacTargetPtr(0); } diff --git a/src/vm/codeversion.cpp b/src/vm/codeversion.cpp index cf756e1..2726a16 100644 --- a/src/vm/codeversion.cpp +++ b/src/vm/codeversion.cpp @@ -940,6 +940,9 @@ HRESULT ILCodeVersion::SetActiveNativeCodeVersion(NativeCodeVersion activeNative ILCodeVersionNode* ILCodeVersion::AsNode() { LIMITED_METHOD_CONTRACT; + //This is dangerous - NativeCodeVersion coerces non-explicit versions to NULL but ILCodeVersion assumes the caller + //will never invoke AsNode() on a non-explicit node. Asserting for now as a minimal fix, but we should revisit this. + _ASSERTE(m_storageKind == StorageKind::Explicit); return m_pVersionNode; } #endif //DACCESS_COMPILE @@ -947,6 +950,9 @@ ILCodeVersionNode* ILCodeVersion::AsNode() PTR_ILCodeVersionNode ILCodeVersion::AsNode() const { LIMITED_METHOD_DAC_CONTRACT; + //This is dangerous - NativeCodeVersion coerces non-explicit versions to NULL but ILCodeVersion assumes the caller + //will never invoke AsNode() on a non-explicit node. Asserting for now as a minimal fix, but we should revisit this. + _ASSERTE(m_storageKind == StorageKind::Explicit); return m_pVersionNode; } -- 2.7.4