2007-04-06 Andreas Faerber <andreas.faerber@web.de>
[mono.git] / mono / metadata / metadata-internals.h
blob7f89b52d2a6ea924a3a7644fa2ffa26a7767b652
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 {
15 /*
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 */
24 char *basedir;
25 MonoAssemblyName aname;
26 MonoDl *aot_module;
27 MonoImage *image;
28 GSList *friend_assembly_names;
29 guint8 in_gac;
30 guint8 dynamic;
31 guint8 corlib_internal;
32 gboolean ref_only;
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 */
40 typedef struct {
41 const char* data;
42 guint32 size;
43 } MonoStreamHeader;
45 struct _MonoTableInfo {
46 const char *base;
47 guint rows : 24;
48 guint row_size : 8;
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;
67 struct _MonoImage {
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 ().
74 int ref_count;
75 FILE *file_descr;
76 /* if file_descr is NULL the image was loaded from raw data */
77 char *raw_data;
78 guint32 raw_data_len;
79 guint8 raw_data_allocated : 1;
81 /* Whenever this is a dynamically emitted module */
82 guint8 dynamic : 1;
84 /* Whenever this is a reflection only image */
85 guint8 ref_only : 1;
87 /* Whenever this image contains uncompressed metadata */
88 guint8 uncompressed_metadata : 1;
90 guint8 checked_module_cctor : 1;
91 guint8 has_module_cctor : 1;
93 guint8 idx_string_wide : 1;
94 guint8 idx_guid_wide : 1;
95 guint8 idx_blob_wide : 1;
97 char *name;
98 const char *assembly_name;
99 const char *module_name;
100 char *version;
101 gint16 md_version_major, md_version_minor;
102 char *guid;
103 void *image_info;
104 MonoMemPool *mempool;
106 char *raw_metadata;
108 MonoStreamHeader heap_strings;
109 MonoStreamHeader heap_us;
110 MonoStreamHeader heap_blob;
111 MonoStreamHeader heap_guid;
112 MonoStreamHeader heap_tables;
114 const char *tables_base;
116 /**/
117 MonoTableInfo tables [MONO_TABLE_NUM];
120 * references is initialized only by using the mono_assembly_open
121 * function, and not by using the lowlevel mono_image_open.
123 * It is NULL terminated.
125 MonoAssembly **references;
127 MonoImage **modules;
128 guint32 module_count;
130 MonoImage **files;
133 * The Assembly this image was loaded from.
135 MonoAssembly *assembly;
138 * Indexed by method tokens and typedef tokens.
140 GHashTable *method_cache;
141 GHashTable *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;
175 * indexed by MonoMethod pointers
177 GHashTable *runtime_invoke_cache;
178 GHashTable *managed_wrapper_cache;
179 GHashTable *native_wrapper_cache;
180 GHashTable *remoting_invoke_cache;
181 GHashTable *synchronized_cache;
182 GHashTable *unbox_wrapper_cache;
183 GHashTable *cominterop_invoke_cache;
184 GHashTable *cominterop_wrapper_cache;
187 * indexed by MonoClass pointers
189 GHashTable *ldfld_wrapper_cache;
190 GHashTable *ldflda_wrapper_cache;
191 GHashTable *ldfld_remote_wrapper_cache;
192 GHashTable *stfld_wrapper_cache;
193 GHashTable *stfld_remote_wrapper_cache;
194 GHashTable *isinst_cache;
195 GHashTable *castclass_cache;
196 GHashTable *proxy_isinst_cache;
198 void *reflection_info;
201 * user_info is a public field and is not touched by the
202 * metadata engine
204 void *user_info;
206 /* dll map entries */
207 MonoDllMap *dll_map;
209 /* interfaces IDs from this image */
210 MonoBitSet *interface_bitset;
213 enum {
214 MONO_SECTION_TEXT,
215 MONO_SECTION_RSRC,
216 MONO_SECTION_RELOC,
217 MONO_SECTION_MAX
220 typedef struct {
221 GHashTable *hash;
222 char *data;
223 guint32 alloc_size; /* malloced bytes */
224 guint32 index;
225 guint32 offset; /* from start of metadata */
226 } MonoDynamicStream;
228 typedef struct {
229 guint32 alloc_rows;
230 guint32 rows;
231 guint8 row_size; /* calculated later with column_sizes */
232 guint8 columns;
233 guint32 next_idx;
234 guint32 *values; /* rows * columns */
235 } MonoDynamicTable;
237 struct _MonoDynamicAssembly {
238 MonoAssembly assembly;
239 char *strong_name;
240 guint32 strong_name_size;
241 guint8 run;
242 guint8 save;
245 struct _MonoDynamicImage {
246 MonoImage image;
247 guint32 meta_size;
248 guint32 text_rva;
249 guint32 metadata_rva;
250 guint32 image_base;
251 guint32 cli_header_offset;
252 guint32 iat_offset;
253 guint32 idt_offset;
254 guint32 ilt_offset;
255 guint32 imp_names_offset;
256 struct {
257 guint32 rva;
258 guint32 size;
259 guint32 offset;
260 guint32 attrs;
261 } sections [MONO_SECTION_MAX];
262 GHashTable *typespec;
263 GHashTable *typeref;
264 GHashTable *handleref;
265 MonoGHashTable *tokens;
266 GHashTable *blob_cache;
267 GList *array_methods;
268 GPtrArray *gen_params;
269 MonoGHashTable *token_fixups;
270 GHashTable *method_to_table_idx;
271 GHashTable *field_to_table_idx;
272 GHashTable *method_aux_hash;
273 gboolean run;
274 gboolean save;
275 gboolean initial_image;
276 guint32 pe_kind, machine;
277 char *strong_name;
278 guint32 strong_name_size;
279 char *win32_res;
280 guint32 win32_res_size;
281 MonoDynamicStream sheap;
282 MonoDynamicStream code; /* used to store method headers and bytecode */
283 MonoDynamicStream resources; /* managed embedded resources */
284 MonoDynamicStream us;
285 MonoDynamicStream blob;
286 MonoDynamicStream tstream;
287 MonoDynamicStream guid;
288 MonoDynamicTable tables [MONO_TABLE_NUM];
291 /* Contains information about assembly binding */
292 typedef struct _MonoAssemblyBindingInfo {
293 char *name;
294 char *culture;
295 guchar public_key_token [MONO_PUBLIC_KEY_TOKEN_LENGTH];
296 int major;
297 int minor;
298 AssemblyVersionSet old_version_bottom;
299 AssemblyVersionSet old_version_top;
300 AssemblyVersionSet new_version;
301 guint has_old_version_bottom : 1;
302 guint has_old_version_top : 1;
303 guint has_new_version : 1;
304 guint is_valid : 1;
305 } MonoAssemblyBindingInfo;
307 struct _MonoMethodHeader {
308 guint32 code_size;
309 const unsigned char *code;
310 guint16 max_stack;
311 unsigned int num_clauses : 15;
312 /* if num_locals != 0, then the following apply: */
313 unsigned int init_locals : 1;
314 guint16 num_locals;
315 MonoExceptionClause *clauses;
316 MonoType *locals [MONO_ZERO_LEN_ARRAY];
319 /* for use with allocated memory blocks (assumes alignment is to 8 bytes) */
320 guint mono_aligned_addr_hash (gconstpointer ptr) MONO_INTERNAL;
322 void
323 mono_image_check_for_module_cctor (MonoImage *image) MONO_INTERNAL;
325 void
326 mono_metadata_cleanup (void);
328 const char * mono_meta_table_name (int table) MONO_INTERNAL;
329 void mono_metadata_compute_table_bases (MonoImage *meta) MONO_INTERNAL;
331 gboolean
332 mono_metadata_interfaces_from_typedef_full (MonoImage *image,
333 guint32 table_index,
334 MonoClass ***interfaces,
335 guint *count,
336 MonoGenericContext *context) MONO_INTERNAL;
338 MonoArrayType *
339 mono_metadata_parse_array_full (MonoImage *image,
340 MonoGenericContainer *container,
341 const char *ptr,
342 const char **rptr) MONO_INTERNAL;
344 MonoType *
345 mono_metadata_parse_type_full (MonoImage *image,
346 MonoGenericContainer *container,
347 MonoParseTypeMode mode,
348 short opt_attrs,
349 const char *ptr,
350 const char **rptr);
352 MonoMethodSignature *
353 mono_metadata_parse_signature_full (MonoImage *image,
354 MonoGenericContainer *generic_container,
355 guint32 token) MONO_INTERNAL;
357 MonoMethodSignature *
358 mono_metadata_parse_method_signature_full (MonoImage *image,
359 MonoGenericContainer *generic_container,
360 int def,
361 const char *ptr,
362 const char **rptr);
364 MonoMethodHeader *
365 mono_metadata_parse_mh_full (MonoImage *image,
366 MonoGenericContainer *container,
367 const char *ptr);
369 int* mono_metadata_get_param_attrs (MonoImage *m, int def);
371 guint
372 mono_metadata_generic_method_hash (MonoGenericMethod *gmethod) MONO_INTERNAL;
374 gboolean
375 mono_metadata_generic_method_equal (MonoGenericMethod *g1,
376 MonoGenericMethod *g2) MONO_INTERNAL;
378 MonoGenericInst *
379 mono_metadata_parse_generic_inst (MonoImage *image,
380 MonoGenericContainer *container,
381 int count,
382 const char *ptr,
383 const char **rptr) MONO_INTERNAL;
385 MonoGenericInst *
386 mono_metadata_lookup_generic_inst (MonoGenericInst *ginst) MONO_INTERNAL;
388 MonoGenericClass *
389 mono_metadata_lookup_generic_class (MonoGenericClass *gclass) MONO_INTERNAL;
391 MonoGenericInst *
392 mono_metadata_inflate_generic_inst (MonoGenericInst *ginst,
393 MonoGenericContext *context) MONO_INTERNAL;
395 void mono_dynamic_stream_reset (MonoDynamicStream* stream) MONO_INTERNAL;
396 void mono_assembly_addref (MonoAssembly *assembly) MONO_INTERNAL;
398 void mono_config_parse_publisher_policy (const char *filename, MonoAssemblyBindingInfo *binding_info) MONO_INTERNAL;
400 gboolean
401 mono_assembly_name_parse_full (const char *name,
402 MonoAssemblyName *aname,
403 gboolean save_public_key,
404 gboolean *is_version_defined) MONO_INTERNAL;
406 guint32 mono_metadata_get_generic_param_row (MonoImage *image, guint32 token, guint32 *owner);
408 void mono_unload_interface_ids (MonoBitSet *bitset) MONO_INTERNAL;
411 MonoType *mono_metadata_type_dup_mp (MonoImage *image, const MonoType *original) MONO_INTERNAL;
413 #endif /* __MONO_METADATA_INTERNALS_H__ */