2001-07-20 Miguel de Icaza <miguel@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 /* A metadata token */
8 typedef guint32 mtoken_t;
9
10 typedef struct {
11         char msdos_header [128];
12 } msdos_header_t;
13
14 typedef struct {
15         guint16  coff_machine;
16         guint16  coff_sections;
17         guint32  coff_time;
18         guint32  coff_symptr;
19         guint32  coff_symcount;
20         guint16  coff_opt_header_size;
21         guint16  coff_attributes;
22 } coff_header_t;
23
24 #define COFF_ATTRIBUTE_EXECUTABLE_IMAGE 0x0002
25 #define COFF_ATTRIBUTE_LIBRARY_IMAGE    0x2000
26
27 typedef struct {
28         guint16 pe_magic;
29         guchar  pe_major;
30         guchar  pe_minor;
31         guint32 pe_code_size;
32         guint32 pe_data_size;
33         guint32 pe_uninit_data_size;
34         guint32 pe_rva_entry_point;
35         guint32 pe_rva_code_base;
36         guint32 pe_rva_data_base;
37 } pe_header_t;
38
39 typedef struct {
40         guint32 pe_image_base;          /* must be 0x400000 */
41         guint32 pe_section_align;       /* must be 8192 */
42         guint32 pe_file_alignment;      /* must be 512 or 4096 */
43         guint16 pe_os_major;            /* must be 4 */
44         guint16 pe_os_minor;            /* must be 0 */
45         guint16 pe_user_major;
46         guint16 pe_user_minor;
47         guint16 pe_subsys_major;
48         guint16 pe_subsys_minor;
49         guint32 pe_reserved_1;
50         guint32 pe_image_size;
51         guint32 pe_header_size;
52         guint32 pe_checksum;
53         guint16 pe_subsys_required;
54         guint16 pe_dll_flags;
55         guint32 pe_stack_reserve;
56         guint32 pe_stack_commit;
57         guint32 pe_heap_reserve;
58         guint32 pe_heap_commit;
59         guint32 pe_loader_flags;
60         guint32 pe_data_dir_count;
61 } pe_header_nt_t;
62
63 typedef struct {
64         guint32 rva;
65         guint32 size;
66 } pe_dir_entry_t;
67
68 typedef struct {
69         pe_dir_entry_t pe_export_table;
70         pe_dir_entry_t pe_import_table;
71         pe_dir_entry_t pe_resource_table;
72         pe_dir_entry_t pe_exception_table;
73         pe_dir_entry_t pe_certificate_table;
74         pe_dir_entry_t pe_reloc_table;
75         pe_dir_entry_t pe_debug;
76         pe_dir_entry_t pe_copyright;
77         pe_dir_entry_t pe_global_ptr;
78         pe_dir_entry_t pe_tls_table;
79         pe_dir_entry_t pe_load_config_table;
80         pe_dir_entry_t pe_bound_import;
81         pe_dir_entry_t pe_iat;
82         pe_dir_entry_t pe_delay_import_desc;
83         pe_dir_entry_t pe_cli_header;
84         pe_dir_entry_t pe_reserved;
85 } pe_datadir_t;
86
87 typedef struct {
88         char            pesig [4];
89         coff_header_t   coff;
90         pe_header_t     pe;
91         pe_header_nt_t  nt;
92         pe_datadir_t    datadir;
93 } dotnet_header_t;
94
95 typedef struct {
96         char    st_name [8];
97         guint32 st_virtual_size;
98         guint32 st_virtual_address;
99         guint32 st_raw_data_size;
100         guint32 st_raw_data_ptr;
101         guint32 st_reloc_ptr;
102         guint32 st_lineno_ptr;
103         guint16 st_reloc_count;
104         guint16 st_line_count;
105
106 #define SECT_FLAGS_HAS_CODE               0x20
107 #define SECT_FLAGS_HAS_INITIALIZED_DATA   0x40
108 #define SECT_FLAGS_HAS_UNINITIALIZED_DATA 0x80
109 #define SECT_FLAGS_MEM_DISCARDABLE        0x02000000
110 #define SECT_FLAGS_MEM_NOT_CACHED         0x04000000
111 #define SECT_FLAGS_MEM_NOT_PAGED          0x08000000
112 #define SECT_FLAGS_MEM_SHARED             0x10000000
113 #define SECT_FLAGS_MEM_EXECUTE            0x20000000
114 #define SECT_FLAGS_MEM_READ               0x40000000
115 #define SECT_FLAGS_MEM_WRITE              0x80000000
116         guint32 st_flags;
117
118 } section_table_t;
119
120 typedef struct {
121         guint32        ch_size;
122         guint16        ch_runtime_major;
123         guint16        ch_runtime_minor;
124         pe_dir_entry_t ch_metadata;
125
126 #define CLI_FLAGS_ILONLY         0x01
127 #define CLI_FLAGS_32BITREQUIRED  0x02
128 #define CLI_FLAGS_TRACKDEBUGDATA 0x00010000
129         guint32        ch_flags;
130
131         mtoken_t       ch_entry_point;
132         pe_dir_entry_t ch_resources;
133         pe_dir_entry_t ch_strong_name;
134         pe_dir_entry_t ch_code_manager_table;
135         pe_dir_entry_t ch_vtable_fixups;
136         pe_dir_entry_t ch_export_address_table_jumps;
137
138         /* The following are zero in the current docs */
139         pe_dir_entry_t ch_eeinfo_table;
140         pe_dir_entry_t ch_helper_table;
141         pe_dir_entry_t ch_dynamic_info;
142         pe_dir_entry_t ch_delay_load_info;
143         pe_dir_entry_t ch_module_image;
144         pe_dir_entry_t ch_external_fixups;
145         pe_dir_entry_t ch_ridmap;
146         pe_dir_entry_t ch_debug_map;
147         pe_dir_entry_t ch_ip_map;
148 } cli_header_t;
149
150 /* This is not an on-disk structure */
151 typedef struct {
152         dotnet_header_t   cli_header;
153         int               cli_section_count;
154         section_table_t  *cli_section_tables;
155         void            **cli_sections;
156         cli_header_t      cli_cli_header;
157
158         metadata_t        cli_metadata;
159 } cli_image_info_t;
160
161 guint32       cli_rva_image_map (cli_image_info_t *iinfo, guint32 rva);
162 char         *cli_rva_map       (cli_image_info_t *iinfo, guint32 rva);
163
164 #endif /* __MONO_CIL_COFF_H__ */