Mon Mar 25 13:04:56 CET 2002 Paolo Molaro <lupus@ximian.com>
[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         int   ref_count;
11         char *name;
12         
13         MonoImage *image;
14         /* Load files here */
15 } MonoAssembly;
16
17 typedef struct {
18         const char* data;
19         guint32  size;
20 } MonoStreamHeader;
21
22 typedef struct {
23         guint32   rows, row_size;
24         char     *base;
25
26         /*
27          * Tables contain up to 9 columns and the possible sizes of the
28          * fields in the documentation are 1, 2 and 4 bytes.  So we
29          * can encode in 2 bits the size.
30          *
31          * A 32 bit value can encode the resulting size
32          *
33          * The top eight bits encode the number of columns in the table.
34          * we only need 4, but 8 is aligned no shift required. 
35          */
36         guint32   size_bitfield;
37 } MonoTableInfo;
38
39 struct _MonoImage {
40         int   ref_count;
41         FILE *f;
42         char *name;
43         const char *assembly_name;
44         void *image_info;
45
46         char                *raw_metadata;
47                             
48         gboolean             idx_string_wide, idx_guid_wide, idx_blob_wide;
49                             
50         MonoStreamHeader     heap_strings;
51         MonoStreamHeader     heap_us;
52         MonoStreamHeader     heap_blob;
53         MonoStreamHeader     heap_guid;
54         MonoStreamHeader     heap_tables;
55                             
56         char                *tables_base;
57
58         MonoTableInfo        tables [64];
59
60         /*
61          * references is initialized only by using the mono_assembly_open
62          * function, and not by using the lowlevel mono_image_open.
63          *
64          * It is NULL terminated.
65          */
66         MonoAssembly **references;
67
68         /*
69          * Indexed by method tokens and typedef tokens.
70          */
71         GHashTable *method_cache;
72         GHashTable *class_cache;
73         /*
74          * Indexes namespaces to hash tables that map class name to typedef token.
75          */
76         GHashTable *name_cache;
77
78         /*
79          * Indexed by ((rank << 24) | (typedef & 0xffffff)), which limits us to a
80          * maximal rank of 255
81          */
82         GHashTable *array_cache;
83
84         void *reflection_info;
85
86         /*
87          * user_info is a public field and is not touched by the
88          * metadata engine
89          */
90         void *user_info;
91 };
92
93 enum MonoImageOpenStatus {
94         MONO_IMAGE_OK,
95         MONO_IMAGE_ERROR_ERRNO,
96         MONO_IMAGE_MISSING_ASSEMBLYREF,
97         MONO_IMAGE_IMAGE_INVALID
98 };
99
100 MonoImage    *mono_image_open     (const char *fname,
101                                    enum MonoImageOpenStatus *status);
102 MonoImage    *mono_image_loaded   (const char *name);
103 void          mono_image_close    (MonoImage *image);
104 const char   *mono_image_strerror (enum MonoImageOpenStatus status);
105
106 int           mono_image_ensure_section     (MonoImage *image,
107                                              const char *section);
108 int           mono_image_ensure_section_idx (MonoImage *image,
109                                              int section);
110         
111 #endif