InterpreterModule.h 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. #pragma once
  2. #include "os/ThreadLocalValue.h"
  3. #include "../CommonDef.h"
  4. #include "MethodBridge.h"
  5. #include "Engine.h"
  6. #include "../metadata/Image.h"
  7. namespace hybridclr
  8. {
  9. namespace interpreter
  10. {
  11. class InterpreterModule
  12. {
  13. public:
  14. static void Initialize();
  15. static MachineState& GetCurrentThreadMachineState()
  16. {
  17. MachineState* state = nullptr;
  18. s_machineState.GetValue((void**)&state);
  19. if (!state)
  20. {
  21. state = new MachineState();
  22. s_machineState.SetValue(state);
  23. }
  24. return *state;
  25. }
  26. static void FreeThreadLocalMachineState()
  27. {
  28. MachineState* state = nullptr;
  29. s_machineState.GetValue((void**)&state);
  30. if (state)
  31. {
  32. delete state;
  33. s_machineState.SetValue(nullptr);
  34. }
  35. }
  36. static InterpMethodInfo* GetInterpMethodInfo(const MethodInfo* methodInfo);
  37. static Il2CppMethodPointer GetMethodPointer(const Il2CppMethodDefinition* method);
  38. static Il2CppMethodPointer GetMethodPointer(const MethodInfo* method);
  39. static Il2CppMethodPointer GetAdjustThunkMethodPointer(const Il2CppMethodDefinition* method);
  40. static Il2CppMethodPointer GetAdjustThunkMethodPointer(const MethodInfo* method);
  41. static Managed2NativeCallMethod GetManaged2NativeMethodPointer(const MethodInfo* method, bool forceStatic);
  42. static Managed2NativeCallMethod GetManaged2NativeMethodPointer(const metadata::ResolveStandAloneMethodSig& methodSig);
  43. static InvokerMethod GetMethodInvoker(const Il2CppMethodDefinition* method);
  44. static InvokerMethod GetMethodInvoker(const MethodInfo* method);
  45. static bool IsImplementsByInterpreter(const MethodInfo* method);
  46. static bool HasImplementCallNative2Managed(const MethodInfo* method)
  47. {
  48. IL2CPP_ASSERT(method->methodPointerCallByInterp != NotSupportAdjustorThunk);
  49. return method->methodPointerCallByInterp != (Il2CppMethodPointer)NotSupportNative2Managed;
  50. }
  51. static bool HasImplementCallVirtualNative2Managed(const MethodInfo* method)
  52. {
  53. IL2CPP_ASSERT(method->virtualMethodPointerCallByInterp != NotSupportNative2Managed);
  54. return method->virtualMethodPointerCallByInterp != (Il2CppMethodPointer)NotSupportAdjustorThunk;
  55. }
  56. static void Managed2NativeCallByReflectionInvoke(const MethodInfo* method, uint16_t* argVarIndexs, StackObject* localVarBase, void* ret);
  57. static void NotSupportNative2Managed();
  58. static void NotSupportAdjustorThunk();
  59. static Il2CppMethodPointer GetReversePInvokeWrapper(const Il2CppImage* image, const MethodInfo* method, Il2CppCallConvention callConvention);
  60. static const MethodInfo* GetMethodInfoByReversePInvokeWrapperIndex(int32_t index);
  61. static const MethodInfo* GetMethodInfoByReversePInvokeWrapperMethodPointer(Il2CppMethodPointer methodPointer);
  62. static int32_t GetWrapperIndexByReversePInvokeWrapperMethodPointer(Il2CppMethodPointer methodPointer);
  63. static const char* GetValueTypeSignature(const char* fullName);
  64. private:
  65. static il2cpp::os::ThreadLocalValue s_machineState;
  66. };
  67. }
  68. }