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