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 */
253 guint32 declsec_flags; /* declarative security attributes flags */
254 guint32 exception_type; /* MONO_EXCEPTION_* */
255 void* exception_data; /* Additional information about the exception */
258 MonoClass *nested_in;
259 GList *nested_classes;
263 const char *name_space;
265 /* for fast subtype checks */
266 MonoClass **supertypes;
269 guint16 interface_count;
270 guint16 interface_id; /* unique inderface id (for interfaces) */
271 guint16 max_interface_id;
272 gint *interface_offsets;
273 MonoClass **interfaces;
276 * Computed object instance size, total.
280 int vtable_size; /* number of slots */
283 * From the TypeDef table
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;
360 guint count_ifaces : 29;
361 guint is_dynamic : 1;
365 struct _MonoDynamicGenericClass {
366 MonoGenericClass generic_class;
368 MonoMethod **methods;
372 MonoClassField *fields;
373 int count_properties;
374 MonoProperty *properties;
380 struct _MonoGenericMethod {
381 MonoGenericInst *inst;
382 MonoGenericClass *generic_class;
383 MonoGenericContainer *container;
384 gpointer reflection_info;
387 struct _MonoGenericContext {
388 MonoGenericContainer *container;
389 MonoGenericClass *gclass;
390 MonoGenericMethod *gmethod;
393 struct _MonoGenericContainer {
394 MonoGenericContext context;
395 MonoGenericContainer *parent;
396 GHashTable *method_hash;
400 int is_signature : 1;
401 MonoGenericParam *type_params;
404 struct _MonoGenericParam {
405 MonoGenericContainer *owner;
411 MonoClass** constraints; /* NULL means end of list */
415 * Class information which might be cached by the runtime in the AOT file for
416 * example. Caching this allows us to avoid computing a generic vtable
417 * (class->vtable) in most cases, saving time and avoiding creation of lots of
418 * MonoMethod structures.
420 typedef struct MonoCachedClassInfo {
422 guint has_finalize : 1;
426 MonoImage *finalize_image;
427 guint32 finalize_token;
428 } MonoCachedClassInfo;
433 gconstpointer wrapper;
434 MonoMethodSignature *sig;
437 #define mono_class_has_parent(klass,parent) (((klass)->idepth >= (parent)->idepth) && ((klass)->supertypes [(parent)->idepth - 1] == (parent)))
440 gulong new_object_count;
441 gulong initialized_class_count;
442 gulong used_class_count;
443 gulong class_vtable_size;
444 gulong class_static_data_size;
445 gulong generic_instance_count;
446 gulong generic_class_count;
447 gulong inflated_method_count;
448 gulong inflated_method_count_2;
449 gulong inflated_type_count;
450 gulong generics_metadata_size;
454 extern MonoStats mono_stats;
456 typedef gpointer (*MonoTrampoline) (MonoMethod *method);
457 typedef gpointer (*MonoRemotingTrampoline) (MonoMethod *method, MonoRemotingTarget target);
459 typedef gpointer (*MonoLookupDynamicToken) (MonoImage *image, guint32 token, MonoClass **handle_class);
461 typedef gboolean (*MonoGetCachedClassInfo) (MonoClass *klass, MonoCachedClassInfo *res);
464 mono_classes_init (void);
467 mono_class_layout_fields (MonoClass *klass);
470 mono_class_setup_vtable_general (MonoClass *klass, MonoMethod **overrides, int onum);
473 mono_class_setup_vtable (MonoClass *klass);
476 mono_class_setup_methods (MonoClass *klass);
479 mono_class_setup_mono_type (MonoClass *klass);
482 mono_class_setup_parent (MonoClass *klass, MonoClass *parent);
485 mono_class_setup_supertypes (MonoClass *klass);
488 mono_class_get_implemented_interfaces (MonoClass *klass);
491 mono_class_is_open_constructed_type (MonoType *t);
494 mono_class_get_overrides_full (MonoImage *image, guint32 type_token, gint32 *num_overrides,
495 MonoGenericContext *generic_context);
498 mono_class_get_cctor (MonoClass *klass);
501 mono_class_get_finalizer (MonoClass *klass);
504 mono_class_needs_cctor_run (MonoClass *klass, MonoMethod *caller);
507 mono_install_trampoline (MonoTrampoline func);
510 mono_install_remoting_trampoline (MonoRemotingTrampoline func);
513 mono_lookup_dynamic_token (MonoImage *image, guint32 token);
516 mono_lookup_dynamic_token_class (MonoImage *image, guint32 token, MonoClass **handle_class);
519 mono_install_lookup_dynamic_token (MonoLookupDynamicToken func);
522 mono_install_get_cached_class_info (MonoGetCachedClassInfo func);
525 mono_class_create_generic (MonoGenericClass *gclass);
529 MonoClass *object_class;
530 MonoClass *byte_class;
531 MonoClass *void_class;
532 MonoClass *boolean_class;
533 MonoClass *sbyte_class;
534 MonoClass *int16_class;
535 MonoClass *uint16_class;
536 MonoClass *int32_class;
537 MonoClass *uint32_class;
538 MonoClass *int_class;
539 MonoClass *uint_class;
540 MonoClass *int64_class;
541 MonoClass *uint64_class;
542 MonoClass *single_class;
543 MonoClass *double_class;
544 MonoClass *char_class;
545 MonoClass *string_class;
546 MonoClass *enum_class;
547 MonoClass *array_class;
548 MonoClass *delegate_class;
549 MonoClass *multicastdelegate_class;
550 MonoClass *asyncresult_class;
551 MonoClass *waithandle_class;
552 MonoClass *typehandle_class;
553 MonoClass *fieldhandle_class;
554 MonoClass *methodhandle_class;
555 MonoClass *monotype_class;
556 MonoClass *exception_class;
557 MonoClass *threadabortexception_class;
558 MonoClass *thread_class;
559 MonoClass *transparent_proxy_class;
560 MonoClass *real_proxy_class;
561 MonoClass *mono_method_message_class;
562 MonoClass *appdomain_class;
563 MonoClass *field_info_class;
564 MonoClass *method_info_class;
565 MonoClass *stringbuilder_class;
566 MonoClass *math_class;
567 MonoClass *stack_frame_class;
568 MonoClass *stack_trace_class;
569 MonoClass *marshal_class;
570 MonoClass *iserializeable_class;
571 MonoClass *serializationinfo_class;
572 MonoClass *streamingcontext_class;
573 MonoClass *typed_reference_class;
574 MonoClass *argumenthandle_class;
575 MonoClass *marshalbyrefobject_class;
576 MonoClass *monitor_class;
577 MonoClass *iremotingtypeinfo_class;
578 MonoClass *runtimesecurityframe_class;
579 MonoClass *executioncontext_class;
580 MonoClass *generic_array_class;
583 extern MonoDefaults mono_defaults;
586 mono_loader_init (void);
589 mono_loader_lock (void);
592 mono_loader_unlock (void);
595 mono_icall_init (void);
598 mono_icall_cleanup (void);
601 mono_method_get_wrapper_data (MonoMethod *method, guint32 id);
604 mono_install_stack_walk (MonoStackWalkImpl func);
607 mono_metadata_has_generic_params (MonoImage *image, guint32 token);
609 MonoGenericContainer *mono_metadata_load_generic_params (MonoImage *image, guint32 token,
610 MonoGenericContainer *parent_container);
613 mono_create_icall_signature (const char *sigstr);
616 mono_register_jit_icall (gconstpointer func, const char *name, MonoMethodSignature *sig, gboolean is_save);
619 mono_register_jit_icall_wrapper (MonoJitICallInfo *info, gconstpointer wrapper);
622 mono_find_jit_icall_by_name (const char *name);
625 mono_find_jit_icall_by_addr (gconstpointer addr);
628 mono_class_inflate_generic_signature (MonoImage *image, MonoMethodSignature *sig, MonoGenericContext *context);
630 MonoMethodSignature *
631 mono_method_signature_full (MonoMethod *image, MonoGenericContext *context);
634 mono_get_shared_generic_class (MonoGenericContainer *container, gboolean is_dynamic);
637 mono_class_set_failure (MonoClass *klass, guint32 ex_type, void *ex_data);
640 mono_class_get_exception_for_failure (MonoClass *klass);
643 mono_type_get_name_full (MonoType *type, MonoTypeNameFormat format);
645 #endif /* __MONO_METADATA_CLASS_INTERBALS_H__ */