MetadataCache.h 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. #pragma once
  2. #include <stdint.h>
  3. #include "il2cpp-config.h"
  4. #include "Assembly.h"
  5. #include "metadata/Il2CppTypeVector.h"
  6. #include "il2cpp-class-internals.h"
  7. #include "utils/dynamic_array.h"
  8. #include "os/Mutex.h"
  9. struct MethodInfo;
  10. struct Il2CppClass;
  11. struct Il2CppGenericContainer;
  12. struct Il2CppGenericContext;
  13. struct Il2CppGenericInst;
  14. struct Il2CppGenericMethod;
  15. struct Il2CppType;
  16. struct Il2CppString;
  17. namespace il2cpp
  18. {
  19. namespace vm
  20. {
  21. struct RGCTXCollection
  22. {
  23. int32_t count;
  24. const Il2CppRGCTXDefinition* items;
  25. };
  26. class LIBIL2CPP_CODEGEN_API MetadataCache
  27. {
  28. public:
  29. static void Register(const Il2CppCodeRegistration * const codeRegistration, const Il2CppMetadataRegistration * const metadataRegistration, const Il2CppCodeGenOptions* const codeGenOptions);
  30. static bool Initialize();
  31. static void InitializeGCSafe();
  32. static void InitializeAllMethodMetadata();
  33. static Il2CppClass* GetGenericInstanceType(Il2CppClass* genericTypeDefinition, const il2cpp::metadata::Il2CppTypeVector& genericArgumentTypes);
  34. static const MethodInfo* GetGenericInstanceMethod(const MethodInfo* genericMethodDefinition, const Il2CppGenericContext* context);
  35. static const MethodInfo* GetGenericInstanceMethod(const MethodInfo* genericMethodDefinition, const il2cpp::metadata::Il2CppTypeVector& genericArgumentTypes);
  36. static const Il2CppGenericContext* GetMethodGenericContext(const MethodInfo* method);
  37. static const Il2CppGenericContainer* GetMethodGenericContainer(const MethodInfo* method);
  38. static const MethodInfo* GetGenericMethodDefinition(const MethodInfo* method);
  39. static Il2CppClass* GetPointerType(Il2CppClass* type);
  40. static Il2CppClass* GetWindowsRuntimeClass(const char* fullName);
  41. static const char* GetWindowsRuntimeClassName(const Il2CppClass* klass);
  42. static Il2CppMethodPointer GetWindowsRuntimeFactoryCreationFunction(const char* fullName);
  43. static Il2CppClass* GetClassForGuid(const Il2CppGuid* guid);
  44. static void AddPointerType(Il2CppClass* type, Il2CppClass* pointerType);
  45. static const Il2CppGenericInst* GetGenericInst(const Il2CppType* const* types, uint32_t typeCount);
  46. static const Il2CppGenericInst* GetGenericInst(const il2cpp::metadata::Il2CppTypeVector& types);
  47. static const Il2CppGenericMethod* GetGenericMethod(const MethodInfo* methodDefinition, const Il2CppGenericInst* classInst, const Il2CppGenericInst* methodInst);
  48. static InvokerMethod GetInvokerMethodPointer(const MethodInfo* methodDefinition, const Il2CppGenericContext* context);
  49. static Il2CppMethodPointer GetMethodPointer(const MethodInfo* methodDefinition, const Il2CppGenericContext* context);
  50. static Il2CppClass* GetTypeInfoFromTypeIndex(TypeIndex index);
  51. static const Il2CppType* GetIl2CppTypeFromIndex(TypeIndex index);
  52. static const MethodInfo* GetMethodInfoFromIndex(EncodedMethodIndex index);
  53. static const Il2CppGenericMethod* GetGenericMethodFromIndex(GenericMethodIndex index);
  54. static Il2CppString* GetStringLiteralFromIndex(StringLiteralIndex index);
  55. static const char* GetStringFromIndex(StringIndex index);
  56. static FieldInfo* GetFieldInfoFromIndex(EncodedMethodIndex index);
  57. static void InitializeMethodMetadata(uint32_t index);
  58. static Il2CppMethodPointer GetMethodPointer(const Il2CppImage* image, uint32_t token);
  59. static InvokerMethod GetMethodInvoker(const Il2CppImage* image, uint32_t token);
  60. static const Il2CppInteropData* GetInteropDataForType(const Il2CppType* type);
  61. static Il2CppMethodPointer GetReversePInvokeWrapper(const Il2CppImage* image, const MethodInfo* method);
  62. static Il2CppMethodPointer GetUnresolvedVirtualCallStub(const MethodInfo* method);
  63. static const Il2CppAssembly* GetAssemblyFromIndex(AssemblyIndex index);
  64. static const Il2CppAssembly* GetAssemblyByName(const char* nameToFind);
  65. static Il2CppImage* GetImageFromIndex(ImageIndex index);
  66. static Il2CppClass* GetTypeInfoFromTypeDefinitionIndex(TypeDefinitionIndex index);
  67. static const Il2CppTypeDefinition* GetTypeDefinitionFromIndex(TypeDefinitionIndex index);
  68. static TypeDefinitionIndex GetExportedTypeFromIndex(TypeDefinitionIndex index);
  69. static const Il2CppGenericContainer* GetGenericContainerFromIndex(GenericContainerIndex index);
  70. static const Il2CppGenericParameter* GetGenericParameterFromIndex(GenericParameterIndex index);
  71. static const Il2CppType* GetGenericParameterConstraintFromIndex(GenericParameterConstraintIndex index);
  72. static Il2CppClass* GetNestedTypeFromIndex(NestedTypeIndex index);
  73. static const Il2CppType* GetInterfaceFromIndex(InterfacesIndex index);
  74. static EncodedMethodIndex GetVTableMethodFromIndex(VTableIndex index);
  75. static Il2CppInterfaceOffsetPair GetInterfaceOffsetIndex(InterfaceOffsetIndex index);
  76. static RGCTXCollection GetRGCTXs(const Il2CppImage* image, uint32_t token);
  77. static const Il2CppEventDefinition* GetEventDefinitionFromIndex(EventIndex index);
  78. static const Il2CppFieldDefinition* GetFieldDefinitionFromIndex(FieldIndex index);
  79. static const Il2CppFieldDefaultValue* GetFieldDefaultValueFromIndex(FieldIndex index);
  80. static const uint8_t* GetFieldDefaultValueDataFromIndex(FieldIndex index);
  81. static const Il2CppFieldDefaultValue* GetFieldDefaultValueForField(const FieldInfo* field);
  82. static const uint8_t* GetParameterDefaultValueDataFromIndex(ParameterIndex index);
  83. static const Il2CppParameterDefaultValue* GetParameterDefaultValueForParameter(const MethodInfo* method, const ParameterInfo* parameter);
  84. static int GetFieldMarshaledSizeForField(const FieldInfo* field);
  85. static const Il2CppMethodDefinition* GetMethodDefinitionFromIndex(MethodIndex index);
  86. static const MethodInfo* GetMethodInfoFromMethodDefinitionIndex(MethodIndex index);
  87. static const Il2CppPropertyDefinition* GetPropertyDefinitionFromIndex(PropertyIndex index);
  88. static const Il2CppParameterDefinition* GetParameterDefinitionFromIndex(ParameterIndex index);
  89. // returns the compiler computer field offset for type definition fields
  90. static int32_t GetFieldOffsetFromIndexLocked(TypeIndex typeIndex, int32_t fieldIndexInType, FieldInfo* field, const il2cpp::os::FastAutoLock& lock);
  91. static int32_t GetThreadLocalStaticOffsetForField(FieldInfo* field);
  92. static void AddThreadLocalStaticOffsetForFieldLocked(FieldInfo* field, int32_t offset, const il2cpp::os::FastAutoLock& lock);
  93. static int32_t GetReferenceAssemblyIndexIntoAssemblyTable(int32_t referencedAssemblyTableIndex);
  94. static const TypeDefinitionIndex GetIndexForTypeDefinition(const Il2CppClass* typeDefinition);
  95. static const GenericParameterIndex GetIndexForGenericParameter(const Il2CppGenericParameter* genericParameter);
  96. static const MethodIndex GetIndexForMethodDefinition(const MethodInfo* method);
  97. static CustomAttributeIndex GetCustomAttributeIndex(const Il2CppImage* image, uint32_t token);
  98. static CustomAttributesCache* GenerateCustomAttributesCache(CustomAttributeIndex index);
  99. static CustomAttributesCache* GenerateCustomAttributesCache(const Il2CppImage* image, uint32_t token);
  100. static bool HasAttribute(CustomAttributeIndex index, Il2CppClass* attribute);
  101. static bool HasAttribute(const Il2CppImage* image, uint32_t token, Il2CppClass* attribute);
  102. typedef void(*WalkTypesCallback)(Il2CppClass* type, void* context);
  103. static void WalkPointerTypes(WalkTypesCallback callback, void* context);
  104. private:
  105. static void InitializeUnresolvedSignatureTable();
  106. static void InitializeStringLiteralTable();
  107. static void InitializeGenericMethodTable();
  108. static void InitializeWindowsRuntimeTypeNamesTables();
  109. static void InitializeGuidToClassTable();
  110. static void IntializeMethodMetadataRange(uint32_t start, uint32_t count, const utils::dynamic_array<Il2CppMetadataUsage>& expectedUsages);
  111. };
  112. } // namespace vm
  113. } // namespace il2cpp