* roottypes.cs: Rename from tree.cs.
[mono.git] / mono / metadata / cil-coff.h
1
2 #ifndef __MONO_CIL_COFF_H__
3 #define __MONO_CIL_COFF_H__
4
5 #include <mono/metadata/metadata.h>
6
7 /*
8  * 25.2.1: Method header type values
9  */
10 #define METHOD_HEADER_FORMAT_MASK   7
11 #define METHOD_HEADER_TINY_FORMAT   2
12 #define METHOD_HEADER_TINY_FORMAT1  6
13 #define METHOD_HEADER_FAT_FORMAT    3
14
15 /*
16  * 25.2.3.1: Flags for method headers
17  */
18 #define METHOD_HEADER_INIT_LOCALS   0x10
19 #define METHOD_HEADER_MORE_SECTS    0x08
20
21 /*
22  * For section data (25.3)
23  */
24 #define METHOD_HEADER_SECTION_RESERVED    0
25 #define METHOD_HEADER_SECTION_EHTABLE     1
26 #define METHOD_HEADER_SECTION_OPTIL_TABLE 2
27 #define METHOD_HEADER_SECTION_FAT_FORMAT  0x40
28 #define METHOD_HEADER_SECTION_MORE_SECTS  0x80
29
30 /* 128 bytes */
31 typedef struct {
32         char    msdos_sig [2];
33         guint16 nlast_page;
34         guint16 npages;
35         char    msdos_header [54];
36         guint32 pe_offset;
37         char    msdos_header2 [64];
38 } MonoMSDOSHeader;
39
40 /* 20 bytes */
41 typedef struct {
42         guint16  coff_machine;
43         guint16  coff_sections;
44         guint32  coff_time;
45         guint32  coff_symptr;
46         guint32  coff_symcount;
47         guint16  coff_opt_header_size;
48         guint16  coff_attributes;
49 } MonoCOFFHeader;
50
51 #define COFF_ATTRIBUTE_EXECUTABLE_IMAGE 0x0002
52 #define COFF_ATTRIBUTE_LIBRARY_IMAGE    0x2000
53
54 /* 28 bytes */
55 typedef struct {
56         guint16 pe_magic;
57         guchar  pe_major;
58         guchar  pe_minor;
59         guint32 pe_code_size;
60         guint32 pe_data_size;
61         guint32 pe_uninit_data_size;
62         guint32 pe_rva_entry_point;
63         guint32 pe_rva_code_base;
64         guint32 pe_rva_data_base;
65 } MonoPEHeader;
66
67 /* 68 bytes */
68 typedef struct {
69         guint32 pe_image_base;          /* must be 0x400000 */
70         guint32 pe_section_align;       /* must be 8192 */
71         guint32 pe_file_alignment;      /* must be 512 or 4096 */
72         guint16 pe_os_major;            /* must be 4 */
73         guint16 pe_os_minor;            /* must be 0 */
74         guint16 pe_user_major;
75         guint16 pe_user_minor;
76         guint16 pe_subsys_major;
77         guint16 pe_subsys_minor;
78         guint32 pe_reserved_1;
79         guint32 pe_image_size;
80         guint32 pe_header_size;
81         guint32 pe_checksum;
82         guint16 pe_subsys_required;
83         guint16 pe_dll_flags;
84         guint32 pe_stack_reserve;
85         guint32 pe_stack_commit;
86         guint32 pe_heap_reserve;
87         guint32 pe_heap_commit;
88         guint32 pe_loader_flags;
89         guint32 pe_data_dir_count;
90 } MonoPEHeaderNT;
91
92 typedef struct {
93         guint32 rde_data_offset;
94         guint32 rde_size;
95         guint32 rde_codepage;
96         guint32 rde_reserved;
97 } MonoPEResourceDataEntry;
98
99 #define MONO_PE_RESOURCE_ID_CURSOR      0x01
100 #define MONO_PE_RESOURCE_ID_BITMAP      0x02
101 #define MONO_PE_RESOURCE_ID_ICON        0x03
102 #define MONO_PE_RESOURCE_ID_MENU        0x04
103 #define MONO_PE_RESOURCE_ID_DIALOG      0x05
104 #define MONO_PE_RESOURCE_ID_STRING      0x06
105 #define MONO_PE_RESOURCE_ID_FONTDIR     0x07
106 #define MONO_PE_RESOURCE_ID_FONT        0x08
107 #define MONO_PE_RESOURCE_ID_ACCEL       0x09
108 #define MONO_PE_RESOURCE_ID_RCDATA      0x0a
109 #define MONO_PE_RESOURCE_ID_MESSAGETABLE        0x0b
110 #define MONO_PE_RESOURCE_ID_GROUP_CURSOR        0x0c
111 #define MONO_PE_RESOURCE_ID_GROUP_ICON  0x0d
112 #define MONO_PE_RESOURCE_ID_VERSION     0x10
113 #define MONO_PE_RESOURCE_ID_DLGINCLUDE  0x11
114 #define MONO_PE_RESOURCE_ID_PLUGPLAY    0x13
115 #define MONO_PE_RESOURCE_ID_VXD         0x14
116 #define MONO_PE_RESOURCE_ID_ANICURSOR   0x15
117 #define MONO_PE_RESOURCE_ID_ANIICON     0x16
118 #define MONO_PE_RESOURCE_ID_HTML        0x17
119
120 typedef struct {
121         /* If the MSB is set, then the other 31 bits store the RVA of
122          * the unicode string containing the name.  Otherwise, the
123          * other 31 bits contain the ID of this entry.
124          */
125 #if G_BYTE_ORDER == G_LITTLE_ENDIAN
126         guint32 name_offset:31;
127         guint32 name_is_string:1;
128 #else
129         guint32 name_is_string:1;
130         guint32 name_offset:31;
131 #endif
132         
133         /* If the MSB is set, then the other 31 bits store the RVA of
134          * another subdirectory.  Otherwise, the other 31 bits store
135          * the RVA of the resource data entry leaf node.
136          */
137 #if G_BYTE_ORDER == G_LITTLE_ENDIAN
138         guint32 dir_offset:31;
139         guint32 is_dir:1;
140 #else
141         guint32 is_dir:1;
142         guint32 dir_offset:31;
143 #endif
144 } MonoPEResourceDirEntry;
145
146 typedef struct 
147 {
148         guint32 res_characteristics;
149         guint32 res_date_stamp;
150         guint16 res_major;
151         guint16 res_minor;
152         guint16 res_named_entries;
153         guint16 res_id_entries;
154         /* Directory entries follow on here.  The array is
155          * res_named_entries + res_id_entries long, containing all
156          * named entries first.
157          */
158 } MonoPEResourceDir;
159
160 typedef struct {
161         guint32 rva;
162         guint32 size;
163 } MonoPEDirEntry;
164
165 /* 128 bytes */
166 typedef struct {
167         MonoPEDirEntry pe_export_table;
168         MonoPEDirEntry pe_import_table;
169         MonoPEDirEntry pe_resource_table;
170         MonoPEDirEntry pe_exception_table;
171         MonoPEDirEntry pe_certificate_table;
172         MonoPEDirEntry pe_reloc_table;
173         MonoPEDirEntry pe_debug;
174         MonoPEDirEntry pe_copyright;
175         MonoPEDirEntry pe_global_ptr;
176         MonoPEDirEntry pe_tls_table;
177         MonoPEDirEntry pe_load_config_table;
178         MonoPEDirEntry pe_bound_import;
179         MonoPEDirEntry pe_iat;
180         MonoPEDirEntry pe_delay_import_desc;
181         MonoPEDirEntry pe_cli_header;
182         MonoPEDirEntry pe_reserved;
183 } MonoPEDatadir;
184
185 /* 248 bytes */
186 typedef struct {
187         char            pesig [4];
188         MonoCOFFHeader  coff;
189         MonoPEHeader    pe;
190         MonoPEHeaderNT  nt;
191         MonoPEDatadir   datadir;
192 } MonoDotNetHeader;
193
194 typedef struct {
195         char    st_name [8];
196         guint32 st_virtual_size;
197         guint32 st_virtual_address;
198         guint32 st_raw_data_size;
199         guint32 st_raw_data_ptr;
200         guint32 st_reloc_ptr;
201         guint32 st_lineno_ptr;
202         guint16 st_reloc_count;
203         guint16 st_line_count;
204
205 #define SECT_FLAGS_HAS_CODE               0x20
206 #define SECT_FLAGS_HAS_INITIALIZED_DATA   0x40
207 #define SECT_FLAGS_HAS_UNINITIALIZED_DATA 0x80
208 #define SECT_FLAGS_MEM_DISCARDABLE        0x02000000
209 #define SECT_FLAGS_MEM_NOT_CACHED         0x04000000
210 #define SECT_FLAGS_MEM_NOT_PAGED          0x08000000
211 #define SECT_FLAGS_MEM_SHARED             0x10000000
212 #define SECT_FLAGS_MEM_EXECUTE            0x20000000
213 #define SECT_FLAGS_MEM_READ               0x40000000
214 #define SECT_FLAGS_MEM_WRITE              0x80000000
215         guint32 st_flags;
216
217 } MonoSectionTable;
218
219 typedef struct {
220         guint32        ch_size;
221         guint16        ch_runtime_major;
222         guint16        ch_runtime_minor;
223         MonoPEDirEntry ch_metadata;
224
225 #define CLI_FLAGS_ILONLY         0x01
226 #define CLI_FLAGS_32BITREQUIRED  0x02
227 #define CLI_FLAGS_STRONGNAMESIGNED 0x8
228 #define CLI_FLAGS_TRACKDEBUGDATA 0x00010000
229         guint32        ch_flags;
230
231         guint32        ch_entry_point;
232         MonoPEDirEntry ch_resources;
233         MonoPEDirEntry ch_strong_name;
234         MonoPEDirEntry ch_code_manager_table;
235         MonoPEDirEntry ch_vtable_fixups;
236         MonoPEDirEntry ch_export_address_table_jumps;
237
238         /* The following are zero in the current docs */
239         MonoPEDirEntry ch_eeinfo_table;
240         MonoPEDirEntry ch_helper_table;
241         MonoPEDirEntry ch_dynamic_info;
242         MonoPEDirEntry ch_delay_load_info;
243         MonoPEDirEntry ch_module_image;
244         MonoPEDirEntry ch_external_fixups;
245         MonoPEDirEntry ch_ridmap;
246         MonoPEDirEntry ch_debug_map;
247         MonoPEDirEntry ch_ip_map;
248 } MonoCLIHeader;
249
250 /* This is not an on-disk structure */
251 typedef struct {
252         MonoDotNetHeader  cli_header;
253         int               cli_section_count;
254         MonoSectionTable  *cli_section_tables;
255         void            **cli_sections;
256         MonoCLIHeader     cli_cli_header;
257 } MonoCLIImageInfo;
258
259 guint32       mono_cli_rva_image_map (MonoCLIImageInfo *iinfo, guint32 rva);
260
261 #endif /* __MONO_CIL_COFF_H__ */