MonoMethod.cs 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. #if ENABLE_MONO && (DEVELOPMENT_BUILD || UNITY_EDITOR)
  2. using System;
  3. using System.Runtime.InteropServices;
  4. namespace SingularityGroup.HotReload.Interop {
  5. //see _MonoMethod struct in class-internals.h
  6. [StructLayout(LayoutKind.Explicit, CharSet = CharSet.Auto, Size = 8 + sizeof(long) * 3 + 4)]
  7. internal unsafe struct MonoMethod64 {
  8. [FieldOffset(0)]
  9. public MethodAttributes flags;
  10. [FieldOffset(2)]
  11. public MethodImplAttributes iflags;
  12. [FieldOffset(4)]
  13. public uint token;
  14. [FieldOffset(8)]
  15. public void* klass;
  16. [FieldOffset(8 + sizeof(long))]
  17. public void* signature;
  18. [FieldOffset(8 + sizeof(long) * 2)]
  19. public char* name;
  20. /* this is used by the inlining algorithm */
  21. [FieldOffset(8 + sizeof(long) * 3)]
  22. public MonoMethodFlags monoMethodFlags;
  23. [FieldOffset(8 + sizeof(long) * 3 + 2)]
  24. public short slot;
  25. }
  26. [StructLayout(LayoutKind.Explicit, CharSet = CharSet.Auto, Size = 8 + sizeof(int) * 3 + 4)]
  27. internal unsafe struct MonoMethod32 {
  28. [FieldOffset(0)]
  29. public MethodAttributes flags;
  30. [FieldOffset(2)]
  31. public MethodImplAttributes iflags;
  32. [FieldOffset(4)]
  33. public uint token;
  34. [FieldOffset(8)]
  35. public void* klass;
  36. [FieldOffset(8 + sizeof(int))]
  37. public void* signature;
  38. [FieldOffset(8 + sizeof(int) * 2)]
  39. public char* name;
  40. /* this is used by the inlining algorithm */
  41. [FieldOffset(8 + sizeof(int) * 3)]
  42. public MonoMethodFlags monoMethodFlags;
  43. [FieldOffset(8 + sizeof(int) * 3 + 2)]
  44. public short slot;
  45. }
  46. //Corresponds to the bitflags of the _MonoMethod struct
  47. [Flags]
  48. internal enum MonoMethodFlags : ushort {
  49. inline_info = 1 << 0, //:1
  50. inline_failure = 1 << 1, //:1
  51. wrapper_type = 1 << 2, //:5
  52. string_ctor = 1 << 7, //:1
  53. save_lmf = 1 << 8, //:1
  54. dynamic = 1 << 9, //:1 /* created & destroyed during runtime */
  55. sre_method = 1 << 10, //:1 /* created at runtime using Reflection.Emit */
  56. is_generic = 1 << 11, //:1 /* whenever this is a generic method definition */
  57. is_inflated = 1 << 12, //:1 /* whether we're a MonoMethodInflated */
  58. skip_visibility = 1 << 13, //:1 /* whenever to skip JIT visibility checks */
  59. verification_success = 1 << 14, //:1 /* whether this method has been verified successfully.*/
  60. }
  61. [Flags]
  62. internal enum MethodImplAttributes : ushort {
  63. /// <summary><para>Specifies that the method implementation is in Microsoft intermediate language (MSIL).</para></summary>
  64. IL = 0,
  65. /// <summary><para>Specifies that the method is implemented in managed code. </para></summary>
  66. Managed = 0,
  67. /// <summary><para>Specifies that the method implementation is native.</para></summary>
  68. Native = 1,
  69. /// <summary><para>Specifies that the method implementation is in Optimized Intermediate Language (OPTIL).</para></summary>
  70. OPTIL = 2,
  71. /// <summary><para>Specifies flags about code type.</para></summary>
  72. CodeTypeMask = 3,
  73. /// <summary><para>Specifies that the method implementation is provided by the runtime.</para></summary>
  74. Runtime = 3,
  75. /// <summary><para>Specifies whether the method is implemented in managed or unmanaged code.</para></summary>
  76. ManagedMask = 4,
  77. /// <summary><para>Specifies that the method is implemented in unmanaged code.</para></summary>
  78. Unmanaged = 4,
  79. /// <summary><para>Specifies that the method cannot be inlined.</para></summary>
  80. NoInlining = 8,
  81. /// <summary><para>Specifies that the method is not defined.</para></summary>
  82. ForwardRef = 16, // 0x00000010
  83. /// <summary><para>Specifies that the method is single-threaded through the body. Static methods (Shared in Visual Basic) lock on the type, whereas instance methods lock on the instance. You can also use the C# <format type="text/html"><a href="656DA1A4-707E-4EF6-9C6E-6D13B646AF42">lock statement</a></format> or the Visual Basic <format type="text/html"><a href="14501703-298f-4d43-b139-c4b6366af176">SyncLock statement</a></format> for this purpose. </para></summary>
  84. Synchronized = 32, // 0x00000020
  85. /// <summary><para>Specifies that the method is not optimized by the just-in-time (JIT) compiler or by native code generation (see <format type="text/html"><a href="44bf97aa-a9a4-4eba-9a0d-cfaa6fc53a66">Ngen.exe</a></format>) when debugging possible code generation problems.</para></summary>
  86. NoOptimization = 64, // 0x00000040
  87. /// <summary><para>Specifies that the method signature is exported exactly as declared.</para></summary>
  88. PreserveSig = 128, // 0x00000080
  89. /// <summary><para>Specifies that the method should be inlined wherever possible.</para></summary>
  90. AggressiveInlining = 256, // 0x00000100
  91. /// <summary><para>Specifies an internal call.</para></summary>
  92. InternalCall = 4096, // 0x00001000
  93. /// <summary><para>Specifies a range check value.</para></summary>
  94. MaxMethodImplVal = 65535, // 0x0000FFFF
  95. }
  96. /// <summary><para>Specifies flags for method attributes. These flags are defined in the corhdr.h file.</para></summary>
  97. [Flags]
  98. internal enum MethodAttributes : ushort {
  99. /// <summary><para>Retrieves accessibility information.</para></summary>
  100. MemberAccessMask = 7,
  101. /// <summary><para>Indicates that the member cannot be referenced.</para></summary>
  102. PrivateScope = 0,
  103. /// <summary><para>Indicates that the method is accessible only to the current class.</para></summary>
  104. Private = 1,
  105. /// <summary><para>Indicates that the method is accessible to members of this type and its derived types that are in this assembly only.</para></summary>
  106. FamANDAssem = 2,
  107. /// <summary><para>Indicates that the method is accessible to any class of this assembly.</para></summary>
  108. Assembly = FamANDAssem | Private, // 0x00000003
  109. /// <summary><para>Indicates that the method is accessible only to members of this class and its derived classes.</para></summary>
  110. Family = 4,
  111. /// <summary><para>Indicates that the method is accessible to derived classes anywhere, as well as to any class in the assembly.</para></summary>
  112. FamORAssem = Family | Private, // 0x00000005
  113. /// <summary><para>Indicates that the method is accessible to any object for which this object is in scope.</para></summary>
  114. Public = Family | FamANDAssem, // 0x00000006
  115. /// <summary><para>Indicates that the method is defined on the type; otherwise, it is defined per instance.</para></summary>
  116. Static = 16, // 0x00000010
  117. /// <summary><para>Indicates that the method cannot be overridden.</para></summary>
  118. Final = 32, // 0x00000020
  119. /// <summary><para>Indicates that the method is virtual.</para></summary>
  120. Virtual = 64, // 0x00000040
  121. /// <summary><para>Indicates that the method hides by name and signature; otherwise, by name only.</para></summary>
  122. HideBySig = 128, // 0x00000080
  123. /// <summary><para>Indicates that the method can only be overridden when it is also accessible.</para></summary>
  124. CheckAccessOnOverride = 512, // 0x00000200
  125. /// <summary><para>Retrieves vtable attributes.</para></summary>
  126. VtableLayoutMask = 256, // 0x00000100
  127. /// <summary><para>Indicates that the method will reuse an existing slot in the vtable. This is the default behavior.</para></summary>
  128. ReuseSlot = 0,
  129. /// <summary><para>Indicates that the method always gets a new slot in the vtable.</para></summary>
  130. NewSlot = VtableLayoutMask, // 0x00000100
  131. /// <summary><para>Indicates that the class does not provide an implementation of this method.</para></summary>
  132. Abstract = 1024, // 0x00000400
  133. /// <summary><para>Indicates that the method is special. The name describes how this method is special.</para></summary>
  134. SpecialName = 2048, // 0x00000800
  135. /// <summary><para>Indicates that the method implementation is forwarded through PInvoke (Platform Invocation Services).</para></summary>
  136. PinvokeImpl = 8192, // 0x00002000
  137. /// <summary><para>Indicates that the managed method is exported by thunk to unmanaged code.</para></summary>
  138. UnmanagedExport = 8,
  139. /// <summary><para>Indicates that the common language runtime checks the name encoding.</para></summary>
  140. RTSpecialName = 4096, // 0x00001000
  141. /// <summary><para>Indicates a reserved flag for runtime use only.</para></summary>
  142. ReservedMask = 53248, // 0x0000D000
  143. /// <summary><para>Indicates that the method has security associated with it. Reserved flag for runtime use only.</para></summary>
  144. HasSecurity = 16384, // 0x00004000
  145. /// <summary><para>Indicates that the method calls another method containing security code. Reserved flag for runtime use only.</para></summary>
  146. RequireSecObject = 32768, // 0x00008000
  147. }
  148. }
  149. #endif