Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit fde6f26

Browse files
committed
Fix instantiating stub for methods of value types
This change fixes a problem with instantiating stubs for methods of value types. The problem was that the CreateInstantiatingILStub didn't take into account the fact that methods of value types need to have "this" passed "byref". The issue manifested itself as a rare corruption of references in array of structs that were thin wrappers for string reference during GC stack scan. GC thought that the reference to an array entry is an object reference that starts with method table. GC marks method table pointers by setting their bit zero to 1. But in this case, it has accidentally modified an object reference instead and a test was crashing with wrong object address. The root cause of the problem is that the instantiating stubs were placed on a global singleton reference class no matter whether the target method was on a reference class or a value type. I have fixed it by putting the stubs on the instantiated target generic type instead.
1 parent 586ce53 commit fde6f26

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/vm/prestub.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -780,15 +780,19 @@ Stub * CreateInstantiatingILStub(MethodDesc* pTargetMD, void* pHiddenArg)
780780
CONTRACT_END;
781781

782782
SigTypeContext typeContext;
783+
MethodTable* pStubMT;
783784
if (pTargetMD->HasMethodInstantiation())
784785
{
785786
// The pHiddenArg shall be a MethodDesc*
786-
SigTypeContext::InitTypeContext(static_cast<MethodDesc *>(pHiddenArg), &typeContext);
787+
MethodDesc* pMD = static_cast<MethodDesc *>(pHiddenArg);
788+
SigTypeContext::InitTypeContext(pMD, &typeContext);
789+
pStubMT = pMD->GetMethodTable();
787790
}
788791
else
789792
{
790793
// The pHiddenArg shall be a MethodTable*
791794
SigTypeContext::InitTypeContext(TypeHandle::FromPtr(pHiddenArg), &typeContext);
795+
pStubMT = static_cast<MethodTable *>(pHiddenArg);
792796
}
793797

794798
MetaSig msig(pTargetMD);
@@ -837,7 +841,7 @@ Stub * CreateInstantiatingILStub(MethodDesc* pTargetMD, void* pHiddenArg)
837841
pTargetMD->GetSig(&pSig,&cbSig);
838842
PTR_Module pLoaderModule = pTargetMD->GetLoaderModule();
839843
MethodDesc * pStubMD = ILStubCache::CreateAndLinkNewILStubMethodDesc(pTargetMD->GetLoaderAllocator(),
840-
pLoaderModule->GetILStubCache()->GetOrCreateStubMethodTable(pLoaderModule),
844+
pStubMT,
841845
ILSTUB_INSTANTIATINGSTUB,
842846
pTargetMD->GetModule(),
843847
pSig, cbSig,

0 commit comments

Comments
 (0)