* Makefile.am (opcode.def): Make $(srcdir)!=$(builddir) safe.
[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
79         MonoImage **files;
80
81         /*
82          * The Assembly this image was loaded from.
83          */
84         MonoAssembly *assembly;
85
86         /*
87          * Indexed by method tokens and typedef tokens.
88          */
89         GHashTable *method_cache;
90         GHashTable *class_cache;
91         /*
92          * Indexed by fielddef and memberref tokens
93          */
94         GHashTable *field_cache;
95
96         /* indexed by typespec tokens. */
97         GHashTable *typespec_cache;
98         /* indexed by token */
99         GHashTable *memberref_signatures;
100         GHashTable *helper_signatures;
101
102         /*
103          * Indexed by MonoGenericInst.
104          */
105         GHashTable *generic_inst_cache;
106
107         /*
108          * Indexes namespaces to hash tables that map class name to typedef token.
109          */
110         GHashTable *name_cache;
111
112         /*
113          * Indexed by ((rank << 24) | (typedef & 0xffffff)), which limits us to a
114          * maximal rank of 255
115          */
116         GHashTable *array_cache;
117
118         /*
119          * indexed by MonoMethodSignature 
120          */
121         GHashTable *delegate_begin_invoke_cache;
122         GHashTable *delegate_end_invoke_cache;
123         GHashTable *delegate_invoke_cache;
124
125         /*
126          * indexed by MonoMethod pointers 
127          */
128         GHashTable *runtime_invoke_cache;
129         GHashTable *managed_wrapper_cache;
130         GHashTable *native_wrapper_cache;
131         GHashTable *remoting_invoke_cache;
132         GHashTable *synchronized_cache;
133
134         void *reflection_info;
135
136         /*
137          * user_info is a public field and is not touched by the
138          * metadata engine
139          */
140         void *user_info;
141
142         /* dll map entries */
143         GHashTable *dll_map;
144
145         /* Whenever this is a dynamically emitted module */
146         gboolean dynamic;
147 };
148
149 enum {
150         MONO_SECTION_TEXT,
151         MONO_SECTION_RSRC,
152         MONO_SECTION_RELOC,
153         MONO_SECTION_MAX
154 };
155
156 typedef struct {
157         GHashTable *hash;
158         char *data;
159         guint32 alloc_size; /* malloced bytes */
160         guint32 index;
161         guint32 offset; /* from start of metadata */
162 } MonoDynamicStream;
163
164 typedef struct {
165         guint32 alloc_rows;
166         guint32 rows;
167         guint32 row_size; /*  calculated later with column_sizes */
168         guint32 columns;
169         guint32 column_sizes [9]; 
170         guint32 *values; /* rows * columns */
171         guint32 next_idx;
172 } MonoDynamicTable;
173
174 struct _MonoDynamicAssembly {
175         MonoAssembly assembly;
176         gboolean run;
177         gboolean save;
178         char *strong_name;
179         guint32 strong_name_size;
180 };
181
182 struct _MonoDynamicImage {
183         MonoImage image;
184         guint32 meta_size;
185         guint32 text_rva;
186         guint32 metadata_rva;
187         guint32 image_base;
188         guint32 cli_header_offset;
189         guint32 iat_offset;
190         guint32 idt_offset;
191         guint32 ilt_offset;
192         guint32 imp_names_offset;
193         struct {
194                 guint32 rva;
195                 guint32 size;
196                 guint32 offset;
197                 guint32 attrs;
198         } sections [MONO_SECTION_MAX];
199         GHashTable *typespec;
200         GHashTable *typeref;
201         GHashTable *handleref;
202         MonoGHashTable *tokens;
203         MonoGHashTable *blob_cache;
204         GList *array_methods;
205         MonoGHashTable *token_fixups;
206         MonoGHashTable *method_to_table_idx;
207         MonoGHashTable *field_to_table_idx;
208         MonoGHashTable *method_aux_hash;
209         gboolean run;
210         gboolean save;
211         char *strong_name;
212         guint32 strong_name_size;
213         char *win32_res;
214         guint32 win32_res_size;
215         MonoDynamicStream pefile;
216         MonoDynamicStream sheap;
217         MonoDynamicStream code; /* used to store method headers and bytecode */
218         MonoDynamicStream resources; /* managed embedded resources */
219         MonoDynamicStream us;
220         MonoDynamicStream blob;
221         MonoDynamicStream tstream;
222         MonoDynamicStream guid;
223         MonoDynamicTable tables [64];
224 };
225
226
227 #endif /* __MONO_METADATA_INTERNALS_H__ */
228