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"
34 #include "commethodrental.h"
36 #include "calendardata.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"
47 #include "comisolatedstorage.h"
49 #include "compatibilityswitch.h"
50 #ifdef FEATURE_REMOTING
51 #include "remotingnative.h"
53 #include "stackbuildersink.h"
55 #include "debugdebugger.h"
56 #include "assemblyname.hpp"
57 #include "assemblynative.hpp"
59 #include "comthreadpool.h"
60 #include "comwaithandle.h"
61 #include "nativeoverlapped.h"
63 #include "proftoeeinterfaceimpl.h"
65 #include "appdomainnative.hpp"
66 #include "arrayhelpers.h"
67 #include "runtimehandles.h"
68 #include "reflectioninvocation.h"
69 #include "managedmdimport.hpp"
70 #include "synchronizationcontextnative.h"
71 #include "commemoryfailpoint.h"
72 #include "typestring.h"
73 #include "comdependenthandle.h"
74 #include "weakreferencenative.h"
75 #include "varargsnative.h"
78 #include "mdaassistants.h"
83 #ifdef FEATURE_COMINTEROP
85 #ifdef FEATURE_COMINTEROP_TLB_SUPPORT
86 #include "comtypelibconverter.h"
88 #include "oavariant.h"
89 #include "registration.h"
90 #include "mngstdinterfaces.h"
91 #include "extensibleclassfactory.h"
92 #endif // FEATURE_COMINTEROP
94 #include "stubhelpers.h"
95 #include "ilmarshalers.h"
97 #ifdef FEATURE_MULTICOREJIT
98 #include "multicorejit.h"
101 #ifdef FEATURE_COMINTEROP
102 #include "clrprivtypecachereflectiononlywinrt.h"
105 #ifdef FEATURE_COMINTEROP
106 #include "windowsruntimebufferhelper.h"
109 #if defined(FEATURE_EVENTSOURCE_XPLAT)
110 #include "nativeeventsource.h"
111 #endif //defined(FEATURE_EVENTSOURCE_XPLAT)
113 #endif // CROSSGEN_MSCORLIB
116 #ifdef CROSSGEN_MSCORLIB
118 ///////////////////////////////////////////////////////////////////////////////
120 // Duplicate definitions of constants and datastructures required to define the tables
123 #define NumItems(s) (sizeof(s) / sizeof(s[0]))
125 #define GetEEFuncEntryPoint(pfn) 0x1001
128 FCFuncFlag_EndOfArray = 0x01,
129 FCFuncFlag_HasSignature = 0x02,
130 FCFuncFlag_Unreferenced = 0x04, // Suppress unused fcall check
131 FCFuncFlag_QCall = 0x08, // QCall - mscorlib.dll to mscorwks.dll transition implemented as PInvoke
136 LPCSTR m_szClassName;
137 LPCSTR m_szNameSpace;
138 const LPVOID * m_pECFunc;
141 struct HardCodedMetaSig
143 const BYTE* m_pMetaSig; // metasig prefixed with INT8 length:
144 // length > 0 - resolved, lenght < 0 - has unresolved type references
149 #define TYPEINFO(e,ns,c,s,g,ia,ip,if,im,gv) CLASS__ ## e,
150 #include "cortypeinfo.h"
153 #define DEFINE_CLASS(i,n,s) CLASS__ ## i,
154 #include "mscorlib.h"
156 CLASS__MSCORLIB_COUNT,
158 CLASS__VOID = CLASS__ELEMENT_TYPE_VOID,
159 CLASS__BOOLEAN = CLASS__ELEMENT_TYPE_BOOLEAN,
160 CLASS__CHAR = CLASS__ELEMENT_TYPE_CHAR,
161 CLASS__BYTE = CLASS__ELEMENT_TYPE_U1,
162 CLASS__SBYTE = CLASS__ELEMENT_TYPE_I1,
163 CLASS__INT16 = CLASS__ELEMENT_TYPE_I2,
164 CLASS__UINT16 = CLASS__ELEMENT_TYPE_U2,
165 CLASS__INT32 = CLASS__ELEMENT_TYPE_I4,
166 CLASS__UINT32 = CLASS__ELEMENT_TYPE_U4,
167 CLASS__INT64 = CLASS__ELEMENT_TYPE_I8,
168 CLASS__UINT64 = CLASS__ELEMENT_TYPE_U8,
169 CLASS__SINGLE = CLASS__ELEMENT_TYPE_R4,
170 CLASS__DOUBLE = CLASS__ELEMENT_TYPE_R8,
171 CLASS__STRING = CLASS__ELEMENT_TYPE_STRING,
172 CLASS__TYPED_REFERENCE = CLASS__ELEMENT_TYPE_TYPEDBYREF,
173 CLASS__INTPTR = CLASS__ELEMENT_TYPE_I,
174 CLASS__UINTPTR = CLASS__ELEMENT_TYPE_U,
175 CLASS__OBJECT = CLASS__ELEMENT_TYPE_OBJECT
178 struct MscorlibClassDescription
184 struct MscorlibMethodDescription
186 BinderClassID classID;
188 const HardCodedMetaSig * sig;
191 struct MscorlibFieldDescription
193 BinderClassID classID;
197 #endif // CROSSGEN_MSCORLIB
200 #ifdef CROSSGEN_MSCORLIB
201 // When compiling crossgen this namespace creates the second version of the tables than matches the target
202 namespace CrossGenMscorlib {
206 ///////////////////////////////////////////////////////////////////////////////
208 // Hardcoded Meta-Sig
212 // Helper enum with metasig lengths
214 // iterate over the metasig recursing into the complex types
215 #define DEFINE_METASIG(body) body,
216 #define METASIG_ATOM(x) + 1
217 #define METASIG_RECURSE 1
218 #define SM(varname, args, retval) gsigl_SM_ ## varname = 1 + 1 retval args
219 #define IM(varname, args, retval) gsigl_IM_ ## varname = 1 + 1 retval args
220 #define GM(varname, conv, n, args, retval) gsigl_GM_ ## varname = 1 + 1 + 1 + retval args
221 #define Fld(varname, val) gsigl_Fld_ ## varname = 1 val
227 // Helper enum with metasig argcount
229 // iterate over the metasig without recursing into the complex types
230 #define DEFINE_METASIG(body) body,
231 #define METASIG_ATOM(x) + 1
232 #define METASIG_RECURSE 0
233 #define SM(varname, args, retval) gsigc_SM_ ## varname = 0 args
234 #define IM(varname, args, retval) gsigc_IM_ ## varname = 0 args
235 #define GM(varname, conv, n, args, retval) gsigc_GM_ ## varname = 0 args
236 #define Fld(varname, val) gsigc_Fld_ ## varname = 0
243 // The actual array with the hardcoded metasig:
245 // There are 3 variations of the macros for Fields, Static Methods and Instance Methods.
247 // Each of them has 2 flavors: one for the fully baked signatures, and the other
248 // for the signatures with unresolved type references
250 // The signatures with unresolved type references are marked with negative size,
251 // and the pointer to them is non-const because of it will be overwritten with
252 // the pointer to the resolved signature at runtime.
255 #define DEFINE_METASIG(body) body
256 #define DEFINE_METASIG_T(body) _##body
257 #define METASIG_ATOM(x) x,
258 #define METASIG_RECURSE 1
260 // define gsig_ ## varname before gsige_ ## varname to give a hint to the compiler about the desired layout
262 #define SM(varname, args, retval) extern const BYTE gsige_SM_ ## varname[]; \
263 const HardCodedMetaSig gsig_SM_ ## varname = { gsige_SM_ ## varname }; \
264 const BYTE gsige_SM_ ## varname[] = { gsigl_SM_ ## varname, \
265 IMAGE_CEE_CS_CALLCONV_DEFAULT, gsigc_SM_ ## varname, retval args };
267 #define IM(varname, args, retval) extern const BYTE gsige_IM_ ## varname[]; \
268 const HardCodedMetaSig gsig_IM_ ## varname = { gsige_IM_ ## varname }; \
269 const BYTE gsige_IM_ ## varname[] = { gsigl_IM_ ## varname, \
270 IMAGE_CEE_CS_CALLCONV_HASTHIS, gsigc_IM_ ## varname, retval args };
272 #define GM(varname, conv, n, args, retval) extern const BYTE gsige_GM_ ## varname[]; \
273 const HardCodedMetaSig gsig_GM_ ## varname = { gsige_GM_ ## varname }; \
274 const BYTE gsige_GM_ ## varname[] = { gsigl_GM_ ## varname, \
275 conv | IMAGE_CEE_CS_CALLCONV_GENERIC, n, gsigc_GM_ ## varname, retval args };
277 #define Fld(varname, val) extern const BYTE gsige_Fld_ ## varname[]; \
278 const HardCodedMetaSig gsig_Fld_ ## varname = { gsige_Fld_ ## varname }; \
279 const BYTE gsige_Fld_ ## varname[] = { gsigl_Fld_ ## varname, \
280 IMAGE_CEE_CS_CALLCONV_FIELD, val };
282 #define _SM(varname, args, retval) extern const BYTE gsige_SM_ ## varname[]; \
283 HardCodedMetaSig gsig_SM_ ## varname = { gsige_SM_ ## varname }; \
284 const BYTE gsige_SM_ ## varname[] = { (BYTE) -gsigl_SM_ ## varname, \
285 IMAGE_CEE_CS_CALLCONV_DEFAULT, gsigc_SM_ ## varname, retval args };
287 #define _IM(varname, args, retval) extern const BYTE gsige_IM_ ## varname[]; \
288 HardCodedMetaSig gsig_IM_ ## varname = { gsige_IM_ ## varname }; \
289 const BYTE gsige_IM_ ## varname[] = { (BYTE) -gsigl_IM_ ## varname, \
290 IMAGE_CEE_CS_CALLCONV_HASTHIS, gsigc_IM_ ## varname, retval args };
292 #define _Fld(varname, val) extern const BYTE gsige_Fld_ ## varname[]; \
293 HardCodedMetaSig gsig_Fld_ ## varname = { gsige_Fld_ ## varname }; \
294 const BYTE gsige_Fld_ ## varname[] = { (BYTE) -gsigl_Fld_ ## varname, \
295 IMAGE_CEE_CS_CALLCONV_FIELD, val };
308 // Make sure DEFINE_METASIG is used for signatures that do not reference other types
310 // counts number of type references in the signature and C_ASSERTs that
311 // it is zero. An assertion failure results in error C2118: negative subscript.
312 #define DEFINE_METASIG(body) body
313 #define DEFINE_METASIG_T(body)
314 #define METASIG_BODY(varname, types) C_ASSERT(types 0 == 0);
315 #define METASIG_ATOM(x) 0+
316 #define METASIG_RECURSE 1
322 // Make sure DEFINE_METASIG_T is used only for signatures that reference
325 // counts number of type references in the signature and C_ASSERTs that
326 // it is non zero. An assertion failure results in error C2118: negative subscript.
327 #define DEFINE_METASIG(body)
328 #define DEFINE_METASIG_T(body) body
329 #define METASIG_BODY(varname, types) C_ASSERT(types 0 != 0);
330 #define METASIG_ATOM(x) 0+
331 #define METASIG_RECURSE 1
342 ///////////////////////////////////////////////////////////////////////////////
347 // Extern definitions so that binder.cpp can see these tables
348 extern const MscorlibClassDescription c_rgMscorlibClassDescriptions[];
349 extern const USHORT c_nMscorlibClassDescriptions;
351 extern const MscorlibMethodDescription c_rgMscorlibMethodDescriptions[];
352 extern const USHORT c_nMscorlibMethodDescriptions;
354 extern const MscorlibFieldDescription c_rgMscorlibFieldDescriptions[];
355 extern const USHORT c_nMscorlibFieldDescriptions;
357 const MscorlibClassDescription c_rgMscorlibClassDescriptions[] =
359 #define TYPEINFO(e,ns,c,s,g,ia,ip,if,im,gv) { ns, c },
360 #include "cortypeinfo.h"
363 #define DEFINE_CLASS(i,n,s) { g_ ## n ## NS, # s },
364 #include "namespace.h"
365 #include "mscorlib.h"
367 // Include all exception types here that are defined in mscorlib. Omit exceptions defined elsewhere.
368 #define DEFINE_EXCEPTION(ns, reKind, bHRformessage, ...) { ns , # reKind },
369 #define DEFINE_EXCEPTION_HR_WINRT_ONLY(ns, reKind, ...)
370 #define DEFINE_EXCEPTION_IN_OTHER_FX_ASSEMBLY(ns, reKind, assemblySimpleName, publicKeyToken, bHRformessage, ...)
373 const USHORT c_nMscorlibClassDescriptions = NumItems(c_rgMscorlibClassDescriptions);
375 #define gsig_NoSig (*(HardCodedMetaSig *)NULL)
377 const MscorlibMethodDescription c_rgMscorlibMethodDescriptions[] =
379 #define DEFINE_METHOD(c,i,s,g) { CLASS__ ## c , # s, & gsig_ ## g },
380 #include "mscorlib.h"
382 const USHORT c_nMscorlibMethodDescriptions = NumItems(c_rgMscorlibMethodDescriptions) + 1;
384 const MscorlibFieldDescription c_rgMscorlibFieldDescriptions[] =
386 #define DEFINE_FIELD(c,i,s) { CLASS__ ## c , # s },
387 #include "mscorlib.h"
389 const USHORT c_nMscorlibFieldDescriptions = NumItems(c_rgMscorlibFieldDescriptions) + 1;
395 ///////////////////////////////////////////////////////////////////////////////
400 // When compiling crossgen, we only need the target version of the ecall tables
401 #if !defined(CROSSGEN_COMPILE) || defined(CROSSGEN_MSCORLIB)
403 #ifdef CROSSGEN_COMPILE
405 #define QCFuncElement(name,impl) \
406 FCFuncFlag_QCall + FCFuncFlags(CORINFO_INTRINSIC_Illegal, ECall::InvalidDynamicFCallId), NULL, (LPVOID)name,
408 #define FCFuncFlags(intrinsicID, dynamicID) \
409 (BYTE*)( (((BYTE)intrinsicID) << 16) )
413 #define QCFuncElement(name,impl) \
414 FCFuncFlag_QCall + FCFuncFlags(CORINFO_INTRINSIC_Illegal, ECall::InvalidDynamicFCallId), (LPVOID)(impl), (LPVOID)name,
416 #define FCFuncFlags(intrinsicID, dynamicID) \
417 (BYTE*)( (((BYTE)intrinsicID) << 16) + (((BYTE)dynamicID) << 24) )
421 #define FCFuncElement(name, impl) FCFuncFlags(CORINFO_INTRINSIC_Illegal, ECall::InvalidDynamicFCallId), \
422 (LPVOID)GetEEFuncEntryPoint(impl), (LPVOID)name,
424 #define FCFuncElementSig(name,sig,impl) \
425 FCFuncFlag_HasSignature + FCFuncElement(name, impl) (LPVOID)sig,
427 #define FCIntrinsic(name,impl,intrinsicID) FCFuncFlags(intrinsicID, ECall::InvalidDynamicFCallId), \
428 (LPVOID)GetEEFuncEntryPoint(impl), (LPVOID)name,
430 #define FCIntrinsicSig(name,sig,impl,intrinsicID) \
431 FCFuncFlag_HasSignature + FCIntrinsic(name,impl,intrinsicID) (LPVOID)sig,
433 #define FCDynamic(name,intrinsicID,dynamicID) FCFuncFlags(intrinsicID, dynamicID), \
436 #define FCDynamicSig(name,sig,intrinsicID,dynamicID) \
437 FCFuncFlag_HasSignature + FCDynamic(name,intrinsicID,dynamicID) (LPVOID)sig,
439 #define FCUnreferenced FCFuncFlag_Unreferenced +
441 #define FCFuncStart(name) static const LPVOID name[] = {
442 #define FCFuncEnd() FCFuncFlag_EndOfArray + FCFuncFlags(CORINFO_INTRINSIC_Illegal, ECall::InvalidDynamicFCallId) };
444 #include "ecalllist.h"
447 // Extern definitions so that ecall.cpp can see these tables
448 extern const ECClass c_rgECClasses[];
449 extern const int c_nECClasses;
451 const ECClass c_rgECClasses[] =
453 #define FCClassElement(name,namespace,funcs) {name, namespace, funcs},
454 #include "ecalllist.h"
455 }; // c_rgECClasses[]
457 const int c_nECClasses = NumItems(c_rgECClasses);
459 #endif // !CROSSGEN_COMPILE && CROSSGEN_MSCORLIB
462 #ifdef CROSSGEN_MSCORLIB
463 }; // namespace CrossGenMscorlib