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 "securityimperative.h"
31 #include "securitystackwalk.h"
32 #include "objectnative.h"
33 #include "comdelegate.h"
34 #include "customattribute.h"
35 #include "comdynamic.h"
36 #include "commethodrental.h"
38 #include "calendardata.h"
39 #include "commodule.h"
40 #include "marshalnative.h"
42 #include "comutilnative.h"
43 #include "comsynchronizable.h"
44 #include "floatdouble.h"
45 #include "floatsingle.h"
48 #include "comdatetime.h"
49 #include "comisolatedstorage.h"
50 #include "securityconfig.h"
52 #include "compatibilityswitch.h"
53 #ifdef FEATURE_REMOTING
54 #include "remotingnative.h"
56 #include "stackbuildersink.h"
58 #include "debugdebugger.h"
59 #include "assemblyname.hpp"
60 #include "assemblynative.hpp"
62 #include "comthreadpool.h"
63 #include "comwaithandle.h"
64 #include "nativeoverlapped.h"
66 #include "proftoeeinterfaceimpl.h"
68 #include "appdomainnative.hpp"
69 #include "arrayhelpers.h"
70 #include "runtimehandles.h"
71 #include "reflectioninvocation.h"
72 #include "managedmdimport.hpp"
73 #include "synchronizationcontextnative.h"
74 #include "newcompressedstack.h"
75 #include "commemoryfailpoint.h"
76 #include "typestring.h"
77 #include "comdependenthandle.h"
78 #include "weakreferencenative.h"
79 #include "varargsnative.h"
81 #ifndef FEATURE_CORECLR
82 #include "confighelper.h"
87 #include "mdaassistants.h"
91 #include "cryptography.h"
92 #endif // FEATURE_CRYPTO
94 #ifndef FEATURE_CORECLR
95 #include "securityprincipal.h"
96 #endif // !FEATURE_CORECLR
99 #include "x509certificate.h"
100 #endif // FEATURE_X509
102 #include "coverage.h"
104 #ifdef FEATURE_COMINTEROP
106 #ifdef FEATURE_COMINTEROP_TLB_SUPPORT
107 #include "comtypelibconverter.h"
109 #include "oavariant.h"
110 #include "registration.h"
111 #include "mngstdinterfaces.h"
112 #include "extensibleclassfactory.h"
113 #endif // FEATURE_COMINTEROP
115 #include "stubhelpers.h"
116 #include "ilmarshalers.h"
118 #include "hostexecutioncontext.h"
120 #ifdef FEATURE_MULTICOREJIT
121 #include "multicorejit.h"
124 #ifdef FEATURE_COMINTEROP
125 #include "clrprivtypecachereflectiononlywinrt.h"
128 #ifdef FEATURE_COMINTEROP
129 #include "windowsruntimebufferhelper.h"
132 #if defined(FEATURE_EVENTSOURCE_XPLAT)
133 #include "nativeeventsource.h"
134 #endif //defined(FEATURE_EVENTSOURCE_XPLAT)
136 #endif // CROSSGEN_MSCORLIB
139 #ifdef CROSSGEN_MSCORLIB
141 ///////////////////////////////////////////////////////////////////////////////
143 // Duplicate definitions of constants and datastructures required to define the tables
146 #define NumItems(s) (sizeof(s) / sizeof(s[0]))
148 #define GetEEFuncEntryPoint(pfn) 0x1001
151 FCFuncFlag_EndOfArray = 0x01,
152 FCFuncFlag_HasSignature = 0x02,
153 FCFuncFlag_Unreferenced = 0x04, // Suppress unused fcall check
154 FCFuncFlag_QCall = 0x08, // QCall - mscorlib.dll to mscorwks.dll transition implemented as PInvoke
159 LPCSTR m_szClassName;
160 LPCSTR m_szNameSpace;
161 const LPVOID * m_pECFunc;
164 struct HardCodedMetaSig
166 const BYTE* m_pMetaSig; // metasig prefixed with INT8 length:
167 // length > 0 - resolved, lenght < 0 - has unresolved type references
172 #define TYPEINFO(e,ns,c,s,g,ia,ip,if,im,gv) CLASS__ ## e,
173 #include "cortypeinfo.h"
176 #define DEFINE_CLASS(i,n,s) CLASS__ ## i,
177 #include "mscorlib.h"
179 CLASS__MSCORLIB_COUNT,
181 CLASS__VOID = CLASS__ELEMENT_TYPE_VOID,
182 CLASS__BOOLEAN = CLASS__ELEMENT_TYPE_BOOLEAN,
183 CLASS__CHAR = CLASS__ELEMENT_TYPE_CHAR,
184 CLASS__BYTE = CLASS__ELEMENT_TYPE_U1,
185 CLASS__SBYTE = CLASS__ELEMENT_TYPE_I1,
186 CLASS__INT16 = CLASS__ELEMENT_TYPE_I2,
187 CLASS__UINT16 = CLASS__ELEMENT_TYPE_U2,
188 CLASS__INT32 = CLASS__ELEMENT_TYPE_I4,
189 CLASS__UINT32 = CLASS__ELEMENT_TYPE_U4,
190 CLASS__INT64 = CLASS__ELEMENT_TYPE_I8,
191 CLASS__UINT64 = CLASS__ELEMENT_TYPE_U8,
192 CLASS__SINGLE = CLASS__ELEMENT_TYPE_R4,
193 CLASS__DOUBLE = CLASS__ELEMENT_TYPE_R8,
194 CLASS__STRING = CLASS__ELEMENT_TYPE_STRING,
195 CLASS__TYPED_REFERENCE = CLASS__ELEMENT_TYPE_TYPEDBYREF,
196 CLASS__INTPTR = CLASS__ELEMENT_TYPE_I,
197 CLASS__UINTPTR = CLASS__ELEMENT_TYPE_U,
198 CLASS__OBJECT = CLASS__ELEMENT_TYPE_OBJECT
201 struct MscorlibClassDescription
207 struct MscorlibMethodDescription
209 BinderClassID classID;
211 const HardCodedMetaSig * sig;
214 struct MscorlibFieldDescription
216 BinderClassID classID;
220 #endif // CROSSGEN_MSCORLIB
223 #ifdef CROSSGEN_MSCORLIB
224 // When compiling crossgen this namespace creates the second version of the tables than matches the target
225 namespace CrossGenMscorlib {
229 ///////////////////////////////////////////////////////////////////////////////
231 // Hardcoded Meta-Sig
235 // Helper enum with metasig lengths
237 // iterate over the metasig recursing into the complex types
238 #define DEFINE_METASIG(body) body,
239 #define METASIG_ATOM(x) + 1
240 #define METASIG_RECURSE 1
241 #define SM(varname, args, retval) gsigl_SM_ ## varname = 1 + 1 retval args
242 #define IM(varname, args, retval) gsigl_IM_ ## varname = 1 + 1 retval args
243 #define GM(varname, conv, n, args, retval) gsigl_GM_ ## varname = 1 + 1 + 1 + retval args
244 #define Fld(varname, val) gsigl_Fld_ ## varname = 1 val
250 // Helper enum with metasig argcount
252 // iterate over the metasig without recursing into the complex types
253 #define DEFINE_METASIG(body) body,
254 #define METASIG_ATOM(x) + 1
255 #define METASIG_RECURSE 0
256 #define SM(varname, args, retval) gsigc_SM_ ## varname = 0 args
257 #define IM(varname, args, retval) gsigc_IM_ ## varname = 0 args
258 #define GM(varname, conv, n, args, retval) gsigc_GM_ ## varname = 0 args
259 #define Fld(varname, val) gsigc_Fld_ ## varname = 0
266 // The actual array with the hardcoded metasig:
268 // There are 3 variations of the macros for Fields, Static Methods and Instance Methods.
270 // Each of them has 2 flavors: one for the fully baked signatures, and the other
271 // for the signatures with unresolved type references
273 // The signatures with unresolved type references are marked with negative size,
274 // and the pointer to them is non-const because of it will be overwritten with
275 // the pointer to the resolved signature at runtime.
278 #define DEFINE_METASIG(body) body
279 #define DEFINE_METASIG_T(body) _##body
280 #define METASIG_ATOM(x) x,
281 #define METASIG_RECURSE 1
283 // define gsig_ ## varname before gsige_ ## varname to give a hint to the compiler about the desired layout
285 #define SM(varname, args, retval) extern const BYTE gsige_SM_ ## varname[]; \
286 const HardCodedMetaSig gsig_SM_ ## varname = { gsige_SM_ ## varname }; \
287 const BYTE gsige_SM_ ## varname[] = { gsigl_SM_ ## varname, \
288 IMAGE_CEE_CS_CALLCONV_DEFAULT, gsigc_SM_ ## varname, retval args };
290 #define IM(varname, args, retval) extern const BYTE gsige_IM_ ## varname[]; \
291 const HardCodedMetaSig gsig_IM_ ## varname = { gsige_IM_ ## varname }; \
292 const BYTE gsige_IM_ ## varname[] = { gsigl_IM_ ## varname, \
293 IMAGE_CEE_CS_CALLCONV_HASTHIS, gsigc_IM_ ## varname, retval args };
295 #define GM(varname, conv, n, args, retval) extern const BYTE gsige_GM_ ## varname[]; \
296 const HardCodedMetaSig gsig_GM_ ## varname = { gsige_GM_ ## varname }; \
297 const BYTE gsige_GM_ ## varname[] = { gsigl_GM_ ## varname, \
298 conv | IMAGE_CEE_CS_CALLCONV_GENERIC, n, gsigc_GM_ ## varname, retval args };
300 #define Fld(varname, val) extern const BYTE gsige_Fld_ ## varname[]; \
301 const HardCodedMetaSig gsig_Fld_ ## varname = { gsige_Fld_ ## varname }; \
302 const BYTE gsige_Fld_ ## varname[] = { gsigl_Fld_ ## varname, \
303 IMAGE_CEE_CS_CALLCONV_FIELD, val };
305 #define _SM(varname, args, retval) extern const BYTE gsige_SM_ ## varname[]; \
306 HardCodedMetaSig gsig_SM_ ## varname = { gsige_SM_ ## varname }; \
307 const BYTE gsige_SM_ ## varname[] = { (BYTE) -gsigl_SM_ ## varname, \
308 IMAGE_CEE_CS_CALLCONV_DEFAULT, gsigc_SM_ ## varname, retval args };
310 #define _IM(varname, args, retval) extern const BYTE gsige_IM_ ## varname[]; \
311 HardCodedMetaSig gsig_IM_ ## varname = { gsige_IM_ ## varname }; \
312 const BYTE gsige_IM_ ## varname[] = { (BYTE) -gsigl_IM_ ## varname, \
313 IMAGE_CEE_CS_CALLCONV_HASTHIS, gsigc_IM_ ## varname, retval args };
315 #define _Fld(varname, val) extern const BYTE gsige_Fld_ ## varname[]; \
316 HardCodedMetaSig gsig_Fld_ ## varname = { gsige_Fld_ ## varname }; \
317 const BYTE gsige_Fld_ ## varname[] = { (BYTE) -gsigl_Fld_ ## varname, \
318 IMAGE_CEE_CS_CALLCONV_FIELD, val };
331 // Make sure DEFINE_METASIG is used for signatures that do not reference other types
333 // counts number of type references in the signature and C_ASSERTs that
334 // it is zero. An assertion failure results in error C2118: negative subscript.
335 #define DEFINE_METASIG(body) body
336 #define DEFINE_METASIG_T(body)
337 #define METASIG_BODY(varname, types) C_ASSERT(types 0 == 0);
338 #define METASIG_ATOM(x) 0+
339 #define METASIG_RECURSE 1
345 // Make sure DEFINE_METASIG_T is used only for signatures that reference
348 // counts number of type references in the signature and C_ASSERTs that
349 // it is non zero. An assertion failure results in error C2118: negative subscript.
350 #define DEFINE_METASIG(body)
351 #define DEFINE_METASIG_T(body) body
352 #define METASIG_BODY(varname, types) C_ASSERT(types 0 != 0);
353 #define METASIG_ATOM(x) 0+
354 #define METASIG_RECURSE 1
365 ///////////////////////////////////////////////////////////////////////////////
370 // Extern definitions so that binder.cpp can see these tables
371 extern const MscorlibClassDescription c_rgMscorlibClassDescriptions[];
372 extern const USHORT c_nMscorlibClassDescriptions;
374 extern const MscorlibMethodDescription c_rgMscorlibMethodDescriptions[];
375 extern const USHORT c_nMscorlibMethodDescriptions;
377 extern const MscorlibFieldDescription c_rgMscorlibFieldDescriptions[];
378 extern const USHORT c_nMscorlibFieldDescriptions;
380 const MscorlibClassDescription c_rgMscorlibClassDescriptions[] =
382 #define TYPEINFO(e,ns,c,s,g,ia,ip,if,im,gv) { ns, c },
383 #include "cortypeinfo.h"
386 #define DEFINE_CLASS(i,n,s) { g_ ## n ## NS, # s },
387 #include "namespace.h"
388 #include "mscorlib.h"
390 // Include all exception types here that are defined in mscorlib. Omit exceptions defined elsewhere.
391 #define DEFINE_EXCEPTION(ns, reKind, bHRformessage, ...) { ns , # reKind },
392 #define DEFINE_EXCEPTION_HR_WINRT_ONLY(ns, reKind, ...)
393 #define DEFINE_EXCEPTION_IN_OTHER_FX_ASSEMBLY(ns, reKind, assemblySimpleName, publicKeyToken, bHRformessage, ...)
396 const USHORT c_nMscorlibClassDescriptions = NumItems(c_rgMscorlibClassDescriptions);
398 #define gsig_NoSig (*(HardCodedMetaSig *)NULL)
400 const MscorlibMethodDescription c_rgMscorlibMethodDescriptions[] =
402 #define DEFINE_METHOD(c,i,s,g) { CLASS__ ## c , # s, & gsig_ ## g },
403 #include "mscorlib.h"
405 const USHORT c_nMscorlibMethodDescriptions = NumItems(c_rgMscorlibMethodDescriptions) + 1;
407 const MscorlibFieldDescription c_rgMscorlibFieldDescriptions[] =
409 #define DEFINE_FIELD(c,i,s) { CLASS__ ## c , # s },
410 #include "mscorlib.h"
412 const USHORT c_nMscorlibFieldDescriptions = NumItems(c_rgMscorlibFieldDescriptions) + 1;
418 ///////////////////////////////////////////////////////////////////////////////
423 // When compiling crossgen, we only need the target version of the ecall tables
424 #if !defined(CROSSGEN_COMPILE) || defined(CROSSGEN_MSCORLIB)
426 #ifdef CROSSGEN_COMPILE
428 #define QCFuncElement(name,impl) \
429 FCFuncFlag_QCall + FCFuncFlags(CORINFO_INTRINSIC_Illegal, ECall::InvalidDynamicFCallId), NULL, (LPVOID)name,
431 #define FCFuncFlags(intrinsicID, dynamicID) \
432 (BYTE*)( (((BYTE)intrinsicID) << 16) )
436 #define QCFuncElement(name,impl) \
437 FCFuncFlag_QCall + FCFuncFlags(CORINFO_INTRINSIC_Illegal, ECall::InvalidDynamicFCallId), (LPVOID)(impl), (LPVOID)name,
439 #define FCFuncFlags(intrinsicID, dynamicID) \
440 (BYTE*)( (((BYTE)intrinsicID) << 16) + (((BYTE)dynamicID) << 24) )
444 #define FCFuncElement(name, impl) FCFuncFlags(CORINFO_INTRINSIC_Illegal, ECall::InvalidDynamicFCallId), \
445 (LPVOID)GetEEFuncEntryPoint(impl), (LPVOID)name,
447 #define FCFuncElementSig(name,sig,impl) \
448 FCFuncFlag_HasSignature + FCFuncElement(name, impl) (LPVOID)sig,
450 #define FCIntrinsic(name,impl,intrinsicID) FCFuncFlags(intrinsicID, ECall::InvalidDynamicFCallId), \
451 (LPVOID)GetEEFuncEntryPoint(impl), (LPVOID)name,
453 #define FCIntrinsicSig(name,sig,impl,intrinsicID) \
454 FCFuncFlag_HasSignature + FCIntrinsic(name,impl,intrinsicID) (LPVOID)sig,
456 #define FCDynamic(name,intrinsicID,dynamicID) FCFuncFlags(intrinsicID, dynamicID), \
459 #define FCDynamicSig(name,sig,intrinsicID,dynamicID) \
460 FCFuncFlag_HasSignature + FCDynamic(name,intrinsicID,dynamicID) (LPVOID)sig,
462 #define FCUnreferenced FCFuncFlag_Unreferenced +
464 #define FCFuncStart(name) static const LPVOID name[] = {
465 #define FCFuncEnd() FCFuncFlag_EndOfArray + FCFuncFlags(CORINFO_INTRINSIC_Illegal, ECall::InvalidDynamicFCallId) };
467 #include "ecalllist.h"
470 // Extern definitions so that ecall.cpp can see these tables
471 extern const ECClass c_rgECClasses[];
472 extern const int c_nECClasses;
474 const ECClass c_rgECClasses[] =
476 #define FCClassElement(name,namespace,funcs) {name, namespace, funcs},
477 #include "ecalllist.h"
478 }; // c_rgECClasses[]
480 const int c_nECClasses = NumItems(c_rgECClasses);
482 #endif // !CROSSGEN_COMPILE && CROSSGEN_MSCORLIB
485 #ifdef CROSSGEN_MSCORLIB
486 }; // namespace CrossGenMscorlib