@@ -1692,11 +1692,20 @@ CorJitResult Interpreter::GenerateInterpreterStub(CEEInfo* comp,
16921692#else
16931693#error unsupported platform
16941694#endif
1695- stub = sl.Link (SystemDomain::GetGlobalLoaderAllocator ()->GetStubHeap ());
1695+ if (false )
1696+ {
1697+ stub = sl.Link (SystemDomain::GetGlobalLoaderAllocator ()->GetStubHeap ());
16961698
1697- *nativeSizeOfCode = static_cast <ULONG>(stub->GetNumCodeBytes ());
1698- // TODO: manage reference count of interpreter stubs. Look for examples...
1699- *nativeEntry = dac_cast<BYTE*>(stub->GetEntryPoint ());
1699+ *nativeSizeOfCode = static_cast <ULONG>(stub->GetNumCodeBytes ());
1700+ // TODO: manage reference count of interpreter stubs. Look for examples...
1701+ *nativeEntry = dac_cast<BYTE*>(stub->GetEntryPoint ());
1702+ }
1703+ else
1704+ {
1705+ // Intentionally avoid generating any code - but it is required
1706+ // for us to have an unique nativeEntry since it will be part of some hash table
1707+ *nativeEntry = (BYTE*)(((uint64_t )interpMethInfo) | 0x1 );
1708+ }
17001709 }
17011710
17021711 // Initialize the arg offset information.
@@ -1773,6 +1782,81 @@ ARG_SLOT Interpreter::ExecuteMethodWrapper(struct InterpreterMethodInfo* interpM
17731782 return retVal;
17741783}
17751784
1785+ COR_ILMETHOD_DECODER* CopiedGetAndVerifyMetadataILHeader (MethodDesc* pMD, PrepareCodeConfig* pConfig, COR_ILMETHOD_DECODER* pDecoderMemory)
1786+ {
1787+ // STANDARD_VM_CONTRACT;
1788+ _ASSERTE (pMD != NULL );
1789+ _ASSERTE (!pMD->IsNoMetadata ());
1790+ _ASSERTE (pConfig != NULL );
1791+ _ASSERTE (pDecoderMemory != NULL );
1792+
1793+ COR_ILMETHOD_DECODER* pHeader = NULL ;
1794+ COR_ILMETHOD* ilHeader = pConfig->GetILHeader ();
1795+ if (ilHeader == NULL )
1796+ return NULL ;
1797+
1798+ COR_ILMETHOD_DECODER::DecoderStatus status = COR_ILMETHOD_DECODER::FORMAT_ERROR;
1799+ {
1800+ // Decoder ctor can AV on a malformed method header
1801+ AVInRuntimeImplOkayHolder AVOkay;
1802+ pHeader = new (pDecoderMemory) COR_ILMETHOD_DECODER (ilHeader, pMD->GetMDImport (), &status);
1803+ }
1804+
1805+ if (status == COR_ILMETHOD_DECODER::FORMAT_ERROR)
1806+ COMPlusThrowHR (COR_E_BADIMAGEFORMAT, BFA_BAD_IL);
1807+
1808+ return pHeader;
1809+ }
1810+
1811+ COR_ILMETHOD_DECODER* CopiedGetAndVerifyILHeader (MethodDesc* pMD, PrepareCodeConfig* pConfig, COR_ILMETHOD_DECODER* pIlDecoderMemory)
1812+ {
1813+ // STANDARD_VM_CONTRACT;
1814+ _ASSERTE (pMD != NULL );
1815+ if (pMD->IsIL ())
1816+ {
1817+ return CopiedGetAndVerifyMetadataILHeader (pMD, pConfig, pIlDecoderMemory);
1818+ }
1819+ else if (pMD->IsILStub ())
1820+ {
1821+ ILStubResolver* pResolver = pMD->AsDynamicMethodDesc ()->GetILStubResolver ();
1822+ return pResolver->GetILHeader ();
1823+ }
1824+
1825+ _ASSERTE (pMD->IsNoMetadata ());
1826+ return NULL ;
1827+ }
1828+
1829+ void ToMethodInfo (MethodDesc* ftn, COR_ILMETHOD_DECODER* ILHeader, CORINFO_METHOD_INFO* pMethodInfo);
1830+
1831+ void * ToInterpreterMethodInfo (MethodDesc* pMd)
1832+ {
1833+ // Given a methodDesc, convert it into an InterpreterMethodInfo
1834+ GCX_PREEMP ();
1835+ NativeCodeVersion activeCodeVersion (pMd);
1836+ PrepareCodeConfigBuffer pccb (activeCodeVersion);
1837+ PrepareCodeConfig* pConfig = pccb.GetConfig ();
1838+ COR_ILMETHOD_DECODER ilDecoderTemp;
1839+ COR_ILMETHOD_DECODER* pilHeader = CopiedGetAndVerifyILHeader (pMd, pConfig, &ilDecoderTemp);
1840+ CORINFO_METHOD_INFO methodInfo;
1841+ ToMethodInfo (pMd, pilHeader, &methodInfo);
1842+ CEEInfo* jitInfo = new CEEInfo (pMd, true );
1843+
1844+ InterpreterMethodInfo* interpreterMethodInfo;
1845+ BYTE* unusedEntry;
1846+ uint32_t unusedSize;
1847+
1848+ // The method is modified so that it won't generate code anymore
1849+ Interpreter::GenerateInterpreterStub (jitInfo, &methodInfo, &unusedEntry, &unusedSize, &interpreterMethodInfo, false );
1850+ return (void *)(((uint64_t )interpreterMethodInfo) | 0x1 );
1851+ }
1852+
1853+ void CallInterpretMethod (void * interpreterMethodInfo, BYTE* ilArgs)
1854+ {
1855+ struct InterpreterMethodInfo * interpMethInfo = (struct InterpreterMethodInfo *)interpreterMethodInfo;
1856+ // TODO, return!
1857+ Interpreter::InterpretMethodBody (interpMethInfo, true , ilArgs, nullptr );
1858+ }
1859+
17761860// TODO: Add GSCookie checks
17771861
17781862// static
0 commit comments