MethodBridge.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. #pragma once
  2. #include "../CommonDef.h"
  3. #include "InterpreterDefs.h"
  4. namespace hybridclr
  5. {
  6. namespace interpreter
  7. {
  8. union StackObject;
  9. typedef void (*Managed2NativeCallMethod)(const MethodInfo* method, uint16_t* argVarIndexs, StackObject* localVarBase, void* ret);
  10. typedef void (*NativeClassCtor0)(Il2CppObject* obj, const MethodInfo* method);
  11. struct Managed2NativeMethodInfo
  12. {
  13. const char* signature;
  14. Managed2NativeCallMethod method;
  15. };
  16. struct Native2ManagedMethodInfo
  17. {
  18. const char* signature;
  19. Il2CppMethodPointer method;
  20. };
  21. struct NativeAdjustThunkMethodInfo
  22. {
  23. const char* signature;
  24. Il2CppMethodPointer method;
  25. };
  26. struct FullName2Signature
  27. {
  28. const char* fullName;
  29. const char* signature;
  30. };
  31. extern const Managed2NativeMethodInfo g_managed2nativeStub[];
  32. extern const Native2ManagedMethodInfo g_native2managedStub[];
  33. extern const NativeAdjustThunkMethodInfo g_adjustThunkStub[];
  34. extern const FullName2Signature g_fullName2SignatureStub[];
  35. struct ReversePInvokeInfo
  36. {
  37. int32_t index;
  38. Il2CppMethodPointer methodPointer;
  39. const MethodInfo* methodInfo;
  40. };
  41. struct ReversePInvokeMethodData
  42. {
  43. const char* methodSig;
  44. Il2CppMethodPointer methodPointer;
  45. };
  46. extern const ReversePInvokeMethodData g_reversePInvokeMethodStub[];
  47. typedef void (*PInvokeMethodPointer)(intptr_t method, uint16_t* argVarIndexs, StackObject* localVarBase, void* ret);
  48. struct PInvokeMethodData
  49. {
  50. const char* methodSig;
  51. PInvokeMethodPointer methodPointer;
  52. };
  53. extern const PInvokeMethodData g_PInvokeMethodStub[];
  54. void ConvertInvokeArgs(StackObject* resultArgs, const MethodInfo* method, MethodArgDesc* argDescs, void** args);
  55. bool ComputeSignature(const MethodInfo* method, bool call, char* sigBuf, size_t bufferSize);
  56. bool ComputeSignature(const Il2CppMethodDefinition* method, bool call, char* sigBuf, size_t bufferSize);
  57. bool ComputeSignature(const Il2CppType* ret, const il2cpp::utils::dynamic_array<const Il2CppType*>& params, bool instanceCall, char* sigBuf, size_t bufferSize);
  58. template<typename T> uint64_t N2MAsUint64ValueOrAddress(T& value)
  59. {
  60. return sizeof(T) <= 8 ? *(uint64_t*)&value : (uint64_t)&value;
  61. }
  62. template<typename T> T& M2NFromValueOrAddress(void* value)
  63. {
  64. //return sizeof(T) <= 8 ? *(T*)value : **(T**)value;
  65. return *(T*)value;
  66. }
  67. }
  68. }