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>
8 #define MONO_CLASS_IS_ARRAY(c) ((c)->rank)
10 #define MONO_DEFAULT_SUPERTABLE_SIZE 6
12 extern gboolean mono_print_vtable;
14 typedef void (*MonoStackWalkImpl) (MonoStackWalk func, gboolean do_il_offset, gpointer user_data);
16 typedef struct _MonoMethodNormal MonoMethodNormal;
17 typedef struct _MonoMethodWrapper MonoMethodWrapper;
18 typedef struct _MonoMethodInflated MonoMethodInflated;
19 typedef struct _MonoMethodPInvoke MonoMethodPInvoke;
22 * remember to update wrapper_type_names if you change something here
26 MONO_WRAPPER_DELEGATE_INVOKE,
27 MONO_WRAPPER_DELEGATE_BEGIN_INVOKE,
28 MONO_WRAPPER_DELEGATE_END_INVOKE,
29 MONO_WRAPPER_RUNTIME_INVOKE,
30 MONO_WRAPPER_NATIVE_TO_MANAGED,
31 MONO_WRAPPER_MANAGED_TO_NATIVE,
32 MONO_WRAPPER_REMOTING_INVOKE,
33 MONO_WRAPPER_REMOTING_INVOKE_WITH_CHECK,
34 MONO_WRAPPER_XDOMAIN_INVOKE,
35 MONO_WRAPPER_XDOMAIN_DISPATCH,
38 MONO_WRAPPER_LDFLD_REMOTE,
39 MONO_WRAPPER_STFLD_REMOTE,
40 MONO_WRAPPER_SYNCHRONIZED,
41 MONO_WRAPPER_DYNAMIC_METHOD,
43 MONO_WRAPPER_CASTCLASS,
44 MONO_WRAPPER_PROXY_ISINST,
45 MONO_WRAPPER_STELEMREF,
52 MONO_TYPE_NAME_FORMAT_IL,
53 MONO_TYPE_NAME_FORMAT_REFLECTION,
54 MONO_TYPE_NAME_FORMAT_FULL_NAME,
55 MONO_TYPE_NAME_FORMAT_ASSEMBLY_QUALIFIED
59 MONO_REMOTING_TARGET_UNKNOWN,
60 MONO_REMOTING_TARGET_APPDOMAIN
64 guint16 flags; /* method flags */
65 guint16 iflags; /* method implementation flags */
68 MonoMethodSignature *signature;
69 MonoGenericContainer *generic_container;
70 /* name is useful mostly for debugging */
72 /* this is used by the inlining algorithm */
73 unsigned int inline_info:1;
74 unsigned int uses_this:1;
75 unsigned int wrapper_type:5;
76 unsigned int string_ctor:1;
77 unsigned int save_lmf:1;
78 unsigned int dynamic:1; /* created & destroyed during runtime */
79 unsigned int is_inflated:1; /* whether we're a MonoMethodInflated */
83 struct _MonoMethodNormal {
85 MonoMethodHeader *header;
88 struct _MonoMethodWrapper {
89 MonoMethodNormal method;
93 struct _MonoMethodPInvoke {
96 /* add marshal info */
97 guint16 piflags; /* pinvoke flags */
98 guint16 implmap_idx; /* index into IMPLMAP */
102 * Inflated generic method.
104 struct _MonoMethodInflated {
107 MonoMethodNormal normal;
108 MonoMethodPInvoke pinvoke;
110 MonoGenericContext *context; /* The current context. */
111 MonoMethod *declaring; /* the generic method definition. */
112 /* This is a big performance optimization:
114 * mono_class_inflate_generic_method() just creates a copy of the method
115 * and computes its new context, but it doesn't actually inflate the
116 * method's signature and header. Very often, we don't actually need them
117 * (for instance because the method is stored in a class'es vtable).
119 * If the `inflated' field in non-NULL, mono_get_inflated_method() already
120 * inflated the signature and header and stored it there.
122 MonoMethodInflated *inflated;
126 MonoType *generic_type;
127 gpointer reflection_info;
131 * MonoClassField is just a runtime representation of the metadata for
132 * field, it doesn't contain the data directly. Static fields are
133 * stored in MonoVTable->data. Instance fields are allocated in the
134 * objects after the object header.
136 struct _MonoClassField {
137 /* Type of the field */
140 /* If this is an instantiated generic type, this is the
141 * "original" type, ie. the MONO_TYPE_VAR or MONO_TYPE_GENERICINST
142 * it was instantiated from.
144 MonoInflatedField *generic_info;
147 * Offset where this field is stored; if it is an instance
148 * field, it's the offset from the start of the object, if
149 * it's static, it's from the start of the memory chunk
150 * allocated for statics for the class.
157 * If the field is constant, pointer to the metadata constant
159 * If the field has an RVA flag, pointer to the data.
164 /* Type where the field was defined */
168 * If the field is constant, the type of the constant.
170 MonoTypeEnum def_type;
173 /* a field is ignored if it's named "_Deleted" and it has the specialname and rtspecialname flags set */
174 #define mono_field_is_deleted(field) (((field)->type->attrs & (FIELD_ATTRIBUTE_SPECIAL_NAME | FIELD_ATTRIBUTE_RT_SPECIAL_NAME)) \
175 && (strcmp ((field)->name, "_Deleted") == 0))
178 MonoClassField *field;
180 MonoMarshalSpec *mspec;
186 MonoMethod *ptr_to_str;
187 MonoMethod *str_to_ptr;
188 MonoMarshalField fields [MONO_ZERO_LEN_ARRAY];
191 struct _MonoProperty {
209 /* type of exception being "on hold" for later processing (see exception_type) */
211 MONO_EXCEPTION_NONE = 0,
212 MONO_EXCEPTION_SECURITY_LINKDEMAND = 1,
213 MONO_EXCEPTION_SECURITY_INHERITANCEDEMAND = 2
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 dummy : 1; /* temporary hack */
269 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 */
273 guint8 exception_type; /* MONO_EXCEPTION_* */
274 void* exception_data; /* Additional information about the exception */
275 guint32 declsec_flags; /* declarative security attributes flags */
278 MonoClass *nested_in;
279 GList *nested_classes;
283 const char *name_space;
285 /* for fast subtype checks */
286 MonoClass **supertypes;
289 guint16 interface_count;
290 guint16 interface_id; /* unique inderface id (for interfaces) */
291 guint16 max_interface_id;
292 gint *interface_offsets;
293 MonoClass **interfaces;
296 * Computed object instance size, total.
300 int vtable_size; /* number of slots */
303 * From the TypeDef table
307 guint32 first, count;
308 } field, method, property, event;
310 /* loaded on demand */
311 MonoMarshalType *marshal_info;
314 * Field information: Type and location from object base
316 MonoClassField *fields;
318 /* Initialized by a call to mono_class_setup_properties () */
319 MonoProperty *properties;
321 /* Initialized by a call to mono_class_setup_events () */
324 MonoMethod **methods;
326 /* used as the type of the this argument and when passing the arg by value */
330 MonoGenericClass *generic_class;
331 MonoGenericContainer *generic_container;
333 void *reflection_info;
337 MonoClassRuntimeInfo *runtime_info;
339 /* Generic vtable. Initialized by a call to mono_class_setup_vtable () */
346 * According to comments in gc_gcj.h, this should be the second word in
350 MonoDomain *domain; /* each object/vtable belongs to exactly one domain */
351 gpointer *interface_offsets;
352 gpointer data; /* to store static class data */
353 gpointer type; /* System.Type type for klass */
354 guint16 max_interface_id;
356 guint remote : 1; /* class is remotely activated */
357 guint initialized : 1; /* cctor has been run */
358 /* do not add any fields after vtable, the structure is dynamically extended */
359 gpointer vtable [MONO_ZERO_LEN_ARRAY];
363 * Generic instantiation data type encoding.
367 * A particular generic instantiation:
369 * All instantiations are cached and we don't distinguish between class and method
370 * instantiations here.
372 struct _MonoGenericInst {
373 guint id; /* unique ID for debugging */
374 guint type_argc : 22; /* number of type arguments */
375 guint is_open : 1; /* if this is an open type */
376 guint is_reference : 1; /* if this is a reference type */
377 MonoType **type_argv;
381 * A particular instantiation of a generic type.
383 struct _MonoGenericClass {
384 MonoGenericInst *inst; /* the instantiation */
385 MonoClass *container_class; /* the generic type definition */
386 MonoGenericContext *context; /* current context */
387 guint is_dynamic : 1; /* We're a MonoDynamicGenericClass */
388 guint is_inflated : 1; /* We're a MonoInflatedGenericClass */
392 * Performance optimization:
393 * We don't create the `MonoClass' for a `MonoGenericClass' until we really
396 struct _MonoInflatedGenericClass {
397 MonoGenericClass generic_class;
398 guint is_initialized : 1;
403 * This is used when instantiating a generic type definition which is
406 struct _MonoDynamicGenericClass {
407 MonoInflatedGenericClass generic_class;
412 MonoMethod **methods;
416 MonoClassField *fields;
417 int count_properties;
418 MonoProperty *properties;
425 * A particular instantiation of a generic method.
427 struct _MonoGenericMethod {
428 MonoGenericInst *inst; /* the instantiation */
429 MonoGenericClass *generic_class; /* if we're in a generic type */
430 MonoGenericContainer *container; /* type parameters */
431 gpointer reflection_info;
435 * The generic context.
437 struct _MonoGenericContext {
439 * The current container:
441 * If we're in a generic method, the generic method definition's container.
442 * Otherwise the generic type's container.
444 MonoGenericContainer *container;
445 /* The current generic class */
446 MonoGenericClass *gclass;
447 /* The current generic method */
448 MonoGenericMethod *gmethod;
452 * The generic container.
454 * Stores the type parameters of a generic type definition or a generic method definition.
456 struct _MonoGenericContainer {
457 MonoGenericContext context;
458 /* If we're a generic method definition, the containing class'es context. */
459 MonoGenericContainer *parent;
460 /* If we're a generic method definition, caches all their instantiations. */
461 GHashTable *method_hash;
462 /* If we're a generic type definition, its `MonoClass'. */
465 /* If true, we're a generic method, otherwise a generic type definition. */
467 /* Our type parameters. */
468 MonoGenericParam *type_params;
469 /* Cache for MonoTypes */
476 struct _MonoGenericParam {
477 MonoGenericContainer *owner; /* Type or method this parameter was defined in. */
478 MonoClass *pklass; /* The corresponding `MonoClass'. */
479 MonoMethod *method; /* If we're a method type parameter, the method. */
483 MonoClass** constraints; /* NULL means end of list */
487 * Class information which might be cached by the runtime in the AOT file for
488 * example. Caching this allows us to avoid computing a generic vtable
489 * (class->vtable) in most cases, saving time and avoiding creation of lots of
490 * MonoMethod structures.
492 typedef struct MonoCachedClassInfo {
494 guint has_finalize : 1;
497 guint has_nested_classes : 1;
499 guint has_references : 1;
500 guint has_static_refs : 1;
501 guint no_special_static_fields : 1;
503 MonoImage *finalize_image;
504 guint32 finalize_token;
505 guint32 instance_size;
507 guint32 packing_size;
509 } MonoCachedClassInfo;
514 gconstpointer wrapper;
515 MonoMethodSignature *sig;
519 * Information about a type load error encountered by the loader.
522 MONO_LOADER_ERROR_TYPE,
523 MONO_LOADER_ERROR_METHOD,
524 MONO_LOADER_ERROR_FIELD
525 } MonoLoaderErrorKind;
528 MonoLoaderErrorKind kind;
529 char *class_name, *assembly_name; /* If kind == TYPE */
530 MonoClass *klass; /* If kind != TYPE */
531 const char *member_name; /* If kind != TYPE */
534 #define mono_class_has_parent(klass,parent) (((klass)->idepth >= (parent)->idepth) && ((klass)->supertypes [(parent)->idepth - 1] == (parent)))
537 gulong new_object_count;
538 gulong initialized_class_count;
539 gulong used_class_count;
540 gulong class_vtable_size;
541 gulong class_static_data_size;
542 gulong generic_instance_count;
543 gulong generic_class_count;
544 gulong inflated_method_count;
545 gulong inflated_method_count_2;
546 gulong inflated_type_count;
547 gulong generics_metadata_size;
551 extern MonoStats mono_stats;
553 typedef gpointer (*MonoTrampoline) (MonoMethod *method);
554 typedef gpointer (*MonoRemotingTrampoline) (MonoMethod *method, MonoRemotingTarget target);
555 typedef gpointer (*MonoDelegateTrampoline) (MonoMethod *method, gpointer addr);
557 typedef gpointer (*MonoLookupDynamicToken) (MonoImage *image, guint32 token, MonoClass **handle_class);
559 typedef gboolean (*MonoGetCachedClassInfo) (MonoClass *klass, MonoCachedClassInfo *res);
562 mono_classes_init (void);
565 mono_class_layout_fields (MonoClass *klass);
568 mono_class_setup_vtable_general (MonoClass *klass, MonoMethod **overrides, int onum);
571 mono_class_setup_vtable (MonoClass *klass);
574 mono_class_setup_methods (MonoClass *klass);
577 mono_class_setup_mono_type (MonoClass *klass);
580 mono_class_setup_parent (MonoClass *klass, MonoClass *parent);
583 mono_class_setup_supertypes (MonoClass *klass);
586 mono_class_get_implemented_interfaces (MonoClass *klass);
589 mono_class_is_open_constructed_type (MonoType *t);
592 mono_class_get_overrides_full (MonoImage *image, guint32 type_token, MonoMethod ***overrides, gint32 *num_overrides,
593 MonoGenericContext *generic_context);
596 mono_class_get_cctor (MonoClass *klass);
599 mono_class_get_finalizer (MonoClass *klass);
602 mono_class_needs_cctor_run (MonoClass *klass, MonoMethod *caller);
605 mono_class_has_special_static_fields (MonoClass *klass);
608 mono_install_trampoline (MonoTrampoline func);
611 mono_install_remoting_trampoline (MonoRemotingTrampoline func);
614 mono_install_delegate_trampoline (MonoDelegateTrampoline func);
617 mono_lookup_dynamic_token (MonoImage *image, guint32 token);
620 mono_lookup_dynamic_token_class (MonoImage *image, guint32 token, MonoClass **handle_class);
623 mono_install_lookup_dynamic_token (MonoLookupDynamicToken func);
626 mono_install_get_cached_class_info (MonoGetCachedClassInfo func);
628 MonoInflatedGenericClass*
629 mono_get_inflated_generic_class (MonoGenericClass *gclass);
633 MonoClass *object_class;
634 MonoClass *byte_class;
635 MonoClass *void_class;
636 MonoClass *boolean_class;
637 MonoClass *sbyte_class;
638 MonoClass *int16_class;
639 MonoClass *uint16_class;
640 MonoClass *int32_class;
641 MonoClass *uint32_class;
642 MonoClass *int_class;
643 MonoClass *uint_class;
644 MonoClass *int64_class;
645 MonoClass *uint64_class;
646 MonoClass *single_class;
647 MonoClass *double_class;
648 MonoClass *char_class;
649 MonoClass *string_class;
650 MonoClass *enum_class;
651 MonoClass *array_class;
652 MonoClass *delegate_class;
653 MonoClass *multicastdelegate_class;
654 MonoClass *asyncresult_class;
655 MonoClass *waithandle_class;
656 MonoClass *typehandle_class;
657 MonoClass *fieldhandle_class;
658 MonoClass *methodhandle_class;
659 MonoClass *monotype_class;
660 MonoClass *exception_class;
661 MonoClass *threadabortexception_class;
662 MonoClass *thread_class;
663 MonoClass *transparent_proxy_class;
664 MonoClass *real_proxy_class;
665 MonoClass *mono_method_message_class;
666 MonoClass *appdomain_class;
667 MonoClass *field_info_class;
668 MonoClass *method_info_class;
669 MonoClass *stringbuilder_class;
670 MonoClass *math_class;
671 MonoClass *stack_frame_class;
672 MonoClass *stack_trace_class;
673 MonoClass *marshal_class;
674 MonoClass *iserializeable_class;
675 MonoClass *serializationinfo_class;
676 MonoClass *streamingcontext_class;
677 MonoClass *typed_reference_class;
678 MonoClass *argumenthandle_class;
679 MonoClass *marshalbyrefobject_class;
680 MonoClass *monitor_class;
681 MonoClass *iremotingtypeinfo_class;
682 MonoClass *runtimesecurityframe_class;
683 MonoClass *executioncontext_class;
684 MonoClass *generic_array_class;
685 MonoClass *generic_nullable_class;
688 extern MonoDefaults mono_defaults;
691 mono_loader_init (void);
694 mono_loader_lock (void);
697 mono_loader_unlock (void);
700 mono_loader_set_error_type_load (char *class_name, char *assembly_name);
703 mono_loader_set_error_method_load (MonoClass *klass, const char *member_name);
706 mono_loader_set_error_field_load (MonoClass *klass, const char *member_name);
709 mono_loader_get_last_error (void);
712 mono_loader_clear_error (void);
715 mono_icall_init (void);
718 mono_icall_cleanup (void);
721 mono_method_get_wrapper_data (MonoMethod *method, guint32 id);
724 mono_install_stack_walk (MonoStackWalkImpl func);
727 mono_metadata_has_generic_params (MonoImage *image, guint32 token);
729 MonoGenericContainer *
730 mono_metadata_load_generic_params (MonoImage *image, guint32 token,
731 MonoGenericContainer *parent_container);
734 mono_metadata_load_generic_param_constraints (MonoImage *image, guint32 token,
735 MonoGenericContainer *container);
738 mono_create_icall_signature (const char *sigstr);
741 mono_register_jit_icall (gconstpointer func, const char *name, MonoMethodSignature *sig, gboolean is_save);
744 mono_register_jit_icall_wrapper (MonoJitICallInfo *info, gconstpointer wrapper);
747 mono_find_jit_icall_by_name (const char *name);
750 mono_find_jit_icall_by_addr (gconstpointer addr);
753 mono_class_inflate_generic_signature (MonoImage *image, MonoMethodSignature *sig, MonoGenericContext *context);
755 MonoMethodSignature *
756 mono_method_signature_full (MonoMethod *image, MonoGenericContainer *container);
759 mono_get_shared_generic_class (MonoGenericContainer *container, gboolean is_dynamic);
762 mono_class_set_failure (MonoClass *klass, guint32 ex_type, void *ex_data);
765 mono_class_get_exception_for_failure (MonoClass *klass);
768 mono_type_get_name_full (MonoType *type, MonoTypeNameFormat format);
771 mono_type_get_full_name (MonoClass *class);
773 MonoArrayType *mono_dup_array_type (MonoArrayType *a);
774 MonoMethodSignature *mono_metadata_signature_deep_dup (MonoMethodSignature *sig);
776 gboolean mono_class_is_nullable (MonoClass *klass);
777 MonoClass *mono_class_get_nullable_param (MonoClass *klass);
779 #endif /* __MONO_METADATA_CLASS_INTERBALS_H__ */