From 63f88ac8f1a7ee1d64f8c9e6b915c8ce8f0da16d Mon Sep 17 00:00:00 2001 From: Aaron R Robinson Date: Tue, 2 May 2023 08:59:11 -0700 Subject: [PATCH] Fix add/edit for generic methods scenario Ensure the canonical MethodTable is always used. --- src/coreclr/vm/methoditer.cpp | 10 +++------- src/coreclr/vm/methodtable.cpp | 1 + src/coreclr/vm/runtimehandles.cpp | 3 ++- 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/coreclr/vm/methoditer.cpp b/src/coreclr/vm/methoditer.cpp index 1da1dbf29897d9..82def6a1bec50a 100644 --- a/src/coreclr/vm/methoditer.cpp +++ b/src/coreclr/vm/methoditer.cpp @@ -24,7 +24,7 @@ BOOL LoadedMethodDescIterator::Next( { NOTHROW; GC_NOTRIGGER; - MODE_PREEMPTIVE; + MODE_ANY; } CONTRACTL_END @@ -203,15 +203,11 @@ MethodDesc *LoadedMethodDescIterator::Current() return m_mainMD; } - MethodTable *pMT = m_typeIteratorEntry->GetTypeHandle().GetMethodTable(); + MethodTable *pMT = m_typeIteratorEntry->GetTypeHandle().GetMethodTable()->GetCanonicalMethodTable(); PREFIX_ASSUME(pMT != NULL); - _ASSERTE(pMT); - - return pMT->GetMethodDescForSlot(m_mainMD->GetSlot()); + return pMT->GetParallelMethodDesc(m_mainMD); } -// Initialize the iterator. It will cover generics + prejitted; -// but it is not EnC aware. void LoadedMethodDescIterator::Start( AppDomain * pAppDomain, diff --git a/src/coreclr/vm/methodtable.cpp b/src/coreclr/vm/methodtable.cpp index a5391fb8b4f763..d40eb089953ba9 100644 --- a/src/coreclr/vm/methodtable.cpp +++ b/src/coreclr/vm/methodtable.cpp @@ -8770,6 +8770,7 @@ namespace GC_NOTRIGGER; MODE_ANY; PRECONDITION(pMT != NULL); + PRECONDITION(pMT->IsCanonicalMethodTable()); PRECONDITION(pDefMD != NULL); PRECONDITION(pDefMD->IsEnCAddedMethod()); PRECONDITION(pDefMD->GetSlot() == MethodTable::NO_SLOT); diff --git a/src/coreclr/vm/runtimehandles.cpp b/src/coreclr/vm/runtimehandles.cpp index 5972c887effad4..e0eba7e1726134 100644 --- a/src/coreclr/vm/runtimehandles.cpp +++ b/src/coreclr/vm/runtimehandles.cpp @@ -2413,7 +2413,8 @@ FCIMPL2(MethodDesc*, RuntimeMethodHandle::GetMethodFromCanonical, MethodDesc *pM REFLECTCLASSBASEREF refType = (REFLECTCLASSBASEREF)ObjectToOBJECTREF(pTypeUNSAFE); TypeHandle instType = refType->GetType(); - MethodDesc* pMDescInCanonMT = instType.GetMethodTable()->GetParallelMethodDesc(pMethod); + MethodTable* pCanonMT = instType.GetMethodTable()->GetCanonicalMethodTable(); + MethodDesc* pMDescInCanonMT = pCanonMT->GetParallelMethodDesc(pMethod); return pMDescInCanonMT; }