d987de10e3cf08bd6b9248fa0f5266d4e7f9d991
[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         guint32 hash_len;
15         guint32 flags;
16         guint16 major, minor, build, revision;
17 } MonoAssemblyName;
18
19 typedef struct {
20         int   ref_count;
21         char *basedir;
22         MonoAssemblyName aname;
23         GModule *aot_module;
24         MonoImage *image;
25         /* Load files here */
26         void *dynamic;
27 } MonoAssembly;
28
29 typedef struct {
30         const char* data;
31         guint32  size;
32 } MonoStreamHeader;
33
34 typedef struct {
35         guint32   rows, row_size;
36         const char *base;
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 } MonoTableInfo;
50
51 struct _MonoImage {
52         int   ref_count;
53         FILE *f;
54         /* if f is NULL the image was loaded rom raw data */
55         char *raw_data;
56         guint32 raw_data_len;
57         gboolean raw_data_allocated;
58         char *name;
59         const char *assembly_name;
60         const char *module_name;
61         const char *version;
62         char *guid;
63         void *image_info;
64
65         char                *raw_metadata;
66                             
67         gboolean             idx_string_wide, idx_guid_wide, idx_blob_wide;
68                             
69         MonoStreamHeader     heap_strings;
70         MonoStreamHeader     heap_us;
71         MonoStreamHeader     heap_blob;
72         MonoStreamHeader     heap_guid;
73         MonoStreamHeader     heap_tables;
74                             
75         const char          *tables_base;
76
77         MonoTableInfo        tables [64];
78
79         /*
80          * references is initialized only by using the mono_assembly_open
81          * function, and not by using the lowlevel mono_image_open.
82          *
83          * It is NULL terminated.
84          */
85         MonoAssembly **references;
86
87         MonoImage **modules;
88
89         /*
90          * The Assembly this image was loaded from.
91          */
92         MonoAssembly *assembly;
93
94         /*
95          * Indexed by method tokens and typedef tokens.
96          */
97         GHashTable *method_cache;
98         GHashTable *class_cache;
99         /* indexed by a generic type instantiation */
100         GHashTable *generics_cache;
101         /*
102          * Indexes namespaces to hash tables that map class name to typedef token.
103          */
104         GHashTable *name_cache;
105
106         /*
107          * Indexed by ((rank << 24) | (typedef & 0xffffff)), which limits us to a
108          * maximal rank of 255
109          */
110         GHashTable *array_cache;
111
112         /*
113          * indexed by MonoMethodSignature 
114          */
115         GHashTable *delegate_begin_invoke_cache;
116         GHashTable *delegate_end_invoke_cache;
117         GHashTable *delegate_invoke_cache;
118
119         /*
120          * indexed by MonoMethod pointers 
121          */
122         GHashTable *runtime_invoke_cache;
123         GHashTable *managed_wrapper_cache;
124         GHashTable *native_wrapper_cache;
125         GHashTable *remoting_invoke_cache;
126         GHashTable *synchronized_cache;
127
128         void *reflection_info;
129
130         /*
131          * user_info is a public field and is not touched by the
132          * metadata engine
133          */
134         void *user_info;
135 };
136
137 typedef enum {
138         MONO_IMAGE_OK,
139         MONO_IMAGE_ERROR_ERRNO,
140         MONO_IMAGE_MISSING_ASSEMBLYREF,
141         MONO_IMAGE_IMAGE_INVALID
142 } MonoImageOpenStatus;
143
144 void          mono_images_init    (void);
145
146 MonoImage    *mono_image_open     (const char *fname,
147                                    MonoImageOpenStatus *status);
148 MonoImage    *mono_image_open_from_data (char *data, guint32 data_len, gboolean need_copy,
149                                          MonoImageOpenStatus *status);
150 MonoImage    *mono_image_loaded   (const char *name);
151 MonoImage    *mono_image_loaded_by_guid (const char *guid);
152 void          mono_image_init     (MonoImage *image);
153 void          mono_image_close    (MonoImage *image);
154 const char   *mono_image_strerror (MonoImageOpenStatus status);
155
156 int           mono_image_ensure_section     (MonoImage *image,
157                                              const char *section);
158 int           mono_image_ensure_section_idx (MonoImage *image,
159                                              int section);
160
161 guint32       mono_image_get_entry_point    (MonoImage *image);
162 const char   *mono_image_get_resource       (MonoImage *image, guint32 offset, guint32 *size);
163
164 void          mono_image_load_references    (MonoImage *image, MonoImageOpenStatus *status);
165
166 /* This actually returns a MonoPEResourceDataEntry *, but declaring it
167  * causes an include file loop.
168  */
169 gpointer      mono_image_lookup_resource (MonoImage *image, guint32 res_id,
170                                           guint32 lang_id, gunichar2 *name);
171
172 const char*   mono_image_get_public_key  (MonoImage *image, guint32 *size);
173 const char*   mono_image_get_strong_name (MonoImage *image, guint32 *size);
174 guint32       mono_image_strong_name_position (MonoImage *image, guint32 *size);
175 void          mono_image_add_to_name_cache (MonoImage *image, 
176                                                                                         const char *nspace, 
177                                                                                         const char *name, guint32 idx);
178
179 #endif