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_REMOTING_TARGET_UNKNOWN,
52 MONO_REMOTING_TARGET_APPDOMAIN
56 guint16 flags; /* method flags */
57 guint16 iflags; /* method implementation flags */
60 MonoMethodSignature *signature;
61 /* name is useful mostly for debugging */
63 /* this is used by the inlining algorithm */
64 unsigned int inline_info:1;
65 unsigned int uses_this:1;
66 unsigned int wrapper_type:5;
67 unsigned int string_ctor:1;
68 unsigned int save_lmf:1;
69 unsigned int dynamic:1; /* created & destroyed during runtime */
70 unsigned int is_inflated:1;
74 struct _MonoMethodNormal {
76 MonoGenericContainer *generic_container;
77 MonoMethodHeader *header;
80 struct _MonoMethodWrapper {
81 MonoMethodNormal method;
85 struct _MonoMethodInflated {
86 MonoMethodNormal nmethod;
87 MonoGenericContext *context;
88 MonoMethod *declaring;
89 MonoMethodInflated *inflated;
92 struct _MonoMethodPInvoke {
95 /* add marshal info */
96 guint16 piflags; /* pinvoke flags */
97 guint16 implmap_idx; /* index into IMPLMAP */
101 MonoType *generic_type;
102 gpointer reflection_info;
106 * MonoClassField is just a runtime representation of the metadata for
107 * field, it doesn't contain the data directly. Static fields are
108 * stored in MonoVTable->data. Instance fields are allocated in the
109 * objects after the object header.
111 struct _MonoClassField {
112 /* Type of the field */
115 /* If this is an instantiated generic type, this is the
116 * "original" type, ie. the MONO_TYPE_VAR or MONO_TYPE_GENERICINST
117 * it was instantiated from.
119 MonoInflatedField *generic_info;
122 * Offset where this field is stored; if it is an instance
123 * field, it's the offset from the start of the object, if
124 * it's static, it's from the start of the memory chunk
125 * allocated for statics for the class.
132 * If the field is constant, pointer to the metadata constant
134 * If the field has an RVA flag, pointer to the data.
139 /* Type where the field was defined */
143 * If the field is constant, the type of the constant.
145 MonoTypeEnum def_type;
148 /* a field is ignored if it's named "_Deleted" and it has the specialname and rtspecialname flags set */
149 #define mono_field_is_deleted(field) ((field)->name[0] == '_' && ((field)->type->attrs & 0x600) && (strcmp ((field)->name, "_Deleted") == 0))
152 MonoClassField *field;
154 MonoMarshalSpec *mspec;
160 MonoMethod *ptr_to_str;
161 MonoMethod *str_to_ptr;
162 MonoMarshalField fields [MONO_ZERO_LEN_ARRAY];
165 struct _MonoProperty {
183 /* type of exception being "on hold" for later processing (see exception_type) */
185 MONO_EXCEPTION_NONE = 0,
186 MONO_EXCEPTION_SECURITY_LINKDEMAND = 1,
187 MONO_EXCEPTION_SECURITY_INHERITANCEDEMAND = 2
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 dummy : 1; /* temporary hack */
243 guint has_references : 1; /* it has GC-tracked references in the instance */
244 guint has_static_refs : 1; /* it has static fields that are GC-tracked */
246 guint32 declsec_flags; /* declarative security attributes flags */
247 guint32 exception_type; /* MONO_EXCEPTION_* */
248 void* exception_data; /* Additional information about the exception */
251 MonoClass *nested_in;
252 GList *nested_classes;
256 const char *name_space;
258 /* for fast subtype checks */
259 MonoClass **supertypes;
262 guint16 interface_count;
263 guint16 interface_id; /* unique inderface id (for interfaces) */
264 guint16 max_interface_id;
265 gint *interface_offsets;
266 MonoClass **interfaces;
269 * Computed object instance size, total.
273 int vtable_size; /* number of slots */
276 * From the TypeDef table
282 } field, method, property, event;
284 /* loaded on demand */
285 MonoMarshalType *marshal_info;
288 * Field information: Type and location from object base
290 MonoClassField *fields;
292 /* Initialized by a call to mono_class_setup_properties () */
293 MonoProperty *properties;
295 /* Initialized by a call to mono_class_setup_events () */
298 MonoMethod **methods;
300 /* used as the type of the this argument and when passing the arg by value */
304 MonoGenericClass *generic_class;
305 MonoGenericContainer *generic_container;
307 void *reflection_info;
311 MonoClassRuntimeInfo *runtime_info;
313 /* Generic vtable. Initialized by a call to mono_class_setup_vtable () */
320 * According to comments in gc_gcj.h, this should be the second word in
324 MonoDomain *domain; /* each object/vtable belongs to exactly one domain */
325 gpointer *interface_offsets;
326 gpointer data; /* to store static class data */
327 gpointer type; /* System.Type type for klass */
328 guint16 max_interface_id;
330 guint remote : 1; /* class is remotely activated */
331 guint initialized : 1; /* cctor has been run */
332 /* do not add any fields after vtable, the structure is dynamically extended */
333 gpointer vtable [MONO_ZERO_LEN_ARRAY];
337 * Generic instantiation data type encoding.
339 struct _MonoGenericInst {
341 guint type_argc : 22;
343 guint is_reference : 1;
344 MonoType **type_argv;
347 struct _MonoGenericClass {
348 MonoGenericInst *inst;
349 MonoClass *container_class;
350 MonoGenericContext *context;
353 guint count_ifaces : 29;
354 guint is_dynamic : 1;
358 struct _MonoDynamicGenericClass {
359 MonoGenericClass generic_class;
361 MonoMethod **methods;
365 MonoClassField *fields;
366 int count_properties;
367 MonoProperty *properties;
373 struct _MonoGenericMethod {
374 MonoGenericInst *inst;
375 MonoGenericContainer *container;
376 gpointer reflection_info;
379 struct _MonoGenericContext {
380 MonoGenericContainer *container;
381 MonoGenericClass *gclass;
382 MonoGenericMethod *gmethod;
385 struct _MonoGenericContainer {
386 MonoGenericContext context;
387 MonoGenericContainer *parent;
388 GHashTable *method_hash;
392 int is_signature : 1;
393 MonoGenericParam *type_params;
396 struct _MonoGenericParam {
397 MonoGenericContainer *owner;
403 MonoClass** constraints; /* NULL means end of list */
407 * Class information which might be cached by the runtime in the AOT file for
408 * example. Caching this allows us to avoid computing a generic vtable
409 * (class->vtable) in most cases, saving time and avoiding creation of lots of
410 * MonoMethod structures.
412 typedef struct MonoCachedClassInfo {
414 guint has_finalize : 1;
418 MonoImage *finalize_image;
419 guint32 finalize_token;
420 } MonoCachedClassInfo;
425 gconstpointer wrapper;
426 MonoMethodSignature *sig;
429 #define mono_class_has_parent(klass,parent) (((klass)->idepth >= (parent)->idepth) && ((klass)->supertypes [(parent)->idepth - 1] == (parent)))
432 gulong new_object_count;
433 gulong initialized_class_count;
434 gulong used_class_count;
435 gulong class_vtable_size;
436 gulong class_static_data_size;
437 gulong generic_instance_count;
438 gulong generic_class_count;
439 gulong inflated_method_count;
440 gulong inflated_method_count_2;
441 gulong inflated_type_count;
442 gulong generics_metadata_size;
446 extern MonoStats mono_stats;
448 typedef gpointer (*MonoTrampoline) (MonoMethod *method);
449 typedef gpointer (*MonoRemotingTrampoline) (MonoMethod *method, MonoRemotingTarget target);
451 typedef gpointer (*MonoLookupDynamicToken) (MonoImage *image, guint32 token, MonoClass **handle_class);
453 typedef gboolean (*MonoGetCachedClassInfo) (MonoClass *klass, MonoCachedClassInfo *res);
456 mono_classes_init (void);
459 mono_class_layout_fields (MonoClass *klass);
462 mono_class_setup_vtable_general (MonoClass *klass, MonoMethod **overrides, int onum);
465 mono_class_setup_vtable (MonoClass *klass);
468 mono_class_setup_methods (MonoClass *klass);
471 mono_class_setup_mono_type (MonoClass *klass);
474 mono_class_setup_parent (MonoClass *klass, MonoClass *parent);
477 mono_class_setup_supertypes (MonoClass *klass);
480 mono_class_get_implemented_interfaces (MonoClass *klass);
483 mono_class_is_open_constructed_type (MonoType *t);
486 mono_class_get_overrides (MonoImage *image, guint32 type_token, gint32 *num_overrides);
489 mono_class_get_cctor (MonoClass *klass);
492 mono_class_get_finalizer (MonoClass *klass);
495 mono_class_needs_cctor_run (MonoClass *klass, MonoMethod *caller);
498 mono_install_trampoline (MonoTrampoline func);
501 mono_install_remoting_trampoline (MonoRemotingTrampoline func);
504 mono_lookup_dynamic_token (MonoImage *image, guint32 token);
507 mono_lookup_dynamic_token_class (MonoImage *image, guint32 token, MonoClass **handle_class);
510 mono_install_lookup_dynamic_token (MonoLookupDynamicToken func);
513 mono_install_get_cached_class_info (MonoGetCachedClassInfo func);
516 mono_class_create_generic (MonoGenericClass *gclass);
520 MonoClass *object_class;
521 MonoClass *byte_class;
522 MonoClass *void_class;
523 MonoClass *boolean_class;
524 MonoClass *sbyte_class;
525 MonoClass *int16_class;
526 MonoClass *uint16_class;
527 MonoClass *int32_class;
528 MonoClass *uint32_class;
529 MonoClass *int_class;
530 MonoClass *uint_class;
531 MonoClass *int64_class;
532 MonoClass *uint64_class;
533 MonoClass *single_class;
534 MonoClass *double_class;
535 MonoClass *char_class;
536 MonoClass *string_class;
537 MonoClass *enum_class;
538 MonoClass *array_class;
539 MonoClass *delegate_class;
540 MonoClass *multicastdelegate_class;
541 MonoClass *asyncresult_class;
542 MonoClass *waithandle_class;
543 MonoClass *typehandle_class;
544 MonoClass *fieldhandle_class;
545 MonoClass *methodhandle_class;
546 MonoClass *monotype_class;
547 MonoClass *exception_class;
548 MonoClass *threadabortexception_class;
549 MonoClass *thread_class;
550 MonoClass *transparent_proxy_class;
551 MonoClass *real_proxy_class;
552 MonoClass *mono_method_message_class;
553 MonoClass *appdomain_class;
554 MonoClass *field_info_class;
555 MonoClass *method_info_class;
556 MonoClass *stringbuilder_class;
557 MonoClass *math_class;
558 MonoClass *stack_frame_class;
559 MonoClass *stack_trace_class;
560 MonoClass *marshal_class;
561 MonoClass *iserializeable_class;
562 MonoClass *serializationinfo_class;
563 MonoClass *streamingcontext_class;
564 MonoClass *typed_reference_class;
565 MonoClass *argumenthandle_class;
566 MonoClass *marshalbyrefobject_class;
567 MonoClass *monitor_class;
568 MonoClass *iremotingtypeinfo_class;
569 MonoClass *runtimesecurityframe_class;
572 extern MonoDefaults mono_defaults;
575 mono_loader_init (void);
578 mono_loader_lock (void);
581 mono_loader_unlock (void);
584 mono_icall_init (void);
587 mono_icall_cleanup (void);
590 mono_method_get_wrapper_data (MonoMethod *method, guint32 id);
593 mono_install_stack_walk (MonoStackWalkImpl func);
596 mono_metadata_has_generic_params (MonoImage *image, guint32 token);
598 MonoGenericContainer *mono_metadata_load_generic_params (MonoImage *image, guint32 token,
599 MonoGenericContainer *parent_container);
602 mono_create_icall_signature (const char *sigstr);
605 mono_register_jit_icall (gconstpointer func, const char *name, MonoMethodSignature *sig, gboolean is_save);
608 mono_register_jit_icall_wrapper (MonoJitICallInfo *info, gconstpointer wrapper);
611 mono_find_jit_icall_by_name (const char *name);
614 mono_find_jit_icall_by_addr (gconstpointer addr);
617 mono_class_inflate_generic_signature (MonoImage *image, MonoMethodSignature *sig, MonoGenericContext *context);
620 mono_get_shared_generic_class (MonoGenericContainer *container, gboolean is_dynamic);
623 mono_class_set_failure (MonoClass *klass, guint32 ex_type, void *ex_data);
626 mono_class_get_exception_for_failure (MonoClass *klass);
628 #endif /* __MONO_METADATA_CLASS_INTERBALS_H__ */