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"
14 struct _MonoAssembly {
16 * The number of appdomains which have this assembly loaded plus the number of
17 * assemblies referencing this assembly through an entry in their image->references
18 * arrays. The later is needed because entries in the image->references array
19 * might point to assemblies which are only loaded in some appdomains, and without
20 * the additional reference, they can be freed at any time.
21 * The ref_count is initially 0.
23 int ref_count; /* use atomic operations only */
25 MonoAssemblyName aname;
28 GSList *friend_assembly_names;
31 guint8 corlib_internal;
33 /* security manager flags (one bit is for lazy initialization) */
34 guint32 ecma:2; /* Has the ECMA key */
35 guint32 aptc:2; /* Has the [AllowPartiallyTrustedCallers] attributes */
36 guint32 fulltrust:2; /* Has FullTrust permission */
37 guint32 unmanaged:2; /* Has SecurityPermissionFlag.UnmanagedCode permission */
45 struct _MonoTableInfo {
51 * Tables contain up to 9 columns and the possible sizes of the
52 * fields in the documentation are 1, 2 and 4 bytes. So we
53 * can encode in 2 bits the size.
55 * A 32 bit value can encode the resulting size
57 * The top eight bits encode the number of columns in the table.
58 * we only need 4, but 8 is aligned no shift required.
60 guint32 size_bitfield;
63 #define REFERENCE_MISSING ((gpointer) -1)
65 typedef struct _MonoDllMap MonoDllMap;
69 * The number of assemblies which reference this MonoImage though their 'image'
70 * field plus the number of images which reference this MonoImage through their
71 * 'modules' field, plus the number of threads holding temporary references to
72 * this image between calls of mono_image_open () and mono_image_close ().
77 guint8 raw_buffer_used : 1;
78 guint8 raw_data_allocated : 1;
80 /* Whenever this is a dynamically emitted module */
83 /* Whenever this is a reflection only image */
86 /* Whenever this image contains uncompressed metadata */
87 guint8 uncompressed_metadata : 1;
89 guint8 checked_module_cctor : 1;
90 guint8 has_module_cctor : 1;
92 guint8 idx_string_wide : 1;
93 guint8 idx_guid_wide : 1;
94 guint8 idx_blob_wide : 1;
97 const char *assembly_name;
98 const char *module_name;
100 gint16 md_version_major, md_version_minor;
103 MonoMemPool *mempool;
107 MonoStreamHeader heap_strings;
108 MonoStreamHeader heap_us;
109 MonoStreamHeader heap_blob;
110 MonoStreamHeader heap_guid;
111 MonoStreamHeader heap_tables;
113 const char *tables_base;
116 MonoTableInfo tables [MONO_TABLE_NUM];
119 * references is initialized only by using the mono_assembly_open
120 * function, and not by using the lowlevel mono_image_open.
122 * It is NULL terminated.
124 MonoAssembly **references;
127 guint32 module_count;
128 gboolean *modules_loaded;
133 * The Assembly this image was loaded from.
135 MonoAssembly *assembly;
138 * Indexed by method tokens and typedef tokens.
140 GHashTable *method_cache;
141 MonoInternalHashTable class_cache;
143 * Indexed by fielddef and memberref tokens
145 GHashTable *field_cache;
147 /* indexed by typespec tokens. */
148 GHashTable *typespec_cache;
149 /* indexed by token */
150 GHashTable *memberref_signatures;
151 GHashTable *helper_signatures;
153 /* Indexed by blob heap indexes */
154 GHashTable *method_signatures;
157 * Indexes namespaces to hash tables that map class name to typedef token.
159 GHashTable *name_cache;
162 * Indexed by MonoClass
164 GHashTable *array_cache;
165 GHashTable *ptr_cache;
168 * indexed by MonoMethodSignature
170 GHashTable *delegate_begin_invoke_cache;
171 GHashTable *delegate_end_invoke_cache;
172 GHashTable *delegate_invoke_cache;
173 GHashTable *runtime_invoke_cache;
176 * indexed by SignatureMethodPair
178 GHashTable *delegate_abstract_invoke_cache;
181 * indexed by MonoMethod pointers
183 GHashTable *runtime_invoke_direct_cache;
184 GHashTable *managed_wrapper_cache;
185 GHashTable *native_wrapper_cache;
186 GHashTable *remoting_invoke_cache;
187 GHashTable *synchronized_cache;
188 GHashTable *unbox_wrapper_cache;
189 GHashTable *cominterop_invoke_cache;
190 GHashTable *cominterop_wrapper_cache;
193 * indexed by MonoClass pointers
195 GHashTable *ldfld_wrapper_cache;
196 GHashTable *ldflda_wrapper_cache;
197 GHashTable *ldfld_remote_wrapper_cache;
198 GHashTable *stfld_wrapper_cache;
199 GHashTable *stfld_remote_wrapper_cache;
200 GHashTable *isinst_cache;
201 GHashTable *castclass_cache;
202 GHashTable *proxy_isinst_cache;
205 * indexed by token and MonoGenericContext pointer
207 GHashTable *generic_class_cache;
209 void *reflection_info;
212 * user_info is a public field and is not touched by the
217 /* dll map entries */
220 /* interfaces IDs from this image */
221 MonoBitSet *interface_bitset;
234 guint32 alloc_size; /* malloced bytes */
236 guint32 offset; /* from start of metadata */
242 guint8 row_size; /* calculated later with column_sizes */
245 guint32 *values; /* rows * columns */
248 struct _MonoDynamicAssembly {
249 MonoAssembly assembly;
251 guint32 strong_name_size;
256 struct _MonoDynamicImage {
260 guint32 metadata_rva;
262 guint32 cli_header_offset;
266 guint32 imp_names_offset;
272 } sections [MONO_SECTION_MAX];
273 GHashTable *typespec;
275 GHashTable *handleref;
276 MonoGHashTable *tokens;
277 GHashTable *blob_cache;
278 GList *array_methods;
279 GPtrArray *gen_params;
280 MonoGHashTable *token_fixups;
281 GHashTable *method_to_table_idx;
282 GHashTable *field_to_table_idx;
283 GHashTable *method_aux_hash;
286 gboolean initial_image;
287 guint32 pe_kind, machine;
289 guint32 strong_name_size;
291 guint32 win32_res_size;
294 MonoDynamicStream sheap;
295 MonoDynamicStream code; /* used to store method headers and bytecode */
296 MonoDynamicStream resources; /* managed embedded resources */
297 MonoDynamicStream us;
298 MonoDynamicStream blob;
299 MonoDynamicStream tstream;
300 MonoDynamicStream guid;
301 MonoDynamicTable tables [MONO_TABLE_NUM];
304 /* Contains information about assembly binding */
305 typedef struct _MonoAssemblyBindingInfo {
308 guchar public_key_token [MONO_PUBLIC_KEY_TOKEN_LENGTH];
311 AssemblyVersionSet old_version_bottom;
312 AssemblyVersionSet old_version_top;
313 AssemblyVersionSet new_version;
314 guint has_old_version_bottom : 1;
315 guint has_old_version_top : 1;
316 guint has_new_version : 1;
318 } MonoAssemblyBindingInfo;
320 struct _MonoMethodHeader {
322 const unsigned char *code;
324 unsigned int num_clauses : 15;
325 /* if num_locals != 0, then the following apply: */
326 unsigned int init_locals : 1;
328 MonoExceptionClause *clauses;
329 MonoType *locals [MONO_ZERO_LEN_ARRAY];
332 /* for use with allocated memory blocks (assumes alignment is to 8 bytes) */
333 guint mono_aligned_addr_hash (gconstpointer ptr) MONO_INTERNAL;
336 mono_image_check_for_module_cctor (MonoImage *image) MONO_INTERNAL;
339 mono_metadata_clean_for_image (MonoImage *image) MONO_INTERNAL;
342 mono_metadata_cleanup (void);
344 const char * mono_meta_table_name (int table) MONO_INTERNAL;
345 void mono_metadata_compute_table_bases (MonoImage *meta) MONO_INTERNAL;
348 mono_metadata_interfaces_from_typedef_full (MonoImage *image,
350 MonoClass ***interfaces,
352 MonoGenericContext *context) MONO_INTERNAL;
355 mono_metadata_parse_array_full (MonoImage *image,
356 MonoGenericContainer *container,
358 const char **rptr) MONO_INTERNAL;
361 mono_metadata_parse_type_full (MonoImage *image,
362 MonoGenericContainer *container,
363 MonoParseTypeMode mode,
368 MonoMethodSignature *
369 mono_metadata_parse_signature_full (MonoImage *image,
370 MonoGenericContainer *generic_container,
371 guint32 token) MONO_INTERNAL;
373 MonoMethodSignature *
374 mono_metadata_parse_method_signature_full (MonoImage *image,
375 MonoGenericContainer *generic_container,
381 mono_metadata_parse_mh_full (MonoImage *image,
382 MonoGenericContainer *container,
385 int* mono_metadata_get_param_attrs (MonoImage *m, int def);
388 mono_metadata_generic_context_hash (const MonoGenericContext *context) MONO_INTERNAL;
391 mono_metadata_generic_context_equal (const MonoGenericContext *g1,
392 const MonoGenericContext *g2) MONO_INTERNAL;
395 mono_metadata_parse_generic_inst (MonoImage *image,
396 MonoGenericContainer *container,
399 const char **rptr) MONO_INTERNAL;
402 mono_metadata_get_generic_inst (int type_argc,
403 MonoType **type_argv) MONO_INTERNAL;
406 mono_metadata_lookup_generic_class (MonoClass *gclass,
407 MonoGenericInst *inst,
408 gboolean is_dynamic) MONO_INTERNAL;
411 mono_metadata_inflate_generic_inst (MonoGenericInst *ginst,
412 MonoGenericContext *context) MONO_INTERNAL;
414 void mono_dynamic_stream_reset (MonoDynamicStream* stream) MONO_INTERNAL;
415 void mono_assembly_addref (MonoAssembly *assembly) MONO_INTERNAL;
416 void mono_assembly_load_friends (MonoAssembly* ass);
418 void mono_config_parse_publisher_policy (const char *filename, MonoAssemblyBindingInfo *binding_info) MONO_INTERNAL;
421 mono_assembly_name_parse_full (const char *name,
422 MonoAssemblyName *aname,
423 gboolean save_public_key,
424 gboolean *is_version_defined) MONO_INTERNAL;
426 guint32 mono_metadata_get_generic_param_row (MonoImage *image, guint32 token, guint32 *owner);
428 void mono_unload_interface_ids (MonoBitSet *bitset) MONO_INTERNAL;
431 MonoType *mono_metadata_type_dup (MonoMemPool *mp, const MonoType *original) MONO_INTERNAL;
434 mono_get_shared_generic_inst (MonoGenericContainer *container) MONO_INTERNAL;
437 mono_type_stack_size_internal (MonoType *t, int *align, gboolean allow_open) MONO_INTERNAL;
440 mono_metadata_type_equal_full (MonoType *t1, MonoType *t2, gboolean signature_only) MONO_INTERNAL;
443 #endif /* __MONO_METADATA_INTERNALS_H__ */