* appdomain.c: Set assembly references public token value when
[mono.git] / mono / metadata / image.h
1 #ifndef _MONONET_METADATA_IMAGE_H_ 
2 #define _MONONET_METADATA_IMAGE_H_
3
4 #include <stdio.h>
5 #include <glib.h>
6 #include <gmodule.h>
7
8 typedef struct _MonoImage MonoImage;
9
10 typedef struct {
11         const char *name;
12         const char *culture;
13         const char *hash_value;
14         const guint8* public_key;
15         const char *public_tok_value;
16         guint32 hash_alg;
17         guint32 hash_len;
18         guint32 flags;
19         guint16 major, minor, build, revision;
20 } MonoAssemblyName;
21
22 typedef struct {
23         int   ref_count;
24         char *basedir;
25         gboolean in_gac;
26         MonoAssemblyName aname;
27         GModule *aot_module;
28         MonoImage *image;
29         /* Load files here */
30         gboolean dynamic;
31 } MonoAssembly;
32
33 typedef struct {
34         const char* data;
35         guint32  size;
36 } MonoStreamHeader;
37
38 typedef struct {
39         guint32   rows, row_size;
40         const char *base;
41
42         /*
43          * Tables contain up to 9 columns and the possible sizes of the
44          * fields in the documentation are 1, 2 and 4 bytes.  So we
45          * can encode in 2 bits the size.
46          *
47          * A 32 bit value can encode the resulting size
48          *
49          * The top eight bits encode the number of columns in the table.
50          * we only need 4, but 8 is aligned no shift required. 
51          */
52         guint32   size_bitfield;
53 } MonoTableInfo;
54
55 struct _MonoImage {
56         int   ref_count;
57         FILE *f;
58         /* if f is NULL the image was loaded from raw data */
59         char *raw_data;
60         guint32 raw_data_len;
61         gboolean raw_data_allocated;
62         char *name;
63         const char *assembly_name;
64         const char *module_name;
65         const char *version;
66         char *guid;
67         void *image_info;
68
69         char                *raw_metadata;
70                             
71         gboolean             idx_string_wide, idx_guid_wide, idx_blob_wide;
72                             
73         MonoStreamHeader     heap_strings;
74         MonoStreamHeader     heap_us;
75         MonoStreamHeader     heap_blob;
76         MonoStreamHeader     heap_guid;
77         MonoStreamHeader     heap_tables;
78                             
79         const char          *tables_base;
80
81         MonoTableInfo        tables [64];
82
83         /*
84          * references is initialized only by using the mono_assembly_open
85          * function, and not by using the lowlevel mono_image_open.
86          *
87          * It is NULL terminated.
88          */
89         MonoAssembly **references;
90
91         MonoImage **modules;
92
93         MonoImage **files;
94
95         /*
96          * The Assembly this image was loaded from.
97          */
98         MonoAssembly *assembly;
99
100         /*
101          * Indexed by method tokens and typedef tokens.
102          */
103         GHashTable *method_cache;
104         GHashTable *class_cache;
105         /*
106          * Indexed by fielddef and memberref tokens
107          */
108         GHashTable *field_cache;
109
110         /* indexed by typespec tokens. */
111         GHashTable *typespec_cache;
112
113         /*
114          * Indexed by MonoGenericInst.
115          */
116         GHashTable *generic_inst_cache;
117
118         /*
119          * Indexes namespaces to hash tables that map class name to typedef token.
120          */
121         GHashTable *name_cache;
122
123         /*
124          * Indexed by ((rank << 24) | (typedef & 0xffffff)), which limits us to a
125          * maximal rank of 255
126          */
127         GHashTable *array_cache;
128
129         /*
130          * indexed by MonoMethodSignature 
131          */
132         GHashTable *delegate_begin_invoke_cache;
133         GHashTable *delegate_end_invoke_cache;
134         GHashTable *delegate_invoke_cache;
135
136         /*
137          * indexed by MonoMethod pointers 
138          */
139         GHashTable *runtime_invoke_cache;
140         GHashTable *managed_wrapper_cache;
141         GHashTable *native_wrapper_cache;
142         GHashTable *remoting_invoke_cache;
143         GHashTable *synchronized_cache;
144
145         void *reflection_info;
146
147         /*
148          * user_info is a public field and is not touched by the
149          * metadata engine
150          */
151         void *user_info;
152
153         /* dll map entries */
154         GHashTable *dll_map;
155
156         /* Whenever this is a dynamically emitted module */
157         gboolean dynamic;
158 };
159
160 typedef enum {
161         MONO_IMAGE_OK,
162         MONO_IMAGE_ERROR_ERRNO,
163         MONO_IMAGE_MISSING_ASSEMBLYREF,
164         MONO_IMAGE_IMAGE_INVALID
165 } MonoImageOpenStatus;
166
167 void          mono_images_init    (void);
168
169 MonoImage    *mono_image_open     (const char *fname,
170                                    MonoImageOpenStatus *status);
171 MonoImage    *mono_image_open_from_data (char *data, guint32 data_len, gboolean need_copy,
172                                          MonoImageOpenStatus *status);
173 MonoImage    *mono_image_loaded   (const char *name);
174 MonoImage    *mono_image_loaded_by_guid (const char *guid);
175 void          mono_image_init     (MonoImage *image);
176 void          mono_image_close    (MonoImage *image);
177 void          mono_image_addref   (MonoImage *image);
178 const char   *mono_image_strerror (MonoImageOpenStatus status);
179
180 int           mono_image_ensure_section     (MonoImage *image,
181                                              const char *section);
182 int           mono_image_ensure_section_idx (MonoImage *image,
183                                              int section);
184
185 guint32       mono_image_get_entry_point    (MonoImage *image);
186 const char   *mono_image_get_resource       (MonoImage *image, guint32 offset, guint32 *size);
187 MonoImage*    mono_image_load_file_for_image (MonoImage *image, int fileidx);
188
189 /* This actually returns a MonoPEResourceDataEntry *, but declaring it
190  * causes an include file loop.
191  */
192 gpointer      mono_image_lookup_resource (MonoImage *image, guint32 res_id,
193                                           guint32 lang_id, gunichar2 *name);
194
195 const char*   mono_image_get_public_key  (MonoImage *image, guint32 *size);
196 const char*   mono_image_get_strong_name (MonoImage *image, guint32 *size);
197 guint32       mono_image_strong_name_position (MonoImage *image, guint32 *size);
198 void          mono_image_add_to_name_cache (MonoImage *image, 
199                                                                                         const char *nspace, 
200                                                                                         const char *name, guint32 idx);
201
202 #endif