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 */
86 unsigned int skip_visibility:1; /* whenever to skip JIT visibility checks */
90 struct _MonoMethodNormal {
92 MonoMethodHeader *header;
95 struct _MonoMethodWrapper {
96 MonoMethodNormal method;
100 struct _MonoMethodPInvoke {
103 /* add marshal info */
104 guint16 piflags; /* pinvoke flags */
105 guint16 implmap_idx; /* index into IMPLMAP */
109 * Inflated generic method.
111 struct _MonoMethodInflated {
114 MonoMethodNormal normal;
115 MonoMethodPInvoke pinvoke;
117 MonoGenericContext *context; /* The current context. */
118 MonoMethod *declaring; /* the generic method definition. */
122 MonoType *generic_type;
123 gpointer reflection_info;
127 * MonoClassField is just a runtime representation of the metadata for
128 * field, it doesn't contain the data directly. Static fields are
129 * stored in MonoVTable->data. Instance fields are allocated in the
130 * objects after the object header.
132 struct _MonoClassField {
133 /* Type of the field */
136 /* If this is an instantiated generic type, this is the
137 * "original" type, ie. the MONO_TYPE_VAR or MONO_TYPE_GENERICINST
138 * it was instantiated from.
140 MonoInflatedField *generic_info;
143 * Offset where this field is stored; if it is an instance
144 * field, it's the offset from the start of the object, if
145 * it's static, it's from the start of the memory chunk
146 * allocated for statics for the class.
153 * If the field is constant, pointer to the metadata constant
155 * If the field has an RVA flag, pointer to the data.
160 /* Type where the field was defined */
164 * If the field is constant, the type of the constant.
166 MonoTypeEnum def_type;
169 /* a field is ignored if it's named "_Deleted" and it has the specialname and rtspecialname flags set */
170 #define mono_field_is_deleted(field) (((field)->type->attrs & (FIELD_ATTRIBUTE_SPECIAL_NAME | FIELD_ATTRIBUTE_RT_SPECIAL_NAME)) \
171 && (strcmp ((field)->name, "_Deleted") == 0))
174 MonoClassField *field;
176 MonoMarshalSpec *mspec;
182 MonoMethod *ptr_to_str;
183 MonoMethod *str_to_ptr;
184 MonoMarshalField fields [MONO_ZERO_LEN_ARRAY];
187 struct _MonoProperty {
205 /* type of exception being "on hold" for later processing (see exception_type) */
207 MONO_EXCEPTION_NONE = 0,
208 MONO_EXCEPTION_SECURITY_LINKDEMAND = 1,
209 MONO_EXCEPTION_SECURITY_INHERITANCEDEMAND = 2,
210 MONO_EXCEPTION_INVALID_PROGRAM = 3,
211 MONO_EXCEPTION_UNVERIFIABLE_IL = 4,
212 MONO_EXCEPTION_MISSING_METHOD = 5,
213 MONO_EXCEPTION_MISSING_FIELD = 6,
214 MONO_EXCEPTION_TYPE_LOAD = 7
215 /* add other exception type */
218 /* This struct collects the info needed for the runtime use of a class,
219 * like the vtables for a domain, the GC descriptor, etc.
223 /* domain_vtables is indexed by the domain id and the size is max_domain + 1 */
224 MonoVTable *domain_vtables [MONO_ZERO_LEN_ARRAY];
225 } MonoClassRuntimeInfo;
230 /* The underlying type of the enum */
231 MonoType *enum_basetype;
232 /* element class for arrays and enum */
233 MonoClass *element_class;
234 /* used for subtype checks */
235 MonoClass *cast_class;
236 /* array dimension */
240 /* We use init_pending to detect cyclic calls to mono_class_init */
241 guint init_pending : 1;
243 /* A class contains static and non static data. Static data can be
244 * of the same type as the class itselfs, but it does not influence
245 * the instance size of the class. To avoid cyclic calls to
246 * mono_class_init (from mono_class_instance_size ()) we first
247 * initialise all non static fields. After that we set size_inited
248 * to 1, because we know the instance size now. After that we
249 * initialise all static fields.
251 guint size_inited : 1;
252 guint valuetype : 1; /* derives from System.ValueType */
253 guint enumtype : 1; /* derives from System.Enum */
254 guint blittable : 1; /* class is blittable */
255 guint unicode : 1; /* class uses unicode char when marshalled */
256 guint wastypebuilder : 1; /* class was created at runtime from a TypeBuilder */
259 guint packing_size : 4;
261 guint ghcimpl : 1; /* class has its own GetHashCode impl */
262 guint has_finalize : 1; /* class has its own Finalize impl */
263 guint marshalbyref : 1; /* class is a MarshalByRefObject */
264 guint contextbound : 1; /* class is a ContextBoundObject */
265 guint delegate : 1; /* class is a Delegate */
266 guint gc_descr_inited : 1; /* gc_descr is initialized */
267 guint has_cctor : 1; /* class has a cctor */
268 guint has_references : 1; /* it has GC-tracked references in the instance */
270 guint has_static_refs : 1; /* it has static fields that are GC-tracked */
271 guint no_special_static_fields : 1; /* has no thread/context static fields */
272 /* directly or indirectly derives from ComImport attributed class.
273 * this means we need to create a proxy for instances of this class
274 * for COM Interop. set this flag on loading so all we need is a quick check
275 * during object creation rather than having to traverse supertypes
277 guint is_com_object : 1;
278 /* Used to detect cycles in mono_marshal_load_type_info */
279 guint marshal_info_init_pending : 1;
281 guint8 exception_type; /* MONO_EXCEPTION_* */
282 void* exception_data; /* Additional information about the exception */
283 guint32 declsec_flags; /* declarative security attributes flags */
286 MonoClass *nested_in;
287 GList *nested_classes;
291 const char *name_space;
293 /* for fast subtype checks */
294 MonoClass **supertypes;
297 guint16 interface_count;
298 guint16 interface_id; /* unique inderface id (for interfaces) */
299 guint16 max_interface_id;
300 gint *interface_offsets;
301 MonoClass **interfaces;
304 * Computed object instance size, total.
308 int vtable_size; /* number of slots */
311 * From the TypeDef table
315 guint32 first, count;
316 } field, method, property, event;
318 /* loaded on demand */
319 MonoMarshalType *marshal_info;
322 * Field information: Type and location from object base
324 MonoClassField *fields;
326 /* Initialized by a call to mono_class_setup_properties () */
327 MonoProperty *properties;
329 /* Initialized by a call to mono_class_setup_events () */
332 MonoMethod **methods;
334 /* used as the type of the this argument and when passing the arg by value */
338 MonoGenericClass *generic_class;
339 MonoGenericContainer *generic_container;
341 void *reflection_info;
345 MonoClassRuntimeInfo *runtime_info;
347 /* Generic vtable. Initialized by a call to mono_class_setup_vtable () */
351 /* the interface_offsets array is stored in memory before this struct */
355 * According to comments in gc_gcj.h, this should be the second word in
359 MonoDomain *domain; /* each object/vtable belongs to exactly one domain */
360 gpointer data; /* to store static class data */
361 gpointer type; /* System.Type type for klass */
362 guint16 max_interface_id;
364 guint remote : 1; /* class is remotely activated */
365 guint initialized : 1; /* cctor has been run */
366 /* do not add any fields after vtable, the structure is dynamically extended */
367 gpointer vtable [MONO_ZERO_LEN_ARRAY];
371 * Generic instantiation data type encoding.
375 * A particular generic instantiation:
377 * All instantiations are cached and we don't distinguish between class and method
378 * instantiations here.
380 struct _MonoGenericInst {
381 guint id; /* unique ID for debugging */
382 guint type_argc : 22; /* number of type arguments */
383 guint is_open : 1; /* if this is an open type */
384 guint is_reference : 1; /* if this is a reference type */
385 MonoType **type_argv;
389 * A particular instantiation of a generic type.
391 struct _MonoGenericClass {
392 MonoGenericInst *inst; /* the instantiation */
393 MonoClass *container_class; /* the generic type definition */
394 MonoGenericContext *context; /* current context */
395 guint is_dynamic : 1; /* We're a MonoDynamicGenericClass */
396 guint is_inflated : 1; /* We're a MonoInflatedGenericClass */
400 * Performance optimization:
401 * We don't create the `MonoClass' for a `MonoGenericClass' until we really
404 struct _MonoInflatedGenericClass {
405 MonoGenericClass generic_class;
406 guint is_initialized : 1;
411 * This is used when instantiating a generic type definition which is
414 struct _MonoDynamicGenericClass {
415 MonoInflatedGenericClass generic_class;
417 MonoMethod **methods;
421 MonoClassField *fields;
422 int count_properties;
423 MonoProperty *properties;
430 * A particular instantiation of a generic method.
432 struct _MonoGenericMethod {
433 MonoGenericInst *inst; /* the instantiation */
434 MonoGenericClass *generic_class; /* if we're in a generic type */
435 MonoGenericContainer *container; /* type parameters */
436 gpointer reflection_info;
440 * The generic context.
442 struct _MonoGenericContext {
444 * The container which has been instantiated.
446 * If we're in a generic method, the generic method definition's container.
447 * Otherwise the generic type's container.
449 MonoGenericContainer *container;
450 /* The current generic class */
451 MonoGenericClass *gclass;
452 /* The current generic method */
453 MonoGenericMethod *gmethod;
457 * The generic container.
459 * Stores the type parameters of a generic type definition or a generic method definition.
461 struct _MonoGenericContainer {
462 MonoGenericContext context;
463 /* If we're a generic method definition in a generic type definition,
464 the generic container of the containing class. */
465 MonoGenericContainer *parent;
466 /* If we're a generic method definition, caches all their instantiations. */
467 GHashTable *method_hash;
468 /* If we're a generic type definition, its `MonoClass'. */
471 /* If true, we're a generic method, otherwise a generic type definition. */
472 /* Invariant: parent != NULL => is_method */
474 /* Our type parameters. */
475 MonoGenericParam *type_params;
481 struct _MonoGenericParam {
482 MonoGenericContainer *owner; /* Type or method this parameter was defined in. */
483 MonoClass *pklass; /* The corresponding `MonoClass'. */
484 MonoMethod *method; /* If we're a method type parameter, the method. */
488 MonoClass** constraints; /* NULL means end of list */
492 * Class information which might be cached by the runtime in the AOT file for
493 * example. Caching this allows us to avoid computing a generic vtable
494 * (class->vtable) in most cases, saving time and avoiding creation of lots of
495 * MonoMethod structures.
497 typedef struct MonoCachedClassInfo {
499 guint has_finalize : 1;
502 guint has_nested_classes : 1;
504 guint has_references : 1;
505 guint has_static_refs : 1;
506 guint no_special_static_fields : 1;
508 MonoImage *finalize_image;
509 guint32 finalize_token;
510 guint32 instance_size;
512 guint32 packing_size;
514 } MonoCachedClassInfo;
519 gconstpointer wrapper;
520 gconstpointer trampoline;
521 MonoMethodSignature *sig;
525 * Information about a type load error encountered by the loader.
528 MONO_LOADER_ERROR_TYPE,
529 MONO_LOADER_ERROR_METHOD,
530 MONO_LOADER_ERROR_FIELD,
531 MONO_LOADER_ERROR_ASSEMBLY
532 } MonoLoaderErrorKind;
535 MonoLoaderErrorKind kind;
536 char *class_name; /* If kind == TYPE */
537 char *assembly_name; /* If kind == TYPE or ASSEMBLY */
538 MonoClass *klass; /* If kind != TYPE */
539 const char *member_name; /* If kind != TYPE */
540 gboolean ref_only; /* If kind == ASSEMBLY */
543 #define mono_class_has_parent(klass,parent) (((klass)->idepth >= (parent)->idepth) && ((klass)->supertypes [(parent)->idepth - 1] == (parent)))
546 gulong new_object_count;
547 gulong initialized_class_count;
548 gulong generic_vtable_count;
549 gulong used_class_count;
551 gulong class_vtable_size;
552 gulong class_static_data_size;
553 gulong generic_instance_count;
554 gulong generic_class_count;
555 gulong inflated_method_count;
556 gulong inflated_method_count_2;
557 gulong inflated_type_count;
558 gulong generics_metadata_size;
562 extern MonoStats mono_stats MONO_INTERNAL;
564 typedef gpointer (*MonoTrampoline) (MonoMethod *method);
565 typedef gpointer (*MonoRemotingTrampoline) (MonoMethod *method, MonoRemotingTarget target);
566 typedef gpointer (*MonoDelegateTrampoline) (MonoMethod *method, gpointer addr);
568 typedef gpointer (*MonoLookupDynamicToken) (MonoImage *image, guint32 token, MonoClass **handle_class);
570 typedef gboolean (*MonoGetCachedClassInfo) (MonoClass *klass, MonoCachedClassInfo *res);
572 typedef gboolean (*MonoGetClassFromName) (MonoImage *image, const char *name_space, const char *name, MonoClass **res);
575 mono_classes_init (void) MONO_INTERNAL;
578 mono_classes_cleanup (void) MONO_INTERNAL;
581 mono_class_layout_fields (MonoClass *klass) MONO_INTERNAL;
584 mono_class_setup_interface_offsets (MonoClass *klass) MONO_INTERNAL;
587 mono_class_setup_vtable_general (MonoClass *klass, MonoMethod **overrides, int onum) MONO_INTERNAL;
590 mono_class_setup_vtable (MonoClass *klass) MONO_INTERNAL;
593 mono_class_setup_methods (MonoClass *klass) MONO_INTERNAL;
596 mono_class_setup_mono_type (MonoClass *klass) MONO_INTERNAL;
599 mono_class_setup_parent (MonoClass *klass, MonoClass *parent) MONO_INTERNAL;
602 mono_class_setup_supertypes (MonoClass *klass) MONO_INTERNAL;
605 mono_class_get_implemented_interfaces (MonoClass *klass) MONO_INTERNAL;
608 mono_class_is_open_constructed_type (MonoType *t) MONO_INTERNAL;
611 mono_class_get_overrides_full (MonoImage *image, guint32 type_token, MonoMethod ***overrides, gint32 *num_overrides,
612 MonoGenericContext *generic_context) MONO_INTERNAL;
615 mono_class_get_cctor (MonoClass *klass) MONO_INTERNAL;
618 mono_class_get_finalizer (MonoClass *klass) MONO_INTERNAL;
621 mono_class_needs_cctor_run (MonoClass *klass, MonoMethod *caller) MONO_INTERNAL;
624 mono_class_has_special_static_fields (MonoClass *klass) MONO_INTERNAL;
627 mono_install_trampoline (MonoTrampoline func) MONO_INTERNAL;
630 mono_install_remoting_trampoline (MonoRemotingTrampoline func) MONO_INTERNAL;
633 mono_install_delegate_trampoline (MonoDelegateTrampoline func) MONO_INTERNAL;
636 mono_lookup_dynamic_token (MonoImage *image, guint32 token) MONO_INTERNAL;
639 mono_lookup_dynamic_token_class (MonoImage *image, guint32 token, MonoClass **handle_class) MONO_INTERNAL;
642 mono_install_lookup_dynamic_token (MonoLookupDynamicToken func) MONO_INTERNAL;
645 mono_install_get_cached_class_info (MonoGetCachedClassInfo func) MONO_INTERNAL;
648 mono_install_get_class_from_name (MonoGetClassFromName func) MONO_INTERNAL;
650 MonoInflatedGenericClass*
651 mono_get_inflated_generic_class (MonoGenericClass *gclass) MONO_INTERNAL;
654 mono_class_inflate_generic_method_full (MonoMethod *method, MonoClass *klass_hint, MonoGenericContext *context);
659 MonoClass *object_class;
660 MonoClass *byte_class;
661 MonoClass *void_class;
662 MonoClass *boolean_class;
663 MonoClass *sbyte_class;
664 MonoClass *int16_class;
665 MonoClass *uint16_class;
666 MonoClass *int32_class;
667 MonoClass *uint32_class;
668 MonoClass *int_class;
669 MonoClass *uint_class;
670 MonoClass *int64_class;
671 MonoClass *uint64_class;
672 MonoClass *single_class;
673 MonoClass *double_class;
674 MonoClass *char_class;
675 MonoClass *string_class;
676 MonoClass *enum_class;
677 MonoClass *array_class;
678 MonoClass *delegate_class;
679 MonoClass *multicastdelegate_class;
680 MonoClass *asyncresult_class;
681 MonoClass *waithandle_class;
682 MonoClass *typehandle_class;
683 MonoClass *fieldhandle_class;
684 MonoClass *methodhandle_class;
685 MonoClass *systemtype_class;
686 MonoClass *monotype_class;
687 MonoClass *exception_class;
688 MonoClass *threadabortexception_class;
689 MonoClass *thread_class;
690 MonoClass *transparent_proxy_class;
691 MonoClass *real_proxy_class;
692 MonoClass *mono_method_message_class;
693 MonoClass *appdomain_class;
694 MonoClass *field_info_class;
695 MonoClass *method_info_class;
696 MonoClass *stringbuilder_class;
697 MonoClass *math_class;
698 MonoClass *stack_frame_class;
699 MonoClass *stack_trace_class;
700 MonoClass *marshal_class;
701 MonoClass *iserializeable_class;
702 MonoClass *serializationinfo_class;
703 MonoClass *streamingcontext_class;
704 MonoClass *typed_reference_class;
705 MonoClass *argumenthandle_class;
706 MonoClass *marshalbyrefobject_class;
707 MonoClass *monitor_class;
708 MonoClass *iremotingtypeinfo_class;
709 MonoClass *runtimesecurityframe_class;
710 MonoClass *executioncontext_class;
711 MonoClass *internals_visible_class;
712 MonoClass *generic_ilist_class;
713 MonoClass *generic_nullable_class;
714 MonoClass *variant_class;
715 MonoClass *com_object_class;
718 extern MonoDefaults mono_defaults MONO_INTERNAL;
721 mono_loader_init (void) MONO_INTERNAL;
724 mono_loader_cleanup (void) MONO_INTERNAL;
727 mono_loader_lock (void) MONO_INTERNAL;
730 mono_loader_unlock (void) MONO_INTERNAL;
733 mono_loader_set_error_assembly_load (const char *assembly_name, gboolean ref_only) MONO_INTERNAL;
736 mono_loader_set_error_type_load (const char *class_name, const char *assembly_name) MONO_INTERNAL;
739 mono_loader_set_error_method_load (const char *class_name, const char *member_name) MONO_INTERNAL;
742 mono_loader_set_error_field_load (MonoClass *klass, const char *member_name) MONO_INTERNAL;
745 mono_loader_error_prepare_exception (MonoLoaderError *error) MONO_INTERNAL;
748 mono_loader_get_last_error (void) MONO_INTERNAL;
751 mono_loader_clear_error (void) MONO_INTERNAL;
754 mono_icall_init (void) MONO_INTERNAL;
757 mono_icall_cleanup (void) MONO_INTERNAL;
760 mono_method_get_wrapper_data (MonoMethod *method, guint32 id) MONO_INTERNAL;
763 mono_install_stack_walk (MonoStackWalkImpl func) MONO_INTERNAL;
766 mono_metadata_has_generic_params (MonoImage *image, guint32 token) MONO_INTERNAL;
768 MonoGenericContainer *
769 mono_metadata_load_generic_params (MonoImage *image, guint32 token,
770 MonoGenericContainer *parent_container);
773 mono_metadata_load_generic_param_constraints (MonoImage *image, guint32 token,
774 MonoGenericContainer *container);
777 mono_create_icall_signature (const char *sigstr) MONO_INTERNAL;
780 mono_register_jit_icall (gconstpointer func, const char *name, MonoMethodSignature *sig, gboolean is_save) MONO_INTERNAL;
783 mono_register_jit_icall_wrapper (MonoJitICallInfo *info, gconstpointer wrapper) MONO_INTERNAL;
786 mono_find_jit_icall_by_name (const char *name) MONO_INTERNAL;
789 mono_find_jit_icall_by_addr (gconstpointer addr) MONO_INTERNAL;
792 mono_get_shared_generic_inst (MonoGenericContainer *container) MONO_INTERNAL;
795 mono_get_shared_generic_class (MonoGenericContainer *container, gboolean is_dynamic) MONO_INTERNAL;
798 mono_get_shared_generic_method (MonoGenericContainer *container) MONO_INTERNAL;
801 mono_class_set_failure (MonoClass *klass, guint32 ex_type, void *ex_data) MONO_INTERNAL;
804 mono_class_get_exception_for_failure (MonoClass *klass) MONO_INTERNAL;
807 mono_type_get_name_full (MonoType *type, MonoTypeNameFormat format) MONO_INTERNAL;
810 mono_type_get_full_name (MonoClass *class) MONO_INTERNAL;
812 MonoArrayType *mono_dup_array_type (MonoArrayType *a) MONO_INTERNAL;
813 MonoMethodSignature *mono_metadata_signature_deep_dup (MonoMethodSignature *sig) MONO_INTERNAL;
816 mono_image_init_name_cache (MonoImage *image);
818 gboolean mono_class_is_nullable (MonoClass *klass) MONO_INTERNAL;
819 MonoClass *mono_class_get_nullable_param (MonoClass *klass) MONO_INTERNAL;
821 #endif /* __MONO_METADATA_CLASS_INTERBALS_H__ */