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