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