GlobalMetadata.h 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. #pragma once
  2. #include <stdint.h>
  3. #include "Assembly.h"
  4. #include "MetadataCache.h"
  5. #include "StackTrace.h"
  6. #include "il2cpp-class-internals.h"
  7. #include "il2cpp-config.h"
  8. #include "metadata/CustomAttributeCreator.h"
  9. #include "os/Mutex.h"
  10. #include "utils/dynamic_array.h"
  11. #include "vm-utils/MethodDefinitionKey.h"
  12. struct MethodInfo;
  13. struct Il2CppClass;
  14. struct Il2CppGenericContext;
  15. struct Il2CppGenericInst;
  16. struct Il2CppGenericMethod;
  17. struct Il2CppType;
  18. struct Il2CppString;
  19. namespace il2cpp
  20. {
  21. namespace vm
  22. {
  23. class GlobalMetadata
  24. {
  25. public:
  26. static void Register(const Il2CppCodeRegistration* const codeRegistration, const Il2CppMetadataRegistration* const metadataRegistration, const Il2CppCodeGenOptions* const codeGenOptions);
  27. static bool Initialize(int32_t* imagesCount, int32_t* assembliesCount);
  28. static void InitializeAllMethodMetadata();
  29. static void* InitializeRuntimeMetadata(uintptr_t* metadataPointer, bool throwOnError);
  30. static void InitializeStringLiteralTable();
  31. static void InitializeWindowsRuntimeTypeNamesTables(WindowsRuntimeTypeNameToClassMap& windowsRuntimeTypeNameToClassMap, ClassToWindowsRuntimeTypeNameMap& classToWindowsRuntimeTypeNameMap);
  32. static void InitializeUnresolvedSignatureTable(Il2CppUnresolvedSignatureMap& unresolvedSignatureMap);
  33. static void InitializeGenericMethodTable(Il2CppMethodTableMap& methodTableMap);
  34. static void BuildIl2CppImage(Il2CppImage* image, ImageIndex imageIndex, AssemblyIndex* imageAssemblyIndex);
  35. static void BuildIl2CppAssembly(Il2CppAssembly* assembly, AssemblyIndex assemblyIndex, ImageIndex* assemblyImageIndex);
  36. static void Clear();
  37. static const MethodInfo* GetAssemblyEntryPoint(const Il2CppImage* image);
  38. static Il2CppMetadataTypeHandle GetAssemblyTypeHandle(const Il2CppImage* image, AssemblyTypeIndex index);
  39. static const Il2CppAssembly* GetReferencedAssembly(const Il2CppAssembly* assembly, int32_t referencedAssemblyTableIndex, const Il2CppAssembly assembliesTable[], int assembliesCount);
  40. static Il2CppMetadataTypeHandle GetAssemblyExportedTypeHandle(const Il2CppImage* image, AssemblyExportedTypeIndex index);
  41. static Il2CppClass* GetTypeInfoFromType(const Il2CppType* type);
  42. static Il2CppClass* GetTypeInfoFromTypeDefinitionIndex(TypeDefinitionIndex index);
  43. static Il2CppClass* GetTypeInfoFromHandle(Il2CppMetadataTypeHandle handle);
  44. static const Il2CppType* GetInterfaceFromOffset(const Il2CppClass* klass, TypeInterfaceIndex offset);
  45. static Il2CppInterfaceOffsetInfo GetInterfaceOffsetInfo(const Il2CppClass* klass, TypeInterfaceOffsetIndex index);
  46. static Il2CppMetadataTypeHandle GetTypeHandleFromIndex(TypeDefinitionIndex typeIndex);
  47. static Il2CppMetadataTypeHandle GetTypeHandleFromType(const Il2CppType* type);
  48. static bool TypeIsNested(Il2CppMetadataTypeHandle handle);
  49. static bool TypeIsValueType(Il2CppMetadataTypeHandle handle);
  50. static bool StructLayoutPackIsDefault(Il2CppMetadataTypeHandle handle);
  51. static int32_t StructLayoutPack(Il2CppMetadataTypeHandle handle);
  52. static bool StructLayoutSizeIsDefault(Il2CppMetadataTypeHandle handle);
  53. static std::pair<const char*, const char*> GetTypeNamespaceAndName(Il2CppMetadataTypeHandle handle);
  54. static Il2CppClass* GetNestedTypeFromOffset(const Il2CppClass* klass, TypeNestedTypeIndex offset);
  55. static Il2CppMetadataTypeHandle GetNestedTypes(Il2CppMetadataTypeHandle handle, void** iter);
  56. static Il2CppMetadataCustomAttributeHandle GetCustomAttributeTypeToken(const Il2CppImage* image, uint32_t token);
  57. static il2cpp::metadata::CustomAttributeDataReader GetCustomAttributeDataReader(const Il2CppImage* image, uint32_t token);
  58. static il2cpp::metadata::CustomAttributeDataReader GetCustomAttributeDataReader(Il2CppMetadataCustomAttributeHandle handle);
  59. static const MethodInfo* GetMethodInfoFromMethodHandle(Il2CppMetadataMethodDefinitionHandle handle);
  60. static const MethodInfo* GetMethodInfoFromVTableSlot(const Il2CppClass* klass, int32_t vTableSlot);
  61. static const uint8_t* GetParameterDefaultValue(const MethodInfo* method, int32_t parameterPosition, const Il2CppType** type, bool* isExplicitySetNullDefaultValue);
  62. static const uint8_t* GetFieldDefaultValue(const FieldInfo* field, const Il2CppType** type);
  63. static uint32_t GetFieldOffset(const Il2CppClass* klass, int32_t fieldIndexInType, FieldInfo* field);
  64. static int GetFieldMarshaledSizeForField(const FieldInfo* field);
  65. static Il2CppMetadataFieldInfo GetFieldInfo(const Il2CppClass* klass, TypeFieldIndex index);
  66. static Il2CppMetadataMethodInfo GetMethodInfo(const Il2CppClass* klass, TypeMethodIndex index);
  67. static Il2CppMetadataParameterInfo GetParameterInfo(const Il2CppClass* klass, Il2CppMetadataMethodDefinitionHandle handle, MethodParameterIndex index);
  68. static Il2CppMetadataPropertyInfo GetPropertyInfo(const Il2CppClass* klass, TypePropertyIndex index);
  69. static Il2CppMetadataEventInfo GetEventInfo(const Il2CppClass* klass, TypeEventIndex index);
  70. static Il2CppMetadataGenericContainerHandle GetGenericContainerFromGenericClass(const Il2CppGenericClass* genericClass);
  71. static Il2CppMetadataGenericContainerHandle GetGenericContainerFromMethod(Il2CppMetadataMethodDefinitionHandle handle);
  72. static Il2CppMetadataGenericParameterHandle GetGenericParameterFromType(const Il2CppType* type);
  73. static const MethodInfo* GetGenericInstanceMethod(const MethodInfo* genericMethodDefinition, const Il2CppGenericContext* context);
  74. static const Il2CppType* GetTypeFromRgctxDefinition(const Il2CppRGCTXDefinition* rgctxDef);
  75. static const Il2CppGenericMethod* GetGenericMethodFromRgctxDefinition(const Il2CppRGCTXDefinition* rgctxDef);
  76. static std::pair<const Il2CppType*, const MethodInfo*> GetConstrainedCallFromRgctxDefinition(const Il2CppRGCTXDefinition* rgctxDef);
  77. static Il2CppClass* GetContainerDeclaringType(Il2CppMetadataGenericContainerHandle handle);
  78. static Il2CppClass* GetParameterDeclaringType(Il2CppMetadataGenericParameterHandle handle);
  79. static const MethodInfo* GetParameterDeclaringMethod(Il2CppMetadataGenericParameterHandle handle);
  80. static Il2CppMetadataGenericParameterHandle GetGenericParameterFromIndex(Il2CppMetadataGenericContainerHandle handle, GenericContainerParameterIndex index);
  81. static const Il2CppType* GetGenericParameterConstraintFromIndex(Il2CppMetadataGenericParameterHandle handle, GenericParameterConstraintIndex index);
  82. static void MakeGenericArgType(Il2CppMetadataGenericContainerHandle containerHandle, Il2CppMetadataGenericParameterHandle paramHandle, Il2CppType* arg);
  83. static uint32_t GetGenericContainerCount(Il2CppMetadataGenericContainerHandle handle);
  84. static bool GetGenericContainerIsMethod(Il2CppMetadataGenericContainerHandle handle);
  85. static const char* GetGenericParameterName(Il2CppMetadataGenericParameterHandle handle);
  86. static Il2CppGenericParameterInfo GetGenericParameterInfo(Il2CppMetadataGenericParameterHandle handle);
  87. static uint16_t GetGenericParameterFlags(Il2CppMetadataGenericParameterHandle handle);
  88. static int16_t GetGenericConstraintCount(Il2CppMetadataGenericParameterHandle handle);
  89. static const Il2CppGenericMethod* GetGenericMethodFromTokenMethodTuple(const Il2CppTokenIndexMethodTuple* tuple);
  90. static const MethodInfo* GetMethodInfoFromCatchPoint(const Il2CppCatchPoint* cp);
  91. static const MethodInfo* GetMethodInfoFromSequencePoint(const Il2CppSequencePoint* cp);
  92. static Il2CppClass* GetTypeInfoFromTypeSourcePair(const Il2CppTypeSourceFilePair* pair);
  93. static Il2CppClass* GetTypeInfoFromTypeIndex(TypeIndex index, bool throwOnError = true);
  94. static const Il2CppType* GetIl2CppTypeFromIndex(TypeIndex index);
  95. static const MethodInfo* GetMethodInfoFromMethodDefinitionIndex(MethodIndex index);
  96. template<typename T>
  97. static inline bool IsRuntimeMetadataInitialized(T item)
  98. {
  99. // Runtime metadata items are initialized to an encoded token with the low bit set
  100. // on startup and when initialized are a pointer to an runtime metadata item
  101. // So we can rely on pointer alignment being > 1 on our supported platforms
  102. return !((uintptr_t)item & 1);
  103. }
  104. #if IL2CPP_ENABLE_NATIVE_STACKTRACES
  105. static void GetAllManagedMethods(std::vector<MethodDefinitionKey>& managedMethods);
  106. #endif
  107. };
  108. }
  109. }