Wed Mar 1 19:13:30 CET 2006 Paolo Molaro <lupus@ximian.com>
[mono.git] / mono / metadata / metadata-internals.h
1
2 #ifndef __MONO_METADATA_INTERNALS_H__
3 #define __MONO_METADATA_INTERNALS_H__
4
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
12 struct _MonoAssembly {
13         int ref_count; /* use atomic operations only */
14         char *basedir;
15         MonoAssemblyName aname;
16         GModule *aot_module;
17         MonoImage *image;
18         guint8 in_gac;
19         guint8 dynamic;
20         guint8 corlib_internal;
21         gboolean ref_only;
22         /* security manager flags (one bit is for lazy initialization) */
23         guint32 ecma:2;         /* Has the ECMA key */
24         guint32 aptc:2;         /* Has the [AllowPartiallyTrustedCallers] attributes */
25         guint32 fulltrust:2;    /* Has FullTrust permission */
26         guint32 unmanaged:2;    /* Has SecurityPermissionFlag.UnmanagedCode permission */
27 };
28
29 typedef struct {
30         const char* data;
31         guint32  size;
32 } MonoStreamHeader;
33
34 struct _MonoTableInfo {
35         const char *base;
36         guint       rows     : 24;
37         guint       row_size : 8;
38
39         /*
40          * Tables contain up to 9 columns and the possible sizes of the
41          * fields in the documentation are 1, 2 and 4 bytes.  So we
42          * can encode in 2 bits the size.
43          *
44          * A 32 bit value can encode the resulting size
45          *
46          * The top eight bits encode the number of columns in the table.
47          * we only need 4, but 8 is aligned no shift required. 
48          */
49         guint32   size_bitfield;
50 };
51
52 struct _MonoImage {
53         int   ref_count;
54         FILE *file_descr;
55         /* if file_descr is NULL the image was loaded from raw data */
56         char *raw_data;
57         guint32 raw_data_len;
58         guint8 raw_data_allocated;
59
60         /* Whenever this is a dynamically emitted module */
61         guint8 dynamic;
62
63         /* Whenever this is a reflection only image */
64         guint8 ref_only;
65
66         char *name;
67         const char *assembly_name;
68         const char *module_name;
69         const char *version;
70         gint16 md_version_major, md_version_minor;
71         char *guid;
72         void *image_info;
73         MonoMemPool         *mempool;
74
75         char                *raw_metadata;
76                             
77         guint8               idx_string_wide, idx_guid_wide, idx_blob_wide;
78                             
79         MonoStreamHeader     heap_strings;
80         MonoStreamHeader     heap_us;
81         MonoStreamHeader     heap_blob;
82         MonoStreamHeader     heap_guid;
83         MonoStreamHeader     heap_tables;
84                             
85         const char          *tables_base;
86
87         /**/
88         MonoTableInfo        tables [MONO_TABLE_NUM];
89
90         /*
91          * references is initialized only by using the mono_assembly_open
92          * function, and not by using the lowlevel mono_image_open.
93          *
94          * It is NULL terminated.
95          */
96         MonoAssembly **references;
97
98         MonoImage **modules;
99         guint32 module_count;
100
101         MonoImage **files;
102
103         /*
104          * The Assembly this image was loaded from.
105          */
106         MonoAssembly *assembly;
107
108         /*
109          * Indexed by method tokens and typedef tokens.
110          */
111         GHashTable *method_cache;
112         GHashTable *class_cache;
113         /*
114          * Indexed by fielddef and memberref tokens
115          */
116         GHashTable *field_cache;
117
118         /* indexed by typespec tokens. */
119         GHashTable *typespec_cache;
120         /* indexed by token */
121         GHashTable *memberref_signatures;
122         GHashTable *helper_signatures;
123
124         /*
125          * Indexes namespaces to hash tables that map class name to typedef token.
126          */
127         GHashTable *name_cache;
128
129         /*
130          * Indexed by ((rank << 24) | (typedef & 0xffffff)), which limits us to a
131          * maximal rank of 255
132          */
133         GHashTable *array_cache;
134
135         /*
136          * indexed by MonoMethodSignature 
137          */
138         GHashTable *delegate_begin_invoke_cache;
139         GHashTable *delegate_end_invoke_cache;
140         GHashTable *delegate_invoke_cache;
141
142         /*
143          * indexed by MonoMethod pointers 
144          */
145         GHashTable *runtime_invoke_cache;
146         GHashTable *managed_wrapper_cache;
147         GHashTable *native_wrapper_cache;
148         GHashTable *remoting_invoke_cache;
149         GHashTable *synchronized_cache;
150         GHashTable *unbox_wrapper_cache;
151
152         void *reflection_info;
153
154         /*
155          * user_info is a public field and is not touched by the
156          * metadata engine
157          */
158         void *user_info;
159
160         /* dll map entries */
161         GHashTable *dll_map;
162 };
163
164 enum {
165         MONO_SECTION_TEXT,
166         MONO_SECTION_RSRC,
167         MONO_SECTION_RELOC,
168         MONO_SECTION_MAX
169 };
170
171 typedef struct {
172         GHashTable *hash;
173         char *data;
174         guint32 alloc_size; /* malloced bytes */
175         guint32 index;
176         guint32 offset; /* from start of metadata */
177 } MonoDynamicStream;
178
179 typedef struct {
180         guint32 alloc_rows;
181         guint32 rows;
182         guint8  row_size; /*  calculated later with column_sizes */
183         guint8  columns;
184         guint32 next_idx;
185         guint32 *values; /* rows * columns */
186 } MonoDynamicTable;
187
188 struct _MonoDynamicAssembly {
189         MonoAssembly assembly;
190         char *strong_name;
191         guint32 strong_name_size;
192         guint8 run;
193         guint8 save;
194 };
195
196 struct _MonoDynamicImage {
197         MonoImage image;
198         guint32 meta_size;
199         guint32 text_rva;
200         guint32 metadata_rva;
201         guint32 image_base;
202         guint32 cli_header_offset;
203         guint32 iat_offset;
204         guint32 idt_offset;
205         guint32 ilt_offset;
206         guint32 imp_names_offset;
207         struct {
208                 guint32 rva;
209                 guint32 size;
210                 guint32 offset;
211                 guint32 attrs;
212         } sections [MONO_SECTION_MAX];
213         GHashTable *typespec;
214         GHashTable *typeref;
215         GHashTable *handleref;
216         MonoGHashTable *tokens;
217         GHashTable *blob_cache;
218         GList *array_methods;
219         GPtrArray *gen_params;
220         MonoGHashTable *token_fixups;
221         GHashTable *method_to_table_idx;
222         GHashTable *field_to_table_idx;
223         GHashTable *method_aux_hash;
224         gboolean run;
225         gboolean save;
226         gboolean initial_image;
227         guint32 pe_kind, machine;
228         char *strong_name;
229         guint32 strong_name_size;
230         char *win32_res;
231         guint32 win32_res_size;
232         MonoDynamicStream sheap;
233         MonoDynamicStream code; /* used to store method headers and bytecode */
234         MonoDynamicStream resources; /* managed embedded resources */
235         MonoDynamicStream us;
236         MonoDynamicStream blob;
237         MonoDynamicStream tstream;
238         MonoDynamicStream guid;
239         MonoDynamicTable tables [MONO_TABLE_NUM];
240 };
241
242 /* Contains information about assembly binding */
243 typedef struct _MonoAssemblyBindingInfo {
244         char *name;
245         char *culture;
246         guchar public_key_token [MONO_PUBLIC_KEY_TOKEN_LENGTH];
247         int major;
248         int minor;
249         AssemblyVersionSet old_version_bottom;
250         AssemblyVersionSet old_version_top;
251         AssemblyVersionSet new_version;
252         guint has_old_version_bottom : 1;
253         guint has_old_version_top : 1;
254         guint has_new_version : 1;
255         guint is_valid : 1;
256 } MonoAssemblyBindingInfo;
257
258 struct _MonoMethodHeader {
259         guint32      code_size;
260         const unsigned char  *code;
261         guint16      max_stack;
262         unsigned int num_clauses : 15;
263         /* if num_locals != 0, then the following apply: */
264         unsigned int init_locals : 1;
265         guint16      num_locals;
266         MonoExceptionClause *clauses;
267         MonoType    *locals [MONO_ZERO_LEN_ARRAY];
268 };
269
270 /* for use with allocated memory blocks (assumes alignment is to 8 bytes) */
271 guint mono_aligned_addr_hash (gconstpointer ptr) MONO_INTERNAL;
272
273 const char *   mono_meta_table_name              (int table) MONO_INTERNAL;
274 void           mono_metadata_compute_table_bases (MonoImage *meta) MONO_INTERNAL;
275
276 gboolean
277 mono_metadata_interfaces_from_typedef_full  (MonoImage             *image,
278                                                                                          guint32                table_index,
279                                                                                          MonoClass           ***interfaces,
280                                                                                          guint                 *count,
281                                                                                          MonoGenericContext    *context) MONO_INTERNAL;
282
283 MonoArrayType *
284 mono_metadata_parse_array_full              (MonoImage             *image,
285                                              MonoGenericContainer  *container,
286                                              const char            *ptr,
287                                              const char           **rptr) MONO_INTERNAL;
288
289 MonoType *
290 mono_metadata_parse_type_full               (MonoImage             *image,
291                                              MonoGenericContainer  *container,
292                                              MonoParseTypeMode      mode,
293                                              short                  opt_attrs,
294                                              const char            *ptr,
295                                              const char           **rptr);
296
297 MonoMethodSignature *
298 mono_metadata_parse_signature_full          (MonoImage             *image,
299                                              MonoGenericContainer  *generic_container,
300                                              guint32                token) MONO_INTERNAL;
301
302 MonoMethodSignature *
303 mono_metadata_parse_method_signature_full   (MonoImage             *image,
304                                              MonoGenericContainer  *generic_container,
305                                              int                     def,
306                                              const char             *ptr,
307                                              const char            **rptr);
308
309 MonoMethodHeader *
310 mono_metadata_parse_mh_full                 (MonoImage             *image,
311                                              MonoGenericContainer  *container,
312                                              const char            *ptr);
313
314 guint
315 mono_metadata_generic_method_hash           (MonoGenericMethod     *gmethod) MONO_INTERNAL;
316
317 gboolean
318 mono_metadata_generic_method_equal          (MonoGenericMethod     *g1,
319                                              MonoGenericMethod     *g2) MONO_INTERNAL;
320
321 MonoGenericInst *
322 mono_metadata_parse_generic_inst            (MonoImage             *image,
323                                              MonoGenericContainer  *container,
324                                              int                    count,
325                                              const char            *ptr,
326                                              const char           **rptr) MONO_INTERNAL;
327
328 MonoGenericInst *
329 mono_metadata_lookup_generic_inst           (MonoGenericInst       *ginst) MONO_INTERNAL;
330
331 MonoGenericClass *
332 mono_metadata_lookup_generic_class          (MonoGenericClass      *gclass) MONO_INTERNAL;
333
334 MonoGenericInst *
335 mono_metadata_inflate_generic_inst          (MonoGenericInst       *ginst,
336                                              MonoGenericContext    *context) MONO_INTERNAL;
337
338 void mono_dynamic_stream_reset (MonoDynamicStream* stream) MONO_INTERNAL;
339 void mono_assembly_addref      (MonoAssembly *assembly) MONO_INTERNAL;
340
341 void mono_config_parse_publisher_policy (const char *filename, MonoAssemblyBindingInfo *binding_info) MONO_INTERNAL;
342
343 gboolean
344 mono_assembly_name_parse_full                (const char           *name,
345                                               MonoAssemblyName     *aname,
346                                               gboolean save_public_key,
347                                               gboolean *is_version_defined) MONO_INTERNAL;
348
349 guint32 mono_metadata_get_generic_param_row (MonoImage *image, guint32 token, guint32 *owner);
350
351 #endif /* __MONO_METADATA_INTERNALS_H__ */
352