[runtime] Store implmap_idx as a guint32 to avoid overflows if the implmap table...
[mono.git] / mono / metadata / class-internals.h
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
332         MonoClass  *parent;
333         MonoClass  *nested_in;
334
335         MonoImage *image;
336         const char *name;
337         const char *name_space;
338
339         guint32    type_token;
340         int        vtable_size; /* number of slots */
341
342         guint16     interface_count;
343         guint32     interface_id;        /* unique inderface id (for interfaces) */
344         guint32     max_interface_id;
345         
346         guint16     interface_offsets_count;
347         MonoClass **interfaces_packed;
348         guint16    *interface_offsets_packed;
349 /* enabled only with small config for now: we might want to do it unconditionally */
350 #ifdef MONO_SMALL_CONFIG
351 #define COMPRESSED_INTERFACE_BITMAP 1
352 #endif
353         guint8     *interface_bitmap;
354
355         MonoClass **interfaces;
356
357         union {
358                 int class_size; /* size of area for static fields */
359                 int element_size; /* for array types */
360                 int generic_param_token; /* for generic param types, both var and mvar */
361         } sizes;
362
363         /*
364          * Field information: Type and location from object base
365          */
366         MonoClassField *fields;
367
368         MonoMethod **methods;
369
370         /* used as the type of the this argument and when passing the arg by value */
371         MonoType this_arg;
372         MonoType byval_arg;
373
374         MonoGCDescriptor gc_descr;
375
376         MonoClassRuntimeInfo *runtime_info;
377
378         /* Generic vtable. Initialized by a call to mono_class_setup_vtable () */
379         MonoMethod **vtable;
380
381         /* Infrequently used items. See class-accessors.c: InfrequentDataKind for what goes into here. */
382         MonoPropertyBag infrequent_data;
383 };
384
385 typedef struct {
386         MonoClass class;
387         guint32 flags;
388         /*
389          * From the TypeDef table
390          */
391         guint32 first_method_idx;
392         guint32 first_field_idx;
393         guint32 method_count, field_count;
394         /* next element in the class_cache hash list (in MonoImage) */
395         MonoClass *next_class_cache;
396 } MonoClassDef;
397
398 typedef struct {
399         MonoClassDef class;
400         MonoGenericContainer *generic_container;
401         /* The canonical GENERICINST where we instantiate a generic type definition with its own generic parameters.*/
402         /* Suppose we have class T`2<A,B> {...}.  canonical_inst is the GTD T`2 applied to A and B. */
403         MonoType canonical_inst;
404 } MonoClassGtd;
405
406 typedef struct {
407         MonoClass class;
408         MonoGenericClass *generic_class;
409 } MonoClassGenericInst;
410
411 typedef struct {
412         MonoClass class;
413 } MonoClassGenericParam;
414
415 typedef struct {
416         MonoClass class;
417         guint32 method_count;
418 } MonoClassArray;
419
420 typedef struct {
421         MonoClass class;
422 } MonoClassPointer;
423
424 #ifdef COMPRESSED_INTERFACE_BITMAP
425 int mono_compress_bitmap (uint8_t *dest, const uint8_t *bitmap, int size);
426 int mono_class_interface_match (const uint8_t *bitmap, int id);
427 #else
428 #define mono_class_interface_match(bmap,uiid) ((bmap) [(uiid) >> 3] & (1 << ((uiid)&7)))
429 #endif
430
431 #define MONO_CLASS_IMPLEMENTS_INTERFACE(k,uiid) (((uiid) <= (k)->max_interface_id) && mono_class_interface_match ((k)->interface_bitmap, (uiid)))
432
433 #define MONO_VTABLE_AVAILABLE_GC_BITS 4
434
435 #ifdef DISABLE_REMOTING
436 #define mono_class_is_marshalbyref(klass) (FALSE)
437 #define mono_class_is_contextbound(klass) (FALSE)
438 #define mono_vtable_is_remote(vtable) (FALSE)
439 #define mono_vtable_set_is_remote(vtable,enable) do {} while (0)
440 #else
441 #define mono_class_is_marshalbyref(klass) ((klass)->marshalbyref)
442 #define mono_class_is_contextbound(klass) ((klass)->contextbound)
443 #define mono_vtable_is_remote(vtable) ((vtable)->remote)
444 #define mono_vtable_set_is_remote(vtable,enable) do { (vtable)->remote = enable ? 1 : 0; } while (0)
445 #endif
446
447 #ifdef DISABLE_COM
448 #define mono_class_is_com_object(klass) (FALSE)
449 #else
450 #define mono_class_is_com_object(klass) ((klass)->is_com_object)
451 #endif
452
453
454 MONO_API int mono_class_interface_offset (MonoClass *klass, MonoClass *itf);
455 int mono_class_interface_offset_with_variance (MonoClass *klass, MonoClass *itf, gboolean *non_exact_match);
456
457 typedef gpointer MonoRuntimeGenericContext;
458
459 /* the interface_offsets array is stored in memory before this struct */
460 struct MonoVTable {
461         MonoClass  *klass;
462          /*
463          * According to comments in gc_gcj.h, this should be the second word in
464          * the vtable.
465          */
466         MonoGCDescriptor gc_descr;
467         MonoDomain *domain;  /* each object/vtable belongs to exactly one domain */
468         gpointer    type; /* System.Type type for klass */
469         guint8     *interface_bitmap;
470         guint32     max_interface_id;
471         guint8      rank;
472         /* Keep this a guint8, the jit depends on it */
473         guint8      initialized; /* cctor has been run */
474         guint remote          : 1; /* class is remotely activated */
475         guint init_failed     : 1; /* cctor execution failed */
476         guint has_static_fields : 1; /* pointer to the data stored at the end of the vtable array */
477         guint gc_bits         : MONO_VTABLE_AVAILABLE_GC_BITS; /* Those bits are reserved for the usaged of the GC */
478
479         guint32     imt_collisions_bitmap;
480         MonoRuntimeGenericContext *runtime_generic_context;
481         /* do not add any fields after vtable, the structure is dynamically extended */
482         /* vtable contains function pointers to methods or their trampolines, at the
483          end there may be a slot containing the pointer to the static fields */
484         gpointer    vtable [MONO_ZERO_LEN_ARRAY];       
485 };
486
487 #define MONO_SIZEOF_VTABLE (sizeof (MonoVTable) - MONO_ZERO_LEN_ARRAY * SIZEOF_VOID_P)
488
489 #define MONO_VTABLE_IMPLEMENTS_INTERFACE(vt,uiid) (((uiid) <= (vt)->max_interface_id) && mono_class_interface_match ((vt)->interface_bitmap, (uiid)))
490
491 /*
492  * Generic instantiation data type encoding.
493  */
494
495 /*
496  * A particular generic instantiation:
497  *
498  * All instantiations are cached and we don't distinguish between class and method
499  * instantiations here.
500  */
501 struct _MonoGenericInst {
502 #ifndef MONO_SMALL_CONFIG
503         gint32 id;                      /* unique ID for debugging */
504 #endif
505         guint type_argc    : 22;        /* number of type arguments */
506         guint is_open      :  1;        /* if this is an open type */
507         MonoType *type_argv [MONO_ZERO_LEN_ARRAY];
508 };
509
510 #define MONO_SIZEOF_GENERIC_INST (sizeof (MonoGenericInst) - MONO_ZERO_LEN_ARRAY * SIZEOF_VOID_P)
511 /*
512  * The generic context: an instantiation of a set of class and method generic parameters.
513  *
514  * NOTE: Never allocate this directly on the heap.  It have to be either allocated on the stack,
515  *       or embedded within other objects.  Don't store pointers to this, because it may be on the stack.
516  *       If you really have to, ensure you store a pointer to the embedding object along with it.
517  */
518 struct _MonoGenericContext {
519         /* The instantiation corresponding to the class generic parameters */
520         MonoGenericInst *class_inst;
521         /* The instantiation corresponding to the method generic parameters */
522         MonoGenericInst *method_inst;
523 };
524
525 /*
526  * Inflated generic method.
527  */
528 struct _MonoMethodInflated {
529         union {
530                 MonoMethod method;
531                 MonoMethodPInvoke pinvoke;
532         } method;
533         MonoMethod *declaring;          /* the generic method definition. */
534         MonoGenericContext context;     /* The current instantiation */
535         MonoImageSet *owner; /* The image set that the inflated method belongs to. */
536 };
537
538 /*
539  * A particular instantiation of a generic type.
540  */
541 struct _MonoGenericClass {
542         MonoClass *container_class;     /* the generic type definition */
543         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 */
544         guint is_dynamic  : 1;          /* Contains dynamic types */
545         guint is_tb_open  : 1;          /* This is the fully open instantiation for a type_builder. Quite ugly, but it's temporary.*/
546         guint need_sync   : 1;      /* Only if dynamic. Need to be synchronized with its container class after its finished. */
547         MonoClass *cached_class;        /* if present, the MonoClass corresponding to the instantiation.  */
548
549         /* 
550          * The image set which owns this generic class. Memory owned by the generic class
551          * including cached_class should be allocated from the mempool of the image set,
552          * so it is easy to free.
553          */
554         MonoImageSet *owner;
555 };
556
557 /*
558  * A type parameter.
559  */
560 struct _MonoGenericParam {
561         /*
562          * Type or method this parameter was defined in.
563          */
564         MonoGenericContainer *owner;
565         guint16 num;
566         /*
567          * If != NULL, this is a generated generic param used by the JIT to implement generic
568          * sharing.
569          */
570         MonoType *gshared_constraint;
571 };
572
573 /* Additional details about a MonoGenericParam */
574 /* Keep in sync with managed Mono.RuntimeStructs.GenericParamInfo */
575 typedef struct {
576         MonoClass *pklass;              /* The corresponding `MonoClass'. */
577         const char *name;
578
579         // See GenericParameterAttributes
580         guint16 flags;
581
582         guint32 token;
583
584         // Constraints on type parameters
585         MonoClass** constraints; /* NULL means end of list */
586 } MonoGenericParamInfo;
587
588 typedef struct {
589         MonoGenericParam param;
590         MonoGenericParamInfo info;
591 } MonoGenericParamFull;
592
593 /*
594  * The generic container.
595  *
596  * Stores the type parameters of a generic type definition or a generic method definition.
597  */
598 struct _MonoGenericContainer {
599         MonoGenericContext context;
600         /* If we're a generic method definition in a generic type definition,
601            the generic container of the containing class. */
602         MonoGenericContainer *parent;
603         /* the generic type definition or the generic method definition corresponding to this container */
604         /* Union rules: If is_anonymous, image field is valid; else if is_method, method field is valid; else klass is valid. */
605         union {
606                 MonoClass *klass;
607                 MonoMethod *method;
608                 MonoImage *image;
609         } owner;
610         int type_argc    : 29; // Per the ECMA spec, this value is capped at 16 bits
611         /* If true, we're a generic method, otherwise a generic type definition. */
612         /* Invariant: parent != NULL => is_method */
613         int is_method     : 1;
614         /* If true, this container has no associated class/method and only the image is known. This can happen:
615            1. For the special anonymous containers kept by MonoImage.
616            2. During container creation via the mono_metadata_load_generic_params path-- in this case the caller
617               sets the owner, so temporarily while load_generic_params is completing the container is anonymous.
618            3. When user code creates a generic parameter via SRE, but has not yet set an owner. */
619         int is_anonymous : 1;
620         /* If false, all params in this container are full-size. If true, all params are just param structs. */
621         /* This field is always == to the is_anonymous field, except in "temporary" cases (2) and (3) above. */
622         /* TODO: Merge GenericParam and GenericParamFull, remove this field. Benefit is marginal. */
623         int is_small_param : 1;
624         /* Our type parameters. */
625         MonoGenericParamFull *type_params;
626 };
627
628 static inline MonoGenericParam *
629 mono_generic_container_get_param (MonoGenericContainer *gc, int i)
630 {
631         return (MonoGenericParam *) &gc->type_params [i];
632 }
633
634 static inline MonoGenericParamInfo *
635 mono_generic_container_get_param_info (MonoGenericContainer *gc, int i)
636 {
637         return &gc->type_params [i].info;
638 }
639
640 static inline MonoGenericContainer *
641 mono_generic_param_owner (MonoGenericParam *p)
642 {
643         return p->owner;
644 }
645
646 static inline int
647 mono_generic_param_num (MonoGenericParam *p)
648 {
649         return p->num;
650 }
651
652 static inline gboolean
653 mono_generic_param_is_fullsize (MonoGenericParam *p)
654 {
655         return !mono_generic_param_owner (p)->is_small_param;
656 }
657
658 static inline MonoGenericParamInfo *
659 mono_generic_param_info (MonoGenericParam *p)
660 {
661         if (mono_generic_param_is_fullsize (p))
662                 return &((MonoGenericParamFull *) p)->info;
663         return NULL;
664 }
665
666 static inline const char *
667 mono_generic_param_name (MonoGenericParam *p)
668 {
669         if (mono_generic_param_is_fullsize (p))
670                 return ((MonoGenericParamFull *) p)->info.name;
671         return NULL;
672 }
673
674 static inline MonoGenericContainer *
675 mono_type_get_generic_param_owner (MonoType *t)
676 {
677         return mono_generic_param_owner (t->data.generic_param);
678 }
679
680 static inline int
681 mono_type_get_generic_param_num (MonoType *t)
682 {
683         return mono_generic_param_num (t->data.generic_param);
684 }
685
686 /*
687  * Class information which might be cached by the runtime in the AOT file for
688  * example. Caching this allows us to avoid computing a generic vtable
689  * (class->vtable) in most cases, saving time and avoiding creation of lots of
690  * MonoMethod structures.
691  */
692 typedef struct MonoCachedClassInfo {
693         guint32 vtable_size;
694         guint has_finalize : 1;
695         guint ghcimpl : 1;
696         guint has_cctor : 1;
697         guint has_nested_classes : 1;
698         guint blittable : 1;
699         guint has_references : 1;
700         guint has_static_refs : 1;
701         guint no_special_static_fields : 1;
702         guint is_generic_container : 1;
703         guint32 cctor_token;
704         MonoImage *finalize_image;
705         guint32 finalize_token;
706         guint32 instance_size;
707         guint32 class_size;
708         guint32 packing_size;
709         guint32 min_align;
710 } MonoCachedClassInfo;
711
712 typedef struct {
713         const char *name;
714         gconstpointer func;
715         gconstpointer wrapper;
716         gconstpointer trampoline;
717         MonoMethodSignature *sig;
718         const char *c_symbol;
719         MonoMethod *wrapper_method;
720         gboolean no_raise;
721 } MonoJitICallInfo;
722
723 void
724 mono_class_setup_supertypes (MonoClass *klass);
725
726 void
727 mono_class_setup_fields (MonoClass *klass);
728
729 /* WARNING
730  * Only call this function if you can ensure both @klass and @parent
731  * have supertype information initialized.
732  * This can be accomplished by mono_class_setup_supertypes or mono_class_init.
733  * If unsure, use mono_class_has_parent.
734  */
735 static inline gboolean
736 mono_class_has_parent_fast (MonoClass *klass, MonoClass *parent)
737 {
738         return (klass->idepth >= parent->idepth) && (klass->supertypes [parent->idepth - 1] == parent);
739 }
740
741 static inline gboolean
742 mono_class_has_parent (MonoClass *klass, MonoClass *parent)
743 {
744         if (G_UNLIKELY (!klass->supertypes))
745                 mono_class_setup_supertypes (klass);
746
747         if (G_UNLIKELY (!parent->supertypes))
748                 mono_class_setup_supertypes (parent);
749
750         return mono_class_has_parent_fast (klass, parent);
751 }
752
753 typedef struct {
754         MonoVTable *default_vtable;
755         MonoVTable *xdomain_vtable;
756         MonoClass *proxy_class;
757         char* proxy_class_name;
758         uint32_t interface_count;
759         MonoClass *interfaces [MONO_ZERO_LEN_ARRAY];
760 } MonoRemoteClass;
761
762 #define MONO_SIZEOF_REMOTE_CLASS (sizeof (MonoRemoteClass) - MONO_ZERO_LEN_ARRAY * SIZEOF_VOID_P)
763
764 typedef struct {
765         gint32 initialized_class_count;
766         gint32 generic_vtable_count;
767         gint32 used_class_count;
768         gint32 method_count;
769         gint32 class_vtable_size;
770         gint32 class_static_data_size;
771         gint32 generic_class_count;
772         gint32 inflated_method_count;
773         gint32 inflated_type_count;
774         gint32 delegate_creations;
775         gint32 imt_tables_size;
776         gint32 imt_number_of_tables;
777         gint32 imt_number_of_methods;
778         gint32 imt_used_slots;
779         gint32 imt_slots_with_collisions;
780         gint32 imt_max_collisions_in_slot;
781         gint32 imt_method_count_when_max_collisions;
782         gint32 imt_trampolines_size;
783         gint32 jit_info_table_insert_count;
784         gint32 jit_info_table_remove_count;
785         gint32 jit_info_table_lookup_count;
786         gint32 generics_sharable_methods;
787         gint32 generics_unsharable_methods;
788         gint32 generics_shared_methods;
789         gint32 gsharedvt_methods;
790         gboolean enabled;
791 } MonoStats;
792
793 /* 
794  * new structure to hold performace counters values that are exported
795  * to managed code.
796  * Note: never remove fields from this structure and only add them to the end.
797  * Size of fields and type should not be changed as well.
798  */
799 typedef struct {
800         /* JIT category */
801         gint32 jit_methods;
802         gint32 jit_bytes;
803         gint32 jit_time;
804         gint32 jit_failures;
805         /* Exceptions category */
806         gint32 exceptions_thrown;
807         gint32 exceptions_filters;
808         gint32 exceptions_finallys;
809         gint32 exceptions_depth;
810         gint32 aspnet_requests_queued;
811         gint32 aspnet_requests;
812         /* Memory category */
813         gint32 gc_collections0;
814         gint32 gc_collections1;
815         gint32 gc_collections2;
816         gint32 gc_promotions0;
817         gint32 gc_promotions1;
818         gint32 gc_promotion_finalizers;
819         gint64 gc_gen0size;
820         gint64 gc_gen1size;
821         gint64 gc_gen2size;
822         gint32 gc_lossize;
823         gint32 gc_fin_survivors;
824         gint32 gc_num_handles;
825         gint32 gc_allocated;
826         gint32 gc_induced;
827         gint32 gc_time;
828         gint64 gc_total_bytes;
829         gint64 gc_committed_bytes;
830         gint64 gc_reserved_bytes;
831         gint32 gc_num_pinned;
832         gint32 gc_sync_blocks;
833         /* Remoting category */
834         gint32 remoting_calls;
835         gint32 remoting_channels;
836         gint32 remoting_proxies;
837         gint32 remoting_classes;
838         gint32 remoting_objects;
839         gint32 remoting_contexts;
840         /* Loader category */
841         gint32 loader_classes;
842         gint32 loader_total_classes;
843         gint32 loader_appdomains;
844         gint32 loader_total_appdomains;
845         gint32 loader_assemblies;
846         gint32 loader_total_assemblies;
847         gint32 loader_failures;
848         gint32 loader_bytes;
849         gint32 loader_appdomains_uloaded;
850         /* Threads and Locks category  */
851         gint32 thread_contentions;
852         gint32 thread_queue_len;
853         gint32 thread_queue_max;
854         gint32 thread_num_logical;
855         gint32 thread_num_physical;
856         gint32 thread_cur_recognized;
857         gint32 thread_num_recognized;
858         /* Interop category */
859         gint32 interop_num_ccw;
860         gint32 interop_num_stubs;
861         gint32 interop_num_marshals;
862         /* Security category */
863         gint32 security_num_checks;
864         gint32 security_num_link_checks;
865         gint32 security_time;
866         gint32 security_depth;
867         gint32 unused;
868         /* Threadpool */
869         gint64 threadpool_workitems;
870         gint64 threadpool_ioworkitems;
871         gint32 threadpool_threads;
872         gint32 threadpool_iothreads;
873 } MonoPerfCounters;
874
875 extern MonoPerfCounters *mono_perfcounters;
876
877 MONO_API void mono_perfcounters_init (void);
878
879 /*
880  * The definition of the first field in SafeHandle,
881  * Keep in sync with SafeHandle.cs, this is only used
882  * to access the `handle' parameter.
883  */
884 typedef struct {
885         MonoObject  base;
886         void       *handle;
887 } MonoSafeHandle;
888
889 /*
890  * Keep in sync with HandleRef.cs
891  */
892 typedef struct {
893         MonoObject *wrapper;
894         void       *handle;
895 } MonoHandleRef;
896
897 extern MonoStats mono_stats;
898
899 typedef gboolean (*MonoGetCachedClassInfo) (MonoClass *klass, MonoCachedClassInfo *res);
900
901 typedef gboolean (*MonoGetClassFromName) (MonoImage *image, const char *name_space, const char *name, MonoClass **res);
902
903 static inline gboolean
904 method_is_dynamic (MonoMethod *method)
905 {
906 #ifdef DISABLE_REFLECTION_EMIT
907         return FALSE;
908 #else
909         return method->dynamic;
910 #endif
911 }
912
913 void
914 mono_classes_init (void);
915
916 void
917 mono_classes_cleanup (void);
918
919 void
920 mono_class_layout_fields (MonoClass *klass, int base_instance_size, int packing_size, gboolean sre);
921
922 void
923 mono_class_setup_interface_offsets (MonoClass *klass);
924
925 void
926 mono_class_setup_vtable_general (MonoClass *klass, MonoMethod **overrides, int onum, GList *in_setup);
927
928 void
929 mono_class_setup_vtable (MonoClass *klass);
930
931 void
932 mono_class_setup_methods (MonoClass *klass);
933
934 void
935 mono_class_setup_mono_type (MonoClass *klass);
936
937 void
938 mono_class_setup_parent    (MonoClass *klass, MonoClass *parent);
939
940 MonoMethod*
941 mono_class_get_method_by_index (MonoClass *klass, int index);
942
943 MonoMethod*
944 mono_class_get_inflated_method (MonoClass *klass, MonoMethod *method);
945
946 MonoMethod*
947 mono_class_get_vtable_entry (MonoClass *klass, int offset);
948
949 GPtrArray*
950 mono_class_get_implemented_interfaces (MonoClass *klass, MonoError *error);
951
952 int
953 mono_class_get_vtable_size (MonoClass *klass);
954
955 gboolean
956 mono_class_is_open_constructed_type (MonoType *t);
957
958 gboolean
959 mono_class_get_overrides_full (MonoImage *image, guint32 type_token, MonoMethod ***overrides, gint32 *num_overrides,
960                                MonoGenericContext *generic_context);
961
962 MonoMethod*
963 mono_class_get_cctor (MonoClass *klass) MONO_LLVM_INTERNAL;
964
965 MonoMethod*
966 mono_class_get_finalizer (MonoClass *klass);
967
968 gboolean
969 mono_class_needs_cctor_run (MonoClass *klass, MonoMethod *caller);
970
971 gboolean
972 mono_class_field_is_special_static (MonoClassField *field);
973
974 guint32
975 mono_class_field_get_special_static_type (MonoClassField *field);
976
977 gboolean
978 mono_class_has_special_static_fields (MonoClass *klass);
979
980 const char*
981 mono_class_get_field_default_value (MonoClassField *field, MonoTypeEnum *def_type);
982
983 const char*
984 mono_class_get_property_default_value (MonoProperty *property, MonoTypeEnum *def_type);
985
986 gpointer
987 mono_lookup_dynamic_token (MonoImage *image, guint32 token, MonoGenericContext *context, MonoError *error);
988
989 gpointer
990 mono_lookup_dynamic_token_class (MonoImage *image, guint32 token, gboolean check_token, MonoClass **handle_class, MonoGenericContext *context, MonoError *error);
991
992 gpointer
993 mono_runtime_create_jump_trampoline (MonoDomain *domain, MonoMethod *method, gboolean add_sync_wrapper, MonoError *error);
994
995 gpointer
996 mono_runtime_create_delegate_trampoline (MonoClass *klass);
997
998 void
999 mono_install_get_cached_class_info (MonoGetCachedClassInfo func);
1000
1001 void
1002 mono_install_get_class_from_name (MonoGetClassFromName func);
1003
1004 MONO_PROFILER_API MonoGenericContext*
1005 mono_class_get_context (MonoClass *klass);
1006
1007 MONO_PROFILER_API MonoMethodSignature*
1008 mono_method_signature_checked (MonoMethod *m, MonoError *err);
1009
1010 MonoGenericContext*
1011 mono_method_get_context_general (MonoMethod *method, gboolean uninflated);
1012
1013 MONO_PROFILER_API MonoGenericContext*
1014 mono_method_get_context (MonoMethod *method);
1015
1016 /* Used by monodis, thus cannot be MONO_INTERNAL */
1017 MONO_API MonoGenericContainer*
1018 mono_method_get_generic_container (MonoMethod *method);
1019
1020 MonoGenericContext*
1021 mono_generic_class_get_context (MonoGenericClass *gclass);
1022
1023 MonoClass*
1024 mono_generic_class_get_class (MonoGenericClass *gclass);
1025
1026 void
1027 mono_method_set_generic_container (MonoMethod *method, MonoGenericContainer* container);
1028
1029 MonoMethod*
1030 mono_class_inflate_generic_method_full (MonoMethod *method, MonoClass *klass_hint, MonoGenericContext *context);
1031
1032 MonoMethod*
1033 mono_class_inflate_generic_method_full_checked (MonoMethod *method, MonoClass *klass_hint, MonoGenericContext *context, MonoError *error);
1034
1035 MonoMethod *
1036 mono_class_inflate_generic_method_checked (MonoMethod *method, MonoGenericContext *context, MonoError *error);
1037
1038 MonoImageSet *
1039 mono_metadata_get_image_set_for_method (MonoMethodInflated *method);
1040
1041 MONO_API MonoMethodSignature *
1042 mono_metadata_get_inflated_signature (MonoMethodSignature *sig, MonoGenericContext *context);
1043
1044 MonoType*
1045 mono_class_inflate_generic_type_with_mempool (MonoImage *image, MonoType *type, MonoGenericContext *context, MonoError *error);
1046
1047 MonoType*
1048 mono_class_inflate_generic_type_checked (MonoType *type, MonoGenericContext *context, MonoError *error);
1049
1050 MONO_API void
1051 mono_metadata_free_inflated_signature (MonoMethodSignature *sig);
1052
1053 MonoMethodSignature*
1054 mono_inflate_generic_signature (MonoMethodSignature *sig, MonoGenericContext *context, MonoError *error);
1055
1056 typedef struct {
1057         MonoImage *corlib;
1058         MonoClass *object_class;
1059         MonoClass *byte_class;
1060         MonoClass *void_class;
1061         MonoClass *boolean_class;
1062         MonoClass *sbyte_class;
1063         MonoClass *int16_class;
1064         MonoClass *uint16_class;
1065         MonoClass *int32_class;
1066         MonoClass *uint32_class;
1067         MonoClass *int_class;
1068         MonoClass *uint_class;
1069         MonoClass *int64_class;
1070         MonoClass *uint64_class;
1071         MonoClass *single_class;
1072         MonoClass *double_class;
1073         MonoClass *char_class;
1074         MonoClass *string_class;
1075         MonoClass *enum_class;
1076         MonoClass *array_class;
1077         MonoClass *delegate_class;
1078         MonoClass *multicastdelegate_class;
1079         MonoClass *asyncresult_class;
1080         MonoClass *manualresetevent_class;
1081         MonoClass *typehandle_class;
1082         MonoClass *fieldhandle_class;
1083         MonoClass *methodhandle_class;
1084         MonoClass *systemtype_class;
1085         MonoClass *runtimetype_class;
1086         MonoClass *exception_class;
1087         MonoClass *threadabortexception_class;
1088         MonoClass *thread_class;
1089         MonoClass *internal_thread_class;
1090 #ifndef DISABLE_REMOTING
1091         MonoClass *transparent_proxy_class;
1092         MonoClass *real_proxy_class;
1093         MonoClass *marshalbyrefobject_class;
1094         MonoClass *iremotingtypeinfo_class;
1095 #endif
1096         MonoClass *mono_method_message_class;
1097         MonoClass *appdomain_class;
1098         MonoClass *field_info_class;
1099         MonoClass *method_info_class;
1100         MonoClass *stringbuilder_class;
1101         MonoClass *math_class;
1102         MonoClass *stack_frame_class;
1103         MonoClass *stack_trace_class;
1104         MonoClass *marshal_class;
1105         MonoClass *typed_reference_class;
1106         MonoClass *argumenthandle_class;
1107         MonoClass *monitor_class;
1108         MonoClass *generic_ilist_class;
1109         MonoClass *generic_nullable_class;
1110         MonoClass *handleref_class;
1111         MonoClass *attribute_class;
1112         MonoClass *customattribute_data_class;
1113         MonoClass *critical_finalizer_object; /* MAYBE NULL */
1114         MonoClass *generic_ireadonlylist_class;
1115         MonoClass *threadpool_wait_callback_class;
1116         MonoMethod *threadpool_perform_wait_callback_method;
1117 } MonoDefaults;
1118
1119 #ifdef DISABLE_REMOTING
1120 #define mono_class_is_transparent_proxy(klass) (FALSE)
1121 #define mono_class_is_real_proxy(klass) (FALSE)
1122 #else
1123 #define mono_class_is_transparent_proxy(klass) ((klass) == mono_defaults.transparent_proxy_class)
1124 #define mono_class_is_real_proxy(klass) ((klass) == mono_defaults.real_proxy_class)
1125 #endif
1126
1127 #define mono_object_is_transparent_proxy(object) (mono_class_is_transparent_proxy (mono_object_class (object)))
1128
1129
1130 #define GENERATE_GET_CLASS_WITH_CACHE_DECL(shortname) \
1131 MonoClass* mono_class_get_##shortname##_class (void);
1132
1133 #define GENERATE_TRY_GET_CLASS_WITH_CACHE_DECL(shortname) \
1134 MonoClass* mono_class_try_get_##shortname##_class (void);
1135
1136 #define GENERATE_GET_CLASS_WITH_CACHE(shortname,name_space,name) \
1137 MonoClass*      \
1138 mono_class_get_##shortname##_class (void)       \
1139 {       \
1140         static MonoClass *tmp_class;    \
1141         MonoClass *klass = tmp_class;   \
1142         if (!klass) {   \
1143                 klass = mono_class_load_from_name (mono_defaults.corlib, name_space, name);     \
1144                 mono_memory_barrier (); \
1145                 tmp_class = klass;      \
1146         }       \
1147         return klass;   \
1148 }
1149
1150 #define GENERATE_TRY_GET_CLASS_WITH_CACHE(shortname,name_space,name) \
1151 MonoClass*      \
1152 mono_class_try_get_##shortname##_class (void)   \
1153 {       \
1154         static volatile MonoClass *tmp_class;   \
1155         static volatile gboolean inited;        \
1156         MonoClass *klass = (MonoClass *)tmp_class;      \
1157         mono_memory_barrier (); \
1158         if (!inited) {  \
1159                 klass = mono_class_try_load_from_name (mono_defaults.corlib, name_space, name); \
1160                 tmp_class = klass;      \
1161                 mono_memory_barrier (); \
1162                 inited = TRUE;  \
1163         }       \
1164         return klass;   \
1165 }
1166
1167 GENERATE_TRY_GET_CLASS_WITH_CACHE_DECL (safehandle)
1168
1169 #ifndef DISABLE_COM
1170
1171 GENERATE_GET_CLASS_WITH_CACHE_DECL (interop_proxy)
1172 GENERATE_GET_CLASS_WITH_CACHE_DECL (idispatch)
1173 GENERATE_GET_CLASS_WITH_CACHE_DECL (iunknown)
1174 GENERATE_GET_CLASS_WITH_CACHE_DECL (com_object)
1175 GENERATE_GET_CLASS_WITH_CACHE_DECL (variant)
1176
1177 #endif
1178
1179 GENERATE_GET_CLASS_WITH_CACHE_DECL (appdomain_unloaded_exception)
1180
1181 extern MonoDefaults mono_defaults;
1182
1183 void
1184 mono_loader_init           (void);
1185
1186 void
1187 mono_loader_cleanup        (void);
1188
1189 void
1190 mono_loader_lock           (void) MONO_LLVM_INTERNAL;
1191
1192 void
1193 mono_loader_unlock         (void) MONO_LLVM_INTERNAL;
1194
1195 void
1196 mono_loader_lock_track_ownership (gboolean track);
1197
1198 gboolean
1199 mono_loader_lock_is_owned_by_self (void);
1200
1201 void
1202 mono_loader_lock_if_inited (void);
1203
1204 void
1205 mono_loader_unlock_if_inited (void);
1206
1207 void
1208 mono_reflection_init       (void);
1209
1210 void
1211 mono_icall_init            (void);
1212
1213 void
1214 mono_icall_cleanup         (void);
1215
1216 gpointer
1217 mono_method_get_wrapper_data (MonoMethod *method, guint32 id);
1218
1219 gboolean
1220 mono_metadata_has_generic_params (MonoImage *image, guint32 token);
1221
1222 MONO_API MonoGenericContainer *
1223 mono_metadata_load_generic_params (MonoImage *image, guint32 token,
1224                                    MonoGenericContainer *parent_container);
1225
1226 MONO_API gboolean
1227 mono_metadata_load_generic_param_constraints_checked (MonoImage *image, guint32 token,
1228                                               MonoGenericContainer *container, MonoError *error);
1229
1230 MonoMethodSignature*
1231 mono_create_icall_signature (const char *sigstr);
1232
1233 MonoJitICallInfo *
1234 mono_register_jit_icall (gconstpointer func, const char *name, MonoMethodSignature *sig, gboolean is_save);
1235
1236 MonoJitICallInfo *
1237 mono_register_jit_icall_full (gconstpointer func, const char *name, MonoMethodSignature *sig, gboolean is_save, gboolean no_raise, const char *c_symbol);
1238
1239 void
1240 mono_register_jit_icall_wrapper (MonoJitICallInfo *info, gconstpointer wrapper);
1241
1242 MonoJitICallInfo *
1243 mono_find_jit_icall_by_name (const char *name) MONO_LLVM_INTERNAL;
1244
1245 MonoJitICallInfo *
1246 mono_find_jit_icall_by_addr (gconstpointer addr) MONO_LLVM_INTERNAL;
1247
1248 GHashTable*
1249 mono_get_jit_icall_info (void);
1250
1251 const char*
1252 mono_lookup_jit_icall_symbol (const char *name);
1253
1254 gboolean
1255 mono_class_set_type_load_failure (MonoClass *klass, const char * fmt, ...) MONO_ATTR_FORMAT_PRINTF(2,3);
1256
1257 MonoException*
1258 mono_class_get_exception_for_failure (MonoClass *klass);
1259
1260 char*
1261 mono_type_get_name_full (MonoType *type, MonoTypeNameFormat format);
1262
1263 char*
1264 mono_type_get_full_name (MonoClass *klass);
1265
1266 char *
1267 mono_method_get_name_full (MonoMethod *method, gboolean signature, gboolean ret, MonoTypeNameFormat format);
1268
1269 char *
1270 mono_method_get_full_name (MonoMethod *method);
1271
1272 MonoArrayType *mono_dup_array_type (MonoImage *image, MonoArrayType *a);
1273 MonoMethodSignature *mono_metadata_signature_deep_dup (MonoImage *image, MonoMethodSignature *sig);
1274
1275 MONO_API void
1276 mono_image_init_name_cache (MonoImage *image);
1277
1278 gboolean mono_class_is_nullable (MonoClass *klass);
1279 MonoClass *mono_class_get_nullable_param (MonoClass *klass);
1280
1281 /* object debugging functions, for use inside gdb */
1282 MONO_API void mono_object_describe        (MonoObject *obj);
1283 MONO_API void mono_object_describe_fields (MonoObject *obj);
1284 MONO_API void mono_value_describe_fields  (MonoClass* klass, const char* addr);
1285 MONO_API void mono_class_describe_statics (MonoClass* klass);
1286
1287 /* method debugging functions, for use inside gdb */
1288 MONO_API void mono_method_print_code (MonoMethod *method);
1289
1290 MONO_PROFILER_API char *mono_signature_full_name (MonoMethodSignature *sig);
1291
1292 /*Enum validation related functions*/
1293 MONO_API gboolean
1294 mono_type_is_valid_enum_basetype (MonoType * type);
1295
1296 MONO_API gboolean
1297 mono_class_is_valid_enum (MonoClass *klass);
1298
1299 MONO_PROFILER_API gboolean
1300 mono_type_is_primitive (MonoType *type);
1301
1302 MonoType *
1303 mono_type_get_checked        (MonoImage *image, guint32 type_token, MonoGenericContext *context, MonoError *error);
1304
1305 gboolean
1306 mono_generic_class_is_generic_type_definition (MonoGenericClass *gklass);
1307
1308 MonoMethod*
1309 mono_class_get_method_generic (MonoClass *klass, MonoMethod *method);
1310
1311 MonoType*
1312 mono_type_get_basic_type_from_generic (MonoType *type);
1313
1314 gboolean
1315 mono_method_can_access_method_full (MonoMethod *method, MonoMethod *called, MonoClass *context_klass);
1316
1317 gboolean
1318 mono_method_can_access_field_full (MonoMethod *method, MonoClassField *field, MonoClass *context_klass);
1319
1320 gboolean
1321 mono_class_can_access_class (MonoClass *access_class, MonoClass *target_class);
1322
1323 MonoClass *
1324 mono_class_get_generic_type_definition (MonoClass *klass);
1325
1326 gboolean
1327 mono_class_has_parent_and_ignore_generics (MonoClass *klass, MonoClass *parent);
1328
1329 int
1330 mono_method_get_vtable_slot (MonoMethod *method);
1331
1332 int
1333 mono_method_get_vtable_index (MonoMethod *method);
1334
1335 MonoMethod*
1336 mono_method_get_base_method (MonoMethod *method, gboolean definition, MonoError *error);
1337
1338 MonoMethod*
1339 mono_method_search_in_array_class (MonoClass *klass, const char *name, MonoMethodSignature *sig);
1340
1341 void
1342 mono_class_setup_interface_id (MonoClass *klass);
1343
1344 MonoGenericContainer*
1345 mono_class_get_generic_container (MonoClass *klass);
1346
1347 gpointer
1348 mono_class_alloc (MonoClass *klass, int size);
1349
1350 gpointer
1351 mono_class_alloc0 (MonoClass *klass, int size);
1352
1353 void
1354 mono_class_setup_interfaces (MonoClass *klass, MonoError *error);
1355
1356 MonoClassField*
1357 mono_class_get_field_from_name_full (MonoClass *klass, const char *name, MonoType *type);
1358
1359 MonoVTable*
1360 mono_class_vtable_full (MonoDomain *domain, MonoClass *klass, MonoError *error);
1361
1362 gboolean
1363 mono_class_is_assignable_from_slow (MonoClass *target, MonoClass *candidate);
1364
1365 gboolean
1366 mono_class_has_variant_generic_params (MonoClass *klass);
1367
1368 gboolean
1369 mono_class_is_variant_compatible (MonoClass *klass, MonoClass *oklass, gboolean check_for_reference_conv);
1370
1371 gboolean mono_is_corlib_image (MonoImage *image);
1372
1373 MonoType*
1374 mono_field_get_type_checked (MonoClassField *field, MonoError *error);
1375
1376 MonoClassField*
1377 mono_class_get_fields_lazy (MonoClass* klass, gpointer *iter);
1378
1379 gboolean
1380 mono_class_check_vtable_constraints (MonoClass *klass, GList *in_setup);
1381
1382 gboolean
1383 mono_class_has_finalizer (MonoClass *klass);
1384
1385 void
1386 mono_unload_interface_id (MonoClass *klass);
1387
1388 GPtrArray*
1389 mono_class_get_methods_by_name (MonoClass *klass, const char *name, guint32 bflags, gboolean ignore_case, gboolean allow_ctors, MonoError *error);
1390
1391 char*
1392 mono_class_full_name (MonoClass *klass);
1393
1394 MonoClass*
1395 mono_class_inflate_generic_class_checked (MonoClass *gklass, MonoGenericContext *context, MonoError *error);
1396
1397 MonoClass *
1398 mono_class_get_checked (MonoImage *image, guint32 type_token, MonoError *error);
1399
1400 MonoClass *
1401 mono_class_get_and_inflate_typespec_checked (MonoImage *image, guint32 type_token, MonoGenericContext *context, MonoError *error);
1402
1403 MonoClass *
1404 mono_class_from_name_checked (MonoImage *image, const char* name_space, const char *name, MonoError *error);
1405
1406 MonoClass *
1407 mono_class_from_name_case_checked (MonoImage *image, const char* name_space, const char *name, MonoError *error);
1408
1409 MonoClassField*
1410 mono_field_from_token_checked (MonoImage *image, uint32_t token, MonoClass **retklass, MonoGenericContext *context, MonoError *error);
1411
1412 gpointer
1413 mono_ldtoken_checked (MonoImage *image, guint32 token, MonoClass **handle_class, MonoGenericContext *context, MonoError *error);
1414
1415 MonoClass *
1416 mono_class_from_generic_parameter_internal (MonoGenericParam *param);
1417
1418 MonoImage *
1419 get_image_for_generic_param (MonoGenericParam *param);
1420
1421 char *
1422 make_generic_name_string (MonoImage *image, int num);
1423
1424 MonoClass *
1425 mono_class_load_from_name (MonoImage *image, const char* name_space, const char *name) MONO_LLVM_INTERNAL;
1426
1427 MonoClass*
1428 mono_class_try_load_from_name (MonoImage *image, const char* name_space, const char *name);
1429
1430 void
1431 mono_error_set_for_class_failure (MonoError *orerror, const MonoClass *klass);
1432
1433 gboolean
1434 mono_class_has_failure (const MonoClass *klass);
1435
1436 /* Kind specific accessors */
1437 MonoGenericClass*
1438 mono_class_get_generic_class (MonoClass *klass);
1439
1440 MonoGenericClass*
1441 mono_class_try_get_generic_class (MonoClass *klass);
1442
1443 void
1444 mono_class_set_flags (MonoClass *klass, guint32 flags);
1445
1446 MonoGenericContainer*
1447 mono_class_try_get_generic_container (MonoClass *klass);
1448
1449 void
1450 mono_class_set_generic_container (MonoClass *klass, MonoGenericContainer *container);
1451
1452 MonoType*
1453 mono_class_gtd_get_canonical_inst (MonoClass *klass);
1454
1455 guint32
1456 mono_class_get_first_method_idx (MonoClass *klass);
1457
1458 void
1459 mono_class_set_first_method_idx (MonoClass *klass, guint32 idx);
1460
1461 guint32
1462 mono_class_get_first_field_idx (MonoClass *klass);
1463
1464 void
1465 mono_class_set_first_field_idx (MonoClass *klass, guint32 idx);
1466
1467 guint32
1468 mono_class_get_method_count (MonoClass *klass);
1469
1470 void
1471 mono_class_set_method_count (MonoClass *klass, guint32 count);
1472
1473 guint32
1474 mono_class_get_field_count (MonoClass *klass);
1475
1476 void
1477 mono_class_set_field_count (MonoClass *klass, guint32 count);
1478
1479 MonoMarshalType*
1480 mono_class_get_marshal_info (MonoClass *class);
1481
1482 void
1483 mono_class_set_marshal_info (MonoClass *class, MonoMarshalType *marshal_info);
1484
1485 guint32
1486 mono_class_get_ref_info_handle (MonoClass *class);
1487
1488 guint32
1489 mono_class_set_ref_info_handle (MonoClass *class, guint32 value);
1490
1491 MonoErrorBoxed*
1492 mono_class_get_exception_data (MonoClass *klass);
1493
1494 void
1495 mono_class_set_exception_data (MonoClass *klass, MonoErrorBoxed *value);
1496
1497 GList*
1498 mono_class_get_nested_classes_property (MonoClass *klass);
1499
1500 void
1501 mono_class_set_nested_classes_property (MonoClass *klass, GList *value);
1502
1503 MonoClassPropertyInfo*
1504 mono_class_get_property_info (MonoClass *klass);
1505
1506 void
1507 mono_class_set_property_info (MonoClass *klass, MonoClassPropertyInfo *info);
1508
1509 MonoClassEventInfo*
1510 mono_class_get_event_info (MonoClass *klass);
1511
1512 void
1513 mono_class_set_event_info (MonoClass *klass, MonoClassEventInfo *info);
1514
1515 MonoFieldDefaultValue*
1516 mono_class_get_field_def_values (MonoClass *klass);
1517
1518 void
1519 mono_class_set_field_def_values (MonoClass *klass, MonoFieldDefaultValue *values);
1520
1521 guint32
1522 mono_class_get_declsec_flags (MonoClass *class);
1523
1524 void
1525 mono_class_set_declsec_flags (MonoClass *class, guint32 value);
1526
1527 void
1528 mono_class_set_is_com_object (MonoClass *klass);
1529
1530 /*Now that everything has been defined, let's include the inline functions */
1531 #include <mono/metadata/class-inlines.h>
1532
1533 #endif /* __MONO_METADATA_CLASS_INTERNALS_H__ */