Merge pull request #9516 from sdmaclea/PR-ARM64-FAILS
[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 "commethodrental.h"
35 #include "nlsinfo.h"
36 #include "calendardata.h"
37 #include "commodule.h"
38 #include "marshalnative.h"
39 #include "system.h"
40 #include "comutilnative.h"
41 #include "comsynchronizable.h"
42 #include "floatdouble.h"
43 #include "floatsingle.h"
44 #include "decimal.h"
45 #include "currency.h"
46 #include "comdatetime.h"
47 #include "comisolatedstorage.h"
48 #include "number.h"
49 #include "compatibilityswitch.h"
50 #ifdef FEATURE_REMOTING
51 #include "remotingnative.h"
52 #include "message.h"
53 #include "stackbuildersink.h"
54 #endif
55 #include "debugdebugger.h"
56 #include "assemblyname.hpp"
57 #include "assemblynative.hpp"
58 #include "rwlock.h"
59 #include "comthreadpool.h"
60 #include "comwaithandle.h"
61 #include "nativeoverlapped.h"
62
63 #include "proftoeeinterfaceimpl.h"
64
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"
76
77 #ifdef MDA_SUPPORTED 
78 #include "mdaassistants.h"
79 #endif
80
81 #include "coverage.h"
82
83 #ifdef FEATURE_COMINTEROP
84 #include "variant.h"
85 #ifdef FEATURE_COMINTEROP_TLB_SUPPORT
86 #include "comtypelibconverter.h"
87 #endif
88 #include "oavariant.h"
89 #include "registration.h"
90 #include "mngstdinterfaces.h"
91 #include "extensibleclassfactory.h"
92 #endif // FEATURE_COMINTEROP
93
94 #include "stubhelpers.h"
95 #include "ilmarshalers.h"
96
97 #ifdef FEATURE_MULTICOREJIT
98 #include "multicorejit.h"
99 #endif
100
101 #ifdef FEATURE_COMINTEROP
102 #include "clrprivtypecachereflectiononlywinrt.h"
103 #endif
104
105 #ifdef FEATURE_COMINTEROP
106 #include "windowsruntimebufferhelper.h"
107 #endif
108
109 #if defined(FEATURE_EVENTSOURCE_XPLAT)
110 #include "nativeeventsource.h"
111 #endif //defined(FEATURE_EVENTSOURCE_XPLAT)
112
113 #endif // CROSSGEN_MSCORLIB
114
115
116 #ifdef CROSSGEN_MSCORLIB
117
118 ///////////////////////////////////////////////////////////////////////////////
119 //
120 // Duplicate definitions of constants and datastructures required to define the tables
121 //
122
123 #define NumItems(s) (sizeof(s) / sizeof(s[0]))
124
125 #define GetEEFuncEntryPoint(pfn) 0x1001
126
127 enum {
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
132 };
133
134 struct ECClass
135 {
136     LPCSTR      m_szClassName;
137     LPCSTR      m_szNameSpace;
138     const LPVOID *  m_pECFunc;
139 };
140
141 struct HardCodedMetaSig
142 {
143     const BYTE* m_pMetaSig; // metasig prefixed with INT8 length:
144                             // length > 0 - resolved, lenght < 0 - has unresolved type references
145 };
146
147 enum BinderClassID
148 {
149 #define TYPEINFO(e,ns,c,s,g,ia,ip,if,im,gv)   CLASS__ ## e,
150 #include "cortypeinfo.h"
151 #undef TYPEINFO
152
153 #define DEFINE_CLASS(i,n,s)         CLASS__ ## i,
154 #include "mscorlib.h"
155
156     CLASS__MSCORLIB_COUNT,
157
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
176 };
177
178 struct MscorlibClassDescription
179 {
180     LPCSTR  nameSpace;
181     LPCSTR  name;
182 };
183
184 struct MscorlibMethodDescription
185 {
186     BinderClassID classID;
187     LPCSTR  name;
188     const HardCodedMetaSig * sig;
189 };
190
191 struct MscorlibFieldDescription
192 {
193     BinderClassID classID;
194     LPCSTR  name;
195 };
196
197 #endif // CROSSGEN_MSCORLIB
198
199
200 #ifdef CROSSGEN_MSCORLIB
201 // When compiling crossgen this namespace creates the second version of the tables than matches the target
202 namespace CrossGenMscorlib {
203 #endif
204
205
206 ///////////////////////////////////////////////////////////////////////////////
207 //
208 // Hardcoded Meta-Sig
209 //
210
211 //
212 // Helper enum with metasig lengths
213 //
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
222 enum _gsigl {
223 #include "metasig.h"
224 };
225
226 //
227 // Helper enum with metasig argcount
228 //
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
237 enum _gsigc {
238 #include "metasig.h"
239 };
240
241
242 //
243 // The actual array with the hardcoded metasig:
244 //
245 // There are 3 variations of the macros for Fields, Static Methods and Instance Methods.
246 //
247 // Each of them has 2 flavors: one for the fully baked signatures, and the other 
248 // for the signatures with unresolved type references
249 //
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.
253 //
254
255 #define DEFINE_METASIG(body)            body
256 #define DEFINE_METASIG_T(body)          _##body
257 #define METASIG_ATOM(x)                 x,
258 #define METASIG_RECURSE                 1
259
260 // define gsig_ ## varname before gsige_ ## varname to give a hint to the compiler about the desired layout
261
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 };
266
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 };
271
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 };
276
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 };
281
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 };
286
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 };
291
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 };
296
297 #include "metasig.h"
298
299 #undef _SM
300 #undef _IM
301 #undef _Fld
302
303
304
305 #ifdef _DEBUG
306
307 //
308 // Make sure DEFINE_METASIG is used for signatures that do not reference other types
309 //
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
317 #define C(x)                            1+
318 #define g(x)                            1+
319 #include "metasig.h"
320
321 //
322 // Make sure DEFINE_METASIG_T is used only for signatures that reference 
323 // other types.
324 //
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
332 #define C(x)                            1+
333 #define g(x)                            1+
334 #include "metasig.h"
335
336 #endif
337
338
339
340
341
342 ///////////////////////////////////////////////////////////////////////////////
343 //
344 // Mscorlib binder
345 //
346
347 // Extern definitions so that binder.cpp can see these tables
348 extern const MscorlibClassDescription c_rgMscorlibClassDescriptions[];
349 extern const USHORT c_nMscorlibClassDescriptions;
350
351 extern const MscorlibMethodDescription c_rgMscorlibMethodDescriptions[];
352 extern const USHORT c_nMscorlibMethodDescriptions;
353
354 extern const MscorlibFieldDescription c_rgMscorlibFieldDescriptions[];
355 extern const USHORT c_nMscorlibFieldDescriptions;
356
357 const MscorlibClassDescription c_rgMscorlibClassDescriptions[] =
358 {
359     #define TYPEINFO(e,ns,c,s,g,ia,ip,if,im,gv)   { ns, c },
360     #include "cortypeinfo.h"
361     #undef TYPEINFO
362     
363     #define DEFINE_CLASS(i,n,s)        { g_ ## n ## NS, # s },
364     #include "namespace.h"
365     #include "mscorlib.h"
366     
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, ...)
371     #include "rexcep.h"
372 };
373 const USHORT c_nMscorlibClassDescriptions = NumItems(c_rgMscorlibClassDescriptions);
374
375 #define gsig_NoSig (*(HardCodedMetaSig *)NULL)
376
377 const MscorlibMethodDescription c_rgMscorlibMethodDescriptions[] =
378 {
379     #define DEFINE_METHOD(c,i,s,g)          { CLASS__ ## c , # s, & gsig_ ## g },
380     #include "mscorlib.h"
381 };
382 const USHORT c_nMscorlibMethodDescriptions = NumItems(c_rgMscorlibMethodDescriptions) + 1;
383
384 const MscorlibFieldDescription c_rgMscorlibFieldDescriptions[] =
385 {
386     #define DEFINE_FIELD(c,i,s)           { CLASS__ ## c , # s },
387     #include "mscorlib.h"
388 };
389 const USHORT c_nMscorlibFieldDescriptions = NumItems(c_rgMscorlibFieldDescriptions) + 1;
390
391
392
393
394
395 ///////////////////////////////////////////////////////////////////////////////
396 //
397 // ECalls
398 //
399
400 // When compiling crossgen, we only need the target version of the ecall tables
401 #if !defined(CROSSGEN_COMPILE) || defined(CROSSGEN_MSCORLIB)
402
403 #ifdef CROSSGEN_COMPILE
404
405 #define QCFuncElement(name,impl) \
406     FCFuncFlag_QCall + FCFuncFlags(CORINFO_INTRINSIC_Illegal, ECall::InvalidDynamicFCallId), NULL, (LPVOID)name,
407
408 #define FCFuncFlags(intrinsicID, dynamicID) \
409     (BYTE*)( (((BYTE)intrinsicID) << 16) )
410
411 #else
412
413 #define QCFuncElement(name,impl) \
414     FCFuncFlag_QCall + FCFuncFlags(CORINFO_INTRINSIC_Illegal, ECall::InvalidDynamicFCallId), (LPVOID)(impl), (LPVOID)name,
415
416 #define FCFuncFlags(intrinsicID, dynamicID) \
417     (BYTE*)( (((BYTE)intrinsicID) << 16) + (((BYTE)dynamicID) << 24) )
418
419 #endif
420
421 #define FCFuncElement(name, impl) FCFuncFlags(CORINFO_INTRINSIC_Illegal, ECall::InvalidDynamicFCallId), \
422     (LPVOID)GetEEFuncEntryPoint(impl), (LPVOID)name,
423
424 #define FCFuncElementSig(name,sig,impl) \
425     FCFuncFlag_HasSignature + FCFuncElement(name, impl) (LPVOID)sig,
426
427 #define FCIntrinsic(name,impl,intrinsicID) FCFuncFlags(intrinsicID, ECall::InvalidDynamicFCallId), \
428     (LPVOID)GetEEFuncEntryPoint(impl), (LPVOID)name,
429
430 #define FCIntrinsicSig(name,sig,impl,intrinsicID) \
431     FCFuncFlag_HasSignature + FCIntrinsic(name,impl,intrinsicID) (LPVOID)sig,
432
433 #define FCDynamic(name,intrinsicID,dynamicID) FCFuncFlags(intrinsicID, dynamicID), \
434     NULL, (LPVOID)name,
435
436 #define FCDynamicSig(name,sig,intrinsicID,dynamicID) \
437     FCFuncFlag_HasSignature + FCDynamic(name,intrinsicID,dynamicID) (LPVOID)sig,
438
439 #define FCUnreferenced FCFuncFlag_Unreferenced +
440
441 #define FCFuncStart(name) static const LPVOID name[] = {
442 #define FCFuncEnd() FCFuncFlag_EndOfArray + FCFuncFlags(CORINFO_INTRINSIC_Illegal, ECall::InvalidDynamicFCallId) };
443
444 #include "ecalllist.h"
445
446
447 // Extern definitions so that ecall.cpp can see these tables
448 extern const ECClass c_rgECClasses[];
449 extern const int c_nECClasses;
450
451 const ECClass c_rgECClasses[] =
452 {
453 #define FCClassElement(name,namespace,funcs) {name, namespace, funcs},
454 #include "ecalllist.h"
455 };  // c_rgECClasses[]
456
457 const int c_nECClasses = NumItems(c_rgECClasses);
458
459 #endif // !CROSSGEN_COMPILE && CROSSGEN_MSCORLIB
460
461
462 #ifdef CROSSGEN_MSCORLIB
463 }; // namespace CrossGenMscorlib
464 #endif