MemoryInformation.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. #pragma once
  2. #include "il2cpp-config.h"
  3. struct Il2CppMetadataField
  4. {
  5. uint32_t offset;
  6. uint32_t typeIndex;
  7. const char* name;
  8. bool isStatic;
  9. };
  10. enum Il2CppMetadataTypeFlags
  11. {
  12. kNone = 0,
  13. kValueType = 1 << 0,
  14. kArray = 1 << 1,
  15. kArrayRankMask = 0xFFFF0000
  16. };
  17. struct Il2CppMetadataType
  18. {
  19. Il2CppMetadataTypeFlags flags; // If it's an array, rank is encoded in the upper 2 bytes
  20. Il2CppMetadataField* fields;
  21. uint32_t fieldCount;
  22. uint32_t staticsSize;
  23. uint8_t* statics;
  24. uint32_t baseOrElementTypeIndex;
  25. char* name;
  26. const char* assemblyName;
  27. uint64_t typeInfoAddress;
  28. uint32_t size;
  29. };
  30. struct Il2CppMetadataSnapshot
  31. {
  32. uint32_t typeCount;
  33. Il2CppMetadataType* types;
  34. };
  35. struct Il2CppManagedMemorySection
  36. {
  37. uint64_t sectionStartAddress;
  38. uint32_t sectionSize;
  39. uint8_t* sectionBytes;
  40. };
  41. struct Il2CppManagedHeap
  42. {
  43. uint32_t sectionCount;
  44. Il2CppManagedMemorySection* sections;
  45. };
  46. struct Il2CppStacks
  47. {
  48. uint32_t stackCount;
  49. Il2CppManagedMemorySection* stacks;
  50. };
  51. struct NativeObject
  52. {
  53. uint32_t gcHandleIndex;
  54. uint32_t size;
  55. uint32_t instanceId;
  56. uint32_t classId;
  57. uint32_t referencedNativeObjectIndicesCount;
  58. uint32_t* referencedNativeObjectIndices;
  59. };
  60. struct Il2CppGCHandles
  61. {
  62. uint32_t trackedObjectCount;
  63. uint64_t* pointersToObjects;
  64. };
  65. struct Il2CppRuntimeInformation
  66. {
  67. uint32_t pointerSize;
  68. uint32_t objectHeaderSize;
  69. uint32_t arrayHeaderSize;
  70. uint32_t arrayBoundsOffsetInHeader;
  71. uint32_t arraySizeOffsetInHeader;
  72. uint32_t allocationGranularity;
  73. };
  74. struct Il2CppManagedMemorySnapshot
  75. {
  76. Il2CppManagedHeap heap;
  77. Il2CppStacks stacks;
  78. Il2CppMetadataSnapshot metadata;
  79. Il2CppGCHandles gcHandles;
  80. Il2CppRuntimeInformation runtimeInformation;
  81. void* additionalUserInformation;
  82. };
  83. namespace il2cpp
  84. {
  85. namespace vm
  86. {
  87. namespace MemoryInformation
  88. {
  89. typedef void(*ClassReportFunc)(Il2CppClass* klass, void* context);
  90. typedef void(*DataReportFunc)(void* data, void* context);
  91. struct IterationContext
  92. {
  93. DataReportFunc callback;
  94. void* userData;
  95. };
  96. void ReportIL2CppClasses(ClassReportFunc callback, void* context);
  97. void ReportGcHeapSection(void* context, void* start, void* end);
  98. void ReportGcHandleTarget(Il2CppObject* obj, void* context);
  99. Il2CppManagedMemorySnapshot* CaptureManagedMemorySnapshot();
  100. void FreeCapturedManagedMemorySnapshot(Il2CppManagedMemorySnapshot* snapshot);
  101. }
  102. }
  103. }