[metadata] Use MONO_PROFILER_API on MonoClass getters in checked builds (#20440)
[mono-project.git] / mono / metadata / class-internals.h
blobe56ae5ea556dd7015a440e653ed330ad22c9129d
1 /**
2 * \file
3 * Copyright 2012 Xamarin Inc
4 * Licensed under the MIT license. See LICENSE file in the project root for full license information.
5 */
6 #ifndef __MONO_METADATA_CLASS_INTERNALS_H__
7 #define __MONO_METADATA_CLASS_INTERNALS_H__
9 #include <mono/metadata/class.h>
10 #include <mono/metadata/object.h>
11 #include <mono/metadata/mempool.h>
12 #include <mono/metadata/metadata-internals.h>
13 #include <mono/metadata/property-bag.h>
14 #include "mono/utils/mono-compiler.h"
15 #include "mono/utils/mono-error.h"
16 #include "mono/sgen/gc-internal-agnostic.h"
17 #include "mono/utils/mono-error-internals.h"
18 #include "mono/utils/mono-memory-model.h"
20 #define MONO_CLASS_IS_ARRAY(c) (m_class_get_rank (c))
22 #define MONO_CLASS_HAS_STATIC_METADATA(klass) (m_class_get_type_token (klass) && !m_class_get_image (klass)->dynamic && !mono_class_is_ginst (klass))
24 #define MONO_DEFAULT_SUPERTABLE_SIZE 6
26 extern gboolean mono_print_vtable;
27 extern gboolean mono_align_small_structs;
28 extern gint32 mono_simd_register_size;
30 typedef struct _MonoMethodWrapper MonoMethodWrapper;
31 typedef struct _MonoMethodInflated MonoMethodInflated;
32 typedef struct _MonoMethodPInvoke MonoMethodPInvoke;
33 typedef struct _MonoDynamicMethod MonoDynamicMethod;
35 /* Properties that applies to a group of structs should better use a higher number
36 * to avoid colision with type specific properties.
38 * This prop applies to class, method, property, event, assembly and image.
40 #define MONO_PROP_DYNAMIC_CATTR 0x1000
42 typedef enum {
43 #define WRAPPER(e,n) MONO_WRAPPER_ ## e,
44 #include "wrapper-types.h"
45 #undef WRAPPER
46 MONO_WRAPPER_NUM
47 } MonoWrapperType;
49 typedef enum {
50 MONO_REMOTING_TARGET_UNKNOWN,
51 MONO_REMOTING_TARGET_APPDOMAIN,
52 MONO_REMOTING_TARGET_COMINTEROP
53 } MonoRemotingTarget;
55 #define MONO_METHOD_PROP_GENERIC_CONTAINER 0
56 /* verification success bit, protected by the image lock */
57 #define MONO_METHOD_PROP_VERIFICATION_SUCCESS 1
58 /* infrequent vtable layout bits protected by the loader lock */
59 #define MONO_METHOD_PROP_INFREQUENT_BITS 2
61 /* Infrequently accessed bits of method definitions stored in the image properties.
62 * The method must not be inflated.
64 * LOCKING: Reading the bits acquires the image lock. Writing the bits assumes
65 * the loader lock is held.
67 typedef struct _MonoMethodDefInfrequentBits {
68 unsigned int is_reabstracted:1; /* whenever this is a reabstraction of another interface */
69 unsigned int is_covariant_override_impl:1; /* whether this is an override with a signature different from its declared method */
70 } MonoMethodDefInfrequentBits;
72 struct _MonoMethod {
73 guint16 flags; /* method flags */
74 guint16 iflags; /* method implementation flags */
75 guint32 token;
76 MonoClass *klass; /* To what class does this method belong */
77 MonoMethodSignature *signature;
78 /* name is useful mostly for debugging */
79 const char *name;
80 /* this is used by the inlining algorithm */
81 unsigned int inline_info:1;
82 unsigned int inline_failure:1;
83 unsigned int wrapper_type:5;
84 unsigned int string_ctor:1;
85 unsigned int save_lmf:1;
86 unsigned int dynamic:1; /* created & destroyed during runtime */
87 unsigned int sre_method:1; /* created at runtime using Reflection.Emit */
88 unsigned int is_generic:1; /* whenever this is a generic method definition */
89 unsigned int is_inflated:1; /* whether we're a MonoMethodInflated */
90 unsigned int skip_visibility:1; /* whenever to skip JIT visibility checks */
91 unsigned int _unused : 2; /* unused */
92 signed int slot : 16;
95 * If is_generic is TRUE, the generic_container is stored in image->property_hash,
96 * using the key MONO_METHOD_PROP_GENERIC_CONTAINER.
100 struct _MonoMethodWrapper {
101 MonoMethod method;
102 MonoMethodHeader *header;
103 void *method_data;
106 struct _MonoDynamicMethod {
107 MonoMethodWrapper method;
108 MonoAssembly *assembly;
111 struct _MonoMethodPInvoke {
112 MonoMethod method;
113 gpointer addr;
114 /* add marshal info */
115 guint16 piflags; /* pinvoke flags */
116 guint32 implmap_idx; /* index into IMPLMAP */
120 * Stores the default value / RVA of fields.
121 * This information is rarely needed, so it is stored separately from
122 * MonoClassField.
124 typedef struct MonoFieldDefaultValue {
126 * If the field is constant, pointer to the metadata constant
127 * value.
128 * If the field has an RVA flag, pointer to the data.
129 * Else, invalid.
131 const char *data;
133 /* If the field is constant, the type of the constant. */
134 MonoTypeEnum def_type;
135 } MonoFieldDefaultValue;
138 * MonoClassField is just a runtime representation of the metadata for
139 * field, it doesn't contain the data directly. Static fields are
140 * stored in MonoVTable->data. Instance fields are allocated in the
141 * objects after the object header.
143 struct _MonoClassField {
144 /* Type of the field */
145 MonoType *type;
147 const char *name;
149 /* Type where the field was defined */
150 MonoClass *parent;
153 * Offset where this field is stored; if it is an instance
154 * field, it's the offset from the start of the object, if
155 * it's static, it's from the start of the memory chunk
156 * allocated for statics for the class.
157 * For special static fields, this is set to -1 during vtable construction.
159 int offset;
162 /* a field is ignored if it's named "_Deleted" and it has the specialname and rtspecialname flags set */
163 #define mono_field_is_deleted(field) (((field)->type->attrs & (FIELD_ATTRIBUTE_SPECIAL_NAME | FIELD_ATTRIBUTE_RT_SPECIAL_NAME)) \
164 && (strcmp (mono_field_get_name (field), "_Deleted") == 0))
166 /* a field is ignored if it's named "_Deleted" and it has the specialname and rtspecialname flags set */
167 /* Try to avoid loading the field's type */
168 #define mono_field_is_deleted_with_flags(field, flags) (((flags) & (FIELD_ATTRIBUTE_SPECIAL_NAME | FIELD_ATTRIBUTE_RT_SPECIAL_NAME)) \
169 && (strcmp (mono_field_get_name (field), "_Deleted") == 0))
171 typedef struct {
172 MonoClassField *field;
173 guint32 offset;
174 MonoMarshalSpec *mspec;
175 } MonoMarshalField;
177 typedef struct {
178 MonoPropertyBagItem head;
180 guint32 native_size, min_align;
181 guint32 num_fields;
182 MonoMethod *ptr_to_str;
183 MonoMethod *str_to_ptr;
184 MonoMarshalField fields [MONO_ZERO_LEN_ARRAY];
185 } MonoMarshalType;
187 #define MONO_SIZEOF_MARSHAL_TYPE (offsetof (MonoMarshalType, fields))
189 struct _MonoProperty {
190 MonoClass *parent;
191 const char *name;
192 MonoMethod *get;
193 MonoMethod *set;
194 guint32 attrs;
197 struct _MonoEvent {
198 MonoClass *parent;
199 const char *name;
200 MonoMethod *add;
201 MonoMethod *remove;
202 MonoMethod *raise;
203 #ifndef MONO_SMALL_CONFIG
204 MonoMethod **other;
205 #endif
206 guint32 attrs;
209 /* type of exception being "on hold" for later processing (see exception_type) */
210 typedef enum {
211 MONO_EXCEPTION_NONE = 0,
212 MONO_EXCEPTION_INVALID_PROGRAM = 3,
213 MONO_EXCEPTION_UNVERIFIABLE_IL = 4,
214 MONO_EXCEPTION_MISSING_METHOD = 5,
215 MONO_EXCEPTION_MISSING_FIELD = 6,
216 MONO_EXCEPTION_TYPE_LOAD = 7,
217 MONO_EXCEPTION_FILE_NOT_FOUND = 8,
218 MONO_EXCEPTION_METHOD_ACCESS = 9,
219 MONO_EXCEPTION_FIELD_ACCESS = 10,
220 MONO_EXCEPTION_GENERIC_SHARING_FAILED = 11,
221 MONO_EXCEPTION_BAD_IMAGE = 12,
222 MONO_EXCEPTION_OBJECT_SUPPLIED = 13, /*The exception object is already created.*/
223 MONO_EXCEPTION_OUT_OF_MEMORY = 14,
224 MONO_EXCEPTION_INLINE_FAILED = 15,
225 MONO_EXCEPTION_MONO_ERROR = 16,
226 /* add other exception type */
227 } MonoExceptionType;
229 /* This struct collects the info needed for the runtime use of a class,
230 * like the vtables for a domain, the GC descriptor, etc.
232 typedef struct {
233 guint16 max_domain;
234 /* domain_vtables is indexed by the domain id and the size is max_domain + 1 */
235 MonoVTable *domain_vtables [MONO_ZERO_LEN_ARRAY];
236 } MonoClassRuntimeInfo;
238 #define MONO_SIZEOF_CLASS_RUNTIME_INFO (sizeof (MonoClassRuntimeInfo) - MONO_ZERO_LEN_ARRAY * SIZEOF_VOID_P)
240 typedef struct {
241 MonoPropertyBagItem head;
243 MonoProperty *properties;
244 guint32 first, count;
245 MonoFieldDefaultValue *def_values;
246 } MonoClassPropertyInfo;
248 typedef struct {
249 MonoPropertyBagItem head;
251 /* Initialized by a call to mono_class_setup_events () */
252 MonoEvent *events;
253 guint32 first, count;
254 } MonoClassEventInfo;
256 typedef enum {
257 MONO_CLASS_DEF = 1, /* non-generic type */
258 MONO_CLASS_GTD, /* generic type definition */
259 MONO_CLASS_GINST, /* generic instantiation */
260 MONO_CLASS_GPARAM, /* generic parameter */
261 MONO_CLASS_ARRAY, /* vector or array, bounded or not */
262 MONO_CLASS_POINTER, /* pointer or function pointer*/
263 } MonoTypeKind;
265 typedef struct _MonoClassDef MonoClassDef;
266 typedef struct _MonoClassGtd MonoClassGtd;
267 typedef struct _MonoClassGenericInst MonoClassGenericInst;
268 typedef struct _MonoClassGenericParam MonoClassGenericParam;
269 typedef struct _MonoClassArray MonoClassArray;
270 typedef struct _MonoClassPointer MonoClassPointer;
272 union _MonoClassSizes {
273 int class_size; /* size of area for static fields */
274 int element_size; /* for array types */
275 int generic_param_token; /* for generic param types, both var and mvar */
278 /* enabled only with small config for now: we might want to do it unconditionally */
279 #ifdef MONO_SMALL_CONFIG
280 #define COMPRESSED_INTERFACE_BITMAP 1
281 #endif
284 #ifdef ENABLE_CHECKED_BUILD_PRIVATE_TYPES
285 #define MONO_CLASS_DEF_PRIVATE 1
286 #endif
288 /* Hide _MonoClass definition in checked build mode to ensure that
289 * it is only accessed via getter and setter methods.
291 #ifndef MONO_CLASS_DEF_PRIVATE
292 #include "class-private-definition.h"
293 #endif
295 /* If MonoClass definition is hidden, just declare the getters.
296 * Otherwise, define them as static inline functions.
298 * In-tree profilers are allowed to use the getters. So if we're compiling
299 * with --enable-checked-build=private_types, mark the symbols with
300 * MONO_PROFILER_API
302 #ifdef MONO_CLASS_DEF_PRIVATE
303 #define MONO_CLASS_GETTER(funcname, rettype, optref, argtype, fieldname) MONO_PROFILER_API rettype funcname (argtype *klass);
304 #else
305 #define MONO_CLASS_GETTER(funcname, rettype, optref, argtype, fieldname) static inline rettype funcname (argtype *klass) { return optref klass-> fieldname ; }
306 #endif
307 #define MONO_CLASS_OFFSET(funcname, argtype, fieldname) /*nothing*/
308 #include "class-getters.h"
309 #undef MONO_CLASS_GETTER
310 #undef MONO_CLASS_OFFSET
312 #ifdef COMPRESSED_INTERFACE_BITMAP
313 int mono_compress_bitmap (uint8_t *dest, const uint8_t *bitmap, int size);
314 int mono_class_interface_match (const uint8_t *bitmap, int id);
315 #else
316 #define mono_class_interface_match(bmap,uiid) ((bmap) [(uiid) >> 3] & (1 << ((uiid)&7)))
317 #endif
319 #define MONO_CLASS_IMPLEMENTS_INTERFACE(k,uiid) (((uiid) <= m_class_get_max_interface_id (k)) && mono_class_interface_match (m_class_get_interface_bitmap (k), (uiid)))
321 #define MONO_VTABLE_AVAILABLE_GC_BITS 4
323 #ifdef DISABLE_REMOTING
324 #define mono_class_is_marshalbyref(klass) (FALSE)
325 #define mono_class_is_contextbound(klass) (FALSE)
326 #define mono_vtable_is_remote(vtable) (FALSE)
327 #define mono_vtable_set_is_remote(vtable,enable) do {} while (0)
328 #else
329 #define mono_class_is_marshalbyref(klass) (m_class_get_marshalbyref (klass))
330 #define mono_class_is_contextbound(klass) (m_class_get_contextbound (klass))
331 #define mono_vtable_is_remote(vtable) ((vtable)->remote)
332 #define mono_vtable_set_is_remote(vtable,enable) do { (vtable)->remote = enable ? 1 : 0; } while (0)
333 #endif
335 #ifdef DISABLE_COM
336 #define mono_class_is_com_object(klass) (FALSE)
337 #else
338 #define mono_class_is_com_object(klass) (m_class_is_com_object (klass))
339 #endif
342 MONO_API int mono_class_interface_offset (MonoClass *klass, MonoClass *itf);
343 int mono_class_interface_offset_with_variance (MonoClass *klass, MonoClass *itf, gboolean *non_exact_match);
345 typedef gpointer MonoRuntimeGenericContext;
347 typedef enum {
348 /* array or string */
349 MONO_VT_FLAG_ARRAY_OR_STRING = (1 << 0),
350 MONO_VT_FLAG_HAS_REFERENCES = (1 << 1),
351 MONO_VT_FLAG_ARRAY_IS_PRIMITIVE = (1 << 2),
352 } MonoVTableFlags;
354 /* the interface_offsets array is stored in memory before this struct */
355 struct MonoVTable {
356 MonoClass *klass;
358 * According to comments in gc_gcj.h, this should be the second word in
359 * the vtable.
361 MonoGCDescriptor gc_descr;
362 MonoDomain *domain; /* each object/vtable belongs to exactly one domain */
363 gpointer type; /* System.Type type for klass */
364 guint8 *interface_bitmap;
365 guint32 max_interface_id;
366 guint8 rank;
367 /* Keep this a guint8, the jit depends on it */
368 guint8 initialized; /* cctor has been run */
369 /* Keep this a guint8, the jit depends on it */
370 guint8 flags; /* MonoVTableFlags */
371 guint remote : 1; /* class is remotely activated */
372 guint init_failed : 1; /* cctor execution failed */
373 guint has_static_fields : 1; /* pointer to the data stored at the end of the vtable array */
374 guint gc_bits : MONO_VTABLE_AVAILABLE_GC_BITS; /* Those bits are reserved for the usaged of the GC */
376 guint32 imt_collisions_bitmap;
377 MonoRuntimeGenericContext *runtime_generic_context;
378 /* interp virtual method table */
379 gpointer *interp_vtable;
380 /* do not add any fields after vtable, the structure is dynamically extended */
381 /* vtable contains function pointers to methods or their trampolines, at the
382 end there may be a slot containing the pointer to the static fields */
383 gpointer vtable [MONO_ZERO_LEN_ARRAY];
386 #define MONO_SIZEOF_VTABLE (sizeof (MonoVTable) - MONO_ZERO_LEN_ARRAY * SIZEOF_VOID_P)
388 #define MONO_VTABLE_IMPLEMENTS_INTERFACE(vt,uiid) (((uiid) <= (vt)->max_interface_id) && mono_class_interface_match ((vt)->interface_bitmap, (uiid)))
391 * Generic instantiation data type encoding.
395 * A particular generic instantiation:
397 * All instantiations are cached and we don't distinguish between class and method
398 * instantiations here.
400 struct _MonoGenericInst {
401 #ifndef MONO_SMALL_CONFIG
402 gint32 id; /* unique ID for debugging */
403 #endif
404 guint type_argc : 22; /* number of type arguments */
405 guint is_open : 1; /* if this is an open type */
406 MonoType *type_argv [MONO_ZERO_LEN_ARRAY];
409 #define MONO_SIZEOF_GENERIC_INST (sizeof (MonoGenericInst) - MONO_ZERO_LEN_ARRAY * SIZEOF_VOID_P)
411 * The generic context: an instantiation of a set of class and method generic parameters.
413 * NOTE: Never allocate this directly on the heap. It have to be either allocated on the stack,
414 * or embedded within other objects. Don't store pointers to this, because it may be on the stack.
415 * If you really have to, ensure you store a pointer to the embedding object along with it.
417 struct _MonoGenericContext {
418 /* The instantiation corresponding to the class generic parameters */
419 MonoGenericInst *class_inst;
420 /* The instantiation corresponding to the method generic parameters */
421 MonoGenericInst *method_inst;
425 * Inflated generic method.
427 struct _MonoMethodInflated {
428 union {
429 MonoMethod method;
430 MonoMethodPInvoke pinvoke;
431 } method;
432 MonoMethod *declaring; /* the generic method definition. */
433 MonoGenericContext context; /* The current instantiation */
434 MonoImageSet *owner; /* The image set that the inflated method belongs to. */
438 * A particular instantiation of a generic type.
440 struct _MonoGenericClass {
441 MonoClass *container_class; /* the generic type definition */
442 MonoGenericContext context; /* a context that contains the type instantiation doesn't contain any method instantiation */ /* FIXME: Only the class_inst member of "context" is ever used, so this field could be replaced with just a monogenericinst */
443 guint is_dynamic : 1; /* Contains dynamic types */
444 guint is_tb_open : 1; /* This is the fully open instantiation for a type_builder. Quite ugly, but it's temporary.*/
445 guint need_sync : 1; /* Only if dynamic. Need to be synchronized with its container class after its finished. */
446 MonoClass *cached_class; /* if present, the MonoClass corresponding to the instantiation. */
449 * The image set which owns this generic class. Memory owned by the generic class
450 * including cached_class should be allocated from the mempool of the image set,
451 * so it is easy to free.
453 MonoImageSet *owner;
456 /* Additional details about a MonoGenericParam */
457 /* Keep in sync with managed Mono.RuntimeStructs.GenericParamInfo */
458 typedef struct {
459 MonoClass *pklass; /* The corresponding `MonoClass'. */
460 const char *name;
462 // See GenericParameterAttributes
463 guint16 flags;
465 guint32 token;
467 // Constraints on type parameters
468 MonoClass** constraints; /* NULL means end of list */
469 } MonoGenericParamInfo;
472 * A type parameter.
474 struct _MonoGenericParam {
476 * Type or method this parameter was defined in.
478 MonoGenericContainer *owner;
479 guint16 num;
481 * If != NULL, this is a generated generic param used by the JIT to implement generic
482 * sharing.
484 MonoType *gshared_constraint;
486 MonoGenericParamInfo info;
489 typedef MonoGenericParam MonoGenericParamFull;
492 * The generic container.
494 * Stores the type parameters of a generic type definition or a generic method definition.
496 struct _MonoGenericContainer {
497 MonoGenericContext context;
498 /* If we're a generic method definition in a generic type definition,
499 the generic container of the containing class. */
500 MonoGenericContainer *parent;
501 /* the generic type definition or the generic method definition corresponding to this container */
502 /* Union rules: If is_anonymous, image field is valid; else if is_method, method field is valid; else klass is valid. */
503 union {
504 MonoClass *klass;
505 MonoMethod *method;
506 MonoImage *image;
507 } owner;
508 int type_argc : 29; // Per the ECMA spec, this value is capped at 16 bits
509 /* If true, we're a generic method, otherwise a generic type definition. */
510 /* Invariant: parent != NULL => is_method */
511 int is_method : 1;
512 /* If true, this container has no associated class/method and only the image is known. This can happen:
513 1. For the special anonymous containers kept by MonoImage.
514 2. When user code creates a generic parameter via SRE, but has not yet set an owner. */
515 int is_anonymous : 1;
516 /* Our type parameters. If this is a special anonymous container (case 1, above), this field is not valid, use mono_metadata_create_anon_gparam () */
517 MonoGenericParamFull *type_params;
520 static inline MonoGenericParam *
521 mono_generic_container_get_param (MonoGenericContainer *gc, int i)
523 return (MonoGenericParam *) &gc->type_params [i];
526 static inline MonoGenericParamInfo *
527 mono_generic_container_get_param_info (MonoGenericContainer *gc, int i)
529 return &gc->type_params [i].info;
532 static inline MonoGenericContainer *
533 mono_generic_param_owner (MonoGenericParam *p)
535 return p->owner;
538 static inline int
539 mono_generic_param_num (MonoGenericParam *p)
541 return p->num;
544 static inline MonoGenericParamInfo *
545 mono_generic_param_info (MonoGenericParam *p)
547 return &((MonoGenericParamFull *) p)->info;
550 static inline const char *
551 mono_generic_param_name (MonoGenericParam *p)
553 return ((MonoGenericParamFull *) p)->info.name;
556 static inline MonoGenericContainer *
557 mono_type_get_generic_param_owner (MonoType *t)
559 return mono_generic_param_owner (t->data.generic_param);
562 static inline int
563 mono_type_get_generic_param_num (MonoType *t)
565 return mono_generic_param_num (t->data.generic_param);
569 * Class information which might be cached by the runtime in the AOT file for
570 * example. Caching this allows us to avoid computing a generic vtable
571 * (class->vtable) in most cases, saving time and avoiding creation of lots of
572 * MonoMethod structures.
574 typedef struct MonoCachedClassInfo {
575 guint32 vtable_size;
576 guint has_finalize : 1;
577 guint ghcimpl : 1;
578 guint has_cctor : 1;
579 guint has_nested_classes : 1;
580 guint blittable : 1;
581 guint has_references : 1;
582 guint has_static_refs : 1;
583 guint no_special_static_fields : 1;
584 guint is_generic_container : 1;
585 guint has_weak_fields : 1;
586 guint32 cctor_token;
587 MonoImage *finalize_image;
588 guint32 finalize_token;
589 guint32 instance_size;
590 guint32 class_size;
591 guint32 packing_size;
592 guint32 min_align;
593 } MonoCachedClassInfo;
595 typedef struct {
596 // Name and func fields double as "inited".
597 // That is, any initialized MonoJitICallInfo must
598 // have both of them to be non-NULL.
599 const char *name;
600 gconstpointer func;
601 gconstpointer wrapper;
602 gconstpointer trampoline;
603 MonoMethodSignature *sig;
604 const char *c_symbol;
605 MonoMethod *wrapper_method;
606 } MonoJitICallInfo;
608 void
609 mono_class_setup_supertypes (MonoClass *klass);
611 /* WARNING
612 * Only call this function if you can ensure both @klass and @parent
613 * have supertype information initialized.
614 * This can be accomplished by mono_class_setup_supertypes or mono_class_init.
615 * If unsure, use mono_class_has_parent.
617 static inline gboolean
618 mono_class_has_parent_fast (MonoClass *klass, MonoClass *parent)
620 return (m_class_get_idepth (klass) >= m_class_get_idepth (parent)) && (m_class_get_supertypes (klass) [m_class_get_idepth (parent) - 1] == parent);
623 static inline gboolean
624 mono_class_has_parent (MonoClass *klass, MonoClass *parent)
626 if (G_UNLIKELY (!m_class_get_supertypes (klass)))
627 mono_class_setup_supertypes (klass);
629 if (G_UNLIKELY (!m_class_get_supertypes (parent)))
630 mono_class_setup_supertypes (parent);
632 return mono_class_has_parent_fast (klass, parent);
635 typedef struct {
636 MonoVTable *default_vtable;
637 MonoVTable *xdomain_vtable;
638 MonoClass *proxy_class;
639 char* proxy_class_name;
640 uint32_t interface_count;
641 MonoClass *interfaces [MONO_ZERO_LEN_ARRAY];
642 } MonoRemoteClass;
644 #define MONO_SIZEOF_REMOTE_CLASS (sizeof (MonoRemoteClass) - MONO_ZERO_LEN_ARRAY * SIZEOF_VOID_P)
646 typedef struct {
647 gint32 initialized_class_count;
648 gint32 generic_vtable_count;
649 gint32 used_class_count;
650 gint32 method_count;
651 gint32 class_vtable_size;
652 gint32 class_static_data_size;
653 gint32 generic_class_count;
654 gint32 inflated_method_count;
655 gint32 inflated_type_count;
656 gint32 delegate_creations;
657 gint32 imt_tables_size;
658 gint32 imt_number_of_tables;
659 gint32 imt_number_of_methods;
660 gint32 imt_used_slots;
661 gint32 imt_slots_with_collisions;
662 gint32 imt_max_collisions_in_slot;
663 gint32 imt_method_count_when_max_collisions;
664 gint32 imt_trampolines_size;
665 gint32 jit_info_table_insert_count;
666 gint32 jit_info_table_remove_count;
667 gint32 jit_info_table_lookup_count;
668 gint32 generics_sharable_methods;
669 gint32 generics_unsharable_methods;
670 gint32 generics_shared_methods;
671 gint32 gsharedvt_methods;
672 gboolean enabled;
673 } MonoStats;
676 * new structure to hold performace counters values that are exported
677 * to managed code.
678 * Note: never remove fields from this structure and only add them to the end.
679 * Size of fields and type should not be changed as well.
681 typedef struct {
682 /* JIT category */
683 gint32 jit_methods;
684 gint32 jit_bytes;
685 gint32 jit_time;
686 gint32 jit_failures;
687 /* Exceptions category */
688 gint32 exceptions_thrown;
689 gint32 exceptions_filters;
690 gint32 exceptions_finallys;
691 gint32 exceptions_depth;
692 gint32 aspnet_requests_queued;
693 gint32 aspnet_requests;
694 /* Memory category */
695 gint32 gc_collections0;
696 gint32 gc_collections1;
697 gint32 gc_collections2;
698 gint32 gc_promotions0;
699 gint32 gc_promotions1;
700 gint32 gc_promotion_finalizers;
701 gint64 gc_gen0size;
702 gint64 gc_gen1size;
703 gint64 gc_gen2size;
704 gint32 gc_lossize;
705 gint32 gc_fin_survivors;
706 gint32 gc_num_handles;
707 gint32 gc_allocated;
708 gint32 gc_induced;
709 gint32 gc_time;
710 gint64 gc_total_bytes;
711 gint64 gc_committed_bytes;
712 gint64 gc_reserved_bytes;
713 gint32 gc_num_pinned;
714 gint32 gc_sync_blocks;
715 /* Remoting category */
716 gint32 remoting_calls;
717 gint32 remoting_channels;
718 gint32 remoting_proxies;
719 gint32 remoting_classes;
720 gint32 remoting_objects;
721 gint32 remoting_contexts;
722 /* Loader category */
723 gint32 loader_classes;
724 gint32 loader_total_classes;
725 gint32 loader_appdomains;
726 gint32 loader_total_appdomains;
727 gint32 loader_assemblies;
728 gint32 loader_total_assemblies;
729 gint32 loader_failures;
730 gint32 loader_bytes;
731 gint32 loader_appdomains_uloaded;
732 /* Threads and Locks category */
733 gint32 thread_contentions;
734 gint32 thread_queue_len;
735 gint32 thread_queue_max;
736 gint32 thread_num_logical;
737 gint32 thread_num_physical;
738 gint32 thread_cur_recognized;
739 gint32 thread_num_recognized;
740 /* Interop category */
741 gint32 interop_num_ccw;
742 gint32 interop_num_stubs;
743 gint32 interop_num_marshals;
744 /* Security category */
745 gint32 security_num_checks;
746 gint32 security_num_link_checks;
747 gint32 security_time;
748 gint32 security_depth;
749 gint32 unused;
750 /* Threadpool */
751 gint32 threadpool_threads;
752 gint64 threadpool_workitems;
753 gint64 threadpool_ioworkitems;
754 gint32 threadpool_iothreads;
755 } MonoPerfCounters;
757 extern MonoPerfCounters *mono_perfcounters;
759 MONO_API void mono_perfcounters_init (void);
762 * The definition of the first field in SafeHandle,
763 * Keep in sync with SafeHandle.cs, this is only used
764 * to access the `handle' parameter.
766 typedef struct {
767 MonoObject base;
768 void *handle;
769 } MonoSafeHandle;
772 * Keep in sync with HandleRef.cs
774 typedef struct {
775 MonoObject *wrapper;
776 void *handle;
777 } MonoHandleRef;
779 extern MonoStats mono_stats;
781 typedef gboolean (*MonoGetCachedClassInfo) (MonoClass *klass, MonoCachedClassInfo *res);
783 typedef gboolean (*MonoGetClassFromName) (MonoImage *image, const char *name_space, const char *name, MonoClass **res);
785 static inline gboolean
786 method_is_dynamic (MonoMethod *method)
788 #ifdef DISABLE_REFLECTION_EMIT
789 return FALSE;
790 #else
791 return method->dynamic;
792 #endif
795 MonoMethod*
796 mono_class_get_method_by_index (MonoClass *klass, int index);
798 MonoMethod*
799 mono_class_get_inflated_method (MonoClass *klass, MonoMethod *method, MonoError *error);
801 MonoMethod*
802 mono_class_get_vtable_entry (MonoClass *klass, int offset);
804 GPtrArray*
805 mono_class_get_implemented_interfaces (MonoClass *klass, MonoError *error);
808 mono_class_get_vtable_size (MonoClass *klass);
810 gboolean
811 mono_class_is_open_constructed_type (MonoType *t);
813 void
814 mono_class_get_overrides_full (MonoImage *image, guint32 type_token, MonoMethod ***overrides, gint32 *num_overrides, MonoGenericContext *generic_context, MonoError *error);
816 MonoMethod*
817 mono_class_get_cctor (MonoClass *klass);
819 MonoMethod*
820 mono_class_get_finalizer (MonoClass *klass);
822 gboolean
823 mono_class_needs_cctor_run (MonoClass *klass, MonoMethod *caller);
825 gboolean
826 mono_class_field_is_special_static (MonoClassField *field);
828 guint32
829 mono_class_field_get_special_static_type (MonoClassField *field);
831 gboolean
832 mono_class_has_special_static_fields (MonoClass *klass);
834 const char*
835 mono_class_get_field_default_value (MonoClassField *field, MonoTypeEnum *def_type);
837 MonoProperty*
838 mono_class_get_property_from_name_internal (MonoClass *klass, const char *name);
840 const char*
841 mono_class_get_property_default_value (MonoProperty *property, MonoTypeEnum *def_type);
843 gpointer
844 mono_lookup_dynamic_token (MonoImage *image, guint32 token, MonoGenericContext *context, MonoError *error);
846 gpointer
847 mono_lookup_dynamic_token_class (MonoImage *image, guint32 token, gboolean check_token, MonoClass **handle_class, MonoGenericContext *context, MonoError *error);
849 gpointer
850 mono_runtime_create_delegate_trampoline (MonoClass *klass);
852 void
853 mono_install_get_cached_class_info (MonoGetCachedClassInfo func);
855 void
856 mono_install_get_class_from_name (MonoGetClassFromName func);
858 MONO_PROFILER_API MonoGenericContext*
859 mono_class_get_context (MonoClass *klass);
861 MONO_PROFILER_API MonoMethodSignature*
862 mono_method_signature_checked_slow (MonoMethod *m, MonoError *err);
864 MONO_PROFILER_API MonoMethodSignature*
865 mono_method_signature_internal_slow (MonoMethod *m);
868 * mono_method_signature_checked:
870 * Return the signature of the method M. On failure, returns NULL, and ERR is set.
872 static inline MonoMethodSignature*
873 mono_method_signature_checked (MonoMethod *m, MonoError *error)
875 error_init (error);
876 MonoMethodSignature* sig = m->signature;
877 return sig ? sig : mono_method_signature_checked_slow (m, error);
881 * mono_method_signature_internal:
882 * \returns the signature of the method \p m. On failure, returns NULL.
884 static inline MonoMethodSignature*
885 mono_method_signature_internal (MonoMethod *m)
887 MonoMethodSignature* sig = m->signature;
888 return sig ? sig : mono_method_signature_internal_slow (m);
891 MonoGenericContext*
892 mono_method_get_context_general (MonoMethod *method, gboolean uninflated);
894 MONO_PROFILER_API MonoGenericContext*
895 mono_method_get_context (MonoMethod *method);
897 /* Used by monodis, thus cannot be MONO_INTERNAL */
898 MONO_API MonoGenericContainer*
899 mono_method_get_generic_container (MonoMethod *method);
901 MonoGenericContext*
902 mono_generic_class_get_context (MonoGenericClass *gclass);
904 void
905 mono_method_set_generic_container (MonoMethod *method, MonoGenericContainer* container);
907 void
908 mono_method_set_verification_success (MonoMethod *method);
910 gboolean
911 mono_method_get_verification_success (MonoMethod *method);
913 const MonoMethodDefInfrequentBits *
914 mono_method_lookup_infrequent_bits (MonoMethod *methoddef);
916 MonoMethodDefInfrequentBits *
917 mono_method_get_infrequent_bits (MonoMethod *methoddef);
919 gboolean
920 mono_method_get_is_reabstracted (MonoMethod *method);
922 void
923 mono_method_set_is_reabstracted (MonoMethod *methoddef);
925 gboolean
926 mono_method_get_is_covariant_override_impl (MonoMethod *method);
928 void
929 mono_method_set_is_covariant_override_impl (MonoMethod *methoddef);
931 MonoMethod*
932 mono_class_inflate_generic_method_full_checked (MonoMethod *method, MonoClass *klass_hint, MonoGenericContext *context, MonoError *error);
934 MonoMethod *
935 mono_class_inflate_generic_method_checked (MonoMethod *method, MonoGenericContext *context, MonoError *error);
937 MonoImageSet *
938 mono_metadata_get_image_set_for_class (MonoClass *klass);
940 MonoImageSet *
941 mono_metadata_get_image_set_for_method (MonoMethodInflated *method);
943 MONO_API MonoMethodSignature *
944 mono_metadata_get_inflated_signature (MonoMethodSignature *sig, MonoGenericContext *context);
946 MonoType*
947 mono_class_inflate_generic_type_with_mempool (MonoImage *image, MonoType *type, MonoGenericContext *context, MonoError *error);
949 MonoType*
950 mono_class_inflate_generic_type_checked (MonoType *type, MonoGenericContext *context, MonoError *error);
952 MONO_API void
953 mono_metadata_free_inflated_signature (MonoMethodSignature *sig);
955 MonoMethodSignature*
956 mono_inflate_generic_signature (MonoMethodSignature *sig, MonoGenericContext *context, MonoError *error);
958 MonoClass*
959 mono_generic_param_get_base_type (MonoClass *klass);
961 typedef struct {
962 MonoImage *corlib;
963 MonoClass *object_class;
964 MonoClass *object_class_array; // used via token pasting in mono_array_class_get_cached
965 MonoClass *byte_class;
966 MonoClass *void_class;
967 MonoClass *boolean_class;
968 MonoClass *sbyte_class;
969 MonoClass *int16_class;
970 MonoClass *uint16_class;
971 MonoClass *int32_class;
972 MonoClass *uint32_class;
973 MonoClass *int_class;
974 MonoClass *uint_class;
975 MonoClass *int64_class;
976 MonoClass *uint64_class;
977 MonoClass *single_class;
978 MonoClass *double_class;
979 MonoClass *char_class;
980 MonoClass *string_class;
981 MonoClass *enum_class;
982 MonoClass *array_class;
983 MonoClass *delegate_class;
984 MonoClass *multicastdelegate_class;
985 MonoClass *manualresetevent_class;
986 MonoClass *typehandle_class;
987 MonoClass *fieldhandle_class;
988 MonoClass *methodhandle_class;
989 MonoClass *systemtype_class;
990 MonoClass *runtimetype_class;
991 MonoClass *runtimetype_class_array; // used via token pasting in mono_array_class_get_cached
992 MonoClass *exception_class;
993 MonoClass *threadabortexception_class;
994 MonoClass *thread_class;
995 MonoClass *internal_thread_class;
996 #ifndef DISABLE_REMOTING
997 MonoClass *transparent_proxy_class;
998 MonoClass *real_proxy_class;
999 MonoClass *marshalbyrefobject_class;
1000 MonoClass *iremotingtypeinfo_class;
1001 #endif
1002 MonoClass *mono_method_message_class;
1003 MonoClass *appdomain_class;
1004 MonoClass *field_info_class;
1005 MonoClass *method_info_class;
1006 MonoClass *stack_frame_class;
1007 MonoClass *marshal_class;
1008 MonoClass *typed_reference_class;
1009 MonoClass *argumenthandle_class;
1010 MonoClass *monitor_class;
1011 MonoClass *generic_ilist_class;
1012 MonoClass *generic_nullable_class;
1013 MonoClass *attribute_class;
1014 MonoClass *attribute_class_array; // used via token pasting in mono_array_class_get_cached
1015 MonoClass *critical_finalizer_object; /* MAYBE NULL */
1016 MonoClass *generic_ireadonlylist_class;
1017 MonoClass *generic_ienumerator_class;
1018 #ifdef ENABLE_NETCORE
1019 MonoClass *alc_class;
1020 MonoClass *appcontext_class;
1021 #endif
1022 #ifndef ENABLE_NETCORE
1023 MonoMethod *threadpool_perform_wait_callback_method;
1024 #endif
1025 } MonoDefaults;
1027 #ifdef DISABLE_REMOTING
1028 #define mono_class_is_transparent_proxy(klass) (FALSE)
1029 #define mono_class_is_real_proxy(klass) (FALSE)
1030 #else
1031 #define mono_class_is_transparent_proxy(klass) ((klass) == mono_defaults.transparent_proxy_class)
1032 #define mono_class_is_real_proxy(klass) ((klass) == mono_defaults.real_proxy_class)
1033 #endif
1035 #define mono_object_is_transparent_proxy(object) (mono_class_is_transparent_proxy (mono_object_class (object)))
1038 #define GENERATE_GET_CLASS_WITH_CACHE_DECL(shortname) \
1039 MonoClass* mono_class_get_##shortname##_class (void);
1041 #define GENERATE_TRY_GET_CLASS_WITH_CACHE_DECL(shortname) \
1042 MonoClass* mono_class_try_get_##shortname##_class (void);
1044 // GENERATE_GET_CLASS_WITH_CACHE attempts mono_class_load_from_name whenever
1045 // its cache is null. i.e. potentially repeatedly, though it is expected to succeed
1046 // the first time.
1048 #define GENERATE_GET_CLASS_WITH_CACHE(shortname,name_space,name) \
1049 MonoClass* \
1050 mono_class_get_##shortname##_class (void) \
1052 static MonoClass *tmp_class; \
1053 MonoClass *klass = tmp_class; \
1054 if (!klass) { \
1055 klass = mono_class_load_from_name (mono_defaults.corlib, name_space, name); \
1056 mono_memory_barrier (); /* FIXME excessive? */ \
1057 tmp_class = klass; \
1059 return klass; \
1062 // GENERATE_TRY_GET_CLASS_WITH_CACHE attempts mono_class_load_from_name approximately
1063 // only once. i.e. if it fails, it will return null and not retry.
1064 // In a race it might try a few times, but not indefinitely.
1066 // FIXME This maybe has excessive volatile/barriers.
1068 #define GENERATE_TRY_GET_CLASS_WITH_CACHE(shortname,name_space,name) \
1069 MonoClass* \
1070 mono_class_try_get_##shortname##_class (void) \
1072 static volatile MonoClass *tmp_class; \
1073 static volatile gboolean inited; \
1074 MonoClass *klass = (MonoClass *)tmp_class; \
1075 mono_memory_barrier (); \
1076 if (!inited) { \
1077 klass = mono_class_try_load_from_name (mono_defaults.corlib, name_space, name); \
1078 tmp_class = klass; \
1079 mono_memory_barrier (); \
1080 inited = TRUE; \
1082 return klass; \
1085 GENERATE_TRY_GET_CLASS_WITH_CACHE_DECL (safehandle)
1087 #ifndef DISABLE_COM
1089 GENERATE_GET_CLASS_WITH_CACHE_DECL (interop_proxy)
1090 GENERATE_GET_CLASS_WITH_CACHE_DECL (idispatch)
1091 GENERATE_GET_CLASS_WITH_CACHE_DECL (iunknown)
1092 GENERATE_GET_CLASS_WITH_CACHE_DECL (com_object)
1093 GENERATE_GET_CLASS_WITH_CACHE_DECL (variant)
1095 #endif
1097 GENERATE_GET_CLASS_WITH_CACHE_DECL (appdomain)
1098 GENERATE_GET_CLASS_WITH_CACHE_DECL (appdomain_setup)
1100 GENERATE_GET_CLASS_WITH_CACHE_DECL (appdomain_unloaded_exception)
1101 GENERATE_TRY_GET_CLASS_WITH_CACHE_DECL (appdomain_unloaded_exception)
1103 GENERATE_GET_CLASS_WITH_CACHE_DECL (valuetype)
1105 GENERATE_TRY_GET_CLASS_WITH_CACHE_DECL(handleref)
1107 #ifdef ENABLE_NETCORE
1108 GENERATE_GET_CLASS_WITH_CACHE_DECL (assembly_load_context)
1109 GENERATE_GET_CLASS_WITH_CACHE_DECL (native_library)
1110 #endif
1112 /* If you need a MonoType, use one of the mono_get_*_type () functions in class-inlines.h */
1113 extern MonoDefaults mono_defaults;
1115 void
1116 mono_loader_init (void);
1118 void
1119 mono_loader_cleanup (void);
1121 void
1122 mono_loader_lock (void);
1124 void
1125 mono_loader_unlock (void);
1127 void
1128 mono_loader_lock_track_ownership (gboolean track);
1130 gboolean
1131 mono_loader_lock_is_owned_by_self (void);
1133 void
1134 mono_loader_lock_if_inited (void);
1136 void
1137 mono_loader_unlock_if_inited (void);
1139 void
1140 mono_reflection_init (void);
1142 void
1143 mono_icall_init (void);
1145 void
1146 mono_icall_cleanup (void);
1148 gpointer
1149 mono_method_get_wrapper_data (MonoMethod *method, guint32 id);
1151 gboolean
1152 mono_metadata_has_generic_params (MonoImage *image, guint32 token);
1154 MONO_API MonoGenericContainer *
1155 mono_metadata_load_generic_params (MonoImage *image, guint32 token,
1156 MonoGenericContainer *parent_container,
1157 gpointer real_owner);
1159 MONO_API gboolean
1160 mono_metadata_load_generic_param_constraints_checked (MonoImage *image, guint32 token,
1161 MonoGenericContainer *container, MonoError *error);
1163 // This is the "real" function for registering JIT icalls. All others are one line wrappers that call it,
1164 // i.e. filling in info or c_symbol.
1165 void
1166 mono_register_jit_icall_info (MonoJitICallInfo *info, gconstpointer func, const char *name,
1167 MonoMethodSignature *sig, gboolean no_wrapper, const char *c_symbol);
1169 #ifdef __cplusplus
1170 template <typename T>
1171 inline void
1172 mono_register_jit_icall_info (MonoJitICallInfo *info, T func, const char *name, MonoMethodSignature *sig, gboolean no_wrapper, const char *c_symbol)
1174 mono_register_jit_icall_info (info, (gconstpointer)func, name, sig, no_wrapper, c_symbol);
1176 #endif // __cplusplus
1178 #define mono_register_jit_icall(func, sig, no_wrapper) (mono_register_jit_icall_info (&mono_get_jit_icall_info ()->func, func, #func, (sig), (no_wrapper), NULL))
1180 gboolean
1181 mono_class_set_type_load_failure (MonoClass *klass, const char * fmt, ...) MONO_ATTR_FORMAT_PRINTF(2,3);
1183 MonoException*
1184 mono_class_get_exception_for_failure (MonoClass *klass);
1186 char*
1187 mono_identifier_escape_type_name_chars (const char* identifier);
1189 char*
1190 mono_type_get_full_name (MonoClass *klass);
1192 char *
1193 mono_method_get_name_full (MonoMethod *method, gboolean signature, gboolean ret, MonoTypeNameFormat format);
1195 MONO_PROFILER_API char *
1196 mono_method_get_full_name (MonoMethod *method);
1198 const char*
1199 mono_wrapper_type_to_str (guint32 wrapper_type);
1201 MonoArrayType *mono_dup_array_type (MonoImage *image, MonoArrayType *a);
1202 MonoMethodSignature *mono_metadata_signature_deep_dup (MonoImage *image, MonoMethodSignature *sig);
1204 MONO_API void
1205 mono_image_init_name_cache (MonoImage *image);
1207 MonoClass*
1208 mono_class_get_nullable_param_internal (MonoClass *klass);
1210 /* object debugging functions, for use inside gdb */
1211 MONO_API void mono_object_describe (MonoObject *obj);
1212 MONO_API void mono_object_describe_fields (MonoObject *obj);
1213 MONO_API void mono_value_describe_fields (MonoClass* klass, const char* addr);
1214 MONO_API void mono_class_describe_statics (MonoClass* klass);
1216 /* method debugging functions, for use inside gdb */
1217 MONO_API void mono_method_print_code (MonoMethod *method);
1219 MONO_PROFILER_API char *mono_signature_full_name (MonoMethodSignature *sig);
1221 /*Enum validation related functions*/
1222 MONO_API gboolean
1223 mono_type_is_valid_enum_basetype (MonoType * type);
1225 MONO_API gboolean
1226 mono_class_is_valid_enum (MonoClass *klass);
1228 MONO_PROFILER_API gboolean
1229 mono_type_is_primitive (MonoType *type);
1231 MonoType *
1232 mono_type_get_checked (MonoImage *image, guint32 type_token, MonoGenericContext *context, MonoError *error);
1234 gboolean
1235 mono_generic_class_is_generic_type_definition (MonoGenericClass *gklass);
1237 MonoType*
1238 mono_type_get_basic_type_from_generic (MonoType *type);
1240 gboolean
1241 mono_method_can_access_method_full (MonoMethod *method, MonoMethod *called, MonoClass *context_klass);
1243 gboolean
1244 mono_method_can_access_field_full (MonoMethod *method, MonoClassField *field, MonoClass *context_klass);
1246 gboolean
1247 mono_class_can_access_class (MonoClass *access_class, MonoClass *target_class);
1249 MonoClass *
1250 mono_class_get_generic_type_definition (MonoClass *klass);
1252 gboolean
1253 mono_class_has_parent_and_ignore_generics (MonoClass *klass, MonoClass *parent);
1256 mono_method_get_vtable_slot (MonoMethod *method);
1259 mono_method_get_vtable_index (MonoMethod *method);
1261 MonoMethod*
1262 mono_method_get_base_method (MonoMethod *method, gboolean definition, MonoError *error);
1264 MonoMethod*
1265 mono_method_search_in_array_class (MonoClass *klass, const char *name, MonoMethodSignature *sig);
1267 void
1268 mono_class_setup_interface_id (MonoClass *klass);
1270 MonoGenericContainer*
1271 mono_class_get_generic_container (MonoClass *klass);
1273 gpointer
1274 mono_class_alloc (MonoClass *klass, int size);
1276 gpointer
1277 mono_class_alloc0 (MonoClass *klass, int size);
1279 #define mono_class_alloc0(klass, size) (g_cast (mono_class_alloc0 ((klass), (size))))
1281 void
1282 mono_class_setup_interfaces (MonoClass *klass, MonoError *error);
1284 MonoClassField*
1285 mono_class_get_field_from_name_full (MonoClass *klass, const char *name, MonoType *type);
1287 MonoVTable*
1288 mono_class_vtable_checked (MonoDomain *domain, MonoClass *klass, MonoError *error);
1290 void
1291 mono_class_is_assignable_from_checked (MonoClass *klass, MonoClass *oklass, gboolean *result, MonoError *error);
1293 void
1294 mono_class_signature_is_assignable_from (MonoClass *klass, MonoClass *oklass, gboolean *result, MonoError *error);
1296 gboolean
1297 mono_class_is_assignable_from_slow (MonoClass *target, MonoClass *candidate);
1299 gboolean
1300 mono_class_has_variant_generic_params (MonoClass *klass);
1302 gboolean
1303 mono_class_is_variant_compatible (MonoClass *klass, MonoClass *oklass, gboolean check_for_reference_conv);
1305 gboolean
1306 mono_class_is_subclass_of_internal (MonoClass *klass, MonoClass *klassc, gboolean check_interfaces);
1308 mono_bool
1309 mono_class_is_assignable_from_internal (MonoClass *klass, MonoClass *oklass);
1311 gboolean
1312 mono_byref_type_is_assignable_from (MonoType *type, MonoType *ctype, gboolean signature_assignment);
1314 gboolean mono_is_corlib_image (MonoImage *image);
1316 MonoType*
1317 mono_field_get_type_checked (MonoClassField *field, MonoError *error);
1319 MonoType*
1320 mono_field_get_type_internal (MonoClassField *field);
1322 MonoClassField*
1323 mono_class_get_fields_internal (MonoClass* klass, gpointer *iter);
1325 MonoClassField*
1326 mono_class_get_fields_lazy (MonoClass* klass, gpointer *iter);
1328 gboolean
1329 mono_class_check_vtable_constraints (MonoClass *klass, GList *in_setup);
1331 gboolean
1332 mono_class_has_finalizer (MonoClass *klass);
1334 void
1335 mono_unload_interface_id (MonoClass *klass);
1337 GPtrArray*
1338 mono_class_get_methods_by_name (MonoClass *klass, const char *name, guint32 bflags, guint32 mlisttype, gboolean allow_ctors, MonoError *error);
1340 char*
1341 mono_class_full_name (MonoClass *klass);
1343 MonoClass*
1344 mono_class_inflate_generic_class_checked (MonoClass *gklass, MonoGenericContext *context, MonoError *error);
1346 MONO_PROFILER_API MonoClass *
1347 mono_class_get_checked (MonoImage *image, guint32 type_token, MonoError *error);
1349 MonoClass *
1350 mono_class_get_and_inflate_typespec_checked (MonoImage *image, guint32 type_token, MonoGenericContext *context, MonoError *error);
1352 MonoClass *
1353 mono_class_from_name_checked (MonoImage *image, const char* name_space, const char *name, MonoError *error);
1355 MonoClass *
1356 mono_class_from_name_case_checked (MonoImage *image, const char* name_space, const char *name, MonoError *error);
1358 MONO_PROFILER_API MonoClass *
1359 mono_class_from_mono_type_internal (MonoType *type);
1361 MonoClassField*
1362 mono_field_from_token_checked (MonoImage *image, uint32_t token, MonoClass **retklass, MonoGenericContext *context, MonoError *error);
1364 gpointer
1365 mono_ldtoken_checked (MonoImage *image, guint32 token, MonoClass **handle_class, MonoGenericContext *context, MonoError *error);
1367 MonoImage *
1368 mono_get_image_for_generic_param (MonoGenericParam *param);
1370 char *
1371 mono_make_generic_name_string (MonoImage *image, int num);
1373 MonoClass *
1374 mono_class_load_from_name (MonoImage *image, const char* name_space, const char *name);
1376 MonoClass*
1377 mono_class_try_load_from_name (MonoImage *image, const char* name_space, const char *name);
1379 void
1380 mono_error_set_for_class_failure (MonoError *orerror, const MonoClass *klass);
1382 gboolean
1383 mono_class_has_failure (const MonoClass *klass);
1385 /* Kind specific accessors */
1386 MonoGenericClass*
1387 mono_class_get_generic_class (MonoClass *klass);
1389 MonoGenericClass*
1390 mono_class_try_get_generic_class (MonoClass *klass);
1392 void
1393 mono_class_set_flags (MonoClass *klass, guint32 flags);
1395 MonoGenericContainer*
1396 mono_class_try_get_generic_container (MonoClass *klass);
1398 void
1399 mono_class_set_generic_container (MonoClass *klass, MonoGenericContainer *container);
1401 MonoType*
1402 mono_class_gtd_get_canonical_inst (MonoClass *klass);
1404 guint32
1405 mono_class_get_first_method_idx (MonoClass *klass);
1407 void
1408 mono_class_set_first_method_idx (MonoClass *klass, guint32 idx);
1410 guint32
1411 mono_class_get_first_field_idx (MonoClass *klass);
1413 void
1414 mono_class_set_first_field_idx (MonoClass *klass, guint32 idx);
1416 guint32
1417 mono_class_get_method_count (MonoClass *klass);
1419 void
1420 mono_class_set_method_count (MonoClass *klass, guint32 count);
1422 guint32
1423 mono_class_get_field_count (MonoClass *klass);
1425 void
1426 mono_class_set_field_count (MonoClass *klass, guint32 count);
1428 MonoMarshalType*
1429 mono_class_get_marshal_info (MonoClass *klass);
1431 void
1432 mono_class_set_marshal_info (MonoClass *klass, MonoMarshalType *marshal_info);
1434 MonoGCHandle
1435 mono_class_get_ref_info_handle (MonoClass *klass);
1437 MonoGCHandle
1438 mono_class_set_ref_info_handle (MonoClass *klass, gpointer value);
1440 MonoErrorBoxed*
1441 mono_class_get_exception_data (MonoClass *klass);
1443 void
1444 mono_class_set_exception_data (MonoClass *klass, MonoErrorBoxed *value);
1446 GList*
1447 mono_class_get_nested_classes_property (MonoClass *klass);
1449 void
1450 mono_class_set_nested_classes_property (MonoClass *klass, GList *value);
1452 MonoClassPropertyInfo*
1453 mono_class_get_property_info (MonoClass *klass);
1455 void
1456 mono_class_set_property_info (MonoClass *klass, MonoClassPropertyInfo *info);
1458 MonoClassEventInfo*
1459 mono_class_get_event_info (MonoClass *klass);
1461 void
1462 mono_class_set_event_info (MonoClass *klass, MonoClassEventInfo *info);
1464 MonoFieldDefaultValue*
1465 mono_class_get_field_def_values (MonoClass *klass);
1467 void
1468 mono_class_set_field_def_values (MonoClass *klass, MonoFieldDefaultValue *values);
1470 guint32
1471 mono_class_get_declsec_flags (MonoClass *klass);
1473 void
1474 mono_class_set_declsec_flags (MonoClass *klass, guint32 value);
1476 void
1477 mono_class_set_is_com_object (MonoClass *klass);
1479 void
1480 mono_class_set_weak_bitmap (MonoClass *klass, int nbits, gsize *bits);
1482 gsize*
1483 mono_class_get_weak_bitmap (MonoClass *klass, int *nbits);
1485 gboolean
1486 mono_class_has_dim_conflicts (MonoClass *klass);
1488 void
1489 mono_class_set_dim_conflicts (MonoClass *klass, GSList *conflicts);
1491 GSList*
1492 mono_class_get_dim_conflicts (MonoClass *klass);
1494 MonoMethod *
1495 mono_class_get_method_from_name_checked (MonoClass *klass, const char *name, int param_count, int flags, MonoError *error);
1497 gboolean
1498 mono_method_has_no_body (MonoMethod *method);
1500 // FIXME Replace all internal callers of mono_method_get_header_checked with
1501 // mono_method_get_header_internal; the difference is in error initialization.
1503 // And then mark mono_method_get_header_checked as MONO_RT_EXTERNAL_ONLY MONO_API.
1505 // Internal callers expected to use ERROR_DECL. External callers are not.
1506 MonoMethodHeader*
1507 mono_method_get_header_internal (MonoMethod *method, MonoError *error);
1509 MonoType*
1510 mono_class_find_enum_basetype (MonoClass *klass, MonoError *error);
1512 gboolean
1513 mono_class_set_failure (MonoClass *klass, MonoErrorBoxed *boxed_error);
1515 gboolean
1516 mono_class_set_type_load_failure_causedby_class (MonoClass *klass, const MonoClass *caused_by, const gchar* msg);
1518 gboolean mono_class_get_cached_class_info (MonoClass *klass, MonoCachedClassInfo *res);
1520 MonoMethod* mono_find_method_in_metadata (MonoClass *klass, const char *name, int param_count, int flags);
1523 mono_class_get_object_finalize_slot (void);
1525 MonoMethod *
1526 mono_class_get_default_finalize_method (void);
1528 void
1529 mono_field_resolve_type (MonoClassField *field, MonoError *error);
1531 gboolean
1532 mono_type_has_exceptions (MonoType *type);
1534 void
1535 mono_class_set_nonblittable (MonoClass *klass);
1537 gboolean
1538 mono_class_publish_gc_descriptor (MonoClass *klass, MonoGCDescriptor gc_descr);
1540 void
1541 mono_class_compute_gc_descriptor (MonoClass *klass);
1543 #ifndef DISABLE_REMOTING
1544 void
1545 mono_class_contextbound_bit_offset (int* byte_offset_out, guint8* mask_out);
1546 #endif
1548 gboolean
1549 mono_class_init_checked (MonoClass *klass, MonoError *error);
1551 MonoType*
1552 mono_class_enum_basetype_internal (MonoClass *klass);
1554 gboolean
1555 mono_method_is_constructor (MonoMethod *method);
1557 gboolean
1558 mono_class_has_default_constructor (MonoClass *klass, gboolean public_only);
1560 gboolean
1561 mono_method_has_unmanaged_callers_only_attribute (MonoMethod *method);
1563 // There are many ways to do on-demand initialization.
1564 // Some allow multiple concurrent initializations. Some do not.
1565 // Some allow multiple concurrent writes to the global. Some do not.
1567 // Booleans or names capturing these factors would be desirable.
1568 // RacyInit?
1570 // This form allows both such races, on the understanding that,
1571 // even if the initialization occurs multiple times, every result is equivalent,
1572 // and the goal is not to initialize no more than once, but for the steady state
1573 // to stop rerunning the initialization.
1575 // It may be desirable to replace this with mono_lazy_initialize, etc.
1577 // These macros cannot be wrapped in do/while as they inject "name" into invoking scope.
1579 #define MONO_STATIC_POINTER_INIT(type, name) \
1580 static type *static_ ## name; \
1581 type *name; \
1582 name = static_ ## name; \
1583 if (!name) { \
1584 /* Custom code here to initialize name */
1585 #define MONO_STATIC_POINTER_INIT_END(type, name) \
1586 if (name) { \
1587 /* Success, commit to static. */ \
1588 mono_atomic_store_seq (&static_ ## name, name); \
1592 static inline gboolean
1593 m_field_get_offset (MonoClassField *field)
1595 g_assert (m_class_is_fields_inited (field->parent));
1596 return field->offset;
1600 * Memory allocation for classes/methods
1602 * These should be used to allocate memory whose lifetime is equal to
1603 * the lifetime of the domain+class/method pair.
1606 static inline MonoMemoryManager*
1607 m_class_get_mem_manager (MonoDomain *domain, MonoClass *klass)
1609 #ifdef ENABLE_NETCORE
1610 // FIXME:
1611 return mono_domain_memory_manager (domain);
1612 #else
1613 return mono_domain_memory_manager (domain);
1614 #endif
1617 static inline void *
1618 m_class_alloc (MonoDomain *domain, MonoClass *klass, guint size)
1620 return mono_mem_manager_alloc (m_class_get_mem_manager (domain, klass), size);
1623 static inline void *
1624 m_class_alloc0 (MonoDomain *domain, MonoClass *klass, guint size)
1626 return mono_mem_manager_alloc0 (m_class_get_mem_manager (domain, klass), size);
1629 static inline MonoMemoryManager*
1630 m_method_get_mem_manager (MonoDomain *domain, MonoMethod *method)
1632 #ifdef ENABLE_NETCORE
1633 // FIXME:
1634 return mono_domain_memory_manager (domain);
1635 #else
1636 return mono_domain_memory_manager (domain);
1637 #endif
1640 static inline void *
1641 m_method_alloc (MonoDomain *domain, MonoMethod *method, guint size)
1643 return mono_mem_manager_alloc (m_method_get_mem_manager (domain, method), size);
1646 static inline void *
1647 m_method_alloc0 (MonoDomain *domain, MonoMethod *method, guint size)
1649 return mono_mem_manager_alloc0 (m_method_get_mem_manager (domain, method), size);
1652 // Enum and static storage for JIT icalls.
1653 #include "jit-icall-reg.h"
1655 /*Now that everything has been defined, let's include the inline functions */
1656 #include <mono/metadata/class-inlines.h>
1658 #endif /* __MONO_METADATA_CLASS_INTERNALS_H__ */