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 "calendardata.h"
38 #include "commodule.h"
39 #include "marshalnative.h"
41 #include "comutilnative.h"
42 #include "comsynchronizable.h"
43 #include "floatdouble.h"
44 #include "floatsingle.h"
47 #include "comdatetime.h"
48 #include "comisolatedstorage.h"
50 #include "compatibilityswitch.h"
51 #ifdef FEATURE_REMOTING
52 #include "remotingnative.h"
54 #include "stackbuildersink.h"
56 #include "debugdebugger.h"
57 #include "assemblyname.hpp"
58 #include "assemblynative.hpp"
60 #include "comthreadpool.h"
61 #include "comwaithandle.h"
62 #include "nativeoverlapped.h"
64 #include "proftoeeinterfaceimpl.h"
66 #include "appdomainnative.hpp"
67 #include "arrayhelpers.h"
68 #include "runtimehandles.h"
69 #include "reflectioninvocation.h"
70 #include "managedmdimport.hpp"
71 #include "synchronizationcontextnative.h"
72 #include "commemoryfailpoint.h"
73 #include "typestring.h"
74 #include "comdependenthandle.h"
75 #include "weakreferencenative.h"
76 #include "varargsnative.h"
79 #include "mdaassistants.h"
84 #ifdef FEATURE_COMINTEROP
86 #include "oavariant.h"
87 #include "registration.h"
88 #include "mngstdinterfaces.h"
89 #include "extensibleclassfactory.h"
90 #endif // FEATURE_COMINTEROP
92 #include "stubhelpers.h"
93 #include "ilmarshalers.h"
95 #ifdef FEATURE_MULTICOREJIT
96 #include "multicorejit.h"
99 #if defined(FEATURE_COMINTEROP) && defined(FEATURE_REFLECTION_ONLY_LOAD)
100 #include "clrprivtypecachereflectiononlywinrt.h"
103 #ifdef FEATURE_COMINTEROP
104 #include "windowsruntimebufferhelper.h"
107 #if defined(FEATURE_EVENTSOURCE_XPLAT)
108 #include "nativeeventsource.h"
109 #endif //defined(FEATURE_EVENTSOURCE_XPLAT)
111 #endif // CROSSGEN_MSCORLIB
114 #ifdef CROSSGEN_MSCORLIB
116 ///////////////////////////////////////////////////////////////////////////////
118 // Duplicate definitions of constants and datastructures required to define the tables
121 #define NumItems(s) (sizeof(s) / sizeof(s[0]))
123 #define GetEEFuncEntryPoint(pfn) 0x1001
126 FCFuncFlag_EndOfArray = 0x01,
127 FCFuncFlag_HasSignature = 0x02,
128 FCFuncFlag_Unreferenced = 0x04, // Suppress unused fcall check
129 FCFuncFlag_QCall = 0x08, // QCall - mscorlib.dll to mscorwks.dll transition implemented as PInvoke
134 LPCSTR m_szClassName;
135 LPCSTR m_szNameSpace;
136 const LPVOID * m_pECFunc;
139 struct HardCodedMetaSig
141 const BYTE* m_pMetaSig; // metasig prefixed with INT8 length:
142 // length > 0 - resolved, lenght < 0 - has unresolved type references
147 #define TYPEINFO(e,ns,c,s,g,ia,ip,if,im,gv) CLASS__ ## e,
148 #include "cortypeinfo.h"
151 #define DEFINE_CLASS(i,n,s) CLASS__ ## i,
152 #include "mscorlib.h"
154 CLASS__MSCORLIB_COUNT,
156 CLASS__VOID = CLASS__ELEMENT_TYPE_VOID,
157 CLASS__BOOLEAN = CLASS__ELEMENT_TYPE_BOOLEAN,
158 CLASS__CHAR = CLASS__ELEMENT_TYPE_CHAR,
159 CLASS__BYTE = CLASS__ELEMENT_TYPE_U1,
160 CLASS__SBYTE = CLASS__ELEMENT_TYPE_I1,
161 CLASS__INT16 = CLASS__ELEMENT_TYPE_I2,
162 CLASS__UINT16 = CLASS__ELEMENT_TYPE_U2,
163 CLASS__INT32 = CLASS__ELEMENT_TYPE_I4,
164 CLASS__UINT32 = CLASS__ELEMENT_TYPE_U4,
165 CLASS__INT64 = CLASS__ELEMENT_TYPE_I8,
166 CLASS__UINT64 = CLASS__ELEMENT_TYPE_U8,
167 CLASS__SINGLE = CLASS__ELEMENT_TYPE_R4,
168 CLASS__DOUBLE = CLASS__ELEMENT_TYPE_R8,
169 CLASS__STRING = CLASS__ELEMENT_TYPE_STRING,
170 CLASS__TYPED_REFERENCE = CLASS__ELEMENT_TYPE_TYPEDBYREF,
171 CLASS__INTPTR = CLASS__ELEMENT_TYPE_I,
172 CLASS__UINTPTR = CLASS__ELEMENT_TYPE_U,
173 CLASS__OBJECT = CLASS__ELEMENT_TYPE_OBJECT
176 struct MscorlibClassDescription
182 struct MscorlibMethodDescription
184 BinderClassID classID;
186 const HardCodedMetaSig * sig;
189 struct MscorlibFieldDescription
191 BinderClassID classID;
195 #endif // CROSSGEN_MSCORLIB
198 #ifdef CROSSGEN_MSCORLIB
199 // When compiling crossgen this namespace creates the second version of the tables than matches the target
200 namespace CrossGenMscorlib {
204 ///////////////////////////////////////////////////////////////////////////////
206 // Hardcoded Meta-Sig
210 // Helper enum with metasig lengths
212 // iterate over the metasig recursing into the complex types
213 #define DEFINE_METASIG(body) body,
214 #define METASIG_ATOM(x) + 1
215 #define METASIG_RECURSE 1
216 #define SM(varname, args, retval) gsigl_SM_ ## varname = 1 + 1 retval args
217 #define IM(varname, args, retval) gsigl_IM_ ## varname = 1 + 1 retval args
218 #define GM(varname, conv, n, args, retval) gsigl_GM_ ## varname = 1 + 1 + 1 + retval args
219 #define Fld(varname, val) gsigl_Fld_ ## varname = 1 val
225 // Helper enum with metasig argcount
227 // iterate over the metasig without recursing into the complex types
228 #define DEFINE_METASIG(body) body,
229 #define METASIG_ATOM(x) + 1
230 #define METASIG_RECURSE 0
231 #define SM(varname, args, retval) gsigc_SM_ ## varname = 0 args
232 #define IM(varname, args, retval) gsigc_IM_ ## varname = 0 args
233 #define GM(varname, conv, n, args, retval) gsigc_GM_ ## varname = 0 args
234 #define Fld(varname, val) gsigc_Fld_ ## varname = 0
241 // The actual array with the hardcoded metasig:
243 // There are 3 variations of the macros for Fields, Static Methods and Instance Methods.
245 // Each of them has 2 flavors: one for the fully baked signatures, and the other
246 // for the signatures with unresolved type references
248 // The signatures with unresolved type references are marked with negative size,
249 // and the pointer to them is non-const because of it will be overwritten with
250 // the pointer to the resolved signature at runtime.
253 #define DEFINE_METASIG(body) body
254 #define DEFINE_METASIG_T(body) _##body
255 #define METASIG_ATOM(x) x,
256 #define METASIG_RECURSE 1
258 // define gsig_ ## varname before gsige_ ## varname to give a hint to the compiler about the desired layout
260 #define SM(varname, args, retval) extern const BYTE gsige_SM_ ## varname[]; \
261 const HardCodedMetaSig gsig_SM_ ## varname = { gsige_SM_ ## varname }; \
262 const BYTE gsige_SM_ ## varname[] = { gsigl_SM_ ## varname, \
263 IMAGE_CEE_CS_CALLCONV_DEFAULT, gsigc_SM_ ## varname, retval args };
265 #define IM(varname, args, retval) extern const BYTE gsige_IM_ ## varname[]; \
266 const HardCodedMetaSig gsig_IM_ ## varname = { gsige_IM_ ## varname }; \
267 const BYTE gsige_IM_ ## varname[] = { gsigl_IM_ ## varname, \
268 IMAGE_CEE_CS_CALLCONV_HASTHIS, gsigc_IM_ ## varname, retval args };
270 #define GM(varname, conv, n, args, retval) extern const BYTE gsige_GM_ ## varname[]; \
271 const HardCodedMetaSig gsig_GM_ ## varname = { gsige_GM_ ## varname }; \
272 const BYTE gsige_GM_ ## varname[] = { gsigl_GM_ ## varname, \
273 conv | IMAGE_CEE_CS_CALLCONV_GENERIC, n, gsigc_GM_ ## varname, retval args };
275 #define Fld(varname, val) extern const BYTE gsige_Fld_ ## varname[]; \
276 const HardCodedMetaSig gsig_Fld_ ## varname = { gsige_Fld_ ## varname }; \
277 const BYTE gsige_Fld_ ## varname[] = { gsigl_Fld_ ## varname, \
278 IMAGE_CEE_CS_CALLCONV_FIELD, val };
280 #define _SM(varname, args, retval) extern const BYTE gsige_SM_ ## varname[]; \
281 HardCodedMetaSig gsig_SM_ ## varname = { gsige_SM_ ## varname }; \
282 const BYTE gsige_SM_ ## varname[] = { (BYTE) -gsigl_SM_ ## varname, \
283 IMAGE_CEE_CS_CALLCONV_DEFAULT, gsigc_SM_ ## varname, retval args };
285 #define _IM(varname, args, retval) extern const BYTE gsige_IM_ ## varname[]; \
286 HardCodedMetaSig gsig_IM_ ## varname = { gsige_IM_ ## varname }; \
287 const BYTE gsige_IM_ ## varname[] = { (BYTE) -gsigl_IM_ ## varname, \
288 IMAGE_CEE_CS_CALLCONV_HASTHIS, gsigc_IM_ ## varname, retval args };
290 #define _Fld(varname, val) extern const BYTE gsige_Fld_ ## varname[]; \
291 HardCodedMetaSig gsig_Fld_ ## varname = { gsige_Fld_ ## varname }; \
292 const BYTE gsige_Fld_ ## varname[] = { (BYTE) -gsigl_Fld_ ## varname, \
293 IMAGE_CEE_CS_CALLCONV_FIELD, val };
306 // Make sure DEFINE_METASIG is used for signatures that do not reference other types
308 // counts number of type references in the signature and C_ASSERTs that
309 // it is zero. An assertion failure results in error C2118: negative subscript.
310 #define DEFINE_METASIG(body) body
311 #define DEFINE_METASIG_T(body)
312 #define METASIG_BODY(varname, types) C_ASSERT(types 0 == 0);
313 #define METASIG_ATOM(x) 0+
314 #define METASIG_RECURSE 1
320 // Make sure DEFINE_METASIG_T is used only for signatures that reference
323 // counts number of type references in the signature and C_ASSERTs that
324 // it is non zero. An assertion failure results in error C2118: negative subscript.
325 #define DEFINE_METASIG(body)
326 #define DEFINE_METASIG_T(body) body
327 #define METASIG_BODY(varname, types) C_ASSERT(types 0 != 0);
328 #define METASIG_ATOM(x) 0+
329 #define METASIG_RECURSE 1
340 ///////////////////////////////////////////////////////////////////////////////
345 // Extern definitions so that binder.cpp can see these tables
346 extern const MscorlibClassDescription c_rgMscorlibClassDescriptions[];
347 extern const USHORT c_nMscorlibClassDescriptions;
349 extern const MscorlibMethodDescription c_rgMscorlibMethodDescriptions[];
350 extern const USHORT c_nMscorlibMethodDescriptions;
352 extern const MscorlibFieldDescription c_rgMscorlibFieldDescriptions[];
353 extern const USHORT c_nMscorlibFieldDescriptions;
355 const MscorlibClassDescription c_rgMscorlibClassDescriptions[] =
357 #define TYPEINFO(e,ns,c,s,g,ia,ip,if,im,gv) { ns, c },
358 #include "cortypeinfo.h"
361 #define DEFINE_CLASS(i,n,s) { g_ ## n ## NS, # s },
362 #include "namespace.h"
363 #include "mscorlib.h"
365 // Include all exception types here that are defined in mscorlib. Omit exceptions defined elsewhere.
366 #define DEFINE_EXCEPTION(ns, reKind, bHRformessage, ...) { ns , # reKind },
367 #define DEFINE_EXCEPTION_HR_WINRT_ONLY(ns, reKind, ...)
368 #define DEFINE_EXCEPTION_IN_OTHER_FX_ASSEMBLY(ns, reKind, assemblySimpleName, publicKeyToken, bHRformessage, ...)
371 const USHORT c_nMscorlibClassDescriptions = NumItems(c_rgMscorlibClassDescriptions);
373 #define gsig_NoSig (*(HardCodedMetaSig *)NULL)
375 const MscorlibMethodDescription c_rgMscorlibMethodDescriptions[] =
377 #define DEFINE_METHOD(c,i,s,g) { CLASS__ ## c , # s, & gsig_ ## g },
378 #include "mscorlib.h"
380 const USHORT c_nMscorlibMethodDescriptions = NumItems(c_rgMscorlibMethodDescriptions) + 1;
382 const MscorlibFieldDescription c_rgMscorlibFieldDescriptions[] =
384 #define DEFINE_FIELD(c,i,s) { CLASS__ ## c , # s },
385 #include "mscorlib.h"
387 const USHORT c_nMscorlibFieldDescriptions = NumItems(c_rgMscorlibFieldDescriptions) + 1;
393 ///////////////////////////////////////////////////////////////////////////////
398 // When compiling crossgen, we only need the target version of the ecall tables
399 #if !defined(CROSSGEN_COMPILE) || defined(CROSSGEN_MSCORLIB)
401 #ifdef CROSSGEN_COMPILE
403 #define QCFuncElement(name,impl) \
404 FCFuncFlag_QCall + FCFuncFlags(CORINFO_INTRINSIC_Illegal, ECall::InvalidDynamicFCallId), NULL, (LPVOID)name,
406 #define FCFuncFlags(intrinsicID, dynamicID) \
407 (BYTE*)( (((BYTE)intrinsicID) << 16) )
411 #define QCFuncElement(name,impl) \
412 FCFuncFlag_QCall + FCFuncFlags(CORINFO_INTRINSIC_Illegal, ECall::InvalidDynamicFCallId), (LPVOID)(impl), (LPVOID)name,
414 #define FCFuncFlags(intrinsicID, dynamicID) \
415 (BYTE*)( (((BYTE)intrinsicID) << 16) + (((BYTE)dynamicID) << 24) )
419 #define FCFuncElement(name, impl) FCFuncFlags(CORINFO_INTRINSIC_Illegal, ECall::InvalidDynamicFCallId), \
420 (LPVOID)GetEEFuncEntryPoint(impl), (LPVOID)name,
422 #define FCFuncElementSig(name,sig,impl) \
423 FCFuncFlag_HasSignature + FCFuncElement(name, impl) (LPVOID)sig,
425 #define FCIntrinsic(name,impl,intrinsicID) FCFuncFlags(intrinsicID, ECall::InvalidDynamicFCallId), \
426 (LPVOID)GetEEFuncEntryPoint(impl), (LPVOID)name,
428 #define FCIntrinsicSig(name,sig,impl,intrinsicID) \
429 FCFuncFlag_HasSignature + FCIntrinsic(name,impl,intrinsicID) (LPVOID)sig,
431 #define FCDynamic(name,intrinsicID,dynamicID) FCFuncFlags(intrinsicID, dynamicID), \
434 #define FCDynamicSig(name,sig,intrinsicID,dynamicID) \
435 FCFuncFlag_HasSignature + FCDynamic(name,intrinsicID,dynamicID) (LPVOID)sig,
437 #define FCUnreferenced FCFuncFlag_Unreferenced +
439 #define FCFuncStart(name) static const LPVOID name[] = {
440 #define FCFuncEnd() FCFuncFlag_EndOfArray + FCFuncFlags(CORINFO_INTRINSIC_Illegal, ECall::InvalidDynamicFCallId) };
442 #include "ecalllist.h"
445 // Extern definitions so that ecall.cpp can see these tables
446 extern const ECClass c_rgECClasses[];
447 extern const int c_nECClasses;
449 const ECClass c_rgECClasses[] =
451 #define FCClassElement(name,namespace,funcs) {name, namespace, funcs},
452 #include "ecalllist.h"
453 }; // c_rgECClasses[]
455 const int c_nECClasses = NumItems(c_rgECClasses);
457 #endif // !CROSSGEN_COMPILE && CROSSGEN_MSCORLIB
460 #ifdef CROSSGEN_MSCORLIB
461 }; // namespace CrossGenMscorlib