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