pe_var.h revision 141963
1259698Sdim/*-
2259698Sdim * Copyright (c) 2003
3259698Sdim *	Bill Paul <wpaul@windriver.com>.  All rights reserved.
4259698Sdim *
5259698Sdim * Redistribution and use in source and binary forms, with or without
6259698Sdim * modification, are permitted provided that the following conditions
7259698Sdim * are met:
8259698Sdim * 1. Redistributions of source code must retain the above copyright
9259698Sdim *    notice, this list of conditions and the following disclaimer.
10259698Sdim * 2. Redistributions in binary form must reproduce the above copyright
11259698Sdim *    notice, this list of conditions and the following disclaimer in the
12259698Sdim *    documentation and/or other materials provided with the distribution.
13259698Sdim * 3. All advertising materials mentioning features or use of this software
14259698Sdim *    must display the following acknowledgement:
15259698Sdim *	This product includes software developed by Bill Paul.
16259698Sdim * 4. Neither the name of the author nor the names of any co-contributors
17259698Sdim *    may be used to endorse or promote products derived from this software
18259698Sdim *    without specific prior written permission.
19259698Sdim *
20259698Sdim * THIS SOFTWARE IS PROVIDED BY Bill Paul AND CONTRIBUTORS ``AS IS'' AND
21259698Sdim * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22259698Sdim * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23259698Sdim * ARE DISCLAIMED.  IN NO EVENT SHALL Bill Paul OR THE VOICES IN HIS HEAD
24259698Sdim * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25259698Sdim * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26259698Sdim * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27259698Sdim * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28259698Sdim * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29259698Sdim * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
30259698Sdim * THE POSSIBILITY OF SUCH DAMAGE.
31259698Sdim *
32259698Sdim * $FreeBSD: head/sys/compat/ndis/pe_var.h 141963 2005-02-16 05:41:18Z wpaul $
33259698Sdim */
34259698Sdim
35259698Sdim#ifndef _PE_VAR_H_
36259698Sdim#define _PE_VAR_H_
37259698Sdim
38259698Sdim/*
39259698Sdim *  Image Format
40259698Sdim */
41259698Sdim
42259698Sdim#define IMAGE_DOS_SIGNATURE			0x5A4D      /* MZ */
43259698Sdim#define IMAGE_OS2_SIGNATURE			0x454E      /* NE */
44259698Sdim#define IMAGE_OS2_SIGNATURE_LE			0x454C      /* LE */
45259698Sdim#define IMAGE_VXD_SIGNATURE			0x454C      /* LE */
46259698Sdim#define IMAGE_NT_SIGNATURE			0x00004550  /* PE00 */
47259698Sdim
48259698Sdim/*
49259698Sdim * All PE files have one of these, just so if you attempt to
50259698Sdim * run them, they'll print out a message telling you they can
51259698Sdim * only be run in Windows.
52259698Sdim */
53259698Sdim
54259698Sdimstruct image_dos_header {
55259698Sdim	uint16_t	idh_magic;	/* Magic number */
56259698Sdim	uint16_t	idh_cblp;	/* Bytes on last page of file */
57259698Sdim	uint16_t	idh_cp;		/* Pages in file */
58259698Sdim	uint16_t	idh_crlc;	/* Relocations */
59259698Sdim	uint16_t	idh_cparhdr;	/* Size of header in paragraphs */
60259698Sdim	uint16_t	idh_minalloc;	/* Minimum extra paragraphs needed */
61259698Sdim	uint16_t	idh_maxalloc;	/* Maximum extra paragraphs needed */
62259698Sdim	uint16_t	idh_ss;		/* Initial (relative) SS value */
63259698Sdim	uint16_t	idh_sp;		/* Initial SP value */
64259698Sdim	uint16_t	idh_csum;	/* Checksum */
65259698Sdim	uint16_t	idh_ip;		/* Initial IP value */
66259698Sdim	uint16_t	idh_cs;		/* Initial (relative) CS value */
67259698Sdim	uint16_t	idh_lfarlc;	/* File address of relocation table */
68259698Sdim	uint16_t	idh_ovno;	/* Overlay number */
69259698Sdim	uint16_t	idh_rsvd1[4];	/* Reserved words */
70259698Sdim	uint16_t	idh_oemid;	/* OEM identifier (for idh_oeminfo) */
71259698Sdim	uint16_t	idh_oeminfo;	/* OEM information; oemid specific */
72259698Sdim	uint16_t	idh_rsvd2[10];	/* Reserved words */
73259698Sdim	uint32_t	idh_lfanew;	/* File address of new exe header */
74259698Sdim};
75259698Sdim
76259698Sdimtypedef struct image_dos_header image_dos_header;
77259698Sdim
78259698Sdim/*
79259698Sdim * File header format.
80259698Sdim */
81259698Sdim
82259698Sdimstruct image_file_header {
83259698Sdim	uint16_t	ifh_machine;		/* Machine type */
84259698Sdim	uint16_t	ifh_numsections;	/* # of sections */
85259698Sdim	uint32_t	ifh_timestamp;		/* Date/time stamp */
86259698Sdim	uint32_t	ifh_symtblptr;		/* Offset to symbol table */
87259698Sdim	uint32_t	ifh_numsyms; 		/* # of symbols */
88259698Sdim	uint16_t	ifh_optionalhdrlen;	/* Size of optional header */
89259698Sdim	uint16_t	ifh_characteristics;	/* Characteristics */
90259698Sdim};
91259698Sdim
92259698Sdimtypedef struct image_file_header image_file_header;
93259698Sdim
94259698Sdim/* Machine types */
95259698Sdim
96259698Sdim#define IMAGE_FILE_MACHINE_UNKNOWN      0
97#define IMAGE_FILE_MACHINE_I860         0x014d
98#define IMAGE_FILE_MACHINE_I386         0x014c
99#define IMAGE_FILE_MACHINE_R3000        0x0162
100#define IMAGE_FILE_MACHINE_R4000        0x0166
101#define IMAGE_FILE_MACHINE_R10000       0x0168
102#define IMAGE_FILE_MACHINE_WCEMIPSV2    0x0169
103#define IMAGE_FILE_MACHINE_ALPHA        0x0184
104#define IMAGE_FILE_MACHINE_SH3          0x01a2
105#define IMAGE_FILE_MACHINE_SH3DSP       0x01a3
106#define IMAGE_FILE_MACHINE_SH3E         0x01a4
107#define IMAGE_FILE_MACHINE_SH4          0x01a6
108#define IMAGE_FILE_MACHINE_SH5          0x01a8
109#define IMAGE_FILE_MACHINE_ARM          0x01c0
110#define IMAGE_FILE_MACHINE_THUMB        0x01c2
111#define IMAGE_FILE_MACHINE_AM33         0x01d3
112#define IMAGE_FILE_MACHINE_POWERPC      0x01f0
113#define IMAGE_FILE_MACHINE_POWERPCFP    0x01f1
114#define IMAGE_FILE_MACHINE_IA64         0x0200
115#define IMAGE_FILE_MACHINE_MIPS16       0x0266
116#define IMAGE_FILE_MACHINE_ALPHA64      0x0284
117#define IMAGE_FILE_MACHINE_MIPSFPU      0x0366
118#define IMAGE_FILE_MACHINE_MIPSFPU16    0x0466
119#define IMAGE_FILE_MACHINE_AXP64        IMAGE_FILE_MACHINE_ALPHA64
120#define IMAGE_FILE_MACHINE_TRICORE      0x0520
121#define IMAGE_FILE_MACHINE_CEF          0x0cef
122#define IMAGE_FILE_MACHINE_EBC          0x0ebc
123#define IMAGE_FILE_MACHINE_AMD64        0x8664
124#define IMAGE_FILE_MACHINE_M32R         0x9041
125#define IMAGE_FILE_MACHINE_CEE          0xc0ee
126
127/* Characteristics */
128
129#define IMAGE_FILE_RELOCS_STRIPPED      0x0001 /* No relocation info */
130#define IMAGE_FILE_EXECUTABLE_IMAGE     0x0002
131#define IMAGE_FILE_LINE_NUMS_STRIPPED   0x0004
132#define IMAGE_FILE_LOCAL_SYMS_STRIPPED  0x0008
133#define IMAGE_FILE_AGGRESIVE_WS_TRIM    0x0010
134#define IMAGE_FILE_LARGE_ADDRESS_AWARE  0x0020
135#define IMAGE_FILE_16BIT_MACHINE        0x0040
136#define IMAGE_FILE_BYTES_REVERSED_LO    0x0080
137#define IMAGE_FILE_32BIT_MACHINE        0x0100
138#define IMAGE_FILE_DEBUG_STRIPPED       0x0200
139#define IMAGE_FILE_REMOVABLE_RUN_FROM_SWAP      0x0400
140#define IMAGE_FILE_NET_RUN_FROM_SWAP    0x0800
141#define IMAGE_FILE_SYSTEM               0x1000
142#define IMAGE_FILE_DLL                  0x2000
143#define IMAGE_FILE_UP_SYSTEM_ONLY       0x4000
144#define IMAGE_FILE_BYTES_REVERSED_HI    0x8000
145
146#define IMAGE_SIZEOF_FILE_HEADER             20
147
148/*
149 * Directory format.
150 */
151
152struct image_data_directory {
153	uint32_t		idd_vaddr;	/* virtual address */
154	uint32_t		idd_size;	/* size */
155};
156
157typedef struct image_data_directory image_data_directory;
158
159#define IMAGE_DIRECTORY_ENTRIES_MAX    16
160
161/*
162 * Optional header format.
163 */
164
165struct image_optional_header {
166
167	/* Standard fields */
168
169	uint16_t	ioh_magic;
170	uint8_t		ioh_linkerver_major;
171	uint8_t		ioh_linkerver_minor;
172	uint32_t	ioh_codesize;
173	uint32_t	ioh_datasize;
174	uint32_t	ioh_bsssize;
175	uint32_t	ioh_entryaddr;
176	uint32_t	ioh_codebaseaddr;
177#ifndef __amd64__
178	uint32_t	ioh_databaseaddr;
179#endif
180
181	/* NT-specific fields */
182
183	uintptr_t	ioh_imagebase;
184	uint32_t	ioh_sectalign;
185	uint32_t	ioh_filealign;
186	uint16_t	ioh_osver_major;
187	uint16_t	ioh_osver_minor;
188	uint16_t	ioh_imagever_major;
189	uint16_t	ioh_imagever_minor;
190	uint16_t	ioh_subsys_major;
191	uint16_t	ioh_subsys_minor;
192	uint32_t	ioh_win32ver;
193	uint32_t	ioh_imagesize;
194	uint32_t	ioh_headersize;
195	uint32_t	ioh_csum;
196	uint16_t	ioh_subsys;
197	uint16_t	ioh_dll_characteristics;
198	uintptr_t	ioh_stackreservesize;
199	uintptr_t	ioh_stackcommitsize;
200	uintptr_t	ioh_heapreservesize;
201	uintptr_t	ioh_heapcommitsize;
202	uint16_t	ioh_loaderflags;
203	uint32_t	ioh_rva_size_cnt;
204	image_data_directory	ioh_datadir[IMAGE_DIRECTORY_ENTRIES_MAX];
205};
206
207typedef struct image_optional_header image_optional_header;
208
209struct image_nt_header {
210	uint32_t		inh_signature;
211	image_file_header	inh_filehdr;
212	image_optional_header	inh_optionalhdr;
213};
214
215typedef struct image_nt_header image_nt_header;
216
217/* Directory Entries */
218
219#define IMAGE_DIRECTORY_ENTRY_EXPORT         0   /* Export Directory */
220#define IMAGE_DIRECTORY_ENTRY_IMPORT         1   /* Import Directory */
221#define IMAGE_DIRECTORY_ENTRY_RESOURCE       2   /* Resource Directory */
222#define IMAGE_DIRECTORY_ENTRY_EXCEPTION      3   /* Exception Directory */
223#define IMAGE_DIRECTORY_ENTRY_SECURITY       4   /* Security Directory */
224#define IMAGE_DIRECTORY_ENTRY_BASERELOC      5   /* Base Relocation Table */
225#define IMAGE_DIRECTORY_ENTRY_DEBUG          6   /* Debug Directory */
226#define IMAGE_DIRECTORY_ENTRY_COPYRIGHT      7   /* Description String */
227#define IMAGE_DIRECTORY_ENTRY_GLOBALPTR      8   /* Machine Value (MIPS GP) */
228#define IMAGE_DIRECTORY_ENTRY_TLS            9   /* TLS Directory */
229#define IMAGE_DIRECTORY_ENTRY_LOAD_CONFIG   10   /* Load Configuration Directory */
230#define IMAGE_DIRECTORY_ENTRY_BOUND_IMPORT  11   /* Bound Import Directory in headers */
231#define IMAGE_DIRECTORY_ENTRY_IAT           12   /* Import Address Table */
232#define IMAGE_DIRECTORY_ENTRY_DELAY_IMPORT      13
233#define IMAGE_DIRECTORY_ENTRY_COM_DESCRIPTOR    14
234
235/* Resource types */
236
237#define RT_CURSOR	1
238#define RT_BITMAP	2
239#define RT_ICON		3
240#define RT_MENU		4
241#define RT_DIALOG	5
242#define RT_STRING	6
243#define RT_FONTDIR	7
244#define RT_FONT		8
245#define RT_ACCELERATOR	9
246#define RT_RCDATA	10
247#define RT_MESSAGETABLE	11
248#define RT_GROUP_CURSOR	12
249#define RT_GROUP_ICON	14
250#define RT_VERSION	16
251#define RT_DLGINCLUDE	17
252#define RT_PLUGPLAY	19
253#define RT_VXD		20
254#define RT_ANICURSOR	21
255#define RT_ANIICON	22
256#define RT_HTML		23
257
258/*
259 * Section header format.
260 */
261
262#define IMAGE_SHORT_NAME_LEN			8
263
264struct image_section_header {
265	uint8_t		ish_name[IMAGE_SHORT_NAME_LEN];
266	union {
267		uint32_t	ish_paddr;
268		uint32_t	ish_vsize;
269	} ish_misc;
270	uint32_t	ish_vaddr;
271	uint32_t	ish_rawdatasize;
272	uint32_t	ish_rawdataaddr;
273	uint32_t	ish_relocaddr;
274	uint32_t	ish_linenumaddr;
275	uint16_t	ish_numrelocs;
276	uint16_t	ish_numlinenums;
277	uint32_t	ish_characteristics;
278};
279
280typedef struct image_section_header image_section_header;
281
282#define IMAGE_SIZEOF_SECTION_HEADER          40
283
284/*
285 * Import format
286 */
287
288struct image_import_by_name {
289	uint16_t	iibn_hint;
290	u_int8_t	iibn_name[1];
291};
292
293#define IMAGE_ORDINAL_FLAG 0x80000000
294#define IMAGE_ORDINAL(Ordinal) (Ordinal & 0xffff)
295
296struct image_import_descriptor {
297	uint32_t	iid_import_name_table_addr;
298	uint32_t	iid_timestamp;
299	uint32_t	iid_forwardchain;
300	uint32_t	iid_nameaddr;
301	uint32_t	iid_import_address_table_addr;
302};
303
304typedef struct image_import_descriptor image_import_descriptor;
305
306struct image_base_reloc {
307	uint32_t	ibr_vaddr;
308	uint32_t	ibr_blocksize;
309	uint16_t	ibr_rel[1];
310};
311
312typedef struct image_base_reloc image_base_reloc;
313
314#define IMR_RELTYPE(x)		((x >> 12) & 0xF)
315#define IMR_RELOFFSET(x)	(x & 0xFFF)
316
317/* generic relocation types */
318#define IMAGE_REL_BASED_ABSOLUTE                0
319#define IMAGE_REL_BASED_HIGH                    1
320#define IMAGE_REL_BASED_LOW                     2
321#define IMAGE_REL_BASED_HIGHLOW                 3
322#define IMAGE_REL_BASED_HIGHADJ                 4
323#define IMAGE_REL_BASED_MIPS_JMPADDR            5
324#define IMAGE_REL_BASED_SECTION                 6
325#define IMAGE_REL_BASED_REL                     7
326#define IMAGE_REL_BASED_MIPS_JMPADDR16          9
327#define IMAGE_REL_BASED_IA64_IMM64              9 /* yes, 9 too */
328#define IMAGE_REL_BASED_DIR64                   10
329#define IMAGE_REL_BASED_HIGH3ADJ                11
330
331struct image_resource_directory_entry {
332	uint32_t		irde_name;
333	uint32_t		irde_dataoff;
334};
335
336typedef struct image_resource_directory_entry image_resource_directory_entry;
337
338#define RESOURCE_NAME_STR	0x80000000
339#define RESOURCE_DIR_FLAG	0x80000000
340
341struct image_resource_directory {
342	uint32_t		ird_characteristics;
343	uint32_t		ird_timestamp;
344	uint16_t		ird_majorver;
345	uint16_t		ird_minorver;
346	uint16_t		ird_named_entries;
347	uint16_t		ird_id_entries;
348#ifdef notdef
349	image_resource_directory_entry	ird_entries[1];
350#endif
351};
352
353typedef struct image_resource_directory image_resource_directory;
354
355struct image_resource_directory_string {
356	uint16_t		irds_len;
357	char			irds_name[1];
358};
359
360typedef struct image_resource_directory_string image_resource_directory_string;
361
362struct image_resource_directory_string_u {
363	uint16_t		irds_len;
364	char			irds_name[1];
365};
366
367typedef struct image_resource_directory_string_u
368	image_resource_directory_string_u;
369
370struct image_resource_data_entry {
371	uint32_t		irde_offset;
372	uint32_t		irde_size;
373	uint32_t		irde_codepage;
374	uint32_t		irde_rsvd;
375};
376
377typedef struct image_resource_data_entry image_resource_data_entry;
378
379struct message_resource_data {
380	uint32_t		mrd_numblocks;
381#ifdef notdef
382	message_resource_block	mrd_blocks[1];
383#endif
384};
385
386typedef struct message_resource_data message_resource_data;
387
388struct message_resource_block {
389	uint32_t		mrb_lowid;
390	uint32_t		mrb_highid;
391	uint32_t		mrb_entryoff;
392};
393
394typedef struct message_resource_block message_resource_block;
395
396struct message_resource_entry {
397	uint16_t		mre_len;
398	uint16_t		mre_flags;
399	char			mre_text[];
400};
401
402typedef struct message_resource_entry message_resource_entry;
403
404#define MESSAGE_RESOURCE_UNICODE	0x0001
405
406struct image_patch_table {
407	char		*ipt_name;
408	void		(*ipt_func)(void);
409	void		(*ipt_wrap)(void);
410};
411
412typedef struct image_patch_table image_patch_table;
413
414/*
415 * Note: Windows uses the _stdcall calling convention. This means
416 * that the callback functions provided in the function table must
417 * be declared using __attribute__((__stdcall__)), otherwise the
418 * Windows code will likely screw up the %esp register and cause
419 * us to jump to an invalid address when it returns.
420 */
421
422#ifdef __amd64__
423#define	__stdcall
424#define __regcall
425#define __fastcall
426#define REGARGS1(decl1)		decl1
427#define REGARGS2(decl1, decl2)	decl1, decl2
428#define REGCALL1(arg1)		arg1
429#define REGCALL2(arg1, arg2)	arg1, arg2
430#else
431#define	__stdcall __attribute__((__stdcall__))
432#define __regcall __attribute__((__regparm__(3)))
433#define __fastcall __stdcall __regcall
434#define REGARGS1(decl1)		int dummy1, int dummy2, decl1
435#define REGARGS2(decl1, decl2)	int dummy1, decl2, decl1
436#define REGCALL1(arg1)		0, 0, arg1
437#define REGCALL2(arg1, arg2)	0, arg2, arg1
438#endif
439
440
441/*
442 * This mess allows us to call a _fastcall style routine with our
443 * version of gcc, which lacks __attribute__((__fastcall__)). Only
444 * has meaning on x86; everywhere else, it's a no-op.
445 */
446
447#ifdef __i386__
448typedef __fastcall int (*fcall1)(REGARGS1(uint32_t));
449typedef __fastcall int (*fcall2)(REGARGS2(uint32_t, uint32_t));
450typedef __fastcall int (*fcall3)(REGARGS2(uint32_t, uint32_t), uint32_t);
451
452static __inline uint32_t
453fastcall1(fcall1 f, uint32_t a)
454{
455	return(f(REGCALL1(a)));
456}
457
458static __inline uint32_t
459fastcall2(fcall2 f, uint32_t a, uint32_t b)
460{
461	return(f(REGCALL2(a, b)));
462}
463
464static __inline uint32_t
465fastcall3(fcall3 f, uint32_t a, uint32_t b, uint32_t c)
466{
467	return(f(REGCALL2(a, b), c));
468}
469
470#define FASTCALL1(f, a)		\
471	fastcall1((fcall1)(f), (uint32_t)(a))
472#define FASTCALL2(f, a, b)	\
473	fastcall2((fcall2)(f), (uint32_t)(a), (uint32_t)(b))
474#define FASTCALL3(f, a, b, c)	\
475	fastcall3((fcall3)(f), (uint32_t)(a), (uint32_t)(b), (uint32_t)(c))
476#else
477#define FASTCALL1(f, a) (f)((a))
478#define FASTCALL2(f, a, b) (f)((a), (b))
479#define FASTCALL3(f, a, b, c) (f)((a), (b), (c))
480#endif /* __i386__ */
481
482
483/*
484 * AMD64 support. Microsoft uses a different calling convention
485 * than everyone else on the amd64 platform. Sadly, gcc has no
486 * built-in support for it (yet).
487 *
488 * The three major differences we're concerned with are:
489 *
490 * - The first 4 register-sized arguments are passed in the
491 *   %rcx, %rdx, %r8 and %r9 registers, and the rest are pushed
492 *   onto the stack. (The ELF ABI uses 6 registers, not 4).
493 *
494 * - The caller must reserve space on the stack for the 4
495 *   register arguments in case the callee has to spill them.
496 *
497 * - The stack myst be 16-byte aligned by the time the callee
498 *   executes. A call instruction implicitly pushes an 8 byte
499 *   return address onto the stack. We have to make sure that
500 *   the amount of space we consume, plus the return address,
501 *   is a multiple of 16 bytes in size. This means that in
502 *   some cases, we may need to chew up an extra 8 bytes on
503 *   the stack that will be unused.
504 *
505 * On the bright side, Microsoft seems to be using just the one
506 * calling convention for all functions on amd64, unlike x86 where
507 * they use a mix of _stdcall, _fastcall and _cdecl.
508 */
509
510#ifdef __amd64__
511
512extern uint64_t x86_64_call1(void *, uint64_t);
513extern uint64_t x86_64_call2(void *, uint64_t, uint64_t);
514extern uint64_t x86_64_call3(void *, uint64_t, uint64_t, uint64_t);
515extern uint64_t x86_64_call4(void *, uint64_t, uint64_t, uint64_t, uint64_t);
516extern uint64_t x86_64_call5(void *, uint64_t, uint64_t, uint64_t, uint64_t,
517	uint64_t);
518extern uint64_t x86_64_call6(void *, uint64_t, uint64_t, uint64_t, uint64_t,
519	uint64_t, uint64_t);
520
521
522#define MSCALL1(fn, a)						\
523	x86_64_call1((fn), (uint64_t)(a))
524#define MSCALL2(fn, a, b)					\
525	x86_64_call2((fn), (uint64_t)(a), (uint64_t)(b))
526#define MSCALL3(fn, a, b, c)					\
527	x86_64_call3((fn), (uint64_t)(a), (uint64_t)(b),		\
528	(uint64_t)(c))
529#define MSCALL4(fn, a, b, c, d)					\
530	x86_64_call4((fn), (uint64_t)(a), (uint64_t)(b),		\
531	(uint64_t)(c), (uint64_t)(d))
532#define MSCALL5(fn, a, b, c, d, e)				\
533	x86_64_call5((fn), (uint64_t)(a), (uint64_t)(b),		\
534	(uint64_t)(c), (uint64_t)(d), (uint64_t)(e))
535#define MSCALL6(fn, a, b, c, d, e, f)				\
536	x86_64_call6((fn), (uint64_t)(a), (uint64_t)(b),		\
537	(uint64_t)(c), (uint64_t)(d), (uint64_t)(e), (uint64_t)(f))
538
539#else /* __amd64__ */
540
541#define MSCALL1(fn, a)			(fn)((a))
542#define MSCALL2(fn, a, b)		(fn)((a), (b))
543#define MSCALL3(fn, a, b, c)		(fn)((a), (b), (c))
544#define MSCALL4(fn, a, b, c, d)		(fn)((a), (b), (c), (d))
545#define MSCALL5(fn, a, b, c, d, e)	(fn)((a), (b), (c), (d), (e))
546#define MSCALL6(fn, a, b, c, d, e, f)	(fn)((a), (b), (c), (d), (e), (f))
547
548#endif /* __amd64__ */
549
550
551#define FUNC void(*)(void)
552#define IMPORT_FUNC(x)		{ #x, (FUNC)x, NULL }
553#define IMPORT_FUNC_MAP(x, y)	{ #x, (FUNC)y, NULL }
554
555__BEGIN_DECLS
556extern int pe_get_dos_header(vm_offset_t, image_dos_header *);
557extern int pe_is_nt_image(vm_offset_t);
558extern int pe_get_optional_header(vm_offset_t, image_optional_header *);
559extern int pe_get_file_header(vm_offset_t, image_file_header *);
560extern int pe_get_section_header(vm_offset_t, image_section_header *);
561extern int pe_numsections(vm_offset_t);
562extern vm_offset_t pe_imagebase(vm_offset_t);
563extern vm_offset_t pe_directory_offset(vm_offset_t, uint32_t);
564extern vm_offset_t pe_translate_addr (vm_offset_t, vm_offset_t);
565extern int pe_get_section(vm_offset_t, image_section_header *, const char *);
566extern int pe_relocate(vm_offset_t);
567extern int pe_get_import_descriptor(vm_offset_t, image_import_descriptor *, char *);
568extern int pe_patch_imports(vm_offset_t, char *, image_patch_table *);
569extern int pe_get_messagetable(vm_offset_t, message_resource_data **);
570extern int pe_get_message(vm_offset_t, uint32_t, char **, int *, uint16_t *);
571__END_DECLS
572
573#endif /* _PE_VAR_H_ */
574