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 #define WRAPPER(e,n) MONO_WRAPPER_ ## e,
24 #include "wrapper-types.h"
30 MONO_TYPE_NAME_FORMAT_IL,
31 MONO_TYPE_NAME_FORMAT_REFLECTION,
32 MONO_TYPE_NAME_FORMAT_FULL_NAME,
33 MONO_TYPE_NAME_FORMAT_ASSEMBLY_QUALIFIED
37 MONO_REMOTING_TARGET_UNKNOWN,
38 MONO_REMOTING_TARGET_APPDOMAIN,
39 MONO_REMOTING_TARGET_COMINTEROP
43 guint16 flags; /* method flags */
44 guint16 iflags; /* method implementation flags */
47 MonoMethodSignature *signature;
48 MonoGenericContainer *generic_container;
49 /* name is useful mostly for debugging */
51 /* this is used by the inlining algorithm */
52 unsigned int inline_info:1;
53 unsigned int uses_this:1;
54 unsigned int wrapper_type:5;
55 unsigned int string_ctor:1;
56 unsigned int save_lmf:1;
57 unsigned int dynamic:1; /* created & destroyed during runtime */
58 unsigned int is_inflated:1; /* whether we're a MonoMethodInflated */
59 unsigned int skip_visibility:1; /* whenever to skip JIT visibility checks */
63 struct _MonoMethodNormal {
65 MonoMethodHeader *header;
68 struct _MonoMethodWrapper {
69 MonoMethodNormal method;
73 struct _MonoMethodPInvoke {
76 /* add marshal info */
77 guint16 piflags; /* pinvoke flags */
78 guint16 implmap_idx; /* index into IMPLMAP */
82 * Inflated generic method.
84 struct _MonoMethodInflated {
87 MonoMethodNormal normal;
88 MonoMethodPInvoke pinvoke;
90 MonoGenericContext *context; /* The current context. */
91 MonoMethod *declaring; /* the generic method definition. */
95 MonoType *generic_type;
96 gpointer reflection_info;
100 * MonoClassField is just a runtime representation of the metadata for
101 * field, it doesn't contain the data directly. Static fields are
102 * stored in MonoVTable->data. Instance fields are allocated in the
103 * objects after the object header.
105 struct _MonoClassField {
106 /* Type of the field */
109 /* If this is an instantiated generic type, this is the
110 * "original" type, ie. the MONO_TYPE_VAR or MONO_TYPE_GENERICINST
111 * it was instantiated from.
113 MonoInflatedField *generic_info;
116 * Offset where this field is stored; if it is an instance
117 * field, it's the offset from the start of the object, if
118 * it's static, it's from the start of the memory chunk
119 * allocated for statics for the class.
126 * If the field is constant, pointer to the metadata constant
128 * If the field has an RVA flag, pointer to the data.
133 /* Type where the field was defined */
137 * If the field is constant, the type of the constant.
139 MonoTypeEnum def_type;
142 /* a field is ignored if it's named "_Deleted" and it has the specialname and rtspecialname flags set */
143 #define mono_field_is_deleted(field) (((field)->type->attrs & (FIELD_ATTRIBUTE_SPECIAL_NAME | FIELD_ATTRIBUTE_RT_SPECIAL_NAME)) \
144 && (strcmp ((field)->name, "_Deleted") == 0))
147 MonoClassField *field;
149 MonoMarshalSpec *mspec;
155 MonoMethod *ptr_to_str;
156 MonoMethod *str_to_ptr;
157 MonoMarshalField fields [MONO_ZERO_LEN_ARRAY];
160 struct _MonoProperty {
178 /* type of exception being "on hold" for later processing (see exception_type) */
180 MONO_EXCEPTION_NONE = 0,
181 MONO_EXCEPTION_SECURITY_LINKDEMAND = 1,
182 MONO_EXCEPTION_SECURITY_INHERITANCEDEMAND = 2,
183 MONO_EXCEPTION_INVALID_PROGRAM = 3,
184 MONO_EXCEPTION_UNVERIFIABLE_IL = 4,
185 MONO_EXCEPTION_MISSING_METHOD = 5,
186 MONO_EXCEPTION_MISSING_FIELD = 6,
187 MONO_EXCEPTION_TYPE_LOAD = 7
188 /* add other exception type */
191 /* This struct collects the info needed for the runtime use of a class,
192 * like the vtables for a domain, the GC descriptor, etc.
196 /* domain_vtables is indexed by the domain id and the size is max_domain + 1 */
197 MonoVTable *domain_vtables [MONO_ZERO_LEN_ARRAY];
198 } MonoClassRuntimeInfo;
203 /* The underlying type of the enum */
204 MonoType *enum_basetype;
205 /* element class for arrays and enum */
206 MonoClass *element_class;
207 /* used for subtype checks */
208 MonoClass *cast_class;
209 /* array dimension */
213 /* We use init_pending to detect cyclic calls to mono_class_init */
214 guint init_pending : 1;
216 /* A class contains static and non static data. Static data can be
217 * of the same type as the class itselfs, but it does not influence
218 * the instance size of the class. To avoid cyclic calls to
219 * mono_class_init (from mono_class_instance_size ()) we first
220 * initialise all non static fields. After that we set size_inited
221 * to 1, because we know the instance size now. After that we
222 * initialise all static fields.
224 guint size_inited : 1;
225 guint valuetype : 1; /* derives from System.ValueType */
226 guint enumtype : 1; /* derives from System.Enum */
227 guint blittable : 1; /* class is blittable */
228 guint unicode : 1; /* class uses unicode char when marshalled */
229 guint wastypebuilder : 1; /* class was created at runtime from a TypeBuilder */
232 guint packing_size : 4;
234 guint ghcimpl : 1; /* class has its own GetHashCode impl */
235 guint has_finalize : 1; /* class has its own Finalize impl */
236 guint marshalbyref : 1; /* class is a MarshalByRefObject */
237 guint contextbound : 1; /* class is a ContextBoundObject */
238 guint delegate : 1; /* class is a Delegate */
239 guint gc_descr_inited : 1; /* gc_descr is initialized */
240 guint has_cctor : 1; /* class has a cctor */
241 guint has_references : 1; /* it has GC-tracked references in the instance */
243 guint has_static_refs : 1; /* it has static fields that are GC-tracked */
244 guint no_special_static_fields : 1; /* has no thread/context static fields */
245 /* directly or indirectly derives from ComImport attributed class.
246 * this means we need to create a proxy for instances of this class
247 * for COM Interop. set this flag on loading so all we need is a quick check
248 * during object creation rather than having to traverse supertypes
250 guint is_com_object : 1;
252 guint8 exception_type; /* MONO_EXCEPTION_* */
253 void* exception_data; /* Additional information about the exception */
254 guint32 declsec_flags; /* declarative security attributes flags */
257 MonoClass *nested_in;
258 GList *nested_classes;
262 const char *name_space;
264 /* for fast subtype checks */
265 MonoClass **supertypes;
268 guint16 interface_count;
269 guint16 interface_id; /* unique inderface id (for interfaces) */
270 guint16 max_interface_id;
272 guint16 interface_offsets_count;
273 MonoClass **interfaces_packed;
274 guint16 *interface_offsets_packed;
275 guint8 *interface_bitmap;
277 MonoClass **interfaces;
280 * Computed object instance size, total.
283 int vtable_size; /* number of slots */
285 int class_size; /* size of area for static fields */
286 int element_size; /* for array types */
290 * From the TypeDef table
294 guint32 first, count;
295 } field, method, property, event;
297 /* loaded on demand */
298 MonoMarshalType *marshal_info;
301 * Field information: Type and location from object base
303 MonoClassField *fields;
305 /* Initialized by a call to mono_class_setup_properties () */
306 MonoProperty *properties;
308 /* Initialized by a call to mono_class_setup_events () */
311 MonoMethod **methods;
313 /* used as the type of the this argument and when passing the arg by value */
317 MonoGenericClass *generic_class;
318 MonoGenericContainer *generic_container;
320 void *reflection_info;
324 MonoClassRuntimeInfo *runtime_info;
326 /* Generic vtable. Initialized by a call to mono_class_setup_vtable () */
330 #define MONO_CLASS_IMPLEMENTS_INTERFACE(k,uiid) (((uiid) <= (k)->max_interface_id) && ((k)->interface_bitmap [(uiid) >> 3] & (1 << ((uiid)&7))))
331 int mono_class_interface_offset (MonoClass *klass, MonoClass *itf);
333 /* the interface_offsets array is stored in memory before this struct */
337 * According to comments in gc_gcj.h, this should be the second word in
341 MonoDomain *domain; /* each object/vtable belongs to exactly one domain */
342 gpointer data; /* to store static class data */
343 gpointer type; /* System.Type type for klass */
344 guint16 max_interface_id;
346 guint remote : 1; /* class is remotely activated */
347 guint initialized : 1; /* cctor has been run */
348 guint init_failed : 1; /* cctor execution failed */
349 /* do not add any fields after vtable, the structure is dynamically extended */
350 gpointer vtable [MONO_ZERO_LEN_ARRAY];
354 * Generic instantiation data type encoding.
358 * A particular generic instantiation:
360 * All instantiations are cached and we don't distinguish between class and method
361 * instantiations here.
363 struct _MonoGenericInst {
364 guint id; /* unique ID for debugging */
365 guint type_argc : 22; /* number of type arguments */
366 guint is_open : 1; /* if this is an open type */
367 guint is_reference : 1; /* if this is a reference type */
368 MonoType **type_argv;
372 * A particular instantiation of a generic type.
374 struct _MonoGenericClass {
375 MonoGenericInst *inst; /* the instantiation */
376 MonoClass *container_class; /* the generic type definition */
377 MonoGenericContext *cached_context; /* if present, a "trivial" context that doesn't contain any method instantiation */
378 guint is_dynamic : 1; /* We're a MonoDynamicGenericClass */
379 MonoClass *cached_class; /* if present, the MonoClass corresponding to the instantiation. */
383 * This is used when instantiating a generic type definition which is
386 struct _MonoDynamicGenericClass {
387 MonoGenericClass generic_class;
389 MonoMethod **methods;
393 MonoClassField *fields;
394 int count_properties;
395 MonoProperty *properties;
402 * A particular instantiation of a generic method.
404 struct _MonoGenericMethod {
405 MonoGenericInst *inst; /* the instantiation */
406 MonoGenericInst *class_inst; /* if we're in a generic type, the instantiation of that type */
407 MonoGenericContainer *container; /* type parameters */
408 gpointer reflection_info;
412 * The generic context: an instantiation of a set of class and method generic parameters.
414 struct _MonoGenericContext {
415 /* The instantiation corresponding to the class generic parameters */
416 MonoGenericInst *class_inst;
417 /* The current generic method */
418 MonoGenericMethod *gmethod;
422 * The generic container.
424 * Stores the type parameters of a generic type definition or a generic method definition.
426 struct _MonoGenericContainer {
427 MonoGenericContext context;
428 /* If we're a generic method definition in a generic type definition,
429 the generic container of the containing class. */
430 MonoGenericContainer *parent;
431 /* If we're a generic method definition, caches all their instantiations. */
432 GHashTable *method_hash;
433 /* the generic type definition or the generic method definition corresponding to this container */
439 /* If true, we're a generic method, otherwise a generic type definition. */
440 /* Invariant: parent != NULL => is_method */
442 /* Our type parameters. */
443 MonoGenericParam *type_params;
449 struct _MonoGenericParam {
450 MonoGenericContainer *owner; /* Type or method this parameter was defined in. */
451 MonoClass *pklass; /* The corresponding `MonoClass'. */
455 MonoClass** constraints; /* NULL means end of list */
459 * Class information which might be cached by the runtime in the AOT file for
460 * example. Caching this allows us to avoid computing a generic vtable
461 * (class->vtable) in most cases, saving time and avoiding creation of lots of
462 * MonoMethod structures.
464 typedef struct MonoCachedClassInfo {
466 guint has_finalize : 1;
469 guint has_nested_classes : 1;
471 guint has_references : 1;
472 guint has_static_refs : 1;
473 guint no_special_static_fields : 1;
475 MonoImage *finalize_image;
476 guint32 finalize_token;
477 guint32 instance_size;
479 guint32 packing_size;
481 } MonoCachedClassInfo;
486 gconstpointer wrapper;
487 gconstpointer trampoline;
488 MonoMethodSignature *sig;
492 * Information about a type load error encountered by the loader.
495 MONO_LOADER_ERROR_TYPE,
496 MONO_LOADER_ERROR_METHOD,
497 MONO_LOADER_ERROR_FIELD,
498 MONO_LOADER_ERROR_ASSEMBLY
499 } MonoLoaderErrorKind;
502 MonoLoaderErrorKind kind;
503 char *class_name; /* If kind == TYPE */
504 char *assembly_name; /* If kind == TYPE or ASSEMBLY */
505 MonoClass *klass; /* If kind != TYPE */
506 const char *member_name; /* If kind != TYPE */
507 gboolean ref_only; /* If kind == ASSEMBLY */
510 #define mono_class_has_parent(klass,parent) (((klass)->idepth >= (parent)->idepth) && ((klass)->supertypes [(parent)->idepth - 1] == (parent)))
513 gulong new_object_count;
514 gulong initialized_class_count;
515 gulong generic_vtable_count;
516 gulong used_class_count;
518 gulong class_vtable_size;
519 gulong class_static_data_size;
520 gulong generic_instance_count;
521 gulong generic_class_count;
522 gulong inflated_method_count;
523 gulong inflated_method_count_2;
524 gulong inflated_type_count;
525 gulong generics_metadata_size;
530 * The definition of the first field in SafeHandle,
531 * Keep in sync with SafeHandle.cs, this is only used
532 * to access the `handle' parameter.
540 * Keep in sync with HandleRef.cs
547 extern MonoStats mono_stats MONO_INTERNAL;
549 typedef gpointer (*MonoTrampoline) (MonoMethod *method);
550 typedef gpointer (*MonoRemotingTrampoline) (MonoMethod *method, MonoRemotingTarget target);
551 typedef gpointer (*MonoDelegateTrampoline) (MonoMethod *method, gpointer addr);
553 typedef gpointer (*MonoLookupDynamicToken) (MonoImage *image, guint32 token, MonoClass **handle_class);
555 typedef gboolean (*MonoGetCachedClassInfo) (MonoClass *klass, MonoCachedClassInfo *res);
557 typedef gboolean (*MonoGetClassFromName) (MonoImage *image, const char *name_space, const char *name, MonoClass **res);
560 mono_classes_init (void) MONO_INTERNAL;
563 mono_classes_cleanup (void) MONO_INTERNAL;
566 mono_class_layout_fields (MonoClass *klass) MONO_INTERNAL;
569 mono_class_setup_interface_offsets (MonoClass *klass) MONO_INTERNAL;
572 mono_class_setup_vtable_general (MonoClass *klass, MonoMethod **overrides, int onum) MONO_INTERNAL;
575 mono_class_setup_vtable (MonoClass *klass) MONO_INTERNAL;
578 mono_class_setup_methods (MonoClass *klass) MONO_INTERNAL;
581 mono_class_setup_mono_type (MonoClass *klass) MONO_INTERNAL;
584 mono_class_setup_parent (MonoClass *klass, MonoClass *parent) MONO_INTERNAL;
587 mono_class_setup_supertypes (MonoClass *klass) MONO_INTERNAL;
590 mono_class_get_implemented_interfaces (MonoClass *klass) MONO_INTERNAL;
593 mono_class_is_open_constructed_type (MonoType *t) MONO_INTERNAL;
596 mono_class_get_overrides_full (MonoImage *image, guint32 type_token, MonoMethod ***overrides, gint32 *num_overrides,
597 MonoGenericContext *generic_context) MONO_INTERNAL;
600 mono_class_get_cctor (MonoClass *klass) MONO_INTERNAL;
603 mono_class_get_finalizer (MonoClass *klass) MONO_INTERNAL;
606 mono_class_needs_cctor_run (MonoClass *klass, MonoMethod *caller) MONO_INTERNAL;
609 mono_class_has_special_static_fields (MonoClass *klass) MONO_INTERNAL;
612 mono_install_trampoline (MonoTrampoline func) MONO_INTERNAL;
615 mono_install_remoting_trampoline (MonoRemotingTrampoline func) MONO_INTERNAL;
618 mono_install_delegate_trampoline (MonoDelegateTrampoline func) MONO_INTERNAL;
621 mono_lookup_dynamic_token (MonoImage *image, guint32 token) MONO_INTERNAL;
624 mono_lookup_dynamic_token_class (MonoImage *image, guint32 token, MonoClass **handle_class) MONO_INTERNAL;
627 mono_install_lookup_dynamic_token (MonoLookupDynamicToken func) MONO_INTERNAL;
630 mono_install_get_cached_class_info (MonoGetCachedClassInfo func) MONO_INTERNAL;
633 mono_install_get_class_from_name (MonoGetClassFromName func) MONO_INTERNAL;
636 mono_class_get_context (MonoClass *class) MONO_INTERNAL;
639 mono_method_get_context (MonoMethod *method) MONO_INTERNAL;
642 mono_generic_class_get_context (MonoGenericClass *gclass) MONO_INTERNAL;
645 mono_generic_class_get_class (MonoGenericClass *gclass) MONO_INTERNAL;
648 mono_class_inflate_generic_method_full (MonoMethod *method, MonoClass *klass_hint, MonoGenericContext *context);
653 MonoClass *object_class;
654 MonoClass *byte_class;
655 MonoClass *void_class;
656 MonoClass *boolean_class;
657 MonoClass *sbyte_class;
658 MonoClass *int16_class;
659 MonoClass *uint16_class;
660 MonoClass *int32_class;
661 MonoClass *uint32_class;
662 MonoClass *int_class;
663 MonoClass *uint_class;
664 MonoClass *int64_class;
665 MonoClass *uint64_class;
666 MonoClass *single_class;
667 MonoClass *double_class;
668 MonoClass *char_class;
669 MonoClass *string_class;
670 MonoClass *enum_class;
671 MonoClass *array_class;
672 MonoClass *delegate_class;
673 MonoClass *multicastdelegate_class;
674 MonoClass *asyncresult_class;
675 MonoClass *waithandle_class;
676 MonoClass *typehandle_class;
677 MonoClass *fieldhandle_class;
678 MonoClass *methodhandle_class;
679 MonoClass *systemtype_class;
680 MonoClass *monotype_class;
681 MonoClass *exception_class;
682 MonoClass *threadabortexception_class;
683 MonoClass *thread_class;
684 MonoClass *transparent_proxy_class;
685 MonoClass *real_proxy_class;
686 MonoClass *mono_method_message_class;
687 MonoClass *appdomain_class;
688 MonoClass *field_info_class;
689 MonoClass *method_info_class;
690 MonoClass *stringbuilder_class;
691 MonoClass *math_class;
692 MonoClass *stack_frame_class;
693 MonoClass *stack_trace_class;
694 MonoClass *marshal_class;
695 MonoClass *iserializeable_class;
696 MonoClass *serializationinfo_class;
697 MonoClass *streamingcontext_class;
698 MonoClass *typed_reference_class;
699 MonoClass *argumenthandle_class;
700 MonoClass *marshalbyrefobject_class;
701 MonoClass *monitor_class;
702 MonoClass *iremotingtypeinfo_class;
703 MonoClass *runtimesecurityframe_class;
704 MonoClass *executioncontext_class;
705 MonoClass *internals_visible_class;
706 MonoClass *generic_ilist_class;
707 MonoClass *generic_nullable_class;
708 MonoClass *variant_class;
709 MonoClass *com_object_class;
710 MonoClass *com_interop_proxy_class;
711 MonoClass *iunknown_class;
712 MonoClass *idispatch_class;
713 MonoClass *safehandle_class;
714 MonoClass *handleref_class;
717 extern MonoDefaults mono_defaults MONO_INTERNAL;
720 mono_loader_init (void) MONO_INTERNAL;
723 mono_loader_cleanup (void) MONO_INTERNAL;
726 mono_loader_lock (void) MONO_INTERNAL;
729 mono_loader_unlock (void) MONO_INTERNAL;
732 mono_loader_set_error_assembly_load (const char *assembly_name, gboolean ref_only) MONO_INTERNAL;
735 mono_loader_set_error_type_load (const char *class_name, const char *assembly_name) MONO_INTERNAL;
738 mono_loader_set_error_method_load (const char *class_name, const char *member_name) MONO_INTERNAL;
741 mono_loader_set_error_field_load (MonoClass *klass, const char *member_name) MONO_INTERNAL;
744 mono_loader_error_prepare_exception (MonoLoaderError *error) MONO_INTERNAL;
747 mono_loader_get_last_error (void) MONO_INTERNAL;
750 mono_loader_clear_error (void) MONO_INTERNAL;
753 mono_reflection_init (void) MONO_INTERNAL;
756 mono_icall_init (void) MONO_INTERNAL;
759 mono_icall_cleanup (void) MONO_INTERNAL;
762 mono_method_get_wrapper_data (MonoMethod *method, guint32 id) MONO_INTERNAL;
765 mono_install_stack_walk (MonoStackWalkImpl func) MONO_INTERNAL;
768 mono_metadata_has_generic_params (MonoImage *image, guint32 token) MONO_INTERNAL;
770 MonoGenericContainer *
771 mono_metadata_load_generic_params (MonoImage *image, guint32 token,
772 MonoGenericContainer *parent_container);
775 mono_metadata_load_generic_param_constraints (MonoImage *image, guint32 token,
776 MonoGenericContainer *container);
779 mono_create_icall_signature (const char *sigstr) MONO_INTERNAL;
782 mono_register_jit_icall (gconstpointer func, const char *name, MonoMethodSignature *sig, gboolean is_save) MONO_INTERNAL;
785 mono_register_jit_icall_wrapper (MonoJitICallInfo *info, gconstpointer wrapper) MONO_INTERNAL;
788 mono_find_jit_icall_by_name (const char *name) MONO_INTERNAL;
791 mono_find_jit_icall_by_addr (gconstpointer addr) MONO_INTERNAL;
794 mono_get_shared_generic_inst (MonoGenericContainer *container) MONO_INTERNAL;
797 mono_get_shared_generic_class (MonoGenericContainer *container, gboolean is_dynamic) MONO_INTERNAL;
800 mono_get_shared_generic_method (MonoGenericContainer *container) MONO_INTERNAL;
803 mono_class_set_failure (MonoClass *klass, guint32 ex_type, void *ex_data) MONO_INTERNAL;
806 mono_class_get_exception_for_failure (MonoClass *klass) MONO_INTERNAL;
809 mono_type_get_name_full (MonoType *type, MonoTypeNameFormat format) MONO_INTERNAL;
812 mono_type_get_full_name (MonoClass *class) MONO_INTERNAL;
814 MonoArrayType *mono_dup_array_type (MonoArrayType *a) MONO_INTERNAL;
815 MonoMethodSignature *mono_metadata_signature_deep_dup (MonoMethodSignature *sig) MONO_INTERNAL;
818 mono_image_init_name_cache (MonoImage *image);
820 gboolean mono_class_is_nullable (MonoClass *klass) MONO_INTERNAL;
821 MonoClass *mono_class_get_nullable_param (MonoClass *klass) MONO_INTERNAL;
823 /* object debugging functions, for use inside gdb */
824 void mono_object_describe (MonoObject *obj);
825 void mono_object_describe_fields (MonoObject *obj);
826 void mono_value_describe_fields (MonoClass* klass, const char* addr);
827 void mono_class_describe_statics (MonoClass* klass);
829 #endif /* __MONO_METADATA_CLASS_INTERBALS_H__ */