1 /**
2  * \file
3  * Copyright 2012 Xamarin Inc
4  * Licensed under the MIT license. See LICENSE file in the project root for full license information.
5  */
6 #ifndef __MONO_METADATA_CLASS_INTERNALS_H__
7 #define __MONO_METADATA_CLASS_INTERNALS_H__
8 
9 #include <mono/metadata/class.h>
10 #include <mono/metadata/object.h>
11 #include <mono/metadata/mempool.h>
12 #include <mono/metadata/metadata-internals.h>
13 #include <mono/metadata/property-bag.h>
14 #include "mono/utils/mono-compiler.h"
15 #include "mono/utils/mono-error.h"
16 #include "mono/sgen/gc-internal-agnostic.h"
17 
18 #define MONO_CLASS_IS_ARRAY(c) ((c)->rank)
19 
20 #define MONO_CLASS_HAS_STATIC_METADATA(klass) ((klass)->type_token && !(klass)->image->dynamic && !mono_class_is_ginst (klass))
21 
22 #define MONO_DEFAULT_SUPERTABLE_SIZE 6
23 
24 extern gboolean mono_print_vtable;
25 extern gboolean mono_align_small_structs;
26 
27 typedef struct _MonoMethodWrapper MonoMethodWrapper;
28 typedef struct _MonoMethodInflated MonoMethodInflated;
29 typedef struct _MonoMethodPInvoke MonoMethodPInvoke;
30 typedef struct _MonoDynamicMethod MonoDynamicMethod;
31 
32 /* Properties that applies to a group of structs should better use a higher number
33  * to avoid colision with type specific properties.
34  *
35  * This prop applies to class, method, property, event, assembly and image.
36  */
37 #define MONO_PROP_DYNAMIC_CATTR 0x1000
38 
39 #ifdef ENABLE_ICALL_EXPORT
40 #pragma GCC diagnostic ignored "-Wmissing-prototypes"
41 #define ICALL_DECL_EXPORT MONO_API
42 #define ICALL_EXPORT MONO_API
43 #else
44 #define ICALL_DECL_EXPORT
45 #define ICALL_EXPORT static
46 #endif
47 
48 typedef enum {
49 #define WRAPPER(e,n) MONO_WRAPPER_ ## e,
50 #include "wrapper-types.h"
51 #undef WRAPPER
52 	MONO_WRAPPER_NUM
53 } MonoWrapperType;
54 
55 typedef enum {
56 	MONO_TYPE_NAME_FORMAT_IL,
57 	MONO_TYPE_NAME_FORMAT_REFLECTION,
58 	MONO_TYPE_NAME_FORMAT_FULL_NAME,
59 	MONO_TYPE_NAME_FORMAT_ASSEMBLY_QUALIFIED
60 } MonoTypeNameFormat;
61 
62 typedef enum {
63 	MONO_REMOTING_TARGET_UNKNOWN,
64 	MONO_REMOTING_TARGET_APPDOMAIN,
65 	MONO_REMOTING_TARGET_COMINTEROP
66 } MonoRemotingTarget;
67 
68 #define MONO_METHOD_PROP_GENERIC_CONTAINER 0
69 
70 struct _MonoMethod {
71 	guint16 flags;  /* method flags */
72 	guint16 iflags; /* method implementation flags */
73 	guint32 token;
74 	MonoClass *klass; /* To what class does this method belong */
75 	MonoMethodSignature *signature;
76 	/* name is useful mostly for debugging */
77 	const char *name;
78 	/* this is used by the inlining algorithm */
79 	unsigned int inline_info:1;
80 	unsigned int inline_failure:1;
81 	unsigned int wrapper_type:5;
82 	unsigned int string_ctor:1;
83 	unsigned int save_lmf:1;
84 	unsigned int dynamic:1; /* created & destroyed during runtime */
85 	unsigned int sre_method:1; /* created at runtime using Reflection.Emit */
86 	unsigned int is_generic:1; /* whenever this is a generic method definition */
87 	unsigned int is_inflated:1; /* whether we're a MonoMethodInflated */
88 	unsigned int skip_visibility:1; /* whenever to skip JIT visibility checks */
89 	unsigned int verification_success:1; /* whether this method has been verified successfully.*/
90 	signed int slot : 16;
91 
92 	/*
93 	 * If is_generic is TRUE, the generic_container is stored in image->property_hash,
94 	 * using the key MONO_METHOD_PROP_GENERIC_CONTAINER.
95 	 */
96 };
97 
98 struct _MonoMethodWrapper {
99 	MonoMethod method;
100 	MonoMethodHeader *header;
101 	void *method_data;
102 };
103 
104 struct _MonoDynamicMethod {
105 	MonoMethodWrapper method;
106 	MonoAssembly *assembly;
107 };
108 
109 struct _MonoMethodPInvoke {
110 	MonoMethod method;
111 	gpointer addr;
112 	/* add marshal info */
113 	guint16 piflags;  /* pinvoke flags */
114 	guint32 implmap_idx;  /* index into IMPLMAP */
115 };
116 
117 /*
118  * Stores the default value / RVA of fields.
119  * This information is rarely needed, so it is stored separately from
120  * MonoClassField.
121  */
122 typedef struct MonoFieldDefaultValue {
123 	/*
124 	 * If the field is constant, pointer to the metadata constant
125 	 * value.
126 	 * If the field has an RVA flag, pointer to the data.
127 	 * Else, invalid.
128 	 */
129 	const char      *data;
130 
131 	/* If the field is constant, the type of the constant. */
132 	MonoTypeEnum     def_type;
133 } MonoFieldDefaultValue;
134 
135 /*
136  * MonoClassField is just a runtime representation of the metadata for
137  * field, it doesn't contain the data directly.  Static fields are
138  * stored in MonoVTable->data.  Instance fields are allocated in the
139  * objects after the object header.
140  */
141 struct _MonoClassField {
142 	/* Type of the field */
143 	MonoType        *type;
144 
145 	const char      *name;
146 
147 	/* Type where the field was defined */
148 	MonoClass       *parent;
149 
150 	/*
151 	 * Offset where this field is stored; if it is an instance
152 	 * field, it's the offset from the start of the object, if
153 	 * it's static, it's from the start of the memory chunk
154 	 * allocated for statics for the class.
155 	 * For special static fields, this is set to -1 during vtable construction.
156 	 */
157 	int              offset;
158 };
159 
160 /* a field is ignored if it's named "_Deleted" and it has the specialname and rtspecialname flags set */
161 #define mono_field_is_deleted(field) (((field)->type->attrs & (FIELD_ATTRIBUTE_SPECIAL_NAME | FIELD_ATTRIBUTE_RT_SPECIAL_NAME)) \
162 				      && (strcmp (mono_field_get_name (field), "_Deleted") == 0))
163 
164 /* a field is ignored if it's named "_Deleted" and it has the specialname and rtspecialname flags set */
165 /* Try to avoid loading the field's type */
166 #define mono_field_is_deleted_with_flags(field, flags) (((flags) & (FIELD_ATTRIBUTE_SPECIAL_NAME | FIELD_ATTRIBUTE_RT_SPECIAL_NAME)) \
167 				      && (strcmp (mono_field_get_name (field), "_Deleted") == 0))
168 
169 typedef struct {
170 	MonoClassField *field;
171 	guint32 offset;
172 	MonoMarshalSpec *mspec;
173 } MonoMarshalField;
174 
175 typedef struct {
176 	MonoPropertyBagItem head;
177 
178 	guint32 native_size, min_align;
179 	guint32 num_fields;
180 	MonoMethod *ptr_to_str;
181 	MonoMethod *str_to_ptr;
182 	MonoMarshalField fields [MONO_ZERO_LEN_ARRAY];
183 } MonoMarshalType;
184 
185 #define MONO_SIZEOF_MARSHAL_TYPE (offsetof (MonoMarshalType, fields))
186 
187 struct _MonoProperty {
188 	MonoClass *parent;
189 	const char *name;
190 	MonoMethod *get;
191 	MonoMethod *set;
192 	guint32 attrs;
193 };
194 
195 struct _MonoEvent {
196 	MonoClass *parent;
197 	const char *name;
198 	MonoMethod *add;
199 	MonoMethod *remove;
200 	MonoMethod *raise;
201 #ifndef MONO_SMALL_CONFIG
202 	MonoMethod **other;
203 #endif
204 	guint32 attrs;
205 };
206 
207 /* type of exception being "on hold" for later processing (see exception_type) */
208 typedef enum {
209 	MONO_EXCEPTION_NONE = 0,
210 	MONO_EXCEPTION_INVALID_PROGRAM = 3,
211 	MONO_EXCEPTION_UNVERIFIABLE_IL = 4,
212 	MONO_EXCEPTION_MISSING_METHOD = 5,
213 	MONO_EXCEPTION_MISSING_FIELD = 6,
214 	MONO_EXCEPTION_TYPE_LOAD = 7,
215 	MONO_EXCEPTION_FILE_NOT_FOUND = 8,
216 	MONO_EXCEPTION_METHOD_ACCESS = 9,
217 	MONO_EXCEPTION_FIELD_ACCESS = 10,
218 	MONO_EXCEPTION_GENERIC_SHARING_FAILED = 11,
219 	MONO_EXCEPTION_BAD_IMAGE = 12,
220 	MONO_EXCEPTION_OBJECT_SUPPLIED = 13, /*The exception object is already created.*/
221 	MONO_EXCEPTION_OUT_OF_MEMORY = 14,
222 	MONO_EXCEPTION_INLINE_FAILED = 15,
223 	MONO_EXCEPTION_MONO_ERROR = 16,
224 	/* add other exception type */
225 } MonoExceptionType;
226 
227 /* This struct collects the info needed for the runtime use of a class,
228  * like the vtables for a domain, the GC descriptor, etc.
229  */
230 typedef struct {
231 	guint16 max_domain;
232 	/* domain_vtables is indexed by the domain id and the size is max_domain + 1 */
233 	MonoVTable *domain_vtables [MONO_ZERO_LEN_ARRAY];
234 } MonoClassRuntimeInfo;
235 
236 #define MONO_SIZEOF_CLASS_RUNTIME_INFO (sizeof (MonoClassRuntimeInfo) - MONO_ZERO_LEN_ARRAY * SIZEOF_VOID_P)
237 
238 typedef struct {
239 	MonoPropertyBagItem head;
240 
241 	MonoProperty *properties;
242 	guint32 first, count;
243 	MonoFieldDefaultValue *def_values;
244 } MonoClassPropertyInfo;
245 
246 typedef struct {
247 	MonoPropertyBagItem head;
248 
249 	/* Initialized by a call to mono_class_setup_events () */
250 	MonoEvent *events;
251 	guint32 first, count;
252 } MonoClassEventInfo;
253 
254 typedef enum {
255 	MONO_CLASS_DEF = 1, /* non-generic type */
256 	MONO_CLASS_GTD, /* generic type definition */
257 	MONO_CLASS_GINST, /* generic instantiation */
258 	MONO_CLASS_GPARAM, /* generic parameter */
259 	MONO_CLASS_ARRAY, /* vector or array, bounded or not */
260 	MONO_CLASS_POINTER, /* pointer of function pointer*/
261 } MonoTypeKind;
262 
263 struct _MonoClass {
264 	/* element class for arrays and enum basetype for enums */
265 	MonoClass *element_class;
266 	/* used for subtype checks */
267 	MonoClass *cast_class;
268 
269 	/* for fast subtype checks */
270 	MonoClass **supertypes;
271 	guint16     idepth;
272 
273 	/* array dimension */
274 	guint8     rank;
275 
276 	int        instance_size; /* object instance size */
277 
278 	guint inited          : 1;
279 
280 	/* A class contains static and non static data. Static data can be
281 	 * of the same type as the class itselfs, but it does not influence
282 	 * the instance size of the class. To avoid cyclic calls to
283 	 * mono_class_init (from mono_class_instance_size ()) we first
284 	 * initialise all non static fields. After that we set size_inited
285 	 * to 1, because we know the instance size now. After that we
286 	 * initialise all static fields.
287 	 */
288 
289 	/* ALL BITFIELDS SHOULD BE WRITTEN WHILE HOLDING THE LOADER LOCK */
290 	guint size_inited     : 1;
291 	guint valuetype       : 1; /* derives from System.ValueType */
292 	guint enumtype        : 1; /* derives from System.Enum */
293 	guint blittable       : 1; /* class is blittable */
294 	guint unicode         : 1; /* class uses unicode char when marshalled */
295 	guint wastypebuilder  : 1; /* class was created at runtime from a TypeBuilder */
296 	guint is_array_special_interface : 1; /* gtd or ginst of once of the magic interfaces that arrays implement */
297 
298 	/* next byte */
299 	guint8 min_align;
300 
301 	/* next byte */
302 	guint packing_size    : 4;
303 	guint ghcimpl         : 1; /* class has its own GetHashCode impl */
304 	guint has_finalize    : 1; /* class has its own Finalize impl */
305 #ifndef DISABLE_REMOTING
306 	guint marshalbyref    : 1; /* class is a MarshalByRefObject */
307 	guint contextbound    : 1; /* class is a ContextBoundObject */
308 #endif
309 	/* next byte */
310 	guint delegate        : 1; /* class is a Delegate */
311 	guint gc_descr_inited : 1; /* gc_descr is initialized */
312 	guint has_cctor       : 1; /* class has a cctor */
313 	guint has_references  : 1; /* it has GC-tracked references in the instance */
314 	guint has_static_refs : 1; /* it has static fields that are GC-tracked */
315 	guint no_special_static_fields : 1; /* has no thread/context static fields */
316 	/* directly or indirectly derives from ComImport attributed class.
317 	 * this means we need to create a proxy for instances of this class
318 	 * for COM Interop. set this flag on loading so all we need is a quick check
319 	 * during object creation rather than having to traverse supertypes
320 	 */
321 	guint is_com_object : 1;
322 	guint nested_classes_inited : 1; /* Whenever nested_class is initialized */
323 
324 	/* next byte*/
325 	guint class_kind : 3; /* One of the values from MonoTypeKind */
326 	guint interfaces_inited : 1; /* interfaces is initialized */
327 	guint simd_type : 1; /* class is a simd intrinsic type */
328 	guint has_finalize_inited    : 1; /* has_finalize is initialized */
329 	guint fields_inited : 1; /* setup_fields () has finished */
330 	guint has_failure : 1; /* See mono_class_get_exception_data () for a MonoErrorBoxed with the details */
331 	guint has_weak_fields : 1; /* class has weak reference fields */
332 
333 	MonoClass  *parent;
334 	MonoClass  *nested_in;
335 
336 	MonoImage *image;
337 	const char *name;
338 	const char *name_space;
339 
340 	guint32    type_token;
341 	int        vtable_size; /* number of slots */
342 
343 	guint16     interface_count;
344 	guint32     interface_id;        /* unique inderface id (for interfaces) */
345 	guint32     max_interface_id;
346 
347 	guint16     interface_offsets_count;
348 	MonoClass **interfaces_packed;
349 	guint16    *interface_offsets_packed;
350 /* enabled only with small config for now: we might want to do it unconditionally */
351 #ifdef MONO_SMALL_CONFIG
352 #define COMPRESSED_INTERFACE_BITMAP 1
353 #endif
354 	guint8     *interface_bitmap;
355 
356 	MonoClass **interfaces;
357 
358 	union {
359 		int class_size; /* size of area for static fields */
360 		int element_size; /* for array types */
361 		int generic_param_token; /* for generic param types, both var and mvar */
362 	} sizes;
363 
364 	/*
365 	 * Field information: Type and location from object base
366 	 */
367 	MonoClassField *fields;
368 
369 	MonoMethod **methods;
370 
371 	/* used as the type of the this argument and when passing the arg by value */
372 	MonoType this_arg;
373 	MonoType byval_arg;
374 
375 	MonoGCDescriptor gc_descr;
376 
377 	MonoClassRuntimeInfo *runtime_info;
378 
379 	/* Generic vtable. Initialized by a call to mono_class_setup_vtable () */
380 	MonoMethod **vtable;
381 
382 	/* Infrequently used items. See class-accessors.c: InfrequentDataKind for what goes into here. */
383 	MonoPropertyBag infrequent_data;
384 };
385 
386 typedef struct {
387 	MonoClass klass;
388 	guint32	flags;
389 	/*
390 	 * From the TypeDef table
391 	 */
392 	guint32 first_method_idx;
393 	guint32 first_field_idx;
394 	guint32 method_count, field_count;
395 	/* next element in the class_cache hash list (in MonoImage) */
396 	MonoClass *next_class_cache;
397 } MonoClassDef;
398 
399 typedef struct {
400 	MonoClassDef klass;
401 	MonoGenericContainer *generic_container;
402 	/* The canonical GENERICINST where we instantiate a generic type definition with its own generic parameters.*/
403 	/* Suppose we have class T`2<A,B> {...}.  canonical_inst is the GTD T`2 applied to A and B. */
404 	MonoType canonical_inst;
405 } MonoClassGtd;
406 
407 typedef struct {
408 	MonoClass klass;
409 	MonoGenericClass *generic_class;
410 } MonoClassGenericInst;
411 
412 typedef struct {
413 	MonoClass klass;
414 } MonoClassGenericParam;
415 
416 typedef struct {
417 	MonoClass klass;
418 	guint32 method_count;
419 } MonoClassArray;
420 
421 typedef struct {
422 	MonoClass klass;
423 } MonoClassPointer;
424 
425 #ifdef COMPRESSED_INTERFACE_BITMAP
426 int mono_compress_bitmap (uint8_t *dest, const uint8_t *bitmap, int size);
427 int mono_class_interface_match (const uint8_t *bitmap, int id);
428 #else
429 #define mono_class_interface_match(bmap,uiid) ((bmap) [(uiid) >> 3] & (1 << ((uiid)&7)))
430 #endif
431 
432 #define MONO_CLASS_IMPLEMENTS_INTERFACE(k,uiid) (((uiid) <= (k)->max_interface_id) && mono_class_interface_match ((k)->interface_bitmap, (uiid)))
433 
434 #define MONO_VTABLE_AVAILABLE_GC_BITS 4
435 
436 #ifdef DISABLE_REMOTING
437 #define mono_class_is_marshalbyref(klass) (FALSE)
438 #define mono_class_is_contextbound(klass) (FALSE)
439 #define mono_vtable_is_remote(vtable) (FALSE)
440 #define mono_vtable_set_is_remote(vtable,enable) do {} while (0)
441 #else
442 #define mono_class_is_marshalbyref(klass) ((klass)->marshalbyref)
443 #define mono_class_is_contextbound(klass) ((klass)->contextbound)
444 #define mono_vtable_is_remote(vtable) ((vtable)->remote)
445 #define mono_vtable_set_is_remote(vtable,enable) do { (vtable)->remote = enable ? 1 : 0; } while (0)
446 #endif
447 
448 #ifdef DISABLE_COM
449 #define mono_class_is_com_object(klass) (FALSE)
450 #else
451 #define mono_class_is_com_object(klass) ((klass)->is_com_object)
452 #endif
453 
454 
455 MONO_API int mono_class_interface_offset (MonoClass *klass, MonoClass *itf);
456 int mono_class_interface_offset_with_variance (MonoClass *klass, MonoClass *itf, gboolean *non_exact_match);
457 
458 typedef gpointer MonoRuntimeGenericContext;
459 
460 /* the interface_offsets array is stored in memory before this struct */
461 struct MonoVTable {
462 	MonoClass  *klass;
463 	 /*
464 	 * According to comments in gc_gcj.h, this should be the second word in
465 	 * the vtable.
466 	 */
467 	MonoGCDescriptor gc_descr;
468 	MonoDomain *domain;  /* each object/vtable belongs to exactly one domain */
469         gpointer    type; /* System.Type type for klass */
470 	guint8     *interface_bitmap;
471 	guint32     max_interface_id;
472 	guint8      rank;
473 	/* Keep this a guint8, the jit depends on it */
474 	guint8      initialized; /* cctor has been run */
475 	guint remote          : 1; /* class is remotely activated */
476 	guint init_failed     : 1; /* cctor execution failed */
477 	guint has_static_fields : 1; /* pointer to the data stored at the end of the vtable array */
478 	guint gc_bits         : MONO_VTABLE_AVAILABLE_GC_BITS; /* Those bits are reserved for the usaged of the GC */
479 
480 	guint32     imt_collisions_bitmap;
481 	MonoRuntimeGenericContext *runtime_generic_context;
482 	/* do not add any fields after vtable, the structure is dynamically extended */
483 	/* vtable contains function pointers to methods or their trampolines, at the
484 	 end there may be a slot containing the pointer to the static fields */
485 	gpointer    vtable [MONO_ZERO_LEN_ARRAY];
486 };
487 
488 #define MONO_SIZEOF_VTABLE (sizeof (MonoVTable) - MONO_ZERO_LEN_ARRAY * SIZEOF_VOID_P)
489 
490 #define MONO_VTABLE_IMPLEMENTS_INTERFACE(vt,uiid) (((uiid) <= (vt)->max_interface_id) && mono_class_interface_match ((vt)->interface_bitmap, (uiid)))
491 
492 /*
493  * Generic instantiation data type encoding.
494  */
495 
496 /*
497  * A particular generic instantiation:
498  *
499  * All instantiations are cached and we don't distinguish between class and method
500  * instantiations here.
501  */
502 struct _MonoGenericInst {
503 #ifndef MONO_SMALL_CONFIG
504 	gint32 id;			/* unique ID for debugging */
505 #endif
506 	guint type_argc    : 22;	/* number of type arguments */
507 	guint is_open      :  1;	/* if this is an open type */
508 	MonoType *type_argv [MONO_ZERO_LEN_ARRAY];
509 };
510 
511 #define MONO_SIZEOF_GENERIC_INST (sizeof (MonoGenericInst) - MONO_ZERO_LEN_ARRAY * SIZEOF_VOID_P)
512 /*
513  * The generic context: an instantiation of a set of class and method generic parameters.
514  *
515  * NOTE: Never allocate this directly on the heap.  It have to be either allocated on the stack,
516  *	 or embedded within other objects.  Don't store pointers to this, because it may be on the stack.
517  *	 If you really have to, ensure you store a pointer to the embedding object along with it.
518  */
519 struct _MonoGenericContext {
520 	/* The instantiation corresponding to the class generic parameters */
521 	MonoGenericInst *class_inst;
522 	/* The instantiation corresponding to the method generic parameters */
523 	MonoGenericInst *method_inst;
524 };
525 
526 /*
527  * Inflated generic method.
528  */
529 struct _MonoMethodInflated {
530 	union {
531 		MonoMethod method;
532 		MonoMethodPInvoke pinvoke;
533 	} method;
534 	MonoMethod *declaring;		/* the generic method definition. */
535 	MonoGenericContext context;	/* The current instantiation */
536 	MonoImageSet *owner; /* The image set that the inflated method belongs to. */
537 };
538 
539 /*
540  * A particular instantiation of a generic type.
541  */
542 struct _MonoGenericClass {
543 	MonoClass *container_class;	/* the generic type definition */
544 	MonoGenericContext context;	/* a context that contains the type instantiation doesn't contain any method instantiation */ /* FIXME: Only the class_inst member of "context" is ever used, so this field could be replaced with just a monogenericinst */
545 	guint is_dynamic  : 1;		/* Contains dynamic types */
546 	guint is_tb_open  : 1;		/* This is the fully open instantiation for a type_builder. Quite ugly, but it's temporary.*/
547 	guint need_sync   : 1;      /* Only if dynamic. Need to be synchronized with its container class after its finished. */
548 	MonoClass *cached_class;	/* if present, the MonoClass corresponding to the instantiation.  */
549 
550 	/*
551 	 * The image set which owns this generic class. Memory owned by the generic class
552 	 * including cached_class should be allocated from the mempool of the image set,
553 	 * so it is easy to free.
554 	 */
555 	MonoImageSet *owner;
556 };
557 
558 /*
559  * A type parameter.
560  */
561 struct _MonoGenericParam {
562 	/*
563 	 * Type or method this parameter was defined in.
564 	 */
565 	MonoGenericContainer *owner;
566 	guint16 num;
567 	/*
568 	 * If != NULL, this is a generated generic param used by the JIT to implement generic
569 	 * sharing.
570 	 */
571 	MonoType *gshared_constraint;
572 };
573 
574 /* Additional details about a MonoGenericParam */
575 /* Keep in sync with managed Mono.RuntimeStructs.GenericParamInfo */
576 typedef struct {
577 	MonoClass *pklass;		/* The corresponding `MonoClass'. */
578 	const char *name;
579 
580 	// See GenericParameterAttributes
581 	guint16 flags;
582 
583 	guint32 token;
584 
585 	// Constraints on type parameters
586 	MonoClass** constraints; /* NULL means end of list */
587 } MonoGenericParamInfo;
588 
589 typedef struct {
590 	MonoGenericParam param;
591 	MonoGenericParamInfo info;
592 } MonoGenericParamFull;
593 
594 /*
595  * The generic container.
596  *
597  * Stores the type parameters of a generic type definition or a generic method definition.
598  */
599 struct _MonoGenericContainer {
600 	MonoGenericContext context;
601 	/* If we're a generic method definition in a generic type definition,
602 	   the generic container of the containing class. */
603 	MonoGenericContainer *parent;
604 	/* the generic type definition or the generic method definition corresponding to this container */
605 	/* Union rules: If is_anonymous, image field is valid; else if is_method, method field is valid; else klass is valid. */
606 	union {
607 		MonoClass *klass;
608 		MonoMethod *method;
609 		MonoImage *image;
610 	} owner;
611 	int type_argc    : 29; // Per the ECMA spec, this value is capped at 16 bits
612 	/* If true, we're a generic method, otherwise a generic type definition. */
613 	/* Invariant: parent != NULL => is_method */
614 	int is_method     : 1;
615 	/* If true, this container has no associated class/method and only the image is known. This can happen:
616 	   1. For the special anonymous containers kept by MonoImage.
617 	   2. During container creation via the mono_metadata_load_generic_params path-- in this case the caller
618 	      sets the owner, so temporarily while load_generic_params is completing the container is anonymous.
619 	   3. When user code creates a generic parameter via SRE, but has not yet set an owner. */
620 	int is_anonymous : 1;
621 	/* If false, all params in this container are full-size. If true, all params are just param structs. */
622 	/* This field is always == to the is_anonymous field, except in "temporary" cases (2) and (3) above. */
623 	/* TODO: Merge GenericParam and GenericParamFull, remove this field. Benefit is marginal. */
624 	int is_small_param : 1;
625 	/* Our type parameters. */
626 	MonoGenericParamFull *type_params;
627 };
628 
629 static inline MonoGenericParam *
mono_generic_container_get_param(MonoGenericContainer * gc,int i)630 mono_generic_container_get_param (MonoGenericContainer *gc, int i)
631 {
632 	return (MonoGenericParam *) &gc->type_params [i];
633 }
634 
635 static inline MonoGenericParamInfo *
mono_generic_container_get_param_info(MonoGenericContainer * gc,int i)636 mono_generic_container_get_param_info (MonoGenericContainer *gc, int i)
637 {
638 	return &gc->type_params [i].info;
639 }
640 
641 static inline MonoGenericContainer *
mono_generic_param_owner(MonoGenericParam * p)642 mono_generic_param_owner (MonoGenericParam *p)
643 {
644 	return p->owner;
645 }
646 
647 static inline int
mono_generic_param_num(MonoGenericParam * p)648 mono_generic_param_num (MonoGenericParam *p)
649 {
650 	return p->num;
651 }
652 
653 static inline gboolean
mono_generic_param_is_fullsize(MonoGenericParam * p)654 mono_generic_param_is_fullsize (MonoGenericParam *p)
655 {
656 	return !mono_generic_param_owner (p)->is_small_param;
657 }
658 
659 static inline MonoGenericParamInfo *
mono_generic_param_info(MonoGenericParam * p)660 mono_generic_param_info (MonoGenericParam *p)
661 {
662 	if (mono_generic_param_is_fullsize (p))
663 		return &((MonoGenericParamFull *) p)->info;
664 	return NULL;
665 }
666 
667 static inline const char *
mono_generic_param_name(MonoGenericParam * p)668 mono_generic_param_name (MonoGenericParam *p)
669 {
670 	if (mono_generic_param_is_fullsize (p))
671 		return ((MonoGenericParamFull *) p)->info.name;
672 	return NULL;
673 }
674 
675 static inline MonoGenericContainer *
mono_type_get_generic_param_owner(MonoType * t)676 mono_type_get_generic_param_owner (MonoType *t)
677 {
678 	return mono_generic_param_owner (t->data.generic_param);
679 }
680 
681 static inline int
mono_type_get_generic_param_num(MonoType * t)682 mono_type_get_generic_param_num (MonoType *t)
683 {
684 	return mono_generic_param_num (t->data.generic_param);
685 }
686 
687 /*
688  * Class information which might be cached by the runtime in the AOT file for
689  * example. Caching this allows us to avoid computing a generic vtable
690  * (class->vtable) in most cases, saving time and avoiding creation of lots of
691  * MonoMethod structures.
692  */
693 typedef struct MonoCachedClassInfo {
694 	guint32 vtable_size;
695 	guint has_finalize : 1;
696 	guint ghcimpl : 1;
697 	guint has_cctor : 1;
698 	guint has_nested_classes : 1;
699 	guint blittable : 1;
700 	guint has_references : 1;
701 	guint has_static_refs : 1;
702 	guint no_special_static_fields : 1;
703 	guint is_generic_container : 1;
704 	guint has_weak_fields : 1;
705 	guint32 cctor_token;
706 	MonoImage *finalize_image;
707 	guint32 finalize_token;
708 	guint32 instance_size;
709 	guint32 class_size;
710 	guint32 packing_size;
711 	guint32 min_align;
712 } MonoCachedClassInfo;
713 
714 typedef struct {
715 	const char *name;
716 	gconstpointer func;
717 	gconstpointer wrapper;
718 	gconstpointer trampoline;
719 	MonoMethodSignature *sig;
720 	const char *c_symbol;
721 	MonoMethod *wrapper_method;
722 } MonoJitICallInfo;
723 
724 void
725 mono_class_setup_supertypes (MonoClass *klass);
726 
727 void
728 mono_class_setup_fields (MonoClass *klass);
729 
730 /* WARNING
731  * Only call this function if you can ensure both @klass and @parent
732  * have supertype information initialized.
733  * This can be accomplished by mono_class_setup_supertypes or mono_class_init.
734  * If unsure, use mono_class_has_parent.
735  */
736 static inline gboolean
mono_class_has_parent_fast(MonoClass * klass,MonoClass * parent)737 mono_class_has_parent_fast (MonoClass *klass, MonoClass *parent)
738 {
739 	return (klass->idepth >= parent->idepth) && (klass->supertypes [parent->idepth - 1] == parent);
740 }
741 
742 static inline gboolean
mono_class_has_parent(MonoClass * klass,MonoClass * parent)743 mono_class_has_parent (MonoClass *klass, MonoClass *parent)
744 {
745 	if (G_UNLIKELY (!klass->supertypes))
746 		mono_class_setup_supertypes (klass);
747 
748 	if (G_UNLIKELY (!parent->supertypes))
749 		mono_class_setup_supertypes (parent);
750 
751 	return mono_class_has_parent_fast (klass, parent);
752 }
753 
754 typedef struct {
755 	MonoVTable *default_vtable;
756 	MonoVTable *xdomain_vtable;
757 	MonoClass *proxy_class;
758 	char* proxy_class_name;
759 	uint32_t interface_count;
760 	MonoClass *interfaces [MONO_ZERO_LEN_ARRAY];
761 } MonoRemoteClass;
762 
763 #define MONO_SIZEOF_REMOTE_CLASS (sizeof (MonoRemoteClass) - MONO_ZERO_LEN_ARRAY * SIZEOF_VOID_P)
764 
765 typedef struct {
766 	gint32 initialized_class_count;
767 	gint32 generic_vtable_count;
768 	gint32 used_class_count;
769 	gint32 method_count;
770 	gint32 class_vtable_size;
771 	gint32 class_static_data_size;
772 	gint32 generic_class_count;
773 	gint32 inflated_method_count;
774 	gint32 inflated_type_count;
775 	gint32 delegate_creations;
776 	gint32 imt_tables_size;
777 	gint32 imt_number_of_tables;
778 	gint32 imt_number_of_methods;
779 	gint32 imt_used_slots;
780 	gint32 imt_slots_with_collisions;
781 	gint32 imt_max_collisions_in_slot;
782 	gint32 imt_method_count_when_max_collisions;
783 	gint32 imt_trampolines_size;
784 	gint32 jit_info_table_insert_count;
785 	gint32 jit_info_table_remove_count;
786 	gint32 jit_info_table_lookup_count;
787 	gint32 generics_sharable_methods;
788 	gint32 generics_unsharable_methods;
789 	gint32 generics_shared_methods;
790 	gint32 gsharedvt_methods;
791 	gboolean enabled;
792 } MonoStats;
793 
794 /*
795  * new structure to hold performace counters values that are exported
796  * to managed code.
797  * Note: never remove fields from this structure and only add them to the end.
798  * Size of fields and type should not be changed as well.
799  */
800 typedef struct {
801 	/* JIT category */
802 	gint32 jit_methods;
803 	gint32 jit_bytes;
804 	gint32 jit_time;
805 	gint32 jit_failures;
806 	/* Exceptions category */
807 	gint32 exceptions_thrown;
808 	gint32 exceptions_filters;
809 	gint32 exceptions_finallys;
810 	gint32 exceptions_depth;
811 	gint32 aspnet_requests_queued;
812 	gint32 aspnet_requests;
813 	/* Memory category */
814 	gint32 gc_collections0;
815 	gint32 gc_collections1;
816 	gint32 gc_collections2;
817 	gint32 gc_promotions0;
818 	gint32 gc_promotions1;
819 	gint32 gc_promotion_finalizers;
820 	gint64 gc_gen0size;
821 	gint64 gc_gen1size;
822 	gint64 gc_gen2size;
823 	gint32 gc_lossize;
824 	gint32 gc_fin_survivors;
825 	gint32 gc_num_handles;
826 	gint32 gc_allocated;
827 	gint32 gc_induced;
828 	gint32 gc_time;
829 	gint64 gc_total_bytes;
830 	gint64 gc_committed_bytes;
831 	gint64 gc_reserved_bytes;
832 	gint32 gc_num_pinned;
833 	gint32 gc_sync_blocks;
834 	/* Remoting category */
835 	gint32 remoting_calls;
836 	gint32 remoting_channels;
837 	gint32 remoting_proxies;
838 	gint32 remoting_classes;
839 	gint32 remoting_objects;
840 	gint32 remoting_contexts;
841 	/* Loader category */
842 	gint32 loader_classes;
843 	gint32 loader_total_classes;
844 	gint32 loader_appdomains;
845 	gint32 loader_total_appdomains;
846 	gint32 loader_assemblies;
847 	gint32 loader_total_assemblies;
848 	gint32 loader_failures;
849 	gint32 loader_bytes;
850 	gint32 loader_appdomains_uloaded;
851 	/* Threads and Locks category  */
852 	gint32 thread_contentions;
853 	gint32 thread_queue_len;
854 	gint32 thread_queue_max;
855 	gint32 thread_num_logical;
856 	gint32 thread_num_physical;
857 	gint32 thread_cur_recognized;
858 	gint32 thread_num_recognized;
859 	/* Interop category */
860 	gint32 interop_num_ccw;
861 	gint32 interop_num_stubs;
862 	gint32 interop_num_marshals;
863 	/* Security category */
864 	gint32 security_num_checks;
865 	gint32 security_num_link_checks;
866 	gint32 security_time;
867 	gint32 security_depth;
868 	gint32 unused;
869 	/* Threadpool */
870 	gint64 threadpool_workitems;
871 	gint64 threadpool_ioworkitems;
872 	gint32 threadpool_threads;
873 	gint32 threadpool_iothreads;
874 } MonoPerfCounters;
875 
876 extern MonoPerfCounters *mono_perfcounters;
877 
878 MONO_API void mono_perfcounters_init (void);
879 
880 /*
881  * The definition of the first field in SafeHandle,
882  * Keep in sync with SafeHandle.cs, this is only used
883  * to access the `handle' parameter.
884  */
885 typedef struct {
886 	MonoObject  base;
887 	void       *handle;
888 } MonoSafeHandle;
889 
890 /*
891  * Keep in sync with HandleRef.cs
892  */
893 typedef struct {
894 	MonoObject *wrapper;
895 	void       *handle;
896 } MonoHandleRef;
897 
898 extern MonoStats mono_stats;
899 
900 typedef gboolean (*MonoGetCachedClassInfo) (MonoClass *klass, MonoCachedClassInfo *res);
901 
902 typedef gboolean (*MonoGetClassFromName) (MonoImage *image, const char *name_space, const char *name, MonoClass **res);
903 
904 static inline gboolean
method_is_dynamic(MonoMethod * method)905 method_is_dynamic (MonoMethod *method)
906 {
907 #ifdef DISABLE_REFLECTION_EMIT
908 	return FALSE;
909 #else
910 	return method->dynamic;
911 #endif
912 }
913 
914 void
915 mono_classes_init (void);
916 
917 void
918 mono_classes_cleanup (void);
919 
920 void
921 mono_class_layout_fields (MonoClass *klass, int base_instance_size, int packing_size, int real_size, gboolean sre);
922 
923 void
924 mono_class_setup_interface_offsets (MonoClass *klass);
925 
926 void
927 mono_class_setup_vtable_general (MonoClass *klass, MonoMethod **overrides, int onum, GList *in_setup);
928 
929 void
930 mono_class_setup_vtable (MonoClass *klass);
931 
932 void
933 mono_class_setup_methods (MonoClass *klass);
934 
935 void
936 mono_class_setup_mono_type (MonoClass *klass);
937 
938 void
939 mono_class_setup_parent    (MonoClass *klass, MonoClass *parent);
940 
941 MonoMethod*
942 mono_class_get_method_by_index (MonoClass *klass, int index);
943 
944 MonoMethod*
945 mono_class_get_inflated_method (MonoClass *klass, MonoMethod *method);
946 
947 MonoMethod*
948 mono_class_get_vtable_entry (MonoClass *klass, int offset);
949 
950 GPtrArray*
951 mono_class_get_implemented_interfaces (MonoClass *klass, MonoError *error);
952 
953 int
954 mono_class_get_vtable_size (MonoClass *klass);
955 
956 gboolean
957 mono_class_is_open_constructed_type (MonoType *t);
958 
959 gboolean
960 mono_class_get_overrides_full (MonoImage *image, guint32 type_token, MonoMethod ***overrides, gint32 *num_overrides,
961 			       MonoGenericContext *generic_context);
962 
963 MonoMethod*
964 mono_class_get_cctor (MonoClass *klass) MONO_LLVM_INTERNAL;
965 
966 MonoMethod*
967 mono_class_get_finalizer (MonoClass *klass);
968 
969 gboolean
970 mono_class_needs_cctor_run (MonoClass *klass, MonoMethod *caller);
971 
972 gboolean
973 mono_class_field_is_special_static (MonoClassField *field);
974 
975 guint32
976 mono_class_field_get_special_static_type (MonoClassField *field);
977 
978 gboolean
979 mono_class_has_special_static_fields (MonoClass *klass);
980 
981 const char*
982 mono_class_get_field_default_value (MonoClassField *field, MonoTypeEnum *def_type);
983 
984 const char*
985 mono_class_get_property_default_value (MonoProperty *property, MonoTypeEnum *def_type);
986 
987 gpointer
988 mono_lookup_dynamic_token (MonoImage *image, guint32 token, MonoGenericContext *context, MonoError *error);
989 
990 gpointer
991 mono_lookup_dynamic_token_class (MonoImage *image, guint32 token, gboolean check_token, MonoClass **handle_class, MonoGenericContext *context, MonoError *error);
992 
993 gpointer
994 mono_runtime_create_jump_trampoline (MonoDomain *domain, MonoMethod *method, gboolean add_sync_wrapper, MonoError *error);
995 
996 gpointer
997 mono_runtime_create_delegate_trampoline (MonoClass *klass);
998 
999 void
1000 mono_install_get_cached_class_info (MonoGetCachedClassInfo func);
1001 
1002 void
1003 mono_install_get_class_from_name (MonoGetClassFromName func);
1004 
1005 MONO_PROFILER_API MonoGenericContext*
1006 mono_class_get_context (MonoClass *klass);
1007 
1008 MONO_PROFILER_API MonoMethodSignature*
1009 mono_method_signature_checked (MonoMethod *m, MonoError *err);
1010 
1011 MonoGenericContext*
1012 mono_method_get_context_general (MonoMethod *method, gboolean uninflated);
1013 
1014 MONO_PROFILER_API MonoGenericContext*
1015 mono_method_get_context (MonoMethod *method);
1016 
1017 /* Used by monodis, thus cannot be MONO_INTERNAL */
1018 MONO_API MonoGenericContainer*
1019 mono_method_get_generic_container (MonoMethod *method);
1020 
1021 MonoGenericContext*
1022 mono_generic_class_get_context (MonoGenericClass *gclass);
1023 
1024 MonoClass*
1025 mono_generic_class_get_class (MonoGenericClass *gclass);
1026 
1027 void
1028 mono_method_set_generic_container (MonoMethod *method, MonoGenericContainer* container);
1029 
1030 MonoMethod*
1031 mono_class_inflate_generic_method_full (MonoMethod *method, MonoClass *klass_hint, MonoGenericContext *context);
1032 
1033 MonoMethod*
1034 mono_class_inflate_generic_method_full_checked (MonoMethod *method, MonoClass *klass_hint, MonoGenericContext *context, MonoError *error);
1035 
1036 MonoMethod *
1037 mono_class_inflate_generic_method_checked (MonoMethod *method, MonoGenericContext *context, MonoError *error);
1038 
1039 MonoImageSet *
1040 mono_metadata_get_image_set_for_class (MonoClass *klass);
1041 
1042 MonoImageSet *
1043 mono_metadata_get_image_set_for_method (MonoMethodInflated *method);
1044 
1045 MONO_API MonoMethodSignature *
1046 mono_metadata_get_inflated_signature (MonoMethodSignature *sig, MonoGenericContext *context);
1047 
1048 MonoType*
1049 mono_class_inflate_generic_type_with_mempool (MonoImage *image, MonoType *type, MonoGenericContext *context, MonoError *error);
1050 
1051 MonoType*
1052 mono_class_inflate_generic_type_checked (MonoType *type, MonoGenericContext *context, MonoError *error);
1053 
1054 MONO_API void
1055 mono_metadata_free_inflated_signature (MonoMethodSignature *sig);
1056 
1057 MonoMethodSignature*
1058 mono_inflate_generic_signature (MonoMethodSignature *sig, MonoGenericContext *context, MonoError *error);
1059 
1060 typedef struct {
1061 	MonoImage *corlib;
1062 	MonoClass *object_class;
1063 	MonoClass *byte_class;
1064 	MonoClass *void_class;
1065 	MonoClass *boolean_class;
1066 	MonoClass *sbyte_class;
1067 	MonoClass *int16_class;
1068 	MonoClass *uint16_class;
1069 	MonoClass *int32_class;
1070 	MonoClass *uint32_class;
1071 	MonoClass *int_class;
1072 	MonoClass *uint_class;
1073 	MonoClass *int64_class;
1074 	MonoClass *uint64_class;
1075 	MonoClass *single_class;
1076 	MonoClass *double_class;
1077 	MonoClass *char_class;
1078 	MonoClass *string_class;
1079 	MonoClass *enum_class;
1080 	MonoClass *array_class;
1081 	MonoClass *delegate_class;
1082 	MonoClass *multicastdelegate_class;
1083 	MonoClass *asyncresult_class;
1084 	MonoClass *manualresetevent_class;
1085 	MonoClass *typehandle_class;
1086 	MonoClass *fieldhandle_class;
1087 	MonoClass *methodhandle_class;
1088 	MonoClass *systemtype_class;
1089 	MonoClass *runtimetype_class;
1090 	MonoClass *exception_class;
1091 	MonoClass *threadabortexception_class;
1092 	MonoClass *thread_class;
1093 	MonoClass *internal_thread_class;
1094 #ifndef DISABLE_REMOTING
1095 	MonoClass *transparent_proxy_class;
1096 	MonoClass *real_proxy_class;
1097 	MonoClass *marshalbyrefobject_class;
1098 	MonoClass *iremotingtypeinfo_class;
1099 #endif
1100 	MonoClass *mono_method_message_class;
1101 	MonoClass *appdomain_class;
1102 	MonoClass *field_info_class;
1103 	MonoClass *method_info_class;
1104 	MonoClass *stringbuilder_class;
1105 	MonoClass *math_class;
1106 	MonoClass *stack_frame_class;
1107 	MonoClass *stack_trace_class;
1108 	MonoClass *marshal_class;
1109 	MonoClass *typed_reference_class;
1110 	MonoClass *argumenthandle_class;
1111 	MonoClass *monitor_class;
1112 	MonoClass *generic_ilist_class;
1113 	MonoClass *generic_nullable_class;
1114 	MonoClass *handleref_class;
1115 	MonoClass *attribute_class;
1116 	MonoClass *customattribute_data_class;
1117 	MonoClass *critical_finalizer_object; /* MAYBE NULL */
1118 	MonoClass *generic_ireadonlylist_class;
1119 	MonoClass *generic_ienumerator_class;
1120 	MonoClass *threadpool_wait_callback_class;
1121 	MonoMethod *threadpool_perform_wait_callback_method;
1122 } MonoDefaults;
1123 
1124 #ifdef DISABLE_REMOTING
1125 #define mono_class_is_transparent_proxy(klass) (FALSE)
1126 #define mono_class_is_real_proxy(klass) (FALSE)
1127 #else
1128 #define mono_class_is_transparent_proxy(klass) ((klass) == mono_defaults.transparent_proxy_class)
1129 #define mono_class_is_real_proxy(klass) ((klass) == mono_defaults.real_proxy_class)
1130 #endif
1131 
1132 #define mono_object_is_transparent_proxy(object) (mono_class_is_transparent_proxy (mono_object_class (object)))
1133 
1134 
1135 #define GENERATE_GET_CLASS_WITH_CACHE_DECL(shortname) \
1136 MonoClass* mono_class_get_##shortname##_class (void);
1137 
1138 #define GENERATE_TRY_GET_CLASS_WITH_CACHE_DECL(shortname) \
1139 MonoClass* mono_class_try_get_##shortname##_class (void);
1140 
1141 #define GENERATE_GET_CLASS_WITH_CACHE(shortname,name_space,name) \
1142 MonoClass*	\
1143 mono_class_get_##shortname##_class (void)	\
1144 {	\
1145 	static MonoClass *tmp_class;	\
1146 	MonoClass *klass = tmp_class;	\
1147 	if (!klass) {	\
1148 		klass = mono_class_load_from_name (mono_defaults.corlib, name_space, name);	\
1149 		mono_memory_barrier ();	\
1150 		tmp_class = klass;	\
1151 	}	\
1152 	return klass;	\
1153 }
1154 
1155 #define GENERATE_TRY_GET_CLASS_WITH_CACHE(shortname,name_space,name) \
1156 MonoClass*	\
1157 mono_class_try_get_##shortname##_class (void)	\
1158 {	\
1159 	static volatile MonoClass *tmp_class;	\
1160 	static volatile gboolean inited;	\
1161 	MonoClass *klass = (MonoClass *)tmp_class;	\
1162 	mono_memory_barrier ();	\
1163 	if (!inited) {	\
1164 		klass = mono_class_try_load_from_name (mono_defaults.corlib, name_space, name);	\
1165 		tmp_class = klass;	\
1166 		mono_memory_barrier ();	\
1167 		inited = TRUE;	\
1168 	}	\
1169 	return klass;	\
1170 }
1171 
1172 GENERATE_TRY_GET_CLASS_WITH_CACHE_DECL (safehandle)
1173 
1174 #ifndef DISABLE_COM
1175 
1176 GENERATE_GET_CLASS_WITH_CACHE_DECL (interop_proxy)
1177 GENERATE_GET_CLASS_WITH_CACHE_DECL (idispatch)
1178 GENERATE_GET_CLASS_WITH_CACHE_DECL (iunknown)
1179 GENERATE_GET_CLASS_WITH_CACHE_DECL (com_object)
1180 GENERATE_GET_CLASS_WITH_CACHE_DECL (variant)
1181 
1182 #endif
1183 
1184 GENERATE_GET_CLASS_WITH_CACHE_DECL (appdomain_unloaded_exception)
1185 
1186 extern MonoDefaults mono_defaults;
1187 
1188 void
1189 mono_loader_init           (void);
1190 
1191 void
1192 mono_loader_cleanup        (void);
1193 
1194 void
1195 mono_loader_lock           (void) MONO_LLVM_INTERNAL;
1196 
1197 void
1198 mono_loader_unlock         (void) MONO_LLVM_INTERNAL;
1199 
1200 void
1201 mono_loader_lock_track_ownership (gboolean track);
1202 
1203 gboolean
1204 mono_loader_lock_is_owned_by_self (void);
1205 
1206 void
1207 mono_loader_lock_if_inited (void);
1208 
1209 void
1210 mono_loader_unlock_if_inited (void);
1211 
1212 void
1213 mono_reflection_init       (void);
1214 
1215 void
1216 mono_icall_init            (void);
1217 
1218 void
1219 mono_icall_cleanup         (void);
1220 
1221 gpointer
1222 mono_method_get_wrapper_data (MonoMethod *method, guint32 id);
1223 
1224 gboolean
1225 mono_metadata_has_generic_params (MonoImage *image, guint32 token);
1226 
1227 MONO_API MonoGenericContainer *
1228 mono_metadata_load_generic_params (MonoImage *image, guint32 token,
1229 				   MonoGenericContainer *parent_container);
1230 
1231 MONO_API gboolean
1232 mono_metadata_load_generic_param_constraints_checked (MonoImage *image, guint32 token,
1233 					      MonoGenericContainer *container, MonoError *error);
1234 
1235 MonoMethodSignature*
1236 mono_create_icall_signature (const char *sigstr);
1237 
1238 MonoJitICallInfo *
1239 mono_register_jit_icall (gconstpointer func, const char *name, MonoMethodSignature *sig, gboolean is_save);
1240 
1241 MonoJitICallInfo *
1242 mono_register_jit_icall_full (gconstpointer func, const char *name, MonoMethodSignature *sig, gboolean no_wrapper, const char *c_symbol);
1243 
1244 void
1245 mono_register_jit_icall_wrapper (MonoJitICallInfo *info, gconstpointer wrapper);
1246 
1247 MonoJitICallInfo *
1248 mono_find_jit_icall_by_name (const char *name) MONO_LLVM_INTERNAL;
1249 
1250 MonoJitICallInfo *
1251 mono_find_jit_icall_by_addr (gconstpointer addr) MONO_LLVM_INTERNAL;
1252 
1253 GHashTable*
1254 mono_get_jit_icall_info (void);
1255 
1256 const char*
1257 mono_lookup_jit_icall_symbol (const char *name);
1258 
1259 gboolean
1260 mono_class_set_type_load_failure (MonoClass *klass, const char * fmt, ...) MONO_ATTR_FORMAT_PRINTF(2,3);
1261 
1262 MonoException*
1263 mono_class_get_exception_for_failure (MonoClass *klass);
1264 
1265 char*
1266 mono_type_get_name_full (MonoType *type, MonoTypeNameFormat format);
1267 
1268 char*
1269 mono_type_get_full_name (MonoClass *klass);
1270 
1271 char *
1272 mono_method_get_name_full (MonoMethod *method, gboolean signature, gboolean ret, MonoTypeNameFormat format);
1273 
1274 char *
1275 mono_method_get_full_name (MonoMethod *method);
1276 
1277 MonoArrayType *mono_dup_array_type (MonoImage *image, MonoArrayType *a);
1278 MonoMethodSignature *mono_metadata_signature_deep_dup (MonoImage *image, MonoMethodSignature *sig);
1279 
1280 MONO_API void
1281 mono_image_init_name_cache (MonoImage *image);
1282 
1283 gboolean mono_class_is_nullable (MonoClass *klass);
1284 MonoClass *mono_class_get_nullable_param (MonoClass *klass);
1285 
1286 /* object debugging functions, for use inside gdb */
1287 MONO_API void mono_object_describe        (MonoObject *obj);
1288 MONO_API void mono_object_describe_fields (MonoObject *obj);
1289 MONO_API void mono_value_describe_fields  (MonoClass* klass, const char* addr);
1290 MONO_API void mono_class_describe_statics (MonoClass* klass);
1291 
1292 /* method debugging functions, for use inside gdb */
1293 MONO_API void mono_method_print_code (MonoMethod *method);
1294 
1295 MONO_PROFILER_API char *mono_signature_full_name (MonoMethodSignature *sig);
1296 
1297 /*Enum validation related functions*/
1298 MONO_API gboolean
1299 mono_type_is_valid_enum_basetype (MonoType * type);
1300 
1301 MONO_API gboolean
1302 mono_class_is_valid_enum (MonoClass *klass);
1303 
1304 MONO_PROFILER_API gboolean
1305 mono_type_is_primitive (MonoType *type);
1306 
1307 MonoType *
1308 mono_type_get_checked        (MonoImage *image, guint32 type_token, MonoGenericContext *context, MonoError *error);
1309 
1310 gboolean
1311 mono_generic_class_is_generic_type_definition (MonoGenericClass *gklass);
1312 
1313 MonoMethod*
1314 mono_class_get_method_generic (MonoClass *klass, MonoMethod *method);
1315 
1316 MonoType*
1317 mono_type_get_basic_type_from_generic (MonoType *type);
1318 
1319 gboolean
1320 mono_method_can_access_method_full (MonoMethod *method, MonoMethod *called, MonoClass *context_klass);
1321 
1322 gboolean
1323 mono_method_can_access_field_full (MonoMethod *method, MonoClassField *field, MonoClass *context_klass);
1324 
1325 gboolean
1326 mono_class_can_access_class (MonoClass *access_class, MonoClass *target_class);
1327 
1328 MonoClass *
1329 mono_class_get_generic_type_definition (MonoClass *klass);
1330 
1331 gboolean
1332 mono_class_has_parent_and_ignore_generics (MonoClass *klass, MonoClass *parent);
1333 
1334 int
1335 mono_method_get_vtable_slot (MonoMethod *method);
1336 
1337 int
1338 mono_method_get_vtable_index (MonoMethod *method);
1339 
1340 MonoMethod*
1341 mono_method_get_base_method (MonoMethod *method, gboolean definition, MonoError *error);
1342 
1343 MonoMethod*
1344 mono_method_search_in_array_class (MonoClass *klass, const char *name, MonoMethodSignature *sig);
1345 
1346 void
1347 mono_class_setup_interface_id (MonoClass *klass);
1348 
1349 MonoGenericContainer*
1350 mono_class_get_generic_container (MonoClass *klass);
1351 
1352 gpointer
1353 mono_class_alloc (MonoClass *klass, int size);
1354 
1355 gpointer
1356 mono_class_alloc0 (MonoClass *klass, int size);
1357 
1358 void
1359 mono_class_setup_interfaces (MonoClass *klass, MonoError *error);
1360 
1361 MonoClassField*
1362 mono_class_get_field_from_name_full (MonoClass *klass, const char *name, MonoType *type);
1363 
1364 MonoVTable*
1365 mono_class_vtable_full (MonoDomain *domain, MonoClass *klass, MonoError *error);
1366 
1367 gboolean
1368 mono_class_is_assignable_from_slow (MonoClass *target, MonoClass *candidate);
1369 
1370 gboolean
1371 mono_class_has_variant_generic_params (MonoClass *klass);
1372 
1373 gboolean
1374 mono_class_is_variant_compatible (MonoClass *klass, MonoClass *oklass, gboolean check_for_reference_conv);
1375 
1376 gboolean mono_is_corlib_image (MonoImage *image);
1377 
1378 MonoType*
1379 mono_field_get_type_checked (MonoClassField *field, MonoError *error);
1380 
1381 MonoClassField*
1382 mono_class_get_fields_lazy (MonoClass* klass, gpointer *iter);
1383 
1384 gboolean
1385 mono_class_check_vtable_constraints (MonoClass *klass, GList *in_setup);
1386 
1387 gboolean
1388 mono_class_has_finalizer (MonoClass *klass);
1389 
1390 void
1391 mono_unload_interface_id (MonoClass *klass);
1392 
1393 GPtrArray*
1394 mono_class_get_methods_by_name (MonoClass *klass, const char *name, guint32 bflags, gboolean ignore_case, gboolean allow_ctors, MonoError *error);
1395 
1396 char*
1397 mono_class_full_name (MonoClass *klass);
1398 
1399 MonoClass*
1400 mono_class_inflate_generic_class_checked (MonoClass *gklass, MonoGenericContext *context, MonoError *error);
1401 
1402 MonoClass *
1403 mono_class_get_checked (MonoImage *image, guint32 type_token, MonoError *error);
1404 
1405 MonoClass *
1406 mono_class_get_and_inflate_typespec_checked (MonoImage *image, guint32 type_token, MonoGenericContext *context, MonoError *error);
1407 
1408 MonoClass *
1409 mono_class_from_name_checked (MonoImage *image, const char* name_space, const char *name, MonoError *error);
1410 
1411 MonoClass *
1412 mono_class_from_name_case_checked (MonoImage *image, const char* name_space, const char *name, MonoError *error);
1413 
1414 MonoClassField*
1415 mono_field_from_token_checked (MonoImage *image, uint32_t token, MonoClass **retklass, MonoGenericContext *context, MonoError *error);
1416 
1417 gpointer
1418 mono_ldtoken_checked (MonoImage *image, guint32 token, MonoClass **handle_class, MonoGenericContext *context, MonoError *error);
1419 
1420 MonoClass *
1421 mono_class_from_generic_parameter_internal (MonoGenericParam *param);
1422 
1423 MonoImage *
1424 get_image_for_generic_param (MonoGenericParam *param);
1425 
1426 char *
1427 make_generic_name_string (MonoImage *image, int num);
1428 
1429 MonoClass *
1430 mono_class_load_from_name (MonoImage *image, const char* name_space, const char *name) MONO_LLVM_INTERNAL;
1431 
1432 MonoClass*
1433 mono_class_try_load_from_name (MonoImage *image, const char* name_space, const char *name);
1434 
1435 void
1436 mono_error_set_for_class_failure (MonoError *orerror, const MonoClass *klass);
1437 
1438 gboolean
1439 mono_class_has_failure (const MonoClass *klass);
1440 
1441 /* Kind specific accessors */
1442 MonoGenericClass*
1443 mono_class_get_generic_class (MonoClass *klass);
1444 
1445 MonoGenericClass*
1446 mono_class_try_get_generic_class (MonoClass *klass);
1447 
1448 void
1449 mono_class_set_flags (MonoClass *klass, guint32 flags);
1450 
1451 MonoGenericContainer*
1452 mono_class_try_get_generic_container (MonoClass *klass);
1453 
1454 void
1455 mono_class_set_generic_container (MonoClass *klass, MonoGenericContainer *container);
1456 
1457 MonoType*
1458 mono_class_gtd_get_canonical_inst (MonoClass *klass);
1459 
1460 guint32
1461 mono_class_get_first_method_idx (MonoClass *klass);
1462 
1463 void
1464 mono_class_set_first_method_idx (MonoClass *klass, guint32 idx);
1465 
1466 guint32
1467 mono_class_get_first_field_idx (MonoClass *klass);
1468 
1469 void
1470 mono_class_set_first_field_idx (MonoClass *klass, guint32 idx);
1471 
1472 guint32
1473 mono_class_get_method_count (MonoClass *klass);
1474 
1475 void
1476 mono_class_set_method_count (MonoClass *klass, guint32 count);
1477 
1478 guint32
1479 mono_class_get_field_count (MonoClass *klass);
1480 
1481 void
1482 mono_class_set_field_count (MonoClass *klass, guint32 count);
1483 
1484 MonoMarshalType*
1485 mono_class_get_marshal_info (MonoClass *klass);
1486 
1487 void
1488 mono_class_set_marshal_info (MonoClass *klass, MonoMarshalType *marshal_info);
1489 
1490 guint32
1491 mono_class_get_ref_info_handle (MonoClass *klass);
1492 
1493 guint32
1494 mono_class_set_ref_info_handle (MonoClass *klass, guint32 value);
1495 
1496 MonoErrorBoxed*
1497 mono_class_get_exception_data (MonoClass *klass);
1498 
1499 void
1500 mono_class_set_exception_data (MonoClass *klass, MonoErrorBoxed *value);
1501 
1502 GList*
1503 mono_class_get_nested_classes_property (MonoClass *klass);
1504 
1505 void
1506 mono_class_set_nested_classes_property (MonoClass *klass, GList *value);
1507 
1508 MonoClassPropertyInfo*
1509 mono_class_get_property_info (MonoClass *klass);
1510 
1511 void
1512 mono_class_set_property_info (MonoClass *klass, MonoClassPropertyInfo *info);
1513 
1514 MonoClassEventInfo*
1515 mono_class_get_event_info (MonoClass *klass);
1516 
1517 void
1518 mono_class_set_event_info (MonoClass *klass, MonoClassEventInfo *info);
1519 
1520 MonoFieldDefaultValue*
1521 mono_class_get_field_def_values (MonoClass *klass);
1522 
1523 void
1524 mono_class_set_field_def_values (MonoClass *klass, MonoFieldDefaultValue *values);
1525 
1526 guint32
1527 mono_class_get_declsec_flags (MonoClass *klass);
1528 
1529 void
1530 mono_class_set_declsec_flags (MonoClass *klass, guint32 value);
1531 
1532 void
1533 mono_class_set_is_com_object (MonoClass *klass);
1534 
1535 void
1536 mono_class_set_weak_bitmap (MonoClass *klass, int nbits, gsize *bits);
1537 
1538 gsize*
1539 mono_class_get_weak_bitmap (MonoClass *klass, int *nbits);
1540 
1541 /*Now that everything has been defined, let's include the inline functions */
1542 #include <mono/metadata/class-inlines.h>
1543 
1544 #endif /* __MONO_METADATA_CLASS_INTERNALS_H__ */
1545