Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
RuntimeHelpers.cs
Go to the documentation of this file.
8
10
11public static class RuntimeHelpers
12{
13 public delegate void TryCode(object? userData);
14
15 public delegate void CleanupCode(object? userData, bool exceptionThrown);
16
17 public static int OffsetToStringData
18 {
20 get
21 {
22 return 12;
23 }
24 }
25
26 [MethodImpl(MethodImplOptions.InternalCall)]
27 [Intrinsic]
29
30 [MethodImpl(MethodImplOptions.InternalCall)]
31 [return: NotNullIfNotNull("obj")]
32 public static extern object? GetObjectValue(object? obj);
33
34 [DllImport("QCall", CharSet = CharSet.Unicode)]
35 private static extern void RunClassConstructor(QCallTypeHandle type);
36
37 [RequiresUnreferencedCode("Trimmer can't guarantee existence of class constructor")]
39 {
40 RuntimeType type2 = type.GetRuntimeType();
41 if ((object)type2 == null)
42 {
44 }
46 }
47
48 [DllImport("QCall", CharSet = CharSet.Unicode)]
49 private static extern void RunModuleConstructor(QCallModule module);
50
52 {
53 RuntimeModule module2 = module.GetRuntimeModule();
54 if ((object)module2 == null)
55 {
57 }
59 }
60
61 [DllImport("QCall", CharSet = CharSet.Unicode)]
62 internal static extern void CompileMethod(RuntimeMethodHandleInternal method);
63
64 [DllImport("QCall", CharSet = CharSet.Unicode)]
66
68 {
69 PrepareMethod(method, null);
70 }
71
88
89 [MethodImpl(MethodImplOptions.InternalCall)]
90 public static extern void PrepareDelegate(Delegate d);
91
92 [MethodImpl(MethodImplOptions.InternalCall)]
93 public static extern int GetHashCode(object? o);
94
95 [MethodImpl(MethodImplOptions.InternalCall)]
96 public new static extern bool Equals(object? o1, object? o2);
97
98 [MethodImpl(MethodImplOptions.InternalCall)]
99 public static extern void EnsureSufficientExecutionStack();
100
101 [MethodImpl(MethodImplOptions.InternalCall)]
102 public static extern bool TryEnsureSufficientExecutionStack();
103
105 {
107 if ((object)type2 == null)
108 {
109 if ((object)type == null)
110 {
111 throw new ArgumentNullException("type", SR.ArgumentNull_Type);
112 }
114 }
115 object o = null;
117 return o;
118 }
119
120 [DllImport("QCall")]
122
123 [MethodImpl(MethodImplOptions.InternalCall)]
124 internal static extern object AllocateUninitializedClone(object obj);
125
126 [Intrinsic]
128 {
129 throw new InvalidOperationException();
130 }
131
132 [Intrinsic]
133 internal static bool IsBitwiseEquatable<T>()
134 {
135 throw new InvalidOperationException();
136 }
137
138 [Intrinsic]
139 internal static bool EnumEquals<T>(T x, T y) where T : struct, Enum
140 {
141 return x.Equals(y);
142 }
143
144 [Intrinsic]
145 internal static int EnumCompareTo<T>(T x, T y) where T : struct, Enum
146 {
147 return x.CompareTo(y);
148 }
149
150 internal static ref byte GetRawData(this object obj)
151 {
152 return ref Unsafe.As<RawData>(obj).Data;
153 }
154
155 [MethodImpl(MethodImplOptions.AggressiveInlining)]
156 internal unsafe static nuint GetRawObjectDataSize(object obj)
157 {
159 nuint num = (nuint)methodTable->BaseSize - (nuint)(2 * sizeof(IntPtr));
160 if (methodTable->HasComponentSize)
161 {
162 num += (nuint)((nint)Unsafe.As<RawArrayData>(obj).Length * (nint)methodTable->ComponentSize);
163 }
165 return num;
166 }
167
168 internal unsafe static ushort GetElementSize(this Array array)
169 {
170 return GetMethodTable(array)->ComponentSize;
171 }
172
173 [MethodImpl(MethodImplOptions.AggressiveInlining)]
175 {
176 return ref Unsafe.As<byte, int>(ref Unsafe.As<RawArrayData>(array).Data);
177 }
178
179 [MethodImpl(MethodImplOptions.AggressiveInlining)]
180 internal unsafe static int GetMultiDimensionalArrayRank(Array array)
181 {
182 int multiDimensionalArrayRank = GetMethodTable(array)->MultiDimensionalArrayRank;
185 }
186
187 [MethodImpl(MethodImplOptions.AggressiveInlining)]
188 internal unsafe static bool ObjectHasComponentSize(object obj)
189 {
190 return GetMethodTable(obj)->HasComponentSize;
191 }
192
193 [MethodImpl(MethodImplOptions.AggressiveInlining)]
194 [Intrinsic]
195 internal unsafe static MethodTable* GetMethodTable(object obj)
196 {
197 return (MethodTable*)(void*)Unsafe.Add(ref Unsafe.As<byte, IntPtr>(ref obj.GetRawData()), -1);
198 }
199
201 {
203 if (type2 == null)
204 {
205 throw new ArgumentException(SR.Arg_MustBeType, "type");
206 }
207 if (size < 0)
208 {
209 throw new ArgumentOutOfRangeException("size");
210 }
211 return AllocateTypeAssociatedMemory(new QCallTypeHandle(ref type2), (uint)size);
212 }
213
214 [DllImport("QCall")]
215 private static extern IntPtr AllocateTypeAssociatedMemory(QCallTypeHandle type, uint size);
216
217 [MethodImpl(MethodImplOptions.InternalCall)]
218 private static extern IntPtr AllocTailCallArgBuffer(int size, IntPtr gcDesc);
219
220 [MethodImpl(MethodImplOptions.InternalCall)]
221 private unsafe static extern TailCallTls* GetTailCallInfo(IntPtr retAddrSlot, IntPtr* retAddr);
222
225 {
228 PortableTailCallFrame* frame = tailCallInfo->Frame;
230 {
231 frame->NextCall = callTarget;
232 return;
233 }
236 try
237 {
239 do
240 {
243 }
244 while (callTarget != (delegate*<IntPtr, IntPtr, PortableTailCallFrame*, void>)null);
245 }
246 finally
247 {
248 tailCallInfo->Frame = frame;
249 if (tailCallInfo->ArgBuffer != IntPtr.Zero && *(int*)(void*)tailCallInfo->ArgBuffer == 1)
250 {
251 *(int*)(void*)tailCallInfo->ArgBuffer = 2;
252 }
253 }
254 }
255
256 public static T[] GetSubArray<T>(T[] array, Range range)
257 {
258 if (array == null)
259 {
261 }
262 var (elementOffset, num) = range.GetOffsetAndLength(array.Length);
263 T[] array2;
264 if (typeof(T).IsValueType || typeof(T[]) == array.GetType())
265 {
266 if (num == 0)
267 {
268 return Array.Empty<T>();
269 }
270 array2 = new T[num];
271 }
272 else
273 {
274 array2 = Unsafe.As<T[]>(Array.CreateInstance(array.GetType().GetElementType(), num));
275 }
277 return array2;
278 }
279
280 [Obsolete("The Constrained Execution Region (CER) feature is not supported.", DiagnosticId = "SYSLIB0004", UrlFormat = "https://aka.ms/dotnet-warnings/{0}")]
282 {
283 if (code == null)
284 {
285 throw new ArgumentNullException("code");
286 }
287 if (backoutCode == null)
288 {
289 throw new ArgumentNullException("backoutCode");
290 }
291 bool exceptionThrown = true;
292 try
293 {
294 code(userData);
295 exceptionThrown = false;
296 }
297 finally
298 {
300 }
301 }
302
303 [Obsolete("The Constrained Execution Region (CER) feature is not supported.", DiagnosticId = "SYSLIB0004", UrlFormat = "https://aka.ms/dotnet-warnings/{0}")]
305 {
306 }
307
308 [Obsolete("The Constrained Execution Region (CER) feature is not supported.", DiagnosticId = "SYSLIB0004", UrlFormat = "https://aka.ms/dotnet-warnings/{0}")]
309 public static void ProbeForSufficientStack()
310 {
311 }
312
313 [Obsolete("The Constrained Execution Region (CER) feature is not supported.", DiagnosticId = "SYSLIB0004", UrlFormat = "https://aka.ms/dotnet-warnings/{0}")]
314 public static void PrepareConstrainedRegions()
315 {
316 }
317
318 [Obsolete("The Constrained Execution Region (CER) feature is not supported.", DiagnosticId = "SYSLIB0004", UrlFormat = "https://aka.ms/dotnet-warnings/{0}")]
319 public static void PrepareConstrainedRegionsNoOP()
320 {
321 }
322
323 internal static bool IsPrimitiveType(this CorElementType et)
324 {
325 return ((1 << (int)et) & 0x3003FFC) != 0;
326 }
327}
static unsafe Array CreateInstance(Type elementType, int length)
Definition Array.cs:473
static void Memmove(ref byte dest, ref byte src, nuint len)
Definition Buffer.cs:215
int CompareTo(object? target)
Definition Enum.cs:1036
override bool Equals([NotNullWhen(true)] object? obj)
static void KeepAlive(object? obj)
Definition GC.cs:180
Definition GC.cs:8
static new bool Equals(object? o1, object? o2)
static ? object GetObjectValue(object? obj)
static unsafe nuint GetRawObjectDataSize(object obj)
static object AllocateUninitializedClone(object obj)
static void CompileMethod(RuntimeMethodHandleInternal method)
static void RunClassConstructor(QCallTypeHandle type)
static IntPtr AllocTailCallArgBuffer(int size, IntPtr gcDesc)
static T[] GetSubArray< T >(T[] array, Range range)
static void InitializeArray(Array array, RuntimeFieldHandle fldHandle)
static unsafe int GetMultiDimensionalArrayRank(Array array)
static unsafe void PrepareMethod(RuntimeMethodHandleInternal method, IntPtr *pInstantiation, int cInstantiation)
static unsafe TailCallTls * GetTailCallInfo(IntPtr retAddrSlot, IntPtr *retAddr)
static unsafe MethodTable * GetMethodTable(object obj)
static IntPtr AllocateTypeAssociatedMemory(QCallTypeHandle type, uint size)
static IntPtr AllocateTypeAssociatedMemory(Type type, int size)
delegate void CleanupCode(object? userData, bool exceptionThrown)
static void GetUninitializedObject(QCallTypeHandle type, ObjectHandleOnStack retObject)
static ref byte GetRawData(this object obj)
static unsafe ushort GetElementSize(this Array array)
static object GetUninitializedObject([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors|DynamicallyAccessedMemberTypes.NonPublicConstructors)] Type type)
static unsafe void PrepareMethod(RuntimeMethodHandle method, RuntimeTypeHandle[]? instantiation)
static unsafe void DispatchTailCalls(IntPtr callersRetAddrSlot, delegate *< IntPtr, IntPtr, PortableTailCallFrame *, void > callTarget, IntPtr retVal)
delegate void TryCode(object? userData)
static unsafe bool ObjectHasComponentSize(object obj)
static void PrepareMethod(RuntimeMethodHandle method)
static bool IsPrimitiveType(this CorElementType et)
static void RunModuleConstructor(QCallModule module)
static void RunModuleConstructor(ModuleHandle module)
static void ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, object? userData)
static ref int GetMultiDimensionalArrayBounds(Array array)
static void RunClassConstructor(RuntimeTypeHandle type)
static unsafe ref byte GetArrayDataReference(Array array)
static string Arg_MustBeType
Definition SR.cs:302
static string Serialization_InvalidType
Definition SR.cs:1886
static string Format(string resourceFormat, object p1)
Definition SR.cs:118
static string InvalidOperation_HandleIsNotInitialized
Definition SR.cs:1454
static string ArgumentNull_Type
Definition SR.cs:962
Definition SR.cs:7
static void ThrowArgumentNullException(string name)
static readonly IntPtr Zero
Definition IntPtr.cs:18
static IntPtr[] CopyRuntimeTypeHandles(RuntimeTypeHandle[] inHandles, out int length)
unsafe delegate *< IntPtr, IntPtr, PortableTailCallFrame *, void > NextCall