2004-12-27 Ben Maurer <bmaurer@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/utils/mono-hash.h"
7
8 struct _MonoAssembly {
9         int   ref_count;
10         char *basedir;
11         gboolean in_gac;
12         MonoAssemblyName aname;
13         GModule *aot_module;
14         MonoImage *image;
15         gboolean dynamic;
16         gboolean corlib_internal;
17 };
18
19 typedef struct {
20         const char* data;
21         guint32  size;
22 } MonoStreamHeader;
23
24 struct _MonoTableInfo {
25         guint32   rows, row_size;
26         const char *base;
27
28         /*
29          * Tables contain up to 9 columns and the possible sizes of the
30          * fields in the documentation are 1, 2 and 4 bytes.  So we
31          * can encode in 2 bits the size.
32          *
33          * A 32 bit value can encode the resulting size
34          *
35          * The top eight bits encode the number of columns in the table.
36          * we only need 4, but 8 is aligned no shift required. 
37          */
38         guint32   size_bitfield;
39 };
40
41 struct _MonoImage {
42         int   ref_count;
43         FILE *f;
44         /* if f is NULL the image was loaded from raw data */
45         char *raw_data;
46         guint32 raw_data_len;
47         gboolean raw_data_allocated;
48         char *name;
49         const char *assembly_name;
50         const char *module_name;
51         const char *version;
52         char *guid;
53         void *image_info;
54
55         char                *raw_metadata;
56                             
57         gboolean             idx_string_wide, idx_guid_wide, idx_blob_wide;
58                             
59         MonoStreamHeader     heap_strings;
60         MonoStreamHeader     heap_us;
61         MonoStreamHeader     heap_blob;
62         MonoStreamHeader     heap_guid;
63         MonoStreamHeader     heap_tables;
64                             
65         const char          *tables_base;
66
67         MonoTableInfo        tables [64];
68
69         /*
70          * references is initialized only by using the mono_assembly_open
71          * function, and not by using the lowlevel mono_image_open.
72          *
73          * It is NULL terminated.
74          */
75         MonoAssembly **references;
76
77         MonoImage **modules;
78         guint32 module_count;
79
80         MonoImage **files;
81
82         /*
83          * The Assembly this image was loaded from.
84          */
85         MonoAssembly *assembly;
86
87         /*
88          * Indexed by method tokens and typedef tokens.
89          */
90         GHashTable *method_cache;
91         GHashTable *class_cache;
92         /*
93          * Indexed by fielddef and memberref tokens
94          */
95         GHashTable *field_cache;
96
97         /* indexed by typespec tokens. */
98         GHashTable *typespec_cache;
99         /* indexed by token */
100         GHashTable *memberref_signatures;
101         GHashTable *helper_signatures;
102
103         /*
104          * Indexes namespaces to hash tables that map class name to typedef token.
105          */
106         GHashTable *name_cache;
107
108         /*
109          * Indexed by ((rank << 24) | (typedef & 0xffffff)), which limits us to a
110          * maximal rank of 255
111          */
112         GHashTable *array_cache;
113
114         /*
115          * indexed by MonoMethodSignature 
116          */
117         GHashTable *delegate_begin_invoke_cache;
118         GHashTable *delegate_end_invoke_cache;
119         GHashTable *delegate_invoke_cache;
120
121         /*
122          * indexed by MonoMethod pointers 
123          */
124         GHashTable *runtime_invoke_cache;
125         GHashTable *managed_wrapper_cache;
126         GHashTable *native_wrapper_cache;
127         GHashTable *remoting_invoke_cache;
128         GHashTable *synchronized_cache;
129         GHashTable *unbox_wrapper_cache;
130
131         void *reflection_info;
132
133         /*
134          * user_info is a public field and is not touched by the
135          * metadata engine
136          */
137         void *user_info;
138
139         /* dll map entries */
140         GHashTable *dll_map;
141
142         /* Whenever this is a dynamically emitted module */
143         gboolean dynamic;
144 };
145
146 enum {
147         MONO_SECTION_TEXT,
148         MONO_SECTION_RSRC,
149         MONO_SECTION_RELOC,
150         MONO_SECTION_MAX
151 };
152
153 typedef struct {
154         GHashTable *hash;
155         char *data;
156         guint32 alloc_size; /* malloced bytes */
157         guint32 index;
158         guint32 offset; /* from start of metadata */
159 } MonoDynamicStream;
160
161 typedef struct {
162         guint32 alloc_rows;
163         guint32 rows;
164         guint32 row_size; /*  calculated later with column_sizes */
165         guint32 columns;
166         guint32 column_sizes [9]; 
167         guint32 *values; /* rows * columns */
168         guint32 next_idx;
169 } MonoDynamicTable;
170
171 struct _MonoDynamicAssembly {
172         MonoAssembly assembly;
173         gboolean run;
174         gboolean save;
175         char *strong_name;
176         guint32 strong_name_size;
177 };
178
179 struct _MonoDynamicImage {
180         MonoImage image;
181         guint32 meta_size;
182         guint32 text_rva;
183         guint32 metadata_rva;
184         guint32 image_base;
185         guint32 cli_header_offset;
186         guint32 iat_offset;
187         guint32 idt_offset;
188         guint32 ilt_offset;
189         guint32 imp_names_offset;
190         struct {
191                 guint32 rva;
192                 guint32 size;
193                 guint32 offset;
194                 guint32 attrs;
195         } sections [MONO_SECTION_MAX];
196         GHashTable *typespec;
197         GHashTable *typeref;
198         GHashTable *handleref;
199         MonoGHashTable *tokens;
200         GHashTable *blob_cache;
201         GList *array_methods;
202         GPtrArray *gen_params;
203         MonoGHashTable *token_fixups;
204         GHashTable *method_to_table_idx;
205         GHashTable *field_to_table_idx;
206         GHashTable *method_aux_hash;
207         gboolean run;
208         gboolean save;
209         gboolean initial_image;
210         guint32 pe_kind, machine;
211         char *strong_name;
212         guint32 strong_name_size;
213         char *win32_res;
214         guint32 win32_res_size;
215         MonoDynamicStream sheap;
216         MonoDynamicStream code; /* used to store method headers and bytecode */
217         MonoDynamicStream resources; /* managed embedded resources */
218         MonoDynamicStream us;
219         MonoDynamicStream blob;
220         MonoDynamicStream tstream;
221         MonoDynamicStream guid;
222         MonoDynamicTable tables [64];
223 };
224
225 MonoClass**
226 mono_metadata_interfaces_from_typedef_full  (MonoImage             *image,
227                                              guint32                table_index,
228                                              guint                 *count,
229                                              MonoGenericContext    *context);
230
231 MonoArrayType *
232 mono_metadata_parse_array_full              (MonoImage             *image,
233                                              MonoGenericContext    *generic_context,
234                                              const char            *ptr,
235                                              const char           **rptr);
236
237 MonoType *
238 mono_metadata_parse_type_full               (MonoImage             *image,
239                                              MonoGenericContext    *generic_context,
240                                              MonoParseTypeMode      mode,
241                                              short                  opt_attrs,
242                                              const char            *ptr,
243                                              const char           **rptr);
244
245 MonoType *
246 mono_type_create_from_typespec_full         (MonoImage             *image,
247                                              MonoGenericContext    *generic_context,
248                                              guint32                type_spec);
249
250 MonoMethodSignature *
251 mono_metadata_parse_signature_full          (MonoImage             *image,
252                                              MonoGenericContext    *generic_context,
253                                              guint32                token);
254
255 MonoMethodSignature *
256 mono_metadata_parse_method_signature_full   (MonoImage             *image,
257                                              MonoGenericContext    *generic_context,
258                                              int                     def,
259                                              const char             *ptr,
260                                              const char            **rptr);
261
262 MonoMethodHeader *
263 mono_metadata_parse_mh_full                 (MonoImage             *image,
264                                              MonoGenericContext    *generic_context,
265                                              const char            *ptr);
266
267 guint
268 mono_metadata_generic_method_hash           (MonoGenericMethod     *gmethod);
269
270 gboolean
271 mono_metadata_generic_method_equal          (MonoGenericMethod     *g1,
272                                              MonoGenericMethod     *g2);
273
274 MonoGenericInst *
275 mono_metadata_parse_generic_inst            (MonoImage             *image,
276                                              MonoGenericContext    *generic_context,
277                                              int                    count,
278                                              const char            *ptr,
279                                              const char           **rptr);
280
281 MonoGenericInst *
282 mono_metadata_lookup_generic_inst           (MonoGenericInst       *ginst);
283
284 MonoGenericClass *
285 mono_metadata_lookup_generic_class          (MonoGenericClass      *gclass);
286
287 MonoGenericInst *
288 mono_metadata_inflate_generic_inst          (MonoGenericInst       *ginst,
289                                              MonoGenericContext    *context);
290
291 #endif /* __MONO_METADATA_INTERNALS_H__ */
292