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