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