2002-04-17 Patrik Torstensson <patrik.torstensson@labs2.com>
[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_header [60];
33         guint32 pe_offset;
34         char    msdos_header2 [64];
35 } MonoMSDOSHeader;
36
37 /* 20 bytes */
38 typedef struct {
39         guint16  coff_machine;
40         guint16  coff_sections;
41         guint32  coff_time;
42         guint32  coff_symptr;
43         guint32  coff_symcount;
44         guint16  coff_opt_header_size;
45         guint16  coff_attributes;
46 } MonoCOFFHeader;
47
48 #define COFF_ATTRIBUTE_EXECUTABLE_IMAGE 0x0002
49 #define COFF_ATTRIBUTE_LIBRARY_IMAGE    0x2000
50
51 /* 28 bytes */
52 typedef struct {
53         guint16 pe_magic;
54         guchar  pe_major;
55         guchar  pe_minor;
56         guint32 pe_code_size;
57         guint32 pe_data_size;
58         guint32 pe_uninit_data_size;
59         guint32 pe_rva_entry_point;
60         guint32 pe_rva_code_base;
61         guint32 pe_rva_data_base;
62 } MonoPEHeader;
63
64 /* 68 bytes */
65 typedef struct {
66         guint32 pe_image_base;          /* must be 0x400000 */
67         guint32 pe_section_align;       /* must be 8192 */
68         guint32 pe_file_alignment;      /* must be 512 or 4096 */
69         guint16 pe_os_major;            /* must be 4 */
70         guint16 pe_os_minor;            /* must be 0 */
71         guint16 pe_user_major;
72         guint16 pe_user_minor;
73         guint16 pe_subsys_major;
74         guint16 pe_subsys_minor;
75         guint32 pe_reserved_1;
76         guint32 pe_image_size;
77         guint32 pe_header_size;
78         guint32 pe_checksum;
79         guint16 pe_subsys_required;
80         guint16 pe_dll_flags;
81         guint32 pe_stack_reserve;
82         guint32 pe_stack_commit;
83         guint32 pe_heap_reserve;
84         guint32 pe_heap_commit;
85         guint32 pe_loader_flags;
86         guint32 pe_data_dir_count;
87 } MonoPEHeaderNT;
88
89 typedef struct {
90         guint32 rva;
91         guint32 size;
92 } MonoPEDirEntry;
93
94 /* 128 bytes */
95 typedef struct {
96         MonoPEDirEntry pe_export_table;
97         MonoPEDirEntry pe_import_table;
98         MonoPEDirEntry pe_resource_table;
99         MonoPEDirEntry pe_exception_table;
100         MonoPEDirEntry pe_certificate_table;
101         MonoPEDirEntry pe_reloc_table;
102         MonoPEDirEntry pe_debug;
103         MonoPEDirEntry pe_copyright;
104         MonoPEDirEntry pe_global_ptr;
105         MonoPEDirEntry pe_tls_table;
106         MonoPEDirEntry pe_load_config_table;
107         MonoPEDirEntry pe_bound_import;
108         MonoPEDirEntry pe_iat;
109         MonoPEDirEntry pe_delay_import_desc;
110         MonoPEDirEntry pe_cli_header;
111         MonoPEDirEntry pe_reserved;
112 } MonoPEDatadir;
113
114 /* 248 bytes */
115 typedef struct {
116         char            pesig [4];
117         MonoCOFFHeader  coff;
118         MonoPEHeader    pe;
119         MonoPEHeaderNT  nt;
120         MonoPEDatadir   datadir;
121 } MonoDotNetHeader;
122
123 typedef struct {
124         char    st_name [8];
125         guint32 st_virtual_size;
126         guint32 st_virtual_address;
127         guint32 st_raw_data_size;
128         guint32 st_raw_data_ptr;
129         guint32 st_reloc_ptr;
130         guint32 st_lineno_ptr;
131         guint16 st_reloc_count;
132         guint16 st_line_count;
133
134 #define SECT_FLAGS_HAS_CODE               0x20
135 #define SECT_FLAGS_HAS_INITIALIZED_DATA   0x40
136 #define SECT_FLAGS_HAS_UNINITIALIZED_DATA 0x80
137 #define SECT_FLAGS_MEM_DISCARDABLE        0x02000000
138 #define SECT_FLAGS_MEM_NOT_CACHED         0x04000000
139 #define SECT_FLAGS_MEM_NOT_PAGED          0x08000000
140 #define SECT_FLAGS_MEM_SHARED             0x10000000
141 #define SECT_FLAGS_MEM_EXECUTE            0x20000000
142 #define SECT_FLAGS_MEM_READ               0x40000000
143 #define SECT_FLAGS_MEM_WRITE              0x80000000
144         guint32 st_flags;
145
146 } MonoSectionTable;
147
148 typedef struct {
149         guint32        ch_size;
150         guint16        ch_runtime_major;
151         guint16        ch_runtime_minor;
152         MonoPEDirEntry ch_metadata;
153
154 #define CLI_FLAGS_ILONLY         0x01
155 #define CLI_FLAGS_32BITREQUIRED  0x02
156 #define CLI_FLAGS_TRACKDEBUGDATA 0x00010000
157         guint32        ch_flags;
158
159         guint32        ch_entry_point;
160         MonoPEDirEntry ch_resources;
161         MonoPEDirEntry ch_strong_name;
162         MonoPEDirEntry ch_code_manager_table;
163         MonoPEDirEntry ch_vtable_fixups;
164         MonoPEDirEntry ch_export_address_table_jumps;
165
166         /* The following are zero in the current docs */
167         MonoPEDirEntry ch_eeinfo_table;
168         MonoPEDirEntry ch_helper_table;
169         MonoPEDirEntry ch_dynamic_info;
170         MonoPEDirEntry ch_delay_load_info;
171         MonoPEDirEntry ch_module_image;
172         MonoPEDirEntry ch_external_fixups;
173         MonoPEDirEntry ch_ridmap;
174         MonoPEDirEntry ch_debug_map;
175         MonoPEDirEntry ch_ip_map;
176 } MonoCLIHeader;
177
178 /* This is not an on-disk structure */
179 typedef struct {
180         MonoDotNetHeader  cli_header;
181         int               cli_section_count;
182         MonoSectionTable  *cli_section_tables;
183         void            **cli_sections;
184         MonoCLIHeader     cli_cli_header;
185 } MonoCLIImageInfo;
186
187 guint32       mono_cli_rva_image_map (MonoCLIImageInfo *iinfo, guint32 rva);
188 char         *mono_cli_rva_map       (MonoCLIImageInfo *iinfo, guint32 rva);
189
190 #endif /* __MONO_CIL_COFF_H__ */