Merge pull request #4570 from lateralusX/jlorenss/visual_studio_msbuild_fix
[mono.git] / mono / metadata / metadata-internals.h
1 /**
2  * \file
3  */
4
5 #ifndef __MONO_METADATA_INTERNALS_H__
6 #define __MONO_METADATA_INTERNALS_H__
7
8 #include "mono/metadata/image.h"
9 #include "mono/metadata/blob.h"
10 #include "mono/metadata/cil-coff.h"
11 #include "mono/metadata/mempool.h"
12 #include "mono/metadata/domain-internals.h"
13 #include "mono/metadata/mono-hash.h"
14 #include "mono/utils/mono-compiler.h"
15 #include "mono/utils/mono-dl.h"
16 #include "mono/utils/monobitset.h"
17 #include "mono/utils/mono-property-hash.h"
18 #include "mono/utils/mono-value-hash.h"
19 #include <mono/utils/mono-error.h>
20 #include "mono/utils/mono-conc-hashtable.h"
21
22 struct _MonoType {
23         union {
24                 MonoClass *klass; /* for VALUETYPE and CLASS */
25                 MonoType *type;   /* for PTR */
26                 MonoArrayType *array; /* for ARRAY */
27                 MonoMethodSignature *method;
28                 MonoGenericParam *generic_param; /* for VAR and MVAR */
29                 MonoGenericClass *generic_class; /* for GENERICINST */
30         } data;
31         unsigned int attrs    : 16; /* param attributes or field flags */
32         MonoTypeEnum type     : 8;
33         unsigned int num_mods : 6;  /* max 64 modifiers follow at the end */
34         unsigned int byref    : 1;
35         unsigned int pinned   : 1;  /* valid when included in a local var signature */
36         MonoCustomMod modifiers [MONO_ZERO_LEN_ARRAY]; /* this may grow */
37 };
38
39 #define MONO_SIZEOF_TYPE (offsetof (struct _MonoType, modifiers))
40
41 #define MONO_SECMAN_FLAG_INIT(x)                (x & 0x2)
42 #define MONO_SECMAN_FLAG_GET_VALUE(x)           (x & 0x1)
43 #define MONO_SECMAN_FLAG_SET_VALUE(x,y)         do { x = ((y) ? 0x3 : 0x2); } while (0)
44
45 #define MONO_PUBLIC_KEY_TOKEN_LENGTH    17
46
47 #define MONO_PROCESSOR_ARCHITECTURE_NONE 0
48 #define MONO_PROCESSOR_ARCHITECTURE_MSIL 1
49 #define MONO_PROCESSOR_ARCHITECTURE_X86 2
50 #define MONO_PROCESSOR_ARCHITECTURE_IA64 3
51 #define MONO_PROCESSOR_ARCHITECTURE_AMD64 4
52 #define MONO_PROCESSOR_ARCHITECTURE_ARM 5
53
54 struct _MonoAssemblyName {
55         const char *name;
56         const char *culture;
57         const char *hash_value;
58         const mono_byte* public_key;
59         // string of 16 hex chars + 1 NULL
60         mono_byte public_key_token [MONO_PUBLIC_KEY_TOKEN_LENGTH];
61         uint32_t hash_alg;
62         uint32_t hash_len;
63         uint32_t flags;
64         uint16_t major, minor, build, revision, arch;
65 };
66
67 struct MonoTypeNameParse {
68         char *name_space;
69         char *name;
70         MonoAssemblyName assembly;
71         GList *modifiers; /* 0 -> byref, -1 -> pointer, > 0 -> array rank */
72         GPtrArray *type_arguments;
73         GList *nested;
74 };
75
76 struct _MonoAssembly {
77         /* 
78          * The number of appdomains which have this assembly loaded plus the number of 
79          * assemblies referencing this assembly through an entry in their image->references
80          * arrays. The latter is needed because entries in the image->references array
81          * might point to assemblies which are only loaded in some appdomains, and without
82          * the additional reference, they can be freed at any time.
83          * The ref_count is initially 0.
84          */
85         int ref_count; /* use atomic operations only */
86         char *basedir;
87         MonoAssemblyName aname;
88         MonoImage *image;
89         GSList *friend_assembly_names; /* Computed by mono_assembly_load_friends () */
90         guint8 friend_assembly_names_inited;
91         guint8 in_gac;
92         guint8 dynamic;
93         guint8 corlib_internal;
94         gboolean ref_only;
95         guint8 wrap_non_exception_throws;
96         guint8 wrap_non_exception_throws_inited;
97         guint8 jit_optimizer_disabled;
98         guint8 jit_optimizer_disabled_inited;
99         /* security manager flags (one bit is for lazy initialization) */
100         guint32 ecma:2;         /* Has the ECMA key */
101         guint32 aptc:2;         /* Has the [AllowPartiallyTrustedCallers] attributes */
102         guint32 fulltrust:2;    /* Has FullTrust permission */
103         guint32 unmanaged:2;    /* Has SecurityPermissionFlag.UnmanagedCode permission */
104         guint32 skipverification:2;     /* Has SecurityPermissionFlag.SkipVerification permission */
105 };
106
107 typedef struct {
108         /*
109          * indexed by MonoMethodSignature 
110          * Protected by the marshal lock
111          */
112         GHashTable *delegate_invoke_cache;
113         GHashTable *delegate_begin_invoke_cache;
114         GHashTable *delegate_end_invoke_cache;
115         GHashTable *runtime_invoke_cache;
116         GHashTable *runtime_invoke_vtype_cache;
117         GHashTable *runtime_invoke_sig_cache;
118
119         /*
120          * indexed by SignaturePointerPair
121          */
122         GHashTable *delegate_abstract_invoke_cache;
123
124         /*
125          * indexed by MonoMethod pointers
126          * Protected by the marshal lock
127          */
128         GHashTable *runtime_invoke_direct_cache;
129         GHashTable *managed_wrapper_cache;
130
131         GHashTable *native_wrapper_cache;
132         GHashTable *native_wrapper_aot_cache;
133         GHashTable *native_wrapper_check_cache;
134         GHashTable *native_wrapper_aot_check_cache;
135
136         GHashTable *native_func_wrapper_aot_cache;
137         GHashTable *remoting_invoke_cache;
138         GHashTable *synchronized_cache;
139         GHashTable *unbox_wrapper_cache;
140         GHashTable *cominterop_invoke_cache;
141         GHashTable *cominterop_wrapper_cache; /* LOCKING: marshal lock */
142         GHashTable *thunk_invoke_cache;
143 } MonoWrapperCaches;
144
145 typedef struct {
146         const char* data;
147         guint32  size;
148 } MonoStreamHeader;
149
150 struct _MonoTableInfo {
151         const char *base;
152         guint       rows     : 24;
153         guint       row_size : 8;
154
155         /*
156          * Tables contain up to 9 columns and the possible sizes of the
157          * fields in the documentation are 1, 2 and 4 bytes.  So we
158          * can encode in 2 bits the size.
159          *
160          * A 32 bit value can encode the resulting size
161          *
162          * The top eight bits encode the number of columns in the table.
163          * we only need 4, but 8 is aligned no shift required. 
164          */
165         guint32   size_bitfield;
166 };
167
168 #define REFERENCE_MISSING ((gpointer) -1)
169
170 typedef struct _MonoDllMap MonoDllMap;
171
172 typedef struct {
173         gboolean (*match) (MonoImage*);
174         gboolean (*load_pe_data) (MonoImage*);
175         gboolean (*load_cli_data) (MonoImage*);
176         gboolean (*load_tables) (MonoImage*);
177 } MonoImageLoader;
178
179 struct _MonoImage {
180         /*
181          * This count is incremented during these situations:
182          *   - An assembly references this MonoImage though its 'image' field
183          *   - This MonoImage is present in the 'files' field of an image
184          *   - This MonoImage is present in the 'modules' field of an image
185          *   - A thread is holding a temporary reference to this MonoImage between
186          *     calls to mono_image_open and mono_image_close ()
187          */
188         int   ref_count;
189
190         /* If the raw data was allocated from a source such as mmap, the allocator may store resource tracking information here. */
191         void *raw_data_handle;
192         char *raw_data;
193         guint32 raw_data_len;
194         guint8 raw_buffer_used    : 1;
195         guint8 raw_data_allocated : 1;
196         guint8 fileio_used : 1;
197
198 #ifdef HOST_WIN32
199         /* Module was loaded using LoadLibrary. */
200         guint8 is_module_handle : 1;
201
202         /* Module entry point is _CorDllMain. */
203         guint8 has_entry_point : 1;
204 #endif
205
206         /* Whenever this is a dynamically emitted module */
207         guint8 dynamic : 1;
208
209         /* Whenever this is a reflection only image */
210         guint8 ref_only : 1;
211
212         /* Whenever this image contains uncompressed metadata */
213         guint8 uncompressed_metadata : 1;
214
215         /* Whenever this image contains metadata only without PE data */
216         guint8 metadata_only : 1;
217
218         /*  Whether this image belongs to load-from context */
219         guint8 load_from_context: 1;
220
221         guint8 checked_module_cctor : 1;
222         guint8 has_module_cctor : 1;
223
224         guint8 idx_string_wide : 1;
225         guint8 idx_guid_wide : 1;
226         guint8 idx_blob_wide : 1;
227
228         /* Whenever this image is considered as platform code for the CoreCLR security model */
229         guint8 core_clr_platform_code : 1;
230
231         /* The path to the file for this image. */
232         char *name;
233
234         /* The assembly name reported in the file for this image (expected to be NULL for a netmodule) */
235         const char *assembly_name;
236
237         /* The module name reported in the file for this image (could be NULL for a malformed file) */
238         const char *module_name;
239
240         char *version;
241         gint16 md_version_major, md_version_minor;
242         char *guid;
243         void *image_info;
244         MonoMemPool         *mempool; /*protected by the image lock*/
245
246         char                *raw_metadata;
247                             
248         MonoStreamHeader     heap_strings;
249         MonoStreamHeader     heap_us;
250         MonoStreamHeader     heap_blob;
251         MonoStreamHeader     heap_guid;
252         MonoStreamHeader     heap_tables;
253         MonoStreamHeader     heap_pdb;
254                             
255         const char          *tables_base;
256
257         /* For PPDB files */
258         guint64 referenced_tables;
259         int *referenced_table_rows;
260
261         /**/
262         MonoTableInfo        tables [MONO_TABLE_NUM];
263
264         /*
265          * references is initialized only by using the mono_assembly_open
266          * function, and not by using the lowlevel mono_image_open.
267          *
268          * It is NULL terminated.
269          */
270         MonoAssembly **references;
271         int nreferences;
272
273         /* Code files in the assembly. The main assembly has a "file" table and also a "module"
274          * table, where the module table is a subset of the file table. We track both lists,
275          * and because we can lazy-load them at different times we reference-increment both.
276          */
277         MonoImage **modules;
278         guint32 module_count;
279         gboolean *modules_loaded;
280
281         MonoImage **files;
282         guint32 file_count;
283
284         gpointer aot_module;
285
286         guint8 aotid[16];
287
288         /*
289          * The Assembly this image was loaded from.
290          */
291         MonoAssembly *assembly;
292
293         /*
294          * Indexed by method tokens and typedef tokens.
295          */
296         GHashTable *method_cache; /*protected by the image lock*/
297         MonoInternalHashTable class_cache;
298
299         /* Indexed by memberref + methodspec tokens */
300         GHashTable *methodref_cache; /*protected by the image lock*/
301
302         /*
303          * Indexed by fielddef and memberref tokens
304          */
305         MonoConcurrentHashTable *field_cache; /*protected by the image lock*/
306
307         /* indexed by typespec tokens. */
308         GHashTable *typespec_cache; /* protected by the image lock */
309         /* indexed by token */
310         GHashTable *memberref_signatures;
311         GHashTable *helper_signatures;
312
313         /* Indexed by blob heap indexes */
314         GHashTable *method_signatures;
315
316         /*
317          * Indexes namespaces to hash tables that map class name to typedef token.
318          */
319         GHashTable *name_cache;  /*protected by the image lock*/
320
321         /*
322          * Indexed by MonoClass
323          */
324         GHashTable *array_cache;
325         GHashTable *ptr_cache;
326
327         GHashTable *szarray_cache;
328         /* This has a separate lock to improve scalability */
329         mono_mutex_t szarray_cache_lock;
330
331         /*
332          * indexed by SignaturePointerPair
333          */
334         GHashTable *delegate_bound_static_invoke_cache;
335         GHashTable *native_func_wrapper_cache;
336
337         /*
338          * indexed by MonoMethod pointers 
339          */
340         GHashTable *runtime_invoke_vcall_cache;
341         GHashTable *wrapper_param_names;
342         GHashTable *array_accessor_cache;
343
344         /*
345          * indexed by MonoClass pointers
346          */
347         GHashTable *ldfld_wrapper_cache;
348         GHashTable *ldflda_wrapper_cache;
349         GHashTable *stfld_wrapper_cache;
350         GHashTable *isinst_cache;
351
352         GHashTable *icall_wrapper_cache;
353         GHashTable *castclass_cache;
354         GHashTable *proxy_isinst_cache;
355         GHashTable *rgctx_template_hash; /* LOCKING: templates lock */
356
357         /* Contains rarely used fields of runtime structures belonging to this image */
358         MonoPropertyHash *property_hash;
359
360         void *reflection_info;
361
362         /*
363          * user_info is a public field and is not touched by the
364          * metadata engine
365          */
366         void *user_info;
367
368         /* dll map entries */
369         MonoDllMap *dll_map;
370
371         /* interfaces IDs from this image */
372         /* protected by the classes lock */
373         MonoBitSet *interface_bitset;
374
375         /* when the image is being closed, this is abused as a list of
376            malloc'ed regions to be freed. */
377         GSList *reflection_info_unregister_classes;
378
379         /* List of dependent image sets containing this image */
380         /* Protected by image_sets_lock */
381         GSList *image_sets;
382
383         /* Caches for wrappers that DO NOT reference generic */
384         /* arguments */
385         MonoWrapperCaches wrapper_caches;
386
387         /* Caches for MonoClass-es representing anon generic params */
388         MonoClass **var_cache_fast;
389         MonoClass **mvar_cache_fast;
390         GHashTable *var_cache_slow;
391         GHashTable *mvar_cache_slow;
392         GHashTable *var_cache_constrained;
393         GHashTable *mvar_cache_constrained;
394
395         /* Maps malloc-ed char* pinvoke scope -> MonoDl* */
396         GHashTable *pinvoke_scopes;
397
398         /* Maps malloc-ed char* pinvoke scope -> malloced-ed char* filename */
399         GHashTable *pinvoke_scope_filenames;
400
401         /* Indexed by MonoGenericParam pointers */
402         GHashTable **gshared_types;
403         /* The length of the above array */
404         int gshared_types_len;
405
406         /* The loader used to load this image */
407         MonoImageLoader *loader;
408
409         // Containers for MonoGenericParams associated with this image but not with any specific class or method. Created on demand.
410         // This could happen, for example, for MonoTypes associated with TypeSpec table entries.
411         MonoGenericContainer *anonymous_generic_class_container;
412         MonoGenericContainer *anonymous_generic_method_container;
413
414         /*
415          * No other runtime locks must be taken while holding this lock.
416          * It's meant to be used only to mutate and query structures part of this image.
417          */
418         mono_mutex_t    lock;
419 };
420
421 /*
422  * Generic instances depend on many images, and they need to be deleted if one
423  * of the images they depend on is unloaded. For example,
424  * List<Foo> depends on both List's image and Foo's image.
425  * A MonoImageSet is the owner of all generic instances depending on the same set of
426  * images.
427  */
428 typedef struct {
429         int nimages;
430         MonoImage **images;
431
432         // Generic-specific caches
433         GHashTable *gclass_cache, *ginst_cache, *gmethod_cache, *gsignature_cache;
434
435         MonoWrapperCaches wrapper_caches;
436
437         mono_mutex_t    lock;
438
439         /*
440          * Memory for generic instances owned by this image set should be allocated from
441          * this mempool, using the mono_image_set_alloc family of functions.
442          */
443         MonoMemPool         *mempool;
444 } MonoImageSet;
445
446 enum {
447         MONO_SECTION_TEXT,
448         MONO_SECTION_RSRC,
449         MONO_SECTION_RELOC,
450         MONO_SECTION_MAX
451 };
452
453 typedef struct {
454         GHashTable *hash;
455         char *data;
456         guint32 alloc_size; /* malloced bytes */
457         guint32 index;
458         guint32 offset; /* from start of metadata */
459 } MonoDynamicStream;
460
461 typedef struct {
462         guint32 alloc_rows;
463         guint32 rows;
464         guint8  row_size; /*  calculated later with column_sizes */
465         guint8  columns;
466         guint32 next_idx;
467         guint32 *values; /* rows * columns */
468 } MonoDynamicTable;
469
470 /* "Dynamic" assemblies and images arise from System.Reflection.Emit */
471 struct _MonoDynamicAssembly {
472         MonoAssembly assembly;
473         char *strong_name;
474         guint32 strong_name_size;
475         guint8 run;
476         guint8 save;
477         MonoDomain *domain;
478 };
479
480 struct _MonoDynamicImage {
481         MonoImage image;
482         guint32 meta_size;
483         guint32 text_rva;
484         guint32 metadata_rva;
485         guint32 image_base;
486         guint32 cli_header_offset;
487         guint32 iat_offset;
488         guint32 idt_offset;
489         guint32 ilt_offset;
490         guint32 imp_names_offset;
491         struct {
492                 guint32 rva;
493                 guint32 size;
494                 guint32 offset;
495                 guint32 attrs;
496         } sections [MONO_SECTION_MAX];
497         GHashTable *typespec;
498         GHashTable *typeref;
499         GHashTable *handleref;
500         MonoGHashTable *handleref_managed;
501         MonoGHashTable *tokens;
502         GHashTable *blob_cache;
503         GHashTable *standalonesig_cache;
504         GList *array_methods;
505         GPtrArray *gen_params;
506         MonoGHashTable *token_fixups;
507         GHashTable *method_to_table_idx;
508         GHashTable *field_to_table_idx;
509         GHashTable *method_aux_hash;
510         GHashTable *vararg_aux_hash;
511         MonoGHashTable *generic_def_objects;
512         /*
513          * Maps final token values to the object they describe.
514          */
515         MonoGHashTable *remapped_tokens;
516         gboolean run;
517         gboolean save;
518         gboolean initial_image;
519         guint32 pe_kind, machine;
520         char *strong_name;
521         guint32 strong_name_size;
522         char *win32_res;
523         guint32 win32_res_size;
524         guint8 *public_key;
525         int public_key_len;
526         MonoDynamicStream sheap;
527         MonoDynamicStream code; /* used to store method headers and bytecode */
528         MonoDynamicStream resources; /* managed embedded resources */
529         MonoDynamicStream us;
530         MonoDynamicStream blob;
531         MonoDynamicStream tstream;
532         MonoDynamicStream guid;
533         MonoDynamicTable tables [MONO_TABLE_NUM];
534         MonoClass *wrappers_type; /*wrappers are bound to this type instead of <Module>*/
535 };
536
537 /* Contains information about assembly binding */
538 typedef struct _MonoAssemblyBindingInfo {
539         char *name;
540         char *culture;
541         guchar public_key_token [MONO_PUBLIC_KEY_TOKEN_LENGTH];
542         int major;
543         int minor;
544         AssemblyVersionSet old_version_bottom;
545         AssemblyVersionSet old_version_top;
546         AssemblyVersionSet new_version;
547         guint has_old_version_bottom : 1;
548         guint has_old_version_top : 1;
549         guint has_new_version : 1;
550         guint is_valid : 1;
551         gint32 domain_id; /*Needed to unload per-domain binding*/
552 } MonoAssemblyBindingInfo;
553
554 struct _MonoMethodHeader {
555         const unsigned char  *code;
556 #ifdef MONO_SMALL_CONFIG
557         guint16      code_size;
558 #else
559         guint32      code_size;
560 #endif
561         guint16      max_stack   : 15;
562         unsigned int is_transient: 1; /* mono_metadata_free_mh () will actually free this header */
563         unsigned int num_clauses : 15;
564         /* if num_locals != 0, then the following apply: */
565         unsigned int init_locals : 1;
566         guint16      num_locals;
567         MonoExceptionClause *clauses;
568         MonoType    *locals [MONO_ZERO_LEN_ARRAY];
569 };
570
571 typedef struct {
572         guint32      code_size;
573         gboolean     has_clauses;
574 } MonoMethodHeaderSummary;
575
576 #define MONO_SIZEOF_METHOD_HEADER (sizeof (struct _MonoMethodHeader) - MONO_ZERO_LEN_ARRAY * SIZEOF_VOID_P)
577
578 struct _MonoMethodSignature {
579         MonoType     *ret;
580 #ifdef MONO_SMALL_CONFIG
581         guint8        param_count;
582         gint8         sentinelpos;
583         unsigned int  generic_param_count : 5;
584 #else
585         guint16       param_count;
586         gint16        sentinelpos;
587         unsigned int  generic_param_count : 16;
588 #endif
589         unsigned int  call_convention     : 6;
590         unsigned int  hasthis             : 1;
591         unsigned int  explicit_this       : 1;
592         unsigned int  pinvoke             : 1;
593         unsigned int  is_inflated         : 1;
594         unsigned int  has_type_parameters : 1;
595         MonoType     *params [MONO_ZERO_LEN_ARRAY];
596 };
597
598 /*
599  * AOT cache configuration loaded from config files.
600  * Doesn't really belong here.
601  */
602 typedef struct {
603         /*
604          * Enable aot caching for applications whose main assemblies are in
605          * this list.
606          */
607         GSList *apps;
608         GSList *assemblies;
609         char *aot_options;
610 } MonoAotCacheConfig;
611
612 #define MONO_SIZEOF_METHOD_SIGNATURE (sizeof (struct _MonoMethodSignature) - MONO_ZERO_LEN_ARRAY * SIZEOF_VOID_P)
613
614 static inline gboolean
615 image_is_dynamic (MonoImage *image)
616 {
617 #ifdef DISABLE_REFLECTION_EMIT
618         return FALSE;
619 #else
620         return image->dynamic;
621 #endif
622 }
623
624 static inline gboolean
625 assembly_is_dynamic (MonoAssembly *assembly)
626 {
627 #ifdef DISABLE_REFLECTION_EMIT
628         return FALSE;
629 #else
630         return assembly->dynamic;
631 #endif
632 }
633
634 /* for use with allocated memory blocks (assumes alignment is to 8 bytes) */
635 guint mono_aligned_addr_hash (gconstpointer ptr);
636
637 void
638 mono_image_check_for_module_cctor (MonoImage *image);
639
640 gpointer
641 mono_image_alloc  (MonoImage *image, guint size);
642
643 gpointer
644 mono_image_alloc0 (MonoImage *image, guint size);
645
646 #define mono_image_new0(image,type,size) ((type *) mono_image_alloc0 (image, sizeof (type)* (size)))
647
648 char*
649 mono_image_strdup (MonoImage *image, const char *s);
650
651 char*
652 mono_image_strdup_vprintf (MonoImage *image, const char *format, va_list args);
653
654 char*
655 mono_image_strdup_printf (MonoImage *image, const char *format, ...) MONO_ATTR_FORMAT_PRINTF(2,3);;
656
657 GList*
658 g_list_prepend_image (MonoImage *image, GList *list, gpointer data);
659
660 GSList*
661 g_slist_append_image (MonoImage *image, GSList *list, gpointer data);
662
663 void
664 mono_image_lock (MonoImage *image);
665
666 void
667 mono_image_unlock (MonoImage *image);
668
669 gpointer
670 mono_image_property_lookup (MonoImage *image, gpointer subject, guint32 property);
671
672 void
673 mono_image_property_insert (MonoImage *image, gpointer subject, guint32 property, gpointer value);
674
675 void
676 mono_image_property_remove (MonoImage *image, gpointer subject);
677
678 gboolean
679 mono_image_close_except_pools (MonoImage *image);
680
681 void
682 mono_image_close_finish (MonoImage *image);
683
684 typedef void  (*MonoImageUnloadFunc) (MonoImage *image, gpointer user_data);
685
686 void
687 mono_install_image_unload_hook (MonoImageUnloadFunc func, gpointer user_data);
688
689 void
690 mono_remove_image_unload_hook (MonoImageUnloadFunc func, gpointer user_data);
691
692 void
693 mono_install_image_loader (const MonoImageLoader *loader);
694
695 void
696 mono_image_append_class_to_reflection_info_set (MonoClass *klass);
697
698 gpointer
699 mono_image_set_alloc  (MonoImageSet *set, guint size);
700
701 gpointer
702 mono_image_set_alloc0 (MonoImageSet *set, guint size);
703
704 void
705 mono_image_set_lock (MonoImageSet *set);
706
707 void
708 mono_image_set_unlock (MonoImageSet *set);
709
710 char*
711 mono_image_set_strdup (MonoImageSet *set, const char *s);
712
713 #define mono_image_set_new0(image,type,size) ((type *) mono_image_set_alloc0 (image, sizeof (type)* (size)))
714
715 gboolean
716 mono_image_load_cli_header (MonoImage *image, MonoCLIImageInfo *iinfo);
717
718 gboolean
719 mono_image_load_metadata (MonoImage *image, MonoCLIImageInfo *iinfo);
720
721 MonoType*
722 mono_metadata_get_shared_type (MonoType *type);
723
724 void
725 mono_metadata_clean_for_image (MonoImage *image);
726
727 void
728 mono_metadata_clean_generic_classes_for_image (MonoImage *image);
729
730 MONO_API void
731 mono_metadata_cleanup (void);
732
733 const char *   mono_meta_table_name              (int table);
734 void           mono_metadata_compute_table_bases (MonoImage *meta);
735
736 gboolean
737 mono_metadata_interfaces_from_typedef_full  (MonoImage             *image,
738                                                                                          guint32                table_index,
739                                                                                          MonoClass           ***interfaces,
740                                                                                          guint                 *count,
741                                                                                          gboolean               heap_alloc_result,
742                                                                                          MonoGenericContext    *context,
743                                                                                          MonoError *error);
744
745 MONO_API MonoMethodSignature *
746 mono_metadata_parse_method_signature_full   (MonoImage             *image,
747                                              MonoGenericContainer  *generic_container,
748                                              int                     def,
749                                              const char             *ptr,
750                                              const char            **rptr,
751                                              MonoError *error);
752
753 MONO_API MonoMethodHeader *
754 mono_metadata_parse_mh_full                 (MonoImage             *image,
755                                              MonoGenericContainer  *container,
756                                              const char            *ptr,
757                                                  MonoError *error);
758
759 MonoMethodSignature  *mono_metadata_parse_signature_checked (MonoImage *image, 
760                                                              uint32_t    token,
761                                                              MonoError *error);
762
763 gboolean
764 mono_method_get_header_summary (MonoMethod *method, MonoMethodHeaderSummary *summary);
765
766 int* mono_metadata_get_param_attrs          (MonoImage *m, int def, int param_count);
767 gboolean mono_metadata_method_has_param_attrs (MonoImage *m, int def);
768
769 guint
770 mono_metadata_generic_context_hash          (const MonoGenericContext *context);
771
772 gboolean
773 mono_metadata_generic_context_equal         (const MonoGenericContext *g1,
774                                              const MonoGenericContext *g2);
775
776 MonoGenericInst *
777 mono_metadata_parse_generic_inst            (MonoImage             *image,
778                                              MonoGenericContainer  *container,
779                                              int                    count,
780                                              const char            *ptr,
781                                              const char           **rptr,
782                                                  MonoError *error);
783
784 MonoGenericInst *
785 mono_metadata_get_generic_inst              (int                    type_argc,
786                                              MonoType             **type_argv);
787
788 MonoGenericInst *
789 mono_metadata_get_canonical_generic_inst    (MonoGenericInst *candidate);
790
791 MonoGenericClass *
792 mono_metadata_lookup_generic_class          (MonoClass             *gclass,
793                                              MonoGenericInst       *inst,
794                                              gboolean               is_dynamic);
795
796 MonoGenericInst * mono_metadata_inflate_generic_inst  (MonoGenericInst *ginst, MonoGenericContext *context, MonoError *error);
797
798 guint
799 mono_metadata_generic_param_hash (MonoGenericParam *p);
800
801 gboolean
802 mono_metadata_generic_param_equal (MonoGenericParam *p1, MonoGenericParam *p2);
803
804 void mono_dynamic_stream_reset  (MonoDynamicStream* stream);
805 MONO_API void mono_assembly_addref       (MonoAssembly *assembly);
806 void mono_assembly_load_friends (MonoAssembly* ass);
807 gboolean mono_assembly_has_skip_verification (MonoAssembly* ass);
808
809 void mono_assembly_release_gc_roots (MonoAssembly *assembly);
810 gboolean mono_assembly_close_except_image_pools (MonoAssembly *assembly);
811 void mono_assembly_close_finish (MonoAssembly *assembly);
812
813
814 gboolean mono_public_tokens_are_equal (const unsigned char *pubt1, const unsigned char *pubt2);
815
816 void mono_config_parse_publisher_policy (const char *filename, MonoAssemblyBindingInfo *binding_info);
817 void mono_config_parse_assembly_bindings (const char *filename, int major, int minor, void *user_data,
818                                           void (*infocb)(MonoAssemblyBindingInfo *info, void *user_data));
819
820 gboolean
821 mono_assembly_name_parse_full                (const char           *name,
822                                               MonoAssemblyName     *aname,
823                                               gboolean save_public_key,
824                                               gboolean *is_version_defined,
825                                                   gboolean *is_token_defined);
826
827 gboolean
828 mono_assembly_fill_assembly_name_full (MonoImage *image, MonoAssemblyName *aname, gboolean copyBlobs);
829
830
831 MONO_API guint32 mono_metadata_get_generic_param_row (MonoImage *image, guint32 token, guint32 *owner);
832
833 void mono_unload_interface_ids (MonoBitSet *bitset);
834
835
836 MonoType *mono_metadata_type_dup (MonoImage *image, const MonoType *original);
837 MonoMethodSignature  *mono_metadata_signature_dup_full (MonoImage *image,MonoMethodSignature *sig);
838 MonoMethodSignature  *mono_metadata_signature_dup_mempool (MonoMemPool *mp, MonoMethodSignature *sig);
839 MonoMethodSignature  *mono_metadata_signature_dup_add_this (MonoImage *image, MonoMethodSignature *sig, MonoClass *klass);
840
841 MonoGenericInst *
842 mono_get_shared_generic_inst (MonoGenericContainer *container);
843
844 int
845 mono_type_stack_size_internal (MonoType *t, int *align, gboolean allow_open);
846
847 MONO_API void            mono_type_get_desc (GString *res, MonoType *type, mono_bool include_namespace);
848
849 gboolean
850 mono_metadata_type_equal_full (MonoType *t1, MonoType *t2, gboolean signature_only);
851
852 MonoMarshalSpec *
853 mono_metadata_parse_marshal_spec_full (MonoImage *image, MonoImage *parent_image, const char *ptr);
854
855 guint          mono_metadata_generic_inst_hash (gconstpointer data);
856 gboolean       mono_metadata_generic_inst_equal (gconstpointer ka, gconstpointer kb);
857
858 MONO_API void
859 mono_metadata_field_info_with_mempool (
860                                           MonoImage *meta, 
861                                       guint32       table_index,
862                                       guint32      *offset,
863                                       guint32      *rva,
864                                       MonoMarshalSpec **marshal_spec);
865
866 MonoClassField*
867 mono_metadata_get_corresponding_field_from_generic_type_definition (MonoClassField *field);
868
869 MonoEvent*
870 mono_metadata_get_corresponding_event_from_generic_type_definition (MonoEvent *event);
871
872 MonoProperty*
873 mono_metadata_get_corresponding_property_from_generic_type_definition (MonoProperty *property);
874
875 guint32
876 mono_metadata_signature_size (MonoMethodSignature *sig);
877
878 guint mono_metadata_str_hash (gconstpointer v1);
879
880 gboolean mono_image_load_pe_data (MonoImage *image);
881
882 gboolean mono_image_load_cli_data (MonoImage *image);
883
884 void mono_image_load_names (MonoImage *image);
885
886 MonoImage *mono_image_open_raw (const char *fname, MonoImageOpenStatus *status);
887
888 MonoImage *mono_image_open_metadata_only (const char *fname, MonoImageOpenStatus *status);
889
890 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);
891
892 MonoException *mono_get_exception_field_access_msg (const char *msg);
893
894 MonoException *mono_get_exception_method_access_msg (const char *msg);
895
896 MonoMethod* method_from_method_def_or_ref (MonoImage *m, guint32 tok, MonoGenericContext *context, MonoError *error);
897
898 MonoMethod *mono_get_method_constrained_with_method (MonoImage *image, MonoMethod *method, MonoClass *constrained_class, MonoGenericContext *context, MonoError *error);
899 MonoMethod *mono_get_method_constrained_checked (MonoImage *image, guint32 token, MonoClass *constrained_class, MonoGenericContext *context, MonoMethod **cil_method, MonoError *error);
900
901 void mono_type_set_alignment (MonoTypeEnum type, int align);
902
903 MonoAotCacheConfig *mono_get_aot_cache_config (void);
904 MonoType *
905 mono_type_create_from_typespec_checked (MonoImage *image, guint32 type_spec, MonoError *error);
906
907 MonoMethodSignature*
908 mono_method_get_signature_checked (MonoMethod *method, MonoImage *image, guint32 token, MonoGenericContext *context, MonoError *error);
909         
910 MonoMethod *
911 mono_get_method_checked (MonoImage *image, guint32 token, MonoClass *klass, MonoGenericContext *context, MonoError *error);
912
913 guint32
914 mono_metadata_localscope_from_methoddef (MonoImage *meta, guint32 index);
915
916 void
917 mono_wrapper_caches_free (MonoWrapperCaches *cache);
918
919 MonoWrapperCaches*
920 mono_method_get_wrapper_cache (MonoMethod *method);
921
922 MonoWrapperCaches*
923 mono_method_get_wrapper_cache (MonoMethod *method);
924
925 MonoType*
926 mono_metadata_parse_type_checked (MonoImage *m, MonoGenericContainer *container, short opt_attrs, gboolean transient, const char *ptr, const char **rptr, MonoError *error);
927
928 MonoGenericContainer *
929 get_anonymous_container_for_image (MonoImage *image, gboolean is_mvar);
930
931 char *
932 mono_image_set_description (MonoImageSet *);
933
934 MonoImageSet *
935 mono_find_image_set_owner (void *ptr);
936
937 void
938 mono_loader_register_module (const char *name, MonoDl *module);
939
940 gboolean
941 mono_assembly_is_problematic_version (const char *name, guint16 major, guint16 minor, guint16 build, guint16 revision);
942
943 void
944 mono_ginst_get_desc (GString *str, MonoGenericInst *ginst);
945
946 #endif /* __MONO_METADATA_INTERNALS_H__ */
947