Commit
[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         /* Load files here */
16         gboolean dynamic;
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          * Indexed by MonoGenericInst.
105          */
106         GHashTable *generic_inst_cache;
107
108         /*
109          * Indexes namespaces to hash tables that map class name to typedef token.
110          */
111         GHashTable *name_cache;
112
113         /*
114          * Indexed by ((rank << 24) | (typedef & 0xffffff)), which limits us to a
115          * maximal rank of 255
116          */
117         GHashTable *array_cache;
118
119         /*
120          * indexed by MonoMethodSignature 
121          */
122         GHashTable *delegate_begin_invoke_cache;
123         GHashTable *delegate_end_invoke_cache;
124         GHashTable *delegate_invoke_cache;
125
126         /*
127          * indexed by MonoMethod pointers 
128          */
129         GHashTable *runtime_invoke_cache;
130         GHashTable *managed_wrapper_cache;
131         GHashTable *native_wrapper_cache;
132         GHashTable *remoting_invoke_cache;
133         GHashTable *synchronized_cache;
134
135         void *reflection_info;
136
137         /*
138          * user_info is a public field and is not touched by the
139          * metadata engine
140          */
141         void *user_info;
142
143         /* dll map entries */
144         GHashTable *dll_map;
145
146         /* Whenever this is a dynamically emitted module */
147         gboolean dynamic;
148 };
149
150 enum {
151         MONO_SECTION_TEXT,
152         MONO_SECTION_RSRC,
153         MONO_SECTION_RELOC,
154         MONO_SECTION_MAX
155 };
156
157 typedef struct {
158         GHashTable *hash;
159         char *data;
160         guint32 alloc_size; /* malloced bytes */
161         guint32 index;
162         guint32 offset; /* from start of metadata */
163 } MonoDynamicStream;
164
165 typedef struct {
166         guint32 alloc_rows;
167         guint32 rows;
168         guint32 row_size; /*  calculated later with column_sizes */
169         guint32 columns;
170         guint32 column_sizes [9]; 
171         guint32 *values; /* rows * columns */
172         guint32 next_idx;
173 } MonoDynamicTable;
174
175 struct _MonoDynamicAssembly {
176         MonoAssembly assembly;
177         gboolean run;
178         gboolean save;
179         char *strong_name;
180         guint32 strong_name_size;
181 };
182
183 struct _MonoDynamicImage {
184         MonoImage image;
185         guint32 meta_size;
186         guint32 text_rva;
187         guint32 metadata_rva;
188         guint32 image_base;
189         guint32 cli_header_offset;
190         guint32 iat_offset;
191         guint32 idt_offset;
192         guint32 ilt_offset;
193         guint32 imp_names_offset;
194         struct {
195                 guint32 rva;
196                 guint32 size;
197                 guint32 offset;
198                 guint32 attrs;
199         } sections [MONO_SECTION_MAX];
200         GHashTable *typespec;
201         GHashTable *typeref;
202         GHashTable *handleref;
203         MonoGHashTable *tokens;
204         MonoGHashTable *blob_cache;
205         GList *array_methods;
206         GPtrArray *gen_params;
207         MonoGHashTable *token_fixups;
208         MonoGHashTable *method_to_table_idx;
209         MonoGHashTable *field_to_table_idx;
210         MonoGHashTable *method_aux_hash;
211         gboolean run;
212         gboolean save;
213         gboolean initial_image;
214         guint32 pe_kind, machine;
215         char *strong_name;
216         guint32 strong_name_size;
217         char *win32_res;
218         guint32 win32_res_size;
219         MonoDynamicStream pefile;
220         MonoDynamicStream sheap;
221         MonoDynamicStream code; /* used to store method headers and bytecode */
222         MonoDynamicStream resources; /* managed embedded resources */
223         MonoDynamicStream us;
224         MonoDynamicStream blob;
225         MonoDynamicStream tstream;
226         MonoDynamicStream guid;
227         MonoDynamicTable tables [64];
228 };
229
230 MonoClass**
231 mono_metadata_interfaces_from_typedef_full  (MonoImage             *image,
232                                              guint32                table_index,
233                                              guint                 *count,
234                                              MonoGenericContext    *context);
235
236 MonoArrayType *
237 mono_metadata_parse_array_full              (MonoImage             *image,
238                                              MonoGenericContainer  *generic_container,
239                                              const char            *ptr,
240                                              const char           **rptr);
241
242 MonoType *
243 mono_metadata_parse_type_full               (MonoImage             *image,
244                                              MonoGenericContainer  *generic_container,
245                                              MonoParseTypeMode      mode,
246                                              short                  opt_attrs,
247                                              const char            *ptr,
248                                              const char           **rptr);
249
250 MonoType *
251 mono_type_create_from_typespec_full         (MonoImage             *image,
252                                              MonoGenericContainer  *generic_container,
253                                              guint32                type_spec);
254
255 MonoMethodSignature *
256 mono_metadata_parse_signature_full          (MonoImage             *image,
257                                              MonoGenericContainer  *generic_container,
258                                              guint32                token);
259
260 MonoMethodSignature *
261 mono_metadata_parse_method_signature_full   (MonoImage             *image,
262                                              MonoGenericContainer  *generic_container,
263                                              int                     def,
264                                              const char             *ptr,
265                                              const char            **rptr);
266
267 MonoMethodHeader *
268 mono_metadata_parse_mh_full                 (MonoImage             *image,
269                                              MonoGenericContainer  *generic_container,
270                                              const char            *ptr);
271
272 #endif /* __MONO_METADATA_INTERNALS_H__ */
273