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