1 // Licensed to the .NET Foundation under one or more agreements.
2 // The .NET Foundation licenses this file to you under the MIT license.
3 // See the LICENSE file in the project root for more information.
4 
5 //
6 // This is where we group together all the internal calls.
7 //
8 
9 using System.Runtime.InteropServices;
10 using System.Runtime.CompilerServices;
11 
12 using Internal.Runtime;
13 
14 namespace System.Runtime
15 {
16     internal enum DispatchCellType
17     {
18         InterfaceAndSlot = 0x0,
19         MetadataToken = 0x1,
20         VTableOffset = 0x2,
21     }
22 
23     internal struct DispatchCellInfo
24     {
25         public DispatchCellType CellType;
26         public EETypePtr InterfaceType;
27         public ushort InterfaceSlot;
28         public byte HasCache;
29         public uint MetadataToken;
30         public uint VTableOffset;
31     }
32 
33     internal static class InternalCalls
34     {
35         //
36         // internalcalls for System.GC.
37         //
38 
39         // Force a garbage collection.
40         [RuntimeExport("RhCollect")]
RhCollect(int generation, InternalGCCollectionMode mode)41         internal static void RhCollect(int generation, InternalGCCollectionMode mode)
42         {
43             RhpCollect(generation, mode);
44         }
45 
46         [DllImport(Redhawk.BaseName, CallingConvention = CallingConvention.Cdecl)]
RhpCollect(int generation, InternalGCCollectionMode mode)47         private static extern void RhpCollect(int generation, InternalGCCollectionMode mode);
48 
49         [RuntimeExport("RhGetGcTotalMemory")]
RhGetGcTotalMemory()50         internal static long RhGetGcTotalMemory()
51         {
52             return RhpGetGcTotalMemory();
53         }
54 
55         [DllImport(Redhawk.BaseName, CallingConvention = CallingConvention.Cdecl)]
RhpGetGcTotalMemory()56         private static extern long RhpGetGcTotalMemory();
57 
58         [RuntimeExport("RhStartNoGCRegion")]
RhStartNoGCRegion(Int64 totalSize, bool hasLohSize, Int64 lohSize, bool disallowFullBlockingGC)59         internal static Int32 RhStartNoGCRegion(Int64 totalSize, bool hasLohSize, Int64 lohSize, bool disallowFullBlockingGC)
60         {
61             return RhpStartNoGCRegion(totalSize, hasLohSize, lohSize, disallowFullBlockingGC);
62         }
63 
64         [RuntimeExport("RhEndNoGCRegion")]
RhEndNoGCRegion()65         internal static Int32 RhEndNoGCRegion()
66         {
67             return RhpEndNoGCRegion();
68         }
69 
70         //
71         // internalcalls for System.Runtime.__Finalizer.
72         //
73 
74         // Fetch next object which needs finalization or return null if we've reached the end of the list.
75         [RuntimeImport(Redhawk.BaseName, "RhpGetNextFinalizableObject")]
76         [MethodImpl(MethodImplOptions.InternalCall)]
77         [ManuallyManaged(GcPollPolicy.Never)]
RhpGetNextFinalizableObject()78         internal static extern Object RhpGetNextFinalizableObject();
79 
80         //
81         // internalcalls for System.Runtime.InteropServices.GCHandle.
82         //
83 
84         // Allocate handle.
85         [RuntimeImport(Redhawk.BaseName, "RhpHandleAlloc")]
86         [MethodImpl(MethodImplOptions.InternalCall)]
87         [ManuallyManaged(GcPollPolicy.Never)]
RhpHandleAlloc(Object value, GCHandleType type)88         internal static extern IntPtr RhpHandleAlloc(Object value, GCHandleType type);
89 
90         // Allocate dependent handle.
91         [RuntimeImport(Redhawk.BaseName, "RhpHandleAllocDependent")]
92         [MethodImpl(MethodImplOptions.InternalCall)]
93         [ManuallyManaged(GcPollPolicy.Never)]
RhpHandleAllocDependent(Object primary, Object secondary)94         internal static extern IntPtr RhpHandleAllocDependent(Object primary, Object secondary);
95 
96         // Allocate variable handle.
97         [RuntimeImport(Redhawk.BaseName, "RhpHandleAllocVariable")]
98         [MethodImpl(MethodImplOptions.InternalCall)]
99         [ManuallyManaged(GcPollPolicy.Never)]
RhpHandleAllocVariable(Object value, uint type)100         internal static extern IntPtr RhpHandleAllocVariable(Object value, uint type);
101 
102         [RuntimeImport(Redhawk.BaseName, "RhHandleGet")]
103         [MethodImpl(MethodImplOptions.InternalCall)]
104         [ManuallyManaged(GcPollPolicy.Never)]
RhHandleGet(IntPtr handle)105         internal static extern Object RhHandleGet(IntPtr handle);
106 
107         [RuntimeImport(Redhawk.BaseName, "RhHandleSet")]
108         [MethodImpl(MethodImplOptions.InternalCall)]
109         [ManuallyManaged(GcPollPolicy.Never)]
RhHandleSet(IntPtr handle, Object value)110         internal static extern IntPtr RhHandleSet(IntPtr handle, Object value);
111 
112         //
113         // internal calls for allocation
114         //
115         [RuntimeImport(Redhawk.BaseName, "RhpNewFast")]
116         [MethodImpl(MethodImplOptions.InternalCall)]
117         [ManuallyManaged(GcPollPolicy.Sometimes)]
RhpNewFast(EEType* pEEType)118         internal extern static unsafe object RhpNewFast(EEType* pEEType);  // BEWARE: not for finalizable objects!
119 
120         [RuntimeImport(Redhawk.BaseName, "RhpNewFinalizable")]
121         [MethodImpl(MethodImplOptions.InternalCall)]
122         [ManuallyManaged(GcPollPolicy.Sometimes)]
RhpNewFinalizable(EEType* pEEType)123         internal extern static unsafe object RhpNewFinalizable(EEType* pEEType);
124 
125         [RuntimeImport(Redhawk.BaseName, "RhpNewArray")]
126         [MethodImpl(MethodImplOptions.InternalCall)]
127         [ManuallyManaged(GcPollPolicy.Sometimes)]
RhpNewArray(EEType* pEEType, int length)128         internal extern static unsafe object RhpNewArray(EEType* pEEType, int length);
129 
130 #if FEATURE_64BIT_ALIGNMENT
131         [RuntimeImport(Redhawk.BaseName, "RhpNewFastAlign8")]
132         [MethodImpl(MethodImplOptions.InternalCall)]
133         [ManuallyManaged(GcPollPolicy.Sometimes)]
RhpNewFastAlign8(EEType * pEEType)134         internal extern static unsafe object RhpNewFastAlign8(EEType * pEEType);  // BEWARE: not for finalizable objects!
135 
136         [RuntimeImport(Redhawk.BaseName, "RhpNewFinalizableAlign8")]
137         [MethodImpl(MethodImplOptions.InternalCall)]
138         [ManuallyManaged(GcPollPolicy.Sometimes)]
RhpNewFinalizableAlign8(EEType* pEEType)139         internal extern static unsafe object RhpNewFinalizableAlign8(EEType* pEEType);
140 
141         [RuntimeImport(Redhawk.BaseName, "RhpNewArrayAlign8")]
142         [MethodImpl(MethodImplOptions.InternalCall)]
143         [ManuallyManaged(GcPollPolicy.Sometimes)]
RhpNewArrayAlign8(EEType* pEEType, int length)144         internal extern static unsafe object RhpNewArrayAlign8(EEType* pEEType, int length);
145 
146         [RuntimeImport(Redhawk.BaseName, "RhpNewFastMisalign")]
147         [MethodImpl(MethodImplOptions.InternalCall)]
148         [ManuallyManaged(GcPollPolicy.Sometimes)]
RhpNewFastMisalign(EEType * pEEType)149         internal extern static unsafe object RhpNewFastMisalign(EEType * pEEType);
150 #endif // FEATURE_64BIT_ALIGNMENT
151 
152         [RuntimeImport(Redhawk.BaseName, "RhpBox")]
153         [MethodImpl(MethodImplOptions.InternalCall)]
154         [ManuallyManaged(GcPollPolicy.Sometimes)]
RhpBox(object obj, ref byte data)155         internal extern static unsafe void RhpBox(object obj, ref byte data);
156 
157         [RuntimeImport(Redhawk.BaseName, "RhUnbox")]
158         [MethodImpl(MethodImplOptions.InternalCall)]
159         [ManuallyManaged(GcPollPolicy.Sometimes)]
RhUnbox(object obj, ref byte data, EEType* pUnboxToEEType)160         internal extern static unsafe void RhUnbox(object obj, ref byte data, EEType* pUnboxToEEType);
161 
162         [RuntimeImport(Redhawk.BaseName, "RhpCopyObjectContents")]
163         [MethodImpl(MethodImplOptions.InternalCall)]
164         [ManuallyManaged(GcPollPolicy.Never)]
RhpCopyObjectContents(object objDest, object objSrc)165         internal extern static unsafe void RhpCopyObjectContents(object objDest, object objSrc);
166 
167         [RuntimeImport(Redhawk.BaseName, "RhpCompareObjectContents")]
168         [MethodImpl(MethodImplOptions.InternalCall)]
169         [ManuallyManaged(GcPollPolicy.Never)]
RhpCompareObjectContentsAndPadding(object obj1, object obj2)170         internal extern static bool RhpCompareObjectContentsAndPadding(object obj1, object obj2);
171 
172         [RuntimeImport(Redhawk.BaseName, "RhpAssignRef")]
173         [MethodImpl(MethodImplOptions.InternalCall)]
174         [ManuallyManaged(GcPollPolicy.Never)]
RhpAssignRef(ref Object address, object obj)175         internal extern static unsafe void RhpAssignRef(ref Object address, object obj);
176 
177 #if FEATURE_GC_STRESS
178         //
179         // internal calls for GC stress
180         //
181         [RuntimeImport(Redhawk.BaseName, "RhpInitializeGcStress")]
182         [MethodImpl(MethodImplOptions.InternalCall)]
183         [ManuallyManaged(GcPollPolicy.Never)]
RhpInitializeGcStress()184         internal extern static unsafe void RhpInitializeGcStress();
185 #endif // FEATURE_GC_STRESS
186 
187         [RuntimeImport(Redhawk.BaseName, "RhpEHEnumInitFromStackFrameIterator")]
188         [MethodImpl(MethodImplOptions.InternalCall)]
189         [ManuallyManaged(GcPollPolicy.Never)]
RhpEHEnumInitFromStackFrameIterator(ref StackFrameIterator pFrameIter, byte** pMethodStartAddress, void* pEHEnum)190         internal extern static unsafe bool RhpEHEnumInitFromStackFrameIterator(ref StackFrameIterator pFrameIter, byte** pMethodStartAddress, void* pEHEnum);
191 
192         [RuntimeImport(Redhawk.BaseName, "RhpEHEnumNext")]
193         [MethodImpl(MethodImplOptions.InternalCall)]
194         [ManuallyManaged(GcPollPolicy.Never)]
RhpEHEnumNext(void* pEHEnum, void* pEHClause)195         internal extern static unsafe bool RhpEHEnumNext(void* pEHEnum, void* pEHClause);
196 
197         [RuntimeImport(Redhawk.BaseName, "RhpGetArrayBaseType")]
198         [MethodImpl(MethodImplOptions.InternalCall)]
199         [ManuallyManaged(GcPollPolicy.Never)]
RhpGetArrayBaseType(EEType* pEEType)200         internal extern static unsafe EEType* RhpGetArrayBaseType(EEType* pEEType);
201 
202         [RuntimeImport(Redhawk.BaseName, "RhpHasDispatchMap")]
203         [MethodImpl(MethodImplOptions.InternalCall)]
204         [ManuallyManaged(GcPollPolicy.Never)]
RhpHasDispatchMap(EEType* pEETypen)205         internal extern static unsafe bool RhpHasDispatchMap(EEType* pEETypen);
206 
207         [RuntimeImport(Redhawk.BaseName, "RhpGetDispatchMap")]
208         [MethodImpl(MethodImplOptions.InternalCall)]
209         [ManuallyManaged(GcPollPolicy.Never)]
RhpGetDispatchMap(EEType* pEEType)210         internal extern static unsafe DispatchResolve.DispatchMap* RhpGetDispatchMap(EEType* pEEType);
211 
212         [RuntimeImport(Redhawk.BaseName, "RhpGetSealedVirtualSlot")]
213         [MethodImpl(MethodImplOptions.InternalCall)]
214         [ManuallyManaged(GcPollPolicy.Never)]
RhpGetSealedVirtualSlot(EEType* pEEType, ushort slot)215         internal extern static unsafe IntPtr RhpGetSealedVirtualSlot(EEType* pEEType, ushort slot);
216 
217         [RuntimeImport(Redhawk.BaseName, "RhpGetDispatchCellInfo")]
218         [MethodImpl(MethodImplOptions.InternalCall)]
219         [ManuallyManaged(GcPollPolicy.Never)]
RhpGetDispatchCellInfo(IntPtr pCell, out DispatchCellInfo newCellInfo)220         internal extern static unsafe void RhpGetDispatchCellInfo(IntPtr pCell, out DispatchCellInfo newCellInfo);
221 
222         [RuntimeImport(Redhawk.BaseName, "RhpSearchDispatchCellCache")]
223         [MethodImpl(MethodImplOptions.InternalCall)]
224         [ManuallyManaged(GcPollPolicy.Never)]
RhpSearchDispatchCellCache(IntPtr pCell, EEType* pInstanceType)225         internal extern static unsafe IntPtr RhpSearchDispatchCellCache(IntPtr pCell, EEType* pInstanceType);
226 
227         [RuntimeImport(Redhawk.BaseName, "RhpUpdateDispatchCellCache")]
228         [MethodImpl(MethodImplOptions.InternalCall)]
229         [ManuallyManaged(GcPollPolicy.Never)]
RhpUpdateDispatchCellCache(IntPtr pCell, IntPtr pTargetCode, EEType* pInstanceType, ref DispatchCellInfo newCellInfo)230         internal extern static unsafe IntPtr RhpUpdateDispatchCellCache(IntPtr pCell, IntPtr pTargetCode, EEType* pInstanceType, ref DispatchCellInfo newCellInfo);
231 
232         [RuntimeImport(Redhawk.BaseName, "RhpGetClasslibFunctionFromCodeAddress")]
233         [MethodImpl(MethodImplOptions.InternalCall)]
234         [ManuallyManaged(GcPollPolicy.Never)]
RhpGetClasslibFunctionFromCodeAddress(IntPtr address, EH.ClassLibFunctionId id)235         internal extern static unsafe void* RhpGetClasslibFunctionFromCodeAddress(IntPtr address, EH.ClassLibFunctionId id);
236 
237         [RuntimeImport(Redhawk.BaseName, "RhpGetClasslibFunctionFromEEType")]
238         [MethodImpl(MethodImplOptions.InternalCall)]
239         [ManuallyManaged(GcPollPolicy.Never)]
RhpGetClasslibFunctionFromEEType(IntPtr pEEType, EH.ClassLibFunctionId id)240         internal extern static unsafe void* RhpGetClasslibFunctionFromEEType(IntPtr pEEType, EH.ClassLibFunctionId id);
241 
242         //
243         // StackFrameIterator
244         //
245 
246         [RuntimeImport(Redhawk.BaseName, "RhpSfiInit")]
247         [MethodImpl(MethodImplOptions.InternalCall)]
248         [ManuallyManaged(GcPollPolicy.Never)]
RhpSfiInit(ref StackFrameIterator pThis, void* pStackwalkCtx, bool instructionFault)249         internal static extern unsafe bool RhpSfiInit(ref StackFrameIterator pThis, void* pStackwalkCtx, bool instructionFault);
250 
251         [RuntimeImport(Redhawk.BaseName, "RhpSfiNext")]
252         [MethodImpl(MethodImplOptions.InternalCall)]
253         [ManuallyManaged(GcPollPolicy.Never)]
RhpSfiNext(ref StackFrameIterator pThis, out uint uExCollideClauseIdx, out bool fUnwoundReversePInvoke)254         internal static extern bool RhpSfiNext(ref StackFrameIterator pThis, out uint uExCollideClauseIdx, out bool fUnwoundReversePInvoke);
255 
256         //
257         // DebugEventSource
258         //
259 
260         [RuntimeImport(Redhawk.BaseName, "RhpGetRequestedExceptionEvents")]
261         [MethodImpl(MethodImplOptions.InternalCall)]
262         [ManuallyManaged(GcPollPolicy.Never)]
RhpGetRequestedExceptionEvents()263         internal static extern ExceptionEventKind RhpGetRequestedExceptionEvents();
264 
265         [DllImport(Redhawk.BaseName)]
RhpSendExceptionEventToDebugger(ExceptionEventKind eventKind, byte* ip, UIntPtr sp)266         internal static extern unsafe void RhpSendExceptionEventToDebugger(ExceptionEventKind eventKind, byte* ip, UIntPtr sp);
267 
268         //
269         // Miscellaneous helpers.
270         //
271 
272         // Get the rarely used (optional) flags of an EEType. If they're not present 0 will be returned.
273         [RuntimeImport(Redhawk.BaseName, "RhpGetEETypeRareFlags")]
274         [MethodImpl(MethodImplOptions.InternalCall)]
275         [ManuallyManaged(GcPollPolicy.Never)]
RhpGetEETypeRareFlags(EEType* pEEType)276         internal extern static unsafe UInt32 RhpGetEETypeRareFlags(EEType* pEEType);
277 
278         // Retrieve the offset of the value embedded in a Nullable<T>.
279         [RuntimeImport(Redhawk.BaseName, "RhpGetNullableEETypeValueOffset")]
280         [MethodImpl(MethodImplOptions.InternalCall)]
281         [ManuallyManaged(GcPollPolicy.Never)]
RhpGetNullableEETypeValueOffset(EEType* pEEType)282         internal extern static unsafe byte RhpGetNullableEETypeValueOffset(EEType* pEEType);
283 
284         // Retrieve the target type T in a Nullable<T>.
285         [RuntimeImport(Redhawk.BaseName, "RhpGetNullableEEType")]
286         [MethodImpl(MethodImplOptions.InternalCall)]
287         [ManuallyManaged(GcPollPolicy.Never)]
RhpGetNullableEEType(EEType* pEEType)288         internal extern static unsafe EEType* RhpGetNullableEEType(EEType* pEEType);
289 
290         // For an ICastable type return a pointer to code that implements ICastable.IsInstanceOfInterface.
291         [RuntimeImport(Redhawk.BaseName, "RhpGetICastableIsInstanceOfInterfaceMethod")]
292         [MethodImpl(MethodImplOptions.InternalCall)]
293         [ManuallyManaged(GcPollPolicy.Never)]
RhpGetICastableIsInstanceOfInterfaceMethod(EEType* pEEType)294         internal extern static unsafe IntPtr RhpGetICastableIsInstanceOfInterfaceMethod(EEType* pEEType);
295 
296         // For an ICastable type return a pointer to code that implements ICastable.GetImplType.
297         [RuntimeImport(Redhawk.BaseName, "RhpGetICastableGetImplTypeMethod")]
298         [MethodImpl(MethodImplOptions.InternalCall)]
299         [ManuallyManaged(GcPollPolicy.Never)]
RhpGetICastableGetImplTypeMethod(EEType* pEEType)300         internal extern static unsafe IntPtr RhpGetICastableGetImplTypeMethod(EEType* pEEType);
301 
302         [RuntimeImport(Redhawk.BaseName, "RhpGetNextFinalizerInitCallback")]
303         [MethodImpl(MethodImplOptions.InternalCall)]
304         [ManuallyManaged(GcPollPolicy.Never)]
RhpGetNextFinalizerInitCallback()305         internal extern static unsafe IntPtr RhpGetNextFinalizerInitCallback();
306 
307         [RuntimeImport(Redhawk.BaseName, "RhpCallCatchFunclet")]
308         [MethodImpl(MethodImplOptions.InternalCall)]
309         [ManuallyManaged(GcPollPolicy.Never)]
RhpCallCatchFunclet( object exceptionObj, byte* pHandlerIP, void* pvRegDisplay, ref EH.ExInfo exInfo)310         internal extern static unsafe IntPtr RhpCallCatchFunclet(
311             object exceptionObj, byte* pHandlerIP, void* pvRegDisplay, ref EH.ExInfo exInfo);
312 
313         [RuntimeImport(Redhawk.BaseName, "RhpCallFinallyFunclet")]
314         [MethodImpl(MethodImplOptions.InternalCall)]
315         [ManuallyManaged(GcPollPolicy.Never)]
RhpCallFinallyFunclet(byte* pHandlerIP, void* pvRegDisplay)316         internal extern static unsafe void RhpCallFinallyFunclet(byte* pHandlerIP, void* pvRegDisplay);
317 
318         [RuntimeImport(Redhawk.BaseName, "RhpCallFilterFunclet")]
319         [MethodImpl(MethodImplOptions.InternalCall)]
320         [ManuallyManaged(GcPollPolicy.Never)]
RhpCallFilterFunclet( object exceptionObj, byte* pFilterIP, void* pvRegDisplay)321         internal extern static unsafe bool RhpCallFilterFunclet(
322             object exceptionObj, byte* pFilterIP, void* pvRegDisplay);
323 
324         [RuntimeImport(Redhawk.BaseName, "RhpFallbackFailFast")]
325         [MethodImpl(MethodImplOptions.InternalCall)]
326         [ManuallyManaged(GcPollPolicy.Never)]
RhpFallbackFailFast()327         internal extern static unsafe void RhpFallbackFailFast();
328 
329         [RuntimeImport(Redhawk.BaseName, "RhpSetThreadDoNotTriggerGC")]
330         [MethodImpl(MethodImplOptions.InternalCall)]
331         [ManuallyManaged(GcPollPolicy.Never)]
RhpSetThreadDoNotTriggerGC()332         internal extern static void RhpSetThreadDoNotTriggerGC();
333 
334         [System.Diagnostics.Conditional("DEBUG")]
335         [RuntimeImport(Redhawk.BaseName, "RhpValidateExInfoStack")]
336         [MethodImpl(MethodImplOptions.InternalCall)]
337         [ManuallyManaged(GcPollPolicy.Never)]
RhpValidateExInfoStack()338         internal extern static void RhpValidateExInfoStack();
339 
340         [RuntimeImport(Redhawk.BaseName, "RhpCopyContextFromExInfo")]
341         [MethodImpl(MethodImplOptions.InternalCall)]
342         [ManuallyManaged(GcPollPolicy.Never)]
RhpCopyContextFromExInfo(void* pOSContext, int cbOSContext, EH.PAL_LIMITED_CONTEXT* pPalContext)343         internal extern static unsafe void RhpCopyContextFromExInfo(void* pOSContext, int cbOSContext, EH.PAL_LIMITED_CONTEXT* pPalContext);
344 
345         [RuntimeImport(Redhawk.BaseName, "RhpGetCastableObjectDispatchHelper")]
346         [MethodImpl(MethodImplOptions.InternalCall)]
347         [ManuallyManaged(GcPollPolicy.Never)]
RhpGetCastableObjectDispatchHelper()348         internal extern static IntPtr RhpGetCastableObjectDispatchHelper();
349 
350         [RuntimeImport(Redhawk.BaseName, "RhpGetCastableObjectDispatchHelper_TailCalled")]
351         [MethodImpl(MethodImplOptions.InternalCall)]
352         [ManuallyManaged(GcPollPolicy.Never)]
RhpGetCastableObjectDispatchHelper_TailCalled()353         internal extern static IntPtr RhpGetCastableObjectDispatchHelper_TailCalled();
354 
355         [RuntimeImport(Redhawk.BaseName, "RhpGetCastableObjectDispatch_CommonStub")]
356         [MethodImpl(MethodImplOptions.InternalCall)]
357         [ManuallyManaged(GcPollPolicy.Never)]
RhpGetCastableObjectDispatch_CommonStub()358         internal extern static IntPtr RhpGetCastableObjectDispatch_CommonStub();
359 
360         [RuntimeImport(Redhawk.BaseName, "RhpGetTailCallTLSDispatchCell")]
361         [MethodImpl(MethodImplOptions.InternalCall)]
362         [ManuallyManaged(GcPollPolicy.Never)]
RhpGetTailCallTLSDispatchCell()363         internal extern static IntPtr RhpGetTailCallTLSDispatchCell();
364 
365         [RuntimeImport(Redhawk.BaseName, "RhpSetTLSDispatchCell")]
366         [MethodImpl(MethodImplOptions.InternalCall)]
367         [ManuallyManaged(GcPollPolicy.Never)]
RhpSetTLSDispatchCell(IntPtr pCell)368         internal extern static unsafe void RhpSetTLSDispatchCell(IntPtr pCell);
369 
370         [RuntimeImport(Redhawk.BaseName, "RhpGetNumThunkBlocksPerMapping")]
371         [MethodImpl(MethodImplOptions.InternalCall)]
372         [ManuallyManaged(GcPollPolicy.Never)]
RhpGetNumThunkBlocksPerMapping()373         internal extern static int RhpGetNumThunkBlocksPerMapping();
374 
375         [RuntimeImport(Redhawk.BaseName, "RhpGetNumThunksPerBlock")]
376         [MethodImpl(MethodImplOptions.InternalCall)]
377         [ManuallyManaged(GcPollPolicy.Never)]
RhpGetNumThunksPerBlock()378         internal extern static int RhpGetNumThunksPerBlock();
379 
380         [RuntimeImport(Redhawk.BaseName, "RhpGetThunkSize")]
381         [MethodImpl(MethodImplOptions.InternalCall)]
382         [ManuallyManaged(GcPollPolicy.Never)]
RhpGetThunkSize()383         internal extern static int RhpGetThunkSize();
384 
385         [RuntimeImport(Redhawk.BaseName, "RhpGetThunkDataBlockAddress")]
386         [MethodImpl(MethodImplOptions.InternalCall)]
387         [ManuallyManaged(GcPollPolicy.Never)]
RhpGetThunkDataBlockAddress(IntPtr thunkStubAddress)388         internal extern static IntPtr RhpGetThunkDataBlockAddress(IntPtr thunkStubAddress);
389 
390         [RuntimeImport(Redhawk.BaseName, "RhpGetThunkStubsBlockAddress")]
391         [MethodImpl(MethodImplOptions.InternalCall)]
392         [ManuallyManaged(GcPollPolicy.Never)]
RhpGetThunkStubsBlockAddress(IntPtr thunkDataAddress)393         internal extern static IntPtr RhpGetThunkStubsBlockAddress(IntPtr thunkDataAddress);
394 
395         [RuntimeImport(Redhawk.BaseName, "RhpGetThunkBlockSize")]
396         [MethodImpl(MethodImplOptions.InternalCall)]
397         [ManuallyManaged(GcPollPolicy.Never)]
RhpGetThunkBlockSize()398         internal extern static int RhpGetThunkBlockSize();
399 
400         [RuntimeImport(Redhawk.BaseName, "RhpGetThreadAbortException")]
401         [MethodImpl(MethodImplOptions.InternalCall)]
RhpGetThreadAbortException()402         internal extern static Exception RhpGetThreadAbortException();
403 
404         //------------------------------------------------------------------------------------------------------------
405         // PInvoke-based internal calls
406         //
407         // These either do not need to be called in cooperative mode or, in some cases, MUST be called in preemptive
408         // mode.  Note that they must use the Cdecl calling convention due to a limitation in our .obj file linking
409         // support.
410         //------------------------------------------------------------------------------------------------------------
411 
412         // Block the current thread until at least one object needs to be finalized (returns true) or
413         // memory is low (returns false and the finalizer thread should initiate a garbage collection).
414         [DllImport(Redhawk.BaseName, CallingConvention = CallingConvention.Cdecl)]
RhpWaitForFinalizerRequest()415         internal static extern UInt32 RhpWaitForFinalizerRequest();
416 
417         // Indicate that the current round of finalizations is complete.
418         [DllImport(Redhawk.BaseName, CallingConvention = CallingConvention.Cdecl)]
RhpSignalFinalizationComplete()419         internal static extern void RhpSignalFinalizationComplete();
420 
421         [DllImport(Redhawk.BaseName, CallingConvention = CallingConvention.Cdecl)]
RhpAcquireCastCacheLock()422         internal static extern void RhpAcquireCastCacheLock();
423 
424         [DllImport(Redhawk.BaseName, CallingConvention = CallingConvention.Cdecl)]
RhpReleaseCastCacheLock()425         internal static extern void RhpReleaseCastCacheLock();
426 
427         [DllImport(Redhawk.BaseName, CallingConvention = CallingConvention.Cdecl)]
PalGetTickCount64()428         internal extern static long PalGetTickCount64();
429 
430         [DllImport(Redhawk.BaseName, CallingConvention = CallingConvention.Cdecl)]
RhpAcquireThunkPoolLock()431         internal static extern void RhpAcquireThunkPoolLock();
432 
433         [DllImport(Redhawk.BaseName, CallingConvention = CallingConvention.Cdecl)]
RhpReleaseThunkPoolLock()434         internal static extern void RhpReleaseThunkPoolLock();
435 
436         [DllImport(Redhawk.BaseName, CallingConvention = CallingConvention.Cdecl)]
RhAllocateThunksMapping()437         internal static extern IntPtr RhAllocateThunksMapping();
438 
439         // Enters a no GC region, possibly doing a blocking GC if there is not enough
440         // memory available to satisfy the caller's request.
441         [DllImport(Redhawk.BaseName, CallingConvention = CallingConvention.Cdecl)]
RhpStartNoGCRegion(Int64 totalSize, bool hasLohSize, Int64 lohSize, bool disallowFullBlockingGC)442         internal static extern Int32 RhpStartNoGCRegion(Int64 totalSize, bool hasLohSize, Int64 lohSize, bool disallowFullBlockingGC);
443 
444         // Exits a no GC region, possibly doing a GC to clean up the garbage that
445         // the caller allocated.
446         [DllImport(Redhawk.BaseName, CallingConvention = CallingConvention.Cdecl)]
RhpEndNoGCRegion()447         internal static extern Int32 RhpEndNoGCRegion();
448     }
449 }
450