| 1 | // Licensed to the .NET Foundation under one or more agreements. |
| 2 | // The .NET Foundation licenses this file to you under the MIT license. |
| 3 | // See the LICENSE file in the project root for more information. |
| 4 | // =========================================================================== |
| 5 | // File: ReadyToRunInfo.h |
| 6 | // |
| 7 | |
| 8 | // |
| 9 | // Runtime support for Ready to Run |
| 10 | // =========================================================================== |
| 11 | |
| 12 | #ifndef _READYTORUNINFO_H_ |
| 13 | #define _READYTORUNINFO_H_ |
| 14 | |
| 15 | #include "nativeformatreader.h" |
| 16 | #include "inlinetracking.h" |
| 17 | |
| 18 | typedef DPTR(struct READYTORUN_SECTION) PTR_READYTORUN_SECTION; |
| 19 | |
| 20 | #ifndef FEATURE_PREJIT |
| 21 | typedef DPTR(struct READYTORUN_IMPORT_SECTION) PTR_CORCOMPILE_IMPORT_SECTION; |
| 22 | #endif |
| 23 | |
| 24 | class PrepareCodeConfig; |
| 25 | |
| 26 | typedef DPTR(class ReadyToRunInfo) PTR_ReadyToRunInfo; |
| 27 | class ReadyToRunInfo |
| 28 | { |
| 29 | friend class ReadyToRunJitManager; |
| 30 | |
| 31 | PTR_Module m_pModule; |
| 32 | |
| 33 | PTR_PEImageLayout m_pLayout; |
| 34 | PTR_READYTORUN_HEADER ; |
| 35 | |
| 36 | PTR_RUNTIME_FUNCTION m_pRuntimeFunctions; |
| 37 | DWORD m_nRuntimeFunctions; |
| 38 | |
| 39 | PTR_CORCOMPILE_IMPORT_SECTION m_pImportSections; |
| 40 | DWORD m_nImportSections; |
| 41 | |
| 42 | NativeFormat::NativeReader m_nativeReader; |
| 43 | NativeFormat::NativeArray m_methodDefEntryPoints; |
| 44 | NativeFormat::NativeHashtable m_instMethodEntryPoints; |
| 45 | NativeFormat::NativeHashtable m_availableTypesHashtable; |
| 46 | |
| 47 | Crst m_Crst; |
| 48 | PtrHashMap m_entryPointToMethodDescMap; |
| 49 | |
| 50 | PTR_PersistentInlineTrackingMapR2R m_pPersistentInlineTrackingMap; |
| 51 | |
| 52 | (Module * pModule, PEImageLayout * pLayout, READYTORUN_HEADER * , AllocMemTracker *pamTracker); |
| 53 | |
| 54 | public: |
| 55 | static BOOL IsReadyToRunEnabled(); |
| 56 | |
| 57 | static PTR_ReadyToRunInfo Initialize(Module * pModule, AllocMemTracker *pamTracker); |
| 58 | |
| 59 | PCODE GetEntryPoint(MethodDesc * pMD, PrepareCodeConfig* pConfig, BOOL fFixups); |
| 60 | |
| 61 | MethodDesc * GetMethodDescForEntryPoint(PCODE entryPoint); |
| 62 | |
| 63 | BOOL HasHashtableOfTypes(); |
| 64 | BOOL TryLookupTypeTokenFromName(NameHandle *pName, mdToken * pFoundTypeToken); |
| 65 | |
| 66 | BOOL SkipTypeValidation() |
| 67 | { |
| 68 | LIMITED_METHOD_CONTRACT; |
| 69 | return m_pHeader->Flags & READYTORUN_FLAG_SKIP_TYPE_VALIDATION; |
| 70 | } |
| 71 | |
| 72 | PTR_PEImageLayout GetImage() |
| 73 | { |
| 74 | LIMITED_METHOD_CONTRACT; |
| 75 | return m_pLayout; |
| 76 | } |
| 77 | |
| 78 | IMAGE_DATA_DIRECTORY * FindSection(DWORD type); |
| 79 | |
| 80 | PTR_CORCOMPILE_IMPORT_SECTION GetImportSections(COUNT_T * pCount) |
| 81 | { |
| 82 | LIMITED_METHOD_CONTRACT; |
| 83 | *pCount = m_nImportSections; |
| 84 | return m_pImportSections; |
| 85 | } |
| 86 | |
| 87 | PTR_CORCOMPILE_IMPORT_SECTION GetImportSectionFromIndex(COUNT_T index) |
| 88 | { |
| 89 | LIMITED_METHOD_CONTRACT; |
| 90 | _ASSERTE(index < m_nImportSections); |
| 91 | return m_pImportSections + index; |
| 92 | } |
| 93 | |
| 94 | PTR_CORCOMPILE_IMPORT_SECTION GetImportSectionForRVA(RVA rva) |
| 95 | { |
| 96 | LIMITED_METHOD_CONTRACT; |
| 97 | |
| 98 | PTR_CORCOMPILE_IMPORT_SECTION pEnd = m_pImportSections + m_nImportSections; |
| 99 | for (PTR_CORCOMPILE_IMPORT_SECTION pSection = m_pImportSections; pSection < pEnd; pSection++) |
| 100 | { |
| 101 | if (rva >= VAL32(pSection->Section.VirtualAddress) && rva < VAL32(pSection->Section.VirtualAddress) + VAL32(pSection->Section.Size)) |
| 102 | return pSection; |
| 103 | } |
| 104 | |
| 105 | return NULL; |
| 106 | } |
| 107 | |
| 108 | PTR_BYTE GetDebugInfo(PTR_RUNTIME_FUNCTION pRuntimeFunction); |
| 109 | |
| 110 | class MethodIterator |
| 111 | { |
| 112 | ReadyToRunInfo * m_pInfo; |
| 113 | int m_methodDefIndex; |
| 114 | |
| 115 | public: |
| 116 | MethodIterator(ReadyToRunInfo * pInfo) |
| 117 | : m_pInfo(pInfo), m_methodDefIndex(-1) |
| 118 | { |
| 119 | } |
| 120 | |
| 121 | BOOL Next(); |
| 122 | |
| 123 | MethodDesc * GetMethodDesc(); |
| 124 | MethodDesc * GetMethodDesc_NoRestore(); |
| 125 | PCODE GetMethodStartAddress(); |
| 126 | }; |
| 127 | |
| 128 | static DWORD GetFieldBaseOffset(MethodTable * pMT); |
| 129 | |
| 130 | PTR_PersistentInlineTrackingMapR2R GetInlineTrackingMap() |
| 131 | { |
| 132 | return m_pPersistentInlineTrackingMap; |
| 133 | } |
| 134 | |
| 135 | private: |
| 136 | BOOL GetTypeNameFromToken(IMDInternalImport * pImport, mdToken mdType, LPCUTF8 * ppszName, LPCUTF8 * ppszNameSpace); |
| 137 | BOOL GetEnclosingToken(IMDInternalImport * pImport, mdToken mdType, mdToken * pEnclosingToken); |
| 138 | BOOL CompareTypeNameOfTokens(mdToken mdToken1, IMDInternalImport * pImport1, mdToken mdToken2, IMDInternalImport * pImport2); |
| 139 | BOOL IsImageVersionAtLeast(int majorVersion, int minorVersion); |
| 140 | }; |
| 141 | |
| 142 | class DynamicHelpers |
| 143 | { |
| 144 | private: |
| 145 | static void EmitHelperWithArg(BYTE*& pCode, LoaderAllocator * pAllocator, TADDR arg, PCODE target); |
| 146 | public: |
| 147 | static PCODE CreateHelper(LoaderAllocator * pAllocator, TADDR arg, PCODE target); |
| 148 | static PCODE CreateHelperWithArg(LoaderAllocator * pAllocator, TADDR arg, PCODE target); |
| 149 | static PCODE CreateHelper(LoaderAllocator * pAllocator, TADDR arg, TADDR arg2, PCODE target); |
| 150 | static PCODE CreateHelperArgMove(LoaderAllocator * pAllocator, TADDR arg, PCODE target); |
| 151 | static PCODE CreateReturn(LoaderAllocator * pAllocator); |
| 152 | static PCODE CreateReturnConst(LoaderAllocator * pAllocator, TADDR arg); |
| 153 | static PCODE CreateReturnIndirConst(LoaderAllocator * pAllocator, TADDR arg, INT8 offset); |
| 154 | static PCODE CreateHelperWithTwoArgs(LoaderAllocator * pAllocator, TADDR arg, PCODE target); |
| 155 | static PCODE CreateHelperWithTwoArgs(LoaderAllocator * pAllocator, TADDR arg, TADDR arg2, PCODE target); |
| 156 | static PCODE CreateDictionaryLookupHelper(LoaderAllocator * pAllocator, CORINFO_RUNTIME_LOOKUP * pLookup, DWORD dictionaryIndexAndSlot, Module * pModule); |
| 157 | }; |
| 158 | |
| 159 | #endif // _READYTORUNINFO_H_ |
| 160 | |