Revert some changes which don't have proper dependencies.
[mono-project.git] / mono / metadata / metadata-internals.h
blob881d619a0c69155cd448d0d524a0bb7151988fbc
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 _MonoDllMap MonoDllMap;
303 typedef struct {
304 gboolean (*match) (MonoImage*);
305 gboolean (*load_pe_data) (MonoImage*);
306 gboolean (*load_cli_data) (MonoImage*);
307 gboolean (*load_tables) (MonoImage*);
308 } MonoImageLoader;
310 /* Represents the physical bytes for an image (usually in the file system, but
311 * could be in memory).
313 * The MonoImageStorage owns the raw data for an image and is responsible for
314 * cleanup.
316 * May be shared by multiple MonoImage objects if they opened the same
317 * underlying file or byte blob in memory.
319 * There is an abstract string key (usually a file path, but could be formed in
320 * other ways) that is used to share MonoImageStorage objects among images.
323 typedef struct {
324 MonoRefCount ref;
326 /* key used for lookups. owned by this image storage. */
327 char *key;
329 /* If the raw data was allocated from a source such as mmap, the allocator may store resource tracking information here. */
330 void *raw_data_handle;
331 char *raw_data;
332 guint32 raw_data_len;
333 guint8 raw_buffer_used : 1;
334 guint8 raw_data_allocated : 1;
335 guint8 fileio_used : 1;
337 #ifdef HOST_WIN32
338 /* Module was loaded using LoadLibrary. */
339 guint8 is_module_handle : 1;
341 /* Module entry point is _CorDllMain. */
342 guint8 has_entry_point : 1;
343 #endif
344 } MonoImageStorage;
346 struct _MonoImage {
348 * This count is incremented during these situations:
349 * - An assembly references this MonoImage through its 'image' field
350 * - This MonoImage is present in the 'files' field of an image
351 * - This MonoImage is present in the 'modules' field of an image
352 * - A thread is holding a temporary reference to this MonoImage between
353 * calls to mono_image_open and mono_image_close ()
355 int ref_count;
357 MonoImageStorage *storage;
359 /* Aliases storage->raw_data when storage is non-NULL. Otherwise NULL. */
360 char *raw_data;
361 guint32 raw_data_len;
363 /* Whenever this is a dynamically emitted module */
364 guint8 dynamic : 1;
366 /* Whenever this is a reflection only image */
367 guint8 ref_only : 1;
369 /* Whenever this image contains uncompressed metadata */
370 guint8 uncompressed_metadata : 1;
372 /* Whenever this image contains metadata only without PE data */
373 guint8 metadata_only : 1;
375 /* Whether this image belongs to load-from context */
376 guint8 load_from_context: 1;
378 guint8 checked_module_cctor : 1;
379 guint8 has_module_cctor : 1;
381 guint8 idx_string_wide : 1;
382 guint8 idx_guid_wide : 1;
383 guint8 idx_blob_wide : 1;
385 /* Whenever this image is considered as platform code for the CoreCLR security model */
386 guint8 core_clr_platform_code : 1;
388 /* The path to the file for this image or an arbitrary name for images loaded from data. */
389 char *name;
391 /* The path to the file for this image or NULL */
392 char *filename;
394 /* The assembly name reported in the file for this image (expected to be NULL for a netmodule) */
395 const char *assembly_name;
397 /* The module name reported in the file for this image (could be NULL for a malformed file) */
398 const char *module_name;
399 guint32 time_date_stamp;
401 char *version;
402 gint16 md_version_major, md_version_minor;
403 char *guid;
404 MonoCLIImageInfo *image_info;
405 MonoMemPool *mempool; /*protected by the image lock*/
407 char *raw_metadata;
409 MonoStreamHeader heap_strings;
410 MonoStreamHeader heap_us;
411 MonoStreamHeader heap_blob;
412 MonoStreamHeader heap_guid;
413 MonoStreamHeader heap_tables;
414 MonoStreamHeader heap_pdb;
416 const char *tables_base;
418 /* For PPDB files */
419 guint64 referenced_tables;
420 int *referenced_table_rows;
422 /**/
423 MonoTableInfo tables [MONO_TABLE_NUM];
426 * references is initialized only by using the mono_assembly_open
427 * function, and not by using the lowlevel mono_image_open.
429 * It is NULL terminated.
431 MonoAssembly **references;
432 int nreferences;
434 /* Code files in the assembly. The main assembly has a "file" table and also a "module"
435 * table, where the module table is a subset of the file table. We track both lists,
436 * and because we can lazy-load them at different times we reference-increment both.
438 MonoImage **modules;
439 guint32 module_count;
440 gboolean *modules_loaded;
442 MonoImage **files;
443 guint32 file_count;
445 MonoAotModule *aot_module;
447 guint8 aotid[16];
450 * The Assembly this image was loaded from.
452 MonoAssembly *assembly;
455 * Indexed by method tokens and typedef tokens.
457 GHashTable *method_cache; /*protected by the image lock*/
458 MonoInternalHashTable class_cache;
460 /* Indexed by memberref + methodspec tokens */
461 GHashTable *methodref_cache; /*protected by the image lock*/
464 * Indexed by fielddef and memberref tokens
466 MonoConcurrentHashTable *field_cache; /*protected by the image lock*/
468 /* indexed by typespec tokens. */
469 MonoConcurrentHashTable *typespec_cache; /* protected by the image lock */
470 /* indexed by token */
471 GHashTable *memberref_signatures;
473 /* Indexed by blob heap indexes */
474 GHashTable *method_signatures;
477 * Indexes namespaces to hash tables that map class name to typedef token.
479 GHashTable *name_cache; /*protected by the image lock*/
482 * Indexed by MonoClass
484 GHashTable *array_cache;
485 GHashTable *ptr_cache;
487 GHashTable *szarray_cache;
488 /* This has a separate lock to improve scalability */
489 mono_mutex_t szarray_cache_lock;
492 * indexed by SignaturePointerPair
494 GHashTable *delegate_bound_static_invoke_cache;
495 GHashTable *native_func_wrapper_cache;
498 * indexed by MonoMethod pointers
500 GHashTable *wrapper_param_names;
501 GHashTable *array_accessor_cache;
504 * indexed by MonoClass pointers
506 GHashTable *ldfld_wrapper_cache;
507 GHashTable *ldflda_wrapper_cache;
508 GHashTable *stfld_wrapper_cache;
509 GHashTable *isinst_cache;
511 GHashTable *icall_wrapper_cache;
512 GHashTable *castclass_cache;
513 GHashTable *proxy_isinst_cache;
514 GHashTable *rgctx_template_hash; /* LOCKING: templates lock */
516 /* Contains rarely used fields of runtime structures belonging to this image */
517 MonoPropertyHash *property_hash;
519 void *reflection_info;
522 * user_info is a public field and is not touched by the
523 * metadata engine
525 void *user_info;
527 /* dll map entries */
528 MonoDllMap *dll_map;
530 /* interfaces IDs from this image */
531 /* protected by the classes lock */
532 MonoBitSet *interface_bitset;
534 /* when the image is being closed, this is abused as a list of
535 malloc'ed regions to be freed. */
536 GSList *reflection_info_unregister_classes;
538 /* List of dependent image sets containing this image */
539 /* Protected by image_sets_lock */
540 GSList *image_sets;
542 /* Caches for wrappers that DO NOT reference generic */
543 /* arguments */
544 MonoWrapperCaches wrapper_caches;
546 /* Pre-allocated anon generic params for the first N generic
547 * parameters, for a small N */
548 MonoGenericParam *var_gparam_cache_fast;
549 MonoGenericParam *mvar_gparam_cache_fast;
550 /* Anon generic parameters past N, if needed */
551 MonoConcurrentHashTable *var_gparam_cache;
552 MonoConcurrentHashTable *mvar_gparam_cache;
554 /* Maps malloc-ed char* pinvoke scope -> MonoDl* */
555 GHashTable *pinvoke_scopes;
557 /* Maps malloc-ed char* pinvoke scope -> malloced-ed char* filename */
558 GHashTable *pinvoke_scope_filenames;
560 /* Indexed by MonoGenericParam pointers */
561 GHashTable **gshared_types;
562 /* The length of the above array */
563 int gshared_types_len;
565 /* The loader used to load this image */
566 MonoImageLoader *loader;
568 // Containers for MonoGenericParams associated with this image but not with any specific class or method. Created on demand.
569 // This could happen, for example, for MonoTypes associated with TypeSpec table entries.
570 MonoGenericContainer *anonymous_generic_class_container;
571 MonoGenericContainer *anonymous_generic_method_container;
573 gboolean weak_fields_inited;
574 /* Contains 1 based indexes */
575 GHashTable *weak_field_indexes;
578 * No other runtime locks must be taken while holding this lock.
579 * It's meant to be used only to mutate and query structures part of this image.
581 mono_mutex_t lock;
585 * Generic instances and aggregated custom modifiers depend on many images, and they need to be deleted if one
586 * of the images they depend on is unloaded. For example,
587 * List<Foo> depends on both List's image and Foo's image.
588 * A MonoImageSet is the owner of all generic instances depending on the same set of
589 * images.
591 typedef struct {
592 int nimages;
593 MonoImage **images;
595 // Generic-specific caches
596 GHashTable *ginst_cache, *gmethod_cache, *gsignature_cache;
597 MonoConcurrentHashTable *gclass_cache;
599 /* mirror caches of ones already on MonoImage. These ones contain generics */
600 GHashTable *szarray_cache, *array_cache, *ptr_cache;
602 MonoWrapperCaches wrapper_caches;
604 GHashTable *aggregate_modifiers_cache;
606 mono_mutex_t lock;
609 * Memory for generic instances owned by this image set should be allocated from
610 * this mempool, using the mono_image_set_alloc family of functions.
612 MonoMemPool *mempool;
613 } MonoImageSet;
615 enum {
616 MONO_SECTION_TEXT,
617 MONO_SECTION_RSRC,
618 MONO_SECTION_RELOC,
619 MONO_SECTION_MAX
622 typedef struct {
623 GHashTable *hash;
624 char *data;
625 guint32 alloc_size; /* malloced bytes */
626 guint32 index;
627 guint32 offset; /* from start of metadata */
628 } MonoDynamicStream;
630 typedef struct {
631 guint32 alloc_rows;
632 guint32 rows;
633 guint8 row_size; /* calculated later with column_sizes */
634 guint8 columns;
635 guint32 next_idx;
636 guint32 *values; /* rows * columns */
637 } MonoDynamicTable;
639 /* "Dynamic" assemblies and images arise from System.Reflection.Emit */
640 struct _MonoDynamicAssembly {
641 MonoAssembly assembly;
642 char *strong_name;
643 guint32 strong_name_size;
644 guint8 run;
645 guint8 save;
646 MonoDomain *domain;
649 struct _MonoDynamicImage {
650 MonoImage image;
651 guint32 meta_size;
652 guint32 text_rva;
653 guint32 metadata_rva;
654 guint32 image_base;
655 guint32 cli_header_offset;
656 guint32 iat_offset;
657 guint32 idt_offset;
658 guint32 ilt_offset;
659 guint32 imp_names_offset;
660 struct {
661 guint32 rva;
662 guint32 size;
663 guint32 offset;
664 guint32 attrs;
665 } sections [MONO_SECTION_MAX];
666 GHashTable *typespec;
667 GHashTable *typeref;
668 GHashTable *handleref;
669 MonoGHashTable *tokens;
670 GHashTable *blob_cache;
671 GHashTable *standalonesig_cache;
672 GList *array_methods;
673 GPtrArray *gen_params;
674 MonoGHashTable *token_fixups;
675 GHashTable *method_to_table_idx;
676 GHashTable *field_to_table_idx;
677 GHashTable *method_aux_hash;
678 GHashTable *vararg_aux_hash;
679 MonoGHashTable *generic_def_objects;
681 * Maps final token values to the object they describe.
683 MonoGHashTable *remapped_tokens;
684 gboolean run;
685 gboolean save;
686 gboolean initial_image;
687 guint32 pe_kind, machine;
688 char *strong_name;
689 guint32 strong_name_size;
690 char *win32_res;
691 guint32 win32_res_size;
692 guint8 *public_key;
693 int public_key_len;
694 MonoDynamicStream sheap;
695 MonoDynamicStream code; /* used to store method headers and bytecode */
696 MonoDynamicStream resources; /* managed embedded resources */
697 MonoDynamicStream us;
698 MonoDynamicStream blob;
699 MonoDynamicStream tstream;
700 MonoDynamicStream guid;
701 MonoDynamicTable tables [MONO_TABLE_NUM];
702 MonoClass *wrappers_type; /*wrappers are bound to this type instead of <Module>*/
705 /* Contains information about assembly binding */
706 typedef struct _MonoAssemblyBindingInfo {
707 char *name;
708 char *culture;
709 guchar public_key_token [MONO_PUBLIC_KEY_TOKEN_LENGTH];
710 int major;
711 int minor;
712 AssemblyVersionSet old_version_bottom;
713 AssemblyVersionSet old_version_top;
714 AssemblyVersionSet new_version;
715 guint has_old_version_bottom : 1;
716 guint has_old_version_top : 1;
717 guint has_new_version : 1;
718 guint is_valid : 1;
719 gint32 domain_id; /*Needed to unload per-domain binding*/
720 } MonoAssemblyBindingInfo;
722 struct _MonoMethodHeader {
723 const unsigned char *code;
724 #ifdef MONO_SMALL_CONFIG
725 guint16 code_size;
726 #else
727 guint32 code_size;
728 #endif
729 guint16 max_stack : 15;
730 unsigned int is_transient: 1; /* mono_metadata_free_mh () will actually free this header */
731 unsigned int num_clauses : 15;
732 /* if num_locals != 0, then the following apply: */
733 unsigned int init_locals : 1;
734 guint16 num_locals;
735 MonoExceptionClause *clauses;
736 MonoBitSet *volatile_args;
737 MonoBitSet *volatile_locals;
738 MonoType *locals [MONO_ZERO_LEN_ARRAY];
741 typedef struct {
742 const unsigned char *code;
743 guint32 code_size;
744 guint16 max_stack;
745 gboolean has_clauses;
746 gboolean has_locals;
747 } MonoMethodHeaderSummary;
749 // FIXME? offsetof (MonoMethodHeader, locals)?
750 #define MONO_SIZEOF_METHOD_HEADER (sizeof (struct _MonoMethodHeader) - MONO_ZERO_LEN_ARRAY * SIZEOF_VOID_P)
752 struct _MonoMethodSignature {
753 MonoType *ret;
754 #ifdef MONO_SMALL_CONFIG
755 guint8 param_count;
756 gint8 sentinelpos;
757 unsigned int generic_param_count : 5;
758 #else
759 guint16 param_count;
760 gint16 sentinelpos;
761 unsigned int generic_param_count : 16;
762 #endif
763 unsigned int call_convention : 6;
764 unsigned int hasthis : 1;
765 unsigned int explicit_this : 1;
766 unsigned int pinvoke : 1;
767 unsigned int is_inflated : 1;
768 unsigned int has_type_parameters : 1;
769 MonoType *params [MONO_ZERO_LEN_ARRAY];
773 * AOT cache configuration loaded from config files.
774 * Doesn't really belong here.
776 typedef struct {
778 * Enable aot caching for applications whose main assemblies are in
779 * this list.
781 GSList *apps;
782 GSList *assemblies;
783 char *aot_options;
784 } MonoAotCacheConfig;
786 #define MONO_SIZEOF_METHOD_SIGNATURE (sizeof (struct _MonoMethodSignature) - MONO_ZERO_LEN_ARRAY * SIZEOF_VOID_P)
788 static inline gboolean
789 image_is_dynamic (MonoImage *image)
791 #ifdef DISABLE_REFLECTION_EMIT
792 return FALSE;
793 #else
794 return image->dynamic;
795 #endif
798 static inline gboolean
799 assembly_is_dynamic (MonoAssembly *assembly)
801 #ifdef DISABLE_REFLECTION_EMIT
802 return FALSE;
803 #else
804 return assembly->dynamic;
805 #endif
808 /* for use with allocated memory blocks (assumes alignment is to 8 bytes) */
809 guint mono_aligned_addr_hash (gconstpointer ptr);
811 void
812 mono_image_check_for_module_cctor (MonoImage *image);
814 gpointer
815 mono_image_alloc (MonoImage *image, guint size);
817 gpointer
818 mono_image_alloc0 (MonoImage *image, guint size);
820 #define mono_image_new0(image,type,size) ((type *) mono_image_alloc0 (image, sizeof (type)* (size)))
822 char*
823 mono_image_strdup (MonoImage *image, const char *s);
825 char*
826 mono_image_strdup_vprintf (MonoImage *image, const char *format, va_list args);
828 char*
829 mono_image_strdup_printf (MonoImage *image, const char *format, ...) MONO_ATTR_FORMAT_PRINTF(2,3);
831 GList*
832 mono_g_list_prepend_image (MonoImage *image, GList *list, gpointer data);
834 GSList*
835 mono_g_slist_append_image (MonoImage *image, GSList *list, gpointer data);
837 void
838 mono_image_lock (MonoImage *image);
840 void
841 mono_image_unlock (MonoImage *image);
843 gpointer
844 mono_image_property_lookup (MonoImage *image, gpointer subject, guint32 property);
846 void
847 mono_image_property_insert (MonoImage *image, gpointer subject, guint32 property, gpointer value);
849 void
850 mono_image_property_remove (MonoImage *image, gpointer subject);
852 gboolean
853 mono_image_close_except_pools (MonoImage *image);
855 void
856 mono_image_close_finish (MonoImage *image);
858 typedef void (*MonoImageUnloadFunc) (MonoImage *image, gpointer user_data);
860 void
861 mono_install_image_unload_hook (MonoImageUnloadFunc func, gpointer user_data);
863 void
864 mono_remove_image_unload_hook (MonoImageUnloadFunc func, gpointer user_data);
866 void
867 mono_install_image_loader (const MonoImageLoader *loader);
869 void
870 mono_image_append_class_to_reflection_info_set (MonoClass *klass);
872 gpointer
873 mono_image_set_alloc (MonoImageSet *set, guint size);
875 gpointer
876 mono_image_set_alloc0 (MonoImageSet *set, guint size);
878 void
879 mono_image_set_lock (MonoImageSet *set);
881 void
882 mono_image_set_unlock (MonoImageSet *set);
884 char*
885 mono_image_set_strdup (MonoImageSet *set, const char *s);
887 MonoImageSet *
888 mono_metadata_get_image_set_for_aggregate_modifiers (MonoAggregateModContainer *amods);
890 #define mono_image_set_new0(image,type,size) ((type *) mono_image_set_alloc0 (image, sizeof (type)* (size)))
892 gboolean
893 mono_image_load_cli_header (MonoImage *image, MonoCLIImageInfo *iinfo);
895 gboolean
896 mono_image_load_metadata (MonoImage *image, MonoCLIImageInfo *iinfo);
898 const char*
899 mono_metadata_string_heap_checked (MonoImage *meta, uint32_t table_index, MonoError *error);
900 const char*
901 mono_metadata_blob_heap_checked (MonoImage *meta, uint32_t table_index, MonoError *error);
902 gboolean
903 mono_metadata_decode_row_checked (const MonoImage *image, const MonoTableInfo *t, int idx, uint32_t *res, int res_size, MonoError *error);
905 MonoType*
906 mono_metadata_get_shared_type (MonoType *type);
908 void
909 mono_metadata_clean_for_image (MonoImage *image);
911 void
912 mono_metadata_clean_generic_classes_for_image (MonoImage *image);
914 MONO_API void
915 mono_metadata_cleanup (void);
917 const char * mono_meta_table_name (int table);
918 void mono_metadata_compute_table_bases (MonoImage *meta);
920 gboolean
921 mono_metadata_interfaces_from_typedef_full (MonoImage *image,
922 guint32 table_index,
923 MonoClass ***interfaces,
924 guint *count,
925 gboolean heap_alloc_result,
926 MonoGenericContext *context,
927 MonoError *error);
929 MONO_API MonoMethodSignature *
930 mono_metadata_parse_method_signature_full (MonoImage *image,
931 MonoGenericContainer *generic_container,
932 int def,
933 const char *ptr,
934 const char **rptr,
935 MonoError *error);
937 MONO_API MonoMethodHeader *
938 mono_metadata_parse_mh_full (MonoImage *image,
939 MonoGenericContainer *container,
940 const char *ptr,
941 MonoError *error);
943 MonoMethodSignature *mono_metadata_parse_signature_checked (MonoImage *image,
944 uint32_t token,
945 MonoError *error);
947 gboolean
948 mono_method_get_header_summary (MonoMethod *method, MonoMethodHeaderSummary *summary);
950 int* mono_metadata_get_param_attrs (MonoImage *m, int def, int param_count);
951 gboolean mono_metadata_method_has_param_attrs (MonoImage *m, int def);
953 guint
954 mono_metadata_generic_context_hash (const MonoGenericContext *context);
956 gboolean
957 mono_metadata_generic_context_equal (const MonoGenericContext *g1,
958 const MonoGenericContext *g2);
960 MonoGenericInst *
961 mono_metadata_parse_generic_inst (MonoImage *image,
962 MonoGenericContainer *container,
963 int count,
964 const char *ptr,
965 const char **rptr,
966 MonoError *error);
968 MonoGenericInst *
969 mono_metadata_get_generic_inst (int type_argc,
970 MonoType **type_argv);
972 MonoGenericInst *
973 mono_metadata_get_canonical_generic_inst (MonoGenericInst *candidate);
975 MonoGenericClass *
976 mono_metadata_lookup_generic_class (MonoClass *gclass,
977 MonoGenericInst *inst,
978 gboolean is_dynamic);
980 MonoGenericInst * mono_metadata_inflate_generic_inst (MonoGenericInst *ginst, MonoGenericContext *context, MonoError *error);
982 guint
983 mono_metadata_generic_param_hash (MonoGenericParam *p);
985 gboolean
986 mono_metadata_generic_param_equal (MonoGenericParam *p1, MonoGenericParam *p2);
988 void mono_dynamic_stream_reset (MonoDynamicStream* stream);
989 MONO_API void mono_assembly_addref (MonoAssembly *assembly);
990 void mono_assembly_load_friends (MonoAssembly* ass);
991 gboolean mono_assembly_has_skip_verification (MonoAssembly* ass);
993 void mono_assembly_release_gc_roots (MonoAssembly *assembly);
994 gboolean mono_assembly_close_except_image_pools (MonoAssembly *assembly);
995 void mono_assembly_close_finish (MonoAssembly *assembly);
998 gboolean mono_public_tokens_are_equal (const unsigned char *pubt1, const unsigned char *pubt2);
1000 void mono_config_parse_publisher_policy (const char *filename, MonoAssemblyBindingInfo *binding_info);
1001 void mono_config_parse_assembly_bindings (const char *filename, int major, int minor, void *user_data,
1002 void (*infocb)(MonoAssemblyBindingInfo *info, void *user_data));
1004 gboolean
1005 mono_assembly_name_parse_full (const char *name,
1006 MonoAssemblyName *aname,
1007 gboolean save_public_key,
1008 gboolean *is_version_defined,
1009 gboolean *is_token_defined);
1011 gboolean
1012 mono_assembly_fill_assembly_name_full (MonoImage *image, MonoAssemblyName *aname, gboolean copyBlobs);
1015 MONO_API guint32 mono_metadata_get_generic_param_row (MonoImage *image, guint32 token, guint32 *owner);
1017 MonoGenericParam*
1018 mono_metadata_create_anon_gparam (MonoImage *image, gint32 param_num, gboolean is_mvar);
1020 void mono_unload_interface_ids (MonoBitSet *bitset);
1023 MonoType *mono_metadata_type_dup (MonoImage *image, const MonoType *original);
1024 MonoType *mono_metadata_type_dup_with_cmods (MonoImage *image, const MonoType *original, const MonoType *cmods_source);
1026 MonoMethodSignature *mono_metadata_signature_dup_full (MonoImage *image,MonoMethodSignature *sig);
1027 MonoMethodSignature *mono_metadata_signature_dup_mempool (MonoMemPool *mp, MonoMethodSignature *sig);
1028 MonoMethodSignature *mono_metadata_signature_dup_add_this (MonoImage *image, MonoMethodSignature *sig, MonoClass *klass);
1030 MonoGenericInst *
1031 mono_get_shared_generic_inst (MonoGenericContainer *container);
1034 mono_type_stack_size_internal (MonoType *t, int *align, gboolean allow_open);
1036 MONO_API void mono_type_get_desc (GString *res, MonoType *type, mono_bool include_namespace);
1038 gboolean
1039 mono_metadata_type_equal_full (MonoType *t1, MonoType *t2, gboolean signature_only);
1041 MonoMarshalSpec *
1042 mono_metadata_parse_marshal_spec_full (MonoImage *image, MonoImage *parent_image, const char *ptr);
1044 guint mono_metadata_generic_inst_hash (gconstpointer data);
1045 gboolean mono_metadata_generic_inst_equal (gconstpointer ka, gconstpointer kb);
1047 MONO_API void
1048 mono_metadata_field_info_with_mempool (
1049 MonoImage *meta,
1050 guint32 table_index,
1051 guint32 *offset,
1052 guint32 *rva,
1053 MonoMarshalSpec **marshal_spec);
1055 MonoClassField*
1056 mono_metadata_get_corresponding_field_from_generic_type_definition (MonoClassField *field);
1058 MonoEvent*
1059 mono_metadata_get_corresponding_event_from_generic_type_definition (MonoEvent *event);
1061 MonoProperty*
1062 mono_metadata_get_corresponding_property_from_generic_type_definition (MonoProperty *property);
1064 guint32
1065 mono_metadata_signature_size (MonoMethodSignature *sig);
1067 guint mono_metadata_str_hash (gconstpointer v1);
1069 gboolean mono_image_load_pe_data (MonoImage *image);
1071 gboolean mono_image_load_cli_data (MonoImage *image);
1073 void mono_image_load_names (MonoImage *image);
1075 MonoImage *mono_image_open_raw (const char *fname, MonoImageOpenStatus *status);
1077 MonoImage *mono_image_open_metadata_only (const char *fname, MonoImageOpenStatus *status);
1079 MonoImage *mono_image_open_from_data_internal (char *data, guint32 data_len, gboolean need_copy, MonoImageOpenStatus *status, gboolean refonly, gboolean metadata_only, const char *name);
1081 MonoException *mono_get_exception_field_access_msg (const char *msg);
1083 MonoException *mono_get_exception_method_access_msg (const char *msg);
1085 MonoMethod* mono_method_from_method_def_or_ref (MonoImage *m, guint32 tok, MonoGenericContext *context, MonoError *error);
1087 MonoMethod *mono_get_method_constrained_with_method (MonoImage *image, MonoMethod *method, MonoClass *constrained_class, MonoGenericContext *context, MonoError *error);
1088 MonoMethod *mono_get_method_constrained_checked (MonoImage *image, guint32 token, MonoClass *constrained_class, MonoGenericContext *context, MonoMethod **cil_method, MonoError *error);
1090 void mono_type_set_alignment (MonoTypeEnum type, int align);
1092 MonoAotCacheConfig *mono_get_aot_cache_config (void);
1093 MonoType *
1094 mono_type_create_from_typespec_checked (MonoImage *image, guint32 type_spec, MonoError *error);
1096 MonoMethodSignature*
1097 mono_method_get_signature_checked (MonoMethod *method, MonoImage *image, guint32 token, MonoGenericContext *context, MonoError *error);
1099 MonoMethod *
1100 mono_get_method_checked (MonoImage *image, guint32 token, MonoClass *klass, MonoGenericContext *context, MonoError *error);
1102 guint32
1103 mono_metadata_localscope_from_methoddef (MonoImage *meta, guint32 index);
1105 void
1106 mono_wrapper_caches_free (MonoWrapperCaches *cache);
1108 MonoWrapperCaches*
1109 mono_method_get_wrapper_cache (MonoMethod *method);
1111 MonoWrapperCaches*
1112 mono_method_get_wrapper_cache (MonoMethod *method);
1114 MonoType*
1115 mono_metadata_parse_type_checked (MonoImage *m, MonoGenericContainer *container, short opt_attrs, gboolean transient, const char *ptr, const char **rptr, MonoError *error);
1117 MonoGenericContainer *
1118 mono_get_anonymous_container_for_image (MonoImage *image, gboolean is_mvar);
1120 char *
1121 mono_image_set_description (MonoImageSet *);
1123 MonoImageSet *
1124 mono_find_image_set_owner (void *ptr);
1126 MONO_API void
1127 mono_loader_register_module (const char *name, MonoDl *module);
1129 gboolean
1130 mono_assembly_is_problematic_version (const char *name, guint16 major, guint16 minor, guint16 build, guint16 revision);
1132 void
1133 mono_ginst_get_desc (GString *str, MonoGenericInst *ginst);
1135 void
1136 mono_loader_set_strict_strong_names (gboolean enabled);
1138 gboolean
1139 mono_loader_get_strict_strong_names (void);
1141 gboolean
1142 mono_type_in_image (MonoType *type, MonoImage *image);
1144 gboolean
1145 mono_type_is_valid_generic_argument (MonoType *type);
1147 MonoAssemblyContextKind
1148 mono_asmctx_get_kind (const MonoAssemblyContext *ctx);
1150 #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)))
1152 static inline gboolean
1153 m_image_is_raw_data_allocated (MonoImage *image)
1155 return image->storage ? image->storage->raw_data_allocated : FALSE;
1158 static inline gboolean
1159 m_image_is_fileio_used (MonoImage *image)
1161 return image->storage ? image->storage->fileio_used : FALSE;
1164 #ifdef HOST_WIN32
1165 static inline gboolean
1166 m_image_is_module_handle (MonoImage *image)
1168 return image->storage ? image->storage->is_module_handle : FALSE;
1171 static inline gboolean
1172 m_image_has_entry_point (MonoImage *image)
1174 return image->storage ? image->storage->has_entry_point : FALSE;
1177 #endif
1179 #endif /* __MONO_METADATA_INTERNALS_H__ */