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.
8 // This file defines tables for references between VM and mscorlib.
10 // When compiling crossgen, this file is compiled with the FEATURE_XXX define settings matching the target.
11 // It allows us to strip features (e.g. refection only load) from crossgen without stripping them from the target.
14 #ifdef CROSSGEN_MSCORLIB
15 // Use minimal set of headers for crossgen
21 #endif // CROSSGEN_MSCORLIB
23 #ifndef CROSSGEN_COMPILE
25 // Headers for all ECall entrypoints
27 #include "arraynative.h"
28 #include "stringnative.h"
29 #include "stringbuffer.h"
30 #include "objectnative.h"
31 #include "comdelegate.h"
32 #include "customattribute.h"
33 #include "comdynamic.h"
37 #include "commodule.h"
38 #include "marshalnative.h"
40 #include "comutilnative.h"
41 #include "comsynchronizable.h"
42 #include "floatdouble.h"
43 #include "floatsingle.h"
46 #include "comdatetime.h"
48 #include "compatibilityswitch.h"
49 #include "debugdebugger.h"
50 #include "assemblyname.hpp"
51 #include "assemblynative.hpp"
52 #include "comthreadpool.h"
53 #include "comwaithandle.h"
54 #include "nativeoverlapped.h"
56 #include "proftoeeinterfaceimpl.h"
58 #include "appdomainnative.hpp"
59 #include "arrayhelpers.h"
60 #include "runtimehandles.h"
61 #include "reflectioninvocation.h"
62 #include "managedmdimport.hpp"
63 #include "synchronizationcontextnative.h"
64 #include "commemoryfailpoint.h"
65 #include "typestring.h"
66 #include "comdependenthandle.h"
67 #include "weakreferencenative.h"
68 #include "varargsnative.h"
71 #include "mdaassistants.h"
76 #ifdef FEATURE_COMINTEROP
78 #include "oavariant.h"
79 #include "registration.h"
80 #include "mngstdinterfaces.h"
81 #include "extensibleclassfactory.h"
82 #endif // FEATURE_COMINTEROP
84 #include "stubhelpers.h"
85 #include "ilmarshalers.h"
87 #ifdef FEATURE_MULTICOREJIT
88 #include "multicorejit.h"
91 #ifdef FEATURE_COMINTEROP
92 #include "windowsruntimebufferhelper.h"
95 #if defined(FEATURE_EVENTSOURCE_XPLAT)
96 #include "nativeeventsource.h"
97 #endif //defined(FEATURE_EVENTSOURCE_XPLAT)
99 #endif // CROSSGEN_MSCORLIB
102 #ifdef CROSSGEN_MSCORLIB
104 ///////////////////////////////////////////////////////////////////////////////
106 // Duplicate definitions of constants and datastructures required to define the tables
109 #define NumItems(s) (sizeof(s) / sizeof(s[0]))
111 #define GetEEFuncEntryPoint(pfn) 0x1001
114 FCFuncFlag_EndOfArray = 0x01,
115 FCFuncFlag_HasSignature = 0x02,
116 FCFuncFlag_Unreferenced = 0x04, // Suppress unused fcall check
117 FCFuncFlag_QCall = 0x08, // QCall - mscorlib.dll to mscorwks.dll transition implemented as PInvoke
122 LPCSTR m_szClassName;
123 LPCSTR m_szNameSpace;
124 const LPVOID * m_pECFunc;
127 struct HardCodedMetaSig
129 const BYTE* m_pMetaSig; // metasig prefixed with INT8 length:
130 // length > 0 - resolved, lenght < 0 - has unresolved type references
135 #define TYPEINFO(e,ns,c,s,g,ia,ip,if,im,gv) CLASS__ ## e,
136 #include "cortypeinfo.h"
139 #define DEFINE_CLASS(i,n,s) CLASS__ ## i,
140 #include "mscorlib.h"
142 CLASS__MSCORLIB_COUNT,
144 CLASS__VOID = CLASS__ELEMENT_TYPE_VOID,
145 CLASS__BOOLEAN = CLASS__ELEMENT_TYPE_BOOLEAN,
146 CLASS__CHAR = CLASS__ELEMENT_TYPE_CHAR,
147 CLASS__BYTE = CLASS__ELEMENT_TYPE_U1,
148 CLASS__SBYTE = CLASS__ELEMENT_TYPE_I1,
149 CLASS__INT16 = CLASS__ELEMENT_TYPE_I2,
150 CLASS__UINT16 = CLASS__ELEMENT_TYPE_U2,
151 CLASS__INT32 = CLASS__ELEMENT_TYPE_I4,
152 CLASS__UINT32 = CLASS__ELEMENT_TYPE_U4,
153 CLASS__INT64 = CLASS__ELEMENT_TYPE_I8,
154 CLASS__UINT64 = CLASS__ELEMENT_TYPE_U8,
155 CLASS__SINGLE = CLASS__ELEMENT_TYPE_R4,
156 CLASS__DOUBLE = CLASS__ELEMENT_TYPE_R8,
157 CLASS__STRING = CLASS__ELEMENT_TYPE_STRING,
158 CLASS__TYPED_REFERENCE = CLASS__ELEMENT_TYPE_TYPEDBYREF,
159 CLASS__INTPTR = CLASS__ELEMENT_TYPE_I,
160 CLASS__UINTPTR = CLASS__ELEMENT_TYPE_U,
161 CLASS__OBJECT = CLASS__ELEMENT_TYPE_OBJECT
164 struct MscorlibClassDescription
170 struct MscorlibMethodDescription
172 BinderClassID classID;
174 const HardCodedMetaSig * sig;
177 struct MscorlibFieldDescription
179 BinderClassID classID;
183 #endif // CROSSGEN_MSCORLIB
186 #ifdef CROSSGEN_MSCORLIB
187 // When compiling crossgen this namespace creates the second version of the tables than matches the target
188 namespace CrossGenMscorlib {
192 ///////////////////////////////////////////////////////////////////////////////
194 // Hardcoded Meta-Sig
198 // Helper enum with metasig lengths
200 // iterate over the metasig recursing into the complex types
201 #define DEFINE_METASIG(body) body,
202 #define METASIG_ATOM(x) + 1
203 #define METASIG_RECURSE 1
204 #define SM(varname, args, retval) gsigl_SM_ ## varname = 1 + 1 retval args
205 #define IM(varname, args, retval) gsigl_IM_ ## varname = 1 + 1 retval args
206 #define GM(varname, conv, n, args, retval) gsigl_GM_ ## varname = 1 + 1 + 1 + retval args
207 #define Fld(varname, val) gsigl_Fld_ ## varname = 1 val
213 // Helper enum with metasig argcount
215 // iterate over the metasig without recursing into the complex types
216 #define DEFINE_METASIG(body) body,
217 #define METASIG_ATOM(x) + 1
218 #define METASIG_RECURSE 0
219 #define SM(varname, args, retval) gsigc_SM_ ## varname = 0 args
220 #define IM(varname, args, retval) gsigc_IM_ ## varname = 0 args
221 #define GM(varname, conv, n, args, retval) gsigc_GM_ ## varname = 0 args
222 #define Fld(varname, val) gsigc_Fld_ ## varname = 0
229 // The actual array with the hardcoded metasig:
231 // There are 3 variations of the macros for Fields, Static Methods and Instance Methods.
233 // Each of them has 2 flavors: one for the fully baked signatures, and the other
234 // for the signatures with unresolved type references
236 // The signatures with unresolved type references are marked with negative size,
237 // and the pointer to them is non-const because of it will be overwritten with
238 // the pointer to the resolved signature at runtime.
241 #define DEFINE_METASIG(body) body
242 #define DEFINE_METASIG_T(body) _##body
243 #define METASIG_ATOM(x) x,
244 #define METASIG_RECURSE 1
246 // define gsig_ ## varname before gsige_ ## varname to give a hint to the compiler about the desired layout
248 #define SM(varname, args, retval) extern const BYTE gsige_SM_ ## varname[]; \
249 const HardCodedMetaSig gsig_SM_ ## varname = { gsige_SM_ ## varname }; \
250 const BYTE gsige_SM_ ## varname[] = { gsigl_SM_ ## varname, \
251 IMAGE_CEE_CS_CALLCONV_DEFAULT, gsigc_SM_ ## varname, retval args };
253 #define IM(varname, args, retval) extern const BYTE gsige_IM_ ## varname[]; \
254 const HardCodedMetaSig gsig_IM_ ## varname = { gsige_IM_ ## varname }; \
255 const BYTE gsige_IM_ ## varname[] = { gsigl_IM_ ## varname, \
256 IMAGE_CEE_CS_CALLCONV_HASTHIS, gsigc_IM_ ## varname, retval args };
258 #define GM(varname, conv, n, args, retval) extern const BYTE gsige_GM_ ## varname[]; \
259 const HardCodedMetaSig gsig_GM_ ## varname = { gsige_GM_ ## varname }; \
260 const BYTE gsige_GM_ ## varname[] = { gsigl_GM_ ## varname, \
261 conv | IMAGE_CEE_CS_CALLCONV_GENERIC, n, gsigc_GM_ ## varname, retval args };
263 #define Fld(varname, val) extern const BYTE gsige_Fld_ ## varname[]; \
264 const HardCodedMetaSig gsig_Fld_ ## varname = { gsige_Fld_ ## varname }; \
265 const BYTE gsige_Fld_ ## varname[] = { gsigl_Fld_ ## varname, \
266 IMAGE_CEE_CS_CALLCONV_FIELD, val };
268 #define _SM(varname, args, retval) extern const BYTE gsige_SM_ ## varname[]; \
269 HardCodedMetaSig gsig_SM_ ## varname = { gsige_SM_ ## varname }; \
270 const BYTE gsige_SM_ ## varname[] = { (BYTE) -gsigl_SM_ ## varname, \
271 IMAGE_CEE_CS_CALLCONV_DEFAULT, gsigc_SM_ ## varname, retval args };
273 #define _IM(varname, args, retval) extern const BYTE gsige_IM_ ## varname[]; \
274 HardCodedMetaSig gsig_IM_ ## varname = { gsige_IM_ ## varname }; \
275 const BYTE gsige_IM_ ## varname[] = { (BYTE) -gsigl_IM_ ## varname, \
276 IMAGE_CEE_CS_CALLCONV_HASTHIS, gsigc_IM_ ## varname, retval args };
278 #define _Fld(varname, val) extern const BYTE gsige_Fld_ ## varname[]; \
279 HardCodedMetaSig gsig_Fld_ ## varname = { gsige_Fld_ ## varname }; \
280 const BYTE gsige_Fld_ ## varname[] = { (BYTE) -gsigl_Fld_ ## varname, \
281 IMAGE_CEE_CS_CALLCONV_FIELD, val };
294 // Make sure DEFINE_METASIG is used for signatures that do not reference other types
296 // counts number of type references in the signature and C_ASSERTs that
297 // it is zero. An assertion failure results in error C2118: negative subscript.
298 #define DEFINE_METASIG(body) body
299 #define DEFINE_METASIG_T(body)
300 #define METASIG_BODY(varname, types) C_ASSERT(types 0 == 0);
301 #define METASIG_ATOM(x) 0+
302 #define METASIG_RECURSE 1
308 // Make sure DEFINE_METASIG_T is used only for signatures that reference
311 // counts number of type references in the signature and C_ASSERTs that
312 // it is non zero. An assertion failure results in error C2118: negative subscript.
313 #define DEFINE_METASIG(body)
314 #define DEFINE_METASIG_T(body) body
315 #define METASIG_BODY(varname, types) C_ASSERT(types 0 != 0);
316 #define METASIG_ATOM(x) 0+
317 #define METASIG_RECURSE 1
328 ///////////////////////////////////////////////////////////////////////////////
333 // Extern definitions so that binder.cpp can see these tables
334 extern const MscorlibClassDescription c_rgMscorlibClassDescriptions[];
335 extern const USHORT c_nMscorlibClassDescriptions;
337 extern const MscorlibMethodDescription c_rgMscorlibMethodDescriptions[];
338 extern const USHORT c_nMscorlibMethodDescriptions;
340 extern const MscorlibFieldDescription c_rgMscorlibFieldDescriptions[];
341 extern const USHORT c_nMscorlibFieldDescriptions;
343 const MscorlibClassDescription c_rgMscorlibClassDescriptions[] =
345 #define TYPEINFO(e,ns,c,s,g,ia,ip,if,im,gv) { ns, c },
346 #include "cortypeinfo.h"
349 #define DEFINE_CLASS(i,n,s) { g_ ## n ## NS, # s },
350 #include "namespace.h"
351 #include "mscorlib.h"
353 // Include all exception types here that are defined in mscorlib. Omit exceptions defined elsewhere.
354 #define DEFINE_EXCEPTION(ns, reKind, bHRformessage, ...) { ns , # reKind },
355 #define DEFINE_EXCEPTION_HR_WINRT_ONLY(ns, reKind, ...)
356 #define DEFINE_EXCEPTION_IN_OTHER_FX_ASSEMBLY(ns, reKind, assemblySimpleName, publicKeyToken, bHRformessage, ...)
359 const USHORT c_nMscorlibClassDescriptions = NumItems(c_rgMscorlibClassDescriptions);
361 #define gsig_NoSig (*(HardCodedMetaSig *)NULL)
363 const MscorlibMethodDescription c_rgMscorlibMethodDescriptions[] =
365 #define DEFINE_METHOD(c,i,s,g) { CLASS__ ## c , # s, & gsig_ ## g },
366 #include "mscorlib.h"
368 const USHORT c_nMscorlibMethodDescriptions = NumItems(c_rgMscorlibMethodDescriptions) + 1;
370 const MscorlibFieldDescription c_rgMscorlibFieldDescriptions[] =
372 #define DEFINE_FIELD(c,i,s) { CLASS__ ## c , # s },
373 #include "mscorlib.h"
375 const USHORT c_nMscorlibFieldDescriptions = NumItems(c_rgMscorlibFieldDescriptions) + 1;
381 ///////////////////////////////////////////////////////////////////////////////
386 // When compiling crossgen, we only need the target version of the ecall tables
387 #if !defined(CROSSGEN_COMPILE) || defined(CROSSGEN_MSCORLIB)
389 #ifdef CROSSGEN_COMPILE
391 #define QCFuncElement(name,impl) \
392 FCFuncFlag_QCall + FCFuncFlags(CORINFO_INTRINSIC_Illegal, ECall::InvalidDynamicFCallId), NULL, (LPVOID)name,
394 #define FCFuncFlags(intrinsicID, dynamicID) \
395 (BYTE*)( (((BYTE)intrinsicID) << 16) )
399 #define QCFuncElement(name,impl) \
400 FCFuncFlag_QCall + FCFuncFlags(CORINFO_INTRINSIC_Illegal, ECall::InvalidDynamicFCallId), (LPVOID)(impl), (LPVOID)name,
402 #define FCFuncFlags(intrinsicID, dynamicID) \
403 (BYTE*)( (((BYTE)intrinsicID) << 16) + (((BYTE)dynamicID) << 24) )
407 #define FCFuncElement(name, impl) FCFuncFlags(CORINFO_INTRINSIC_Illegal, ECall::InvalidDynamicFCallId), \
408 (LPVOID)GetEEFuncEntryPoint(impl), (LPVOID)name,
410 #define FCFuncElementSig(name,sig,impl) \
411 FCFuncFlag_HasSignature + FCFuncElement(name, impl) (LPVOID)sig,
413 #define FCIntrinsic(name,impl,intrinsicID) FCFuncFlags(intrinsicID, ECall::InvalidDynamicFCallId), \
414 (LPVOID)GetEEFuncEntryPoint(impl), (LPVOID)name,
416 #define FCIntrinsicSig(name,sig,impl,intrinsicID) \
417 FCFuncFlag_HasSignature + FCIntrinsic(name,impl,intrinsicID) (LPVOID)sig,
419 #define FCDynamic(name,intrinsicID,dynamicID) FCFuncFlags(intrinsicID, dynamicID), \
422 #define FCDynamicSig(name,sig,intrinsicID,dynamicID) \
423 FCFuncFlag_HasSignature + FCDynamic(name,intrinsicID,dynamicID) (LPVOID)sig,
425 #define FCUnreferenced FCFuncFlag_Unreferenced +
427 #define FCFuncStart(name) static const LPVOID name[] = {
428 #define FCFuncEnd() FCFuncFlag_EndOfArray + FCFuncFlags(CORINFO_INTRINSIC_Illegal, ECall::InvalidDynamicFCallId) };
430 #include "ecalllist.h"
433 // Extern definitions so that ecall.cpp can see these tables
434 extern const ECClass c_rgECClasses[];
435 extern const int c_nECClasses;
437 const ECClass c_rgECClasses[] =
439 #define FCClassElement(name,namespace,funcs) {name, namespace, funcs},
440 #include "ecalllist.h"
441 }; // c_rgECClasses[]
443 const int c_nECClasses = NumItems(c_rgECClasses);
445 #endif // !CROSSGEN_COMPILE && CROSSGEN_MSCORLIB
448 #ifdef CROSSGEN_MSCORLIB
449 }; // namespace CrossGenMscorlib