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 "clrconfignative.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"
49 #include "compatibilityswitch.h"
50 #include "debugdebugger.h"
51 #include "assemblyname.hpp"
52 #include "assemblynative.hpp"
53 #include "comthreadpool.h"
54 #include "comwaithandle.h"
55 #include "nativeoverlapped.h"
57 #include "proftoeeinterfaceimpl.h"
59 #include "appdomainnative.hpp"
60 #include "arrayhelpers.h"
61 #include "runtimehandles.h"
62 #include "reflectioninvocation.h"
63 #include "managedmdimport.hpp"
64 #include "synchronizationcontextnative.h"
65 #include "commemoryfailpoint.h"
66 #include "typestring.h"
67 #include "comdependenthandle.h"
68 #include "weakreferencenative.h"
69 #include "varargsnative.h"
72 #include "mdaassistants.h"
75 #ifdef FEATURE_COMINTEROP
77 #include "oavariant.h"
78 #include "registration.h"
79 #include "mngstdinterfaces.h"
80 #include "extensibleclassfactory.h"
81 #endif // FEATURE_COMINTEROP
83 #include "stubhelpers.h"
84 #include "ilmarshalers.h"
86 #ifdef FEATURE_MULTICOREJIT
87 #include "multicorejit.h"
90 #ifdef FEATURE_COMINTEROP
91 #include "windowsruntimebufferhelper.h"
94 #if defined(FEATURE_EVENTSOURCE_XPLAT)
95 #include "nativeeventsource.h"
96 #endif //defined(FEATURE_EVENTSOURCE_XPLAT)
98 #endif // CROSSGEN_MSCORLIB
101 #ifdef CROSSGEN_MSCORLIB
103 ///////////////////////////////////////////////////////////////////////////////
105 // Duplicate definitions of constants and datastructures required to define the tables
108 #define NumItems(s) (sizeof(s) / sizeof(s[0]))
110 #define GetEEFuncEntryPoint(pfn) 0x1001
113 FCFuncFlag_EndOfArray = 0x01,
114 FCFuncFlag_HasSignature = 0x02,
115 FCFuncFlag_Unreferenced = 0x04, // Suppress unused fcall check
116 FCFuncFlag_QCall = 0x08, // QCall - mscorlib.dll to mscorwks.dll transition implemented as PInvoke
121 LPCSTR m_szClassName;
122 LPCSTR m_szNameSpace;
123 const LPVOID * m_pECFunc;
126 struct HardCodedMetaSig
128 const BYTE* m_pMetaSig; // metasig prefixed with INT8 length:
129 // length > 0 - resolved, lenght < 0 - has unresolved type references
134 #define TYPEINFO(e,ns,c,s,g,ia,ip,if,im,gv) CLASS__ ## e,
135 #include "cortypeinfo.h"
138 #define DEFINE_CLASS(i,n,s) CLASS__ ## i,
139 #include "mscorlib.h"
141 CLASS__MSCORLIB_COUNT,
143 CLASS__VOID = CLASS__ELEMENT_TYPE_VOID,
144 CLASS__BOOLEAN = CLASS__ELEMENT_TYPE_BOOLEAN,
145 CLASS__CHAR = CLASS__ELEMENT_TYPE_CHAR,
146 CLASS__BYTE = CLASS__ELEMENT_TYPE_U1,
147 CLASS__SBYTE = CLASS__ELEMENT_TYPE_I1,
148 CLASS__INT16 = CLASS__ELEMENT_TYPE_I2,
149 CLASS__UINT16 = CLASS__ELEMENT_TYPE_U2,
150 CLASS__INT32 = CLASS__ELEMENT_TYPE_I4,
151 CLASS__UINT32 = CLASS__ELEMENT_TYPE_U4,
152 CLASS__INT64 = CLASS__ELEMENT_TYPE_I8,
153 CLASS__UINT64 = CLASS__ELEMENT_TYPE_U8,
154 CLASS__SINGLE = CLASS__ELEMENT_TYPE_R4,
155 CLASS__DOUBLE = CLASS__ELEMENT_TYPE_R8,
156 CLASS__STRING = CLASS__ELEMENT_TYPE_STRING,
157 CLASS__TYPED_REFERENCE = CLASS__ELEMENT_TYPE_TYPEDBYREF,
158 CLASS__INTPTR = CLASS__ELEMENT_TYPE_I,
159 CLASS__UINTPTR = CLASS__ELEMENT_TYPE_U,
160 CLASS__OBJECT = CLASS__ELEMENT_TYPE_OBJECT
163 struct MscorlibClassDescription
169 struct MscorlibMethodDescription
171 BinderClassID classID;
173 const HardCodedMetaSig * sig;
176 struct MscorlibFieldDescription
178 BinderClassID classID;
182 #endif // CROSSGEN_MSCORLIB
185 #ifdef CROSSGEN_MSCORLIB
186 // When compiling crossgen this namespace creates the second version of the tables than matches the target
187 namespace CrossGenMscorlib {
191 ///////////////////////////////////////////////////////////////////////////////
193 // Hardcoded Meta-Sig
197 // Helper enum with metasig lengths
199 // iterate over the metasig recursing into the complex types
200 #define DEFINE_METASIG(body) body,
201 #define METASIG_ATOM(x) + 1
202 #define METASIG_RECURSE 1
203 #define SM(varname, args, retval) gsigl_SM_ ## varname = 1 + 1 retval args
204 #define IM(varname, args, retval) gsigl_IM_ ## varname = 1 + 1 retval args
205 #define GM(varname, conv, n, args, retval) gsigl_GM_ ## varname = 1 + 1 + 1 + retval args
206 #define Fld(varname, val) gsigl_Fld_ ## varname = 1 val
212 // Helper enum with metasig argcount
214 // iterate over the metasig without recursing into the complex types
215 #define DEFINE_METASIG(body) body,
216 #define METASIG_ATOM(x) + 1
217 #define METASIG_RECURSE 0
218 #define SM(varname, args, retval) gsigc_SM_ ## varname = 0 args
219 #define IM(varname, args, retval) gsigc_IM_ ## varname = 0 args
220 #define GM(varname, conv, n, args, retval) gsigc_GM_ ## varname = 0 args
221 #define Fld(varname, val) gsigc_Fld_ ## varname = 0
228 // The actual array with the hardcoded metasig:
230 // There are 3 variations of the macros for Fields, Static Methods and Instance Methods.
232 // Each of them has 2 flavors: one for the fully baked signatures, and the other
233 // for the signatures with unresolved type references
235 // The signatures with unresolved type references are marked with negative size,
236 // and the pointer to them is non-const because of it will be overwritten with
237 // the pointer to the resolved signature at runtime.
240 #define DEFINE_METASIG(body) body
241 #define DEFINE_METASIG_T(body) _##body
242 #define METASIG_ATOM(x) x,
243 #define METASIG_RECURSE 1
245 // define gsig_ ## varname before gsige_ ## varname to give a hint to the compiler about the desired layout
247 #define SM(varname, args, retval) extern const BYTE gsige_SM_ ## varname[]; \
248 const HardCodedMetaSig gsig_SM_ ## varname = { gsige_SM_ ## varname }; \
249 const BYTE gsige_SM_ ## varname[] = { gsigl_SM_ ## varname, \
250 IMAGE_CEE_CS_CALLCONV_DEFAULT, gsigc_SM_ ## varname, retval args };
252 #define IM(varname, args, retval) extern const BYTE gsige_IM_ ## varname[]; \
253 const HardCodedMetaSig gsig_IM_ ## varname = { gsige_IM_ ## varname }; \
254 const BYTE gsige_IM_ ## varname[] = { gsigl_IM_ ## varname, \
255 IMAGE_CEE_CS_CALLCONV_HASTHIS, gsigc_IM_ ## varname, retval args };
257 #define GM(varname, conv, n, args, retval) extern const BYTE gsige_GM_ ## varname[]; \
258 const HardCodedMetaSig gsig_GM_ ## varname = { gsige_GM_ ## varname }; \
259 const BYTE gsige_GM_ ## varname[] = { gsigl_GM_ ## varname, \
260 conv | IMAGE_CEE_CS_CALLCONV_GENERIC, n, gsigc_GM_ ## varname, retval args };
262 #define Fld(varname, val) extern const BYTE gsige_Fld_ ## varname[]; \
263 const HardCodedMetaSig gsig_Fld_ ## varname = { gsige_Fld_ ## varname }; \
264 const BYTE gsige_Fld_ ## varname[] = { gsigl_Fld_ ## varname, \
265 IMAGE_CEE_CS_CALLCONV_FIELD, val };
267 #define _SM(varname, args, retval) extern const BYTE gsige_SM_ ## varname[]; \
268 HardCodedMetaSig gsig_SM_ ## varname = { gsige_SM_ ## varname }; \
269 const BYTE gsige_SM_ ## varname[] = { (BYTE) -gsigl_SM_ ## varname, \
270 IMAGE_CEE_CS_CALLCONV_DEFAULT, gsigc_SM_ ## varname, retval args };
272 #define _IM(varname, args, retval) extern const BYTE gsige_IM_ ## varname[]; \
273 HardCodedMetaSig gsig_IM_ ## varname = { gsige_IM_ ## varname }; \
274 const BYTE gsige_IM_ ## varname[] = { (BYTE) -gsigl_IM_ ## varname, \
275 IMAGE_CEE_CS_CALLCONV_HASTHIS, gsigc_IM_ ## varname, retval args };
277 #define _Fld(varname, val) extern const BYTE gsige_Fld_ ## varname[]; \
278 HardCodedMetaSig gsig_Fld_ ## varname = { gsige_Fld_ ## varname }; \
279 const BYTE gsige_Fld_ ## varname[] = { (BYTE) -gsigl_Fld_ ## varname, \
280 IMAGE_CEE_CS_CALLCONV_FIELD, val };
293 // Make sure DEFINE_METASIG is used for signatures that do not reference other types
295 // counts number of type references in the signature and C_ASSERTs that
296 // it is zero. An assertion failure results in error C2118: negative subscript.
297 #define DEFINE_METASIG(body) body
298 #define DEFINE_METASIG_T(body)
299 #define METASIG_BODY(varname, types) C_ASSERT(types 0 == 0);
300 #define METASIG_ATOM(x) 0+
301 #define METASIG_RECURSE 1
307 // Make sure DEFINE_METASIG_T is used only for signatures that reference
310 // counts number of type references in the signature and C_ASSERTs that
311 // it is non zero. An assertion failure results in error C2118: negative subscript.
312 #define DEFINE_METASIG(body)
313 #define DEFINE_METASIG_T(body) body
314 #define METASIG_BODY(varname, types) C_ASSERT(types 0 != 0);
315 #define METASIG_ATOM(x) 0+
316 #define METASIG_RECURSE 1
327 ///////////////////////////////////////////////////////////////////////////////
332 // Extern definitions so that binder.cpp can see these tables
333 extern const MscorlibClassDescription c_rgMscorlibClassDescriptions[];
334 extern const USHORT c_nMscorlibClassDescriptions;
336 extern const MscorlibMethodDescription c_rgMscorlibMethodDescriptions[];
337 extern const USHORT c_nMscorlibMethodDescriptions;
339 extern const MscorlibFieldDescription c_rgMscorlibFieldDescriptions[];
340 extern const USHORT c_nMscorlibFieldDescriptions;
342 const MscorlibClassDescription c_rgMscorlibClassDescriptions[] =
344 #define TYPEINFO(e,ns,c,s,g,ia,ip,if,im,gv) { ns, c },
345 #include "cortypeinfo.h"
348 #define DEFINE_CLASS(i,n,s) { g_ ## n ## NS, # s },
349 #include "namespace.h"
350 #include "mscorlib.h"
352 // Include all exception types here that are defined in mscorlib. Omit exceptions defined elsewhere.
353 #define DEFINE_EXCEPTION(ns, reKind, bHRformessage, ...) { ns , # reKind },
354 #define DEFINE_EXCEPTION_HR_WINRT_ONLY(ns, reKind, ...)
355 #define DEFINE_EXCEPTION_IN_OTHER_FX_ASSEMBLY(ns, reKind, assemblySimpleName, publicKeyToken, bHRformessage, ...)
358 const USHORT c_nMscorlibClassDescriptions = NumItems(c_rgMscorlibClassDescriptions);
360 #define gsig_NoSig (*(HardCodedMetaSig *)NULL)
362 const MscorlibMethodDescription c_rgMscorlibMethodDescriptions[] =
364 #define DEFINE_METHOD(c,i,s,g) { CLASS__ ## c , # s, & gsig_ ## g },
365 #include "mscorlib.h"
367 const USHORT c_nMscorlibMethodDescriptions = NumItems(c_rgMscorlibMethodDescriptions) + 1;
369 const MscorlibFieldDescription c_rgMscorlibFieldDescriptions[] =
371 #define DEFINE_FIELD(c,i,s) { CLASS__ ## c , # s },
372 #include "mscorlib.h"
374 const USHORT c_nMscorlibFieldDescriptions = NumItems(c_rgMscorlibFieldDescriptions) + 1;
380 ///////////////////////////////////////////////////////////////////////////////
385 // When compiling crossgen, we only need the target version of the ecall tables
386 #if !defined(CROSSGEN_COMPILE) || defined(CROSSGEN_MSCORLIB)
388 #ifdef CROSSGEN_COMPILE
390 #define QCFuncElement(name,impl) \
391 FCFuncFlag_QCall + FCFuncFlags(CORINFO_INTRINSIC_Illegal, ECall::InvalidDynamicFCallId), NULL, (LPVOID)name,
393 #define FCFuncFlags(intrinsicID, dynamicID) \
394 (BYTE*)( (((BYTE)intrinsicID) << 16) )
398 #define QCFuncElement(name,impl) \
399 FCFuncFlag_QCall + FCFuncFlags(CORINFO_INTRINSIC_Illegal, ECall::InvalidDynamicFCallId), (LPVOID)(impl), (LPVOID)name,
401 #define FCFuncFlags(intrinsicID, dynamicID) \
402 (BYTE*)( (((BYTE)intrinsicID) << 16) + (((BYTE)dynamicID) << 24) )
406 #define FCFuncElement(name, impl) FCFuncFlags(CORINFO_INTRINSIC_Illegal, ECall::InvalidDynamicFCallId), \
407 (LPVOID)GetEEFuncEntryPoint(impl), (LPVOID)name,
409 #define FCFuncElementSig(name,sig,impl) \
410 FCFuncFlag_HasSignature + FCFuncElement(name, impl) (LPVOID)sig,
412 #define FCIntrinsic(name,impl,intrinsicID) FCFuncFlags(intrinsicID, ECall::InvalidDynamicFCallId), \
413 (LPVOID)GetEEFuncEntryPoint(impl), (LPVOID)name,
415 #define FCIntrinsicSig(name,sig,impl,intrinsicID) \
416 FCFuncFlag_HasSignature + FCIntrinsic(name,impl,intrinsicID) (LPVOID)sig,
418 #define FCDynamic(name,intrinsicID,dynamicID) FCFuncFlags(intrinsicID, dynamicID), \
421 #define FCDynamicSig(name,sig,intrinsicID,dynamicID) \
422 FCFuncFlag_HasSignature + FCDynamic(name,intrinsicID,dynamicID) (LPVOID)sig,
424 #define FCUnreferenced FCFuncFlag_Unreferenced +
426 #define FCFuncStart(name) static const LPVOID name[] = {
427 #define FCFuncEnd() FCFuncFlag_EndOfArray + FCFuncFlags(CORINFO_INTRINSIC_Illegal, ECall::InvalidDynamicFCallId) };
429 #include "ecalllist.h"
432 // Extern definitions so that ecall.cpp can see these tables
433 extern const ECClass c_rgECClasses[];
434 extern const int c_nECClasses;
436 const ECClass c_rgECClasses[] =
438 #define FCClassElement(name,namespace,funcs) {name, namespace, funcs},
439 #include "ecalllist.h"
440 }; // c_rgECClasses[]
442 const int c_nECClasses = NumItems(c_rgECClasses);
444 #endif // !CROSSGEN_COMPILE && CROSSGEN_MSCORLIB
447 #ifdef CROSSGEN_MSCORLIB
448 }; // namespace CrossGenMscorlib