summaryrefslogtreecommitdiff
path: root/src/vm/zapsig.cpp
diff options
context:
space:
mode:
authorJan Vorlicek <janvorli@microsoft.com>2019-05-01 03:22:03 +0200
committerJan Vorlicek <janvorli@microsoft.com>2019-05-01 03:22:03 +0200
commit4b603baf496544a6a6d67c4ef43ee1b3a200acfc (patch)
tree893e886099a8b15242e405304f445dacc8846e06 /src/vm/zapsig.cpp
parent6bca031ae0e612c5d9dbe350e435cce9d9d1919a (diff)
downloadcoreclr-4b603baf496544a6a6d67c4ef43ee1b3a200acfc.tar.gz
coreclr-4b603baf496544a6a6d67c4ef43ee1b3a200acfc.tar.bz2
coreclr-4b603baf496544a6a6d67c4ef43ee1b3a200acfc.zip
Fix module override effect on method instantiating signature
When a module override is placed on a fixup blob top level, it also affects types in the method instantiating signature. This can cause tokens in the signature to be resolved in a wrong module. This change fixes it by adding module zapsig elements before each argument of the method's instantiating signature.
Diffstat (limited to 'src/vm/zapsig.cpp')
-rw-r--r--src/vm/zapsig.cpp36
1 files changed, 33 insertions, 3 deletions
diff --git a/src/vm/zapsig.cpp b/src/vm/zapsig.cpp
index cfccdea90a..8feb7bebcd 100644
--- a/src/vm/zapsig.cpp
+++ b/src/vm/zapsig.cpp
@@ -1315,7 +1315,7 @@ BOOL ZapSig::EncodeMethod(
}
else
{
- _ASSERTE(pInfoModule = pMethod->GetModule());
+ _ASSERTE(pInfoModule == pMethod->GetModule());
}
if (!ownerType.HasInstantiation())
@@ -1366,10 +1366,40 @@ BOOL ZapSig::EncodeMethod(
{
_ASSERTE(pResolvedToken->cbMethodSpec > 1);
- if (*(BYTE*)pResolvedToken->pMethodSpec != (BYTE)IMAGE_CEE_CS_CALLCONV_GENERICINST)
+ // Copy the pResolvedToken->pMethodSpec, inserting ELEMENT_TYPE_MODULE_ZAPSIG in front of each type parameter in needed
+ SigParser sigParser(pResolvedToken->pMethodSpec);
+ BYTE callingConvention;
+ IfFailThrow(sigParser.GetByte(&callingConvention));
+ if (callingConvention != (BYTE)IMAGE_CEE_CS_CALLCONV_GENERICINST)
+ {
ThrowHR(COR_E_BADIMAGEFORMAT);
+ }
+
+ ULONG numGenArgs;
+ IfFailThrow(sigParser.GetData(&numGenArgs));
+ pSigBuilder->AppendData(numGenArgs);
+
+ DWORD moduleIndex;
+ bool addModuleZapSig = (IsReadyToRunCompilation() && pMethod->GetModule()->IsInCurrentVersionBubble() && pInfoModule != (Module *) pResolvedToken->tokenScope);
+ if (addModuleZapSig)
+ {
+ moduleIndex = (*((EncodeModuleCallback)pfnEncodeModule))(pEncodeModuleContext, (Module *) pResolvedToken->tokenScope);
+ }
- pSigBuilder->AppendBlob((PVOID)(((BYTE*)pResolvedToken->pMethodSpec) + 1), pResolvedToken->cbMethodSpec - 1);
+ while (numGenArgs != 0)
+ {
+ if (addModuleZapSig)
+ {
+ pSigBuilder->AppendElementType((CorElementType)ELEMENT_TYPE_MODULE_ZAPSIG);
+ pSigBuilder->AppendData(moduleIndex);
+ }
+
+ PCCOR_SIGNATURE typeSigStart = sigParser.GetPtr();
+ IfFailThrow(sigParser.SkipExactlyOne());
+ PCCOR_SIGNATURE typeSigEnd = sigParser.GetPtr();
+ pSigBuilder->AppendBlob((PVOID)typeSigStart, typeSigEnd - typeSigStart);
+ numGenArgs--;
+ }
}
else
{