InterpreterDefs.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. #pragma once
  2. #include "../CommonDef.h"
  3. #include "../metadata/MetadataDef.h"
  4. namespace hybridclr
  5. {
  6. namespace interpreter
  7. {
  8. // from obj or arg
  9. enum class LocationDataType
  10. {
  11. I1,
  12. U1,
  13. I2,
  14. U2,
  15. U8,
  16. S_N, // struct size = 3,5,6,7, > 8, size is described by stackObjectSize
  17. };
  18. union StackObject
  19. {
  20. uint64_t __u64;
  21. void* ptr; // can't adjust position. will raise native_invoke init args bugs.
  22. bool b;
  23. int8_t i8;
  24. uint8_t u8;
  25. int16_t i16;
  26. uint16_t u16;
  27. int32_t i32;
  28. uint32_t u32;
  29. int64_t i64;
  30. uint64_t u64;
  31. float f4;
  32. double f8;
  33. Il2CppObject* obj;
  34. Il2CppString* str;
  35. Il2CppObject** ptrObj;
  36. };
  37. static_assert(sizeof(StackObject) == 8, "requrie 8 bytes");
  38. enum class ExceptionFlowType
  39. {
  40. Exception,
  41. Catch,
  42. Leave,
  43. };
  44. struct InterpMethodInfo;
  45. struct ExceptionFlowInfo
  46. {
  47. ExceptionFlowType exFlowType;
  48. int32_t throwOffset;
  49. Il2CppException* ex;
  50. int32_t nextExClauseIndex;
  51. int32_t leaveTarget;
  52. };
  53. struct InterpFrame
  54. {
  55. const InterpMethodInfo* method;
  56. StackObject* stackBasePtr;
  57. int32_t oldStackTop;
  58. void* ret;
  59. byte* ip;
  60. ExceptionFlowInfo* exFlowBase;
  61. int32_t exFlowCount;
  62. int32_t exFlowCapaticy;
  63. int32_t oldLocalPoolBottomIdx;
  64. ExceptionFlowInfo* GetCurExFlow() const
  65. {
  66. return exFlowCount > 0 ? exFlowBase + exFlowCount - 1 : nullptr;
  67. }
  68. ExceptionFlowInfo* GetPrevExFlow() const
  69. {
  70. return exFlowCount > 1 ? exFlowBase + exFlowCount - 2 : nullptr;
  71. }
  72. };
  73. struct InterpExceptionClause
  74. {
  75. metadata::CorILExceptionClauseType flags;
  76. int32_t tryBeginOffset;
  77. int32_t tryEndOffset;
  78. int32_t handlerBeginOffset;
  79. int32_t handlerEndOffset;
  80. int32_t filterBeginOffset;
  81. Il2CppClass* exKlass;
  82. };
  83. struct MethodArgDesc
  84. {
  85. LocationDataType type;
  86. uint32_t stackObjectSize;
  87. bool passbyValWhenInvoke;
  88. };
  89. struct InterpMethodInfo
  90. {
  91. const MethodInfo* method;
  92. MethodArgDesc* args;
  93. uint32_t argCount;
  94. uint32_t argStackObjectSize;
  95. byte* codes;
  96. uint32_t codeLength;
  97. uint32_t maxStackSize; // args + locals + evalstack size
  98. uint32_t localVarBaseOffset;
  99. uint32_t evalStackBaseOffset;
  100. uint32_t localStackSize; // args + locals StackObject size
  101. std::vector<uint64_t> resolveDatas;
  102. std::vector<InterpExceptionClause*> exClauses;
  103. bool initLocals;
  104. };
  105. }
  106. }