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 #include "oavariant.h"
86 #include "registration.h"
87 #include "mngstdinterfaces.h"
88 #include "extensibleclassfactory.h"
89 #endif // FEATURE_COMINTEROP
91 #include "stubhelpers.h"
92 #include "ilmarshalers.h"
94 #ifdef FEATURE_MULTICOREJIT
95 #include "multicorejit.h"
98 #ifdef FEATURE_COMINTEROP
99 #include "clrprivtypecachereflectiononlywinrt.h"
102 #ifdef FEATURE_COMINTEROP
103 #include "windowsruntimebufferhelper.h"
106 #if defined(FEATURE_EVENTSOURCE_XPLAT)
107 #include "nativeeventsource.h"
108 #endif //defined(FEATURE_EVENTSOURCE_XPLAT)
110 #endif // CROSSGEN_MSCORLIB
113 #ifdef CROSSGEN_MSCORLIB
115 ///////////////////////////////////////////////////////////////////////////////
117 // Duplicate definitions of constants and datastructures required to define the tables
120 #define NumItems(s) (sizeof(s) / sizeof(s[0]))
122 #define GetEEFuncEntryPoint(pfn) 0x1001
125 FCFuncFlag_EndOfArray = 0x01,
126 FCFuncFlag_HasSignature = 0x02,
127 FCFuncFlag_Unreferenced = 0x04, // Suppress unused fcall check
128 FCFuncFlag_QCall = 0x08, // QCall - mscorlib.dll to mscorwks.dll transition implemented as PInvoke
133 LPCSTR m_szClassName;
134 LPCSTR m_szNameSpace;
135 const LPVOID * m_pECFunc;
138 struct HardCodedMetaSig
140 const BYTE* m_pMetaSig; // metasig prefixed with INT8 length:
141 // length > 0 - resolved, lenght < 0 - has unresolved type references
146 #define TYPEINFO(e,ns,c,s,g,ia,ip,if,im,gv) CLASS__ ## e,
147 #include "cortypeinfo.h"
150 #define DEFINE_CLASS(i,n,s) CLASS__ ## i,
151 #include "mscorlib.h"
153 CLASS__MSCORLIB_COUNT,
155 CLASS__VOID = CLASS__ELEMENT_TYPE_VOID,
156 CLASS__BOOLEAN = CLASS__ELEMENT_TYPE_BOOLEAN,
157 CLASS__CHAR = CLASS__ELEMENT_TYPE_CHAR,
158 CLASS__BYTE = CLASS__ELEMENT_TYPE_U1,
159 CLASS__SBYTE = CLASS__ELEMENT_TYPE_I1,
160 CLASS__INT16 = CLASS__ELEMENT_TYPE_I2,
161 CLASS__UINT16 = CLASS__ELEMENT_TYPE_U2,
162 CLASS__INT32 = CLASS__ELEMENT_TYPE_I4,
163 CLASS__UINT32 = CLASS__ELEMENT_TYPE_U4,
164 CLASS__INT64 = CLASS__ELEMENT_TYPE_I8,
165 CLASS__UINT64 = CLASS__ELEMENT_TYPE_U8,
166 CLASS__SINGLE = CLASS__ELEMENT_TYPE_R4,
167 CLASS__DOUBLE = CLASS__ELEMENT_TYPE_R8,
168 CLASS__STRING = CLASS__ELEMENT_TYPE_STRING,
169 CLASS__TYPED_REFERENCE = CLASS__ELEMENT_TYPE_TYPEDBYREF,
170 CLASS__INTPTR = CLASS__ELEMENT_TYPE_I,
171 CLASS__UINTPTR = CLASS__ELEMENT_TYPE_U,
172 CLASS__OBJECT = CLASS__ELEMENT_TYPE_OBJECT
175 struct MscorlibClassDescription
181 struct MscorlibMethodDescription
183 BinderClassID classID;
185 const HardCodedMetaSig * sig;
188 struct MscorlibFieldDescription
190 BinderClassID classID;
194 #endif // CROSSGEN_MSCORLIB
197 #ifdef CROSSGEN_MSCORLIB
198 // When compiling crossgen this namespace creates the second version of the tables than matches the target
199 namespace CrossGenMscorlib {
203 ///////////////////////////////////////////////////////////////////////////////
205 // Hardcoded Meta-Sig
209 // Helper enum with metasig lengths
211 // iterate over the metasig recursing into the complex types
212 #define DEFINE_METASIG(body) body,
213 #define METASIG_ATOM(x) + 1
214 #define METASIG_RECURSE 1
215 #define SM(varname, args, retval) gsigl_SM_ ## varname = 1 + 1 retval args
216 #define IM(varname, args, retval) gsigl_IM_ ## varname = 1 + 1 retval args
217 #define GM(varname, conv, n, args, retval) gsigl_GM_ ## varname = 1 + 1 + 1 + retval args
218 #define Fld(varname, val) gsigl_Fld_ ## varname = 1 val
224 // Helper enum with metasig argcount
226 // iterate over the metasig without recursing into the complex types
227 #define DEFINE_METASIG(body) body,
228 #define METASIG_ATOM(x) + 1
229 #define METASIG_RECURSE 0
230 #define SM(varname, args, retval) gsigc_SM_ ## varname = 0 args
231 #define IM(varname, args, retval) gsigc_IM_ ## varname = 0 args
232 #define GM(varname, conv, n, args, retval) gsigc_GM_ ## varname = 0 args
233 #define Fld(varname, val) gsigc_Fld_ ## varname = 0
240 // The actual array with the hardcoded metasig:
242 // There are 3 variations of the macros for Fields, Static Methods and Instance Methods.
244 // Each of them has 2 flavors: one for the fully baked signatures, and the other
245 // for the signatures with unresolved type references
247 // The signatures with unresolved type references are marked with negative size,
248 // and the pointer to them is non-const because of it will be overwritten with
249 // the pointer to the resolved signature at runtime.
252 #define DEFINE_METASIG(body) body
253 #define DEFINE_METASIG_T(body) _##body
254 #define METASIG_ATOM(x) x,
255 #define METASIG_RECURSE 1
257 // define gsig_ ## varname before gsige_ ## varname to give a hint to the compiler about the desired layout
259 #define SM(varname, args, retval) extern const BYTE gsige_SM_ ## varname[]; \
260 const HardCodedMetaSig gsig_SM_ ## varname = { gsige_SM_ ## varname }; \
261 const BYTE gsige_SM_ ## varname[] = { gsigl_SM_ ## varname, \
262 IMAGE_CEE_CS_CALLCONV_DEFAULT, gsigc_SM_ ## varname, retval args };
264 #define IM(varname, args, retval) extern const BYTE gsige_IM_ ## varname[]; \
265 const HardCodedMetaSig gsig_IM_ ## varname = { gsige_IM_ ## varname }; \
266 const BYTE gsige_IM_ ## varname[] = { gsigl_IM_ ## varname, \
267 IMAGE_CEE_CS_CALLCONV_HASTHIS, gsigc_IM_ ## varname, retval args };
269 #define GM(varname, conv, n, args, retval) extern const BYTE gsige_GM_ ## varname[]; \
270 const HardCodedMetaSig gsig_GM_ ## varname = { gsige_GM_ ## varname }; \
271 const BYTE gsige_GM_ ## varname[] = { gsigl_GM_ ## varname, \
272 conv | IMAGE_CEE_CS_CALLCONV_GENERIC, n, gsigc_GM_ ## varname, retval args };
274 #define Fld(varname, val) extern const BYTE gsige_Fld_ ## varname[]; \
275 const HardCodedMetaSig gsig_Fld_ ## varname = { gsige_Fld_ ## varname }; \
276 const BYTE gsige_Fld_ ## varname[] = { gsigl_Fld_ ## varname, \
277 IMAGE_CEE_CS_CALLCONV_FIELD, val };
279 #define _SM(varname, args, retval) extern const BYTE gsige_SM_ ## varname[]; \
280 HardCodedMetaSig gsig_SM_ ## varname = { gsige_SM_ ## varname }; \
281 const BYTE gsige_SM_ ## varname[] = { (BYTE) -gsigl_SM_ ## varname, \
282 IMAGE_CEE_CS_CALLCONV_DEFAULT, gsigc_SM_ ## varname, retval args };
284 #define _IM(varname, args, retval) extern const BYTE gsige_IM_ ## varname[]; \
285 HardCodedMetaSig gsig_IM_ ## varname = { gsige_IM_ ## varname }; \
286 const BYTE gsige_IM_ ## varname[] = { (BYTE) -gsigl_IM_ ## varname, \
287 IMAGE_CEE_CS_CALLCONV_HASTHIS, gsigc_IM_ ## varname, retval args };
289 #define _Fld(varname, val) extern const BYTE gsige_Fld_ ## varname[]; \
290 HardCodedMetaSig gsig_Fld_ ## varname = { gsige_Fld_ ## varname }; \
291 const BYTE gsige_Fld_ ## varname[] = { (BYTE) -gsigl_Fld_ ## varname, \
292 IMAGE_CEE_CS_CALLCONV_FIELD, val };
305 // Make sure DEFINE_METASIG is used for signatures that do not reference other types
307 // counts number of type references in the signature and C_ASSERTs that
308 // it is zero. An assertion failure results in error C2118: negative subscript.
309 #define DEFINE_METASIG(body) body
310 #define DEFINE_METASIG_T(body)
311 #define METASIG_BODY(varname, types) C_ASSERT(types 0 == 0);
312 #define METASIG_ATOM(x) 0+
313 #define METASIG_RECURSE 1
319 // Make sure DEFINE_METASIG_T is used only for signatures that reference
322 // counts number of type references in the signature and C_ASSERTs that
323 // it is non zero. An assertion failure results in error C2118: negative subscript.
324 #define DEFINE_METASIG(body)
325 #define DEFINE_METASIG_T(body) body
326 #define METASIG_BODY(varname, types) C_ASSERT(types 0 != 0);
327 #define METASIG_ATOM(x) 0+
328 #define METASIG_RECURSE 1
339 ///////////////////////////////////////////////////////////////////////////////
344 // Extern definitions so that binder.cpp can see these tables
345 extern const MscorlibClassDescription c_rgMscorlibClassDescriptions[];
346 extern const USHORT c_nMscorlibClassDescriptions;
348 extern const MscorlibMethodDescription c_rgMscorlibMethodDescriptions[];
349 extern const USHORT c_nMscorlibMethodDescriptions;
351 extern const MscorlibFieldDescription c_rgMscorlibFieldDescriptions[];
352 extern const USHORT c_nMscorlibFieldDescriptions;
354 const MscorlibClassDescription c_rgMscorlibClassDescriptions[] =
356 #define TYPEINFO(e,ns,c,s,g,ia,ip,if,im,gv) { ns, c },
357 #include "cortypeinfo.h"
360 #define DEFINE_CLASS(i,n,s) { g_ ## n ## NS, # s },
361 #include "namespace.h"
362 #include "mscorlib.h"
364 // Include all exception types here that are defined in mscorlib. Omit exceptions defined elsewhere.
365 #define DEFINE_EXCEPTION(ns, reKind, bHRformessage, ...) { ns , # reKind },
366 #define DEFINE_EXCEPTION_HR_WINRT_ONLY(ns, reKind, ...)
367 #define DEFINE_EXCEPTION_IN_OTHER_FX_ASSEMBLY(ns, reKind, assemblySimpleName, publicKeyToken, bHRformessage, ...)
370 const USHORT c_nMscorlibClassDescriptions = NumItems(c_rgMscorlibClassDescriptions);
372 #define gsig_NoSig (*(HardCodedMetaSig *)NULL)
374 const MscorlibMethodDescription c_rgMscorlibMethodDescriptions[] =
376 #define DEFINE_METHOD(c,i,s,g) { CLASS__ ## c , # s, & gsig_ ## g },
377 #include "mscorlib.h"
379 const USHORT c_nMscorlibMethodDescriptions = NumItems(c_rgMscorlibMethodDescriptions) + 1;
381 const MscorlibFieldDescription c_rgMscorlibFieldDescriptions[] =
383 #define DEFINE_FIELD(c,i,s) { CLASS__ ## c , # s },
384 #include "mscorlib.h"
386 const USHORT c_nMscorlibFieldDescriptions = NumItems(c_rgMscorlibFieldDescriptions) + 1;
392 ///////////////////////////////////////////////////////////////////////////////
397 // When compiling crossgen, we only need the target version of the ecall tables
398 #if !defined(CROSSGEN_COMPILE) || defined(CROSSGEN_MSCORLIB)
400 #ifdef CROSSGEN_COMPILE
402 #define QCFuncElement(name,impl) \
403 FCFuncFlag_QCall + FCFuncFlags(CORINFO_INTRINSIC_Illegal, ECall::InvalidDynamicFCallId), NULL, (LPVOID)name,
405 #define FCFuncFlags(intrinsicID, dynamicID) \
406 (BYTE*)( (((BYTE)intrinsicID) << 16) )
410 #define QCFuncElement(name,impl) \
411 FCFuncFlag_QCall + FCFuncFlags(CORINFO_INTRINSIC_Illegal, ECall::InvalidDynamicFCallId), (LPVOID)(impl), (LPVOID)name,
413 #define FCFuncFlags(intrinsicID, dynamicID) \
414 (BYTE*)( (((BYTE)intrinsicID) << 16) + (((BYTE)dynamicID) << 24) )
418 #define FCFuncElement(name, impl) FCFuncFlags(CORINFO_INTRINSIC_Illegal, ECall::InvalidDynamicFCallId), \
419 (LPVOID)GetEEFuncEntryPoint(impl), (LPVOID)name,
421 #define FCFuncElementSig(name,sig,impl) \
422 FCFuncFlag_HasSignature + FCFuncElement(name, impl) (LPVOID)sig,
424 #define FCIntrinsic(name,impl,intrinsicID) FCFuncFlags(intrinsicID, ECall::InvalidDynamicFCallId), \
425 (LPVOID)GetEEFuncEntryPoint(impl), (LPVOID)name,
427 #define FCIntrinsicSig(name,sig,impl,intrinsicID) \
428 FCFuncFlag_HasSignature + FCIntrinsic(name,impl,intrinsicID) (LPVOID)sig,
430 #define FCDynamic(name,intrinsicID,dynamicID) FCFuncFlags(intrinsicID, dynamicID), \
433 #define FCDynamicSig(name,sig,intrinsicID,dynamicID) \
434 FCFuncFlag_HasSignature + FCDynamic(name,intrinsicID,dynamicID) (LPVOID)sig,
436 #define FCUnreferenced FCFuncFlag_Unreferenced +
438 #define FCFuncStart(name) static const LPVOID name[] = {
439 #define FCFuncEnd() FCFuncFlag_EndOfArray + FCFuncFlags(CORINFO_INTRINSIC_Illegal, ECall::InvalidDynamicFCallId) };
441 #include "ecalllist.h"
444 // Extern definitions so that ecall.cpp can see these tables
445 extern const ECClass c_rgECClasses[];
446 extern const int c_nECClasses;
448 const ECClass c_rgECClasses[] =
450 #define FCClassElement(name,namespace,funcs) {name, namespace, funcs},
451 #include "ecalllist.h"
452 }; // c_rgECClasses[]
454 const int c_nECClasses = NumItems(c_rgECClasses);
456 #endif // !CROSSGEN_COMPILE && CROSSGEN_MSCORLIB
459 #ifdef CROSSGEN_MSCORLIB
460 }; // namespace CrossGenMscorlib