733cc3e77bd672b79700d15bb20966a24edf9c7e
[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
7 typedef struct _MonoImage MonoImage;
8
9 typedef struct {
10         const char *name;
11         const char *culture;
12         const char *hash_value;
13         guint32 hash_len;
14         guint32 flags;
15         gint16 major, minor, build, revision;
16 } MonoAssemblyName;
17
18 typedef struct {
19         int   ref_count;
20         char *basedir;
21         MonoAssemblyName aname;
22         
23         MonoImage *image;
24         MonoImage **modules;
25         /* Load files here */
26 } MonoAssembly;
27
28 typedef struct {
29         const char* data;
30         guint32  size;
31 } MonoStreamHeader;
32
33 typedef struct {
34         guint32   rows, row_size;
35         const char *base;
36
37         /*
38          * Tables contain up to 9 columns and the possible sizes of the
39          * fields in the documentation are 1, 2 and 4 bytes.  So we
40          * can encode in 2 bits the size.
41          *
42          * A 32 bit value can encode the resulting size
43          *
44          * The top eight bits encode the number of columns in the table.
45          * we only need 4, but 8 is aligned no shift required. 
46          */
47         guint32   size_bitfield;
48 } MonoTableInfo;
49
50 struct _MonoImage {
51         int   ref_count;
52         FILE *f;
53         char *name;
54         const char *assembly_name;
55         const char *module_name;
56         void *image_info;
57
58         char                *raw_metadata;
59                             
60         gboolean             idx_string_wide, idx_guid_wide, idx_blob_wide;
61                             
62         MonoStreamHeader     heap_strings;
63         MonoStreamHeader     heap_us;
64         MonoStreamHeader     heap_blob;
65         MonoStreamHeader     heap_guid;
66         MonoStreamHeader     heap_tables;
67                             
68         const char          *tables_base;
69
70         MonoTableInfo        tables [64];
71
72         /*
73          * references is initialized only by using the mono_assembly_open
74          * function, and not by using the lowlevel mono_image_open.
75          *
76          * It is NULL terminated.
77          */
78         MonoAssembly **references;
79
80         /*
81          * The Assembly this image was loaded from.
82          */
83         MonoAssembly *assembly;
84
85         /*
86          * Indexed by method tokens and typedef tokens.
87          */
88         GHashTable *method_cache;
89         GHashTable *class_cache;
90         /*
91          * Indexes namespaces to hash tables that map class name to typedef token.
92          */
93         GHashTable *name_cache;
94
95         /*
96          * Indexed by ((rank << 24) | (typedef & 0xffffff)), which limits us to a
97          * maximal rank of 255
98          */
99         GHashTable *array_cache;
100
101         /*
102          * indexed by MonoMethodSignature 
103          */
104         GHashTable *delegate_begin_invoke_cache;
105         GHashTable *delegate_invoke_cache;
106
107         /*
108          * indexed by MonoMethod pointers 
109          */
110         GHashTable *runtime_invoke_cache;
111         GHashTable *managed_wrapper_cache;
112         GHashTable *native_wrapper_cache;
113
114         void *reflection_info;
115
116         /*
117          * user_info is a public field and is not touched by the
118          * metadata engine
119          */
120         void *user_info;
121 };
122
123 typedef enum {
124         MONO_IMAGE_OK,
125         MONO_IMAGE_ERROR_ERRNO,
126         MONO_IMAGE_MISSING_ASSEMBLYREF,
127         MONO_IMAGE_IMAGE_INVALID
128 } MonoImageOpenStatus;
129
130 MonoImage    *mono_image_open     (const char *fname,
131                                    MonoImageOpenStatus *status);
132 MonoImage    *mono_image_loaded   (const char *name);
133 void          mono_image_close    (MonoImage *image);
134 const char   *mono_image_strerror (MonoImageOpenStatus status);
135
136 int           mono_image_ensure_section     (MonoImage *image,
137                                              const char *section);
138 int           mono_image_ensure_section_idx (MonoImage *image,
139                                              int section);
140 /* This actually returns a MonoPEResourceDataEntry *, but declaring it
141  * causes an include file loop.
142  */
143 gpointer      mono_image_lookup_resource (MonoImage *image, guint32 res_id,
144                                           guint32 lang_id, gunichar2 *name);
145         
146 #endif