In .:
[mono.git] / mono / metadata / class-internals.h
1 #ifndef __MONO_METADATA_CLASS_INTERBALS_H__
2 #define __MONO_METADATA_CLASS_INTERBALS_H__
3
4 #include <mono/metadata/class.h>
5 #include <mono/metadata/object.h>
6 #include <mono/metadata/mempool.h>
7 #include <mono/io-layer/io-layer.h>
8 #include "mono/utils/mono-compiler.h"
9
10 #define MONO_CLASS_IS_ARRAY(c) ((c)->rank)
11
12 #define MONO_CLASS_HAS_STATIC_METADATA(klass) ((klass)->type_token && !(klass)->image->dynamic && !(klass)->generic_class)
13
14 #define MONO_DEFAULT_SUPERTABLE_SIZE 6
15
16 extern gboolean mono_print_vtable;
17
18 extern gboolean mono_setup_vtable_in_class_init;
19
20 typedef void     (*MonoStackWalkImpl) (MonoStackWalk func, gboolean do_il_offset, gpointer user_data);
21
22 typedef struct _MonoMethodNormal MonoMethodNormal;
23 typedef struct _MonoMethodWrapper MonoMethodWrapper;
24 typedef struct _MonoMethodInflated MonoMethodInflated;
25 typedef struct _MonoMethodPInvoke MonoMethodPInvoke;
26
27 /* Properties that applies to a group of structs should better use a higher number
28  * to avoid colision with type specific properties.
29  * 
30  * This prop applies to class, method, property, event, assembly and image.
31  */
32 #define MONO_PROP_DYNAMIC_CATTR 0x1000
33
34 typedef enum {
35 #define WRAPPER(e,n) MONO_WRAPPER_ ## e,
36 #include "wrapper-types.h"
37 #undef WRAPPER
38         MONO_WRAPPER_NUM
39 } MonoWrapperType;
40
41 typedef enum {
42         MONO_TYPE_NAME_FORMAT_IL,
43         MONO_TYPE_NAME_FORMAT_REFLECTION,
44         MONO_TYPE_NAME_FORMAT_FULL_NAME,
45         MONO_TYPE_NAME_FORMAT_ASSEMBLY_QUALIFIED
46 } MonoTypeNameFormat;
47
48 typedef enum {
49         MONO_REMOTING_TARGET_UNKNOWN,
50         MONO_REMOTING_TARGET_APPDOMAIN,
51         MONO_REMOTING_TARGET_COMINTEROP
52 } MonoRemotingTarget;
53
54 #define MONO_METHOD_PROP_GENERIC_CONTAINER 0
55
56 struct _MonoMethod {
57         guint16 flags;  /* method flags */
58         guint16 iflags; /* method implementation flags */
59         guint32 token;
60         MonoClass *klass;
61         MonoMethodSignature *signature;
62         /* name is useful mostly for debugging */
63         const char *name;
64         /* this is used by the inlining algorithm */
65         unsigned int inline_info:1;
66         unsigned int inline_failure:1;
67         unsigned int wrapper_type:5;
68         unsigned int string_ctor:1;
69         unsigned int save_lmf:1;
70         unsigned int dynamic:1; /* created & destroyed during runtime */
71         unsigned int is_generic:1; /* whenever this is a generic method definition */
72         unsigned int is_inflated:1; /* whether we're a MonoMethodInflated */
73         unsigned int skip_visibility:1; /* whenever to skip JIT visibility checks */
74         unsigned int verification_success:1; /* whether this method has been verified successfully.*/
75         /* TODO we MUST get rid of this field, it's an ugly hack nobody is proud of. */
76         unsigned int is_mb_open : 1;            /* This is the fully open instantiation of a generic method_builder. Worse than is_tb_open, but it's temporary */
77         signed int slot : 17;
78
79         /*
80          * If is_generic is TRUE, the generic_container is stored in image->property_hash, 
81          * using the key MONO_METHOD_PROP_GENERIC_CONTAINER.
82          */
83 };
84
85 struct _MonoMethodNormal {
86         MonoMethod method;
87         MonoMethodHeader *header;
88 };
89
90 struct _MonoMethodWrapper {
91         MonoMethodNormal method;
92         void *method_data;
93 };
94
95 struct _MonoMethodPInvoke {
96         MonoMethod method;
97         gpointer addr;
98         /* add marshal info */
99         guint16 piflags;  /* pinvoke flags */
100         guint16 implmap_idx;  /* index into IMPLMAP */
101 };
102
103 /* 
104  * Stores the default value / RVA of fields.
105  * This information is rarely needed, so it is stored separately from MonoClassField.
106  */
107 typedef struct MonoFieldDefaultValue {
108         /*
109          * If the field is constant, pointer to the metadata constant
110          * value.
111          * If the field has an RVA flag, pointer to the data.
112          * Else, invalid.
113          */
114         const char      *data;
115
116         /* If the field is constant, the type of the constant. */
117         MonoTypeEnum     def_type;
118 } MonoFieldDefaultValue;
119
120 /*
121  * MonoClassField is just a runtime representation of the metadata for
122  * field, it doesn't contain the data directly.  Static fields are
123  * stored in MonoVTable->data.  Instance fields are allocated in the
124  * objects after the object header.
125  */
126 struct _MonoClassField {
127         /* Type of the field */
128         MonoType        *type;
129
130         const char      *name;
131
132         /* Type where the field was defined */
133         MonoClass       *parent;
134
135         /*
136          * Offset where this field is stored; if it is an instance
137          * field, it's the offset from the start of the object, if
138          * it's static, it's from the start of the memory chunk
139          * allocated for statics for the class.
140          */
141         int              offset;
142 };
143
144 /* a field is ignored if it's named "_Deleted" and it has the specialname and rtspecialname flags set */
145 #define mono_field_is_deleted(field) (((field)->type->attrs & (FIELD_ATTRIBUTE_SPECIAL_NAME | FIELD_ATTRIBUTE_RT_SPECIAL_NAME)) \
146                                       && (strcmp (mono_field_get_name (field), "_Deleted") == 0))
147
148 typedef struct {
149         MonoClassField *field;
150         guint32 offset;
151         MonoMarshalSpec *mspec;
152 } MonoMarshalField;
153
154 typedef struct {
155         guint32 native_size, min_align;
156         guint32 num_fields;
157         MonoMethod *ptr_to_str;
158         MonoMethod *str_to_ptr;
159         MonoMarshalField fields [MONO_ZERO_LEN_ARRAY];
160 } MonoMarshalType;
161
162 struct _MonoProperty {
163         MonoClass *parent;
164         const char *name;
165         MonoMethod *get;
166         MonoMethod *set;
167         guint32 attrs;
168 };
169
170 struct _MonoEvent {
171         MonoClass *parent;
172         const char *name;
173         MonoMethod *add;
174         MonoMethod *remove;
175         MonoMethod *raise;
176         MonoMethod **other;
177         guint32 attrs;
178 };
179
180 /* type of exception being "on hold" for later processing (see exception_type) */
181 enum {
182         MONO_EXCEPTION_NONE = 0,
183         MONO_EXCEPTION_SECURITY_LINKDEMAND = 1,
184         MONO_EXCEPTION_SECURITY_INHERITANCEDEMAND = 2,
185         MONO_EXCEPTION_INVALID_PROGRAM = 3,
186         MONO_EXCEPTION_UNVERIFIABLE_IL = 4,
187         MONO_EXCEPTION_MISSING_METHOD = 5,
188         MONO_EXCEPTION_MISSING_FIELD = 6,
189         MONO_EXCEPTION_TYPE_LOAD = 7,
190         MONO_EXCEPTION_FILE_NOT_FOUND = 8,
191         MONO_EXCEPTION_METHOD_ACCESS = 9,
192         MONO_EXCEPTION_FIELD_ACCESS = 10,
193         MONO_EXCEPTION_GENERIC_SHARING_FAILED = 11,
194         MONO_EXCEPTION_BAD_IMAGE = 12,
195         MONO_EXCEPTION_OBJECT_SUPPLIED = 13 /*The exception object is already created.*/
196         /* add other exception type */
197 };
198
199 /* This struct collects the info needed for the runtime use of a class,
200  * like the vtables for a domain, the GC descriptor, etc.
201  */
202 typedef struct {
203         guint16 max_domain;
204         /* domain_vtables is indexed by the domain id and the size is max_domain + 1 */
205         MonoVTable *domain_vtables [MONO_ZERO_LEN_ARRAY];
206 } MonoClassRuntimeInfo;
207
208 enum {
209         MONO_RGCTX_INFO_STATIC_DATA,
210         MONO_RGCTX_INFO_KLASS,
211         MONO_RGCTX_INFO_VTABLE,
212         MONO_RGCTX_INFO_TYPE,
213         MONO_RGCTX_INFO_REFLECTION_TYPE,
214         MONO_RGCTX_INFO_METHOD,
215         MONO_RGCTX_INFO_GENERIC_METHOD_CODE,
216         MONO_RGCTX_INFO_CLASS_FIELD,
217         MONO_RGCTX_INFO_METHOD_RGCTX,
218         MONO_RGCTX_INFO_METHOD_CONTEXT
219 };
220
221 typedef struct _MonoRuntimeGenericContextOtherInfoTemplate {
222         int info_type;
223         gpointer data;
224         struct _MonoRuntimeGenericContextOtherInfoTemplate *next;
225 } MonoRuntimeGenericContextOtherInfoTemplate;
226
227 typedef struct {
228         MonoClass *next_subclass;
229         MonoRuntimeGenericContextOtherInfoTemplate *other_infos;
230         GSList *method_templates;
231 } MonoRuntimeGenericContextTemplate;
232
233 typedef struct {
234         MonoVTable *class_vtable; /* must be the first element */
235         MonoGenericInst *method_inst;
236         gpointer infos [MONO_ZERO_LEN_ARRAY];
237 } MonoMethodRuntimeGenericContext;
238
239 #define MONO_RGCTX_SLOT_MAKE_RGCTX(i)   (i)
240 #define MONO_RGCTX_SLOT_MAKE_MRGCTX(i)  ((i) | 0x80000000)
241 #define MONO_RGCTX_SLOT_INDEX(s)        ((s) & 0x7fffffff)
242 #define MONO_RGCTX_SLOT_IS_MRGCTX(s)    (((s) & 0x80000000) ? TRUE : FALSE)
243
244
245 #define MONO_CLASS_PROP_EXCEPTION_DATA 0
246
247 /* 
248  * This structure contains the rarely used fields of MonoClass
249  * Since using just one field causes the whole structure to be allocated, it should
250  * be used for fields which are only used in like 5% of all classes.
251  */
252 typedef struct {
253         struct {
254                 guint32 first, count;
255         } property, event;
256
257         /* Initialized by a call to mono_class_setup_properties () */
258         MonoProperty *properties;
259
260         /* Initialized by a call to mono_class_setup_events () */
261         MonoEvent *events;
262
263         guint32    declsec_flags;       /* declarative security attributes flags */
264
265         /* Default values/RVA for fields */
266         /* Accessed using mono_class_get_field_default_value () / mono_field_get_data () */
267         MonoFieldDefaultValue *field_def_values;
268
269         GList      *nested_classes;
270 } MonoClassExt;
271
272 struct _MonoClass {
273         /* element class for arrays and enum basetype for enums */
274         MonoClass *element_class; 
275         /* used for subtype checks */
276         MonoClass *cast_class; 
277
278         /* for fast subtype checks */
279         MonoClass **supertypes;
280         guint16     idepth;
281
282         /* array dimension */
283         guint8     rank;          
284
285         int        instance_size; /* object instance size */
286
287         guint inited          : 1;
288         /* We use init_pending to detect cyclic calls to mono_class_init */
289         guint init_pending    : 1;
290
291         /* A class contains static and non static data. Static data can be
292          * of the same type as the class itselfs, but it does not influence
293          * the instance size of the class. To avoid cyclic calls to 
294          * mono_class_init (from mono_class_instance_size ()) we first 
295          * initialise all non static fields. After that we set size_inited 
296          * to 1, because we know the instance size now. After that we 
297          * initialise all static fields.
298          */
299         guint size_inited     : 1;
300         guint valuetype       : 1; /* derives from System.ValueType */
301         guint enumtype        : 1; /* derives from System.Enum */
302         guint blittable       : 1; /* class is blittable */
303         guint unicode         : 1; /* class uses unicode char when marshalled */
304         guint wastypebuilder  : 1; /* class was created at runtime from a TypeBuilder */
305         /* next byte */
306         guint8 min_align;
307         /* next byte */
308         guint packing_size    : 4;
309         /* still 4 bits free */
310         /* next byte */
311         guint ghcimpl         : 1; /* class has its own GetHashCode impl */ 
312         guint has_finalize    : 1; /* class has its own Finalize impl */ 
313         guint marshalbyref    : 1; /* class is a MarshalByRefObject */
314         guint contextbound    : 1; /* class is a ContextBoundObject */
315         guint delegate        : 1; /* class is a Delegate */
316         guint gc_descr_inited : 1; /* gc_descr is initialized */
317         guint has_cctor       : 1; /* class has a cctor */
318         guint has_references  : 1; /* it has GC-tracked references in the instance */
319         /* next byte */
320         guint has_static_refs : 1; /* it has static fields that are GC-tracked */
321         guint no_special_static_fields : 1; /* has no thread/context static fields */
322         /* directly or indirectly derives from ComImport attributed class.
323          * this means we need to create a proxy for instances of this class
324          * for COM Interop. set this flag on loading so all we need is a quick check
325          * during object creation rather than having to traverse supertypes
326          */
327         guint is_com_object : 1; 
328         guint nested_classes_inited : 1; /* Whenever nested_class is initialized */
329         guint interfaces_inited : 1; /* interfaces is initialized */
330         guint simd_type : 1; /* class is a simd intrinsic type */
331         guint is_generic : 1; /* class is a generic type definition */
332         guint is_inflated : 1; /* class is a generic instance */
333
334         guint8     exception_type;      /* MONO_EXCEPTION_* */
335
336         /* Additional information about the exception */
337         /* Stored as property MONO_CLASS_PROP_EXCEPTION_DATA */
338         //void       *exception_data;
339
340         MonoClass  *parent;
341         MonoClass  *nested_in;
342
343         MonoImage *image;
344         const char *name;
345         const char *name_space;
346
347         guint32    type_token;
348         int        vtable_size; /* number of slots */
349
350         guint16     interface_count;
351         guint16     interface_id;        /* unique inderface id (for interfaces) */
352         guint16     max_interface_id;
353         
354         guint16     interface_offsets_count;
355         MonoClass **interfaces_packed;
356         guint16    *interface_offsets_packed;
357         guint8     *interface_bitmap;
358         
359         MonoClass **interfaces;
360
361         union {
362                 int class_size; /* size of area for static fields */
363                 int element_size; /* for array types */
364                 int generic_param_token; /* for generic param types, both var and mvar */
365         } sizes;
366
367         /*
368          * From the TypeDef table
369          */
370         guint32    flags;
371         struct {
372                 guint32 first, count;
373         } field, method;
374
375         /* loaded on demand */
376         MonoMarshalType *marshal_info;
377
378         /*
379          * Field information: Type and location from object base
380          */
381         MonoClassField *fields;
382
383         MonoMethod **methods;
384
385         /* used as the type of the this argument and when passing the arg by value */
386         MonoType this_arg;
387         MonoType byval_arg;
388
389         MonoGenericClass *generic_class;
390         MonoGenericContainer *generic_container;
391
392         void *reflection_info;
393
394         void *gc_descr;
395
396         MonoClassRuntimeInfo *runtime_info;
397
398         /* next element in the class_cache hash list (in MonoImage) */
399         MonoClass *next_class_cache;
400
401         /* Generic vtable. Initialized by a call to mono_class_setup_vtable () */
402         MonoMethod **vtable;
403
404         /* Rarely used fields of classes */
405         MonoClassExt *ext;
406 };
407
408 #define MONO_CLASS_IMPLEMENTS_INTERFACE(k,uiid) (((uiid) <= (k)->max_interface_id) && ((k)->interface_bitmap [(uiid) >> 3] & (1 << ((uiid)&7))))
409 int mono_class_interface_offset (MonoClass *klass, MonoClass *itf);
410
411 typedef gpointer MonoRuntimeGenericContext;
412
413 /* the interface_offsets array is stored in memory before this struct */
414 struct MonoVTable {
415         MonoClass  *klass;
416          /*
417          * According to comments in gc_gcj.h, this should be the second word in
418          * the vtable.
419          */
420         void *gc_descr;         
421         MonoDomain *domain;  /* each object/vtable belongs to exactly one domain */
422         gpointer    data; /* to store static class data */
423         gpointer    type; /* System.Type type for klass */
424         guint8     *interface_bitmap;
425         guint16     max_interface_id;
426         guint8      rank;
427         guint remote          : 1; /* class is remotely activated */
428         guint initialized     : 1; /* cctor has been run */
429         guint init_failed     : 1; /* cctor execution failed */
430         guint32     imt_collisions_bitmap;
431         MonoRuntimeGenericContext *runtime_generic_context;
432         /* do not add any fields after vtable, the structure is dynamically extended */
433         gpointer    vtable [MONO_ZERO_LEN_ARRAY];       
434 };
435
436 #define MONO_VTABLE_IMPLEMENTS_INTERFACE(vt,uiid) (((uiid) <= (vt)->max_interface_id) && ((vt)->interface_bitmap [(uiid) >> 3] & (1 << ((uiid)&7))))
437
438 /*
439  * Generic instantiation data type encoding.
440  */
441
442 /*
443  * A particular generic instantiation:
444  *
445  * All instantiations are cached and we don't distinguish between class and method
446  * instantiations here.
447  */
448 struct _MonoGenericInst {
449         guint id;                       /* unique ID for debugging */
450         guint type_argc    : 22;        /* number of type arguments */
451         guint is_open      :  1;        /* if this is an open type */
452         MonoType *type_argv [MONO_ZERO_LEN_ARRAY];
453 };
454
455 /*
456  * The generic context: an instantiation of a set of class and method generic parameters.
457  *
458  * NOTE: Never allocate this directly on the heap.  It have to be either allocated on the stack,
459  *       or embedded within other objects.  Don't store pointers to this, because it may be on the stack.
460  *       If you really have to, ensure you store a pointer to the embedding object along with it.
461  */
462 struct _MonoGenericContext {
463         /* The instantiation corresponding to the class generic parameters */
464         MonoGenericInst *class_inst;
465         /* The instantiation corresponding to the method generic parameters */
466         MonoGenericInst *method_inst;
467 };
468
469 /*
470  * Inflated generic method.
471  */
472 struct _MonoMethodInflated {
473         union {
474                 MonoMethod method;
475                 MonoMethodNormal normal;
476                 MonoMethodPInvoke pinvoke;
477         } method;
478         MonoMethod *declaring;          /* the generic method definition. */
479         MonoGenericContext context;     /* The current instantiation */
480 };
481
482 /*
483  * A particular instantiation of a generic type.
484  */
485 struct _MonoGenericClass {
486         MonoClass *container_class;     /* the generic type definition */
487         MonoGenericContext context;     /* a context that contains the type instantiation doesn't contain any method instantiation */
488         guint is_dynamic  : 1;          /* We're a MonoDynamicGenericClass */
489         guint is_tb_open  : 1;          /* This is the fully open instantiation for a type_builder. Quite ugly, but it's temporary.*/
490         MonoClass *cached_class;        /* if present, the MonoClass corresponding to the instantiation.  */
491 };
492
493 /*
494  * This is used when instantiating a generic type definition which is
495  * a TypeBuilder.
496  */
497 struct _MonoDynamicGenericClass {
498         MonoGenericClass generic_class;
499         int count_methods;
500         MonoMethod **methods;
501         int count_ctors;
502         MonoMethod **ctors;
503         int count_fields;
504         MonoClassField *fields;
505         int count_properties;
506         MonoProperty *properties;
507         int count_events;
508         MonoEvent *events;
509         guint initialized;
510         /* The non-inflated types of the fields */
511         MonoType **field_generic_types;
512         /* The managed objects representing the fields */
513         MonoObject **field_objects;
514 };
515
516 /*
517  * The generic container.
518  *
519  * Stores the type parameters of a generic type definition or a generic method definition.
520  */
521 struct _MonoGenericContainer {
522         MonoGenericContext context;
523         /* If we're a generic method definition in a generic type definition,
524            the generic container of the containing class. */
525         MonoGenericContainer *parent;
526         /* the generic type definition or the generic method definition corresponding to this container */
527         union {
528                 MonoClass *klass;
529                 MonoMethod *method;
530         } owner;
531         int type_argc    : 31;
532         /* If true, we're a generic method, otherwise a generic type definition. */
533         /* Invariant: parent != NULL => is_method */
534         int is_method    : 1;
535         /* Our type parameters. */
536         MonoGenericParam *type_params;
537 };
538
539 /*
540  * A type parameter.
541  */
542 struct _MonoGenericParam {
543         MonoGenericContainer *owner;    /* Type or method this parameter was defined in. */
544         MonoClass *pklass;              /* The corresponding `MonoClass'. */
545         const char *name;
546         guint16 flags;
547         guint16 num;
548         MonoClass** constraints; /* NULL means end of list */
549         /* If owner is NULL, this is the image whose mempool this struct was allocated from */
550         MonoImage *image;
551 };
552
553 /*
554  * Class information which might be cached by the runtime in the AOT file for
555  * example. Caching this allows us to avoid computing a generic vtable
556  * (class->vtable) in most cases, saving time and avoiding creation of lots of
557  * MonoMethod structures.
558  */
559 typedef struct MonoCachedClassInfo {
560         guint32 vtable_size;
561         guint has_finalize : 1;
562         guint ghcimpl : 1;
563         guint has_cctor : 1;
564         guint has_nested_classes : 1;
565         guint blittable : 1;
566         guint has_references : 1;
567         guint has_static_refs : 1;
568         guint no_special_static_fields : 1;
569         guint32 cctor_token;
570         MonoImage *finalize_image;
571         guint32 finalize_token;
572         guint32 instance_size;
573         guint32 class_size;
574         guint32 packing_size;
575         guint32 min_align;
576 } MonoCachedClassInfo;
577
578 typedef struct {
579         const char *name;
580         gconstpointer func;
581         gconstpointer wrapper;
582         gconstpointer trampoline;
583         MonoMethodSignature *sig;
584 } MonoJitICallInfo;
585
586 typedef struct {
587         guint8 exception_type;
588         char *class_name; /* If kind == TYPE */
589         char *assembly_name; /* If kind == TYPE or ASSEMBLY */
590         MonoClass *klass; /* If kind != TYPE */
591         const char *member_name; /* If kind != TYPE */
592         gboolean ref_only; /* If kind == ASSEMBLY */
593         char *msg; /* If kind == BAD_IMAGE */
594 } MonoLoaderError;
595
596 #define mono_class_has_parent(klass,parent) (((klass)->idepth >= (parent)->idepth) && ((klass)->supertypes [(parent)->idepth - 1] == (parent)))
597
598 typedef struct {
599         gulong new_object_count;
600         gulong initialized_class_count;
601         gulong generic_vtable_count;
602         gulong used_class_count;
603         gulong method_count;
604         gulong class_vtable_size;
605         gulong class_static_data_size;
606         gulong generic_instance_count;
607         gulong generic_class_count;
608         gulong inflated_method_count;
609         gulong inflated_method_count_2;
610         gulong inflated_type_count;
611         gulong generics_metadata_size;
612         gulong dynamic_code_alloc_count;
613         gulong dynamic_code_bytes_count;
614         gulong dynamic_code_frees_count;
615         gulong delegate_creations;
616         gulong imt_tables_size;
617         gulong imt_number_of_tables;
618         gulong imt_number_of_methods;
619         gulong imt_used_slots;
620         gulong imt_slots_with_collisions;
621         gulong imt_max_collisions_in_slot;
622         gulong imt_method_count_when_max_collisions;
623         gulong imt_thunks_size;
624         gulong jit_info_table_insert_count;
625         gulong jit_info_table_remove_count;
626         gulong jit_info_table_lookup_count;
627         gulong hazardous_pointer_count;
628         gulong generics_sharable_methods;
629         gulong generics_unsharable_methods;
630         gulong generics_shared_methods;
631         gulong minor_gc_count;
632         gulong major_gc_count;
633         gulong minor_gc_time_usecs;
634         gulong major_gc_time_usecs;
635         gboolean enabled;
636 } MonoStats;
637
638 /* 
639  * new structure to hold performace counters values that are exported
640  * to managed code.
641  * Note: never remove fields from this structure and only add them to the end.
642  * Size of fields and type should not be changed as well.
643  */
644 typedef struct {
645         /* JIT category */
646         guint32 jit_methods;
647         guint32 jit_bytes;
648         guint32 jit_time;
649         guint32 jit_failures;
650         /* Exceptions category */
651         guint32 exceptions_thrown;
652         guint32 exceptions_filters;
653         guint32 exceptions_finallys;
654         guint32 exceptions_depth;
655         guint32 aspnet_requests_queued;
656         guint32 aspnet_requests;
657         /* Memory category */
658         guint32 gc_collections0;
659         guint32 gc_collections1;
660         guint32 gc_collections2;
661         guint32 gc_promotions0;
662         guint32 gc_promotions1;
663         guint32 gc_promotion_finalizers;
664         guint32 gc_gen0size;
665         guint32 gc_gen1size;
666         guint32 gc_gen2size;
667         guint32 gc_lossize;
668         guint32 gc_fin_survivors;
669         guint32 gc_num_handles;
670         guint32 gc_allocated;
671         guint32 gc_induced;
672         guint32 gc_time;
673         guint32 gc_total_bytes;
674         guint32 gc_committed_bytes;
675         guint32 gc_reserved_bytes;
676         guint32 gc_num_pinned;
677         guint32 gc_sync_blocks;
678         /* Remoting category */
679         guint32 remoting_calls;
680         guint32 remoting_channels;
681         guint32 remoting_proxies;
682         guint32 remoting_classes;
683         guint32 remoting_objects;
684         guint32 remoting_contexts;
685         /* Loader category */
686         guint32 loader_classes;
687         guint32 loader_total_classes;
688         guint32 loader_appdomains;
689         guint32 loader_total_appdomains;
690         guint32 loader_assemblies;
691         guint32 loader_total_assemblies;
692         guint32 loader_failures;
693         guint32 loader_bytes;
694         guint32 loader_appdomains_uloaded;
695         /* Threads and Locks category  */
696         guint32 thread_contentions;
697         guint32 thread_queue_len;
698         guint32 thread_queue_max;
699         guint32 thread_num_logical;
700         guint32 thread_num_physical;
701         guint32 thread_cur_recognized;
702         guint32 thread_num_recognized;
703         /* Interop category */
704         guint32 interop_num_ccw;
705         guint32 interop_num_stubs;
706         guint32 interop_num_marshals;
707         /* Security category */
708         guint32 security_num_checks;
709         guint32 security_num_link_checks;
710         guint32 security_time;
711         guint32 security_depth;
712         guint32 unused;
713 } MonoPerfCounters;
714
715 extern MonoPerfCounters *mono_perfcounters MONO_INTERNAL;
716
717 void mono_perfcounters_init (void);
718
719 /*
720  * The definition of the first field in SafeHandle,
721  * Keep in sync with SafeHandle.cs, this is only used
722  * to access the `handle' parameter.
723  */
724 typedef struct {
725         MonoObject  base;
726         void       *handle;
727 } MonoSafeHandle;
728
729 /*
730  * Keep in sync with HandleRef.cs
731  */
732 typedef struct {
733         MonoObject *wrapper;
734         void       *handle;
735 } MonoHandleRef;
736
737 enum {
738         MONO_GENERIC_SHARING_NONE,
739         MONO_GENERIC_SHARING_COLLECTIONS,
740         MONO_GENERIC_SHARING_CORLIB,
741         MONO_GENERIC_SHARING_ALL
742 };
743
744 /*
745  * Flags for which contexts were used in inflating a generic.
746  */
747 enum {
748         MONO_GENERIC_CONTEXT_USED_CLASS = 1,
749         MONO_GENERIC_CONTEXT_USED_METHOD = 2
750 };
751
752 #define MONO_GENERIC_CONTEXT_USED_BOTH          (MONO_GENERIC_CONTEXT_USED_CLASS | MONO_GENERIC_CONTEXT_USED_METHOD)
753
754 extern MonoStats mono_stats MONO_INTERNAL;
755
756 typedef gpointer (*MonoTrampoline)       (MonoMethod *method);
757 typedef gpointer (*MonoJumpTrampoline)       (MonoDomain *domain, MonoMethod *method, gboolean add_sync_wrapper);
758 typedef gpointer (*MonoRemotingTrampoline)       (MonoDomain *domain, MonoMethod *method, MonoRemotingTarget target);
759 typedef gpointer (*MonoDelegateTrampoline)       (MonoClass *klass);
760
761 typedef gpointer (*MonoLookupDynamicToken) (MonoImage *image, guint32 token, gboolean valid_token, MonoClass **handle_class, MonoGenericContext *context);
762
763 typedef gboolean (*MonoGetCachedClassInfo) (MonoClass *klass, MonoCachedClassInfo *res);
764
765 typedef gboolean (*MonoGetClassFromName) (MonoImage *image, const char *name_space, const char *name, MonoClass **res);
766
767 void
768 mono_classes_init (void) MONO_INTERNAL;
769
770 void
771 mono_classes_cleanup (void) MONO_INTERNAL;
772
773 void
774 mono_class_layout_fields   (MonoClass *klass) MONO_INTERNAL;
775
776 void
777 mono_class_setup_interface_offsets (MonoClass *klass) MONO_INTERNAL;
778
779 void
780 mono_class_setup_vtable_general (MonoClass *klass, MonoMethod **overrides, int onum) MONO_INTERNAL;
781
782 void
783 mono_class_setup_vtable (MonoClass *klass) MONO_INTERNAL;
784
785 void
786 mono_class_setup_methods (MonoClass *klass) MONO_INTERNAL;
787
788 void
789 mono_class_setup_mono_type (MonoClass *klass) MONO_INTERNAL;
790
791 void
792 mono_class_setup_parent    (MonoClass *klass, MonoClass *parent) MONO_INTERNAL;
793
794 void
795 mono_class_setup_supertypes (MonoClass *klass) MONO_INTERNAL;
796
797 MonoMethod*
798 mono_class_get_method_by_index (MonoClass *class, int index) MONO_INTERNAL;
799
800 MonoMethod*
801 mono_class_get_inflated_method (MonoClass *class, MonoMethod *method) MONO_INTERNAL;
802
803 MonoMethod*
804 mono_class_get_vtable_entry (MonoClass *class, int offset) MONO_INTERNAL;
805
806 GPtrArray*
807 mono_class_get_implemented_interfaces (MonoClass *klass) MONO_INTERNAL;
808
809 gboolean
810 mono_class_is_open_constructed_type (MonoType *t) MONO_INTERNAL;
811
812 gboolean
813 mono_class_get_overrides_full (MonoImage *image, guint32 type_token, MonoMethod ***overrides, gint32 *num_overrides,
814                                MonoGenericContext *generic_context) MONO_INTERNAL;
815
816 MonoMethod*
817 mono_class_get_cctor (MonoClass *klass) MONO_INTERNAL;
818
819 MonoMethod*
820 mono_class_get_finalizer (MonoClass *klass) MONO_INTERNAL;
821
822 gboolean
823 mono_class_needs_cctor_run (MonoClass *klass, MonoMethod *caller) MONO_INTERNAL;
824
825 gboolean
826 mono_class_field_is_special_static (MonoClassField *field) MONO_INTERNAL;
827
828 gboolean
829 mono_class_has_special_static_fields (MonoClass *klass) MONO_INTERNAL;
830
831 const char*
832 mono_class_get_field_default_value (MonoClassField *field, MonoTypeEnum *def_type) MONO_INTERNAL;
833
834 void
835 mono_install_trampoline (MonoTrampoline func) MONO_INTERNAL;
836
837 void
838 mono_install_jump_trampoline (MonoJumpTrampoline func) MONO_INTERNAL;
839
840 void
841 mono_install_remoting_trampoline (MonoRemotingTrampoline func) MONO_INTERNAL;
842
843 void
844 mono_install_delegate_trampoline (MonoDelegateTrampoline func) MONO_INTERNAL;
845
846 gpointer
847 mono_lookup_dynamic_token (MonoImage *image, guint32 token, MonoGenericContext *context) MONO_INTERNAL;
848
849 gpointer
850 mono_lookup_dynamic_token_class (MonoImage *image, guint32 token, gboolean check_token, MonoClass **handle_class, MonoGenericContext *context) MONO_INTERNAL;
851
852 void
853 mono_install_lookup_dynamic_token (MonoLookupDynamicToken func) MONO_INTERNAL;
854
855 gpointer
856 mono_runtime_create_jump_trampoline (MonoDomain *domain, MonoMethod *method, gboolean add_sync_wrapper) MONO_INTERNAL;
857
858 gpointer
859 mono_runtime_create_delegate_trampoline (MonoClass *klass) MONO_INTERNAL;
860
861 void
862 mono_install_get_cached_class_info (MonoGetCachedClassInfo func) MONO_INTERNAL;
863
864 void
865 mono_install_get_class_from_name (MonoGetClassFromName func) MONO_INTERNAL;
866
867 MonoGenericContext*
868 mono_class_get_context (MonoClass *class) MONO_INTERNAL;
869
870 MonoGenericContext*
871 mono_method_get_context_general (MonoMethod *method, gboolean uninflated) MONO_INTERNAL;
872
873 MonoGenericContext*
874 mono_method_get_context (MonoMethod *method) MONO_INTERNAL;
875
876 /* Used by monodis, thus cannot be MONO_INTERNAL */
877 MonoGenericContainer*
878 mono_method_get_generic_container (MonoMethod *method);
879
880 MonoGenericContext*
881 mono_generic_class_get_context (MonoGenericClass *gclass) MONO_INTERNAL;
882
883 MonoClass*
884 mono_generic_class_get_class (MonoGenericClass *gclass) MONO_INTERNAL;
885
886 void
887 mono_method_set_generic_container (MonoMethod *method, MonoGenericContainer* container) MONO_INTERNAL;
888
889 MonoMethod*
890 mono_class_inflate_generic_method_full (MonoMethod *method, MonoClass *klass_hint, MonoGenericContext *context);
891
892 MonoMethodInflated*
893 mono_method_inflated_lookup (MonoMethodInflated* method, gboolean cache) MONO_INTERNAL;
894
895 MonoMethodSignature *
896 mono_metadata_get_inflated_signature (MonoMethodSignature *sig, MonoGenericContext *context);
897
898 MonoType*
899 mono_class_inflate_generic_type_with_mempool (MonoImage *image, MonoType *type, MonoGenericContext *context) MONO_INTERNAL;
900
901 MonoClass*
902 mono_class_inflate_generic_class (MonoClass *gklass, MonoGenericContext *context) MONO_INTERNAL;
903
904 void
905 mono_metadata_free_inflated_signature (MonoMethodSignature *sig);
906
907 typedef struct {
908         MonoImage *corlib;
909         MonoClass *object_class;
910         MonoClass *byte_class;
911         MonoClass *void_class;
912         MonoClass *boolean_class;
913         MonoClass *sbyte_class;
914         MonoClass *int16_class;
915         MonoClass *uint16_class;
916         MonoClass *int32_class;
917         MonoClass *uint32_class;
918         MonoClass *int_class;
919         MonoClass *uint_class;
920         MonoClass *int64_class;
921         MonoClass *uint64_class;
922         MonoClass *single_class;
923         MonoClass *double_class;
924         MonoClass *char_class;
925         MonoClass *string_class;
926         MonoClass *enum_class;
927         MonoClass *array_class;
928         MonoClass *delegate_class;
929         MonoClass *multicastdelegate_class;
930         MonoClass *asyncresult_class;
931         MonoClass *waithandle_class;
932         MonoClass *typehandle_class;
933         MonoClass *fieldhandle_class;
934         MonoClass *methodhandle_class;
935         MonoClass *systemtype_class;
936         MonoClass *monotype_class;
937         MonoClass *exception_class;
938         MonoClass *threadabortexception_class;
939         MonoClass *thread_class;
940         MonoClass *transparent_proxy_class;
941         MonoClass *real_proxy_class;
942         MonoClass *mono_method_message_class;
943         MonoClass *appdomain_class;
944         MonoClass *field_info_class;
945         MonoClass *method_info_class;
946         MonoClass *stringbuilder_class;
947         MonoClass *math_class;
948         MonoClass *stack_frame_class;
949         MonoClass *stack_trace_class;
950         MonoClass *marshal_class;
951         MonoClass *iserializeable_class;
952         MonoClass *serializationinfo_class;
953         MonoClass *streamingcontext_class;
954         MonoClass *typed_reference_class;
955         MonoClass *argumenthandle_class;
956         MonoClass *marshalbyrefobject_class;
957         MonoClass *monitor_class;
958         MonoClass *iremotingtypeinfo_class;
959         MonoClass *runtimesecurityframe_class;
960         MonoClass *executioncontext_class;
961         MonoClass *internals_visible_class;
962         MonoClass *generic_ilist_class;
963         MonoClass *generic_nullable_class;
964         MonoClass *variant_class;
965         MonoClass *com_object_class;
966         MonoClass *com_interop_proxy_class;
967         MonoClass *iunknown_class;
968         MonoClass *idispatch_class;
969         MonoClass *safehandle_class;
970         MonoClass *handleref_class;
971         MonoClass *attribute_class;
972         MonoClass *customattribute_data_class;
973 } MonoDefaults;
974
975 extern MonoDefaults mono_defaults MONO_INTERNAL;
976
977 void
978 mono_loader_init           (void) MONO_INTERNAL;
979
980 void
981 mono_loader_cleanup        (void) MONO_INTERNAL;
982
983 void
984 mono_loader_lock           (void) MONO_INTERNAL;
985
986 void
987 mono_loader_unlock         (void) MONO_INTERNAL;
988
989 void
990 mono_loader_set_error_assembly_load (const char *assembly_name, gboolean ref_only) MONO_INTERNAL;
991
992 void
993 mono_loader_set_error_type_load (const char *class_name, const char *assembly_name) MONO_INTERNAL;
994
995 void
996 mono_loader_set_error_method_load (const char *class_name, const char *member_name) MONO_INTERNAL;
997
998 void
999 mono_loader_set_error_field_load (MonoClass *klass, const char *member_name) MONO_INTERNAL;
1000 void
1001 mono_loader_set_error_bad_image (char *msg) MONO_INTERNAL;
1002
1003 MonoException *
1004 mono_loader_error_prepare_exception (MonoLoaderError *error) MONO_INTERNAL;
1005
1006 MonoLoaderError *
1007 mono_loader_get_last_error (void) MONO_INTERNAL;
1008
1009 void
1010 mono_loader_clear_error    (void) MONO_INTERNAL;
1011
1012 void
1013 mono_reflection_init       (void) MONO_INTERNAL;
1014
1015 void
1016 mono_icall_init            (void) MONO_INTERNAL;
1017
1018 void
1019 mono_icall_cleanup         (void) MONO_INTERNAL;
1020
1021 gpointer
1022 mono_method_get_wrapper_data (MonoMethod *method, guint32 id) MONO_INTERNAL;
1023
1024 void
1025 mono_install_stack_walk (MonoStackWalkImpl func) MONO_INTERNAL;
1026
1027 gboolean
1028 mono_metadata_has_generic_params (MonoImage *image, guint32 token) MONO_INTERNAL;
1029
1030 MonoGenericContainer *
1031 mono_metadata_load_generic_params (MonoImage *image, guint32 token,
1032                                    MonoGenericContainer *parent_container);
1033
1034 void
1035 mono_metadata_load_generic_param_constraints (MonoImage *image, guint32 token,
1036                                               MonoGenericContainer *container);
1037
1038 MonoMethodSignature*
1039 mono_create_icall_signature (const char *sigstr) MONO_INTERNAL;
1040
1041 MonoJitICallInfo *
1042 mono_register_jit_icall (gconstpointer func, const char *name, MonoMethodSignature *sig, gboolean is_save) MONO_INTERNAL;
1043
1044 void
1045 mono_register_jit_icall_wrapper (MonoJitICallInfo *info, gconstpointer wrapper) MONO_INTERNAL;
1046
1047 MonoJitICallInfo *
1048 mono_find_jit_icall_by_name (const char *name) MONO_INTERNAL;
1049
1050 MonoJitICallInfo *
1051 mono_find_jit_icall_by_addr (gconstpointer addr) MONO_INTERNAL;
1052
1053 GHashTable*
1054 mono_get_jit_icall_info (void) MONO_INTERNAL;
1055
1056 gboolean
1057 mono_class_set_failure (MonoClass *klass, guint32 ex_type, void *ex_data) MONO_INTERNAL;
1058
1059 gpointer
1060 mono_class_get_exception_data (MonoClass *klass) MONO_INTERNAL;
1061
1062 MonoException*
1063 mono_class_get_exception_for_failure (MonoClass *klass) MONO_INTERNAL;
1064
1065 char*
1066 mono_type_get_name_full (MonoType *type, MonoTypeNameFormat format) MONO_INTERNAL;
1067
1068 char*
1069 mono_type_get_full_name (MonoClass *class) MONO_INTERNAL;
1070
1071 MonoArrayType *mono_dup_array_type (MonoImage *image, MonoArrayType *a) MONO_INTERNAL;
1072 MonoMethodSignature *mono_metadata_signature_deep_dup (MonoImage *image, MonoMethodSignature *sig) MONO_INTERNAL;
1073
1074 void
1075 mono_image_init_name_cache (MonoImage *image);
1076
1077 gboolean mono_class_is_nullable (MonoClass *klass) MONO_INTERNAL;
1078 MonoClass *mono_class_get_nullable_param (MonoClass *klass) MONO_INTERNAL;
1079
1080 /* object debugging functions, for use inside gdb */
1081 void mono_object_describe        (MonoObject *obj);
1082 void mono_object_describe_fields (MonoObject *obj);
1083 void mono_value_describe_fields  (MonoClass* klass, const char* addr);
1084 void mono_class_describe_statics (MonoClass* klass);
1085
1086 /*Enum validation related functions*/
1087 gboolean
1088 mono_type_is_valid_enum_basetype (MonoType * type);
1089
1090 gboolean
1091 mono_class_is_valid_enum (MonoClass *klass);
1092
1093 MonoType *
1094 mono_type_get_full        (MonoImage *image, guint32 type_token, MonoGenericContext *context) MONO_INTERNAL;
1095
1096 gboolean
1097 mono_generic_class_is_generic_type_definition (MonoGenericClass *gklass) MONO_INTERNAL;
1098
1099 MonoMethod*
1100 mono_method_get_declaring_generic_method (MonoMethod *method) MONO_INTERNAL;
1101
1102 MonoMethod*
1103 mono_class_get_method_generic (MonoClass *klass, MonoMethod *method) MONO_INTERNAL;
1104
1105 MonoType*
1106 mono_type_get_basic_type_from_generic (MonoType *type) MONO_INTERNAL;
1107
1108 gboolean
1109 mono_class_generic_sharing_enabled (MonoClass *class) MONO_INTERNAL;
1110
1111 gpointer
1112 mono_class_fill_runtime_generic_context (MonoVTable *class_vtable, guint32 slot) MONO_INTERNAL;
1113
1114 gpointer
1115 mono_method_fill_runtime_generic_context (MonoMethodRuntimeGenericContext *mrgctx, guint32 slot) MONO_INTERNAL;
1116
1117 MonoMethodRuntimeGenericContext*
1118 mono_method_lookup_rgctx (MonoVTable *class_vtable, MonoGenericInst *method_inst) MONO_INTERNAL;
1119
1120 gboolean
1121 mono_method_needs_static_rgctx_invoke (MonoMethod *method, gboolean allow_type_vars) MONO_INTERNAL;
1122
1123 int
1124 mono_class_rgctx_get_array_size (int n, gboolean mrgctx) MONO_INTERNAL;
1125
1126 guint32
1127 mono_method_lookup_or_register_other_info (MonoMethod *method, gboolean in_mrgctx, gpointer data,
1128         int info_type, MonoGenericContext *generic_context) MONO_INTERNAL;
1129
1130 MonoGenericContext
1131 mono_method_construct_object_context (MonoMethod *method) MONO_INTERNAL;
1132
1133 int
1134 mono_generic_context_check_used (MonoGenericContext *context) MONO_INTERNAL;
1135
1136 int
1137 mono_class_check_context_used (MonoClass *class) MONO_INTERNAL;
1138
1139 gboolean
1140 mono_generic_context_is_sharable (MonoGenericContext *context, gboolean allow_type_vars) MONO_INTERNAL;
1141
1142 gboolean
1143 mono_method_is_generic_impl (MonoMethod *method) MONO_INTERNAL;
1144 gboolean
1145 mono_method_is_generic_sharable_impl (MonoMethod *method, gboolean allow_type_vars) MONO_INTERNAL;
1146
1147 void
1148 mono_class_unregister_image_generic_subclasses (MonoImage *image) MONO_INTERNAL;
1149
1150 gboolean
1151 mono_method_can_access_method_full (MonoMethod *method, MonoMethod *called, MonoClass *context_klass) MONO_INTERNAL;
1152
1153 gboolean
1154 mono_method_can_access_field_full (MonoMethod *method, MonoClassField *field, MonoClass *context_klass) MONO_INTERNAL;
1155
1156 MonoClass *
1157 mono_class_get_generic_type_definition (MonoClass *klass) MONO_INTERNAL;
1158
1159 gboolean
1160 mono_class_has_parent_and_ignore_generics (MonoClass *klass, MonoClass *parent) MONO_INTERNAL;
1161
1162 int
1163 mono_method_get_vtable_slot (MonoMethod *method) MONO_INTERNAL;
1164
1165 int
1166 mono_method_get_vtable_index (MonoMethod *method) MONO_INTERNAL;
1167
1168 MonoMethod*
1169 mono_method_search_in_array_class (MonoClass *klass, const char *name, MonoMethodSignature *sig) MONO_INTERNAL;
1170
1171 void
1172 mono_class_setup_interface_id (MonoClass *class) MONO_INTERNAL;
1173
1174 MonoGenericContainer*
1175 mono_class_get_generic_container (MonoClass *klass) MONO_INTERNAL;
1176
1177 MonoGenericClass*
1178 mono_class_get_generic_class (MonoClass *klass) MONO_INTERNAL;
1179
1180 void
1181 mono_class_alloc_ext (MonoClass *klass) MONO_INTERNAL;
1182
1183 void
1184 mono_class_setup_interfaces (MonoClass *klass) MONO_INTERNAL;
1185
1186 #endif /* __MONO_METADATA_CLASS_INTERBALS_H__ */