MetadataCache.cpp 57 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450
  1. #include "il2cpp-config.h"
  2. #include "MetadataCache.h"
  3. #include "GlobalMetadata.h"
  4. #include <map>
  5. #include <limits>
  6. #include "il2cpp-tabledefs.h"
  7. #include "il2cpp-runtime-stats.h"
  8. #include "gc/GarbageCollector.h"
  9. #include "metadata/ArrayMetadata.h"
  10. #include "metadata/GenericMetadata.h"
  11. #include "metadata/GenericMethod.h"
  12. #include "os/Atomic.h"
  13. #include "os/Mutex.h"
  14. #include "utils/CallOnce.h"
  15. #include "utils/Collections.h"
  16. #include "utils/Il2CppHashSet.h"
  17. #include "utils/Memory.h"
  18. #include "utils/PathUtils.h"
  19. #include "vm/Assembly.h"
  20. #include "vm/Class.h"
  21. #include "vm/ClassInlines.h"
  22. #include "vm/GenericClass.h"
  23. #include "vm/MetadataAlloc.h"
  24. #include "vm/MetadataLoader.h"
  25. #include "vm/MetadataLock.h"
  26. #include "vm/Method.h"
  27. #include "vm/Object.h"
  28. #include "vm/Runtime.h"
  29. #include "vm/String.h"
  30. #include "vm/Type.h"
  31. #include "vm-utils/MethodDefinitionKey.h"
  32. #include "vm-utils/NativeSymbol.h"
  33. #include "Baselib.h"
  34. #include "Cpp/ReentrantLock.h"
  35. #include "hybridclr/metadata/Assembly.h"
  36. #include "hybridclr/metadata/MetadataModule.h"
  37. typedef Il2CppReaderWriterLockedHashMap<Il2CppClass*, Il2CppClass*> PointerTypeMap;
  38. typedef Il2CppHashSet<const Il2CppGenericMethod*, il2cpp::metadata::Il2CppGenericMethodHash, il2cpp::metadata::Il2CppGenericMethodCompare> Il2CppGenericMethodSet;
  39. typedef Il2CppGenericMethodSet::const_iterator Il2CppGenericMethodSetIter;
  40. static Il2CppGenericMethodSet s_GenericMethodSet;
  41. struct Il2CppMetadataCache
  42. {
  43. il2cpp::os::FastReaderReaderWriterLock m_CacheLock;
  44. PointerTypeMap m_PointerTypes;
  45. };
  46. static Il2CppMetadataCache s_MetadataCache;
  47. static int32_t s_ImagesCount = 0;
  48. static Il2CppImage* s_ImagesTable = NULL;
  49. static int32_t s_AssembliesCount = 0;
  50. static Il2CppAssembly* s_AssembliesTable = NULL;
  51. typedef Il2CppReaderWriterLockedHashSet<const Il2CppGenericInst*, il2cpp::metadata::Il2CppGenericInstHash, il2cpp::metadata::Il2CppGenericInstCompare> Il2CppGenericInstSet;
  52. static Il2CppGenericInstSet s_GenericInstSet;
  53. typedef il2cpp::vm::Il2CppMethodTableMap::const_iterator Il2CppMethodTableMapIter;
  54. static il2cpp::vm::Il2CppMethodTableMap s_MethodTableMap;
  55. typedef il2cpp::vm::Il2CppUnresolvedSignatureMap::const_iterator Il2CppUnresolvedSignatureMapIter;
  56. static il2cpp::vm::Il2CppUnresolvedSignatureMap *s_pUnresolvedSignatureMap;
  57. typedef Il2CppHashMap<FieldInfo*, int32_t, il2cpp::utils::PointerHash<FieldInfo> > Il2CppThreadLocalStaticOffsetHashMap;
  58. typedef Il2CppThreadLocalStaticOffsetHashMap::iterator Il2CppThreadLocalStaticOffsetHashMapIter;
  59. static Il2CppThreadLocalStaticOffsetHashMap s_ThreadLocalStaticOffsetMap;
  60. static const Il2CppCodeRegistration * s_Il2CppCodeRegistration;
  61. static const Il2CppMetadataRegistration* s_MetadataCache_Il2CppMetadataRegistration;
  62. static const Il2CppCodeGenOptions* s_Il2CppCodeGenOptions;
  63. #if !IL2CPP_TRIM_COM
  64. static il2cpp::vm::WindowsRuntimeTypeNameToClassMap s_WindowsRuntimeTypeNameToClassMap;
  65. static il2cpp::vm::ClassToWindowsRuntimeTypeNameMap s_ClassToWindowsRuntimeTypeNameMap;
  66. #endif
  67. #if ENABLE_HMI_MODE || PLATFORM_WEIXINMINIGAME
  68. static il2cpp::vm::Il2CppGenericMethodTableItem* s_GenericMethodTableVector = NULL;
  69. static uint32_t s_GenericMethodTableVectorSize = 0;
  70. #endif
  71. struct InteropDataToTypeConverter
  72. {
  73. inline const Il2CppType* operator()(const Il2CppInteropData& interopData) const
  74. {
  75. return interopData.type;
  76. }
  77. };
  78. typedef il2cpp::utils::collections::ArrayValueMap<const Il2CppType*, Il2CppInteropData, InteropDataToTypeConverter, il2cpp::metadata::Il2CppTypeLess, il2cpp::metadata::Il2CppTypeEqualityComparer> InteropDataMap;
  79. static InteropDataMap s_InteropData;
  80. #if !IL2CPP_TRIM_COM
  81. struct WindowsRuntimeFactoryTableEntryToTypeConverter
  82. {
  83. inline const Il2CppType* operator()(const Il2CppWindowsRuntimeFactoryTableEntry& entry) const
  84. {
  85. return entry.type;
  86. }
  87. };
  88. typedef il2cpp::utils::collections::ArrayValueMap<const Il2CppType*, Il2CppWindowsRuntimeFactoryTableEntry, WindowsRuntimeFactoryTableEntryToTypeConverter, il2cpp::metadata::Il2CppTypeLess, il2cpp::metadata::Il2CppTypeEqualityComparer> WindowsRuntimeFactoryTable;
  89. static WindowsRuntimeFactoryTable s_WindowsRuntimeFactories;
  90. #endif
  91. template<typename K, typename V>
  92. struct PairToKeyConverter
  93. {
  94. inline const K& operator()(const std::pair<K, V>& pair) const
  95. {
  96. return pair.first;
  97. }
  98. };
  99. #if !IL2CPP_TRIM_COM
  100. typedef il2cpp::utils::collections::ArrayValueMap<const Il2CppGuid*, std::pair<const Il2CppGuid*, Il2CppClass*>, PairToKeyConverter<const Il2CppGuid*, Il2CppClass*> > GuidToClassMap;
  101. static GuidToClassMap s_GuidToNonImportClassMap;
  102. #endif
  103. static il2cpp::utils::dynamic_array<Il2CppAssembly*> s_cliAssemblies;
  104. void il2cpp::vm::MetadataCache::Register(const Il2CppCodeRegistration* const codeRegistration, const Il2CppMetadataRegistration* const metadataRegistration, const Il2CppCodeGenOptions* const codeGenOptions)
  105. {
  106. il2cpp::vm::GlobalMetadata::Register(codeRegistration, metadataRegistration, codeGenOptions);
  107. s_Il2CppCodeRegistration = codeRegistration;
  108. s_MetadataCache_Il2CppMetadataRegistration = metadataRegistration;
  109. s_Il2CppCodeGenOptions = codeGenOptions;
  110. }
  111. Il2CppClass* il2cpp::vm::MetadataCache::GetTypeInfoFromTypeIndex(const Il2CppImage *image, TypeIndex index)
  112. {
  113. return il2cpp::vm::GlobalMetadata::GetTypeInfoFromTypeIndex(index);
  114. }
  115. const MethodInfo* il2cpp::vm::MetadataCache::GetMethodInfoFromMethodDefinitionIndex(const Il2CppImage *image, MethodIndex index)
  116. {
  117. return il2cpp::vm::GlobalMetadata::GetMethodInfoFromMethodDefinitionIndex(index);
  118. }
  119. const MethodInfo* il2cpp::vm::MetadataCache::GetAssemblyEntryPoint(const Il2CppImage* image)
  120. {
  121. return il2cpp::vm::GlobalMetadata::GetAssemblyEntryPoint(image);
  122. }
  123. Il2CppMetadataTypeHandle il2cpp::vm::MetadataCache::GetAssemblyTypeHandle(const Il2CppImage* image, AssemblyTypeIndex index)
  124. {
  125. return il2cpp::vm::GlobalMetadata::GetAssemblyTypeHandle(image, index);
  126. }
  127. Il2CppMetadataTypeHandle il2cpp::vm::MetadataCache::GetAssemblyExportedTypeHandle(const Il2CppImage* image, AssemblyExportedTypeIndex index)
  128. {
  129. return il2cpp::vm::GlobalMetadata::GetAssemblyExportedTypeHandle(image, index);
  130. }
  131. const MethodInfo* il2cpp::vm::MetadataCache::GetMethodInfoFromMethodHandle(Il2CppMetadataMethodDefinitionHandle handle)
  132. {
  133. return il2cpp::vm::GlobalMetadata::GetMethodInfoFromMethodHandle(handle);
  134. }
  135. bool il2cpp::vm::MetadataCache::Initialize()
  136. {
  137. if (!il2cpp::vm::GlobalMetadata::Initialize(&s_ImagesCount, &s_AssembliesCount))
  138. {
  139. return false;
  140. }
  141. il2cpp::metadata::GenericMetadata::RegisterGenericClasses(s_MetadataCache_Il2CppMetadataRegistration->genericClasses, s_MetadataCache_Il2CppMetadataRegistration->genericClassesCount);
  142. il2cpp::metadata::GenericMetadata::SetMaximumRuntimeGenericDepth(s_Il2CppCodeGenOptions->maximumRuntimeGenericDepth);
  143. il2cpp::metadata::GenericMetadata::SetGenericVirtualIterations(s_Il2CppCodeGenOptions->recursiveGenericIterations);
  144. s_GenericInstSet.Resize(s_MetadataCache_Il2CppMetadataRegistration->genericInstsCount);
  145. for (int32_t i = 0; i < s_MetadataCache_Il2CppMetadataRegistration->genericInstsCount; i++)
  146. {
  147. bool inserted = s_GenericInstSet.Add(s_MetadataCache_Il2CppMetadataRegistration->genericInsts[i]);
  148. IL2CPP_ASSERT(inserted);
  149. }
  150. s_InteropData.assign_external(s_Il2CppCodeRegistration->interopData, s_Il2CppCodeRegistration->interopDataCount);
  151. #if !IL2CPP_TRIM_COM
  152. s_WindowsRuntimeFactories.assign_external(s_Il2CppCodeRegistration->windowsRuntimeFactoryTable, s_Il2CppCodeRegistration->windowsRuntimeFactoryCount);
  153. #endif
  154. // Pre-allocate these arrays so we don't need to lock when reading later.
  155. // These arrays hold the runtime metadata representation for metadata explicitly
  156. // referenced during conversion. There is a corresponding table of same size
  157. // in the converted metadata, giving a description of runtime metadata to construct.
  158. s_ImagesTable = (Il2CppImage*)IL2CPP_CALLOC(s_ImagesCount, sizeof(Il2CppImage), IL2CPP_MEM_METADATA_CACHE);
  159. s_AssembliesTable = (Il2CppAssembly*)IL2CPP_CALLOC(s_AssembliesCount, sizeof(Il2CppAssembly), IL2CPP_MEM_METADATA_CACHE);
  160. // setup all the Il2CppImages. There are not many and it avoid locks later on
  161. for (int32_t imageIndex = 0; imageIndex < s_ImagesCount; imageIndex++)
  162. {
  163. Il2CppImage* image = s_ImagesTable + imageIndex;
  164. AssemblyIndex imageAssemblyIndex;
  165. il2cpp::vm::GlobalMetadata::BuildIl2CppImage(image, imageIndex, &imageAssemblyIndex);
  166. image->assembly = const_cast<Il2CppAssembly*>(GetAssemblyFromIndex(imageAssemblyIndex));
  167. std::string nameNoExt = il2cpp::utils::PathUtils::PathNoExtension(image->name);
  168. image->nameNoExt = (char*)IL2CPP_CALLOC(nameNoExt.size() + 1, sizeof(char), IL2CPP_MEM_STRING);
  169. strcpy(const_cast<char*>(image->nameNoExt), nameNoExt.c_str());
  170. for (uint32_t codeGenModuleIndex = 0; codeGenModuleIndex < s_Il2CppCodeRegistration->codeGenModulesCount; ++codeGenModuleIndex)
  171. {
  172. if (strcmp(image->name, s_Il2CppCodeRegistration->codeGenModules[codeGenModuleIndex]->moduleName) == 0)
  173. image->codeGenModule = s_Il2CppCodeRegistration->codeGenModules[codeGenModuleIndex];
  174. }
  175. IL2CPP_ASSERT(image->codeGenModule);
  176. image->dynamic = false;
  177. }
  178. // setup all the Il2CppAssemblies.
  179. for (int32_t assemblyIndex = 0; assemblyIndex < s_ImagesCount; assemblyIndex++)
  180. {
  181. Il2CppAssembly* assembly = s_AssembliesTable + assemblyIndex;
  182. ImageIndex assemblyImageIndex;
  183. il2cpp::vm::GlobalMetadata::BuildIl2CppAssembly(assembly, assemblyIndex, &assemblyImageIndex);
  184. assembly->image = il2cpp::vm::MetadataCache::GetImageFromIndex(assemblyImageIndex);
  185. Assembly::Register(assembly);
  186. }
  187. InitializeUnresolvedSignatureTable();
  188. #if IL2CPP_ENABLE_NATIVE_STACKTRACES
  189. std::vector<MethodDefinitionKey> managedMethods;
  190. il2cpp::vm::GlobalMetadata::GetAllManagedMethods(managedMethods);
  191. il2cpp::utils::NativeSymbol::RegisterMethods(managedMethods);
  192. #endif
  193. return true;
  194. }
  195. void il2cpp::vm::MetadataCache::ExecuteEagerStaticClassConstructors()
  196. {
  197. for (int32_t i = 0; i < s_AssembliesCount; i++)
  198. {
  199. const Il2CppImage* image = s_AssembliesTable[i].image;
  200. if (image->codeGenModule->staticConstructorTypeIndices != NULL)
  201. {
  202. TypeDefinitionIndex* indexPointer = image->codeGenModule->staticConstructorTypeIndices;
  203. while (*indexPointer) // 0 terminated
  204. {
  205. Il2CppMetadataTypeHandle handle = GetTypeHandleFromIndex(image, *indexPointer);
  206. Il2CppClass* klass = GlobalMetadata::GetTypeInfoFromHandle(handle);
  207. Runtime::ClassInit(klass);
  208. indexPointer++;
  209. }
  210. }
  211. }
  212. }
  213. typedef void(*Il2CppModuleInitializerMethodPointer)(const MethodInfo*);
  214. void il2cpp::vm::MetadataCache::ExecuteModuleInitializers()
  215. {
  216. for (int32_t i = 0; i < s_AssembliesCount; i++)
  217. {
  218. const Il2CppImage* image = s_AssembliesTable[i].image;
  219. if (image->codeGenModule->moduleInitializer != NULL)
  220. {
  221. Il2CppModuleInitializerMethodPointer moduleInitializer = (Il2CppModuleInitializerMethodPointer)image->codeGenModule->moduleInitializer;
  222. moduleInitializer(NULL);
  223. }
  224. }
  225. }
  226. void ClearGenericMethodTable()
  227. {
  228. s_MethodTableMap.clear();
  229. }
  230. #if !IL2CPP_TRIM_COM
  231. void ClearWindowsRuntimeTypeNamesTables()
  232. {
  233. s_ClassToWindowsRuntimeTypeNameMap.clear();
  234. }
  235. void il2cpp::vm::MetadataCache::InitializeGuidToClassTable()
  236. {
  237. Il2CppInteropData* interopData = s_Il2CppCodeRegistration->interopData;
  238. uint32_t interopDataCount = s_Il2CppCodeRegistration->interopDataCount;
  239. std::vector<std::pair<const Il2CppGuid*, Il2CppClass*> > guidToNonImportClassMap;
  240. guidToNonImportClassMap.reserve(interopDataCount);
  241. for (uint32_t i = 0; i < interopDataCount; i++)
  242. {
  243. // It's important to check for non-import types because type projections will have identical GUIDs (e.g. IEnumerable<T> and IIterable<T>)
  244. if (interopData[i].guid != NULL)
  245. {
  246. Il2CppClass* klass = il2cpp::vm::Class::FromIl2CppType(interopData[i].type);
  247. if (!klass->is_import_or_windows_runtime)
  248. guidToNonImportClassMap.push_back(std::make_pair(interopData[i].guid, klass));
  249. }
  250. }
  251. s_GuidToNonImportClassMap.assign(guidToNonImportClassMap);
  252. }
  253. #endif
  254. // this is called later in the intialization cycle with more systems setup like GC
  255. void il2cpp::vm::MetadataCache::InitializeGCSafe()
  256. {
  257. il2cpp::vm::GlobalMetadata::InitializeStringLiteralTable();
  258. #if ENABLE_HMI_MODE || PLATFORM_WEIXINMINIGAME
  259. assert(s_GenericMethodSet.size() == 0);
  260. s_GenericMethodTableVectorSize = il2cpp::vm::GlobalMetadata::InitializeGenericMethodTableFast(&s_GenericMethodTableVector);
  261. #else
  262. il2cpp::vm::GlobalMetadata::InitializeGenericMethodTable(s_MethodTableMap);
  263. #endif
  264. #if !IL2CPP_TRIM_COM
  265. il2cpp::vm::GlobalMetadata::InitializeWindowsRuntimeTypeNamesTables(s_WindowsRuntimeTypeNameToClassMap, s_ClassToWindowsRuntimeTypeNameMap);
  266. InitializeGuidToClassTable();
  267. #endif
  268. }
  269. void ClearImageNames()
  270. {
  271. for (int32_t imageIndex = 0; imageIndex < s_ImagesCount; imageIndex++)
  272. {
  273. Il2CppImage* image = s_ImagesTable + imageIndex;
  274. IL2CPP_FREE((void*)image->nameNoExt, IL2CPP_MEM_STRING);
  275. }
  276. }
  277. void il2cpp::vm::MetadataCache::Clear()
  278. {
  279. ClearGenericMethodTable();
  280. #if !IL2CPP_TRIM_COM
  281. ClearWindowsRuntimeTypeNamesTables();
  282. #endif
  283. delete s_pUnresolvedSignatureMap;
  284. Assembly::ClearAllAssemblies();
  285. ClearImageNames();
  286. IL2CPP_FREE(s_ImagesTable, IL2CPP_MEM_METADATA_CACHE);
  287. s_ImagesTable = NULL;
  288. s_ImagesCount = 0;
  289. IL2CPP_FREE(s_AssembliesTable, IL2CPP_MEM_METADATA_CACHE);
  290. s_AssembliesTable = NULL;
  291. s_AssembliesCount = 0;
  292. s_GenericMethodSet.clear();
  293. metadata::ArrayMetadata::Clear();
  294. s_GenericInstSet.Clear();
  295. s_Il2CppCodeRegistration = NULL;
  296. s_Il2CppCodeGenOptions = NULL;
  297. il2cpp::metadata::GenericMetadata::Clear();
  298. il2cpp::metadata::GenericMethod::ClearStatics();
  299. il2cpp::vm::GlobalMetadata::Clear();
  300. }
  301. void il2cpp::vm::MetadataCache::InitializeUnresolvedSignatureTable()
  302. {
  303. s_pUnresolvedSignatureMap = new Il2CppUnresolvedSignatureMap();
  304. il2cpp::vm::GlobalMetadata::InitializeUnresolvedSignatureTable(*s_pUnresolvedSignatureMap);
  305. }
  306. Il2CppClass* il2cpp::vm::MetadataCache::GetGenericInstanceType(Il2CppClass* genericTypeDefinition, const Il2CppType** genericArgumentTypes, uint32_t genericArgumentCount)
  307. {
  308. const Il2CppGenericInst* inst = il2cpp::vm::MetadataCache::GetGenericInst(genericArgumentTypes, genericArgumentCount);
  309. Il2CppGenericClass* genericClass = il2cpp::metadata::GenericMetadata::GetGenericClass(genericTypeDefinition, inst);
  310. return il2cpp::vm::GenericClass::GetClass(genericClass);
  311. }
  312. const MethodInfo* il2cpp::vm::MetadataCache::GetGenericInstanceMethod(const MethodInfo* genericMethodDefinition, const Il2CppType** genericArgumentTypes, uint32_t genericArgumentCount)
  313. {
  314. Il2CppGenericContext context = { NULL, GetGenericInst(genericArgumentTypes, genericArgumentCount) };
  315. return il2cpp::vm::GlobalMetadata::GetGenericInstanceMethod(genericMethodDefinition, &context);
  316. }
  317. const Il2CppGenericContext* il2cpp::vm::MetadataCache::GetMethodGenericContext(const MethodInfo* method)
  318. {
  319. if (!method->is_inflated)
  320. {
  321. IL2CPP_NOT_IMPLEMENTED(Image::GetMethodGenericContext);
  322. return NULL;
  323. }
  324. return &method->genericMethod->context;
  325. }
  326. const MethodInfo* il2cpp::vm::MetadataCache::GetGenericMethodDefinition(const MethodInfo* method)
  327. {
  328. if (!method->is_inflated)
  329. {
  330. IL2CPP_NOT_IMPLEMENTED(Image::GetGenericMethodDefinition);
  331. return NULL;
  332. }
  333. return method->genericMethod->methodDefinition;
  334. }
  335. Il2CppClass* il2cpp::vm::MetadataCache::GetPointerType(Il2CppClass* type)
  336. {
  337. Il2CppClass* pointerClass;
  338. if (s_MetadataCache.m_PointerTypes.TryGet(type, &pointerClass))
  339. return pointerClass;
  340. return NULL;
  341. }
  342. Il2CppClass* il2cpp::vm::MetadataCache::GetWindowsRuntimeClass(const char* fullName)
  343. {
  344. #if !IL2CPP_TRIM_COM
  345. WindowsRuntimeTypeNameToClassMap::iterator it = s_WindowsRuntimeTypeNameToClassMap.find(fullName);
  346. if (it != s_WindowsRuntimeTypeNameToClassMap.end())
  347. return it->second;
  348. #endif
  349. return NULL;
  350. }
  351. const char* il2cpp::vm::MetadataCache::GetWindowsRuntimeClassName(const Il2CppClass* klass)
  352. {
  353. #if !IL2CPP_TRIM_COM
  354. ClassToWindowsRuntimeTypeNameMap::iterator it = s_ClassToWindowsRuntimeTypeNameMap.find(klass);
  355. if (it != s_ClassToWindowsRuntimeTypeNameMap.end())
  356. return it->second;
  357. #endif
  358. return NULL;
  359. }
  360. Il2CppMethodPointer il2cpp::vm::MetadataCache::GetWindowsRuntimeFactoryCreationFunction(const char* fullName)
  361. {
  362. #if IL2CPP_TRIM_COM
  363. IL2CPP_NOT_IMPLEMENTED(MetadataCache::GetWindowsRuntimeFactoryCreationFunction);
  364. return NULL;
  365. #else
  366. Il2CppClass* klass = GetWindowsRuntimeClass(fullName);
  367. if (klass == NULL)
  368. return NULL;
  369. WindowsRuntimeFactoryTable::iterator factoryEntry = s_WindowsRuntimeFactories.find_first(&klass->byval_arg);
  370. if (factoryEntry == s_WindowsRuntimeFactories.end())
  371. return NULL;
  372. return factoryEntry->createFactoryFunction;
  373. #endif
  374. }
  375. Il2CppClass* il2cpp::vm::MetadataCache::GetClassForGuid(const Il2CppGuid* guid)
  376. {
  377. #if IL2CPP_TRIM_COM
  378. IL2CPP_NOT_IMPLEMENTED(MetadataCache::GetClassForGuid);
  379. return NULL;
  380. #else
  381. IL2CPP_ASSERT(guid != NULL);
  382. GuidToClassMap::iterator it = s_GuidToNonImportClassMap.find_first(guid);
  383. if (it != s_GuidToNonImportClassMap.end())
  384. return it->second;
  385. return NULL;
  386. #endif
  387. }
  388. void il2cpp::vm::MetadataCache::AddPointerTypeLocked(Il2CppClass* type, Il2CppClass* pointerType, const il2cpp::os::FastAutoLock& lock)
  389. {
  390. // This method must be called while holding the g_MetadataLock to ensure that we don't insert the same pointer type twice
  391. // And WalkPointerTypes assumes this
  392. IL2CPP_ASSERT(lock.IsLock(&g_MetadataLock));
  393. s_MetadataCache.m_PointerTypes.Add(type, pointerType);
  394. }
  395. const Il2CppGenericInst* il2cpp::vm::MetadataCache::GetGenericInst(const Il2CppType* const* types, uint32_t typeCount)
  396. {
  397. // temporary inst to lookup a permanent one that may already exist
  398. Il2CppGenericInst inst;
  399. inst.type_argc = typeCount;
  400. inst.type_argv = (const Il2CppType**)types;
  401. const Il2CppGenericInst* foundInst;
  402. if (s_GenericInstSet.TryGet(&inst, &foundInst))
  403. return foundInst;
  404. il2cpp::os::FastAutoLock lock(&g_MetadataLock);
  405. // Check if instance was added while we were blocked on g_MetadataLock
  406. if (s_GenericInstSet.TryGet(&inst, &foundInst))
  407. return foundInst;
  408. Il2CppGenericInst* newInst = NULL;
  409. newInst = (Il2CppGenericInst*)MetadataMalloc(sizeof(Il2CppGenericInst), IL2CPP_MSTAT_GENERIC_INST);
  410. newInst->type_argc = typeCount;
  411. newInst->type_argv = (const Il2CppType**)MetadataMalloc(newInst->type_argc * sizeof(Il2CppType*), IL2CPP_MSTAT_TYPE);
  412. int index = 0;
  413. const Il2CppType* const* typesEnd = types + typeCount;
  414. for (const Il2CppType* const* iter = types; iter != typesEnd; ++iter, ++index)
  415. newInst->type_argv[index] = *iter;
  416. // Do this while still holding the g_MetadataLock to prevent the same instance from being added twice
  417. bool added = s_GenericInstSet.Add(newInst);
  418. IL2CPP_ASSERT(added);
  419. ++il2cpp_runtime_stats.generic_instance_count;
  420. return newInst;
  421. }
  422. static baselib::ReentrantLock s_GenericMethodMutex;
  423. const Il2CppGenericMethod* il2cpp::vm::MetadataCache::GetGenericMethod(const MethodInfo* methodDefinition, const Il2CppGenericInst* classInst, const Il2CppGenericInst* methodInst)
  424. {
  425. Il2CppGenericMethod method = { 0 };
  426. method.methodDefinition = methodDefinition;
  427. method.context.class_inst = classInst;
  428. method.context.method_inst = methodInst;
  429. #if ENABLE_HMI_MODE || PLATFORM_WEIXINMINIGAME
  430. Il2CppGenericMethodTableItem item;
  431. item.method = &method;
  432. Il2CppGenericMethodTableItem* itemIter = std::lower_bound(s_GenericMethodTableVector, s_GenericMethodTableVector + s_GenericMethodTableVectorSize, item);
  433. if (itemIter != s_GenericMethodTableVector + s_GenericMethodTableVectorSize && *itemIter == item)
  434. return itemIter->method;
  435. #endif
  436. il2cpp::os::FastAutoLock lock(&s_GenericMethodMutex);
  437. Il2CppGenericMethodSet::const_iterator iter = s_GenericMethodSet.find(&method);
  438. if (iter != s_GenericMethodSet.end())
  439. return *iter;
  440. Il2CppGenericMethod* newMethod = MetadataAllocGenericMethod();
  441. newMethod->methodDefinition = methodDefinition;
  442. newMethod->context.class_inst = classInst;
  443. newMethod->context.method_inst = methodInst;
  444. s_GenericMethodSet.insert(newMethod);
  445. return newMethod;
  446. }
  447. static bool IsShareableEnum(const Il2CppType* type)
  448. {
  449. // Base case for recursion - we've found an enum.
  450. if (il2cpp::vm::Type::IsEnum(type))
  451. return true;
  452. if (il2cpp::vm::Type::IsGenericInstance(type))
  453. {
  454. // Recursive case - look "inside" the generic instance type to see if this is a nested enum.
  455. Il2CppClass* definition = il2cpp::vm::GenericClass::GetTypeDefinition(type->data.generic_class);
  456. return IsShareableEnum(il2cpp::vm::Class::GetType(definition));
  457. }
  458. // Base case for recurion - this is not an enum or a generic instance type.
  459. return false;
  460. }
  461. static il2cpp::vm::GenericParameterRestriction IsReferenceTypeGenericConstraint(const Il2CppType* constraint)
  462. {
  463. // This must match GenericSharingAnalsyis.GetGenericParameterConstraintRestriction()
  464. if (constraint->type == IL2CPP_TYPE_VAR || constraint->type == IL2CPP_TYPE_MVAR)
  465. return il2cpp::vm::GenericParameterRestrictionNone;
  466. if (il2cpp::metadata::Il2CppTypeEqualityComparer::AreEqual(constraint, &il2cpp_defaults.enum_class->byval_arg))
  467. return il2cpp::vm::GenericParameterRestrictionValueType;
  468. if (il2cpp::metadata::Il2CppTypeEqualityComparer::AreEqual(constraint, &il2cpp_defaults.value_type_class->byval_arg))
  469. return il2cpp::vm::GenericParameterRestrictionNone; // Not a valid constraint, so consider it unconstrained
  470. else if (il2cpp::vm::Class::IsInterface(il2cpp::vm::Class::FromIl2CppType(constraint)))
  471. return il2cpp::vm::GenericParameterRestrictionNone; // Interfaces constraints can be satisfied by reference or value types
  472. // Any other type constraint e.g. T : SomeType, SomeType must be a reference type
  473. return il2cpp::vm::GenericParameterRestrictionReferenceType;
  474. }
  475. il2cpp::vm::GenericParameterRestriction il2cpp::vm::MetadataCache::IsReferenceTypeGenericParameter(Il2CppMetadataGenericParameterHandle genericParameter)
  476. {
  477. uint16_t flags = il2cpp::vm::GlobalMetadata::GetGenericParameterFlags(genericParameter);
  478. if ((flags & IL2CPP_GENERIC_PARAMETER_ATTRIBUTE_REFERENCE_TYPE_CONSTRAINT) != 0)
  479. return GenericParameterRestrictionReferenceType;
  480. if ((flags & IL2CPP_GENERIC_PARAMETER_ATTRIBUTE_NOT_NULLABLE_VALUE_TYPE_CONSTRAINT) != 0)
  481. return GenericParameterRestrictionValueType; // Must be a value type
  482. uint32_t count = il2cpp::vm::GlobalMetadata::GetGenericConstraintCount(genericParameter);
  483. for (uint32_t constraintIndex = 0; constraintIndex < count; ++constraintIndex)
  484. {
  485. const Il2CppType* constraint = il2cpp::vm::GlobalMetadata::GetGenericParameterConstraintFromIndex(genericParameter, constraintIndex);
  486. GenericParameterRestriction restriction = IsReferenceTypeGenericConstraint(constraint);
  487. if (restriction != GenericParameterRestrictionNone)
  488. return restriction;
  489. }
  490. return GenericParameterRestrictionNone;
  491. }
  492. static const Il2CppGenericInst* GetFullySharedInst(Il2CppMetadataGenericContainerHandle genericContainer, const Il2CppGenericInst* inst)
  493. {
  494. if (inst == NULL || !il2cpp::vm::Runtime::IsFullGenericSharingEnabled())
  495. return NULL;
  496. const Il2CppType** types = (const Il2CppType**)alloca(inst->type_argc * sizeof(Il2CppType*));
  497. for (uint32_t i = 0; i < inst->type_argc; ++i)
  498. {
  499. const Il2CppType* type;
  500. switch (il2cpp::vm::MetadataCache::IsReferenceTypeGenericParameter(il2cpp::vm::GlobalMetadata::GetGenericParameterFromIndex(genericContainer, i)))
  501. {
  502. case il2cpp::vm::GenericParameterRestrictionValueType:
  503. type = &il2cpp_defaults.il2cpp_fully_shared_struct_type->byval_arg;
  504. break;
  505. case il2cpp::vm::GenericParameterRestrictionReferenceType:
  506. type = &il2cpp_defaults.object_class->byval_arg;
  507. break;
  508. default:
  509. type = &il2cpp_defaults.il2cpp_fully_shared_type->byval_arg;
  510. break;
  511. }
  512. types[i] = type;
  513. }
  514. const Il2CppGenericInst* sharedInst = il2cpp::vm::MetadataCache::GetGenericInst(types, inst->type_argc);
  515. return sharedInst;
  516. }
  517. // this logic must match the C# logic in GenericSharingAnalysis.GetSharedTypeForGenericParameter
  518. static const Il2CppGenericInst* GetSharedInst(const Il2CppGenericInst* inst)
  519. {
  520. if (inst == NULL)
  521. return NULL;
  522. const Il2CppType** types = (const Il2CppType**)alloca(inst->type_argc * sizeof(Il2CppType*));
  523. for (uint32_t i = 0; i < inst->type_argc; ++i)
  524. {
  525. if (il2cpp::vm::Type::IsReference(inst->type_argv[i]))
  526. types[i] = &il2cpp_defaults.object_class->byval_arg;
  527. else
  528. {
  529. const Il2CppType* type = inst->type_argv[i];
  530. if (s_Il2CppCodeGenOptions->enablePrimitiveValueTypeGenericSharing)
  531. {
  532. if (IsShareableEnum(type))
  533. {
  534. const Il2CppType* underlyingType = il2cpp::vm::Type::GetUnderlyingType(type);
  535. switch (underlyingType->type)
  536. {
  537. case IL2CPP_TYPE_I1:
  538. type = &il2cpp_defaults.sbyte_shared_enum->byval_arg;
  539. break;
  540. case IL2CPP_TYPE_I2:
  541. type = &il2cpp_defaults.int16_shared_enum->byval_arg;
  542. break;
  543. case IL2CPP_TYPE_I4:
  544. type = &il2cpp_defaults.int32_shared_enum->byval_arg;
  545. break;
  546. case IL2CPP_TYPE_I8:
  547. type = &il2cpp_defaults.int64_shared_enum->byval_arg;
  548. break;
  549. case IL2CPP_TYPE_U1:
  550. type = &il2cpp_defaults.byte_shared_enum->byval_arg;
  551. break;
  552. case IL2CPP_TYPE_U2:
  553. type = &il2cpp_defaults.uint16_shared_enum->byval_arg;
  554. break;
  555. case IL2CPP_TYPE_U4:
  556. type = &il2cpp_defaults.uint32_shared_enum->byval_arg;
  557. break;
  558. case IL2CPP_TYPE_U8:
  559. type = &il2cpp_defaults.uint64_shared_enum->byval_arg;
  560. break;
  561. default:
  562. IL2CPP_ASSERT(0 && "Invalid enum underlying type");
  563. break;
  564. }
  565. }
  566. }
  567. if (il2cpp::vm::Type::IsGenericInstance(type))
  568. {
  569. const Il2CppGenericInst* sharedInst = GetSharedInst(type->data.generic_class->context.class_inst);
  570. Il2CppGenericClass* gklass = il2cpp::metadata::GenericMetadata::GetGenericClass(type->data.generic_class->type, sharedInst);
  571. Il2CppClass* klass = il2cpp::vm::GenericClass::GetClass(gklass);
  572. type = &klass->byval_arg;
  573. }
  574. types[i] = type;
  575. }
  576. }
  577. const Il2CppGenericInst* sharedInst = il2cpp::vm::MetadataCache::GetGenericInst(types, inst->type_argc);
  578. return sharedInst;
  579. }
  580. static il2cpp::vm::Il2CppGenericMethodPointers MakeGenericMethodPointers(const Il2CppGenericMethodIndices* methodIndicies, bool isFullyShared)
  581. {
  582. IL2CPP_ASSERT(methodIndicies->methodIndex >= 0 && methodIndicies->invokerIndex >= 0);
  583. if (static_cast<uint32_t>(methodIndicies->methodIndex) < s_Il2CppCodeRegistration->genericMethodPointersCount && static_cast<uint32_t>(methodIndicies->invokerIndex) < s_Il2CppCodeRegistration->invokerPointersCount)
  584. {
  585. Il2CppMethodPointer virtualMethod;
  586. Il2CppMethodPointer method;
  587. method = s_Il2CppCodeRegistration->genericMethodPointers[methodIndicies->methodIndex];
  588. if (methodIndicies->adjustorThunkIndex != -1)
  589. {
  590. virtualMethod = s_Il2CppCodeRegistration->genericAdjustorThunks[methodIndicies->adjustorThunkIndex];
  591. }
  592. else
  593. {
  594. virtualMethod = method;
  595. }
  596. return { method, virtualMethod, s_Il2CppCodeRegistration->invokerPointers[methodIndicies->invokerIndex], isFullyShared };
  597. }
  598. return { NULL, NULL, NULL, false };
  599. }
  600. il2cpp::vm::Il2CppGenericMethodPointers il2cpp::vm::MetadataCache::GetGenericMethodPointers(const MethodInfo* methodDefinition, const Il2CppGenericContext* context)
  601. {
  602. Il2CppGenericMethod method = { 0 };
  603. method.methodDefinition = const_cast<MethodInfo*>(methodDefinition);
  604. method.context.class_inst = context->class_inst;
  605. method.context.method_inst = context->method_inst;
  606. #if ENABLE_HMI_MODE || PLATFORM_WEIXINMINIGAME
  607. Il2CppGenericMethodTableItem item;
  608. item.method = &method;
  609. #endif
  610. #if ENABLE_HMI_MODE || PLATFORM_WEIXINMINIGAME
  611. Il2CppGenericMethodTableItem* iter = std::lower_bound(s_GenericMethodTableVector, s_GenericMethodTableVector + s_GenericMethodTableVectorSize, item);
  612. if (iter != s_GenericMethodTableVector + s_GenericMethodTableVectorSize && *iter == item)
  613. return MakeGenericMethodPointers(iter->indices, false);
  614. #else
  615. Il2CppMethodTableMapIter iter = s_MethodTableMap.find(&method);
  616. if (iter != s_MethodTableMap.end())
  617. return MakeGenericMethodPointers(iter->second, false);
  618. #endif
  619. // get the shared version if it exists
  620. method.context.class_inst = GetSharedInst(context->class_inst);
  621. method.context.method_inst = GetSharedInst(context->method_inst);
  622. #if ENABLE_HMI_MODE || PLATFORM_WEIXINMINIGAME
  623. iter = std::lower_bound(s_GenericMethodTableVector, s_GenericMethodTableVector + s_GenericMethodTableVectorSize, item);
  624. if (iter != s_GenericMethodTableVector + s_GenericMethodTableVectorSize && *iter == item)
  625. return MakeGenericMethodPointers(iter->indices, false);
  626. #else
  627. iter = s_MethodTableMap.find(&method);
  628. if (iter != s_MethodTableMap.end())
  629. return MakeGenericMethodPointers(iter->second, false);
  630. #endif
  631. // get the fully shared version if it exists
  632. method.context.class_inst = GetFullySharedInst(methodDefinition->klass->genericContainerHandle, context->class_inst);
  633. method.context.method_inst = GetFullySharedInst(methodDefinition->genericContainerHandle, context->method_inst);
  634. #if ENABLE_HMI_MODE || PLATFORM_WEIXINMINIGAME
  635. iter = std::lower_bound(s_GenericMethodTableVector, s_GenericMethodTableVector + s_GenericMethodTableVectorSize, item);
  636. if (iter != s_GenericMethodTableVector + s_GenericMethodTableVectorSize && *iter == item)
  637. return MakeGenericMethodPointers(iter->indices, true);
  638. #else
  639. iter = s_MethodTableMap.find(&method);
  640. if (iter != s_MethodTableMap.end())
  641. return MakeGenericMethodPointers(iter->second, true);
  642. #endif
  643. return { NULL, NULL, NULL };
  644. }
  645. const Il2CppType* il2cpp::vm::MetadataCache::GetIl2CppTypeFromIndex(const Il2CppImage* image, TypeIndex index)
  646. {
  647. return il2cpp::vm::GlobalMetadata::GetIl2CppTypeFromIndex(index);
  648. }
  649. const Il2CppType* il2cpp::vm::MetadataCache::GetTypeFromRgctxDefinition(const Il2CppRGCTXDefinition* rgctxDef)
  650. {
  651. return il2cpp::vm::GlobalMetadata::GetTypeFromRgctxDefinition(rgctxDef);
  652. }
  653. const Il2CppGenericMethod* il2cpp::vm::MetadataCache::GetGenericMethodFromRgctxDefinition(const Il2CppRGCTXDefinition* rgctxDef)
  654. {
  655. return il2cpp::vm::GlobalMetadata::GetGenericMethodFromRgctxDefinition(rgctxDef);
  656. }
  657. std::pair<const Il2CppType*, const MethodInfo*> il2cpp::vm::MetadataCache::GetConstrainedCallFromRgctxDefinition(const Il2CppRGCTXDefinition* rgctxDef)
  658. {
  659. return il2cpp::vm::GlobalMetadata::GetConstrainedCallFromRgctxDefinition(rgctxDef);
  660. }
  661. const MethodInfo* il2cpp::vm::MetadataCache::GetMethodInfoFromVTableSlot(const Il2CppClass* klass, int32_t vTableSlot)
  662. {
  663. return il2cpp::vm::GlobalMetadata::GetMethodInfoFromVTableSlot(klass, vTableSlot);
  664. }
  665. static int CompareIl2CppTokenAdjustorThunkPair(const void* pkey, const void* pelem)
  666. {
  667. return (int)(((Il2CppTokenAdjustorThunkPair*)pkey)->token - ((Il2CppTokenAdjustorThunkPair*)pelem)->token);
  668. }
  669. Il2CppMethodPointer il2cpp::vm::MetadataCache::GetAdjustorThunk(const Il2CppImage* image, uint32_t token)
  670. {
  671. if (hybridclr::metadata::IsInterpreterIndex(image->token))
  672. {
  673. return hybridclr::metadata::MetadataModule::GetAdjustorThunk(image, token);
  674. }
  675. if (image->codeGenModule->adjustorThunkCount == 0)
  676. return NULL;
  677. Il2CppTokenAdjustorThunkPair key;
  678. memset(&key, 0, sizeof(Il2CppTokenAdjustorThunkPair));
  679. key.token = token;
  680. const Il2CppTokenAdjustorThunkPair* result = (const Il2CppTokenAdjustorThunkPair*)bsearch(&key, image->codeGenModule->adjustorThunks,
  681. image->codeGenModule->adjustorThunkCount, sizeof(Il2CppTokenAdjustorThunkPair), CompareIl2CppTokenAdjustorThunkPair);
  682. if (result == NULL)
  683. return NULL;
  684. return result->adjustorThunk;
  685. }
  686. Il2CppMethodPointer il2cpp::vm::MetadataCache::GetMethodPointer(const Il2CppImage* image, uint32_t token)
  687. {
  688. uint32_t rid = GetTokenRowId(token);
  689. uint32_t table = GetTokenType(token);
  690. if (rid == 0)
  691. return NULL;
  692. if (hybridclr::metadata::IsInterpreterImage(image))
  693. {
  694. return hybridclr::metadata::MetadataModule::GetMethodPointer(image, token);
  695. }
  696. IL2CPP_ASSERT(rid <= image->codeGenModule->methodPointerCount);
  697. return image->codeGenModule->methodPointers[rid - 1];
  698. }
  699. InvokerMethod il2cpp::vm::MetadataCache::GetMethodInvoker(const Il2CppImage* image, uint32_t token)
  700. {
  701. uint32_t rid = GetTokenRowId(token);
  702. uint32_t table = GetTokenType(token);
  703. if (rid == 0)
  704. return Runtime::GetMissingMethodInvoker();
  705. if (hybridclr::metadata::IsInterpreterImage(image))
  706. {
  707. return hybridclr::metadata::MetadataModule::GetMethodInvoker(image, token);
  708. }
  709. int32_t index = image->codeGenModule->invokerIndices[rid - 1];
  710. if (index == kMethodIndexInvalid)
  711. return Runtime::GetMissingMethodInvoker();
  712. IL2CPP_ASSERT(index >= 0 && static_cast<uint32_t>(index) < s_Il2CppCodeRegistration->invokerPointersCount);
  713. return s_Il2CppCodeRegistration->invokerPointers[index];
  714. }
  715. const Il2CppInteropData* il2cpp::vm::MetadataCache::GetInteropDataForType(const Il2CppType* type)
  716. {
  717. IL2CPP_ASSERT(type != NULL);
  718. InteropDataMap::iterator interopData = s_InteropData.find_first(type);
  719. if (interopData == s_InteropData.end())
  720. return NULL;
  721. return interopData;
  722. }
  723. static bool MatchTokens(Il2CppTokenIndexMethodTuple key, Il2CppTokenIndexMethodTuple element)
  724. {
  725. return key.token < element.token;
  726. }
  727. static bool GenericInstancesMatch(const MethodInfo* method, const MethodInfo* matchingMethod)
  728. {
  729. if (method->genericMethod->context.class_inst != NULL && matchingMethod->genericMethod->context.class_inst != NULL)
  730. {
  731. if (!il2cpp::metadata::Il2CppGenericInstCompare::AreEqual(method->genericMethod->context.class_inst, matchingMethod->genericMethod->context.class_inst))
  732. return false;
  733. }
  734. if (method->genericMethod->context.method_inst != NULL && matchingMethod->genericMethod->context.method_inst != NULL)
  735. {
  736. if (!il2cpp::metadata::Il2CppGenericInstCompare::AreEqual(method->genericMethod->context.method_inst, matchingMethod->genericMethod->context.method_inst))
  737. return false;
  738. }
  739. return true;
  740. }
  741. Il2CppMethodPointer il2cpp::vm::MetadataCache::GetReversePInvokeWrapper(const Il2CppImage* image, const MethodInfo* method)
  742. {
  743. if (image->codeGenModule->reversePInvokeWrapperCount == 0)
  744. return NULL;
  745. // For each image (i.e. assembly), the reverse pinvoke wrapper indices are in an array sorted by
  746. // metadata token. Each entry also might have the method metadata pointer, which is used to further
  747. // find methods that have a matching metadata token.
  748. Il2CppTokenIndexMethodTuple key;
  749. memset(&key, 0, sizeof(Il2CppTokenIndexMethodTuple));
  750. key.token = method->token;
  751. // Binary search for a range which matches the metadata token.
  752. auto begin = image->codeGenModule->reversePInvokeWrapperIndices;
  753. auto end = image->codeGenModule->reversePInvokeWrapperIndices + image->codeGenModule->reversePInvokeWrapperCount;
  754. auto matchingRange = std::equal_range(begin, end, key, &MatchTokens);
  755. int32_t index = -1;
  756. auto numberOfMatches = std::distance(matchingRange.first, matchingRange.second);
  757. if (numberOfMatches == 1)
  758. {
  759. if (method->genericMethod == NULL)
  760. {
  761. // We found one non-generic method.
  762. index = matchingRange.first->index;
  763. }
  764. else
  765. {
  766. // We found one generic method - let's make sure the class and method generic instances match. This reverse p/invoke
  767. // wrapper might be for a different inflated generic instance.
  768. const MethodInfo* possibleMatch = il2cpp::metadata::GenericMethod::GetMethod(il2cpp::vm::GlobalMetadata::GetGenericMethodFromTokenMethodTuple(matchingRange.first));
  769. if (possibleMatch->genericMethod != NULL && GenericInstancesMatch(method, possibleMatch))
  770. index = matchingRange.first->index;
  771. }
  772. }
  773. else if (numberOfMatches > 1)
  774. {
  775. // Multiple generic instance methods share the same token, since it is from the generic method definition.
  776. // To find the proper method, look for the one with a matching method metadata pointer.
  777. const Il2CppTokenIndexMethodTuple* currentMatch = matchingRange.first;
  778. const Il2CppTokenIndexMethodTuple* lastMatch = matchingRange.second;
  779. while (currentMatch != lastMatch)
  780. {
  781. // First, check the method metadata, and use it if it has been initialized.
  782. // If not, let's fall back to the generic method.
  783. const MethodInfo* possibleMatch = (const MethodInfo*)*currentMatch->method;
  784. if (!il2cpp::vm::GlobalMetadata::IsRuntimeMetadataInitialized(possibleMatch))
  785. possibleMatch = il2cpp::metadata::GenericMethod::GetMethod(il2cpp::vm::GlobalMetadata::GetGenericMethodFromTokenMethodTuple(currentMatch));
  786. if (possibleMatch == method)
  787. {
  788. index = currentMatch->index;
  789. break;
  790. }
  791. currentMatch++;
  792. }
  793. }
  794. if (index == -1)
  795. return NULL;
  796. IL2CPP_ASSERT(index >= 0 && static_cast<uint32_t>(index) < s_Il2CppCodeRegistration->reversePInvokeWrapperCount);
  797. return s_Il2CppCodeRegistration->reversePInvokeWrappers[index];
  798. }
  799. static const Il2CppType* GetReducedType(const Il2CppType* type)
  800. {
  801. if (type->byref)
  802. return &il2cpp_defaults.object_class->byval_arg;
  803. if (il2cpp::vm::Type::IsEnum(type))
  804. type = il2cpp::vm::Type::GetUnderlyingType(type);
  805. switch (type->type)
  806. {
  807. case IL2CPP_TYPE_BOOLEAN:
  808. return &il2cpp_defaults.byte_class->byval_arg;
  809. case IL2CPP_TYPE_CHAR:
  810. return &il2cpp_defaults.uint16_class->byval_arg;
  811. case IL2CPP_TYPE_BYREF:
  812. case IL2CPP_TYPE_CLASS:
  813. case IL2CPP_TYPE_OBJECT:
  814. case IL2CPP_TYPE_STRING:
  815. case IL2CPP_TYPE_ARRAY:
  816. case IL2CPP_TYPE_SZARRAY:
  817. return &il2cpp_defaults.object_class->byval_arg;
  818. case IL2CPP_TYPE_GENERICINST:
  819. if (il2cpp::vm::Type::GenericInstIsValuetype(type))
  820. {
  821. // We can't inflate a generic instance that contains generic arguments
  822. if (il2cpp::metadata::GenericMetadata::ContainsGenericParameters(type))
  823. return type;
  824. const Il2CppGenericInst* sharedInst = GetSharedInst(type->data.generic_class->context.class_inst);
  825. Il2CppGenericClass* gklass = il2cpp::metadata::GenericMetadata::GetGenericClass(type->data.generic_class->type, sharedInst);
  826. Il2CppClass* klass = il2cpp::vm::GenericClass::GetClass(gklass);
  827. return &klass->byval_arg;
  828. }
  829. return &il2cpp_defaults.object_class->byval_arg;
  830. default:
  831. return type;
  832. }
  833. }
  834. il2cpp::vm::Il2CppUnresolvedCallStubs il2cpp::vm::MetadataCache::GetUnresovledCallStubs(const MethodInfo* method)
  835. {
  836. il2cpp::vm::Il2CppUnresolvedCallStubs stubs;
  837. stubs.stubsFound = false;
  838. il2cpp::metadata::Il2CppSignature signature;
  839. signature.Count = method->parameters_count + 1;
  840. signature.Types = (const Il2CppType**)alloca(signature.Count * sizeof(Il2CppType*));
  841. signature.Types[0] = GetReducedType(method->return_type);
  842. for (int i = 0; i < method->parameters_count; ++i)
  843. signature.Types[i + 1] = GetReducedType(method->parameters[i]);
  844. Il2CppUnresolvedSignatureMapIter it = s_pUnresolvedSignatureMap->find(signature);
  845. if (it != s_pUnresolvedSignatureMap->end())
  846. {
  847. if (il2cpp::vm::Method::IsInstance(method))
  848. {
  849. stubs.methodPointer = s_Il2CppCodeRegistration->unresolvedInstanceCallPointers[it->second];
  850. stubs.virtualMethodPointer = s_Il2CppCodeRegistration->unresolvedVirtualCallPointers[it->second];
  851. stubs.stubsFound = true;
  852. }
  853. else
  854. {
  855. stubs.methodPointer = s_Il2CppCodeRegistration->unresolvedStaticCallPointers[it->second];
  856. stubs.virtualMethodPointer = stubs.methodPointer;
  857. stubs.stubsFound = true;
  858. }
  859. }
  860. else
  861. {
  862. const MethodInfo* entryPointNotFoundMethod = il2cpp::vm::Method::GetEntryPointNotFoundMethodInfo();
  863. stubs.methodPointer = entryPointNotFoundMethod->methodPointer;
  864. stubs.virtualMethodPointer = entryPointNotFoundMethod->methodPointer;
  865. }
  866. return stubs;
  867. }
  868. const Il2CppAssembly* il2cpp::vm::MetadataCache::GetAssemblyFromIndex(AssemblyIndex index)
  869. {
  870. if (index == kGenericContainerIndexInvalid)
  871. return NULL;
  872. IL2CPP_ASSERT(index <= s_AssembliesCount);
  873. return s_AssembliesTable + index;
  874. }
  875. const Il2CppAssembly* il2cpp::vm::MetadataCache::GetAssemblyByName(const char* nameToFind)
  876. {
  877. const char* assemblyName = hybridclr::GetAssemblyNameFromPath(nameToFind);
  878. il2cpp::utils::VmStringUtils::CaseInsensitiveComparer comparer;
  879. for (int i = 0; i < s_AssembliesCount; i++)
  880. {
  881. const Il2CppAssembly* assembly = s_AssembliesTable + i;
  882. if (comparer(assembly->aname.name, assemblyName) || comparer(assembly->image->name, assemblyName))
  883. return assembly;
  884. }
  885. il2cpp::os::FastAutoLock lock(&il2cpp::vm::g_MetadataLock);
  886. for (auto assembly : s_cliAssemblies)
  887. {
  888. if (comparer(assembly->aname.name, assemblyName) || comparer(assembly->image->name, assemblyName))
  889. return assembly;
  890. }
  891. return nullptr;
  892. }
  893. void il2cpp::vm::MetadataCache::RegisterInterpreterAssembly(Il2CppAssembly* assembly)
  894. {
  895. il2cpp::vm::Assembly::Register(assembly);
  896. s_cliAssemblies.push_back(assembly);
  897. }
  898. const Il2CppAssembly* il2cpp::vm::MetadataCache::LoadAssemblyFromBytes(const char* assemblyBytes, size_t length, const char* rawSymbolStoreBytes, size_t rawSymbolStoreLength)
  899. {
  900. Il2CppAssembly* newAssembly = hybridclr::metadata::Assembly::LoadFromBytes(assemblyBytes, length, rawSymbolStoreBytes, rawSymbolStoreLength);
  901. il2cpp::os::FastAutoLock lock(&il2cpp::vm::g_MetadataLock);
  902. // avoid register placeholder assembly twicely.
  903. for (Il2CppAssembly* ass : s_cliAssemblies)
  904. {
  905. if (ass == newAssembly)
  906. {
  907. il2cpp::vm::Assembly::InvalidateAssemblyList();
  908. return ass;
  909. }
  910. }
  911. RegisterInterpreterAssembly(newAssembly);
  912. return newAssembly;
  913. }
  914. const Il2CppGenericMethod* il2cpp::vm::MetadataCache::FindGenericMethod(std::function<bool(const Il2CppGenericMethod*)> predic)
  915. {
  916. for (auto e : s_MethodTableMap)
  917. {
  918. if (predic(e.first))
  919. {
  920. return e.first;
  921. }
  922. }
  923. return nullptr;
  924. }
  925. void il2cpp::vm::MetadataCache::FixThreadLocalStaticOffsetForFieldLocked(FieldInfo* field, int32_t offset, const il2cpp::os::FastAutoLock& lock)
  926. {
  927. s_ThreadLocalStaticOffsetMap[field] = offset;
  928. }
  929. Il2CppImage* il2cpp::vm::MetadataCache::GetImageFromIndex(ImageIndex index)
  930. {
  931. if (index == kGenericContainerIndexInvalid)
  932. return NULL;
  933. IL2CPP_ASSERT(index <= s_ImagesCount);
  934. return s_ImagesTable + index;
  935. }
  936. Il2CppClass* il2cpp::vm::MetadataCache::GetTypeInfoFromType(const Il2CppType* type)
  937. {
  938. if (type == NULL)
  939. return NULL;
  940. return il2cpp::vm::GlobalMetadata::GetTypeInfoFromType(type);
  941. }
  942. Il2CppClass* il2cpp::vm::MetadataCache::GetTypeInfoFromHandle(Il2CppMetadataTypeHandle handle)
  943. {
  944. return il2cpp::vm::GlobalMetadata::GetTypeInfoFromHandle(handle);
  945. }
  946. Il2CppMetadataGenericContainerHandle il2cpp::vm::MetadataCache::GetGenericContainerFromGenericClass(const Il2CppImage* image, const Il2CppGenericClass* genericClass)
  947. {
  948. return il2cpp::vm::GlobalMetadata::GetGenericContainerFromGenericClass(genericClass);
  949. }
  950. Il2CppMetadataGenericContainerHandle il2cpp::vm::MetadataCache::GetGenericContainerFromMethod(Il2CppMetadataMethodDefinitionHandle handle)
  951. {
  952. return il2cpp::vm::GlobalMetadata::GetGenericContainerFromMethod(handle);
  953. }
  954. Il2CppMetadataGenericParameterHandle il2cpp::vm::MetadataCache::GetGenericParameterFromType(const Il2CppType* type)
  955. {
  956. return il2cpp::vm::GlobalMetadata::GetGenericParameterFromType(type);
  957. }
  958. Il2CppClass* il2cpp::vm::MetadataCache::GetContainerDeclaringType(Il2CppMetadataGenericContainerHandle handle)
  959. {
  960. return il2cpp::vm::GlobalMetadata::GetContainerDeclaringType(handle);
  961. }
  962. Il2CppClass* il2cpp::vm::MetadataCache::GetParameterDeclaringType(Il2CppMetadataGenericParameterHandle handle)
  963. {
  964. return il2cpp::vm::GlobalMetadata::GetParameterDeclaringType(handle);
  965. }
  966. const MethodInfo* il2cpp::vm::MetadataCache::GetParameterDeclaringMethod(Il2CppMetadataGenericParameterHandle handle)
  967. {
  968. return il2cpp::vm::GlobalMetadata::GetParameterDeclaringMethod(handle);
  969. }
  970. Il2CppMetadataGenericParameterHandle il2cpp::vm::MetadataCache::GetGenericParameterFromIndex(Il2CppMetadataGenericContainerHandle handle, GenericContainerParameterIndex index)
  971. {
  972. return il2cpp::vm::GlobalMetadata::GetGenericParameterFromIndex(handle, index);
  973. }
  974. const Il2CppType* il2cpp::vm::MetadataCache::GetGenericParameterConstraintFromIndex(Il2CppMetadataGenericParameterHandle handle, GenericParameterConstraintIndex index)
  975. {
  976. return il2cpp::vm::GlobalMetadata::GetGenericParameterConstraintFromIndex(handle, index);
  977. }
  978. Il2CppClass* il2cpp::vm::MetadataCache::GetNestedTypeFromOffset(const Il2CppClass* klass, TypeNestedTypeIndex offset)
  979. {
  980. return il2cpp::vm::GlobalMetadata::GetNestedTypeFromOffset(klass, offset);
  981. }
  982. const Il2CppType* il2cpp::vm::MetadataCache::GetInterfaceFromOffset(const Il2CppClass* klass, TypeInterfaceIndex offset)
  983. {
  984. return il2cpp::vm::GlobalMetadata::GetInterfaceFromOffset(klass, offset);
  985. }
  986. Il2CppInterfaceOffsetInfo il2cpp::vm::MetadataCache::GetInterfaceOffsetInfo(const Il2CppClass* klass, TypeInterfaceOffsetIndex index)
  987. {
  988. return il2cpp::vm::GlobalMetadata::GetInterfaceOffsetInfo(klass, index);
  989. }
  990. static int CompareIl2CppTokenRangePair(const void* pkey, const void* pelem)
  991. {
  992. return (int)(((Il2CppTokenRangePair*)pkey)->token - ((Il2CppTokenRangePair*)pelem)->token);
  993. }
  994. il2cpp::vm::RGCTXCollection il2cpp::vm::MetadataCache::GetRGCTXs(const Il2CppImage* image, uint32_t token)
  995. {
  996. RGCTXCollection collection = { 0, NULL };
  997. if (image->codeGenModule->rgctxRangesCount == 0)
  998. return collection;
  999. Il2CppTokenRangePair key;
  1000. memset(&key, 0, sizeof(Il2CppTokenRangePair));
  1001. key.token = token;
  1002. const Il2CppTokenRangePair* res = (const Il2CppTokenRangePair*)bsearch(&key, image->codeGenModule->rgctxRanges, image->codeGenModule->rgctxRangesCount, sizeof(Il2CppTokenRangePair), CompareIl2CppTokenRangePair);
  1003. if (res == NULL)
  1004. return collection;
  1005. collection.count = res->range.length;
  1006. collection.items = image->codeGenModule->rgctxs + res->range.start;
  1007. return collection;
  1008. }
  1009. const uint8_t* il2cpp::vm::MetadataCache::GetFieldDefaultValue(const FieldInfo* field, const Il2CppType** type)
  1010. {
  1011. return il2cpp::vm::GlobalMetadata::GetFieldDefaultValue(field, type);
  1012. }
  1013. const uint8_t* il2cpp::vm::MetadataCache::GetParameterDefaultValue(const MethodInfo* method, int32_t parameterPosition, const Il2CppType** type, bool* isExplicitySetNullDefaultValue)
  1014. {
  1015. return il2cpp::vm::GlobalMetadata::GetParameterDefaultValue(method, parameterPosition, type, isExplicitySetNullDefaultValue);
  1016. }
  1017. int il2cpp::vm::MetadataCache::GetFieldMarshaledSizeForField(const FieldInfo* field)
  1018. {
  1019. return il2cpp::vm::GlobalMetadata::GetFieldMarshaledSizeForField(field);
  1020. }
  1021. int32_t il2cpp::vm::MetadataCache::GetFieldOffsetFromIndexLocked(const Il2CppClass* klass, int32_t fieldIndexInType, FieldInfo* field, const il2cpp::os::FastAutoLock& lock)
  1022. {
  1023. int32_t offset = il2cpp::vm::GlobalMetadata::GetFieldOffset(klass, fieldIndexInType, field);
  1024. if (offset < 0)
  1025. {
  1026. AddThreadLocalStaticOffsetForFieldLocked(field, offset & ~THREAD_LOCAL_STATIC_MASK, lock);
  1027. return THREAD_STATIC_FIELD_OFFSET;
  1028. }
  1029. return offset;
  1030. }
  1031. void il2cpp::vm::MetadataCache::AddThreadLocalStaticOffsetForFieldLocked(FieldInfo* field, int32_t offset, const il2cpp::os::FastAutoLock& lock)
  1032. {
  1033. s_ThreadLocalStaticOffsetMap.add(field, offset);
  1034. }
  1035. int32_t il2cpp::vm::MetadataCache::GetThreadLocalStaticOffsetForField(FieldInfo* field)
  1036. {
  1037. IL2CPP_ASSERT(field->offset == THREAD_STATIC_FIELD_OFFSET);
  1038. il2cpp::os::FastAutoLock lock(&g_MetadataLock);
  1039. Il2CppThreadLocalStaticOffsetHashMapIter iter = s_ThreadLocalStaticOffsetMap.find(field);
  1040. IL2CPP_ASSERT(iter != s_ThreadLocalStaticOffsetMap.end());
  1041. return iter->second;
  1042. }
  1043. Il2CppMetadataCustomAttributeHandle il2cpp::vm::MetadataCache::GetCustomAttributeTypeToken(const Il2CppImage* image, uint32_t token)
  1044. {
  1045. return il2cpp::vm::GlobalMetadata::GetCustomAttributeTypeToken(image, token);
  1046. }
  1047. il2cpp::metadata::CustomAttributeDataReader il2cpp::vm::MetadataCache::GetCustomAttributeDataReader(const Il2CppImage* image, uint32_t token)
  1048. {
  1049. return il2cpp::vm::GlobalMetadata::GetCustomAttributeDataReader(image, token);
  1050. }
  1051. il2cpp::metadata::CustomAttributeDataReader il2cpp::vm::MetadataCache::GetCustomAttributeDataReader(Il2CppMetadataCustomAttributeHandle handle)
  1052. {
  1053. return il2cpp::vm::GlobalMetadata::GetCustomAttributeDataReader(handle);
  1054. }
  1055. const Il2CppAssembly* il2cpp::vm::MetadataCache::GetReferencedAssembly(const Il2CppAssembly* assembly, int32_t referencedAssemblyTableIndex)
  1056. {
  1057. return il2cpp::vm::GlobalMetadata::GetReferencedAssembly(assembly, referencedAssemblyTableIndex, s_AssembliesTable, s_AssembliesCount);
  1058. }
  1059. void il2cpp::vm::MetadataCache::InitializeAllMethodMetadata()
  1060. {
  1061. il2cpp::vm::GlobalMetadata::InitializeAllMethodMetadata();
  1062. }
  1063. void* il2cpp::vm::MetadataCache::InitializeRuntimeMetadata(uintptr_t* metadataPointer)
  1064. {
  1065. return il2cpp::vm::GlobalMetadata::InitializeRuntimeMetadata(metadataPointer, true);
  1066. }
  1067. void il2cpp::vm::MetadataCache::WalkPointerTypes(WalkTypesCallback callback, void* context)
  1068. {
  1069. os::FastAutoLock lock(&g_MetadataLock);
  1070. for (PointerTypeMap::iterator it = s_MetadataCache.m_PointerTypes.UnlockedBegin(); it != s_MetadataCache.m_PointerTypes.UnlockedEnd(); it++)
  1071. {
  1072. callback(it->second, context);
  1073. }
  1074. }
  1075. Il2CppMetadataTypeHandle il2cpp::vm::MetadataCache::GetTypeHandleFromIndex(const Il2CppImage* image, TypeDefinitionIndex typeIndex)
  1076. {
  1077. return il2cpp::vm::GlobalMetadata::GetTypeHandleFromIndex(typeIndex);
  1078. }
  1079. Il2CppMetadataTypeHandle il2cpp::vm::MetadataCache::GetTypeHandleFromType(const Il2CppType* type)
  1080. {
  1081. return il2cpp::vm::GlobalMetadata::GetTypeHandleFromType(type);
  1082. }
  1083. bool il2cpp::vm::MetadataCache::TypeIsNested(Il2CppMetadataTypeHandle handle)
  1084. {
  1085. return il2cpp::vm::GlobalMetadata::TypeIsNested(handle);
  1086. }
  1087. bool il2cpp::vm::MetadataCache::TypeIsValueType(Il2CppMetadataTypeHandle handle)
  1088. {
  1089. return il2cpp::vm::GlobalMetadata::TypeIsValueType(handle);
  1090. }
  1091. bool il2cpp::vm::MetadataCache::StructLayoutPackIsDefault(Il2CppMetadataTypeHandle handle)
  1092. {
  1093. return il2cpp::vm::GlobalMetadata::StructLayoutPackIsDefault(handle);
  1094. }
  1095. int32_t il2cpp::vm::MetadataCache::StructLayoutPack(Il2CppMetadataTypeHandle handle)
  1096. {
  1097. return il2cpp::vm::GlobalMetadata::StructLayoutPack(handle);
  1098. }
  1099. bool il2cpp::vm::MetadataCache::StructLayoutSizeIsDefault(Il2CppMetadataTypeHandle handle)
  1100. {
  1101. return il2cpp::vm::GlobalMetadata::StructLayoutSizeIsDefault(handle);
  1102. }
  1103. std::pair<const char*, const char*> il2cpp::vm::MetadataCache::GetTypeNamespaceAndName(Il2CppMetadataTypeHandle handle)
  1104. {
  1105. return il2cpp::vm::GlobalMetadata::GetTypeNamespaceAndName(handle);
  1106. }
  1107. Il2CppMetadataTypeHandle il2cpp::vm::MetadataCache::GetNestedTypes(Il2CppClass *klass, void* *iter)
  1108. {
  1109. return GetNestedTypes(
  1110. klass->typeMetadataHandle,
  1111. iter
  1112. );
  1113. }
  1114. Il2CppMetadataTypeHandle il2cpp::vm::MetadataCache::GetNestedTypes(Il2CppMetadataTypeHandle handle, void** iter)
  1115. {
  1116. return il2cpp::vm::GlobalMetadata::GetNestedTypes(handle, iter);
  1117. }
  1118. Il2CppMetadataFieldInfo il2cpp::vm::MetadataCache::GetFieldInfo(const Il2CppClass* klass, TypeFieldIndex fieldIndex)
  1119. {
  1120. return il2cpp::vm::GlobalMetadata::GetFieldInfo(klass, fieldIndex);
  1121. }
  1122. Il2CppMetadataMethodInfo il2cpp::vm::MetadataCache::GetMethodInfo(const Il2CppClass* klass, TypeMethodIndex index)
  1123. {
  1124. return il2cpp::vm::GlobalMetadata::GetMethodInfo(klass, index);
  1125. }
  1126. Il2CppMetadataParameterInfo il2cpp::vm::MetadataCache::GetParameterInfo(const Il2CppClass* klass, Il2CppMetadataMethodDefinitionHandle handle, MethodParameterIndex paramIndex)
  1127. {
  1128. return il2cpp::vm::GlobalMetadata::GetParameterInfo(klass, handle, paramIndex);
  1129. }
  1130. Il2CppMetadataPropertyInfo il2cpp::vm::MetadataCache::GetPropertyInfo(const Il2CppClass* klass, TypePropertyIndex index)
  1131. {
  1132. return il2cpp::vm::GlobalMetadata::GetPropertyInfo(klass, index);
  1133. }
  1134. Il2CppMetadataEventInfo il2cpp::vm::MetadataCache::GetEventInfo(const Il2CppClass* klass, TypeEventIndex index)
  1135. {
  1136. return il2cpp::vm::GlobalMetadata::GetEventInfo(klass, index);
  1137. }
  1138. #if SUPPORT_METHOD_RETURN_TYPE_CUSTOM_ATTRIBUTE
  1139. uint32_t il2cpp::vm::MetadataCache::GetReturnParameterToken(Il2CppMetadataMethodDefinitionHandle handle)
  1140. {
  1141. return il2cpp::vm::GlobalMetadata::GetReturnParameterToken(handle);
  1142. }
  1143. #endif
  1144. uint32_t il2cpp::vm::MetadataCache::GetGenericContainerCount(Il2CppMetadataGenericContainerHandle handle)
  1145. {
  1146. return il2cpp::vm::GlobalMetadata::GetGenericContainerCount(handle);
  1147. }
  1148. void il2cpp::vm::MetadataCache::MakeGenericArgType(Il2CppMetadataGenericContainerHandle containerHandle, Il2CppMetadataGenericParameterHandle paramHandle, Il2CppType* arg)
  1149. {
  1150. return il2cpp::vm::GlobalMetadata::MakeGenericArgType(containerHandle, paramHandle, arg);
  1151. }
  1152. bool il2cpp::vm::MetadataCache::GetGenericContainerIsMethod(Il2CppMetadataGenericContainerHandle handle)
  1153. {
  1154. return il2cpp::vm::GlobalMetadata::GetGenericContainerIsMethod(handle);
  1155. }
  1156. int16_t il2cpp::vm::MetadataCache::GetGenericConstraintCount(Il2CppMetadataGenericParameterHandle handle)
  1157. {
  1158. return il2cpp::vm::GlobalMetadata::GetGenericConstraintCount(handle);
  1159. }
  1160. const char* il2cpp::vm::MetadataCache::GetGenericParameterName(Il2CppMetadataGenericParameterHandle handle)
  1161. {
  1162. return il2cpp::vm::GlobalMetadata::GetGenericParameterName(handle);
  1163. }
  1164. Il2CppGenericParameterInfo il2cpp::vm::MetadataCache::GetGenericParameterInfo(Il2CppMetadataGenericParameterHandle handle)
  1165. {
  1166. return il2cpp::vm::GlobalMetadata::GetGenericParameterInfo(handle);
  1167. }
  1168. uint16_t il2cpp::vm::MetadataCache::GetGenericParameterFlags(Il2CppMetadataGenericParameterHandle handle)
  1169. {
  1170. return il2cpp::vm::GlobalMetadata::GetGenericParameterFlags(handle);
  1171. }
  1172. const MethodInfo* il2cpp::vm::MetadataCache::GetMethodInfoFromCatchPoint(const Il2CppImage* image, const Il2CppCatchPoint* cp)
  1173. {
  1174. return il2cpp::vm::GlobalMetadata::GetMethodInfoFromCatchPoint(cp);
  1175. }
  1176. const MethodInfo* il2cpp::vm::MetadataCache::GetMethodInfoFromSequencePoint(const Il2CppImage* image, const Il2CppSequencePoint* seqPoint)
  1177. {
  1178. return il2cpp::vm::GlobalMetadata::GetMethodInfoFromSequencePoint(seqPoint);
  1179. }
  1180. Il2CppClass* il2cpp::vm::MetadataCache::GetTypeInfoFromTypeSourcePair(const Il2CppImage* image, const Il2CppTypeSourceFilePair* pair)
  1181. {
  1182. return il2cpp::vm::GlobalMetadata::GetTypeInfoFromTypeSourcePair(pair);
  1183. }
  1184. #if ENABLE_HMI_MODE || PLATFORM_WEIXINMINIGAME
  1185. bool il2cpp::vm::Il2CppGenericMethodTableItem::operator<(const Il2CppGenericMethodTableItem& other) const
  1186. {
  1187. if (method->methodDefinition != other.method->methodDefinition)
  1188. {
  1189. return method->methodDefinition < other.method->methodDefinition;
  1190. }
  1191. const Il2CppGenericContext& ctxa = method->context;
  1192. const Il2CppGenericContext& ctxb = other.method->context;
  1193. if (ctxa.class_inst != ctxb.class_inst)
  1194. return ctxa.class_inst < ctxb.class_inst;
  1195. return ctxa.method_inst < ctxb.method_inst;
  1196. }
  1197. bool il2cpp::vm::Il2CppGenericMethodTableItem::operator==(const Il2CppGenericMethodTableItem& other) const
  1198. {
  1199. if (method->methodDefinition != other.method->methodDefinition)
  1200. return false;
  1201. const Il2CppGenericContext& ctxa = method->context;
  1202. const Il2CppGenericContext& ctxb = other.method->context;
  1203. return ctxa.class_inst == ctxb.class_inst && ctxa.method_inst == ctxb.method_inst;
  1204. }
  1205. #endif