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