test/amd64: build and install modules
[dragonfly.git] / sys / emulation / ndis / pe_var.h
blob42fbb5e74c7b72d13d828365723acd5d0f133b66
1 /*
2 * Copyright (c) 2003
3 * Bill Paul <wpaul@windriver.com>. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by Bill Paul.
16 * 4. Neither the name of the author nor the names of any co-contributors
17 * may be used to endorse or promote products derived from this software
18 * without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY Bill Paul AND CONTRIBUTORS ``AS IS'' AND
21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL Bill Paul OR THE VOICES IN HIS HEAD
24 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
30 * THE POSSIBILITY OF SUCH DAMAGE.
32 * $FreeBSD: src/sys/compat/ndis/pe_var.h,v 1.7 2004/04/14 07:48:02 wpaul Exp $
33 * $DragonFly: src/sys/emulation/ndis/pe_var.h,v 1.1 2004/07/29 20:51:34 dillon Exp $
36 #ifndef _PE_VAR_H_
37 #define _PE_VAR_H_
40 * Image Format
43 #define IMAGE_DOS_SIGNATURE 0x5A4D /* MZ */
44 #define IMAGE_OS2_SIGNATURE 0x454E /* NE */
45 #define IMAGE_OS2_SIGNATURE_LE 0x454C /* LE */
46 #define IMAGE_VXD_SIGNATURE 0x454C /* LE */
47 #define IMAGE_NT_SIGNATURE 0x00004550 /* PE00 */
50 * All PE files have one of these, just so if you attempt to
51 * run them, they'll print out a message telling you they can
52 * only be run in Windows.
55 struct image_dos_header {
56 uint16_t idh_magic; /* Magic number */
57 uint16_t idh_cblp; /* Bytes on last page of file */
58 uint16_t idh_cp; /* Pages in file */
59 uint16_t idh_crlc; /* Relocations */
60 uint16_t idh_cparhdr; /* Size of header in paragraphs */
61 uint16_t idh_minalloc; /* Minimum extra paragraphs needed */
62 uint16_t idh_maxalloc; /* Maximum extra paragraphs needed */
63 uint16_t idh_ss; /* Initial (relative) SS value */
64 uint16_t idh_sp; /* Initial SP value */
65 uint16_t idh_csum; /* Checksum */
66 uint16_t idh_ip; /* Initial IP value */
67 uint16_t idh_cs; /* Initial (relative) CS value */
68 uint16_t idh_lfarlc; /* File address of relocation table */
69 uint16_t idh_ovno; /* Overlay number */
70 uint16_t idh_rsvd1[4]; /* Reserved words */
71 uint16_t idh_oemid; /* OEM identifier (for idh_oeminfo) */
72 uint16_t idh_oeminfo; /* OEM information; oemid specific */
73 uint16_t idh_rsvd2[10]; /* Reserved words */
74 uint32_t idh_lfanew; /* File address of new exe header */
77 typedef struct image_dos_header image_dos_header;
80 * File header format.
83 struct image_file_header {
84 uint16_t ifh_machine; /* Machine type */
85 uint16_t ifh_numsections; /* # of sections */
86 uint32_t ifh_timestamp; /* Date/time stamp */
87 uint32_t ifh_symtblptr; /* Offset to symbol table */
88 uint32_t ifh_numsyms; /* # of symbols */
89 uint16_t ifh_optionalhdrlen; /* Size of optional header */
90 uint16_t ifh_characteristics; /* Characteristics */
93 typedef struct image_file_header image_file_header;
95 /* Machine types */
97 #define IMAGE_FILE_MACHINE_UNKNOWN 0
98 #define IMAGE_FILE_MACHINE_I860 0x014d
99 #define IMAGE_FILE_MACHINE_I386 0x014c
100 #define IMAGE_FILE_MACHINE_R3000 0x0162
101 #define IMAGE_FILE_MACHINE_R4000 0x0166
102 #define IMAGE_FILE_MACHINE_R10000 0x0168
103 #define IMAGE_FILE_MACHINE_WCEMIPSV2 0x0169
104 #define IMAGE_FILE_MACHINE_ALPHA 0x0184
105 #define IMAGE_FILE_MACHINE_SH3 0x01a2
106 #define IMAGE_FILE_MACHINE_SH3DSP 0x01a3
107 #define IMAGE_FILE_MACHINE_SH3E 0x01a4
108 #define IMAGE_FILE_MACHINE_SH4 0x01a6
109 #define IMAGE_FILE_MACHINE_SH5 0x01a8
110 #define IMAGE_FILE_MACHINE_ARM 0x01c0
111 #define IMAGE_FILE_MACHINE_THUMB 0x01c2
112 #define IMAGE_FILE_MACHINE_AM33 0x01d3
113 #define IMAGE_FILE_MACHINE_POWERPC 0x01f0
114 #define IMAGE_FILE_MACHINE_POWERPCFP 0x01f1
115 #define IMAGE_FILE_MACHINE_IA64 0x0200
116 #define IMAGE_FILE_MACHINE_MIPS16 0x0266
117 #define IMAGE_FILE_MACHINE_ALPHA64 0x0284
118 #define IMAGE_FILE_MACHINE_MIPSFPU 0x0366
119 #define IMAGE_FILE_MACHINE_MIPSFPU16 0x0466
120 #define IMAGE_FILE_MACHINE_AXP64 IMAGE_FILE_MACHINE_ALPHA64
121 #define IMAGE_FILE_MACHINE_TRICORE 0x0520
122 #define IMAGE_FILE_MACHINE_CEF 0x0cef
123 #define IMAGE_FILE_MACHINE_EBC 0x0ebc
124 #define IMAGE_FILE_MACHINE_AMD64 0x8664
125 #define IMAGE_FILE_MACHINE_M32R 0x9041
126 #define IMAGE_FILE_MACHINE_CEE 0xc0ee
128 /* Characteristics */
130 #define IMAGE_FILE_RELOCS_STRIPPED 0x0001 /* No relocation info */
131 #define IMAGE_FILE_EXECUTABLE_IMAGE 0x0002
132 #define IMAGE_FILE_LINE_NUMS_STRIPPED 0x0004
133 #define IMAGE_FILE_LOCAL_SYMS_STRIPPED 0x0008
134 #define IMAGE_FILE_AGGRESIVE_WS_TRIM 0x0010
135 #define IMAGE_FILE_LARGE_ADDRESS_AWARE 0x0020
136 #define IMAGE_FILE_16BIT_MACHINE 0x0040
137 #define IMAGE_FILE_BYTES_REVERSED_LO 0x0080
138 #define IMAGE_FILE_32BIT_MACHINE 0x0100
139 #define IMAGE_FILE_DEBUG_STRIPPED 0x0200
140 #define IMAGE_FILE_REMOVABLE_RUN_FROM_SWAP 0x0400
141 #define IMAGE_FILE_NET_RUN_FROM_SWAP 0x0800
142 #define IMAGE_FILE_SYSTEM 0x1000
143 #define IMAGE_FILE_DLL 0x2000
144 #define IMAGE_FILE_UP_SYSTEM_ONLY 0x4000
145 #define IMAGE_FILE_BYTES_REVERSED_HI 0x8000
147 #define IMAGE_SIZEOF_FILE_HEADER 20
150 * Directory format.
153 struct image_data_directory {
154 uint32_t idd_vaddr; /* virtual address */
155 uint32_t idd_size; /* size */
158 typedef struct image_data_directory image_data_directory;
160 #define IMAGE_DIRECTORY_ENTRIES_MAX 16
163 * Optional header format.
166 struct image_optional_header {
168 /* Standard fields */
170 uint16_t ioh_magic;
171 uint8_t ioh_linkerver_major;
172 uint8_t ioh_linkerver_minor;
173 uint32_t ioh_codesize;
174 uint32_t ioh_datasize;
175 uint32_t ioh_bsssize;
176 uint32_t ioh_entryaddr;
177 uint32_t ioh_codebaseaddr;
178 uint32_t ioh_databaseaddr;
180 /* NT-specific fields */
182 uint32_t ioh_imagebase;
183 uint32_t ioh_sectalign;
184 uint32_t ioh_filealign;
185 uint16_t ioh_osver_major;
186 uint16_t ioh_osver_minor;
187 uint16_t ioh_imagever_major;
188 uint16_t ioh_imagever_minor;
189 uint16_t ioh_subsys_major;
190 uint16_t ioh_subsys_minor;
191 uint32_t ioh_win32ver;
192 uint32_t ioh_imagesize;
193 uint32_t ioh_headersize;
194 uint32_t ioh_csum;
195 uint16_t ioh_subsys;
196 uint16_t ioh_dll_characteristics;
197 uint32_t ioh_stackreservesize;
198 uint32_t ioh_stackcommitsize;
199 uint32_t ioh_heapreservesize;
200 uint32_t ioh_heapcommitsize;
201 uint16_t ioh_loaderflags;
202 uint32_t ioh_rva_size_cnt;
203 image_data_directory ioh_datadir[IMAGE_DIRECTORY_ENTRIES_MAX];
206 typedef struct image_optional_header image_optional_header;
208 struct image_nt_header {
209 uint32_t inh_signature;
210 image_file_header inh_filehdr;
211 image_optional_header inh_optionalhdr;
214 typedef struct image_nt_header image_nt_header;
216 /* Directory Entries */
218 #define IMAGE_DIRECTORY_ENTRY_EXPORT 0 /* Export Directory */
219 #define IMAGE_DIRECTORY_ENTRY_IMPORT 1 /* Import Directory */
220 #define IMAGE_DIRECTORY_ENTRY_RESOURCE 2 /* Resource Directory */
221 #define IMAGE_DIRECTORY_ENTRY_EXCEPTION 3 /* Exception Directory */
222 #define IMAGE_DIRECTORY_ENTRY_SECURITY 4 /* Security Directory */
223 #define IMAGE_DIRECTORY_ENTRY_BASERELOC 5 /* Base Relocation Table */
224 #define IMAGE_DIRECTORY_ENTRY_DEBUG 6 /* Debug Directory */
225 #define IMAGE_DIRECTORY_ENTRY_COPYRIGHT 7 /* Description String */
226 #define IMAGE_DIRECTORY_ENTRY_GLOBALPTR 8 /* Machine Value (MIPS GP) */
227 #define IMAGE_DIRECTORY_ENTRY_TLS 9 /* TLS Directory */
228 #define IMAGE_DIRECTORY_ENTRY_LOAD_CONFIG 10 /* Load Configuration Directory */
229 #define IMAGE_DIRECTORY_ENTRY_BOUND_IMPORT 11 /* Bound Import Directory in headers */
230 #define IMAGE_DIRECTORY_ENTRY_IAT 12 /* Import Address Table */
231 #define IMAGE_DIRECTORY_ENTRY_DELAY_IMPORT 13
232 #define IMAGE_DIRECTORY_ENTRY_COM_DESCRIPTOR 14
234 /* Resource types */
236 #define RT_CURSOR 1
237 #define RT_BITMAP 2
238 #define RT_ICON 3
239 #define RT_MENU 4
240 #define RT_DIALOG 5
241 #define RT_STRING 6
242 #define RT_FONTDIR 7
243 #define RT_FONT 8
244 #define RT_ACCELERATOR 9
245 #define RT_RCDATA 10
246 #define RT_MESSAGETABLE 11
247 #define RT_GROUP_CURSOR 12
248 #define RT_GROUP_ICON 14
249 #define RT_VERSION 16
250 #define RT_DLGINCLUDE 17
251 #define RT_PLUGPLAY 19
252 #define RT_VXD 20
253 #define RT_ANICURSOR 21
254 #define RT_ANIICON 22
255 #define RT_HTML 23
258 * Section header format.
261 #define IMAGE_SHORT_NAME_LEN 8
263 struct image_section_header {
264 uint8_t ish_name[IMAGE_SHORT_NAME_LEN];
265 union {
266 uint32_t ish_paddr;
267 uint32_t ish_vsize;
268 } ish_misc;
269 uint32_t ish_vaddr;
270 uint32_t ish_rawdatasize;
271 uint32_t ish_rawdataaddr;
272 uint32_t ish_relocaddr;
273 uint32_t ish_linenumaddr;
274 uint16_t ish_numrelocs;
275 uint16_t ish_numlinenums;
276 uint32_t ish_characteristics;
279 typedef struct image_section_header image_section_header;
281 #define IMAGE_SIZEOF_SECTION_HEADER 40
284 * Import format
287 struct image_import_by_name {
288 uint16_t iibn_hint;
289 u_int8_t iibn_name[1];
292 #define IMAGE_ORDINAL_FLAG 0x80000000
293 #define IMAGE_ORDINAL(Ordinal) (Ordinal & 0xffff)
295 struct image_import_descriptor {
296 uint32_t iid_import_name_table_addr;
297 uint32_t iid_timestamp;
298 uint32_t iid_forwardchain;
299 uint32_t iid_nameaddr;
300 uint32_t iid_import_address_table_addr;
303 typedef struct image_import_descriptor image_import_descriptor;
305 struct image_base_reloc {
306 uint32_t ibr_vaddr;
307 uint32_t ibr_blocksize;
308 uint16_t ibr_rel[1];
311 typedef struct image_base_reloc image_base_reloc;
313 #define IMR_RELTYPE(x) ((x >> 12) & 0xF)
314 #define IMR_RELOFFSET(x) (x & 0xFFF)
316 /* generic relocation types */
317 #define IMAGE_REL_BASED_ABSOLUTE 0
318 #define IMAGE_REL_BASED_HIGH 1
319 #define IMAGE_REL_BASED_LOW 2
320 #define IMAGE_REL_BASED_HIGHLOW 3
321 #define IMAGE_REL_BASED_HIGHADJ 4
322 #define IMAGE_REL_BASED_MIPS_JMPADDR 5
323 #define IMAGE_REL_BASED_SECTION 6
324 #define IMAGE_REL_BASED_REL 7
325 #define IMAGE_REL_BASED_MIPS_JMPADDR16 9
326 #define IMAGE_REL_BASED_IA64_IMM64 9 /* yes, 9 too */
327 #define IMAGE_REL_BASED_DIR64 10
328 #define IMAGE_REL_BASED_HIGH3ADJ 11
330 struct image_resource_directory_entry {
331 uint32_t irde_name;
332 uint32_t irde_dataoff;
335 typedef struct image_resource_directory_entry image_resource_directory_entry;
337 #define RESOURCE_NAME_STR 0x80000000
338 #define RESOURCE_DIR_FLAG 0x80000000
340 struct image_resource_directory {
341 uint32_t ird_characteristics;
342 uint32_t ird_timestamp;
343 uint16_t ird_majorver;
344 uint16_t ird_minorver;
345 uint16_t ird_named_entries;
346 uint16_t ird_id_entries;
347 #ifdef notdef
348 image_resource_directory_entry ird_entries[1];
349 #endif
352 typedef struct image_resource_directory image_resource_directory;
354 struct image_resource_directory_string {
355 uint16_t irds_len;
356 char irds_name[1];
359 typedef struct image_resource_directory_string image_resource_directory_string;
361 struct image_resource_directory_string_u {
362 uint16_t irds_len;
363 char irds_name[1];
366 typedef struct image_resource_directory_string_u
367 image_resource_directory_string_u;
369 struct image_resource_data_entry {
370 uint32_t irde_offset;
371 uint32_t irde_size;
372 uint32_t irde_codepage;
373 uint32_t irde_rsvd;
376 typedef struct image_resource_data_entry image_resource_data_entry;
378 struct message_resource_data {
379 uint32_t mrd_numblocks;
380 #ifdef notdef
381 message_resource_block mrd_blocks[1];
382 #endif
385 typedef struct message_resource_data message_resource_data;
387 struct message_resource_block {
388 uint32_t mrb_lowid;
389 uint32_t mrb_highid;
390 uint32_t mrb_entryoff;
393 typedef struct message_resource_block message_resource_block;
395 struct message_resource_entry {
396 uint16_t mre_len;
397 uint16_t mre_flags;
398 char mre_text[0];
401 typedef struct message_resource_entry message_resource_entry;
403 #define MESSAGE_RESOURCE_UNICODE 0x0001
405 struct image_patch_table {
406 char *ipt_name;
407 void (*ipt_func)(void);
410 typedef struct image_patch_table image_patch_table;
412 __BEGIN_DECLS
413 extern int pe_get_dos_header(vm_offset_t, image_dos_header *);
414 extern int pe_is_nt_image(vm_offset_t);
415 extern int pe_get_optional_header(vm_offset_t, image_optional_header *);
416 extern int pe_get_file_header(vm_offset_t, image_file_header *);
417 extern int pe_get_section_header(vm_offset_t, image_section_header *);
418 extern int pe_numsections(vm_offset_t);
419 extern vm_offset_t pe_imagebase(vm_offset_t);
420 extern vm_offset_t pe_directory_offset(vm_offset_t, uint32_t);
421 extern vm_offset_t pe_translate_addr (vm_offset_t, uint32_t);
422 extern int pe_get_section(vm_offset_t, image_section_header *, const char *);
423 extern int pe_relocate(vm_offset_t);
424 extern int pe_get_import_descriptor(vm_offset_t, image_import_descriptor *, char *);
425 extern int pe_patch_imports(vm_offset_t, char *, image_patch_table *);
426 extern int pe_get_messagetable(vm_offset_t, message_resource_data **);
427 extern int pe_get_message(vm_offset_t, uint32_t, char **, int *, uint16_t *);
428 __END_DECLS
430 #endif /* _PE_VAR_H_ */