remove GenericVectorTests from rsp (#17366)
[mono-project.git] / mono / metadata / metadata-internals.h
blob15f66bf33e776f5a62e3cf2ec4a2da3ca4e5db5a
1 /**
2 * \file
3 */
5 #ifndef __MONO_METADATA_INTERNALS_H__
6 #define __MONO_METADATA_INTERNALS_H__
8 #include "mono/utils/mono-forward-internal.h"
9 #include "mono/metadata/image.h"
10 #include "mono/metadata/blob.h"
11 #include "mono/metadata/cil-coff.h"
12 #include "mono/metadata/mempool.h"
13 #include "mono/metadata/domain-internals.h"
14 #include "mono/metadata/mono-hash.h"
15 #include "mono/utils/mono-compiler.h"
16 #include "mono/utils/mono-dl.h"
17 #include "mono/utils/monobitset.h"
18 #include "mono/utils/mono-property-hash.h"
19 #include "mono/utils/mono-value-hash.h"
20 #include <mono/utils/mono-error.h>
21 #include "mono/utils/mono-conc-hashtable.h"
22 #include "mono/utils/refcount.h"
24 struct _MonoType {
25 union {
26 MonoClass *klass; /* for VALUETYPE and CLASS */
27 MonoType *type; /* for PTR */
28 MonoArrayType *array; /* for ARRAY */
29 MonoMethodSignature *method;
30 MonoGenericParam *generic_param; /* for VAR and MVAR */
31 MonoGenericClass *generic_class; /* for GENERICINST */
32 } data;
33 unsigned int attrs : 16; /* param attributes or field flags */
34 MonoTypeEnum type : 8;
35 unsigned int has_cmods : 1;
36 unsigned int byref : 1;
37 unsigned int pinned : 1; /* valid when included in a local var signature */
40 typedef struct {
41 unsigned int required : 1;
42 MonoType *type;
43 } MonoSingleCustomMod;
45 /* Aggregate custom modifiers can happen if a generic VAR or MVAR is inflated,
46 * and both the VAR and the type that will be used to inflated it have custom
47 * modifiers, but they come from different images. (e.g. inflating 'class G<T>
48 * {void Test (T modopt(IsConst) t);}' with 'int32 modopt(IsLong)' where G is
49 * in image1 and the int32 is in image2.)
51 * Moreover, we can't just store an image and a type token per modifier, because
52 * Roslyn and C++/CLI sometimes create modifiers that mention generic parameters that must be inflated, like:
53 * void .CL1`1.Test(!0 modopt(System.Nullable`1<!0>))
54 * So we have to store a resolved MonoType*.
56 * Because the types come from different images, we allocate the aggregate
57 * custom modifiers container object in the mempool of a MonoImageSet to ensure
58 * that it doesn't have dangling image pointers.
60 typedef struct {
61 uint8_t count;
62 MonoSingleCustomMod modifiers[1]; /* Actual length is count */
63 } MonoAggregateModContainer;
65 /* ECMA says upto 64 custom modifiers. It's possible we could see more at
66 * runtime due to modifiers being appended together when we inflate type. In
67 * that case we should revisit the places where this define is used to make
68 * sure that we don't blow up the stack (or switch to heap allocation for
69 * temporaries).
71 #define MONO_MAX_EXPECTED_CMODS 64
73 typedef struct {
74 MonoType unmodified;
75 gboolean is_aggregate;
76 union {
77 MonoCustomModContainer cmods;
78 /* the actual aggregate modifiers are in a MonoImageSet mempool
79 * that includes all the images of all the modifier types and
80 * also the type that this aggregate container is a part of.*/
81 MonoAggregateModContainer *amods;
82 } mods;
83 } MonoTypeWithModifiers;
85 gboolean
86 mono_type_is_aggregate_mods (const MonoType *t);
88 static inline void
89 mono_type_with_mods_init (MonoType *dest, uint8_t num_mods, gboolean is_aggregate)
91 if (num_mods == 0) {
92 dest->has_cmods = 0;
93 return;
95 dest->has_cmods = 1;
96 MonoTypeWithModifiers *dest_full = (MonoTypeWithModifiers *)dest;
97 dest_full->is_aggregate = !!is_aggregate;
98 if (is_aggregate)
99 dest_full->mods.amods = NULL;
100 else
101 dest_full->mods.cmods.count = num_mods;
104 MonoCustomModContainer *
105 mono_type_get_cmods (const MonoType *t);
107 MonoAggregateModContainer *
108 mono_type_get_amods (const MonoType *t);
110 void
111 mono_type_set_amods (MonoType *t, MonoAggregateModContainer *amods);
113 static inline uint8_t
114 mono_type_custom_modifier_count (const MonoType *t)
116 if (!t->has_cmods)
117 return 0;
118 MonoTypeWithModifiers *full = (MonoTypeWithModifiers *)t;
119 if (full->is_aggregate)
120 return full->mods.amods->count;
121 else
122 return full->mods.cmods.count;
125 MonoType *
126 mono_type_get_custom_modifier (const MonoType *ty, uint8_t idx, gboolean *required, MonoError *error);
128 // Note: sizeof (MonoType) is dangerous. It can copy the num_mods
129 // field without copying the variably sized array. This leads to
130 // memory unsafety on the stack and/or heap, when we try to traverse
131 // this array.
133 // Use mono_sizeof_monotype
134 // to get the size of the memory to copy.
135 #define MONO_SIZEOF_TYPE sizeof (MonoType)
137 size_t
138 mono_sizeof_type_with_mods (uint8_t num_mods, gboolean aggregate);
140 size_t
141 mono_sizeof_type (const MonoType *ty);
143 size_t
144 mono_sizeof_aggregate_modifiers (uint8_t num_mods);
146 MonoAggregateModContainer *
147 mono_metadata_get_canonical_aggregate_modifiers (MonoAggregateModContainer *candidate);
149 #define MONO_SECMAN_FLAG_INIT(x) (x & 0x2)
150 #define MONO_SECMAN_FLAG_GET_VALUE(x) (x & 0x1)
151 #define MONO_SECMAN_FLAG_SET_VALUE(x,y) do { x = ((y) ? 0x3 : 0x2); } while (0)
153 #define MONO_PUBLIC_KEY_TOKEN_LENGTH 17
155 #define MONO_PROCESSOR_ARCHITECTURE_NONE 0
156 #define MONO_PROCESSOR_ARCHITECTURE_MSIL 1
157 #define MONO_PROCESSOR_ARCHITECTURE_X86 2
158 #define MONO_PROCESSOR_ARCHITECTURE_IA64 3
159 #define MONO_PROCESSOR_ARCHITECTURE_AMD64 4
160 #define MONO_PROCESSOR_ARCHITECTURE_ARM 5
162 struct _MonoAssemblyName {
163 const char *name;
164 const char *culture;
165 const char *hash_value;
166 const mono_byte* public_key;
167 // string of 16 hex chars + 1 NULL
168 mono_byte public_key_token [MONO_PUBLIC_KEY_TOKEN_LENGTH];
169 uint32_t hash_alg;
170 uint32_t hash_len;
171 uint32_t flags;
172 #ifdef ENABLE_NETCORE
173 int major, minor, build, revision, arch;
174 #else
175 uint16_t major, minor, build, revision, arch;
176 #endif
179 struct MonoTypeNameParse {
180 char *name_space;
181 char *name;
182 MonoAssemblyName assembly;
183 GList *modifiers; /* 0 -> byref, -1 -> pointer, > 0 -> array rank */
184 GPtrArray *type_arguments;
185 GList *nested;
189 typedef enum MonoAssemblyContextKind {
190 /* Default assembly context: Load(String) and assembly references */
191 MONO_ASMCTX_DEFAULT = 0,
192 /* Reflection-only only context: ReflectionOnlyLoad and ReeflectionOnlyLoadFrom */
193 MONO_ASMCTX_REFONLY = 1,
194 /* LoadFrom context: LoadFrom() and references */
195 MONO_ASMCTX_LOADFROM = 2,
196 /* Individual assembly context (.NET Framework docs call this "not in
197 * any context"): LoadFile(String) and Load(byte[]) are here.
199 MONO_ASMCTX_INDIVIDUAL = 3,
201 MONO_ASMCTX_LAST = 3
202 } MonoAssemblyContextKind;
204 typedef struct _MonoAssemblyContext {
205 MonoAssemblyContextKind kind;
206 } MonoAssemblyContext;
208 struct _MonoAssembly {
210 * The number of appdomains which have this assembly loaded plus the number of
211 * assemblies referencing this assembly through an entry in their image->references
212 * arrays. The latter is needed because entries in the image->references array
213 * might point to assemblies which are only loaded in some appdomains, and without
214 * the additional reference, they can be freed at any time.
215 * The ref_count is initially 0.
217 int ref_count; /* use atomic operations only */
218 char *basedir;
219 MonoAssemblyName aname;
220 MonoImage *image;
221 GSList *friend_assembly_names; /* Computed by mono_assembly_load_friends () */
222 guint8 friend_assembly_names_inited;
223 guint8 in_gac;
224 guint8 dynamic;
225 guint8 corlib_internal;
226 MonoAssemblyContext context;
227 guint8 wrap_non_exception_throws;
228 guint8 wrap_non_exception_throws_inited;
229 guint8 jit_optimizer_disabled;
230 guint8 jit_optimizer_disabled_inited;
231 /* security manager flags (one bit is for lazy initialization) */
232 guint32 ecma:2; /* Has the ECMA key */
233 guint32 aptc:2; /* Has the [AllowPartiallyTrustedCallers] attributes */
234 guint32 fulltrust:2; /* Has FullTrust permission */
235 guint32 unmanaged:2; /* Has SecurityPermissionFlag.UnmanagedCode permission */
236 guint32 skipverification:2; /* Has SecurityPermissionFlag.SkipVerification permission */
239 typedef struct {
241 * indexed by MonoMethodSignature
242 * Protected by the marshal lock
244 GHashTable *delegate_invoke_cache;
245 GHashTable *delegate_begin_invoke_cache;
246 GHashTable *delegate_end_invoke_cache;
247 GHashTable *runtime_invoke_signature_cache;
248 GHashTable *runtime_invoke_sig_cache;
251 * indexed by SignaturePointerPair
253 GHashTable *delegate_abstract_invoke_cache;
256 * indexed by MonoMethod pointers
257 * Protected by the marshal lock
259 GHashTable *runtime_invoke_method_cache;
260 GHashTable *managed_wrapper_cache;
262 GHashTable *native_wrapper_cache;
263 GHashTable *native_wrapper_aot_cache;
264 GHashTable *native_wrapper_check_cache;
265 GHashTable *native_wrapper_aot_check_cache;
267 GHashTable *native_func_wrapper_aot_cache;
268 GHashTable *remoting_invoke_cache;
269 GHashTable *synchronized_cache;
270 GHashTable *unbox_wrapper_cache;
271 GHashTable *cominterop_invoke_cache;
272 GHashTable *cominterop_wrapper_cache; /* LOCKING: marshal lock */
273 GHashTable *thunk_invoke_cache;
274 } MonoWrapperCaches;
276 typedef struct {
277 const char* data;
278 guint32 size;
279 } MonoStreamHeader;
281 struct _MonoTableInfo {
282 const char *base;
283 guint rows : 24;
284 guint row_size : 8;
287 * Tables contain up to 9 columns and the possible sizes of the
288 * fields in the documentation are 1, 2 and 4 bytes. So we
289 * can encode in 2 bits the size.
291 * A 32 bit value can encode the resulting size
293 * The top eight bits encode the number of columns in the table.
294 * we only need 4, but 8 is aligned no shift required.
296 guint32 size_bitfield;
299 #define REFERENCE_MISSING ((gpointer) -1)
301 typedef struct {
302 gboolean (*match) (MonoImage*);
303 gboolean (*load_pe_data) (MonoImage*);
304 gboolean (*load_cli_data) (MonoImage*);
305 gboolean (*load_tables) (MonoImage*);
306 } MonoImageLoader;
308 /* Represents the physical bytes for an image (usually in the file system, but
309 * could be in memory).
311 * The MonoImageStorage owns the raw data for an image and is responsible for
312 * cleanup.
314 * May be shared by multiple MonoImage objects if they opened the same
315 * underlying file or byte blob in memory.
317 * There is an abstract string key (usually a file path, but could be formed in
318 * other ways) that is used to share MonoImageStorage objects among images.
321 typedef struct {
322 MonoRefCount ref;
324 /* key used for lookups. owned by this image storage. */
325 char *key;
327 /* If the raw data was allocated from a source such as mmap, the allocator may store resource tracking information here. */
328 void *raw_data_handle;
329 char *raw_data;
330 guint32 raw_data_len;
331 /* data was allocated with mono_file_map and must be unmapped */
332 guint8 raw_buffer_used : 1;
333 /* data was allocated with malloc and must be freed */
334 guint8 raw_data_allocated : 1;
335 /* data was allocated with mono_file_map_fileio */
336 guint8 fileio_used : 1;
338 #ifdef HOST_WIN32
339 /* Module was loaded using LoadLibrary. */
340 guint8 is_module_handle : 1;
342 /* Module entry point is _CorDllMain. */
343 guint8 has_entry_point : 1;
344 #endif
345 } MonoImageStorage;
347 struct _MonoImage {
349 * This count is incremented during these situations:
350 * - An assembly references this MonoImage through its 'image' field
351 * - This MonoImage is present in the 'files' field of an image
352 * - This MonoImage is present in the 'modules' field of an image
353 * - A thread is holding a temporary reference to this MonoImage between
354 * calls to mono_image_open and mono_image_close ()
356 int ref_count;
358 MonoImageStorage *storage;
360 /* Aliases storage->raw_data when storage is non-NULL. Otherwise NULL. */
361 char *raw_data;
362 guint32 raw_data_len;
364 /* Whenever this is a dynamically emitted module */
365 guint8 dynamic : 1;
367 /* Whenever this is a reflection only image */
368 guint8 ref_only : 1;
370 /* Whenever this image contains uncompressed metadata */
371 guint8 uncompressed_metadata : 1;
373 /* Whenever this image contains metadata only without PE data */
374 guint8 metadata_only : 1;
376 /* Whether this image belongs to load-from context */
377 guint8 load_from_context: 1;
379 guint8 checked_module_cctor : 1;
380 guint8 has_module_cctor : 1;
382 guint8 idx_string_wide : 1;
383 guint8 idx_guid_wide : 1;
384 guint8 idx_blob_wide : 1;
386 /* Whenever this image is considered as platform code for the CoreCLR security model */
387 guint8 core_clr_platform_code : 1;
389 /* The path to the file for this image or an arbitrary name for images loaded from data. */
390 char *name;
392 /* The path to the file for this image or NULL */
393 char *filename;
395 /* The assembly name reported in the file for this image (expected to be NULL for a netmodule) */
396 const char *assembly_name;
398 /* The module name reported in the file for this image (could be NULL for a malformed file) */
399 const char *module_name;
400 guint32 time_date_stamp;
402 char *version;
403 gint16 md_version_major, md_version_minor;
404 char *guid;
405 MonoCLIImageInfo *image_info;
406 MonoMemPool *mempool; /*protected by the image lock*/
408 char *raw_metadata;
410 MonoStreamHeader heap_strings;
411 MonoStreamHeader heap_us;
412 MonoStreamHeader heap_blob;
413 MonoStreamHeader heap_guid;
414 MonoStreamHeader heap_tables;
415 MonoStreamHeader heap_pdb;
417 const char *tables_base;
419 /* For PPDB files */
420 guint64 referenced_tables;
421 int *referenced_table_rows;
423 /**/
424 MonoTableInfo tables [MONO_TABLE_NUM];
427 * references is initialized only by using the mono_assembly_open
428 * function, and not by using the lowlevel mono_image_open.
430 * It is NULL terminated.
432 MonoAssembly **references;
433 int nreferences;
435 /* Code files in the assembly. The main assembly has a "file" table and also a "module"
436 * table, where the module table is a subset of the file table. We track both lists,
437 * and because we can lazy-load them at different times we reference-increment both.
439 /* No netmodules in netcore, but for System.Reflection.Emit support we still use modules */
440 MonoImage **modules;
441 guint32 module_count;
442 gboolean *modules_loaded;
444 MonoImage **files;
445 guint32 file_count;
447 MonoAotModule *aot_module;
449 guint8 aotid[16];
452 * The Assembly this image was loaded from.
454 MonoAssembly *assembly;
456 #ifdef ENABLE_NETCORE
458 * The AssemblyLoadContext that this image was loaded into.
460 MonoAssemblyLoadContext *alc;
461 #endif
464 * Indexed by method tokens and typedef tokens.
466 GHashTable *method_cache; /*protected by the image lock*/
467 MonoInternalHashTable class_cache;
469 /* Indexed by memberref + methodspec tokens */
470 GHashTable *methodref_cache; /*protected by the image lock*/
473 * Indexed by fielddef and memberref tokens
475 MonoConcurrentHashTable *field_cache; /*protected by the image lock*/
477 /* indexed by typespec tokens. */
478 MonoConcurrentHashTable *typespec_cache; /* protected by the image lock */
479 /* indexed by token */
480 GHashTable *memberref_signatures;
482 /* Indexed by blob heap indexes */
483 GHashTable *method_signatures;
486 * Indexes namespaces to hash tables that map class name to typedef token.
488 GHashTable *name_cache; /*protected by the image lock*/
491 * Indexed by MonoClass
493 GHashTable *array_cache;
494 GHashTable *ptr_cache;
496 GHashTable *szarray_cache;
497 /* This has a separate lock to improve scalability */
498 mono_mutex_t szarray_cache_lock;
501 * indexed by SignaturePointerPair
503 GHashTable *delegate_bound_static_invoke_cache;
504 GHashTable *native_func_wrapper_cache;
507 * indexed by MonoMethod pointers
509 GHashTable *wrapper_param_names;
510 GHashTable *array_accessor_cache;
513 * indexed by MonoClass pointers
515 GHashTable *ldfld_wrapper_cache;
516 GHashTable *ldflda_wrapper_cache;
517 GHashTable *stfld_wrapper_cache;
518 GHashTable *isinst_cache;
520 GHashTable *icall_wrapper_cache;
521 GHashTable *castclass_cache;
522 GHashTable *proxy_isinst_cache;
523 GHashTable *rgctx_template_hash; /* LOCKING: templates lock */
525 /* Contains rarely used fields of runtime structures belonging to this image */
526 MonoPropertyHash *property_hash;
528 void *reflection_info;
531 * user_info is a public field and is not touched by the
532 * metadata engine
534 void *user_info;
536 #ifndef DISABLE_DLLMAP
537 /* dll map entries */
538 MonoDllMap *dll_map;
539 #endif
541 /* interfaces IDs from this image */
542 /* protected by the classes lock */
543 MonoBitSet *interface_bitset;
545 /* when the image is being closed, this is abused as a list of
546 malloc'ed regions to be freed. */
547 GSList *reflection_info_unregister_classes;
549 /* List of dependent image sets containing this image */
550 /* Protected by image_sets_lock */
551 GSList *image_sets;
553 /* Caches for wrappers that DO NOT reference generic */
554 /* arguments */
555 MonoWrapperCaches wrapper_caches;
557 /* Pre-allocated anon generic params for the first N generic
558 * parameters, for a small N */
559 MonoGenericParam *var_gparam_cache_fast;
560 MonoGenericParam *mvar_gparam_cache_fast;
561 /* Anon generic parameters past N, if needed */
562 MonoConcurrentHashTable *var_gparam_cache;
563 MonoConcurrentHashTable *mvar_gparam_cache;
565 /* Maps malloc-ed char* pinvoke scope -> MonoDl* */
566 GHashTable *pinvoke_scopes;
568 /* Maps malloc-ed char* pinvoke scope -> malloced-ed char* filename */
569 GHashTable *pinvoke_scope_filenames;
571 /* Indexed by MonoGenericParam pointers */
572 GHashTable **gshared_types;
573 /* The length of the above array */
574 int gshared_types_len;
576 /* The loader used to load this image */
577 MonoImageLoader *loader;
579 // Containers for MonoGenericParams associated with this image but not with any specific class or method. Created on demand.
580 // This could happen, for example, for MonoTypes associated with TypeSpec table entries.
581 MonoGenericContainer *anonymous_generic_class_container;
582 MonoGenericContainer *anonymous_generic_method_container;
584 gboolean weak_fields_inited;
585 /* Contains 1 based indexes */
586 GHashTable *weak_field_indexes;
589 * No other runtime locks must be taken while holding this lock.
590 * It's meant to be used only to mutate and query structures part of this image.
592 mono_mutex_t lock;
596 * Generic instances and aggregated custom modifiers depend on many images, and they need to be deleted if one
597 * of the images they depend on is unloaded. For example,
598 * List<Foo> depends on both List's image and Foo's image.
599 * A MonoImageSet is the owner of all generic instances depending on the same set of
600 * images.
602 typedef struct {
603 int nimages;
604 MonoImage **images;
606 // Generic-specific caches
607 GHashTable *ginst_cache, *gmethod_cache, *gsignature_cache;
608 MonoConcurrentHashTable *gclass_cache;
610 /* mirror caches of ones already on MonoImage. These ones contain generics */
611 GHashTable *szarray_cache, *array_cache, *ptr_cache;
613 MonoWrapperCaches wrapper_caches;
615 GHashTable *aggregate_modifiers_cache;
617 mono_mutex_t lock;
620 * Memory for generic instances owned by this image set should be allocated from
621 * this mempool, using the mono_image_set_alloc family of functions.
623 MonoMemPool *mempool;
624 } MonoImageSet;
626 enum {
627 MONO_SECTION_TEXT,
628 MONO_SECTION_RSRC,
629 MONO_SECTION_RELOC,
630 MONO_SECTION_MAX
633 typedef struct {
634 GHashTable *hash;
635 char *data;
636 guint32 alloc_size; /* malloced bytes */
637 guint32 index;
638 guint32 offset; /* from start of metadata */
639 } MonoDynamicStream;
641 typedef struct {
642 guint32 alloc_rows;
643 guint32 rows;
644 guint8 row_size; /* calculated later with column_sizes */
645 guint8 columns;
646 guint32 next_idx;
647 guint32 *values; /* rows * columns */
648 } MonoDynamicTable;
650 /* "Dynamic" assemblies and images arise from System.Reflection.Emit */
651 struct _MonoDynamicAssembly {
652 MonoAssembly assembly;
653 char *strong_name;
654 guint32 strong_name_size;
655 guint8 run;
656 guint8 save;
657 MonoDomain *domain;
660 struct _MonoDynamicImage {
661 MonoImage image;
662 guint32 meta_size;
663 guint32 text_rva;
664 guint32 metadata_rva;
665 guint32 image_base;
666 guint32 cli_header_offset;
667 guint32 iat_offset;
668 guint32 idt_offset;
669 guint32 ilt_offset;
670 guint32 imp_names_offset;
671 struct {
672 guint32 rva;
673 guint32 size;
674 guint32 offset;
675 guint32 attrs;
676 } sections [MONO_SECTION_MAX];
677 GHashTable *typespec;
678 GHashTable *typeref;
679 GHashTable *handleref;
680 MonoGHashTable *tokens;
681 GHashTable *blob_cache;
682 GHashTable *standalonesig_cache;
683 GList *array_methods;
684 GPtrArray *gen_params;
685 MonoGHashTable *token_fixups;
686 GHashTable *method_to_table_idx;
687 GHashTable *field_to_table_idx;
688 GHashTable *method_aux_hash;
689 GHashTable *vararg_aux_hash;
690 MonoGHashTable *generic_def_objects;
692 * Maps final token values to the object they describe.
694 MonoGHashTable *remapped_tokens;
695 gboolean run;
696 gboolean save;
697 gboolean initial_image;
698 guint32 pe_kind, machine;
699 char *strong_name;
700 guint32 strong_name_size;
701 char *win32_res;
702 guint32 win32_res_size;
703 guint8 *public_key;
704 int public_key_len;
705 MonoDynamicStream sheap;
706 MonoDynamicStream code; /* used to store method headers and bytecode */
707 MonoDynamicStream resources; /* managed embedded resources */
708 MonoDynamicStream us;
709 MonoDynamicStream blob;
710 MonoDynamicStream tstream;
711 MonoDynamicStream guid;
712 MonoDynamicTable tables [MONO_TABLE_NUM];
713 MonoClass *wrappers_type; /*wrappers are bound to this type instead of <Module>*/
716 /* Contains information about assembly binding */
717 typedef struct _MonoAssemblyBindingInfo {
718 char *name;
719 char *culture;
720 guchar public_key_token [MONO_PUBLIC_KEY_TOKEN_LENGTH];
721 int major;
722 int minor;
723 AssemblyVersionSet old_version_bottom;
724 AssemblyVersionSet old_version_top;
725 AssemblyVersionSet new_version;
726 guint has_old_version_bottom : 1;
727 guint has_old_version_top : 1;
728 guint has_new_version : 1;
729 guint is_valid : 1;
730 gint32 domain_id; /*Needed to unload per-domain binding*/
731 } MonoAssemblyBindingInfo;
733 struct _MonoMethodHeader {
734 const unsigned char *code;
735 #ifdef MONO_SMALL_CONFIG
736 guint16 code_size;
737 #else
738 guint32 code_size;
739 #endif
740 guint16 max_stack : 15;
741 unsigned int is_transient: 1; /* mono_metadata_free_mh () will actually free this header */
742 unsigned int num_clauses : 15;
743 /* if num_locals != 0, then the following apply: */
744 unsigned int init_locals : 1;
745 guint16 num_locals;
746 MonoExceptionClause *clauses;
747 MonoBitSet *volatile_args;
748 MonoBitSet *volatile_locals;
749 MonoType *locals [MONO_ZERO_LEN_ARRAY];
752 typedef struct {
753 const unsigned char *code;
754 guint32 code_size;
755 guint16 max_stack;
756 gboolean has_clauses;
757 gboolean has_locals;
758 } MonoMethodHeaderSummary;
760 // FIXME? offsetof (MonoMethodHeader, locals)?
761 #define MONO_SIZEOF_METHOD_HEADER (sizeof (struct _MonoMethodHeader) - MONO_ZERO_LEN_ARRAY * SIZEOF_VOID_P)
763 struct _MonoMethodSignature {
764 MonoType *ret;
765 #ifdef MONO_SMALL_CONFIG
766 guint8 param_count;
767 gint8 sentinelpos;
768 unsigned int generic_param_count : 5;
769 #else
770 guint16 param_count;
771 gint16 sentinelpos;
772 unsigned int generic_param_count : 16;
773 #endif
774 unsigned int call_convention : 6;
775 unsigned int hasthis : 1;
776 unsigned int explicit_this : 1;
777 unsigned int pinvoke : 1;
778 unsigned int is_inflated : 1;
779 unsigned int has_type_parameters : 1;
780 MonoType *params [MONO_ZERO_LEN_ARRAY];
784 * AOT cache configuration loaded from config files.
785 * Doesn't really belong here.
787 typedef struct {
789 * Enable aot caching for applications whose main assemblies are in
790 * this list.
792 GSList *apps;
793 GSList *assemblies;
794 char *aot_options;
795 } MonoAotCacheConfig;
797 #define MONO_SIZEOF_METHOD_SIGNATURE (sizeof (struct _MonoMethodSignature) - MONO_ZERO_LEN_ARRAY * SIZEOF_VOID_P)
799 static inline gboolean
800 image_is_dynamic (MonoImage *image)
802 #ifdef DISABLE_REFLECTION_EMIT
803 return FALSE;
804 #else
805 return image->dynamic;
806 #endif
809 static inline gboolean
810 assembly_is_dynamic (MonoAssembly *assembly)
812 #ifdef DISABLE_REFLECTION_EMIT
813 return FALSE;
814 #else
815 return assembly->dynamic;
816 #endif
819 /* for use with allocated memory blocks (assumes alignment is to 8 bytes) */
820 guint mono_aligned_addr_hash (gconstpointer ptr);
822 void
823 mono_image_check_for_module_cctor (MonoImage *image);
825 gpointer
826 mono_image_alloc (MonoImage *image, guint size);
828 gpointer
829 mono_image_alloc0 (MonoImage *image, guint size);
831 #define mono_image_new0(image,type,size) ((type *) mono_image_alloc0 (image, sizeof (type)* (size)))
833 char*
834 mono_image_strdup (MonoImage *image, const char *s);
836 char*
837 mono_image_strdup_vprintf (MonoImage *image, const char *format, va_list args);
839 char*
840 mono_image_strdup_printf (MonoImage *image, const char *format, ...) MONO_ATTR_FORMAT_PRINTF(2,3);
842 GList*
843 mono_g_list_prepend_image (MonoImage *image, GList *list, gpointer data);
845 GSList*
846 mono_g_slist_append_image (MonoImage *image, GSList *list, gpointer data);
848 void
849 mono_image_lock (MonoImage *image);
851 void
852 mono_image_unlock (MonoImage *image);
854 gpointer
855 mono_image_property_lookup (MonoImage *image, gpointer subject, guint32 property);
857 void
858 mono_image_property_insert (MonoImage *image, gpointer subject, guint32 property, gpointer value);
860 void
861 mono_image_property_remove (MonoImage *image, gpointer subject);
863 gboolean
864 mono_image_close_except_pools (MonoImage *image);
866 void
867 mono_image_close_finish (MonoImage *image);
869 typedef void (*MonoImageUnloadFunc) (MonoImage *image, gpointer user_data);
871 void
872 mono_install_image_unload_hook (MonoImageUnloadFunc func, gpointer user_data);
874 void
875 mono_remove_image_unload_hook (MonoImageUnloadFunc func, gpointer user_data);
877 void
878 mono_install_image_loader (const MonoImageLoader *loader);
880 void
881 mono_image_append_class_to_reflection_info_set (MonoClass *klass);
883 gpointer
884 mono_image_set_alloc (MonoImageSet *set, guint size);
886 gpointer
887 mono_image_set_alloc0 (MonoImageSet *set, guint size);
889 void
890 mono_image_set_lock (MonoImageSet *set);
892 void
893 mono_image_set_unlock (MonoImageSet *set);
895 char*
896 mono_image_set_strdup (MonoImageSet *set, const char *s);
898 MonoImageSet *
899 mono_metadata_get_image_set_for_aggregate_modifiers (MonoAggregateModContainer *amods);
901 #define mono_image_set_new0(image,type,size) ((type *) mono_image_set_alloc0 (image, sizeof (type)* (size)))
903 gboolean
904 mono_image_load_cli_header (MonoImage *image, MonoCLIImageInfo *iinfo);
906 gboolean
907 mono_image_load_metadata (MonoImage *image, MonoCLIImageInfo *iinfo);
909 const char*
910 mono_metadata_string_heap_checked (MonoImage *meta, uint32_t table_index, MonoError *error);
911 const char*
912 mono_metadata_blob_heap_checked (MonoImage *meta, uint32_t table_index, MonoError *error);
913 gboolean
914 mono_metadata_decode_row_checked (const MonoImage *image, const MonoTableInfo *t, int idx, uint32_t *res, int res_size, MonoError *error);
916 MonoType*
917 mono_metadata_get_shared_type (MonoType *type);
919 void
920 mono_metadata_clean_for_image (MonoImage *image);
922 void
923 mono_metadata_clean_generic_classes_for_image (MonoImage *image);
925 MONO_API void
926 mono_metadata_cleanup (void);
928 const char * mono_meta_table_name (int table);
929 void mono_metadata_compute_table_bases (MonoImage *meta);
931 gboolean
932 mono_metadata_interfaces_from_typedef_full (MonoImage *image,
933 guint32 table_index,
934 MonoClass ***interfaces,
935 guint *count,
936 gboolean heap_alloc_result,
937 MonoGenericContext *context,
938 MonoError *error);
940 MONO_API MonoMethodSignature *
941 mono_metadata_parse_method_signature_full (MonoImage *image,
942 MonoGenericContainer *generic_container,
943 int def,
944 const char *ptr,
945 const char **rptr,
946 MonoError *error);
948 MONO_API MonoMethodHeader *
949 mono_metadata_parse_mh_full (MonoImage *image,
950 MonoGenericContainer *container,
951 const char *ptr,
952 MonoError *error);
954 MonoMethodSignature *mono_metadata_parse_signature_checked (MonoImage *image,
955 uint32_t token,
956 MonoError *error);
958 gboolean
959 mono_method_get_header_summary (MonoMethod *method, MonoMethodHeaderSummary *summary);
961 int* mono_metadata_get_param_attrs (MonoImage *m, int def, int param_count);
962 gboolean mono_metadata_method_has_param_attrs (MonoImage *m, int def);
964 guint
965 mono_metadata_generic_context_hash (const MonoGenericContext *context);
967 gboolean
968 mono_metadata_generic_context_equal (const MonoGenericContext *g1,
969 const MonoGenericContext *g2);
971 MonoGenericInst *
972 mono_metadata_parse_generic_inst (MonoImage *image,
973 MonoGenericContainer *container,
974 int count,
975 const char *ptr,
976 const char **rptr,
977 MonoError *error);
979 MonoGenericInst *
980 mono_metadata_get_generic_inst (int type_argc,
981 MonoType **type_argv);
983 MonoGenericInst *
984 mono_metadata_get_canonical_generic_inst (MonoGenericInst *candidate);
986 MonoGenericClass *
987 mono_metadata_lookup_generic_class (MonoClass *gclass,
988 MonoGenericInst *inst,
989 gboolean is_dynamic);
991 MonoGenericInst * mono_metadata_inflate_generic_inst (MonoGenericInst *ginst, MonoGenericContext *context, MonoError *error);
993 guint
994 mono_metadata_generic_param_hash (MonoGenericParam *p);
996 gboolean
997 mono_metadata_generic_param_equal (MonoGenericParam *p1, MonoGenericParam *p2);
999 void mono_dynamic_stream_reset (MonoDynamicStream* stream);
1000 MONO_API void mono_assembly_addref (MonoAssembly *assembly);
1001 void mono_assembly_load_friends (MonoAssembly* ass);
1002 gboolean mono_assembly_has_skip_verification (MonoAssembly* ass);
1004 void mono_assembly_release_gc_roots (MonoAssembly *assembly);
1005 gboolean mono_assembly_close_except_image_pools (MonoAssembly *assembly);
1006 void mono_assembly_close_finish (MonoAssembly *assembly);
1009 gboolean mono_public_tokens_are_equal (const unsigned char *pubt1, const unsigned char *pubt2);
1011 void mono_config_parse_publisher_policy (const char *filename, MonoAssemblyBindingInfo *binding_info);
1012 void mono_config_parse_assembly_bindings (const char *filename, int major, int minor, void *user_data,
1013 void (*infocb)(MonoAssemblyBindingInfo *info, void *user_data));
1015 gboolean
1016 mono_assembly_name_parse_full (const char *name,
1017 MonoAssemblyName *aname,
1018 gboolean save_public_key,
1019 gboolean *is_version_defined,
1020 gboolean *is_token_defined);
1022 gboolean
1023 mono_assembly_fill_assembly_name_full (MonoImage *image, MonoAssemblyName *aname, gboolean copyBlobs);
1026 MONO_API guint32 mono_metadata_get_generic_param_row (MonoImage *image, guint32 token, guint32 *owner);
1028 MonoGenericParam*
1029 mono_metadata_create_anon_gparam (MonoImage *image, gint32 param_num, gboolean is_mvar);
1031 void mono_unload_interface_ids (MonoBitSet *bitset);
1034 MonoType *mono_metadata_type_dup (MonoImage *image, const MonoType *original);
1035 MonoType *mono_metadata_type_dup_with_cmods (MonoImage *image, const MonoType *original, const MonoType *cmods_source);
1037 MonoMethodSignature *mono_metadata_signature_dup_full (MonoImage *image,MonoMethodSignature *sig);
1038 MonoMethodSignature *mono_metadata_signature_dup_mempool (MonoMemPool *mp, MonoMethodSignature *sig);
1039 MonoMethodSignature *mono_metadata_signature_dup_add_this (MonoImage *image, MonoMethodSignature *sig, MonoClass *klass);
1041 MonoGenericInst *
1042 mono_get_shared_generic_inst (MonoGenericContainer *container);
1045 mono_type_stack_size_internal (MonoType *t, int *align, gboolean allow_open);
1047 MONO_API void mono_type_get_desc (GString *res, MonoType *type, mono_bool include_namespace);
1049 gboolean
1050 mono_metadata_type_equal_full (MonoType *t1, MonoType *t2, gboolean signature_only);
1052 MonoMarshalSpec *
1053 mono_metadata_parse_marshal_spec_full (MonoImage *image, MonoImage *parent_image, const char *ptr);
1055 guint mono_metadata_generic_inst_hash (gconstpointer data);
1056 gboolean mono_metadata_generic_inst_equal (gconstpointer ka, gconstpointer kb);
1058 MONO_API void
1059 mono_metadata_field_info_with_mempool (
1060 MonoImage *meta,
1061 guint32 table_index,
1062 guint32 *offset,
1063 guint32 *rva,
1064 MonoMarshalSpec **marshal_spec);
1066 MonoClassField*
1067 mono_metadata_get_corresponding_field_from_generic_type_definition (MonoClassField *field);
1069 MonoEvent*
1070 mono_metadata_get_corresponding_event_from_generic_type_definition (MonoEvent *event);
1072 MonoProperty*
1073 mono_metadata_get_corresponding_property_from_generic_type_definition (MonoProperty *property);
1075 guint32
1076 mono_metadata_signature_size (MonoMethodSignature *sig);
1078 guint mono_metadata_str_hash (gconstpointer v1);
1080 gboolean mono_image_load_pe_data (MonoImage *image);
1082 gboolean mono_image_load_cli_data (MonoImage *image);
1084 void mono_image_load_names (MonoImage *image);
1086 MonoImage *mono_image_open_raw (MonoAssemblyLoadContext *alc, const char *fname, MonoImageOpenStatus *status);
1088 MonoImage *mono_image_open_metadata_only (MonoAssemblyLoadContext *alc, const char *fname, MonoImageOpenStatus *status);
1090 MonoImage *mono_image_open_from_data_internal (MonoAssemblyLoadContext *alc, char *data, guint32 data_len, gboolean need_copy, MonoImageOpenStatus *status, gboolean refonly, gboolean metadata_only, const char *name);
1092 MonoException *mono_get_exception_field_access_msg (const char *msg);
1094 MonoException *mono_get_exception_method_access_msg (const char *msg);
1096 MonoMethod* mono_method_from_method_def_or_ref (MonoImage *m, guint32 tok, MonoGenericContext *context, MonoError *error);
1098 MonoMethod *mono_get_method_constrained_with_method (MonoImage *image, MonoMethod *method, MonoClass *constrained_class, MonoGenericContext *context, MonoError *error);
1099 MonoMethod *mono_get_method_constrained_checked (MonoImage *image, guint32 token, MonoClass *constrained_class, MonoGenericContext *context, MonoMethod **cil_method, MonoError *error);
1101 void mono_type_set_alignment (MonoTypeEnum type, int align);
1103 MonoAotCacheConfig *mono_get_aot_cache_config (void);
1104 MonoType *
1105 mono_type_create_from_typespec_checked (MonoImage *image, guint32 type_spec, MonoError *error);
1107 MonoMethodSignature*
1108 mono_method_get_signature_checked (MonoMethod *method, MonoImage *image, guint32 token, MonoGenericContext *context, MonoError *error);
1110 MonoMethod *
1111 mono_get_method_checked (MonoImage *image, guint32 token, MonoClass *klass, MonoGenericContext *context, MonoError *error);
1113 guint32
1114 mono_metadata_localscope_from_methoddef (MonoImage *meta, guint32 index);
1116 void
1117 mono_wrapper_caches_free (MonoWrapperCaches *cache);
1119 MonoWrapperCaches*
1120 mono_method_get_wrapper_cache (MonoMethod *method);
1122 MonoWrapperCaches*
1123 mono_method_get_wrapper_cache (MonoMethod *method);
1125 MonoType*
1126 mono_metadata_parse_type_checked (MonoImage *m, MonoGenericContainer *container, short opt_attrs, gboolean transient, const char *ptr, const char **rptr, MonoError *error);
1128 MonoGenericContainer *
1129 mono_get_anonymous_container_for_image (MonoImage *image, gboolean is_mvar);
1131 char *
1132 mono_image_set_description (MonoImageSet *);
1134 MonoImageSet *
1135 mono_find_image_set_owner (void *ptr);
1137 MONO_API void
1138 mono_loader_register_module (const char *name, MonoDl *module);
1140 gboolean
1141 mono_assembly_is_problematic_version (const char *name, guint16 major, guint16 minor, guint16 build, guint16 revision);
1143 void
1144 mono_ginst_get_desc (GString *str, MonoGenericInst *ginst);
1146 void
1147 mono_loader_set_strict_strong_names (gboolean enabled);
1149 gboolean
1150 mono_loader_get_strict_strong_names (void);
1152 gboolean
1153 mono_type_in_image (MonoType *type, MonoImage *image);
1155 gboolean
1156 mono_type_is_valid_generic_argument (MonoType *type);
1158 MonoAssemblyContextKind
1159 mono_asmctx_get_kind (const MonoAssemblyContext *ctx);
1161 #define MONO_CLASS_IS_INTERFACE_INTERNAL(c) ((mono_class_get_flags (c) & TYPE_ATTRIBUTE_INTERFACE) || mono_type_is_generic_parameter (m_class_get_byval_arg (c)))
1163 static inline gboolean
1164 m_image_is_raw_data_allocated (MonoImage *image)
1166 return image->storage ? image->storage->raw_data_allocated : FALSE;
1169 static inline gboolean
1170 m_image_is_fileio_used (MonoImage *image)
1172 return image->storage ? image->storage->fileio_used : FALSE;
1175 #ifdef HOST_WIN32
1176 static inline gboolean
1177 m_image_is_module_handle (MonoImage *image)
1179 return image->storage ? image->storage->is_module_handle : FALSE;
1182 static inline gboolean
1183 m_image_has_entry_point (MonoImage *image)
1185 return image->storage ? image->storage->has_entry_point : FALSE;
1187 #endif
1189 static inline const char *
1190 m_image_get_name (MonoImage *image)
1192 return image->name;
1195 static inline const char *
1196 m_image_get_filename (MonoImage *image)
1198 return image->filename;
1201 static inline const char *
1202 m_image_get_assembly_name (MonoImage *image)
1204 return image->assembly_name;
1207 static inline
1208 MonoAssemblyLoadContext *
1209 mono_image_get_alc (MonoImage *image)
1211 #ifndef ENABLE_NETCORE
1212 return NULL;
1213 #else
1214 return image->alc;
1215 #endif
1218 static inline
1219 MonoAssemblyLoadContext *
1220 mono_assembly_get_alc (MonoAssembly *assm)
1222 return mono_image_get_alc (assm->image);
1226 * mono_type_get_type_internal:
1227 * \param type the \c MonoType operated on
1228 * \returns the IL type value for \p type. This is one of the \c MonoTypeEnum
1229 * enum members like \c MONO_TYPE_I4 or \c MONO_TYPE_STRING.
1231 static inline int
1232 mono_type_get_type_internal (MonoType *type)
1234 return type->type;
1238 * mono_type_get_signature:
1239 * \param type the \c MonoType operated on
1240 * It is only valid to call this function if \p type is a \c MONO_TYPE_FNPTR .
1241 * \returns the \c MonoMethodSignature pointer that describes the signature
1242 * of the function pointer \p type represents.
1244 static inline MonoMethodSignature*
1245 mono_type_get_signature_internal (MonoType *type)
1247 g_assert (type->type == MONO_TYPE_FNPTR);
1248 return type->data.method;
1252 * mono_type_is_byref_internal:
1253 * \param type the \c MonoType operated on
1254 * \returns TRUE if \p type represents a type passed by reference,
1255 * FALSE otherwise.
1257 static inline mono_bool
1258 mono_type_is_byref_internal (MonoType *type)
1260 return type->byref;
1264 * mono_type_get_class_internal:
1265 * \param type the \c MonoType operated on
1266 * It is only valid to call this function if \p type is a \c MONO_TYPE_CLASS or a
1267 * \c MONO_TYPE_VALUETYPE . For more general functionality, use \c mono_class_from_mono_type_internal,
1268 * instead.
1269 * \returns the \c MonoClass pointer that describes the class that \p type represents.
1271 static inline MonoClass*
1272 mono_type_get_class_internal (MonoType *type)
1274 /* FIXME: review the runtime users before adding the assert here */
1275 return type->data.klass;
1279 * mono_type_get_array_type_internal:
1280 * \param type the \c MonoType operated on
1281 * It is only valid to call this function if \p type is a \c MONO_TYPE_ARRAY .
1282 * \returns a \c MonoArrayType struct describing the array type that \p type
1283 * represents. The info includes details such as rank, array element type
1284 * and the sizes and bounds of multidimensional arrays.
1286 static inline MonoArrayType*
1287 mono_type_get_array_type_internal (MonoType *type)
1289 return type->data.array;
1292 #endif /* __MONO_METADATA_INTERNALS_H__ */