2 #ifndef __MONO_CIL_COFF_H__
3 #define __MONO_CIL_COFF_H__
5 #include <mono/metadata/metadata.h>
8 * 25.2.1: Method header type values
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
16 * 25.2.3.1: Flags for method headers
18 #define METHOD_HEADER_INIT_LOCALS 0x10
19 #define METHOD_HEADER_MORE_SECTS 0x08
22 * For section data (25.3)
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
35 char msdos_header
[54];
37 char msdos_header2
[64];
43 guint16 coff_sections
;
46 guint32 coff_symcount
;
47 guint16 coff_opt_header_size
;
48 guint16 coff_attributes
;
51 #define COFF_ATTRIBUTE_EXECUTABLE_IMAGE 0x0002
52 #define COFF_ATTRIBUTE_LIBRARY_IMAGE 0x2000
61 guint32 pe_uninit_data_size
;
62 guint32 pe_rva_entry_point
;
63 guint32 pe_rva_code_base
;
64 guint32 pe_rva_data_base
;
74 guint32 pe_uninit_data_size
;
75 guint32 pe_rva_entry_point
;
76 guint32 pe_rva_code_base
;
81 guint32 pe_image_base
; /* must be 0x400000 */
82 guint32 pe_section_align
; /* must be 8192 */
83 guint32 pe_file_alignment
; /* must be 512 or 4096 */
84 guint16 pe_os_major
; /* must be 4 */
85 guint16 pe_os_minor
; /* must be 0 */
86 guint16 pe_user_major
;
87 guint16 pe_user_minor
;
88 guint16 pe_subsys_major
;
89 guint16 pe_subsys_minor
;
90 guint32 pe_reserved_1
;
91 guint32 pe_image_size
;
92 guint32 pe_header_size
;
94 guint16 pe_subsys_required
;
96 guint32 pe_stack_reserve
;
97 guint32 pe_stack_commit
;
98 guint32 pe_heap_reserve
;
99 guint32 pe_heap_commit
;
100 guint32 pe_loader_flags
;
101 guint32 pe_data_dir_count
;
106 guint64 pe_image_base
;
107 guint32 pe_section_align
; /* must be 8192 */
108 guint32 pe_file_alignment
; /* must be 512 or 4096 */
109 guint16 pe_os_major
; /* must be 4 */
110 guint16 pe_os_minor
; /* must be 0 */
111 guint16 pe_user_major
;
112 guint16 pe_user_minor
;
113 guint16 pe_subsys_major
;
114 guint16 pe_subsys_minor
;
115 guint32 pe_reserved_1
;
116 guint32 pe_image_size
;
117 guint32 pe_header_size
;
119 guint16 pe_subsys_required
;
120 guint16 pe_dll_flags
;
121 guint64 pe_stack_reserve
;
122 guint64 pe_stack_commit
;
123 guint64 pe_heap_reserve
;
124 guint64 pe_heap_commit
;
125 guint32 pe_loader_flags
;
126 guint32 pe_data_dir_count
;
130 guint32 rde_data_offset
;
132 guint32 rde_codepage
;
133 guint32 rde_reserved
;
134 } MonoPEResourceDataEntry
;
136 #define MONO_PE_RESOURCE_ID_CURSOR 0x01
137 #define MONO_PE_RESOURCE_ID_BITMAP 0x02
138 #define MONO_PE_RESOURCE_ID_ICON 0x03
139 #define MONO_PE_RESOURCE_ID_MENU 0x04
140 #define MONO_PE_RESOURCE_ID_DIALOG 0x05
141 #define MONO_PE_RESOURCE_ID_STRING 0x06
142 #define MONO_PE_RESOURCE_ID_FONTDIR 0x07
143 #define MONO_PE_RESOURCE_ID_FONT 0x08
144 #define MONO_PE_RESOURCE_ID_ACCEL 0x09
145 #define MONO_PE_RESOURCE_ID_RCDATA 0x0a
146 #define MONO_PE_RESOURCE_ID_MESSAGETABLE 0x0b
147 #define MONO_PE_RESOURCE_ID_GROUP_CURSOR 0x0c
148 #define MONO_PE_RESOURCE_ID_GROUP_ICON 0x0d
149 #define MONO_PE_RESOURCE_ID_VERSION 0x10
150 #define MONO_PE_RESOURCE_ID_DLGINCLUDE 0x11
151 #define MONO_PE_RESOURCE_ID_PLUGPLAY 0x13
152 #define MONO_PE_RESOURCE_ID_VXD 0x14
153 #define MONO_PE_RESOURCE_ID_ANICURSOR 0x15
154 #define MONO_PE_RESOURCE_ID_ANIICON 0x16
155 #define MONO_PE_RESOURCE_ID_HTML 0x17
156 #define MONO_PE_RESOURCE_ID_ASPNET_STRING 0x65
159 /* If the MSB is set, then the other 31 bits store the RVA of
160 * the unicode string containing the name. Otherwise, the
161 * other 31 bits contain the ID of this entry.
165 /* If the MSB is set, then the other 31 bits store the RVA of
166 * another subdirectory. Otherwise, the other 31 bits store
167 * the RVA of the resource data entry leaf node.
170 } MonoPEResourceDirEntry
;
172 #define MONO_PE_RES_DIR_ENTRY_NAME_IS_STRING(d) (GUINT32_FROM_LE((d).name) >> 31)
173 #define MONO_PE_RES_DIR_ENTRY_NAME_OFFSET(d) (GUINT32_FROM_LE((d).name) & 0x7fffffff)
174 #define MONO_PE_RES_DIR_ENTRY_SET_NAME(d,i,o) ((d).name = GUINT32_TO_LE(((guint32)((i)?1:0) << 31) | ((o) & 0x7fffffff)))
176 #define MONO_PE_RES_DIR_ENTRY_IS_DIR(d) (GUINT32_FROM_LE((d).dir) >> 31)
177 #define MONO_PE_RES_DIR_ENTRY_DIR_OFFSET(d) (GUINT32_FROM_LE((d).dir) & 0x7fffffff)
178 #define MONO_PE_RES_DIR_ENTRY_SET_DIR(d,i,o) ((d).dir = GUINT32_TO_LE(((guint32)((i)?1:0) << 31) | ((o) & 0x7fffffff)))
182 guint32 res_characteristics
;
183 guint32 res_date_stamp
;
186 guint16 res_named_entries
;
187 guint16 res_id_entries
;
188 /* Directory entries follow on here. The array is
189 * res_named_entries + res_id_entries long, containing all
190 * named entries first.
201 MonoPEDirEntry pe_export_table
;
202 MonoPEDirEntry pe_import_table
;
203 MonoPEDirEntry pe_resource_table
;
204 MonoPEDirEntry pe_exception_table
;
205 MonoPEDirEntry pe_certificate_table
;
206 MonoPEDirEntry pe_reloc_table
;
207 MonoPEDirEntry pe_debug
;
208 MonoPEDirEntry pe_copyright
;
209 MonoPEDirEntry pe_global_ptr
;
210 MonoPEDirEntry pe_tls_table
;
211 MonoPEDirEntry pe_load_config_table
;
212 MonoPEDirEntry pe_bound_import
;
213 MonoPEDirEntry pe_iat
;
214 MonoPEDirEntry pe_delay_import_desc
;
215 MonoPEDirEntry pe_cli_header
;
216 MonoPEDirEntry pe_reserved
;
225 MonoPEDatadir datadir
;
226 } MonoDotNetHeader32
;
234 MonoPEDatadir datadir
;
243 MonoPEDatadir datadir
;
244 } MonoDotNetHeader64
;
246 #define VTFIXUP_TYPE_32BIT 0x01
247 #define VTFIXUP_TYPE_64BIT 0x02
248 #define VTFIXUP_TYPE_FROM_UNMANAGED 0x04
249 #define VTFIXUP_TYPE_FROM_UNMANAGED_RETAIN_APPDOMAIN 0x08
250 #define VTFIXUP_TYPE_CALL_MOST_DERIVED 0x10
260 guint32 st_virtual_size
;
261 guint32 st_virtual_address
;
262 guint32 st_raw_data_size
;
263 guint32 st_raw_data_ptr
;
264 guint32 st_reloc_ptr
;
265 guint32 st_lineno_ptr
;
266 guint16 st_reloc_count
;
267 guint16 st_line_count
;
269 #define SECT_FLAGS_HAS_CODE 0x20
270 #define SECT_FLAGS_HAS_INITIALIZED_DATA 0x40
271 #define SECT_FLAGS_HAS_UNINITIALIZED_DATA 0x80
272 #define SECT_FLAGS_MEM_DISCARDABLE 0x02000000
273 #define SECT_FLAGS_MEM_NOT_CACHED 0x04000000
274 #define SECT_FLAGS_MEM_NOT_PAGED 0x08000000
275 #define SECT_FLAGS_MEM_SHARED 0x10000000
276 #define SECT_FLAGS_MEM_EXECUTE 0x20000000
277 #define SECT_FLAGS_MEM_READ 0x40000000
278 #define SECT_FLAGS_MEM_WRITE 0x80000000
285 guint16 ch_runtime_major
;
286 guint16 ch_runtime_minor
;
287 MonoPEDirEntry ch_metadata
;
289 #define CLI_FLAGS_ILONLY 0x01
290 #define CLI_FLAGS_32BITREQUIRED 0x02
291 #define CLI_FLAGS_STRONGNAMESIGNED 0x8
292 #define CLI_FLAGS_TRACKDEBUGDATA 0x00010000
295 guint32 ch_entry_point
;
296 MonoPEDirEntry ch_resources
;
297 MonoPEDirEntry ch_strong_name
;
298 MonoPEDirEntry ch_code_manager_table
;
299 MonoPEDirEntry ch_vtable_fixups
;
300 MonoPEDirEntry ch_export_address_table_jumps
;
302 /* The following are zero in the current docs */
303 MonoPEDirEntry ch_eeinfo_table
;
304 MonoPEDirEntry ch_helper_table
;
305 MonoPEDirEntry ch_dynamic_info
;
306 MonoPEDirEntry ch_delay_load_info
;
307 MonoPEDirEntry ch_module_image
;
308 MonoPEDirEntry ch_external_fixups
;
309 MonoPEDirEntry ch_ridmap
;
310 MonoPEDirEntry ch_debug_map
;
311 MonoPEDirEntry ch_ip_map
;
314 /* This is not an on-disk structure */
316 MonoDotNetHeader cli_header
;
317 int cli_section_count
;
318 MonoSectionTable
*cli_section_tables
;
320 MonoCLIHeader cli_cli_header
;
323 guint32
mono_cli_rva_image_map (MonoImage
*image
, guint32 rva
);
325 #endif /* __MONO_CIL_COFF_H__ */