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// FCall.H
5//
6
7//
8// FCall is a high-performance alternative to ECall. Unlike ECall, FCall
9// methods do not necessarily create a frame. Jitted code calls directly
10// to the FCall entry point. It is possible to do operations that need
11// to have a frame within an FCall, you need to manually set up the frame
12// before you do such operations.
13
14// It is illegal to cause a GC or EH to happen in an FCALL before setting
15// up a frame. To prevent accidentally violating this rule, FCALLs turn
16// on BEGINGCFORBID, which insures that these things can't happen in a
17// checked build without causing an ASSERTE. Once you set up a frame,
18// this state is turned off as long as the frame is active, and then is
19// turned on again when the frame is torn down. This mechanism should
20// be sufficient to insure that the rules are followed.
21
22// In general you set up a frame by using the following macros
23
24// HELPER_METHOD_FRAME_BEGIN_RET*() // Use If the FCALL has a return value
25// HELPER_METHOD_FRAME_BEGIN*() // Use If FCALL does not return a value
26// HELPER_METHOD_FRAME_END*()
27
28// These macros introduce a scope which is protected by an HelperMethodFrame.
29// In this scope you can do EH or GC. There are rules associated with
30// their use. In particular
31
32// 1) These macros can only be used in the body of a FCALL (that is
33// something using the FCIMPL* or HCIMPL* macros for their decaration.
34
35// 2) You may not perform a 'return' within this scope..
36
37// Compile time errors occur if you try to violate either of these rules.
38
39// The frame that is set up does NOT protect any GC variables (in particular the
40// arguments of the FCALL. Thus you need to do an explicit GCPROTECT once the
41// frame is established if you need to protect an argument. There are flavors
42// of HELPER_METHOD_FRAME that protect a certain number of GC variables. For
43// example
44
45// HELPER_METHOD_FRAME_BEGIN_RET_2(arg1, arg2)
46
47// will protect the GC variables arg1, and arg2 as well as erecting the frame.
48
49// Another invariant that you must be aware of is the need to poll to see if
50// a GC is needed by some other thread. Unless the FCALL is VERY short,
51// every code path through the FCALL must do such a poll. The important
52// thing here is that a poll will cause a GC, and thus you can only do it
53// when all you GC variables are protected. To make things easier
54// HELPER_METHOD_FRAMES that protect things automatically do this poll.
55// If you don't need to protect anything HELPER_METHOD_FRAME_BEGIN_0
56// will also do the poll.
57
58// Sometimes it is convenient to do the poll a the end of the frame, you
59// can use HELPER_METHOD_FRAME_BEGIN_NOPOLL and HELPER_METHOD_FRAME_END_POLL
60// to do the poll at the end. If somewhere in the middle is the best
61// place you can do that too with HELPER_METHOD_POLL()
62
63// You don't need to erect a helper method frame to do a poll. FC_GC_POLL
64// can do this (remember all your GC refs will be trashed).
65
66// Finally if your method is VERY small, you can get away without a poll,
67// you have to use FC_GC_POLL_NOT_NEEDED to mark this.
68// Use sparingly!
69
70// It is possible to set up the frame as the first operation in the FCALL and
71// tear it down as the last operation before returning. This works and is
72// reasonably efficient (as good as an ECall), however, if it is the case that
73// you can defer the setup of the frame to an unlikely code path (exception path)
74// that is much better.
75
76// If you defer setup of the frame, all codepaths leading to the frame setup
77// must be wrapped with PERMIT_HELPER_METHOD_FRAME_BEGIN/END. These block
78// certain compiler optimizations that interfere with the delayed frame setup.
79// These macros are automatically included in the HCIMPL, FCIMPL, and frame
80// setup macros.
81
82// <TODO>TODO: we should have a way of doing a trial allocation (an allocation that
83// will fail if it would cause a GC). That way even FCALLs that need to allocate
84// would not necessarily need to set up a frame. </TODO>
85
86// It is common to only need to set up a frame in order to throw an exception.
87// While this can be done by doing
88
89// HELPER_METHOD_FRAME_BEGIN() // Use if FCALL does not return a value
90// COMPlusThrow(execpt);
91// HELPER_METHOD_FRAME_END()
92
93// It is more efficient (in space) to use convenience macro FCTHROW that does
94// this for you (sets up a frame, and does the throw).
95
96// FCTHROW(except)
97
98// Since FCALLS have to conform to the EE calling conventions and not to C
99// calling conventions, FCALLS, need to be declared using special macros (FCIMPL*)
100// that implement the correct calling conventions. There are variants of these
101// macros depending on the number of args, and sometimes the types of the
102// arguments.
103
104//------------------------------------------------------------------------
105// A very simple example:
106//
107// FCIMPL2(INT32, Div, INT32 x, INT32 y)
108// {
109// if (y == 0)
110// FCThrow(kDivideByZeroException);
111// return x/y;
112// }
113// FCIMPLEND
114//
115//
116// *** WATCH OUT FOR THESE GOTCHAS: ***
117// ------------------------------------
118// - In your FCDECL & FCIMPL protos, don't declare a param as type OBJECTREF
119// or any of its deriveds. This will break on the checked build because
120// __fastcall doesn't enregister C++ objects (which OBJECTREF is).
121// Instead, you need to do something like;
122//
123// FCIMPL(.., .., Object* pObject0)
124// OBJECTREF pObject = ObjectToOBJECTREF(pObject0);
125// FCIMPL
126//
127// For similar reasons, use Object* rather than OBJECTREF as a return type.
128// Consider either using ObjectToOBJECTREF or calling VALIDATEOBJECTREF
129// to make sure your Object* is valid.
130//
131// - FCThrow() must be called directly from your FCall impl function: it
132// cannot be called from a subfunction. Calling from a subfunction breaks
133// the VC code parsing workaround that lets us recover the callee saved registers.
134// Fortunately, you'll get a compile error complaining about an
135// unknown variable "__me".
136//
137// - If your FCall returns VOID, you must use FCThrowVoid() rather than
138// FCThrow(). This is because FCThrow() has to generate an unexecuted
139// "return" statement for the code parser.
140//
141// - On x86, if first and/or second argument of your FCall cannot be passed
142// in either of the __fastcall registers (ECX/EDX), you must use "V" versions
143// of FCDECL and FCIMPL macros to enregister arguments correctly. Some of the
144// most common types that fit this requirement are 64-bit values (i.e. INT64 or
145// UINT64) and floating-point values (i.e. FLOAT or DOUBLE). For example, FCDECL3_IVI
146// must be used for FCalls that take 3 arguments and 2nd argument is INT64 and
147// FDECL2_VV must be used for FCalls that take 2 arguments where both are FLOAT.
148//
149// - You may use structs for protecting multiple OBJECTREF's simultaneously.
150// In these cases, you must use a variant of a helper method frame with PROTECT
151// in the name, to ensure all the OBJECTREF's in the struct get protected.
152// Also, initialize all the OBJECTREF's first. Like this:
153//
154// FCIMPL4(Object*, COMNlsInfo::nativeChangeCaseString, LocaleIDObject* localeUNSAFE,
155// INT_PTR pNativeTextInfo, StringObject* pStringUNSAFE, CLR_BOOL bIsToUpper)
156// {
157// [ignoring CONTRACT for now]
158// struct _gc
159// {
160// STRINGREF pResult;
161// STRINGREF pString;
162// LOCALEIDREF pLocale;
163// } gc;
164// gc.pResult = NULL;
165// gc.pString = ObjectToSTRINGREF(pStringUNSAFE);
166// gc.pLocale = (LOCALEIDREF)ObjectToOBJECTREF(localeUNSAFE);
167//
168// HELPER_METHOD_FRAME_BEGIN_RET_PROTECT(gc)
169//
170// If you forgot the PROTECT part, the macro will only protect the first OBJECTREF,
171// introducing a subtle GC hole in your code. Fortunately, we now issue a
172// compile-time error if you forget.
173
174// How FCall works:
175// ----------------
176// An FCall target uses __fastcall or some other calling convention to
177// match the IL calling convention exactly. Thus, a call to FCall is a direct
178// call to the target w/ no intervening stub or frame.
179//
180// The tricky part is when FCThrow is called. FCThrow must generate
181// a proper method frame before allocating and throwing the exception.
182// To do this, it must recover several things:
183//
184// - The location of the FCIMPL's return address (since that's
185// where the frame will be based.)
186//
187// - The on-entry values of the callee-saved regs; which must
188// be recorded in the frame so that GC can update them.
189// Depending on how VC compiles your FCIMPL, those values are still
190// in the original registers or saved on the stack.
191//
192// To figure out which, FCThrow() generates the code:
193//
194// while (NULL == __FCThrow(__me, ...)) {};
195// return 0;
196//
197// The "return" statement will never execute; but its presence guarantees
198// that VC will follow the __FCThrow() call with a VC epilog
199// that restores the callee-saved registers using a pretty small
200// and predictable set of Intel opcodes. __FCThrow() parses this
201// epilog and simulates its execution to recover the callee saved
202// registers.
203//
204// The while loop is to prevent the compiler from doing tail call optimizations.
205// The helper frame interpretter needs the frame to be present.
206//
207// - The MethodDesc* that this FCall implements. This MethodDesc*
208// is part of the frame and ensures that the FCall will appear
209// in the exception's stack trace. To get this, FCDECL declares
210// a static local __me, initialized to point to the FC target itself.
211// This address is exactly what's stored in the ECall lookup tables;
212// so __FCThrow() simply does a reverse lookup on that table to recover
213// the MethodDesc*.
214//
215
216
217#ifndef __FCall_h__
218#define __FCall_h__
219
220#include "gms.h"
221#include "runtimeexceptionkind.h"
222#include "debugreturn.h"
223#include "stackprobe.h"
224
225//==============================================================================================
226// These macros defeat compiler optimizations that might mix nonvolatile
227// register loads and stores with other code in the function body. This
228// creates problems for the frame setup code, which assumes that any
229// nonvolatiles that are saved at the point of the frame setup will be
230// re-loaded when the frame is popped.
231//
232// Currently this is only known to be an issue on AMD64. It's uncertain
233// whether it is an issue on x86.
234//==============================================================================================
235
236#if defined(_TARGET_AMD64_) && !defined(FEATURE_PAL)
237
238//
239// On AMD64 this is accomplished by including a setjmp anywhere in a function.
240// Doesn't matter whether it is reachable or not, and in fact in optimized
241// builds the setjmp is removed altogether.
242//
243#include <setjmp.h>
244
245//
246// Use of setjmp is temporary, we will eventually have compiler intrinsics to
247// disable the optimizations. Besides, we don't actually execute setjmp in
248// these macros (or anywhere else in the VM on AMD64).
249//
250#pragma warning(disable:4611) // interaction between '_setjmp' and C++ object destruction is non-portable
251
252#ifdef _DEBUG
253//
254// Linked list of unmanaged methods preceeding a HelperMethodFrame push. This
255// is linked onto the current Thread. Each list entry is stack-allocated so it
256// can be associated with an unmanaged frame. Each unmanaged frame needs to be
257// associated with at least one list entry.
258//
259struct HelperMethodFrameCallerList
260{
261 HelperMethodFrameCallerList *pCaller;
262};
263#endif // _DEBUG
264
265//
266// Resets the Thread state at a new managed -> fcall transition.
267//
268class FCallTransitionState
269{
270public:
271
272 FCallTransitionState () NOT_DEBUG({ LIMITED_METHOD_CONTRACT; });
273 ~FCallTransitionState () NOT_DEBUG({ LIMITED_METHOD_CONTRACT; });
274
275#ifdef _DEBUG
276private:
277 Thread *m_pThread;
278 HelperMethodFrameCallerList *m_pPreviousHelperMethodFrameCallerList;
279#endif // _DEBUG
280};
281
282//
283// Pushes/pops state for each caller.
284//
285class PermitHelperMethodFrameState
286{
287public:
288
289 PermitHelperMethodFrameState () NOT_DEBUG({ LIMITED_METHOD_CONTRACT; });
290 ~PermitHelperMethodFrameState () NOT_DEBUG({ LIMITED_METHOD_CONTRACT; });
291
292 static VOID CheckHelperMethodFramePermitted () NOT_DEBUG({ LIMITED_METHOD_CONTRACT; });
293
294#ifdef _DEBUG
295private:
296 Thread *m_pThread;
297 HelperMethodFrameCallerList m_ListEntry;
298#endif // _DEBUG
299};
300
301//
302// Resets the Thread state after the HelperMethodFrame is pushed. At this
303// point, the HelperMethodFrame is capable of unwinding to the managed code,
304// so we can reset the Thread state for any nested fcalls.
305//
306class CompletedFCallTransitionState
307{
308public:
309
310 CompletedFCallTransitionState () NOT_DEBUG({ LIMITED_METHOD_CONTRACT; });
311 ~CompletedFCallTransitionState () NOT_DEBUG({ LIMITED_METHOD_CONTRACT; });
312
313#ifdef _DEBUG
314private:
315
316 HelperMethodFrameCallerList *m_pLastHelperMethodFrameCallerList;
317#endif // _DEBUG
318};
319
320#define PERMIT_HELPER_METHOD_FRAME_BEGIN() \
321 if (1) \
322 { \
323 PermitHelperMethodFrameState ___PermitHelperMethodFrameState;
324
325#define PERMIT_HELPER_METHOD_FRAME_END() \
326 } \
327 else \
328 { \
329 jmp_buf ___jmpbuf; \
330 setjmp(___jmpbuf); \
331 __assume(0); \
332 }
333
334#define FCALL_TRANSITION_BEGIN() \
335 FCallTransitionState ___FCallTransitionState; \
336 PERMIT_HELPER_METHOD_FRAME_BEGIN();
337
338#define FCALL_TRANSITION_END() \
339 PERMIT_HELPER_METHOD_FRAME_END();
340
341#define CHECK_HELPER_METHOD_FRAME_PERMITTED() \
342 PermitHelperMethodFrameState::CheckHelperMethodFramePermitted(); \
343 CompletedFCallTransitionState ___CompletedFCallTransitionState;
344
345#else // unsupported processor
346
347#define PERMIT_HELPER_METHOD_FRAME_BEGIN()
348#define PERMIT_HELPER_METHOD_FRAME_END()
349#define FCALL_TRANSITION_BEGIN()
350#define FCALL_TRANSITION_END()
351#define CHECK_HELPER_METHOD_FRAME_PERMITTED()
352
353#endif // unsupported processor
354
355//==============================================================================================
356// This is where FCThrow ultimately ends up. Never call this directly.
357// Use the FCThrow() macros. __FCThrowArgument is the helper to throw ArgumentExceptions
358// with a resource taken from the managed resource manager.
359//==============================================================================================
360LPVOID __FCThrow(LPVOID me, enum RuntimeExceptionKind reKind, UINT resID, LPCWSTR arg1, LPCWSTR arg2, LPCWSTR arg3);
361LPVOID __FCThrowArgument(LPVOID me, enum RuntimeExceptionKind reKind, LPCWSTR argumentName, LPCWSTR resourceName);
362
363//==============================================================================================
364// FDECLn: A set of macros for generating header declarations for FC targets.
365// Use FIMPLn for the actual body.
366//==============================================================================================
367
368// Note: on the x86, these defs reverse all but the first two arguments
369// (IL stack calling convention is reversed from __fastcall.)
370
371
372// Calling convention for varargs
373#define F_CALL_VA_CONV __cdecl
374
375
376#ifdef _TARGET_X86_
377
378// Choose the appropriate calling convention for FCALL helpers on the basis of the JIT calling convention
379#ifdef __GNUC__
380#define F_CALL_CONV __attribute__((cdecl, regparm(3)))
381
382// GCC fastcall convention (simulated via stdcall) is different from MSVC fastcall convention. GCC can use up
383// to 3 registers to store parameters. The registers used are EAX, EDX, ECX. Dummy parameters and reordering
384// of the actual parameters in the FCALL signature is used to make the calling convention to look like in MSVC.
385#define SWIZZLE_REGARG_ORDER
386#else // __GNUC__
387#define F_CALL_CONV __fastcall
388#endif // !__GNUC__
389
390#define SWIZZLE_STKARG_ORDER
391#else // _TARGET_X86_
392
393//
394// non-x86 platforms don't have messed-up calling convention swizzling
395//
396#define F_CALL_CONV
397#endif // !_TARGET_X86_
398
399#ifdef SWIZZLE_STKARG_ORDER
400#ifdef SWIZZLE_REGARG_ORDER
401
402#define FCDECL0(rettype, funcname) rettype F_CALL_CONV funcname()
403#define FCDECL1(rettype, funcname, a1) rettype F_CALL_CONV funcname(int /* EAX */, int /* EDX */, a1)
404#define FCDECL1_V(rettype, funcname, a1) rettype F_CALL_CONV funcname(int /* EAX */, int /* EDX */, int /* ECX */, a1)
405#define FCDECL2(rettype, funcname, a1, a2) rettype F_CALL_CONV funcname(int /* EAX */, a2, a1)
406#define FCDECL2VA(rettype, funcname, a1, a2) rettype F_CALL_VA_CONV funcname(a1, a2, ...)
407#define FCDECL2_VV(rettype, funcname, a1, a2) rettype F_CALL_CONV funcname(int /* EAX */, int /* EDX */, int /* ECX */, a2, a1)
408#define FCDECL2_VI(rettype, funcname, a1, a2) rettype F_CALL_CONV funcname(int /* EAX */, int /* EDX */, a2, a1)
409#define FCDECL2_IV(rettype, funcname, a1, a2) rettype F_CALL_CONV funcname(int /* EAX */, int /* EDX */, a1, a2)
410#define FCDECL3(rettype, funcname, a1, a2, a3) rettype F_CALL_CONV funcname(int /* EAX */, a2, a1, a3)
411#define FCDECL3_IIV(rettype, funcname, a1, a2, a3) rettype F_CALL_CONV funcname(int /* EAX */, a2, a1, a3)
412#define FCDECL3_VII(rettype, funcname, a1, a2, a3) rettype F_CALL_CONV funcname(int /* EAX */, a3, a2, a1)
413#define FCDECL3_IVV(rettype, funcname, a1, a2, a3) rettype F_CALL_CONV funcname(int /* EAX */, int /* EDX */, a1, a3, a2)
414#define FCDECL3_IVI(rettype, funcname, a1, a2, a3) rettype F_CALL_CONV funcname(int /* EAX */, a3, a1, a2)
415#define FCDECL3_VVI(rettype, funcname, a1, a2, a3) rettype F_CALL_CONV funcname(int /* EAX */, int /* EDX */, a3, a2, a1)
416#define FCDECL3_VVV(rettype, funcname, a1, a2, a3) rettype F_CALL_CONV funcname(int /* EAX */, int /* EDX */, int /* ECX */, a3, a2, a1)
417#define FCDECL4(rettype, funcname, a1, a2, a3, a4) rettype F_CALL_CONV funcname(int /* EAX */, a2, a1, a4, a3)
418#define FCDECL5(rettype, funcname, a1, a2, a3, a4, a5) rettype F_CALL_CONV funcname(int /* EAX */, a2, a1, a5, a4, a3)
419#define FCDECL6(rettype, funcname, a1, a2, a3, a4, a5, a6) rettype F_CALL_CONV funcname(int /* EAX */, a2, a1, a6, a5, a4, a3)
420#define FCDECL7(rettype, funcname, a1, a2, a3, a4, a5, a6, a7) rettype F_CALL_CONV funcname(int /* EAX */, a2, a1, a7, a6, a5, a4, a3)
421#define FCDECL8(rettype, funcname, a1, a2, a3, a4, a5, a6, a7, a8) rettype F_CALL_CONV funcname(int /* EAX */, a2, a1, a8, a7, a6, a5, a4, a3)
422#define FCDECL9(rettype, funcname, a1, a2, a3, a4, a5, a6, a7, a8, a9) rettype F_CALL_CONV funcname(int /* EAX */, a2, a1, a9, a8, a7, a6, a5, a4, a3)
423#define FCDECL10(rettype,funcname, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10) rettype F_CALL_CONV funcname(int /* EAX */, a2, a1, a10, a9, a8, a7, a6, a5, a4, a3)
424#define FCDECL11(rettype,funcname, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11) rettype F_CALL_CONV funcname(int /* EAX */, a2, a1, a11, a10, a9, a8, a7, a6, a5, a4, a3)
425#define FCDECL12(rettype,funcname, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12) rettype F_CALL_CONV funcname(int /* EAX */, a2, a1, a12, a11, a10, a9, a8, a7, a6, a5, a4, a3)
426#define FCDECL13(rettype,funcname, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13) rettype F_CALL_CONV funcname(int /* EAX */, a2, a1, a13, a12, a11, a10, a9, a8, a7, a6, a5, a4, a3)
427#define FCDECL14(rettype,funcname, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14) rettype F_CALL_CONV funcname(int /* EAX */, a2, a1, a14, a13, a12, a11, a10, a9, a8, a7, a6, a5, a4, a3)
428
429#define FCDECL5_IVI(rettype, funcname, a1, a2, a3, a4, a5) rettype F_CALL_CONV funcname(int /* EAX */, a3, a1, a5, a4, a2)
430#define FCDECL5_VII(rettype, funcname, a1, a2, a3, a4, a5) rettype F_CALL_CONV funcname(int /* EAX */, a3, a2, a5, a4, a1)
431
432#else // SWIZZLE_REGARG_ORDER
433
434#define FCDECL0(rettype, funcname) rettype F_CALL_CONV funcname()
435#define FCDECL1(rettype, funcname, a1) rettype F_CALL_CONV funcname(a1)
436#define FCDECL1_V(rettype, funcname, a1) rettype F_CALL_CONV funcname(a1)
437#define FCDECL2(rettype, funcname, a1, a2) rettype F_CALL_CONV funcname(a1, a2)
438#define FCDECL2VA(rettype, funcname, a1, a2) rettype F_CALL_VA_CONV funcname(a1, a2, ...)
439#define FCDECL2_VV(rettype, funcname, a1, a2) rettype F_CALL_CONV funcname(a2, a1)
440#define FCDECL2_VI(rettype, funcname, a1, a2) rettype F_CALL_CONV funcname(a2, a1)
441#define FCDECL2_IV(rettype, funcname, a1, a2) rettype F_CALL_CONV funcname(a1, a2)
442#define FCDECL3(rettype, funcname, a1, a2, a3) rettype F_CALL_CONV funcname(a1, a2, a3)
443#define FCDECL3_IIV(rettype, funcname, a1, a2, a3) rettype F_CALL_CONV funcname(a1, a2, a3)
444#define FCDECL3_VII(rettype, funcname, a1, a2, a3) rettype F_CALL_CONV funcname(a2, a3, a1)
445#define FCDECL3_IVV(rettype, funcname, a1, a2, a3) rettype F_CALL_CONV funcname(a1, a3, a2)
446#define FCDECL3_IVI(rettype, funcname, a1, a2, a3) rettype F_CALL_CONV funcname(a1, a3, a2)
447#define FCDECL3_VVI(rettype, funcname, a1, a2, a3) rettype F_CALL_CONV funcname(a2, a1, a3)
448#define FCDECL3_VVV(rettype, funcname, a1, a2, a3) rettype F_CALL_CONV funcname(a3, a2, a1)
449#define FCDECL4(rettype, funcname, a1, a2, a3, a4) rettype F_CALL_CONV funcname(a1, a2, a4, a3)
450#define FCDECL5(rettype, funcname, a1, a2, a3, a4, a5) rettype F_CALL_CONV funcname(a1, a2, a5, a4, a3)
451#define FCDECL6(rettype, funcname, a1, a2, a3, a4, a5, a6) rettype F_CALL_CONV funcname(a1, a2, a6, a5, a4, a3)
452#define FCDECL7(rettype, funcname, a1, a2, a3, a4, a5, a6, a7) rettype F_CALL_CONV funcname(a1, a2, a7, a6, a5, a4, a3)
453#define FCDECL8(rettype, funcname, a1, a2, a3, a4, a5, a6, a7, a8) rettype F_CALL_CONV funcname(a1, a2, a8, a7, a6, a5, a4, a3)
454#define FCDECL9(rettype, funcname, a1, a2, a3, a4, a5, a6, a7, a8, a9) rettype F_CALL_CONV funcname(a1, a2, a9, a8, a7, a6, a5, a4, a3)
455#define FCDECL10(rettype,funcname, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10) rettype F_CALL_CONV funcname(a1, a2, a10, a9, a8, a7, a6, a5, a4, a3)
456#define FCDECL11(rettype,funcname, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11) rettype F_CALL_CONV funcname(a1, a2, a11, a10, a9, a8, a7, a6, a5, a4, a3)
457#define FCDECL12(rettype,funcname, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12) rettype F_CALL_CONV funcname(a1, a2, a12, a11, a10, a9, a8, a7, a6, a5, a4, a3)
458#define FCDECL13(rettype,funcname, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13) rettype F_CALL_CONV funcname(a1, a2, a13, a12, a11, a10, a9, a8, a7, a6, a5, a4, a3)
459#define FCDECL14(rettype,funcname, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14) rettype F_CALL_CONV funcname(a1, a2, a14, a13, a12, a11, a10, a9, a8, a7, a6, a5, a4, a3)
460
461#define FCDECL5_IVI(rettype, funcname, a1, a2, a3, a4, a5) rettype F_CALL_CONV funcname(a1, a3, a5, a4, a2)
462#define FCDECL5_VII(rettype, funcname, a1, a2, a3, a4, a5) rettype F_CALL_CONV funcname(a2, a3, a5, a4, a1)
463
464#endif // !SWIZZLE_REGARG_ORDER
465
466#if 0
467//
468// don't use something like this... directly calling an FCALL from within the runtime breaks stackwalking because
469// the FCALL reverse mapping only gets established in ECall::GetFCallImpl and that codepath is circumvented by
470// directly calling and FCALL
471// See below for usage of FC_CALL_INNER (used in SecurityStackWalk::Check presently)
472//
473#define FCCALL0(funcname) funcname()
474#define FCCALL1(funcname, a1) funcname(a1)
475#define FCCALL2(funcname, a1, a2) funcname(a1, a2)
476#define FCCALL3(funcname, a1, a2, a3) funcname(a1, a2, a3)
477#define FCCALL4(funcname, a1, a2, a3, a4) funcname(a1, a2, a4, a3)
478#define FCCALL5(funcname, a1, a2, a3, a4, a5) funcname(a1, a2, a5, a4, a3)
479#define FCCALL6(funcname, a1, a2, a3, a4, a5, a6) funcname(a1, a2, a6, a5, a4, a3)
480#define FCCALL7(funcname, a1, a2, a3, a4, a5, a6, a7) funcname(a1, a2, a7, a6, a5, a4, a3)
481#define FCCALL8(funcname, a1, a2, a3, a4, a5, a6, a7, a8) funcname(a1, a2, a8, a7, a6, a5, a4, a3)
482#define FCCALL9(funcname, a1, a2, a3, a4, a5, a6, a7, a8, a9) funcname(a1, a2, a9, a8, a7, a6, a5, a4, a3)
483#define FCCALL10(funcname, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10) funcname(a1, a2, a10, a9, a8, a7, a6, a5, a4, a3)
484#define FCCALL11(funcname, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11) funcname(a1, a2, a11, a10, a9, a8, a7, a6, a5, a4, a3)
485#define FCCALL12(funcname, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12) funcname(a1, a2, a12, a11, a10, a9, a8, a7, a6, a5, a4, a3)
486#endif // 0
487
488#else // !SWIZZLE_STKARG_ORDER
489
490#define FCDECL0(rettype, funcname) rettype F_CALL_CONV funcname()
491#define FCDECL1(rettype, funcname, a1) rettype F_CALL_CONV funcname(a1)
492#define FCDECL1_V(rettype, funcname, a1) rettype F_CALL_CONV funcname(a1)
493#define FCDECL2(rettype, funcname, a1, a2) rettype F_CALL_CONV funcname(a1, a2)
494#define FCDECL2VA(rettype, funcname, a1, a2) rettype F_CALL_CONV funcname(a1, a2, ...)
495#define FCDECL2_VV(rettype, funcname, a1, a2) rettype F_CALL_CONV funcname(a1, a2)
496#define FCDECL2_VI(rettype, funcname, a1, a2) rettype F_CALL_CONV funcname(a1, a2)
497#define FCDECL2_IV(rettype, funcname, a1, a2) rettype F_CALL_CONV funcname(a1, a2)
498#define FCDECL3(rettype, funcname, a1, a2, a3) rettype F_CALL_CONV funcname(a1, a2, a3)
499#define FCDECL3_IIV(rettype, funcname, a1, a2, a3) rettype F_CALL_CONV funcname(a1, a2, a3)
500#define FCDECL3_VII(rettype, funcname, a1, a2, a3) rettype F_CALL_CONV funcname(a1, a2, a3)
501#define FCDECL3_IVV(rettype, funcname, a1, a2, a3) rettype F_CALL_CONV funcname(a1, a2, a3)
502#define FCDECL3_IVI(rettype, funcname, a1, a2, a3) rettype F_CALL_CONV funcname(a1, a2, a3)
503#define FCDECL3_VVI(rettype, funcname, a1, a2, a3) rettype F_CALL_CONV funcname(a1, a2, a3)
504#define FCDECL3_VVV(rettype, funcname, a1, a2, a3) rettype F_CALL_CONV funcname(a1, a2, a3)
505#define FCDECL4(rettype, funcname, a1, a2, a3, a4) rettype F_CALL_CONV funcname(a1, a2, a3, a4)
506#define FCDECL5(rettype, funcname, a1, a2, a3, a4, a5) rettype F_CALL_CONV funcname(a1, a2, a3, a4, a5)
507#define FCDECL6(rettype, funcname, a1, a2, a3, a4, a5, a6) rettype F_CALL_CONV funcname(a1, a2, a3, a4, a5, a6)
508#define FCDECL7(rettype, funcname, a1, a2, a3, a4, a5, a6, a7) rettype F_CALL_CONV funcname(a1, a2, a3, a4, a5, a6, a7)
509#define FCDECL8(rettype, funcname, a1, a2, a3, a4, a5, a6, a7, a8) rettype F_CALL_CONV funcname(a1, a2, a3, a4, a5, a6, a7, a8)
510#define FCDECL9(rettype, funcname, a1, a2, a3, a4, a5, a6, a7, a8, a9) rettype F_CALL_CONV funcname(a1, a2, a3, a4, a5, a6, a7, a8, a9)
511#define FCDECL10(rettype,funcname, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10) rettype F_CALL_CONV funcname(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10)
512#define FCDECL11(rettype,funcname, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11) rettype F_CALL_CONV funcname(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11)
513#define FCDECL12(rettype,funcname, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12) rettype F_CALL_CONV funcname(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12)
514#define FCDECL13(rettype,funcname, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13) rettype F_CALL_CONV funcname(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13)
515#define FCDECL14(rettype,funcname, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14) rettype F_CALL_CONV funcname(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14)
516
517#define FCDECL5_IVI(rettype, funcname, a1, a2, a3, a4, a5) rettype F_CALL_CONV funcname(a1, a2, a3, a4, a5)
518#define FCDECL5_VII(rettype, funcname, a1, a2, a3, a4, a5) rettype F_CALL_CONV funcname(a1, a2, a3, a4, a5)
519
520#endif // !SWIZZLE_STKARG_ORDER
521
522#define HELPER_FRAME_DECL(x) FrameWithCookie<HelperMethodFrame_##x##OBJ> __helperframe
523
524// use the capture state machinery if the architecture has one
525//
526// For a normal build we create a loop (see explaination on RestoreState below)
527// We don't want a loop here for PREFAST since that causes
528// warning 263: Using _alloca in a loop
529// And we can't use DEBUG_OK_TO_RETURN for PREFAST because the PREFAST version
530// requires that you already be in a DEBUG_ASSURE_NO_RETURN_BEGIN scope
531
532#define HelperMethodFrame_0OBJ HelperMethodFrame
533#define HELPER_FRAME_ARGS(attribs) __me, attribs
534#define FORLAZYMACHSTATE(x) x
535
536#if defined(_PREFAST_)
537 #define FORLAZYMACHSTATE_BEGINLOOP(x) x
538 #define FORLAZYMACHSTATE_ENDLOOP(x)
539 #define FORLAZYMACHSTATE_DEBUG_OK_TO_RETURN_BEGIN
540 #define FORLAZYMACHSTATE_DEBUG_OK_TO_RETURN_END
541#else
542 #define FORLAZYMACHSTATE_BEGINLOOP(x) x do
543 #define FORLAZYMACHSTATE_ENDLOOP(x) while(x)
544 #define FORLAZYMACHSTATE_DEBUG_OK_TO_RETURN_BEGIN DEBUG_OK_TO_RETURN_BEGIN(LAZYMACHSTATE)
545 #define FORLAZYMACHSTATE_DEBUG_OK_TO_RETURN_END DEBUG_OK_TO_RETURN_END(LAZYMACHSTATE)
546#endif
547
548// BEGIN: before gcpoll
549//FCallGCCanTriggerNoDtor __fcallGcCanTrigger;
550//__fcallGcCanTrigger.Enter();
551
552// END: after gcpoll
553//__fcallGcCanTrigger.Leave(__FUNCTION__, __FILE__, __LINE__);
554
555// We have to put DEBUG_OK_TO_RETURN_BEGIN around the FORLAZYMACHSTATE
556// to allow the HELPER_FRAME to be installed inside an SO_INTOLERANT region
557// which does not allow a return. The return is used by FORLAZYMACHSTATE
558// to capture the state, but is not an actual return, so it is ok.
559#define HELPER_METHOD_FRAME_BEGIN_EX_BODY(ret, helperFrame, gcpoll, allowGC) \
560 FORLAZYMACHSTATE_BEGINLOOP(int alwaysZero = 0;) \
561 { \
562 INDEBUG(static BOOL __haveCheckedRestoreState = FALSE;) \
563 PERMIT_HELPER_METHOD_FRAME_BEGIN(); \
564 CHECK_HELPER_METHOD_FRAME_PERMITTED(); \
565 helperFrame; \
566 FORLAZYMACHSTATE_DEBUG_OK_TO_RETURN_BEGIN; \
567 FORLAZYMACHSTATE(CAPTURE_STATE(__helperframe.MachineState(), ret);) \
568 FORLAZYMACHSTATE_DEBUG_OK_TO_RETURN_END; \
569 INDEBUG(__helperframe.SetAddrOfHaveCheckedRestoreState(&__haveCheckedRestoreState)); \
570 DEBUG_ASSURE_NO_RETURN_BEGIN(HELPER_METHOD_FRAME); \
571 INCONTRACT(FCallGCCanTrigger::Enter()); \
572 __helperframe.Push(); \
573 MAKE_CURRENT_THREAD_AVAILABLE_EX(__helperframe.GetThread()); \
574
575#define HELPER_METHOD_FRAME_BEGIN_EX(ret, helperFrame, gcpoll, allowGC) \
576 HELPER_METHOD_FRAME_BEGIN_EX_BODY(ret, helperFrame, gcpoll, allowGC) \
577 TESTHOOKCALL(AppDomainCanBeUnloaded(GET_THREAD()->GetDomain()->GetId().m_dwId,!allowGC)); \
578 /* <TODO>TODO TURN THIS ON!!! </TODO> */ \
579 /* gcpoll; */ \
580 INSTALL_MANAGED_EXCEPTION_DISPATCHER; \
581 INSTALL_UNWIND_AND_CONTINUE_HANDLER_FOR_HMF(&__helperframe);
582
583#define HELPER_METHOD_FRAME_BEGIN_EX_NOTHROW(ret, helperFrame, gcpoll, allowGC, probeFailExpr) \
584 HELPER_METHOD_FRAME_BEGIN_EX_BODY(ret, helperFrame, gcpoll, allowGC) \
585 /* <TODO>TODO TURN THIS ON!!! </TODO> */ \
586 /* gcpoll; */ \
587 BEGIN_SO_INTOLERANT_CODE_NOTHROW(GET_THREAD(), probeFailExpr);
588
589
590// The while(__helperframe.RestoreState() needs a bit of explanation.
591// The issue is insuring that the same machine state (which registers saved)
592// exists when the machine state is probed (when the frame is created, and
593// when it is actually used (when the frame is popped. We do this by creating
594// a flow of control from use to def. Note that 'RestoreState' always returns false
595// we never actually loop, but the compiler does not know that, and thus
596// will be forced to make the keep the state of register spills the same at
597// the two locations.
598
599#define HELPER_METHOD_FRAME_END_EX_BODY(gcpoll,allowGC) \
600 /* <TODO>TODO TURN THIS ON!!! </TODO> */ \
601 /* gcpoll; */ \
602 __helperframe.Pop(); \
603 DEBUG_ASSURE_NO_RETURN_END(HELPER_METHOD_FRAME); \
604 INCONTRACT(FCallGCCanTrigger::Leave(__FUNCTION__, __FILE__, __LINE__)); \
605 FORLAZYMACHSTATE(alwaysZero = \
606 HelperMethodFrameRestoreState(INDEBUG_COMMA(&__helperframe) \
607 __helperframe.MachineState());) \
608 PERMIT_HELPER_METHOD_FRAME_END() \
609 } FORLAZYMACHSTATE_ENDLOOP(alwaysZero);
610
611#define HELPER_METHOD_FRAME_END_EX(gcpoll,allowGC) \
612 UNINSTALL_UNWIND_AND_CONTINUE_HANDLER; \
613 UNINSTALL_MANAGED_EXCEPTION_DISPATCHER; \
614 TESTHOOKCALL(AppDomainCanBeUnloaded(GET_THREAD()->GetDomain()->GetId().m_dwId,!allowGC)); \
615 HELPER_METHOD_FRAME_END_EX_BODY(gcpoll,allowGC);
616
617#define HELPER_METHOD_FRAME_END_EX_NOTHROW(gcpoll,allowGC) \
618 END_SO_INTOLERANT_CODE; \
619 HELPER_METHOD_FRAME_END_EX_BODY(gcpoll,allowGC);
620
621#define HELPER_METHOD_FRAME_BEGIN_ATTRIB(attribs) \
622 HELPER_METHOD_FRAME_BEGIN_EX( \
623 return, \
624 HELPER_FRAME_DECL(0)(HELPER_FRAME_ARGS(attribs)), \
625 HELPER_METHOD_POLL(),TRUE)
626
627#define HELPER_METHOD_FRAME_BEGIN_0() \
628 HELPER_METHOD_FRAME_BEGIN_ATTRIB(Frame::FRAME_ATTR_NONE)
629
630#define HELPER_METHOD_FRAME_BEGIN_ATTRIB_NOPOLL(attribs) \
631 HELPER_METHOD_FRAME_BEGIN_EX( \
632 return, \
633 HELPER_FRAME_DECL(0)(HELPER_FRAME_ARGS(attribs)), \
634 {},FALSE)
635
636#define HELPER_METHOD_FRAME_BEGIN_NOPOLL() HELPER_METHOD_FRAME_BEGIN_ATTRIB_NOPOLL(Frame::FRAME_ATTR_NONE)
637
638#define HELPER_METHOD_FRAME_BEGIN_ATTRIB_1(attribs, arg1) \
639 static_assert(sizeof(arg1) == sizeof(OBJECTREF), "GC protecting structs of multiple OBJECTREFs requires a PROTECT variant of the HELPER METHOD FRAME macro");\
640 HELPER_METHOD_FRAME_BEGIN_EX( \
641 return, \
642 HELPER_FRAME_DECL(1)(HELPER_FRAME_ARGS(attribs), \
643 (OBJECTREF*) &arg1), \
644 HELPER_METHOD_POLL(),TRUE)
645
646#define HELPER_METHOD_FRAME_BEGIN_1(arg1) HELPER_METHOD_FRAME_BEGIN_ATTRIB_1(Frame::FRAME_ATTR_NONE, arg1)
647
648#define HELPER_METHOD_FRAME_BEGIN_ATTRIB_2(attribs, arg1, arg2) \
649 static_assert(sizeof(arg1) == sizeof(OBJECTREF), "GC protecting structs of multiple OBJECTREFs requires a PROTECT variant of the HELPER METHOD FRAME macro");\
650 static_assert(sizeof(arg2) == sizeof(OBJECTREF), "GC protecting structs of multiple OBJECTREFs requires a PROTECT variant of the HELPER METHOD FRAME macro");\
651 HELPER_METHOD_FRAME_BEGIN_EX( \
652 return, \
653 HELPER_FRAME_DECL(2)(HELPER_FRAME_ARGS(attribs), \
654 (OBJECTREF*) &arg1, (OBJECTREF*) &arg2), \
655 HELPER_METHOD_POLL(),TRUE)
656
657#define HELPER_METHOD_FRAME_BEGIN_2(arg1, arg2) HELPER_METHOD_FRAME_BEGIN_ATTRIB_2(Frame::FRAME_ATTR_NONE, arg1, arg2)
658
659#define HELPER_METHOD_FRAME_BEGIN_ATTRIB_3(attribs, arg1, arg2, arg3) \
660 static_assert(sizeof(arg1) == sizeof(OBJECTREF), "GC protecting structs of multiple OBJECTREFs requires a PROTECT variant of the HELPER METHOD FRAME macro");\
661 static_assert(sizeof(arg2) == sizeof(OBJECTREF), "GC protecting structs of multiple OBJECTREFs requires a PROTECT variant of the HELPER METHOD FRAME macro");\
662 static_assert(sizeof(arg3) == sizeof(OBJECTREF), "GC protecting structs of multiple OBJECTREFs requires a PROTECT variant of the HELPER METHOD FRAME macro");\
663 HELPER_METHOD_FRAME_BEGIN_EX( \
664 return, \
665 HELPER_FRAME_DECL(3)(HELPER_FRAME_ARGS(attribs), \
666 (OBJECTREF*) &arg1, (OBJECTREF*) &arg2, (OBJECTREF*) &arg3), \
667 HELPER_METHOD_POLL(),TRUE)
668
669#define HELPER_METHOD_FRAME_BEGIN_3(arg1, arg2, arg3) HELPER_METHOD_FRAME_BEGIN_ATTRIB_3(Frame::FRAME_ATTR_NONE, arg1, arg2, arg3)
670
671#define HELPER_METHOD_FRAME_BEGIN_PROTECT(gc) \
672 HELPER_METHOD_FRAME_BEGIN_EX( \
673 return, \
674 HELPER_FRAME_DECL(PROTECT)(HELPER_FRAME_ARGS(Frame::FRAME_ATTR_NONE), \
675 (OBJECTREF*)&(gc), sizeof(gc)/sizeof(OBJECTREF)), \
676 HELPER_METHOD_POLL(),TRUE)
677
678#define HELPER_METHOD_FRAME_BEGIN_RET_ATTRIB_NOPOLL(attribs) \
679 HELPER_METHOD_FRAME_BEGIN_EX( \
680 return 0, \
681 HELPER_FRAME_DECL(0)(HELPER_FRAME_ARGS(attribs)), \
682 {},FALSE)
683
684#define HELPER_METHOD_FRAME_BEGIN_RET_VC_ATTRIB_NOPOLL(attribs) \
685 HELPER_METHOD_FRAME_BEGIN_EX( \
686 FC_RETURN_VC(), \
687 HELPER_FRAME_DECL(0)(HELPER_FRAME_ARGS(attribs)), \
688 {},FALSE)
689
690#define HELPER_METHOD_FRAME_BEGIN_RET_ATTRIB(attribs) \
691 HELPER_METHOD_FRAME_BEGIN_EX( \
692 return 0, \
693 HELPER_FRAME_DECL(0)(HELPER_FRAME_ARGS(attribs)), \
694 HELPER_METHOD_POLL(),TRUE)
695
696#define HELPER_METHOD_FRAME_BEGIN_RET_0() \
697 HELPER_METHOD_FRAME_BEGIN_RET_ATTRIB(Frame::FRAME_ATTR_NONE)
698
699#define HELPER_METHOD_FRAME_BEGIN_RET_VC_0() \
700 HELPER_METHOD_FRAME_BEGIN_EX( \
701 FC_RETURN_VC(), \
702 HELPER_FRAME_DECL(0)(HELPER_FRAME_ARGS(Frame::FRAME_ATTR_NONE)), \
703 HELPER_METHOD_POLL(),TRUE)
704
705#define HELPER_METHOD_FRAME_BEGIN_RET_ATTRIB_1(attribs, arg1) \
706 static_assert(sizeof(arg1) == sizeof(OBJECTREF), "GC protecting structs of multiple OBJECTREFs requires a PROTECT variant of the HELPER METHOD FRAME macro");\
707 HELPER_METHOD_FRAME_BEGIN_EX( \
708 return 0, \
709 HELPER_FRAME_DECL(1)(HELPER_FRAME_ARGS(attribs), \
710 (OBJECTREF*) &arg1), \
711 HELPER_METHOD_POLL(),TRUE)
712
713#define HELPER_METHOD_FRAME_BEGIN_RET_NOTHROW_1(probeFailExpr, arg1) \
714 static_assert(sizeof(arg1) == sizeof(OBJECTREF), "GC protecting structs of multiple OBJECTREFs requires a PROTECT variant of the HELPER METHOD FRAME macro");\
715 HELPER_METHOD_FRAME_BEGIN_EX_NOTHROW( \
716 return 0, \
717 HELPER_FRAME_DECL(1)(HELPER_FRAME_ARGS(Frame::FRAME_ATTR_NO_THREAD_ABORT), \
718 (OBJECTREF*) &arg1), \
719 HELPER_METHOD_POLL(), TRUE, probeFailExpr)
720
721#define HELPER_METHOD_FRAME_BEGIN_RET_VC_ATTRIB_1(attribs, arg1) \
722 static_assert(sizeof(arg1) == sizeof(OBJECTREF), "GC protecting structs of multiple OBJECTREFs requires a PROTECT variant of the HELPER METHOD FRAME macro");\
723 HELPER_METHOD_FRAME_BEGIN_EX( \
724 FC_RETURN_VC(), \
725 HELPER_FRAME_DECL(1)(HELPER_FRAME_ARGS(attribs), \
726 (OBJECTREF*) &arg1), \
727 HELPER_METHOD_POLL(),TRUE)
728
729#define HELPER_METHOD_FRAME_BEGIN_RET_ATTRIB_2(attribs, arg1, arg2) \
730 static_assert(sizeof(arg1) == sizeof(OBJECTREF), "GC protecting structs of multiple OBJECTREFs requires a PROTECT variant of the HELPER METHOD FRAME macro");\
731 static_assert(sizeof(arg2) == sizeof(OBJECTREF), "GC protecting structs of multiple OBJECTREFs requires a PROTECT variant of the HELPER METHOD FRAME macro");\
732 HELPER_METHOD_FRAME_BEGIN_EX( \
733 return 0, \
734 HELPER_FRAME_DECL(2)(HELPER_FRAME_ARGS(attribs), \
735 (OBJECTREF*) &arg1, (OBJECTREF*) &arg2), \
736 HELPER_METHOD_POLL(),TRUE)
737
738#define HELPER_METHOD_FRAME_BEGIN_RET_VC_ATTRIB_2(attribs, arg1, arg2) \
739 static_assert(sizeof(arg1) == sizeof(OBJECTREF), "GC protecting structs of multiple OBJECTREFs requires a PROTECT variant of the HELPER METHOD FRAME macro");\
740 static_assert(sizeof(arg2) == sizeof(OBJECTREF), "GC protecting structs of multiple OBJECTREFs requires a PROTECT variant of the HELPER METHOD FRAME macro");\
741 HELPER_METHOD_FRAME_BEGIN_EX( \
742 FC_RETURN_VC(), \
743 HELPER_FRAME_DECL(2)(HELPER_FRAME_ARGS(attribs), \
744 (OBJECTREF*) &arg1, (OBJECTREF*) &arg2), \
745 HELPER_METHOD_POLL(),TRUE)
746
747#define HELPER_METHOD_FRAME_BEGIN_RET_ATTRIB_PROTECT(attribs, gc) \
748 HELPER_METHOD_FRAME_BEGIN_EX( \
749 return 0, \
750 HELPER_FRAME_DECL(PROTECT)(HELPER_FRAME_ARGS(attribs), \
751 (OBJECTREF*)&(gc), sizeof(gc)/sizeof(OBJECTREF)), \
752 HELPER_METHOD_POLL(),TRUE)
753
754#define HELPER_METHOD_FRAME_BEGIN_RET_VC_NOPOLL() \
755 HELPER_METHOD_FRAME_BEGIN_RET_VC_ATTRIB_NOPOLL(Frame::FRAME_ATTR_NONE)
756
757#define HELPER_METHOD_FRAME_BEGIN_RET_NOPOLL() \
758 HELPER_METHOD_FRAME_BEGIN_RET_ATTRIB_NOPOLL(Frame::FRAME_ATTR_NONE)
759
760#define HELPER_METHOD_FRAME_BEGIN_RET_1(arg1) \
761 static_assert(sizeof(arg1) == sizeof(OBJECTREF), "GC protecting structs of multiple OBJECTREFs requires a PROTECT variant of the HELPER METHOD FRAME macro");\
762 HELPER_METHOD_FRAME_BEGIN_RET_ATTRIB_1(Frame::FRAME_ATTR_NONE, arg1)
763
764#define HELPER_METHOD_FRAME_BEGIN_RET_VC_1(arg1) \
765 static_assert(sizeof(arg1) == sizeof(OBJECTREF), "GC protecting structs of multiple OBJECTREFs requires a PROTECT variant of the HELPER METHOD FRAME macro");\
766 HELPER_METHOD_FRAME_BEGIN_RET_VC_ATTRIB_1(Frame::FRAME_ATTR_NONE, arg1)
767
768#define HELPER_METHOD_FRAME_BEGIN_RET_2(arg1, arg2) \
769 static_assert(sizeof(arg1) == sizeof(OBJECTREF), "GC protecting structs of multiple OBJECTREFs requires a PROTECT variant of the HELPER METHOD FRAME macro");\
770 static_assert(sizeof(arg2) == sizeof(OBJECTREF), "GC protecting structs of multiple OBJECTREFs requires a PROTECT variant of the HELPER METHOD FRAME macro");\
771 HELPER_METHOD_FRAME_BEGIN_RET_ATTRIB_2(Frame::FRAME_ATTR_NONE, arg1, arg2)
772
773#define HELPER_METHOD_FRAME_BEGIN_RET_VC_2(arg1, arg2) \
774 static_assert(sizeof(arg1) == sizeof(OBJECTREF), "GC protecting structs of multiple OBJECTREFs requires a PROTECT variant of the HELPER METHOD FRAME macro");\
775 static_assert(sizeof(arg2) == sizeof(OBJECTREF), "GC protecting structs of multiple OBJECTREFs requires a PROTECT variant of the HELPER METHOD FRAME macro");\
776 HELPER_METHOD_FRAME_BEGIN_RET_VC_ATTRIB_2(Frame::FRAME_ATTR_NONE, arg1, arg2)
777
778#define HELPER_METHOD_FRAME_BEGIN_RET_PROTECT(gc) \
779 HELPER_METHOD_FRAME_BEGIN_RET_ATTRIB_PROTECT(Frame::FRAME_ATTR_NONE, gc)
780
781
782#define HELPER_METHOD_FRAME_END() HELPER_METHOD_FRAME_END_EX({},FALSE)
783#define HELPER_METHOD_FRAME_END_POLL() HELPER_METHOD_FRAME_END_EX(HELPER_METHOD_POLL(),TRUE)
784#define HELPER_METHOD_FRAME_END_NOTHROW()HELPER_METHOD_FRAME_END_EX_NOTHROW({},FALSE)
785
786// This is the fastest way to do a GC poll if you have already erected a HelperMethodFrame
787#define HELPER_METHOD_POLL() { __helperframe.Poll(); INCONTRACT(__fCallCheck.SetDidPoll()); }
788
789// The HelperMethodFrame knows how to get its return address. Let other code get at it, too.
790// (Uses comma operator to call InsureInit & discard result.
791#define HELPER_METHOD_FRAME_GET_RETURN_ADDRESS() \
792 ( static_cast<UINT_PTR>( (__helperframe.InsureInit(false, NULL)), (__helperframe.MachineState()->GetRetAddr()) ) )
793
794 // Very short routines, or routines that are guarenteed to force GC or EH
795 // don't need to poll the GC. USE VERY SPARINGLY!!!
796#define FC_GC_POLL_NOT_NEEDED() INCONTRACT(__fCallCheck.SetNotNeeded())
797
798Object* FC_GCPoll(void* me, Object* objToProtect = NULL);
799
800#define FC_GC_POLL_EX(ret) \
801 { \
802 INCONTRACT(Thread::TriggersGC(GetThread());) \
803 INCONTRACT(__fCallCheck.SetDidPoll();) \
804 if (g_TrapReturningThreads.LoadWithoutBarrier()) \
805 { \
806 if (FC_GCPoll(__me)) \
807 return ret; \
808 while (0 == FC_NO_TAILCALL) { }; /* side effect the compile can't remove */ \
809 } \
810 }
811
812#define FC_GC_POLL() FC_GC_POLL_EX(;)
813#define FC_GC_POLL_RET() FC_GC_POLL_EX(0)
814
815#define FC_GC_POLL_AND_RETURN_OBJREF(obj) \
816 { \
817 INCONTRACT(__fCallCheck.SetDidPoll();) \
818 Object* __temp = OBJECTREFToObject(obj); \
819 if (g_TrapReturningThreads.LoadWithoutBarrier()) \
820 { \
821 __temp = FC_GCPoll(__me, __temp); \
822 while (0 == FC_NO_TAILCALL) { }; /* side effect the compile can't remove */ \
823 } \
824 return __temp; \
825 }
826
827#if defined(ENABLE_CONTRACTS)
828#define FC_CAN_TRIGGER_GC() FCallGCCanTrigger::Enter()
829#define FC_CAN_TRIGGER_GC_END() FCallGCCanTrigger::Leave(__FUNCTION__, __FILE__, __LINE__)
830
831#define FC_CAN_TRIGGER_GC_HAVE_THREAD(thread) FCallGCCanTrigger::Enter(thread)
832#define FC_CAN_TRIGGER_GC_HAVE_THREADEND(thread) FCallGCCanTrigger::Leave(thread, __FUNCTION__, __FILE__, __LINE__)
833
834 // turns on forbidGC for the lifetime of the instance
835class ForbidGC {
836protected:
837 Thread *m_pThread;
838public:
839 ForbidGC(const char *szFile, int lineNum);
840 ~ForbidGC();
841};
842
843 // this little helper class checks to make certain
844 // 1) ForbidGC is set throughout the routine.
845 // 2) Sometime during the routine, a GC poll is done
846
847class FCallCheck : public ForbidGC {
848public:
849 FCallCheck(const char *szFile, int lineNum);
850 ~FCallCheck();
851 void SetDidPoll() {LIMITED_METHOD_CONTRACT; didGCPoll = true; }
852 void SetNotNeeded() {LIMITED_METHOD_CONTRACT; notNeeded = true; }
853
854private:
855#ifdef _DEBUG
856 DWORD unbreakableLockCount;
857#endif
858 bool didGCPoll; // GC poll was done
859 bool notNeeded; // GC poll not needed
860 unsigned __int64 startTicks; // tick count at begining of FCall
861};
862
863 // FC_COMMON_PROLOG is used for both FCalls and HCalls
864#define FC_COMMON_PROLOG(target, assertFn) \
865 /* The following line has to be first. We do not want to trash last error */ \
866 DWORD __lastError = ::GetLastError(); \
867 static void* __cache = 0; \
868 assertFn(__cache, (LPVOID)target); \
869 { \
870 Thread *_pThread = GetThread(); \
871 Thread::ObjectRefFlush(_pThread); \
872 /*_ASSERTE (_pThread->IsSOTolerant() ||*/ \
873 /* _pThread->HasThreadStateNC(Thread::TSNC_DisableSOCheckInHCALL)); */ \
874 } \
875 FCallCheck __fCallCheck(__FILE__, __LINE__); \
876 FCALL_TRANSITION_BEGIN(); \
877 ::SetLastError(__lastError); \
878
879void FCallAssert(void*& cache, void* target);
880void HCallAssert(void*& cache, void* target);
881
882#else
883#define FC_COMMON_PROLOG(target, assertFn) FCALL_TRANSITION_BEGIN()
884#define FC_CAN_TRIGGER_GC()
885#define FC_CAN_TRIGGER_GC_END()
886#endif // ENABLE_CONTRACTS
887
888// #FC_INNER
889// Macros that allows fcall to be split into two function to avoid the helper frame overhead on common fast
890// codepaths.
891//
892// The helper routine needs to know the name of the routine that called it so that it can look up the name of
893// the managed routine this code is associted with (for managed stack traces). This is passed with the
894// FC_INNER_PROLOG macro.
895//
896// The helper can set up a HELPER_METHOD_FRAME, but should pass the
897// Frame::FRAME_ATTR_EXACT_DEPTH|Frame::FRAME_ATTR_CAPTURE_DEPTH_2 which indicates the exact number of
898// unwinds to do to get back to managed code. Currently we only support depth 2 which means that the
899// HELPER_METHOD_FRAME needs to be set up in the function directly called by the FCALL. The helper should
900// use the NOINLINE macro to prevent the compiler from inlining it into the FCALL (which would obviously
901// mess up the unwind count).
902//
903// The other invarient that needs to hold is that the epilog walker needs to be able to get from the call to
904// the helper routine to the end of the FCALL using trivial heurisitics. The easiest (and only supported)
905// way of doing this is to place your helper right before a return (eg at the end of the method). Generally
906// this is not a problem at all, since the FCALL itself will pick off some common case and then tail-call to
907// the helper for everything else. You must use the code:FC_INNER_RETURN macros to do the call, to insure
908// that the C++ compiler does not tail-call optimize the call to the inner function and mess up the stack
909// depth.
910//
911// see code:ObjectNative::GetClass for an example
912//
913#define FC_INNER_PROLOG(outerfuncname) \
914 LPVOID __me; \
915 __me = GetEEFuncEntryPointMacro(outerfuncname); \
916 FC_CAN_TRIGGER_GC(); \
917 INCONTRACT(FCallCheck __fCallCheck(__FILE__, __LINE__));
918
919// This variant should be used for inner fcall functions that have the
920// __me value passed as an argument to the function. This allows
921// inner functions to be shared across multiple fcalls.
922#define FC_INNER_PROLOG_NO_ME_SETUP() \
923 FC_CAN_TRIGGER_GC(); \
924 INCONTRACT(FCallCheck __fCallCheck(__FILE__, __LINE__));
925
926#define FC_INNER_EPILOG() \
927 FC_CAN_TRIGGER_GC_END();
928
929// If you are using FC_INNER, and you are tail calling to the helper method (a common case), then you need
930// to use the FC_INNER_RETURN macros (there is one for methods that return a value and another if the
931// function returns void). This macro's purpose is to inhibit any tail calll optimization the C++ compiler
932// might do, which would otherwise confuse the epilog walker.
933//
934// * See #FC_INNER for more
935extern int FC_NO_TAILCALL;
936#define FC_INNER_RETURN(type, expr) \
937 type __retVal = expr; \
938 while (0 == FC_NO_TAILCALL) { }; /* side effect the compile can't remove */ \
939 return(__retVal);
940
941#define FC_INNER_RETURN_VOID(stmt) \
942 stmt; \
943 while (0 == FC_NO_TAILCALL) { }; /* side effect the compile can't remove */ \
944 return;
945
946//==============================================================================================
947// FIMPLn: A set of macros for generating the proto for the actual
948// implementation (use FDECLN for header protos.)
949//
950// The hidden "__me" variable lets us recover the original MethodDesc*
951// so any thrown exceptions will have the correct stack trace. FCThrow()
952// passes this along to __FCThrowInternal().
953//==============================================================================================
954
955#define GetEEFuncEntryPointMacro(func) ((LPVOID)(func))
956
957#define FCIMPL_PROLOG(funcname) \
958 LPVOID __me; \
959 __me = GetEEFuncEntryPointMacro(funcname); \
960 FC_COMMON_PROLOG(__me, FCallAssert)
961
962
963#if defined(_DEBUG) && !defined(CROSSGEN_COMPILE) && !defined(__GNUC__)
964// Build the list of all fcalls signatures. It is used in binder.cpp to verify
965// compatibility of managed and unmanaged fcall signatures. The check is currently done
966// for x86 only.
967#define CHECK_FCALL_SIGNATURE
968#endif
969
970#ifdef CHECK_FCALL_SIGNATURE
971struct FCSigCheck {
972public:
973 FCSigCheck(void* fnc, const char* sig)
974 {
975 LIMITED_METHOD_CONTRACT;
976 func = fnc;
977 signature = sig;
978 next = g_pFCSigCheck;
979 g_pFCSigCheck = this;
980 }
981
982 FCSigCheck* next;
983 void* func;
984 const char* signature;
985
986 static FCSigCheck* g_pFCSigCheck;
987};
988
989#define FCSIGCHECK(funcname, signature) \
990 static FCSigCheck UNIQUE_LABEL(FCSigCheck)(GetEEFuncEntryPointMacro(funcname), signature);
991
992#else // CHECK_FCALL_SIGNATURE
993
994#define FCSIGCHECK(funcname, signature)
995
996#endif // !CHECK_FCALL_SIGNATURE
997
998
999#ifdef SWIZZLE_STKARG_ORDER
1000#ifdef SWIZZLE_REGARG_ORDER
1001
1002#define FCIMPL0(rettype, funcname) rettype F_CALL_CONV funcname() { FCIMPL_PROLOG(funcname)
1003#define FCIMPL1(rettype, funcname, a1) rettype F_CALL_CONV funcname(int /* EAX */, int /* EDX */, a1) { FCIMPL_PROLOG(funcname)
1004#define FCIMPL1_V(rettype, funcname, a1) rettype F_CALL_CONV funcname(int /* EAX */, int /* EDX */, int /* ECX */, a1) { FCIMPL_PROLOG(funcname)
1005#define FCIMPL2(rettype, funcname, a1, a2) rettype F_CALL_CONV funcname(int /* EAX */, a2, a1) { FCIMPL_PROLOG(funcname)
1006#define FCIMPL2_VV(rettype, funcname, a1, a2) rettype F_CALL_CONV funcname(int /* EAX */, int /* EDX */, int /* ECX */, a2, a1) { FCIMPL_PROLOG(funcname)
1007#define FCIMPL2_VI(rettype, funcname, a1, a2) rettype F_CALL_CONV funcname(int /* EAX */, int /* EDX */, a2, a1) { FCIMPL_PROLOG(funcname)
1008#define FCIMPL2_IV(rettype, funcname, a1, a2) rettype F_CALL_CONV funcname(int /* EAX */, int /* EDX */, a1, a2) { FCIMPL_PROLOG(funcname)
1009#define FCIMPL3(rettype, funcname, a1, a2, a3) rettype F_CALL_CONV funcname(int /* EAX */, a2, a1, a3) { FCIMPL_PROLOG(funcname)
1010#define FCIMPL3_IIV(rettype, funcname, a1, a2, a3) rettype F_CALL_CONV funcname(int /* EAX */, a2, a1, a3) { FCIMPL_PROLOG(funcname)
1011#define FCIMPL3_VII(rettype, funcname, a1, a2, a3) rettype F_CALL_CONV funcname(int /* EAX */, a3, a2, a1) { FCIMPL_PROLOG(funcname)
1012#define FCIMPL3_IVV(rettype, funcname, a1, a2, a3) rettype F_CALL_CONV funcname(int /* EAX */, int /* EDX */, a1, a3, a2) { FCIMPL_PROLOG(funcname)
1013#define FCIMPL3_IVI(rettype, funcname, a1, a2, a3) rettype F_CALL_CONV funcname(int /* EAX */, a3, a1, a2) { FCIMPL_PROLOG(funcname)
1014#define FCIMPL3_VVI(rettype, funcname, a1, a2, a3) rettype F_CALL_CONV funcname(int /* EAX */, int /* EDX */, a3, a2, a1) { FCIMPL_PROLOG(funcname)
1015#define FCIMPL3_VVV(rettype, funcname, a1, a2, a3) rettype F_CALL_CONV funcname(int /* EAX */, int /* EDX */, int /* ECX */, a3, a2, a1) { FCIMPL_PROLOG(funcname)
1016#define FCIMPL4(rettype, funcname, a1, a2, a3, a4) rettype F_CALL_CONV funcname(int /* EAX */, a2, a1, a4, a3) { FCIMPL_PROLOG(funcname)
1017#define FCIMPL5(rettype, funcname, a1, a2, a3, a4, a5) rettype F_CALL_CONV funcname(int /* EAX */, a2, a1, a5, a4, a3) { FCIMPL_PROLOG(funcname)
1018#define FCIMPL6(rettype, funcname, a1, a2, a3, a4, a5, a6) rettype F_CALL_CONV funcname(int /* EAX */, a2, a1, a6, a5, a4, a3) { FCIMPL_PROLOG(funcname)
1019#define FCIMPL7(rettype, funcname, a1, a2, a3, a4, a5, a6, a7) rettype F_CALL_CONV funcname(int /* EAX */, a2, a1, a7, a6, a5, a4, a3) { FCIMPL_PROLOG(funcname)
1020#define FCIMPL8(rettype, funcname, a1, a2, a3, a4, a5, a6, a7, a8) rettype F_CALL_CONV funcname(int /* EAX */, a2, a1, a8, a7, a6, a5, a4, a3) { FCIMPL_PROLOG(funcname)
1021#define FCIMPL9(rettype, funcname, a1, a2, a3, a4, a5, a6, a7, a8, a9) rettype F_CALL_CONV funcname(int /* EAX */, a2, a1, a9, a8, a7, a6, a5, a4, a3) { FCIMPL_PROLOG(funcname)
1022#define FCIMPL10(rettype,funcname, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10) rettype F_CALL_CONV funcname(int /* EAX */, a2, a1, a10, a9, a8, a7, a6, a5, a4, a3) { FCIMPL_PROLOG(funcname)
1023#define FCIMPL11(rettype,funcname, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11) rettype F_CALL_CONV funcname(int /* EAX */, a2, a1, a11, a10, a9, a8, a7, a6, a5, a4, a3) { FCIMPL_PROLOG(funcname)
1024#define FCIMPL12(rettype,funcname, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12) rettype F_CALL_CONV funcname(int /* EAX */, a2, a1, a12, a11, a10, a9, a8, a7, a6, a5, a4, a3) { FCIMPL_PROLOG(funcname)
1025#define FCIMPL13(rettype,funcname, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13) rettype F_CALL_CONV funcname(int /* EAX */, a2, a1, a13, a12, a11, a10, a9, a8, a7, a6, a5, a4, a3) { FCIMPL_PROLOG(funcname)
1026#define FCIMPL14(rettype,funcname, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14) rettype F_CALL_CONV funcname(int /* EAX */, a2, a1, a14, a13, a12, a11, a10, a9, a8, a7, a6, a5, a4, a3) { FCIMPL_PROLOG(funcname)
1027
1028#define FCIMPL5_IVI(rettype, funcname, a1, a2, a3, a4, a5) rettype F_CALL_CONV funcname(int /* EAX */, a3, a1, a5, a4, a2) { FCIMPL_PROLOG(funcname)
1029#define FCIMPL5_VII(rettype, funcname, a1, a2, a3, a4, a5) rettype F_CALL_CONV funcname(int /* EAX */, a3, a2, a5, a4, a1) { FCIMPL_PROLOG(funcname)
1030
1031#else // SWIZZLE_REGARG_ORDER
1032
1033#define FCIMPL0(rettype, funcname) FCSIGCHECK(funcname, #rettype) \
1034 rettype F_CALL_CONV funcname() { FCIMPL_PROLOG(funcname)
1035#define FCIMPL1(rettype, funcname, a1) FCSIGCHECK(funcname, #rettype "," #a1) \
1036 rettype F_CALL_CONV funcname(a1) { FCIMPL_PROLOG(funcname)
1037#define FCIMPL1_V(rettype, funcname, a1) FCSIGCHECK(funcname, #rettype "," "V" #a1) \
1038 rettype F_CALL_CONV funcname(a1) { FCIMPL_PROLOG(funcname)
1039#define FCIMPL2(rettype, funcname, a1, a2) FCSIGCHECK(funcname, #rettype "," #a1 "," #a2) \
1040 rettype F_CALL_CONV funcname(a1, a2) { FCIMPL_PROLOG(funcname)
1041#define FCIMPL2VA(rettype, funcname, a1, a2) FCSIGCHECK(funcname, #rettype "," #a1 "," #a2 "," "...") \
1042 rettype F_CALL_VA_CONV funcname(a1, a2, ...) { FCIMPL_PROLOG(funcname)
1043#define FCIMPL2_VV(rettype, funcname, a1, a2) FCSIGCHECK(funcname, #rettype "," "V" #a1 "," "V" #a2) \
1044 rettype F_CALL_CONV funcname(a2, a1) { FCIMPL_PROLOG(funcname)
1045#define FCIMPL2_VI(rettype, funcname, a1, a2) FCSIGCHECK(funcname, #rettype "," "V" #a1 "," #a2) \
1046 rettype F_CALL_CONV funcname(a2, a1) { FCIMPL_PROLOG(funcname)
1047#define FCIMPL2_IV(rettype, funcname, a1, a2) FCSIGCHECK(funcname, #rettype "," #a1 "," "V" #a2) \
1048 rettype F_CALL_CONV funcname(a1, a2) { FCIMPL_PROLOG(funcname)
1049#define FCIMPL3(rettype, funcname, a1, a2, a3) FCSIGCHECK(funcname, #rettype "," #a1 "," #a2 "," #a3) \
1050 rettype F_CALL_CONV funcname(a1, a2, a3) { FCIMPL_PROLOG(funcname)
1051#define FCIMPL3_IIV(rettype, funcname, a1, a2, a3) FCSIGCHECK(funcname, #rettype "," #a1 "," #a2 "," "V" #a3) \
1052 rettype F_CALL_CONV funcname(a1, a2, a3) { FCIMPL_PROLOG(funcname)
1053#define FCIMPL3_VII(rettype, funcname, a1, a2, a3) FCSIGCHECK(funcname, #rettype "," "V" #a1 "," #a2 "," #a3) \
1054 rettype F_CALL_CONV funcname(a2, a3, a1) { FCIMPL_PROLOG(funcname)
1055#define FCIMPL3_IVV(rettype, funcname, a1, a2, a3) FCSIGCHECK(funcname, #rettype "," #a1 "," "V" #a2 "," "V" #a3) \
1056 rettype F_CALL_CONV funcname(a1, a3, a2) { FCIMPL_PROLOG(funcname)
1057#define FCIMPL3_IVI(rettype, funcname, a1, a2, a3) FCSIGCHECK(funcname, #rettype "," #a1 "," "V" #a2 "," #a3) \
1058 rettype F_CALL_CONV funcname(a1, a3, a2) { FCIMPL_PROLOG(funcname)
1059#define FCIMPL3_VVI(rettype, funcname, a1, a2, a3) FCSIGCHECK(funcname, #rettype "," "V" #a1 "," "V" #a2 "," #a3) \
1060 rettype F_CALL_CONV funcname(a2, a1, a3) { FCIMPL_PROLOG(funcname)
1061#define FCIMPL3_VVV(rettype, funcname, a1, a2, a3) FCSIGCHECK(funcname, #rettype "," "V" #a1 "," "V" #a2 "," "V" #a3) \
1062 rettype F_CALL_CONV funcname(a3, a2, a1) { FCIMPL_PROLOG(funcname)
1063#define FCIMPL4(rettype, funcname, a1, a2, a3, a4) FCSIGCHECK(funcname, #rettype "," #a1 "," #a2 "," #a3 "," #a4) \
1064 rettype F_CALL_CONV funcname(a1, a2, a4, a3) { FCIMPL_PROLOG(funcname)
1065#define FCIMPL5(rettype, funcname, a1, a2, a3, a4, a5) FCSIGCHECK(funcname, #rettype "," #a1 "," #a2 "," #a3 "," #a4 "," #a5) \
1066 rettype F_CALL_CONV funcname(a1, a2, a5, a4, a3) { FCIMPL_PROLOG(funcname)
1067#define FCIMPL6(rettype, funcname, a1, a2, a3, a4, a5, a6) FCSIGCHECK(funcname, #rettype "," #a1 "," #a2 "," #a3 "," #a4 "," #a5 "," #a6) \
1068 rettype F_CALL_CONV funcname(a1, a2, a6, a5, a4, a3) { FCIMPL_PROLOG(funcname)
1069#define FCIMPL7(rettype, funcname, a1, a2, a3, a4, a5, a6, a7) FCSIGCHECK(funcname, #rettype "," #a1 "," #a2 "," #a3 "," #a4 "," #a5 "," #a6 "," #a7) \
1070 rettype F_CALL_CONV funcname(a1, a2, a7, a6, a5, a4, a3) { FCIMPL_PROLOG(funcname)
1071#define FCIMPL8(rettype, funcname, a1, a2, a3, a4, a5, a6, a7, a8) FCSIGCHECK(funcname, #rettype "," #a1 "," #a2 "," #a3 "," #a4 "," #a5 "," #a6 "," #a7 "," #a8) \
1072 rettype F_CALL_CONV funcname(a1, a2, a8, a7, a6, a5, a4, a3) { FCIMPL_PROLOG(funcname)
1073#define FCIMPL9(rettype, funcname, a1, a2, a3, a4, a5, a6, a7, a8, a9) FCSIGCHECK(funcname, #rettype "," #a1 "," #a2 "," #a3 "," #a4 "," #a5 "," #a6 "," #a7 "," #a8 "," #a9) \
1074 rettype F_CALL_CONV funcname(a1, a2, a9, a8, a7, a6, a5, a4, a3) { FCIMPL_PROLOG(funcname)
1075#define FCIMPL10(rettype,funcname, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10) FCSIGCHECK(funcname, #rettype "," #a1 "," #a2 "," #a3 "," #a4 "," #a5 "," #a6 "," #a7 "," #a8 "," #a9 "," #a10) \
1076 rettype F_CALL_CONV funcname(a1, a2, a10, a9, a8, a7, a6, a5, a4, a3) { FCIMPL_PROLOG(funcname)
1077#define FCIMPL11(rettype,funcname, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11) FCSIGCHECK(funcname, #rettype "," #a1 "," #a2 "," #a3 "," #a4 "," #a5 "," #a6 "," #a7 "," #a8 "," #a9 "," #a10 "," #a11) \
1078 rettype F_CALL_CONV funcname(a1, a2, a11, a10, a9, a8, a7, a6, a5, a4, a3) { FCIMPL_PROLOG(funcname)
1079#define FCIMPL12(rettype,funcname, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12) FCSIGCHECK(funcname, #rettype "," #a1 "," #a2 "," #a3 "," #a4 "," #a5 "," #a6 "," #a7 "," #a8 "," #a9 "," #a10 "," #a11 "," #a12) \
1080 rettype F_CALL_CONV funcname(a1, a2, a12, a11, a10, a9, a8, a7, a6, a5, a4, a3) { FCIMPL_PROLOG(funcname)
1081#define FCIMPL13(rettype,funcname, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13) FCSIGCHECK(funcname, #rettype "," #a1 "," #a2 "," #a3 "," #a4 "," #a5 "," #a6 "," #a7 "," #a8 "," #a9 "," #a10 "," #a11 "," #a12 "," #a13) \
1082 rettype F_CALL_CONV funcname(a1, a2, a13, a12, a11, a10, a9, a8, a7, a6, a5, a4, a3) { FCIMPL_PROLOG(funcname)
1083#define FCIMPL14(rettype,funcname, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14) FCSIGCHECK(funcname, #rettype "," #a1 "," #a2 "," #a3 "," #a4 "," #a5 "," #a6 "," #a7 "," #a8 "," #a9 "," #a10 "," #a11 "," #a12 "," #a13 "," #a14) \
1084 rettype F_CALL_CONV funcname(a1, a2, a14, a13, a12, a11, a10, a9, a8, a7, a6, a5, a4, a3) { FCIMPL_PROLOG(funcname)
1085
1086#define FCIMPL5_IVI(rettype, funcname, a1, a2, a3, a4, a5) FCSIGCHECK(funcname, #rettype "," #a1 "," "V" #a2 "," #a3 "," #a4 "," #a5) \
1087 rettype F_CALL_CONV funcname(a1, a3, a5, a4, a2) { FCIMPL_PROLOG(funcname)
1088#define FCIMPL5_VII(rettype, funcname, a1, a2, a3, a4, a5) FCSIGCHECK(funcname, #rettype "," "V" #a1 "," #a2 "," #a3 "," #a4 "," #a5) \
1089 rettype F_CALL_CONV funcname(a2, a3, a5, a4, a1) { FCIMPL_PROLOG(funcname)
1090
1091#endif // !SWIZZLE_REGARG_ORDER
1092
1093#else // SWIZZLE_STKARG_ORDER
1094
1095#define FCIMPL0(rettype, funcname) rettype funcname() { FCIMPL_PROLOG(funcname)
1096#define FCIMPL1(rettype, funcname, a1) rettype funcname(a1) { FCIMPL_PROLOG(funcname)
1097#define FCIMPL1_V(rettype, funcname, a1) rettype funcname(a1) { FCIMPL_PROLOG(funcname)
1098#define FCIMPL2(rettype, funcname, a1, a2) rettype funcname(a1, a2) { FCIMPL_PROLOG(funcname)
1099#define FCIMPL2VA(rettype, funcname, a1, a2) rettype funcname(a1, a2, ...) { FCIMPL_PROLOG(funcname)
1100#define FCIMPL2_VV(rettype, funcname, a1, a2) rettype funcname(a1, a2) { FCIMPL_PROLOG(funcname)
1101#define FCIMPL2_VI(rettype, funcname, a1, a2) rettype funcname(a1, a2) { FCIMPL_PROLOG(funcname)
1102#define FCIMPL2_IV(rettype, funcname, a1, a2) rettype funcname(a1, a2) { FCIMPL_PROLOG(funcname)
1103#define FCIMPL3(rettype, funcname, a1, a2, a3) rettype funcname(a1, a2, a3) { FCIMPL_PROLOG(funcname)
1104#define FCIMPL3_IIV(rettype, funcname, a1, a2, a3) rettype funcname(a1, a2, a3) { FCIMPL_PROLOG(funcname)
1105#define FCIMPL3_IVV(rettype, funcname, a1, a2, a3) rettype funcname(a1, a2, a3) { FCIMPL_PROLOG(funcname)
1106#define FCIMPL3_VII(rettype, funcname, a1, a2, a3) rettype funcname(a1, a2, a3) { FCIMPL_PROLOG(funcname)
1107#define FCIMPL3_IVI(rettype, funcname, a1, a2, a3) rettype funcname(a1, a2, a3) { FCIMPL_PROLOG(funcname)
1108#define FCIMPL3_VVI(rettype, funcname, a1, a2, a3) rettype funcname(a1, a2, a3) { FCIMPL_PROLOG(funcname)
1109#define FCIMPL3_VVV(rettype, funcname, a1, a2, a3) rettype funcname(a1, a2, a3) { FCIMPL_PROLOG(funcname)
1110#define FCIMPL4(rettype, funcname, a1, a2, a3, a4) rettype funcname(a1, a2, a3, a4) { FCIMPL_PROLOG(funcname)
1111#define FCIMPL5(rettype, funcname, a1, a2, a3, a4, a5) rettype funcname(a1, a2, a3, a4, a5) { FCIMPL_PROLOG(funcname)
1112#define FCIMPL6(rettype, funcname, a1, a2, a3, a4, a5, a6) rettype funcname(a1, a2, a3, a4, a5, a6) { FCIMPL_PROLOG(funcname)
1113#define FCIMPL7(rettype, funcname, a1, a2, a3, a4, a5, a6, a7) rettype funcname(a1, a2, a3, a4, a5, a6, a7) { FCIMPL_PROLOG(funcname)
1114#define FCIMPL8(rettype, funcname, a1, a2, a3, a4, a5, a6, a7, a8) rettype funcname(a1, a2, a3, a4, a5, a6, a7, a8) { FCIMPL_PROLOG(funcname)
1115#define FCIMPL9(rettype, funcname, a1, a2, a3, a4, a5, a6, a7, a8, a9) rettype funcname(a1, a2, a3, a4, a5, a6, a7, a8, a9) { FCIMPL_PROLOG(funcname)
1116#define FCIMPL10(rettype,funcname, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10) rettype funcname(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10) { FCIMPL_PROLOG(funcname)
1117#define FCIMPL11(rettype,funcname, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11) rettype funcname(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11) { FCIMPL_PROLOG(funcname)
1118#define FCIMPL12(rettype,funcname, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12) rettype funcname(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12) { FCIMPL_PROLOG(funcname)
1119#define FCIMPL13(rettype,funcname, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13) rettype funcname(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13) { FCIMPL_PROLOG(funcname)
1120#define FCIMPL14(rettype,funcname, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14) rettype funcname(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14) { FCIMPL_PROLOG(funcname)
1121
1122#define FCIMPL5_IVI(rettype, funcname, a1, a2, a3, a4, a5) rettype funcname(a1, a2, a3, a4, a5) { FCIMPL_PROLOG(funcname)
1123#define FCIMPL5_VII(rettype, funcname, a1, a2, a3, a4, a5) rettype funcname(a1, a2, a3, a4, a5) { FCIMPL_PROLOG(funcname)
1124
1125#endif // !SWIZZLE_STKARG_ORDER
1126
1127//==============================================================================================
1128// Use this to terminte an FCIMPLEND.
1129//==============================================================================================
1130
1131#define FCIMPL_EPILOG() FCALL_TRANSITION_END()
1132
1133#define FCIMPLEND FCIMPL_EPILOG(); }
1134
1135#define HCIMPL_PROLOG(funcname) LPVOID __me; __me = 0; FC_COMMON_PROLOG(funcname, HCallAssert)
1136
1137 // HCIMPL macros are just like their FCIMPL counterparts, however
1138 // they do not remember the function they come from. Thus they will not
1139 // show up in a stack trace. This is what you want for JIT helpers and the like
1140
1141#ifdef SWIZZLE_STKARG_ORDER
1142#ifdef SWIZZLE_REGARG_ORDER
1143
1144#define HCIMPL0(rettype, funcname) rettype F_CALL_CONV funcname() { HCIMPL_PROLOG(funcname)
1145#define HCIMPL1(rettype, funcname, a1) rettype F_CALL_CONV funcname(int /* EAX */, int /* EDX */, a1) { HCIMPL_PROLOG(funcname)
1146#define HCIMPL1_RAW(rettype, funcname, a1) rettype F_CALL_CONV funcname(int /* EAX */, int /* EDX */, a1) {
1147#define HCIMPL1_V(rettype, funcname, a1) rettype F_CALL_CONV funcname(int /* EAX */, int /* EDX */, int /* ECX */, a1) { HCIMPL_PROLOG(funcname)
1148#define HCIMPL2(rettype, funcname, a1, a2) rettype F_CALL_CONV funcname(int /* EAX */, a2, a1) { HCIMPL_PROLOG(funcname)
1149#define HCIMPL2_RAW(rettype, funcname, a1, a2) rettype F_CALL_CONV funcname(int /* EAX */, a2, a1) {
1150#define HCIMPL2_VV(rettype, funcname, a1, a2) rettype F_CALL_CONV funcname(int /* EAX */, int /* EDX */, int /* ECX */, a2, a1) { HCIMPL_PROLOG(funcname)
1151#define HCIMPL2_IV(rettype, funcname, a1, a2) rettype F_CALL_CONV funcname(int /* EAX */, int /* EDX */, a1, a2) { HCIMPL_PROLOG(funcname)
1152#define HCIMPL2VA(rettype, funcname, a1, a2) rettype F_CALL_VA_CONV funcname(a1, a2, ...) { HCIMPL_PROLOG(funcname)
1153#define HCIMPL3(rettype, funcname, a1, a2, a3) rettype F_CALL_CONV funcname(int /* EAX */, a2, a1, a3) { HCIMPL_PROLOG(funcname)
1154#define HCIMPL4(rettype, funcname, a1, a2, a3, a4) rettype F_CALL_CONV funcname(int /* EAX */, a2, a1, a4, a3) { HCIMPL_PROLOG(funcname)
1155#define HCIMPL5(rettype, funcname, a1, a2, a3, a4, a5) rettype F_CALL_CONV funcname(int /* EAX */, a2, a1, a5, a4, a3) { HCIMPL_PROLOG(funcname)
1156
1157#define HCCALL1(funcname, a1) funcname(0, 0, a1)
1158#define HCCALL1_V(funcname, a1) funcname(0, 0, 0, a1)
1159#define HCCALL2(funcname, a1, a2) funcname(0, a2, a1)
1160#define HCCALL3(funcname, a1, a2, a3) funcname(0, a2, a1, a3)
1161#define HCCALL4(funcname, a1, a2, a3, a4) funcname(0, a2, a1, a4, a3)
1162#define HCCALL5(funcname, a1, a2, a3, a4, a5) funcname(0, a2, a1, a5, a4, a3)
1163#define HCCALL1_PTR(rettype, funcptr, a1) rettype (F_CALL_CONV * funcptr)(int /* EAX */, int /* EDX */, a1)
1164#define HCCALL2_PTR(rettype, funcptr, a1, a2) rettype (F_CALL_CONV * funcptr)(int /* EAX */, a2, a1)
1165#else // SWIZZLE_REGARG_ORDER
1166
1167#define HCIMPL0(rettype, funcname) rettype F_CALL_CONV funcname() { HCIMPL_PROLOG(funcname)
1168#define HCIMPL1(rettype, funcname, a1) rettype F_CALL_CONV funcname(a1) { HCIMPL_PROLOG(funcname)
1169#define HCIMPL1_RAW(rettype, funcname, a1) rettype F_CALL_CONV funcname(a1) {
1170#define HCIMPL1_V(rettype, funcname, a1) rettype F_CALL_CONV funcname(a1) { HCIMPL_PROLOG(funcname)
1171#define HCIMPL2(rettype, funcname, a1, a2) rettype F_CALL_CONV funcname(a1, a2) { HCIMPL_PROLOG(funcname)
1172#define HCIMPL2_RAW(rettype, funcname, a1, a2) rettype F_CALL_CONV funcname(a1, a2) {
1173#define HCIMPL2_VV(rettype, funcname, a1, a2) rettype F_CALL_CONV funcname(a2, a1) { HCIMPL_PROLOG(funcname)
1174#define HCIMPL2_IV(rettype, funcname, a1, a2) rettype F_CALL_CONV funcname(a1, a2) { HCIMPL_PROLOG(funcname)
1175#define HCIMPL2VA(rettype, funcname, a1, a2) rettype F_CALL_VA_CONV funcname(a1, a2, ...) { HCIMPL_PROLOG(funcname)
1176#define HCIMPL3(rettype, funcname, a1, a2, a3) rettype F_CALL_CONV funcname(a1, a2, a3) { HCIMPL_PROLOG(funcname)
1177#define HCIMPL4(rettype, funcname, a1, a2, a3, a4) rettype F_CALL_CONV funcname(a1, a2, a4, a3) { HCIMPL_PROLOG(funcname)
1178#define HCIMPL5(rettype, funcname, a1, a2, a3, a4, a5) rettype F_CALL_CONV funcname(a1, a2, a5, a4, a3) { HCIMPL_PROLOG(funcname)
1179
1180#define HCCALL1(funcname, a1) funcname(a1)
1181#define HCCALL1_V(funcname, a1) funcname(a1)
1182#define HCCALL2(funcname, a1, a2) funcname(a1, a2)
1183#define HCCALL3(funcname, a1, a2, a3) funcname(a1, a2, a3)
1184#define HCCALL4(funcname, a1, a2, a3, a4) funcname(a1, a2, a4, a3)
1185#define HCCALL5(funcname, a1, a2, a3, a4, a5) funcname(a1, a2, a5, a4, a3)
1186#define HCCALL1_PTR(rettype, funcptr, a1) rettype (F_CALL_CONV * funcptr)(a1)
1187#define HCCALL2_PTR(rettype, funcptr, a1, a2) rettype (F_CALL_CONV * funcptr)(a1, a2)
1188#endif // !SWIZZLE_REGARG_ORDER
1189#else // SWIZZLE_STKARG_ORDER
1190
1191#define HCIMPL0(rettype, funcname) rettype F_CALL_CONV funcname() { HCIMPL_PROLOG(funcname)
1192#define HCIMPL1(rettype, funcname, a1) rettype F_CALL_CONV funcname(a1) { HCIMPL_PROLOG(funcname)
1193#define HCIMPL1_RAW(rettype, funcname, a1) rettype F_CALL_CONV funcname(a1) {
1194#define HCIMPL1_V(rettype, funcname, a1) rettype F_CALL_CONV funcname(a1) { HCIMPL_PROLOG(funcname)
1195#define HCIMPL2(rettype, funcname, a1, a2) rettype F_CALL_CONV funcname(a1, a2) { HCIMPL_PROLOG(funcname)
1196#define HCIMPL2_RAW(rettype, funcname, a1, a2) rettype F_CALL_CONV funcname(a1, a2) {
1197#define HCIMPL2_VV(rettype, funcname, a1, a2) rettype F_CALL_CONV funcname(a1, a2) { HCIMPL_PROLOG(funcname)
1198#define HCIMPL2_IV(rettype, funcname, a1, a2) rettype F_CALL_CONV funcname(a1, a2) { HCIMPL_PROLOG(funcname)
1199#define HCIMPL2VA(rettype, funcname, a1, a2) rettype F_CALL_VA_CONV funcname(a1, a2, ...) { HCIMPL_PROLOG(funcname)
1200#define HCIMPL3(rettype, funcname, a1, a2, a3) rettype F_CALL_CONV funcname(a1, a2, a3) { HCIMPL_PROLOG(funcname)
1201#define HCIMPL4(rettype, funcname, a1, a2, a3, a4) rettype F_CALL_CONV funcname(a1, a2, a3, a4) { HCIMPL_PROLOG(funcname)
1202#define HCIMPL5(rettype, funcname, a1, a2, a3, a4, a5) rettype F_CALL_CONV funcname(a1, a2, a3, a4, a5) { HCIMPL_PROLOG(funcname)
1203
1204#define HCCALL1(funcname, a1) funcname(a1)
1205#define HCCALL1_V(funcname, a1) funcname(a1)
1206#define HCCALL2(funcname, a1, a2) funcname(a1, a2)
1207#define HCCALL3(funcname, a1, a2, a3) funcname(a1, a2, a3)
1208#define HCCALL4(funcname, a1, a2, a3, a4) funcname(a1, a2, a3, a4)
1209#define HCCALL5(funcname, a1, a2, a3, a4, a5) funcname(a1, a2, a3, a4, a5)
1210#define HCCALL1_PTR(rettype, funcptr, a1) rettype (F_CALL_CONV * funcptr)(a1)
1211#define HCCALL2_PTR(rettype, funcptr, a1, a2) rettype (F_CALL_CONV * funcptr)(a1, a2)
1212
1213#endif // !SWIZZLE_STKARG_ORDER
1214
1215#define HCIMPLEND_RAW }
1216#define HCIMPLEND FCALL_TRANSITION_END(); }
1217
1218
1219//==============================================================================================
1220// Throws an exception from an FCall. See rexcep.h for a list of valid
1221// exception codes.
1222//==============================================================================================
1223#define FCThrow(reKind) FCThrowEx(reKind, 0, 0, 0, 0)
1224
1225//==============================================================================================
1226// This version lets you attach a message with inserts (similar to
1227// COMPlusThrow()).
1228//==============================================================================================
1229#define FCThrowEx(reKind, resID, arg1, arg2, arg3) \
1230 { \
1231 while (NULL == \
1232 __FCThrow(__me, reKind, resID, arg1, arg2, arg3)) {}; \
1233 return 0; \
1234 }
1235
1236//==============================================================================================
1237// Like FCThrow but can be used for a VOID-returning FCall. The only
1238// difference is in the "return" statement.
1239//==============================================================================================
1240#define FCThrowVoid(reKind) FCThrowExVoid(reKind, 0, 0, 0, 0)
1241
1242//==============================================================================================
1243// This version lets you attach a message with inserts (similar to
1244// COMPlusThrow()).
1245//==============================================================================================
1246#define FCThrowExVoid(reKind, resID, arg1, arg2, arg3) \
1247 { \
1248 while (NULL == \
1249 __FCThrow(__me, reKind, resID, arg1, arg2, arg3)) {}; \
1250 return; \
1251 }
1252
1253// Use FCThrowRes to throw an exception with a localized error message from the
1254// ResourceManager in managed code.
1255#define FCThrowRes(reKind, resourceName) FCThrowArgumentEx(reKind, NULL, resourceName)
1256#define FCThrowArgumentNull(argName) FCThrowArgumentEx(kArgumentNullException, argName, NULL)
1257#define FCThrowArgumentOutOfRange(argName, message) FCThrowArgumentEx(kArgumentOutOfRangeException, argName, message)
1258#define FCThrowArgument(argName, message) FCThrowArgumentEx(kArgumentException, argName, message)
1259
1260#define FCThrowArgumentEx(reKind, argName, resourceName) \
1261 { \
1262 while (NULL == \
1263 __FCThrowArgument(__me, reKind, argName, resourceName)) {}; \
1264 return 0; \
1265 }
1266
1267// Use FCThrowRes to throw an exception with a localized error message from the
1268// ResourceManager in managed code.
1269#define FCThrowResVoid(reKind, resourceName) FCThrowArgumentVoidEx(reKind, NULL, resourceName)
1270#define FCThrowArgumentNullVoid(argName) FCThrowArgumentVoidEx(kArgumentNullException, argName, NULL)
1271#define FCThrowArgumentOutOfRangeVoid(argName, message) FCThrowArgumentVoidEx(kArgumentOutOfRangeException, argName, message)
1272#define FCThrowArgumentVoid(argName, message) FCThrowArgumentVoidEx(kArgumentException, argName, message)
1273
1274#define FCThrowArgumentVoidEx(reKind, argName, resourceName) \
1275 { \
1276 while (NULL == \
1277 __FCThrowArgument(__me, reKind, argName, resourceName)) {}; \
1278 return; \
1279 }
1280
1281
1282
1283// The x86 JIT calling convention expects returned small types (e.g. bool) to be
1284// widened on return. The C/C++ calling convention does not guarantee returned
1285// small types to be widened. The small types has to be artifically widened on return
1286// to fit x86 JIT calling convention. Thus fcalls returning small types has to
1287// use the FC_XXX_RET types to force C/C++ compiler to do the widening.
1288//
1289// The most common small return type of FCALLs is bool. The widening of bool is
1290// especially tricky since the value has to be also normalized. FC_BOOL_RET and
1291// FC_RETURN_BOOL macros are provided to make it fool-proof. FCALLs returning bool
1292// should be implemented using following pattern:
1293
1294// FCIMPL0(FC_BOOL_RET, Foo) // the return type should be FC_BOOL_RET
1295// BOOL ret;
1296//
1297// FC_RETURN_BOOL(ret); // return statements should be FC_RETURN_BOOL
1298// FCIMPLEND
1299
1300// This rules are verified in binder.cpp if COMPlus_ConsistencyCheck is set.
1301
1302#ifdef _PREFAST_
1303
1304// Use prefast build to ensure that functions returning FC_BOOL_RET
1305// are using FC_RETURN_BOOL to return it. Missing FC_RETURN_BOOL will
1306// result into type mismatch error in prefast builds. This will also
1307// catch misuses of FC_BOOL_RET for other places (e.g. in FCALL parameters).
1308
1309typedef LPVOID FC_BOOL_RET;
1310#define FC_RETURN_BOOL(x) do { return (LPVOID)!!(x); } while(0)
1311
1312#else
1313
1314#if defined(_TARGET_X86_) || defined(_TARGET_AMD64_)
1315// The return value is artifically widened on x86 and amd64
1316typedef INT32 FC_BOOL_RET;
1317#else
1318typedef CLR_BOOL FC_BOOL_RET;
1319#endif
1320
1321#define FC_RETURN_BOOL(x) do { return !!(x); } while(0)
1322
1323#endif
1324
1325
1326#if defined(_TARGET_X86_) || defined(_TARGET_AMD64_)
1327// The return value is artifically widened on x86 and amd64
1328typedef UINT32 FC_CHAR_RET;
1329typedef INT32 FC_INT8_RET;
1330typedef UINT32 FC_UINT8_RET;
1331typedef INT32 FC_INT16_RET;
1332typedef UINT32 FC_UINT16_RET;
1333#else
1334typedef CLR_CHAR FC_CHAR_RET;
1335typedef INT8 FC_INT8_RET;
1336typedef UINT8 FC_UINT8_RET;
1337typedef INT16 FC_INT16_RET;
1338typedef UINT16 FC_UINT16_RET;
1339#endif
1340
1341
1342// FC_TypedByRef should be used for TypedReferences in FCall signatures
1343#define FC_TypedByRef TypedByRef
1344#define FC_DECIMAL DECIMAL
1345
1346
1347// The fcall entrypoints has to be at unique addresses. Use this helper macro to make
1348// the code of the fcalls unique if you get assert in ecall.cpp that mentions it.
1349// The parameter of the FCUnique macro is an arbitrary 32-bit random non-zero number.
1350#define FCUnique(unique) { Volatile<int> u = (unique); while (u.LoadWithoutBarrier() == 0) { }; }
1351
1352
1353
1354
1355// FCALL contracts come in two forms:
1356//
1357// Short form that should be used if the FCALL contract does not have any extras like preconditions, failure injection. Example:
1358//
1359// FCIMPL0(void, foo)
1360// {
1361// FCALL_CONTRACT;
1362// ...
1363//
1364// Long form that should be used otherwise. Example:
1365//
1366// FCIMPL1(void, foo, void *p)
1367// {
1368// CONTRACTL {
1369// FCALL_CHECK;
1370// PRECONDITION(CheckPointer(p));
1371// } CONTRACTL_END;
1372// ...
1373
1374
1375//
1376// FCALL_CHECK defines the actual contract conditions required for FCALLs
1377//
1378#define FCALL_CHECK \
1379 THROWS; \
1380 DISABLED(GC_TRIGGERS); /* FCALLS with HELPER frames have issues with GC_TRIGGERS */ \
1381 MODE_COOPERATIVE; \
1382 SO_TOLERANT
1383
1384//
1385// FCALL_CONTRACT should be the following shortcut:
1386//
1387// #define FCALL_CONTRACT CONTRACTL { FCALL_CHECK; } CONTRACTL_END;
1388//
1389// Since there is very little value in having runtime contracts in FCalls, FCALL_CONTRACT is defined as static contract only for performance reasons.
1390//
1391#define FCALL_CONTRACT \
1392 STATIC_CONTRACT_SO_TOLERANT; \
1393 STATIC_CONTRACT_THROWS; \
1394 /* FCALLS are a special case contract wise, they are "NOTRIGGER, unless you setup a frame" */ \
1395 STATIC_CONTRACT_GC_NOTRIGGER; \
1396 STATIC_CONTRACT_MODE_COOPERATIVE
1397
1398#endif //__FCall_h__
1399