1 #ifndef __MONO_METADATA_CLASS_INTERBALS_H__
2 #define __MONO_METADATA_CLASS_INTERBALS_H__
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"
9 #define MONO_CLASS_IS_ARRAY(c) ((c)->rank)
11 #define MONO_DEFAULT_SUPERTABLE_SIZE 6
13 extern gboolean mono_print_vtable;
15 typedef void (*MonoStackWalkImpl) (MonoStackWalk func, gboolean do_il_offset, gpointer user_data);
17 typedef struct _MonoMethodNormal MonoMethodNormal;
18 typedef struct _MonoMethodWrapper MonoMethodWrapper;
19 typedef struct _MonoMethodInflated MonoMethodInflated;
20 typedef struct _MonoMethodPInvoke MonoMethodPInvoke;
23 * remember to update wrapper_type_names if you change something here
27 MONO_WRAPPER_DELEGATE_INVOKE,
28 MONO_WRAPPER_DELEGATE_BEGIN_INVOKE,
29 MONO_WRAPPER_DELEGATE_END_INVOKE,
30 MONO_WRAPPER_RUNTIME_INVOKE,
31 MONO_WRAPPER_NATIVE_TO_MANAGED,
32 MONO_WRAPPER_MANAGED_TO_NATIVE,
33 MONO_WRAPPER_MANAGED_TO_MANAGED,
34 MONO_WRAPPER_REMOTING_INVOKE,
35 MONO_WRAPPER_REMOTING_INVOKE_WITH_CHECK,
36 MONO_WRAPPER_XDOMAIN_INVOKE,
37 MONO_WRAPPER_XDOMAIN_DISPATCH,
40 MONO_WRAPPER_LDFLD_REMOTE,
41 MONO_WRAPPER_STFLD_REMOTE,
42 MONO_WRAPPER_SYNCHRONIZED,
43 MONO_WRAPPER_DYNAMIC_METHOD,
45 MONO_WRAPPER_CASTCLASS,
46 MONO_WRAPPER_PROXY_ISINST,
47 MONO_WRAPPER_STELEMREF,
50 MONO_WRAPPER_WRITE_BARRIER,
52 MONO_WRAPPER_COMINTEROP_INVOKE,
53 MONO_WRAPPER_COMINTEROP
57 MONO_TYPE_NAME_FORMAT_IL,
58 MONO_TYPE_NAME_FORMAT_REFLECTION,
59 MONO_TYPE_NAME_FORMAT_FULL_NAME,
60 MONO_TYPE_NAME_FORMAT_ASSEMBLY_QUALIFIED
64 MONO_REMOTING_TARGET_UNKNOWN,
65 MONO_REMOTING_TARGET_APPDOMAIN,
66 MONO_REMOTING_TARGET_COMINTEROP
70 guint16 flags; /* method flags */
71 guint16 iflags; /* method implementation flags */
74 MonoMethodSignature *signature;
75 MonoGenericContainer *generic_container;
76 /* name is useful mostly for debugging */
78 /* this is used by the inlining algorithm */
79 unsigned int inline_info:1;
80 unsigned int uses_this: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 is_inflated:1; /* whether we're a MonoMethodInflated */
89 struct _MonoMethodNormal {
91 MonoMethodHeader *header;
94 struct _MonoMethodWrapper {
95 MonoMethodNormal method;
99 struct _MonoMethodPInvoke {
102 /* add marshal info */
103 guint16 piflags; /* pinvoke flags */
104 guint16 implmap_idx; /* index into IMPLMAP */
108 * Inflated generic method.
110 struct _MonoMethodInflated {
113 MonoMethodNormal normal;
114 MonoMethodPInvoke pinvoke;
116 MonoGenericContext *context; /* The current context. */
117 MonoMethod *declaring; /* the generic method definition. */
121 MonoType *generic_type;
122 gpointer reflection_info;
126 * MonoClassField is just a runtime representation of the metadata for
127 * field, it doesn't contain the data directly. Static fields are
128 * stored in MonoVTable->data. Instance fields are allocated in the
129 * objects after the object header.
131 struct _MonoClassField {
132 /* Type of the field */
135 /* If this is an instantiated generic type, this is the
136 * "original" type, ie. the MONO_TYPE_VAR or MONO_TYPE_GENERICINST
137 * it was instantiated from.
139 MonoInflatedField *generic_info;
142 * Offset where this field is stored; if it is an instance
143 * field, it's the offset from the start of the object, if
144 * it's static, it's from the start of the memory chunk
145 * allocated for statics for the class.
152 * If the field is constant, pointer to the metadata constant
154 * If the field has an RVA flag, pointer to the data.
159 /* Type where the field was defined */
163 * If the field is constant, the type of the constant.
165 MonoTypeEnum def_type;
168 /* a field is ignored if it's named "_Deleted" and it has the specialname and rtspecialname flags set */
169 #define mono_field_is_deleted(field) (((field)->type->attrs & (FIELD_ATTRIBUTE_SPECIAL_NAME | FIELD_ATTRIBUTE_RT_SPECIAL_NAME)) \
170 && (strcmp ((field)->name, "_Deleted") == 0))
173 MonoClassField *field;
175 MonoMarshalSpec *mspec;
181 MonoMethod *ptr_to_str;
182 MonoMethod *str_to_ptr;
183 MonoMarshalField fields [MONO_ZERO_LEN_ARRAY];
186 struct _MonoProperty {
204 /* type of exception being "on hold" for later processing (see exception_type) */
206 MONO_EXCEPTION_NONE = 0,
207 MONO_EXCEPTION_SECURITY_LINKDEMAND = 1,
208 MONO_EXCEPTION_SECURITY_INHERITANCEDEMAND = 2,
209 MONO_EXCEPTION_INVALID_PROGRAM = 3,
210 MONO_EXCEPTION_UNVERIFIABLE_IL = 4,
211 MONO_EXCEPTION_MISSING_METHOD = 5,
212 MONO_EXCEPTION_MISSING_FIELD = 6,
213 MONO_EXCEPTION_TYPE_LOAD = 7
214 /* add other exception type */
217 /* This struct collects the info needed for the runtime use of a class,
218 * like the vtables for a domain, the GC descriptor, etc.
222 /* domain_vtables is indexed by the domain id and the size is max_domain + 1 */
223 MonoVTable *domain_vtables [MONO_ZERO_LEN_ARRAY];
224 } MonoClassRuntimeInfo;
229 /* The underlying type of the enum */
230 MonoType *enum_basetype;
231 /* element class for arrays and enum */
232 MonoClass *element_class;
233 /* used for subtype checks */
234 MonoClass *cast_class;
235 /* array dimension */
239 /* We use init_pending to detect cyclic calls to mono_class_init */
240 guint init_pending : 1;
242 /* A class contains static and non static data. Static data can be
243 * of the same type as the class itselfs, but it does not influence
244 * the instance size of the class. To avoid cyclic calls to
245 * mono_class_init (from mono_class_instance_size ()) we first
246 * initialise all non static fields. After that we set size_inited
247 * to 1, because we know the instance size now. After that we
248 * initialise all static fields.
250 guint size_inited : 1;
251 guint valuetype : 1; /* derives from System.ValueType */
252 guint enumtype : 1; /* derives from System.Enum */
253 guint blittable : 1; /* class is blittable */
254 guint unicode : 1; /* class uses unicode char when marshalled */
255 guint wastypebuilder : 1; /* class was created at runtime from a TypeBuilder */
258 guint packing_size : 4;
260 guint ghcimpl : 1; /* class has its own GetHashCode impl */
261 guint has_finalize : 1; /* class has its own Finalize impl */
262 guint marshalbyref : 1; /* class is a MarshalByRefObject */
263 guint contextbound : 1; /* class is a ContextBoundObject */
264 guint delegate : 1; /* class is a Delegate */
265 guint gc_descr_inited : 1; /* gc_descr is initialized */
266 guint has_cctor : 1; /* class has a cctor */
267 guint has_references : 1; /* it has GC-tracked references in the instance */
269 guint has_static_refs : 1; /* it has static fields that are GC-tracked */
270 guint no_special_static_fields : 1; /* has no thread/context static fields */
271 /* directly or indirectly derives from ComImport attributed class.
272 * this means we need to create a proxy for instances of this class
273 * for COM Interop. set this flag on loading so all we need is a quick check
274 * during object creation rather than having to traverse supertypes
276 guint is_com_object : 1;
278 guint8 exception_type; /* MONO_EXCEPTION_* */
279 void* exception_data; /* Additional information about the exception */
280 guint32 declsec_flags; /* declarative security attributes flags */
283 MonoClass *nested_in;
284 GList *nested_classes;
288 const char *name_space;
290 /* for fast subtype checks */
291 MonoClass **supertypes;
294 guint16 interface_count;
295 guint16 interface_id; /* unique inderface id (for interfaces) */
296 guint16 max_interface_id;
297 gint *interface_offsets;
298 MonoClass **interfaces;
301 * Computed object instance size, total.
305 int vtable_size; /* number of slots */
308 * From the TypeDef table
312 guint32 first, count;
313 } field, method, property, event;
315 /* loaded on demand */
316 MonoMarshalType *marshal_info;
319 * Field information: Type and location from object base
321 MonoClassField *fields;
323 /* Initialized by a call to mono_class_setup_properties () */
324 MonoProperty *properties;
326 /* Initialized by a call to mono_class_setup_events () */
329 MonoMethod **methods;
331 /* used as the type of the this argument and when passing the arg by value */
335 MonoGenericClass *generic_class;
336 MonoGenericContainer *generic_container;
338 void *reflection_info;
342 MonoClassRuntimeInfo *runtime_info;
344 /* Generic vtable. Initialized by a call to mono_class_setup_vtable () */
348 /* the interface_offsets array is stored in memory before this struct */
352 * According to comments in gc_gcj.h, this should be the second word in
356 MonoDomain *domain; /* each object/vtable belongs to exactly one domain */
357 gpointer data; /* to store static class data */
358 gpointer type; /* System.Type type for klass */
359 guint16 max_interface_id;
361 guint remote : 1; /* class is remotely activated */
362 guint initialized : 1; /* cctor has been run */
363 /* do not add any fields after vtable, the structure is dynamically extended */
364 gpointer vtable [MONO_ZERO_LEN_ARRAY];
368 * Generic instantiation data type encoding.
372 * A particular generic instantiation:
374 * All instantiations are cached and we don't distinguish between class and method
375 * instantiations here.
377 struct _MonoGenericInst {
378 guint id; /* unique ID for debugging */
379 guint type_argc : 22; /* number of type arguments */
380 guint is_open : 1; /* if this is an open type */
381 guint is_reference : 1; /* if this is a reference type */
382 MonoType **type_argv;
386 * A particular instantiation of a generic type.
388 struct _MonoGenericClass {
389 MonoGenericInst *inst; /* the instantiation */
390 MonoClass *container_class; /* the generic type definition */
391 MonoGenericContext *context; /* current context */
392 guint is_dynamic : 1; /* We're a MonoDynamicGenericClass */
393 guint is_inflated : 1; /* We're a MonoInflatedGenericClass */
397 * Performance optimization:
398 * We don't create the `MonoClass' for a `MonoGenericClass' until we really
401 struct _MonoInflatedGenericClass {
402 MonoGenericClass generic_class;
403 guint is_initialized : 1;
408 * This is used when instantiating a generic type definition which is
411 struct _MonoDynamicGenericClass {
412 MonoInflatedGenericClass generic_class;
414 MonoMethod **methods;
418 MonoClassField *fields;
419 int count_properties;
420 MonoProperty *properties;
427 * A particular instantiation of a generic method.
429 struct _MonoGenericMethod {
430 MonoGenericInst *inst; /* the instantiation */
431 MonoGenericClass *generic_class; /* if we're in a generic type */
432 MonoGenericContainer *container; /* type parameters */
433 gpointer reflection_info;
437 * The generic context.
439 struct _MonoGenericContext {
441 * The container which has been instantiated.
443 * If we're in a generic method, the generic method definition's container.
444 * Otherwise the generic type's container.
446 MonoGenericContainer *container;
447 /* The current generic class */
448 MonoGenericClass *gclass;
449 /* The current generic method */
450 MonoGenericMethod *gmethod;
454 * The generic container.
456 * Stores the type parameters of a generic type definition or a generic method definition.
458 struct _MonoGenericContainer {
459 MonoGenericContext context;
460 /* If we're a generic method definition in a generic type definition,
461 the generic container of the containing class. */
462 MonoGenericContainer *parent;
463 /* If we're a generic method definition, caches all their instantiations. */
464 GHashTable *method_hash;
465 /* If we're a generic type definition, its `MonoClass'. */
468 /* If true, we're a generic method, otherwise a generic type definition. */
469 /* Invariant: parent != NULL => is_method */
471 /* Our type parameters. */
472 MonoGenericParam *type_params;
478 struct _MonoGenericParam {
479 MonoGenericContainer *owner; /* Type or method this parameter was defined in. */
480 MonoClass *pklass; /* The corresponding `MonoClass'. */
481 MonoMethod *method; /* If we're a method type parameter, the method. */
485 MonoClass** constraints; /* NULL means end of list */
489 * Class information which might be cached by the runtime in the AOT file for
490 * example. Caching this allows us to avoid computing a generic vtable
491 * (class->vtable) in most cases, saving time and avoiding creation of lots of
492 * MonoMethod structures.
494 typedef struct MonoCachedClassInfo {
496 guint has_finalize : 1;
499 guint has_nested_classes : 1;
501 guint has_references : 1;
502 guint has_static_refs : 1;
503 guint no_special_static_fields : 1;
505 MonoImage *finalize_image;
506 guint32 finalize_token;
507 guint32 instance_size;
509 guint32 packing_size;
511 } MonoCachedClassInfo;
516 gconstpointer wrapper;
517 gconstpointer trampoline;
518 MonoMethodSignature *sig;
522 * Information about a type load error encountered by the loader.
525 MONO_LOADER_ERROR_TYPE,
526 MONO_LOADER_ERROR_METHOD,
527 MONO_LOADER_ERROR_FIELD,
528 MONO_LOADER_ERROR_ASSEMBLY
529 } MonoLoaderErrorKind;
532 MonoLoaderErrorKind kind;
533 char *class_name; /* If kind == TYPE */
534 char *assembly_name; /* If kind == TYPE or ASSEMBLY */
535 MonoClass *klass; /* If kind != TYPE */
536 const char *member_name; /* If kind != TYPE */
537 gboolean ref_only; /* If kind == ASSEMBLY */
540 #define mono_class_has_parent(klass,parent) (((klass)->idepth >= (parent)->idepth) && ((klass)->supertypes [(parent)->idepth - 1] == (parent)))
543 gulong new_object_count;
544 gulong initialized_class_count;
545 gulong used_class_count;
546 gulong class_vtable_size;
547 gulong class_static_data_size;
548 gulong generic_instance_count;
549 gulong generic_class_count;
550 gulong inflated_method_count;
551 gulong inflated_method_count_2;
552 gulong inflated_type_count;
553 gulong generics_metadata_size;
557 extern MonoStats mono_stats MONO_INTERNAL;
559 typedef gpointer (*MonoTrampoline) (MonoMethod *method);
560 typedef gpointer (*MonoRemotingTrampoline) (MonoMethod *method, MonoRemotingTarget target);
561 typedef gpointer (*MonoDelegateTrampoline) (MonoMethod *method, gpointer addr);
563 typedef gpointer (*MonoLookupDynamicToken) (MonoImage *image, guint32 token, MonoClass **handle_class);
565 typedef gboolean (*MonoGetCachedClassInfo) (MonoClass *klass, MonoCachedClassInfo *res);
568 mono_classes_init (void) MONO_INTERNAL;
571 mono_classes_cleanup (void) MONO_INTERNAL;
574 mono_class_layout_fields (MonoClass *klass) MONO_INTERNAL;
577 mono_class_setup_interface_offsets (MonoClass *klass) MONO_INTERNAL;
580 mono_class_setup_vtable_general (MonoClass *klass, MonoMethod **overrides, int onum) MONO_INTERNAL;
583 mono_class_setup_vtable (MonoClass *klass) MONO_INTERNAL;
586 mono_class_setup_methods (MonoClass *klass) MONO_INTERNAL;
589 mono_class_setup_mono_type (MonoClass *klass) MONO_INTERNAL;
592 mono_class_setup_parent (MonoClass *klass, MonoClass *parent) MONO_INTERNAL;
595 mono_class_setup_supertypes (MonoClass *klass) MONO_INTERNAL;
598 mono_class_get_implemented_interfaces (MonoClass *klass) MONO_INTERNAL;
601 mono_class_is_open_constructed_type (MonoType *t) MONO_INTERNAL;
604 mono_class_get_overrides_full (MonoImage *image, guint32 type_token, MonoMethod ***overrides, gint32 *num_overrides,
605 MonoGenericContext *generic_context) MONO_INTERNAL;
608 mono_class_get_cctor (MonoClass *klass) MONO_INTERNAL;
611 mono_class_get_finalizer (MonoClass *klass) MONO_INTERNAL;
614 mono_class_needs_cctor_run (MonoClass *klass, MonoMethod *caller) MONO_INTERNAL;
617 mono_class_has_special_static_fields (MonoClass *klass) MONO_INTERNAL;
620 mono_install_trampoline (MonoTrampoline func) MONO_INTERNAL;
623 mono_install_remoting_trampoline (MonoRemotingTrampoline func) MONO_INTERNAL;
626 mono_install_delegate_trampoline (MonoDelegateTrampoline func) MONO_INTERNAL;
629 mono_lookup_dynamic_token (MonoImage *image, guint32 token) MONO_INTERNAL;
632 mono_lookup_dynamic_token_class (MonoImage *image, guint32 token, MonoClass **handle_class) MONO_INTERNAL;
635 mono_install_lookup_dynamic_token (MonoLookupDynamicToken func) MONO_INTERNAL;
638 mono_install_get_cached_class_info (MonoGetCachedClassInfo func) MONO_INTERNAL;
640 MonoInflatedGenericClass*
641 mono_get_inflated_generic_class (MonoGenericClass *gclass) MONO_INTERNAL;
644 mono_class_inflate_generic_method_full (MonoMethod *method, MonoClass *klass_hint, MonoGenericContext *context);
649 MonoClass *object_class;
650 MonoClass *byte_class;
651 MonoClass *void_class;
652 MonoClass *boolean_class;
653 MonoClass *sbyte_class;
654 MonoClass *int16_class;
655 MonoClass *uint16_class;
656 MonoClass *int32_class;
657 MonoClass *uint32_class;
658 MonoClass *int_class;
659 MonoClass *uint_class;
660 MonoClass *int64_class;
661 MonoClass *uint64_class;
662 MonoClass *single_class;
663 MonoClass *double_class;
664 MonoClass *char_class;
665 MonoClass *string_class;
666 MonoClass *enum_class;
667 MonoClass *array_class;
668 MonoClass *delegate_class;
669 MonoClass *multicastdelegate_class;
670 MonoClass *asyncresult_class;
671 MonoClass *waithandle_class;
672 MonoClass *typehandle_class;
673 MonoClass *fieldhandle_class;
674 MonoClass *methodhandle_class;
675 MonoClass *systemtype_class;
676 MonoClass *monotype_class;
677 MonoClass *exception_class;
678 MonoClass *threadabortexception_class;
679 MonoClass *thread_class;
680 MonoClass *transparent_proxy_class;
681 MonoClass *real_proxy_class;
682 MonoClass *mono_method_message_class;
683 MonoClass *appdomain_class;
684 MonoClass *field_info_class;
685 MonoClass *method_info_class;
686 MonoClass *stringbuilder_class;
687 MonoClass *math_class;
688 MonoClass *stack_frame_class;
689 MonoClass *stack_trace_class;
690 MonoClass *marshal_class;
691 MonoClass *iserializeable_class;
692 MonoClass *serializationinfo_class;
693 MonoClass *streamingcontext_class;
694 MonoClass *typed_reference_class;
695 MonoClass *argumenthandle_class;
696 MonoClass *marshalbyrefobject_class;
697 MonoClass *monitor_class;
698 MonoClass *iremotingtypeinfo_class;
699 MonoClass *runtimesecurityframe_class;
700 MonoClass *executioncontext_class;
701 MonoClass *internals_visible_class;
702 MonoClass *generic_array_class;
703 MonoClass *generic_nullable_class;
704 MonoClass *variant_class;
705 MonoClass *com_object_class;
708 extern MonoDefaults mono_defaults MONO_INTERNAL;
711 mono_loader_init (void) MONO_INTERNAL;
714 mono_loader_cleanup (void) MONO_INTERNAL;
717 mono_loader_lock (void) MONO_INTERNAL;
720 mono_loader_unlock (void) MONO_INTERNAL;
723 mono_loader_set_error_assembly_load (const char *assembly_name, gboolean ref_only) MONO_INTERNAL;
726 mono_loader_set_error_type_load (const char *class_name, const char *assembly_name) MONO_INTERNAL;
729 mono_loader_set_error_method_load (const char *class_name, const char *member_name) MONO_INTERNAL;
732 mono_loader_set_error_field_load (MonoClass *klass, const char *member_name) MONO_INTERNAL;
735 mono_loader_error_prepare_exception (MonoLoaderError *error) MONO_INTERNAL;
738 mono_loader_get_last_error (void) MONO_INTERNAL;
741 mono_loader_clear_error (void) MONO_INTERNAL;
744 mono_icall_init (void) MONO_INTERNAL;
747 mono_icall_cleanup (void) MONO_INTERNAL;
750 mono_method_get_wrapper_data (MonoMethod *method, guint32 id) MONO_INTERNAL;
753 mono_install_stack_walk (MonoStackWalkImpl func) MONO_INTERNAL;
756 mono_metadata_has_generic_params (MonoImage *image, guint32 token) MONO_INTERNAL;
758 MonoGenericContainer *
759 mono_metadata_load_generic_params (MonoImage *image, guint32 token,
760 MonoGenericContainer *parent_container);
763 mono_metadata_load_generic_param_constraints (MonoImage *image, guint32 token,
764 MonoGenericContainer *container);
767 mono_create_icall_signature (const char *sigstr) MONO_INTERNAL;
770 mono_register_jit_icall (gconstpointer func, const char *name, MonoMethodSignature *sig, gboolean is_save) MONO_INTERNAL;
773 mono_register_jit_icall_wrapper (MonoJitICallInfo *info, gconstpointer wrapper) MONO_INTERNAL;
776 mono_find_jit_icall_by_name (const char *name) MONO_INTERNAL;
779 mono_find_jit_icall_by_addr (gconstpointer addr) MONO_INTERNAL;
782 mono_get_shared_generic_inst (MonoGenericContainer *container) MONO_INTERNAL;
785 mono_get_shared_generic_class (MonoGenericContainer *container, gboolean is_dynamic) MONO_INTERNAL;
788 mono_get_shared_generic_method (MonoGenericContainer *container) MONO_INTERNAL;
791 mono_class_set_failure (MonoClass *klass, guint32 ex_type, void *ex_data) MONO_INTERNAL;
794 mono_class_get_exception_for_failure (MonoClass *klass) MONO_INTERNAL;
797 mono_type_get_name_full (MonoType *type, MonoTypeNameFormat format) MONO_INTERNAL;
800 mono_type_get_full_name (MonoClass *class) MONO_INTERNAL;
802 MonoArrayType *mono_dup_array_type (MonoArrayType *a) MONO_INTERNAL;
803 MonoMethodSignature *mono_metadata_signature_deep_dup (MonoMethodSignature *sig) MONO_INTERNAL;
805 gboolean mono_class_is_nullable (MonoClass *klass) MONO_INTERNAL;
806 MonoClass *mono_class_get_nullable_param (MonoClass *klass) MONO_INTERNAL;
808 #endif /* __MONO_METADATA_CLASS_INTERBALS_H__ */