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,
51 MONO_TYPE_NAME_FORMAT_IL,
52 MONO_TYPE_NAME_FORMAT_REFLECTION,
53 MONO_TYPE_NAME_FORMAT_FULL_NAME,
54 MONO_TYPE_NAME_FORMAT_ASSEMBLY_QUALIFIED
58 MONO_REMOTING_TARGET_UNKNOWN,
59 MONO_REMOTING_TARGET_APPDOMAIN
63 guint16 flags; /* method flags */
64 guint16 iflags; /* method implementation flags */
67 MonoMethodSignature *signature;
68 /* name is useful mostly for debugging */
70 /* this is used by the inlining algorithm */
71 unsigned int inline_info:1;
72 unsigned int uses_this:1;
73 unsigned int wrapper_type:5;
74 unsigned int string_ctor:1;
75 unsigned int save_lmf:1;
76 unsigned int dynamic:1; /* created & destroyed during runtime */
77 unsigned int is_inflated:1;
81 struct _MonoMethodNormal {
83 MonoGenericContainer *generic_container;
84 MonoMethodHeader *header;
87 struct _MonoMethodWrapper {
88 MonoMethodNormal method;
92 struct _MonoMethodInflated {
93 MonoMethodNormal nmethod;
94 MonoGenericContext *context;
95 MonoMethod *declaring;
96 MonoMethodInflated *inflated;
99 struct _MonoMethodPInvoke {
102 /* add marshal info */
103 guint16 piflags; /* pinvoke flags */
104 guint16 implmap_idx; /* index into IMPLMAP */
108 MonoType *generic_type;
109 gpointer reflection_info;
113 * MonoClassField is just a runtime representation of the metadata for
114 * field, it doesn't contain the data directly. Static fields are
115 * stored in MonoVTable->data. Instance fields are allocated in the
116 * objects after the object header.
118 struct _MonoClassField {
119 /* Type of the field */
122 /* If this is an instantiated generic type, this is the
123 * "original" type, ie. the MONO_TYPE_VAR or MONO_TYPE_GENERICINST
124 * it was instantiated from.
126 MonoInflatedField *generic_info;
129 * Offset where this field is stored; if it is an instance
130 * field, it's the offset from the start of the object, if
131 * it's static, it's from the start of the memory chunk
132 * allocated for statics for the class.
139 * If the field is constant, pointer to the metadata constant
141 * If the field has an RVA flag, pointer to the data.
146 /* Type where the field was defined */
150 * If the field is constant, the type of the constant.
152 MonoTypeEnum def_type;
155 /* a field is ignored if it's named "_Deleted" and it has the specialname and rtspecialname flags set */
156 #define mono_field_is_deleted(field) ((field)->name[0] == '_' && ((field)->type->attrs & 0x600) && (strcmp ((field)->name, "_Deleted") == 0))
159 MonoClassField *field;
161 MonoMarshalSpec *mspec;
167 MonoMethod *ptr_to_str;
168 MonoMethod *str_to_ptr;
169 MonoMarshalField fields [MONO_ZERO_LEN_ARRAY];
172 struct _MonoProperty {
190 /* type of exception being "on hold" for later processing (see exception_type) */
192 MONO_EXCEPTION_NONE = 0,
193 MONO_EXCEPTION_SECURITY_LINKDEMAND = 1,
194 MONO_EXCEPTION_SECURITY_INHERITANCEDEMAND = 2
195 /* add other exception type */
198 /* This struct collects the info needed for the runtime use of a class,
199 * like the vtables for a domain, the GC descriptor, etc.
203 /* domain_vtables is indexed by the domain id and the size is max_domain + 1 */
204 MonoVTable *domain_vtables [MONO_ZERO_LEN_ARRAY];
205 } MonoClassRuntimeInfo;
210 /* The underlying type of the enum */
211 MonoType *enum_basetype;
212 /* element class for arrays and enum */
213 MonoClass *element_class;
214 /* used for subtype checks */
215 MonoClass *cast_class;
216 /* array dimension */
220 /* We use init_pending to detect cyclic calls to mono_class_init */
221 guint init_pending : 1;
223 /* A class contains static and non static data. Static data can be
224 * of the same type as the class itselfs, but it does not influence
225 * the instance size of the class. To avoid cyclic calls to
226 * mono_class_init (from mono_class_instance_size ()) we first
227 * initialise all non static fields. After that we set size_inited
228 * to 1, because we know the instance size now. After that we
229 * initialise all static fields.
231 guint size_inited : 1;
232 guint valuetype : 1; /* derives from System.ValueType */
233 guint enumtype : 1; /* derives from System.Enum */
234 guint blittable : 1; /* class is blittable */
235 guint unicode : 1; /* class uses unicode char when marshalled */
236 guint wastypebuilder : 1; /* class was created at runtime from a TypeBuilder */
239 guint packing_size : 4;
241 guint ghcimpl : 1; /* class has its own GetHashCode impl */
242 guint has_finalize : 1; /* class has its own Finalize impl */
243 guint marshalbyref : 1; /* class is a MarshalByRefObject */
244 guint contextbound : 1; /* class is a ContextBoundObject */
245 guint delegate : 1; /* class is a Delegate */
246 guint gc_descr_inited : 1; /* gc_descr is initialized */
247 guint has_cctor : 1; /* class has a cctor */
248 guint dummy : 1; /* temporary hack */
250 guint has_references : 1; /* it has GC-tracked references in the instance */
251 guint has_static_refs : 1; /* it has static fields that are GC-tracked */
252 guint no_special_static_fields : 1; /* has no thread/context static fields */
254 guint8 exception_type; /* MONO_EXCEPTION_* */
255 void* exception_data; /* Additional information about the exception */
256 guint32 declsec_flags; /* declarative security attributes flags */
259 MonoClass *nested_in;
260 GList *nested_classes;
264 const char *name_space;
266 /* for fast subtype checks */
267 MonoClass **supertypes;
270 guint16 interface_count;
271 guint16 interface_id; /* unique inderface id (for interfaces) */
272 guint16 max_interface_id;
273 gint *interface_offsets;
274 MonoClass **interfaces;
277 * Computed object instance size, total.
281 int vtable_size; /* number of slots */
284 * From the TypeDef table
288 guint32 first, count;
289 } field, method, property, event;
291 /* loaded on demand */
292 MonoMarshalType *marshal_info;
295 * Field information: Type and location from object base
297 MonoClassField *fields;
299 /* Initialized by a call to mono_class_setup_properties () */
300 MonoProperty *properties;
302 /* Initialized by a call to mono_class_setup_events () */
305 MonoMethod **methods;
307 /* used as the type of the this argument and when passing the arg by value */
311 MonoGenericClass *generic_class;
312 MonoGenericContainer *generic_container;
314 void *reflection_info;
318 MonoClassRuntimeInfo *runtime_info;
320 /* Generic vtable. Initialized by a call to mono_class_setup_vtable () */
327 * According to comments in gc_gcj.h, this should be the second word in
331 MonoDomain *domain; /* each object/vtable belongs to exactly one domain */
332 gpointer *interface_offsets;
333 gpointer data; /* to store static class data */
334 gpointer type; /* System.Type type for klass */
335 guint16 max_interface_id;
337 guint remote : 1; /* class is remotely activated */
338 guint initialized : 1; /* cctor has been run */
339 /* do not add any fields after vtable, the structure is dynamically extended */
340 gpointer vtable [MONO_ZERO_LEN_ARRAY];
344 * Generic instantiation data type encoding.
346 struct _MonoGenericInst {
348 guint type_argc : 22;
350 guint is_reference : 1;
351 MonoType **type_argv;
354 struct _MonoGenericClass {
355 MonoGenericInst *inst;
356 MonoClass *container_class;
357 MonoGenericContext *context;
358 guint is_dynamic : 1;
359 guint is_inflated : 1;
362 struct _MonoInflatedGenericClass {
363 MonoGenericClass generic_class;
364 guint is_initialized : 1;
368 struct _MonoDynamicGenericClass {
369 MonoInflatedGenericClass generic_class;
374 MonoMethod **methods;
378 MonoClassField *fields;
379 int count_properties;
380 MonoProperty *properties;
386 struct _MonoGenericMethod {
387 MonoGenericInst *inst;
388 MonoGenericClass *generic_class;
389 MonoGenericContainer *container;
390 gpointer reflection_info;
393 struct _MonoGenericContext {
394 MonoGenericContainer *container;
395 MonoGenericClass *gclass;
396 MonoGenericMethod *gmethod;
399 struct _MonoGenericContainer {
400 MonoGenericContext context;
401 MonoGenericContainer *parent;
402 GHashTable *method_hash;
406 int is_signature : 1;
407 MonoGenericParam *type_params;
410 struct _MonoGenericParam {
411 MonoGenericContainer *owner;
417 MonoClass** constraints; /* NULL means end of list */
421 * Class information which might be cached by the runtime in the AOT file for
422 * example. Caching this allows us to avoid computing a generic vtable
423 * (class->vtable) in most cases, saving time and avoiding creation of lots of
424 * MonoMethod structures.
426 typedef struct MonoCachedClassInfo {
428 guint has_finalize : 1;
431 guint has_nested_classes : 1;
433 guint has_references : 1;
434 guint has_static_refs : 1;
435 guint no_special_static_fields : 1;
437 MonoImage *finalize_image;
438 guint32 finalize_token;
439 guint32 instance_size;
441 guint32 packing_size;
443 } MonoCachedClassInfo;
448 gconstpointer wrapper;
449 MonoMethodSignature *sig;
453 * Information about a type load error encountered by the loader.
456 MONO_LOADER_ERROR_TYPE,
457 MONO_LOADER_ERROR_METHOD,
458 MONO_LOADER_ERROR_FIELD
459 } MonoLoaderErrorKind;
462 MonoLoaderErrorKind kind;
463 char *class_name, *assembly_name; /* If kind == TYPE */
464 MonoClass *klass; /* If kind != TYPE */
465 const char *member_name; /* If kind != TYPE */
468 #define mono_class_has_parent(klass,parent) (((klass)->idepth >= (parent)->idepth) && ((klass)->supertypes [(parent)->idepth - 1] == (parent)))
471 gulong new_object_count;
472 gulong initialized_class_count;
473 gulong used_class_count;
474 gulong class_vtable_size;
475 gulong class_static_data_size;
476 gulong generic_instance_count;
477 gulong generic_class_count;
478 gulong inflated_method_count;
479 gulong inflated_method_count_2;
480 gulong inflated_type_count;
481 gulong generics_metadata_size;
485 extern MonoStats mono_stats;
487 typedef gpointer (*MonoTrampoline) (MonoMethod *method);
488 typedef gpointer (*MonoRemotingTrampoline) (MonoMethod *method, MonoRemotingTarget target);
489 typedef gpointer (*MonoDelegateTrampoline) (MonoMethod *method, gpointer addr);
491 typedef gpointer (*MonoLookupDynamicToken) (MonoImage *image, guint32 token, MonoClass **handle_class);
493 typedef gboolean (*MonoGetCachedClassInfo) (MonoClass *klass, MonoCachedClassInfo *res);
496 mono_classes_init (void);
499 mono_class_layout_fields (MonoClass *klass);
502 mono_class_setup_vtable_general (MonoClass *klass, MonoMethod **overrides, int onum);
505 mono_class_setup_vtable (MonoClass *klass);
508 mono_class_setup_methods (MonoClass *klass);
511 mono_class_setup_mono_type (MonoClass *klass);
514 mono_class_setup_parent (MonoClass *klass, MonoClass *parent);
517 mono_class_setup_supertypes (MonoClass *klass);
520 mono_class_get_implemented_interfaces (MonoClass *klass);
523 mono_class_is_open_constructed_type (MonoType *t);
526 mono_class_get_overrides_full (MonoImage *image, guint32 type_token, MonoMethod ***overrides, gint32 *num_overrides,
527 MonoGenericContext *generic_context);
530 mono_class_get_cctor (MonoClass *klass);
533 mono_class_get_finalizer (MonoClass *klass);
536 mono_class_needs_cctor_run (MonoClass *klass, MonoMethod *caller);
539 mono_class_has_special_static_fields (MonoClass *klass);
542 mono_install_trampoline (MonoTrampoline func);
545 mono_install_remoting_trampoline (MonoRemotingTrampoline func);
548 mono_install_delegate_trampoline (MonoDelegateTrampoline func);
551 mono_lookup_dynamic_token (MonoImage *image, guint32 token);
554 mono_lookup_dynamic_token_class (MonoImage *image, guint32 token, MonoClass **handle_class);
557 mono_install_lookup_dynamic_token (MonoLookupDynamicToken func);
560 mono_install_get_cached_class_info (MonoGetCachedClassInfo func);
562 MonoInflatedGenericClass*
563 mono_get_inflated_generic_class (MonoGenericClass *gclass);
567 MonoClass *object_class;
568 MonoClass *byte_class;
569 MonoClass *void_class;
570 MonoClass *boolean_class;
571 MonoClass *sbyte_class;
572 MonoClass *int16_class;
573 MonoClass *uint16_class;
574 MonoClass *int32_class;
575 MonoClass *uint32_class;
576 MonoClass *int_class;
577 MonoClass *uint_class;
578 MonoClass *int64_class;
579 MonoClass *uint64_class;
580 MonoClass *single_class;
581 MonoClass *double_class;
582 MonoClass *char_class;
583 MonoClass *string_class;
584 MonoClass *enum_class;
585 MonoClass *array_class;
586 MonoClass *delegate_class;
587 MonoClass *multicastdelegate_class;
588 MonoClass *asyncresult_class;
589 MonoClass *waithandle_class;
590 MonoClass *typehandle_class;
591 MonoClass *fieldhandle_class;
592 MonoClass *methodhandle_class;
593 MonoClass *monotype_class;
594 MonoClass *exception_class;
595 MonoClass *threadabortexception_class;
596 MonoClass *thread_class;
597 MonoClass *transparent_proxy_class;
598 MonoClass *real_proxy_class;
599 MonoClass *mono_method_message_class;
600 MonoClass *appdomain_class;
601 MonoClass *field_info_class;
602 MonoClass *method_info_class;
603 MonoClass *stringbuilder_class;
604 MonoClass *math_class;
605 MonoClass *stack_frame_class;
606 MonoClass *stack_trace_class;
607 MonoClass *marshal_class;
608 MonoClass *iserializeable_class;
609 MonoClass *serializationinfo_class;
610 MonoClass *streamingcontext_class;
611 MonoClass *typed_reference_class;
612 MonoClass *argumenthandle_class;
613 MonoClass *marshalbyrefobject_class;
614 MonoClass *monitor_class;
615 MonoClass *iremotingtypeinfo_class;
616 MonoClass *runtimesecurityframe_class;
617 MonoClass *executioncontext_class;
618 MonoClass *generic_array_class;
621 extern MonoDefaults mono_defaults;
624 mono_loader_init (void);
627 mono_loader_lock (void);
630 mono_loader_unlock (void);
633 mono_loader_set_error_type_load (char *class_name, char *assembly_name);
636 mono_loader_set_error_method_load (MonoClass *klass, const char *member_name);
639 mono_loader_set_error_field_load (MonoClass *klass, const char *member_name);
642 mono_loader_get_last_error (void);
645 mono_loader_clear_error (void);
648 mono_icall_init (void);
651 mono_icall_cleanup (void);
654 mono_method_get_wrapper_data (MonoMethod *method, guint32 id);
657 mono_install_stack_walk (MonoStackWalkImpl func);
660 mono_metadata_has_generic_params (MonoImage *image, guint32 token);
662 MonoGenericContainer *mono_metadata_load_generic_params (MonoImage *image, guint32 token,
663 MonoGenericContainer *parent_container);
666 mono_create_icall_signature (const char *sigstr);
669 mono_register_jit_icall (gconstpointer func, const char *name, MonoMethodSignature *sig, gboolean is_save);
672 mono_register_jit_icall_wrapper (MonoJitICallInfo *info, gconstpointer wrapper);
675 mono_find_jit_icall_by_name (const char *name);
678 mono_find_jit_icall_by_addr (gconstpointer addr);
681 mono_class_inflate_generic_signature (MonoImage *image, MonoMethodSignature *sig, MonoGenericContext *context);
683 MonoMethodSignature *
684 mono_method_signature_full (MonoMethod *image, MonoGenericContext *context);
687 mono_get_shared_generic_class (MonoGenericContainer *container, gboolean is_dynamic);
690 mono_class_set_failure (MonoClass *klass, guint32 ex_type, void *ex_data);
693 mono_class_get_exception_for_failure (MonoClass *klass);
696 mono_type_get_name_full (MonoType *type, MonoTypeNameFormat format);
698 MonoArrayType *mono_dup_array_type (MonoArrayType *a);
699 MonoMethodSignature *mono_metadata_signature_deep_dup (MonoMethodSignature *sig);
701 #endif /* __MONO_METADATA_CLASS_INTERBALS_H__ */