2 #ifndef __MONO_METADATA_INTERNALS_H__
3 #define __MONO_METADATA_INTERNALS_H__
5 #include "mono/metadata/image.h"
6 #include "mono/metadata/blob.h"
7 #include "mono/metadata/mempool.h"
8 #include "mono/metadata/domain-internals.h"
9 #include "mono/utils/mono-hash.h"
10 #include "mono/utils/mono-compiler.h"
11 #include "mono/utils/mono-dl.h"
12 #include "mono/utils/monobitset.h"
13 #include "mono/utils/mono-property-hash.h"
14 #include "mono/utils/mono-value-hash.h"
16 #define MONO_SECMAN_FLAG_INIT(x) (x & 0x2)
17 #define MONO_SECMAN_FLAG_GET_VALUE(x) (x & 0x1)
18 #define MONO_SECMAN_FLAG_SET_VALUE(x,y) do { x = ((y) ? 0x3 : 0x2); } while (0)
20 struct _MonoAssembly {
22 * The number of appdomains which have this assembly loaded plus the number of
23 * assemblies referencing this assembly through an entry in their image->references
24 * arrays. The later is needed because entries in the image->references array
25 * might point to assemblies which are only loaded in some appdomains, and without
26 * the additional reference, they can be freed at any time.
27 * The ref_count is initially 0.
29 int ref_count; /* use atomic operations only */
31 MonoAssemblyName aname;
33 GSList *friend_assembly_names; /* Computed by mono_assembly_load_friends () */
34 guint8 friend_assembly_names_inited;
37 guint8 corlib_internal;
39 /* security manager flags (one bit is for lazy initialization) */
40 guint32 ecma:2; /* Has the ECMA key */
41 guint32 aptc:2; /* Has the [AllowPartiallyTrustedCallers] attributes */
42 guint32 fulltrust:2; /* Has FullTrust permission */
43 guint32 unmanaged:2; /* Has SecurityPermissionFlag.UnmanagedCode permission */
44 guint32 skipverification:2; /* Has SecurityPermissionFlag.SkipVerification permission */
52 struct _MonoTableInfo {
58 * Tables contain up to 9 columns and the possible sizes of the
59 * fields in the documentation are 1, 2 and 4 bytes. So we
60 * can encode in 2 bits the size.
62 * A 32 bit value can encode the resulting size
64 * The top eight bits encode the number of columns in the table.
65 * we only need 4, but 8 is aligned no shift required.
67 guint32 size_bitfield;
70 #define REFERENCE_MISSING ((gpointer) -1)
72 typedef struct _MonoDllMap MonoDllMap;
76 * The number of assemblies which reference this MonoImage though their 'image'
77 * field plus the number of images which reference this MonoImage through their
78 * 'modules' field, plus the number of threads holding temporary references to
79 * this image between calls of mono_image_open () and mono_image_close ().
82 void *raw_data_handle;
85 guint8 raw_buffer_used : 1;
86 guint8 raw_data_allocated : 1;
89 /* Module was loaded using LoadLibrary. */
90 guint8 is_module_handle : 1;
92 /* Module entry point is _CorDllMain. */
93 guint8 has_entry_point : 1;
96 /* Whenever this is a dynamically emitted module */
99 /* Whenever this is a reflection only image */
102 /* Whenever this image contains uncompressed metadata */
103 guint8 uncompressed_metadata : 1;
105 guint8 checked_module_cctor : 1;
106 guint8 has_module_cctor : 1;
108 guint8 idx_string_wide : 1;
109 guint8 idx_guid_wide : 1;
110 guint8 idx_blob_wide : 1;
113 const char *assembly_name;
114 const char *module_name;
116 gint16 md_version_major, md_version_minor;
119 MonoMemPool *mempool; /*protected by the image lock*/
123 MonoStreamHeader heap_strings;
124 MonoStreamHeader heap_us;
125 MonoStreamHeader heap_blob;
126 MonoStreamHeader heap_guid;
127 MonoStreamHeader heap_tables;
129 const char *tables_base;
132 MonoTableInfo tables [MONO_TABLE_NUM];
135 * references is initialized only by using the mono_assembly_open
136 * function, and not by using the lowlevel mono_image_open.
138 * It is NULL terminated.
140 MonoAssembly **references;
143 guint32 module_count;
144 gboolean *modules_loaded;
151 * The Assembly this image was loaded from.
153 MonoAssembly *assembly;
156 * Indexed by method tokens and typedef tokens.
158 MonoValueHashTable *method_cache; /*protected by the image lock*/
159 MonoInternalHashTable class_cache;
161 /* Indexed by memberref + methodspec tokens */
162 GHashTable *methodref_cache; /*protected by the image lock*/
165 * Indexed by fielddef and memberref tokens
167 GHashTable *field_cache;
169 /* indexed by typespec tokens. */
170 GHashTable *typespec_cache;
171 /* indexed by token */
172 GHashTable *memberref_signatures;
173 GHashTable *helper_signatures;
175 /* Indexed by blob heap indexes */
176 GHashTable *method_signatures;
179 * Indexes namespaces to hash tables that map class name to typedef token.
181 GHashTable *name_cache;
184 * Indexed by MonoClass
186 GHashTable *array_cache;
187 GHashTable *ptr_cache;
190 * indexed by MonoMethodSignature
192 GHashTable *delegate_begin_invoke_cache;
193 GHashTable *delegate_end_invoke_cache;
194 GHashTable *delegate_invoke_cache;
195 GHashTable *runtime_invoke_cache;
198 * indexed by SignatureMethodPair
200 GHashTable *delegate_abstract_invoke_cache;
203 * indexed by MonoMethod pointers
205 GHashTable *runtime_invoke_direct_cache;
206 GHashTable *managed_wrapper_cache;
207 GHashTable *native_wrapper_cache;
208 GHashTable *native_wrapper_aot_cache;
209 GHashTable *remoting_invoke_cache;
210 GHashTable *synchronized_cache;
211 GHashTable *unbox_wrapper_cache;
212 GHashTable *cominterop_invoke_cache;
213 GHashTable *cominterop_wrapper_cache;
214 GHashTable *static_rgctx_invoke_cache; /* LOCKING: marshal lock */
215 GHashTable *thunk_invoke_cache;
218 * indexed by MonoClass pointers
220 GHashTable *ldfld_wrapper_cache;
221 GHashTable *ldflda_wrapper_cache;
222 GHashTable *stfld_wrapper_cache;
223 GHashTable *isinst_cache;
224 GHashTable *castclass_cache;
225 GHashTable *proxy_isinst_cache;
226 GHashTable *rgctx_template_hash; /* LOCKING: templates lock */
229 * indexed by token and MonoGenericContext pointer
231 GHashTable *generic_class_cache;
233 /* Contains rarely used fields of runtime structures belonging to this image */
234 MonoPropertyHash *property_hash;
236 void *reflection_info;
239 * user_info is a public field and is not touched by the
244 /* dll map entries */
247 /* interfaces IDs from this image */
248 MonoBitSet *interface_bitset;
251 * No other runtime locks must be taken while holding this lock.
252 * It's meant to be used only to mutate and query structures part of this image.
254 CRITICAL_SECTION lock;
267 guint32 alloc_size; /* malloced bytes */
269 guint32 offset; /* from start of metadata */
275 guint8 row_size; /* calculated later with column_sizes */
278 guint32 *values; /* rows * columns */
281 struct _MonoDynamicAssembly {
282 MonoAssembly assembly;
284 guint32 strong_name_size;
289 struct _MonoDynamicImage {
293 guint32 metadata_rva;
295 guint32 cli_header_offset;
299 guint32 imp_names_offset;
305 } sections [MONO_SECTION_MAX];
306 GHashTable *typespec;
308 GHashTable *handleref;
309 MonoGHashTable *tokens;
310 GHashTable *blob_cache;
311 GHashTable *standalonesig_cache;
312 GList *array_methods;
313 GPtrArray *gen_params;
314 MonoGHashTable *token_fixups;
315 GHashTable *method_to_table_idx;
316 GHashTable *field_to_table_idx;
317 GHashTable *method_aux_hash;
318 MonoGHashTable *generic_def_objects;
319 MonoGHashTable *methodspec;
322 gboolean initial_image;
323 guint32 pe_kind, machine;
325 guint32 strong_name_size;
327 guint32 win32_res_size;
330 MonoDynamicStream sheap;
331 MonoDynamicStream code; /* used to store method headers and bytecode */
332 MonoDynamicStream resources; /* managed embedded resources */
333 MonoDynamicStream us;
334 MonoDynamicStream blob;
335 MonoDynamicStream tstream;
336 MonoDynamicStream guid;
337 MonoDynamicTable tables [MONO_TABLE_NUM];
340 /* Contains information about assembly binding */
341 typedef struct _MonoAssemblyBindingInfo {
344 guchar public_key_token [MONO_PUBLIC_KEY_TOKEN_LENGTH];
347 AssemblyVersionSet old_version_bottom;
348 AssemblyVersionSet old_version_top;
349 AssemblyVersionSet new_version;
350 guint has_old_version_bottom : 1;
351 guint has_old_version_top : 1;
352 guint has_new_version : 1;
354 } MonoAssemblyBindingInfo;
356 struct _MonoMethodHeader {
358 const unsigned char *code;
360 unsigned int num_clauses : 15;
361 /* if num_locals != 0, then the following apply: */
362 unsigned int init_locals : 1;
364 MonoExceptionClause *clauses;
365 MonoType *locals [MONO_ZERO_LEN_ARRAY];
368 /* for use with allocated memory blocks (assumes alignment is to 8 bytes) */
369 guint mono_aligned_addr_hash (gconstpointer ptr) MONO_INTERNAL;
372 mono_image_check_for_module_cctor (MonoImage *image) MONO_INTERNAL;
375 mono_image_alloc (MonoImage *image, guint size) MONO_INTERNAL;
378 mono_image_alloc0 (MonoImage *image, guint size) MONO_INTERNAL;
381 mono_image_strdup (MonoImage *image, const char *s) MONO_INTERNAL;
384 g_list_prepend_image (MonoImage *image, GList *list, gpointer data) MONO_INTERNAL;
387 g_slist_append_image (MonoImage *image, GSList *list, gpointer data) MONO_INTERNAL;
390 mono_image_lock (MonoImage *image) MONO_INTERNAL;
393 mono_image_unlock (MonoImage *image) MONO_INTERNAL;
396 mono_image_property_lookup (MonoImage *image, gpointer subject, guint32 property) MONO_INTERNAL;
399 mono_image_property_insert (MonoImage *image, gpointer subject, guint32 property, gpointer value) MONO_INTERNAL;
402 mono_image_property_remove (MonoImage *image, gpointer subject) MONO_INTERNAL;
406 mono_metadata_get_shared_type (MonoType *type) MONO_INTERNAL;
409 mono_metadata_clean_for_image (MonoImage *image) MONO_INTERNAL;
412 mono_metadata_cleanup (void);
414 const char * mono_meta_table_name (int table) MONO_INTERNAL;
415 void mono_metadata_compute_table_bases (MonoImage *meta) MONO_INTERNAL;
418 mono_metadata_interfaces_from_typedef_full (MonoImage *image,
420 MonoClass ***interfaces,
422 MonoGenericContext *context) MONO_INTERNAL;
425 mono_metadata_parse_array_full (MonoImage *image,
426 MonoGenericContainer *container,
428 const char **rptr) MONO_INTERNAL;
431 mono_metadata_parse_type_full (MonoImage *image,
432 MonoGenericContainer *container,
433 MonoParseTypeMode mode,
438 MonoMethodSignature *
439 mono_metadata_parse_signature_full (MonoImage *image,
440 MonoGenericContainer *generic_container,
441 guint32 token) MONO_INTERNAL;
443 MonoMethodSignature *
444 mono_metadata_parse_method_signature_full (MonoImage *image,
445 MonoGenericContainer *generic_container,
451 mono_metadata_parse_mh_full (MonoImage *image,
452 MonoGenericContainer *container,
455 int* mono_metadata_get_param_attrs (MonoImage *m, int def);
458 mono_metadata_generic_context_hash (const MonoGenericContext *context) MONO_INTERNAL;
461 mono_metadata_generic_context_equal (const MonoGenericContext *g1,
462 const MonoGenericContext *g2) MONO_INTERNAL;
465 mono_metadata_parse_generic_inst (MonoImage *image,
466 MonoGenericContainer *container,
469 const char **rptr) MONO_INTERNAL;
472 mono_metadata_get_generic_inst (int type_argc,
473 MonoType **type_argv) MONO_INTERNAL;
476 mono_metadata_lookup_generic_class (MonoClass *gclass,
477 MonoGenericInst *inst,
478 gboolean is_dynamic) MONO_INTERNAL;
481 mono_metadata_inflate_generic_inst (MonoGenericInst *ginst,
482 MonoGenericContext *context) MONO_INTERNAL;
484 void mono_dynamic_stream_reset (MonoDynamicStream* stream) MONO_INTERNAL;
485 void mono_assembly_addref (MonoAssembly *assembly) MONO_INTERNAL;
486 void mono_assembly_load_friends (MonoAssembly* ass) MONO_INTERNAL;
487 gboolean mono_assembly_has_skip_verification (MonoAssembly* ass) MONO_INTERNAL;
489 gboolean mono_public_tokens_are_equal (const unsigned char *pubt1, const unsigned char *pubt2) MONO_INTERNAL;
491 void mono_config_parse_publisher_policy (const char *filename, MonoAssemblyBindingInfo *binding_info) MONO_INTERNAL;
494 mono_assembly_name_parse_full (const char *name,
495 MonoAssemblyName *aname,
496 gboolean save_public_key,
497 gboolean *is_version_defined,
498 gboolean *is_token_defined) MONO_INTERNAL;
500 guint32 mono_metadata_get_generic_param_row (MonoImage *image, guint32 token, guint32 *owner);
502 void mono_unload_interface_ids (MonoBitSet *bitset) MONO_INTERNAL;
505 MonoType *mono_metadata_type_dup (MonoImage *image, const MonoType *original) MONO_INTERNAL;
506 MonoMethodSignature *mono_metadata_signature_dup_full (MonoImage *image,MonoMethodSignature *sig) MONO_INTERNAL;
507 MonoMethodSignature *mono_metadata_signature_dup_mempool (MonoMemPool *mp, MonoMethodSignature *sig) MONO_INTERNAL;
510 mono_get_shared_generic_inst (MonoGenericContainer *container) MONO_INTERNAL;
513 mono_type_stack_size_internal (MonoType *t, int *align, gboolean allow_open) MONO_INTERNAL;
516 mono_metadata_type_equal_full (MonoType *t1, MonoType *t2, gboolean signature_only) MONO_INTERNAL;
519 mono_metadata_parse_marshal_spec_full (MonoImage *image, const char *ptr) MONO_INTERNAL;
521 guint mono_metadata_generic_inst_hash (gconstpointer data) MONO_INTERNAL;
522 gboolean mono_metadata_generic_inst_equal (gconstpointer ka, gconstpointer kb) MONO_INTERNAL;
525 mono_metadata_field_info_with_mempool (
530 MonoMarshalSpec **marshal_spec);
533 mono_metadata_get_corresponding_field_from_generic_type_definition (MonoClassField *field) MONO_INTERNAL;
536 mono_metadata_get_corresponding_event_from_generic_type_definition (MonoEvent *event) MONO_INTERNAL;
539 mono_metadata_get_corresponding_property_from_generic_type_definition (MonoProperty *property) MONO_INTERNAL;
542 mono_metadata_signature_size (MonoMethodSignature *sig) MONO_INTERNAL;
544 #endif /* __MONO_METADATA_INTERNALS_H__ */