mscorlib(4.0.0.0) API with additions
RuntimeHelpers.cs
1 using System.Reflection;
5 using System.Security;
6 
8 {
10  [__DynamicallyInvokable]
11  public static class RuntimeHelpers
12  {
15  public delegate void TryCode(object userData);
16 
21  public delegate void CleanupCode(object userData, bool exceptionThrown);
22 
25  [__DynamicallyInvokable]
26  public static int OffsetToStringData
27  {
28  [NonVersionable]
29  [__DynamicallyInvokable]
30  get
31  {
32  return 12;
33  }
34  }
35 
39  [MethodImpl(MethodImplOptions.InternalCall)]
40  [SecuritySafeCritical]
41  [__DynamicallyInvokable]
42  public static extern void InitializeArray(Array array, RuntimeFieldHandle fldHandle);
43 
47  [MethodImpl(MethodImplOptions.InternalCall)]
48  [SecuritySafeCritical]
49  [__DynamicallyInvokable]
50  public static extern object GetObjectValue(object obj);
51 
52  [MethodImpl(MethodImplOptions.InternalCall)]
53  [SecuritySafeCritical]
54  private static extern void _RunClassConstructor(RuntimeType type);
55 
59  [__DynamicallyInvokable]
60  public static void RunClassConstructor(RuntimeTypeHandle type)
61  {
62  _RunClassConstructor(type.GetRuntimeType());
63  }
64 
65  [MethodImpl(MethodImplOptions.InternalCall)]
66  [SecuritySafeCritical]
67  private static extern void _RunModuleConstructor(RuntimeModule module);
68 
72  public static void RunModuleConstructor(ModuleHandle module)
73  {
74  _RunModuleConstructor(module.GetRuntimeModule());
75  }
76 
77  [MethodImpl(MethodImplOptions.InternalCall)]
78  [SecurityCritical]
79  private unsafe static extern void _PrepareMethod(IRuntimeMethodInfo method, IntPtr* pInstantiation, int cInstantiation);
80 
81  [DllImport("QCall", CharSet = CharSet.Unicode)]
82  [SecurityCritical]
83  [SuppressUnmanagedCodeSecurity]
84  internal static extern void _CompileMethod(IRuntimeMethodInfo method);
85 
88  [SecurityCritical]
89  public static void PrepareMethod(RuntimeMethodHandle method)
90  {
91  _PrepareMethod(method.GetMethodInfo(), null, 0);
92  }
93 
97  [SecurityCritical]
98  public unsafe static void PrepareMethod(RuntimeMethodHandle method, RuntimeTypeHandle[] instantiation)
99  {
100  int length;
101  IntPtr[] array = RuntimeTypeHandle.CopyRuntimeTypeHandles(instantiation, out length);
102  IntPtr[] array2 = array;
103  fixed (IntPtr* pInstantiation = array2)
104  {
105  _PrepareMethod(method.GetMethodInfo(), pInstantiation, length);
106  GC.KeepAlive(instantiation);
107  }
108  }
109 
112  [MethodImpl(MethodImplOptions.InternalCall)]
113  [SecurityCritical]
114  public static extern void PrepareDelegate(Delegate d);
115 
118  [MethodImpl(MethodImplOptions.InternalCall)]
119  [SecurityCritical]
120  public static extern void PrepareContractedDelegate(Delegate d);
121 
125  [MethodImpl(MethodImplOptions.InternalCall)]
126  [SecuritySafeCritical]
127  [__DynamicallyInvokable]
128  public static extern int GetHashCode(object o);
129 
135  [MethodImpl(MethodImplOptions.InternalCall)]
136  [SecuritySafeCritical]
137  public new static extern bool Equals(object o1, object o2);
138 
141  [MethodImpl(MethodImplOptions.InternalCall)]
142  [SecuritySafeCritical]
143  [ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
144  [__DynamicallyInvokable]
145  public static extern void EnsureSufficientExecutionStack();
146 
148  [MethodImpl(MethodImplOptions.InternalCall)]
149  [SecurityCritical]
150  [ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)]
151  public static extern void ProbeForSufficientStack();
152 
154  [SecurityCritical]
155  [ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)]
156  public static void PrepareConstrainedRegions()
157  {
159  }
160 
162  [SecurityCritical]
163  [ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail)]
164  public static void PrepareConstrainedRegionsNoOP()
165  {
166  }
167 
172  [MethodImpl(MethodImplOptions.InternalCall)]
173  [SecurityCritical]
174  public static extern void ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, object userData);
175 
176  [PrePrepareMethod]
177  internal static void ExecuteBackoutCodeHelper(object backoutCode, object userData, bool exceptionThrown)
178  {
179  ((CleanupCode)backoutCode)(userData, exceptionThrown);
180  }
181  }
182 }
delegate void TryCode(object userData)
Represents a delegate to code that should be run in a try block..
static void PrepareMethod(RuntimeMethodHandle method)
Prepares a method for inclusion in a constrained execution region (CER).
static void PrepareContractedDelegate(Delegate d)
Provides a way for applications to dynamically prepare T:System.AppDomain event delegates.
static void ProbeForSufficientStack()
Probes for a certain amount of stack space to ensure that a stack overflow cannot happen within a sub...
static void InitializeArray(Array array, RuntimeFieldHandle fldHandle)
Provides a fast way to initialize an array from data that is stored in a module.
static int GetHashCode(object o)
Serves as a hash function for a particular object, and is suitable for use in algorithms and data str...
static void ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, object userData)
Executes code using a T:System.Delegate while using another T:System.Delegate to execute additional c...
Definition: __Canon.cs:3
Represents a field using an internal metadata token.
Represents a runtime handle for a module.
Definition: ModuleHandle.cs:12
static void KeepAlive(object obj)
References the specified object, which makes it ineligible for garbage collection from the start of t...
Definition: GC.cs:267
Represents a type using an internal metadata token.
static void PrepareConstrainedRegionsNoOP()
Designates a body of code as a constrained execution region (CER) without performing any probing.
Cer
Specifies a method's behavior when called within a constrained execution region.
Definition: Cer.cs:5
static new bool Equals(object o1, object o2)
Determines whether the specified T:System.Object instances are considered equal.
T:System.RuntimeMethodHandle is a handle to the internal metadata representation of a method.
static void RunModuleConstructor(ModuleHandle module)
Runs a specified module constructor method.
static object GetObjectValue(object obj)
Boxes a value type.
A platform-specific type that is used to represent a pointer or a handle.
Definition: IntPtr.cs:14
static void PrepareConstrainedRegions()
Designates a body of code as a constrained execution region (CER).
Provides methods for creating, manipulating, searching, and sorting arrays, thereby serving as the ba...
Definition: Array.cs:17
Represents a delegate, which is a data structure that refers to a static method or to a class instanc...
Definition: Delegate.cs:15
MethodImplOptions
Defines the details of how a method is implemented.
CharSet
Dictates which character set marshaled strings should use.
Definition: CharSet.cs:7
Controls the system garbage collector, a service that automatically reclaims unused memory.
Definition: GC.cs:11
delegate void CleanupCode(object userData, bool exceptionThrown)
Represents a method to run when an exception occurs.
static int OffsetToStringData
Gets the offset, in bytes, to the data in the given string.
Consistency
Specifies a reliability contract.
Definition: Consistency.cs:5
static void RunClassConstructor(RuntimeTypeHandle type)
Runs a specified class constructor method.
static unsafe void PrepareMethod(RuntimeMethodHandle method, RuntimeTypeHandle[] instantiation)
Prepares a method for inclusion in a constrained execution region (CER) with the specified instantiat...
static void EnsureSufficientExecutionStack()
Ensures that the remaining stack space is large enough to execute the average .NET Framework function...
Provides a set of static methods and properties that provide support for compilers....
static void PrepareDelegate(Delegate d)
Indicates that the specified delegate should be prepared for inclusion in a constrained execution reg...