Merge pull request #9615 from JosephTremoulet/UpdateCompareVN
[platform/upstream/coreclr.git] / src / vm / mscorlib.cpp
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.
4 //
5
6
7 // 
8 // This file defines tables for references between VM and mscorlib.
9 //
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.
12 //
13
14 #ifdef CROSSGEN_MSCORLIB
15 // Use minimal set of headers for crossgen
16 #include "windows.h"
17 #include "corinfo.h"
18 #else
19 #include "common.h"
20 #include "ecall.h"
21 #endif // CROSSGEN_MSCORLIB
22
23 #ifndef CROSSGEN_COMPILE
24 //
25 // Headers for all ECall entrypoints
26 //
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 "excep.h"
35 #include "fcall.h"
36 #include "nlsinfo.h"
37 #include "calendardata.h"
38 #include "commodule.h"
39 #include "marshalnative.h"
40 #include "system.h"
41 #include "comutilnative.h"
42 #include "comsynchronizable.h"
43 #include "floatdouble.h"
44 #include "floatsingle.h"
45 #include "decimal.h"
46 #include "currency.h"
47 #include "comdatetime.h"
48 #include "number.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"
56
57 #include "proftoeeinterfaceimpl.h"
58
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"
70
71 #ifdef MDA_SUPPORTED 
72 #include "mdaassistants.h"
73 #endif
74
75 #include "coverage.h"
76
77 #ifdef FEATURE_COMINTEROP
78 #include "variant.h"
79 #include "oavariant.h"
80 #include "registration.h"
81 #include "mngstdinterfaces.h"
82 #include "extensibleclassfactory.h"
83 #endif // FEATURE_COMINTEROP
84
85 #include "stubhelpers.h"
86 #include "ilmarshalers.h"
87
88 #ifdef FEATURE_MULTICOREJIT
89 #include "multicorejit.h"
90 #endif
91
92 #ifdef FEATURE_COMINTEROP
93 #include "windowsruntimebufferhelper.h"
94 #endif
95
96 #if defined(FEATURE_EVENTSOURCE_XPLAT)
97 #include "nativeeventsource.h"
98 #endif //defined(FEATURE_EVENTSOURCE_XPLAT)
99
100 #endif // CROSSGEN_MSCORLIB
101
102
103 #ifdef CROSSGEN_MSCORLIB
104
105 ///////////////////////////////////////////////////////////////////////////////
106 //
107 // Duplicate definitions of constants and datastructures required to define the tables
108 //
109
110 #define NumItems(s) (sizeof(s) / sizeof(s[0]))
111
112 #define GetEEFuncEntryPoint(pfn) 0x1001
113
114 enum {
115     FCFuncFlag_EndOfArray   = 0x01,
116     FCFuncFlag_HasSignature = 0x02,
117     FCFuncFlag_Unreferenced = 0x04, // Suppress unused fcall check
118     FCFuncFlag_QCall        = 0x08, // QCall - mscorlib.dll to mscorwks.dll transition implemented as PInvoke
119 };
120
121 struct ECClass
122 {
123     LPCSTR      m_szClassName;
124     LPCSTR      m_szNameSpace;
125     const LPVOID *  m_pECFunc;
126 };
127
128 struct HardCodedMetaSig
129 {
130     const BYTE* m_pMetaSig; // metasig prefixed with INT8 length:
131                             // length > 0 - resolved, lenght < 0 - has unresolved type references
132 };
133
134 enum BinderClassID
135 {
136 #define TYPEINFO(e,ns,c,s,g,ia,ip,if,im,gv)   CLASS__ ## e,
137 #include "cortypeinfo.h"
138 #undef TYPEINFO
139
140 #define DEFINE_CLASS(i,n,s)         CLASS__ ## i,
141 #include "mscorlib.h"
142
143     CLASS__MSCORLIB_COUNT,
144
145     CLASS__VOID     = CLASS__ELEMENT_TYPE_VOID,
146     CLASS__BOOLEAN  = CLASS__ELEMENT_TYPE_BOOLEAN,
147     CLASS__CHAR     = CLASS__ELEMENT_TYPE_CHAR,
148     CLASS__BYTE     = CLASS__ELEMENT_TYPE_U1,
149     CLASS__SBYTE    = CLASS__ELEMENT_TYPE_I1,
150     CLASS__INT16    = CLASS__ELEMENT_TYPE_I2,
151     CLASS__UINT16   = CLASS__ELEMENT_TYPE_U2,
152     CLASS__INT32    = CLASS__ELEMENT_TYPE_I4,
153     CLASS__UINT32   = CLASS__ELEMENT_TYPE_U4,
154     CLASS__INT64    = CLASS__ELEMENT_TYPE_I8,
155     CLASS__UINT64   = CLASS__ELEMENT_TYPE_U8,
156     CLASS__SINGLE   = CLASS__ELEMENT_TYPE_R4,
157     CLASS__DOUBLE   = CLASS__ELEMENT_TYPE_R8,
158     CLASS__STRING   = CLASS__ELEMENT_TYPE_STRING,
159     CLASS__TYPED_REFERENCE = CLASS__ELEMENT_TYPE_TYPEDBYREF,
160     CLASS__INTPTR   = CLASS__ELEMENT_TYPE_I,
161     CLASS__UINTPTR  = CLASS__ELEMENT_TYPE_U,
162     CLASS__OBJECT   = CLASS__ELEMENT_TYPE_OBJECT
163 };
164
165 struct MscorlibClassDescription
166 {
167     LPCSTR  nameSpace;
168     LPCSTR  name;
169 };
170
171 struct MscorlibMethodDescription
172 {
173     BinderClassID classID;
174     LPCSTR  name;
175     const HardCodedMetaSig * sig;
176 };
177
178 struct MscorlibFieldDescription
179 {
180     BinderClassID classID;
181     LPCSTR  name;
182 };
183
184 #endif // CROSSGEN_MSCORLIB
185
186
187 #ifdef CROSSGEN_MSCORLIB
188 // When compiling crossgen this namespace creates the second version of the tables than matches the target
189 namespace CrossGenMscorlib {
190 #endif
191
192
193 ///////////////////////////////////////////////////////////////////////////////
194 //
195 // Hardcoded Meta-Sig
196 //
197
198 //
199 // Helper enum with metasig lengths
200 //
201 // iterate over the metasig recursing into the complex types
202 #define DEFINE_METASIG(body)            body,
203 #define METASIG_ATOM(x)                 + 1
204 #define METASIG_RECURSE                 1
205 #define SM(varname, args, retval)       gsigl_SM_ ## varname = 1 + 1 retval args
206 #define IM(varname, args, retval)       gsigl_IM_ ## varname = 1 + 1 retval args
207 #define GM(varname, conv, n, args, retval) gsigl_GM_ ## varname = 1 + 1 + 1 + retval args
208 #define Fld(varname, val)               gsigl_Fld_ ## varname = 1 val
209 enum _gsigl {
210 #include "metasig.h"
211 };
212
213 //
214 // Helper enum with metasig argcount
215 //
216 // iterate over the metasig without recursing into the complex types
217 #define DEFINE_METASIG(body)            body,
218 #define METASIG_ATOM(x)                 + 1
219 #define METASIG_RECURSE                 0
220 #define SM(varname, args, retval)       gsigc_SM_ ## varname = 0 args
221 #define IM(varname, args, retval)       gsigc_IM_ ## varname = 0 args
222 #define GM(varname, conv, n, args, retval) gsigc_GM_ ## varname = 0 args
223 #define Fld(varname, val)               gsigc_Fld_ ## varname = 0
224 enum _gsigc {
225 #include "metasig.h"
226 };
227
228
229 //
230 // The actual array with the hardcoded metasig:
231 //
232 // There are 3 variations of the macros for Fields, Static Methods and Instance Methods.
233 //
234 // Each of them has 2 flavors: one for the fully baked signatures, and the other 
235 // for the signatures with unresolved type references
236 //
237 // The signatures with unresolved type references are marked with negative size, 
238 // and the pointer to them is non-const because of it will be overwritten with
239 // the pointer to the resolved signature at runtime.
240 //
241
242 #define DEFINE_METASIG(body)            body
243 #define DEFINE_METASIG_T(body)          _##body
244 #define METASIG_ATOM(x)                 x,
245 #define METASIG_RECURSE                 1
246
247 // define gsig_ ## varname before gsige_ ## varname to give a hint to the compiler about the desired layout
248
249 #define SM(varname, args, retval) extern const BYTE gsige_SM_ ## varname[];     \
250     const HardCodedMetaSig gsig_SM_ ## varname = { gsige_SM_ ## varname };      \
251     const BYTE gsige_SM_ ## varname[] = { gsigl_SM_ ## varname,                 \
252         IMAGE_CEE_CS_CALLCONV_DEFAULT, gsigc_SM_ ## varname, retval args };
253
254 #define IM(varname, args, retval) extern const BYTE gsige_IM_ ## varname[];     \
255     const HardCodedMetaSig gsig_IM_ ## varname = { gsige_IM_ ## varname };      \
256     const BYTE gsige_IM_ ## varname[] = { gsigl_IM_ ## varname,                 \
257         IMAGE_CEE_CS_CALLCONV_HASTHIS, gsigc_IM_ ## varname, retval args };
258
259 #define GM(varname, conv, n, args, retval) extern const BYTE gsige_GM_ ## varname[];    \
260     const HardCodedMetaSig gsig_GM_ ## varname = { gsige_GM_ ## varname };              \
261     const BYTE gsige_GM_ ## varname[] = { gsigl_GM_ ## varname,                         \
262         conv | IMAGE_CEE_CS_CALLCONV_GENERIC, n, gsigc_GM_ ## varname, retval args };
263
264 #define Fld(varname, val) extern const BYTE gsige_Fld_ ## varname[];            \
265     const HardCodedMetaSig gsig_Fld_ ## varname = { gsige_Fld_ ## varname };    \
266     const BYTE gsige_Fld_ ## varname[] = { gsigl_Fld_ ## varname,               \
267         IMAGE_CEE_CS_CALLCONV_FIELD, val };
268
269 #define _SM(varname, args, retval) extern const BYTE gsige_SM_ ## varname[];    \
270     HardCodedMetaSig gsig_SM_ ## varname = { gsige_SM_ ## varname };            \
271     const BYTE gsige_SM_ ## varname[] = { (BYTE) -gsigl_SM_ ## varname,         \
272         IMAGE_CEE_CS_CALLCONV_DEFAULT, gsigc_SM_ ## varname, retval args };
273
274 #define _IM(varname, args, retval) extern const BYTE gsige_IM_ ## varname[];    \
275     HardCodedMetaSig gsig_IM_ ## varname = { gsige_IM_ ## varname };            \
276     const BYTE gsige_IM_ ## varname[] = { (BYTE) -gsigl_IM_ ## varname,         \
277         IMAGE_CEE_CS_CALLCONV_HASTHIS, gsigc_IM_ ## varname, retval args };
278
279 #define _Fld(varname, val) extern const BYTE gsige_Fld_ ## varname[];           \
280     HardCodedMetaSig gsig_Fld_ ## varname = { gsige_Fld_ ## varname };          \
281     const BYTE gsige_Fld_ ## varname[] = { (BYTE) -gsigl_Fld_ ## varname,       \
282         IMAGE_CEE_CS_CALLCONV_FIELD, val };
283
284 #include "metasig.h"
285
286 #undef _SM
287 #undef _IM
288 #undef _Fld
289
290
291
292 #ifdef _DEBUG
293
294 //
295 // Make sure DEFINE_METASIG is used for signatures that do not reference other types
296 //
297 // counts number of type references in the signature and C_ASSERTs that 
298 // it is zero. An assertion failure results in error C2118: negative subscript.
299 #define DEFINE_METASIG(body)            body
300 #define DEFINE_METASIG_T(body)
301 #define METASIG_BODY(varname, types)    C_ASSERT(types 0 == 0);
302 #define METASIG_ATOM(x)                 0+
303 #define METASIG_RECURSE                 1
304 #define C(x)                            1+
305 #define g(x)                            1+
306 #include "metasig.h"
307
308 //
309 // Make sure DEFINE_METASIG_T is used only for signatures that reference 
310 // other types.
311 //
312 // counts number of type references in the signature and C_ASSERTs that 
313 // it is non zero. An assertion failure results in error C2118: negative subscript.
314 #define DEFINE_METASIG(body)
315 #define DEFINE_METASIG_T(body)          body
316 #define METASIG_BODY(varname, types)    C_ASSERT(types 0 != 0);
317 #define METASIG_ATOM(x)                 0+
318 #define METASIG_RECURSE                 1
319 #define C(x)                            1+
320 #define g(x)                            1+
321 #include "metasig.h"
322
323 #endif
324
325
326
327
328
329 ///////////////////////////////////////////////////////////////////////////////
330 //
331 // Mscorlib binder
332 //
333
334 // Extern definitions so that binder.cpp can see these tables
335 extern const MscorlibClassDescription c_rgMscorlibClassDescriptions[];
336 extern const USHORT c_nMscorlibClassDescriptions;
337
338 extern const MscorlibMethodDescription c_rgMscorlibMethodDescriptions[];
339 extern const USHORT c_nMscorlibMethodDescriptions;
340
341 extern const MscorlibFieldDescription c_rgMscorlibFieldDescriptions[];
342 extern const USHORT c_nMscorlibFieldDescriptions;
343
344 const MscorlibClassDescription c_rgMscorlibClassDescriptions[] =
345 {
346     #define TYPEINFO(e,ns,c,s,g,ia,ip,if,im,gv)   { ns, c },
347     #include "cortypeinfo.h"
348     #undef TYPEINFO
349     
350     #define DEFINE_CLASS(i,n,s)        { g_ ## n ## NS, # s },
351     #include "namespace.h"
352     #include "mscorlib.h"
353     
354     // Include all exception types here that are defined in mscorlib.  Omit exceptions defined elsewhere.
355     #define DEFINE_EXCEPTION(ns, reKind, bHRformessage, ...) { ns , # reKind },
356     #define DEFINE_EXCEPTION_HR_WINRT_ONLY(ns, reKind, ...)
357     #define DEFINE_EXCEPTION_IN_OTHER_FX_ASSEMBLY(ns, reKind, assemblySimpleName, publicKeyToken, bHRformessage, ...)
358     #include "rexcep.h"
359 };
360 const USHORT c_nMscorlibClassDescriptions = NumItems(c_rgMscorlibClassDescriptions);
361
362 #define gsig_NoSig (*(HardCodedMetaSig *)NULL)
363
364 const MscorlibMethodDescription c_rgMscorlibMethodDescriptions[] =
365 {
366     #define DEFINE_METHOD(c,i,s,g)          { CLASS__ ## c , # s, & gsig_ ## g },
367     #include "mscorlib.h"
368 };
369 const USHORT c_nMscorlibMethodDescriptions = NumItems(c_rgMscorlibMethodDescriptions) + 1;
370
371 const MscorlibFieldDescription c_rgMscorlibFieldDescriptions[] =
372 {
373     #define DEFINE_FIELD(c,i,s)           { CLASS__ ## c , # s },
374     #include "mscorlib.h"
375 };
376 const USHORT c_nMscorlibFieldDescriptions = NumItems(c_rgMscorlibFieldDescriptions) + 1;
377
378
379
380
381
382 ///////////////////////////////////////////////////////////////////////////////
383 //
384 // ECalls
385 //
386
387 // When compiling crossgen, we only need the target version of the ecall tables
388 #if !defined(CROSSGEN_COMPILE) || defined(CROSSGEN_MSCORLIB)
389
390 #ifdef CROSSGEN_COMPILE
391
392 #define QCFuncElement(name,impl) \
393     FCFuncFlag_QCall + FCFuncFlags(CORINFO_INTRINSIC_Illegal, ECall::InvalidDynamicFCallId), NULL, (LPVOID)name,
394
395 #define FCFuncFlags(intrinsicID, dynamicID) \
396     (BYTE*)( (((BYTE)intrinsicID) << 16) )
397
398 #else
399
400 #define QCFuncElement(name,impl) \
401     FCFuncFlag_QCall + FCFuncFlags(CORINFO_INTRINSIC_Illegal, ECall::InvalidDynamicFCallId), (LPVOID)(impl), (LPVOID)name,
402
403 #define FCFuncFlags(intrinsicID, dynamicID) \
404     (BYTE*)( (((BYTE)intrinsicID) << 16) + (((BYTE)dynamicID) << 24) )
405
406 #endif
407
408 #define FCFuncElement(name, impl) FCFuncFlags(CORINFO_INTRINSIC_Illegal, ECall::InvalidDynamicFCallId), \
409     (LPVOID)GetEEFuncEntryPoint(impl), (LPVOID)name,
410
411 #define FCFuncElementSig(name,sig,impl) \
412     FCFuncFlag_HasSignature + FCFuncElement(name, impl) (LPVOID)sig,
413
414 #define FCIntrinsic(name,impl,intrinsicID) FCFuncFlags(intrinsicID, ECall::InvalidDynamicFCallId), \
415     (LPVOID)GetEEFuncEntryPoint(impl), (LPVOID)name,
416
417 #define FCIntrinsicSig(name,sig,impl,intrinsicID) \
418     FCFuncFlag_HasSignature + FCIntrinsic(name,impl,intrinsicID) (LPVOID)sig,
419
420 #define FCDynamic(name,intrinsicID,dynamicID) FCFuncFlags(intrinsicID, dynamicID), \
421     NULL, (LPVOID)name,
422
423 #define FCDynamicSig(name,sig,intrinsicID,dynamicID) \
424     FCFuncFlag_HasSignature + FCDynamic(name,intrinsicID,dynamicID) (LPVOID)sig,
425
426 #define FCUnreferenced FCFuncFlag_Unreferenced +
427
428 #define FCFuncStart(name) static const LPVOID name[] = {
429 #define FCFuncEnd() FCFuncFlag_EndOfArray + FCFuncFlags(CORINFO_INTRINSIC_Illegal, ECall::InvalidDynamicFCallId) };
430
431 #include "ecalllist.h"
432
433
434 // Extern definitions so that ecall.cpp can see these tables
435 extern const ECClass c_rgECClasses[];
436 extern const int c_nECClasses;
437
438 const ECClass c_rgECClasses[] =
439 {
440 #define FCClassElement(name,namespace,funcs) {name, namespace, funcs},
441 #include "ecalllist.h"
442 };  // c_rgECClasses[]
443
444 const int c_nECClasses = NumItems(c_rgECClasses);
445
446 #endif // !CROSSGEN_COMPILE && CROSSGEN_MSCORLIB
447
448
449 #ifdef CROSSGEN_MSCORLIB
450 }; // namespace CrossGenMscorlib
451 #endif