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