Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

498 lines
22 KiB

  1. /* SCCSID = @(#)newexe.h 4.6 86/09/10 */
  2. /*
  3. * Title
  4. *
  5. * newexe.h
  6. * Pete Stewart
  7. * (C) Copyright Microsoft Corp 1984-1987
  8. * 17 August 1984
  9. *
  10. * Description
  11. *
  12. * Data structure definitions for the DOS 4.0/Windows 2.0
  13. * executable file format.
  14. *
  15. * Modification History
  16. *
  17. * 84/08/17 Pete Stewart Initial version
  18. * 84/10/17 Pete Stewart Changed some constants to match OMF
  19. * 84/10/23 Pete Stewart Updates to match .EXE format revision
  20. * 84/11/20 Pete Stewart Substantial .EXE format revision
  21. * 85/01/09 Pete Stewart Added constants ENEWEXE and ENEWHDR
  22. * 85/01/10 Steve Wood Added resource definitions
  23. * 85/03/04 Vic Heller Reconciled Windows and DOS 4.0 versions
  24. * 85/03/07 Pete Stewart Added movable entry count
  25. * 85/04/01 Pete Stewart Segment alignment field, error bit
  26. * 85/10/03 Reuben Borman Removed segment discard priority
  27. * 85/10/11 Vic Heller Added PIF header fields
  28. * 86/03/10 Reuben Borman Changes for DOS 5.0
  29. * 86/09/02 Reuben Borman NSPURE ==> NSSHARED
  30. * 87/05/04 Reuben Borman Added ne_cres and NSCONFORM
  31. * 87/07/08 Reuben Borman Added NEAPPTYPE definitions
  32. * 87/10/28 Wieslaw Kalkus Added ne_exetyp
  33. * 89/03/23 Wieslaw Kalkus Added ne_flagsothers for OS/2 1.2
  34. */
  35. /*_________________________________________________________________*
  36. | |
  37. | |
  38. | DOS3 .EXE FILE HEADER DEFINITION |
  39. | |
  40. |_________________________________________________________________|
  41. * */
  42. #define EMAGIC 0x5A4D /* Old magic number */
  43. #define ENEWEXE sizeof(struct exe_hdr)
  44. /* Value of E_LFARLC for new .EXEs */
  45. #define ENEWHDR 0x003C /* Offset in old hdr. of ptr. to new */
  46. #define ERESWDS 0x000d /* No. of reserved words (OLD) */
  47. #define ERES2WDS 0x000A /* No. of reserved words in e_res2 */
  48. #define ECP 0x0004 /* Offset in struct of E_CP */
  49. #define ECBLP 0x0002 /* Offset in struct of E_CBLP */
  50. #define EMINALLOC 0x000A /* Offset in struct of E_MINALLOC */
  51. #define EKNOWEAS 0x0001 /* e_flags - program understands EAs */
  52. #define EDOSEXTENDED 0x0002 /* e_flags - program runs under DOS extender */
  53. #define EPCODE 0x0004 /* e_flags - memory image constructed from PCODE */
  54. struct exe_hdr /* DOS 1, 2, 3 .EXE header */
  55. {
  56. unsigned short e_magic; /* Magic number */
  57. unsigned short e_cblp; /* Bytes on last page of file */
  58. unsigned short e_cp; /* Pages in file */
  59. unsigned short e_crlc; /* Relocations */
  60. unsigned short e_cparhdr; /* Size of header in paragraphs */
  61. unsigned short e_minalloc; /* Minimum extra paragraphs needed */
  62. unsigned short e_maxalloc; /* Maximum extra paragraphs needed */
  63. unsigned short e_ss; /* Initial (relative) SS value */
  64. unsigned short e_sp; /* Initial SP value */
  65. unsigned short e_csum; /* Checksum */
  66. unsigned short e_ip; /* Initial IP value */
  67. unsigned short e_cs; /* Initial (relative) CS value */
  68. unsigned short e_lfarlc; /* File address of relocation table */
  69. unsigned short e_ovno; /* Overlay number */
  70. unsigned long e_sym_tab; /* offset of symbol table file */
  71. unsigned short e_flags; /* old exe header flags */
  72. unsigned short e_res; /* Reserved words */
  73. unsigned short e_oemid; /* OEM identifier (for e_oeminfo) */
  74. unsigned short e_oeminfo; /* OEM information; e_oemid specific */
  75. unsigned short e_res2[ERES2WDS];/* Reserved words */
  76. long e_lfanew; /* File address of new exe header */
  77. };
  78. #define E_MAGIC(x) (x).e_magic
  79. #define E_CBLP(x) (x).e_cblp
  80. #define E_CP(x) (x).e_cp
  81. #define E_CRLC(x) (x).e_crlc
  82. #define E_CPARHDR(x) (x).e_cparhdr
  83. #define E_MINALLOC(x) (x).e_minalloc
  84. #define E_MAXALLOC(x) (x).e_maxalloc
  85. #define E_SS(x) (x).e_ss
  86. #define E_SP(x) (x).e_sp
  87. #define E_CSUM(x) (x).e_csum
  88. #define E_IP(x) (x).e_ip
  89. #define E_CS(x) (x).e_cs
  90. #define E_LFARLC(x) (x).e_lfarlc
  91. #define E_OVNO(x) (x).e_ovno
  92. #define E_SYM_TAB(x) (x).e_sym_tab
  93. #define E_FLAGS(x) (x).e_flags
  94. #define E_RES(x) (x).e_res
  95. #define E_OEMID(x) (x).e_oemid
  96. #define E_OEMINFO(x) (x).e_oeminfo
  97. #define E_RES2(x) (x).e_res2
  98. #define E_LFANEW(x) (x).e_lfanew
  99. /*_________________________________________________________________*
  100. | |
  101. | |
  102. | OS/2 & WINDOWS .EXE FILE HEADER DEFINITION - 286 version |
  103. | |
  104. |_________________________________________________________________|
  105. * */
  106. #define NEMAGIC 0x454E /* New magic number */
  107. #define NERESBYTES 0 /* No bytes reserved after Windows 3.0 changes */
  108. #define NECRC 8 /* Offset into new header of NE_CRC */
  109. struct new_exe /* New .EXE header */
  110. {
  111. unsigned short ne_magic; /* Magic number NE_MAGIC */
  112. unsigned char ne_ver; /* Version number */
  113. unsigned char ne_rev; /* Revision number */
  114. unsigned short ne_enttab; /* Offset of Entry Table */
  115. unsigned short ne_cbenttab; /* Number of bytes in Entry Table */
  116. long ne_crc; /* Checksum of whole file */
  117. unsigned short ne_flags; /* Flag word */
  118. unsigned short ne_autodata; /* Automatic data segment number */
  119. unsigned short ne_heap; /* Initial heap allocation */
  120. unsigned short ne_stack; /* Initial stack allocation */
  121. long ne_csip; /* Initial CS:IP setting */
  122. long ne_sssp; /* Initial SS:SP setting */
  123. unsigned short ne_cseg; /* Count of file segments */
  124. unsigned short ne_cmod; /* Entries in Module Reference Table */
  125. unsigned short ne_cbnrestab; /* Size of non-resident name table */
  126. unsigned short ne_segtab; /* Offset of Segment Table */
  127. unsigned short ne_rsrctab; /* Offset of Resource Table */
  128. unsigned short ne_restab; /* Offset of resident name table */
  129. unsigned short ne_modtab; /* Offset of Module Reference Table */
  130. unsigned short ne_imptab; /* Offset of Imported Names Table */
  131. long ne_nrestab; /* Offset of Non-resident Names Table */
  132. unsigned short ne_cmovent; /* Count of movable entries */
  133. unsigned short ne_align; /* Segment alignment shift count */
  134. unsigned short ne_cres; /* Count of resource entries */
  135. unsigned char ne_exetyp; /* Target operating system */
  136. unsigned char ne_flagsothers; /* Other .EXE flags */
  137. unsigned short ne_pretthunks; /* Windows 3.0 - offset to return thunks */
  138. unsigned short ne_psegrefbytes;/* Windows 3.0 - offset to segment ref. bytes */
  139. unsigned short ne_swaparea; /* Windows 3.0 - minimum code swap size */
  140. unsigned short ne_expver; /* Windows 3.0 - expected windows version number */
  141. };
  142. #define NE_MAGIC(x) (x).ne_magic
  143. #define NE_VER(x) (x).ne_ver
  144. #define NE_REV(x) (x).ne_rev
  145. #define NE_ENTTAB(x) (x).ne_enttab
  146. #define NE_CBENTTAB(x) (x).ne_cbenttab
  147. #define NE_CRC(x) (x).ne_crc
  148. #define NE_FLAGS(x) (x).ne_flags
  149. #define NE_AUTODATA(x) (x).ne_autodata
  150. #define NE_HEAP(x) (x).ne_heap
  151. #define NE_STACK(x) (x).ne_stack
  152. #define NE_CSIP(x) (x).ne_csip
  153. #define NE_SSSP(x) (x).ne_sssp
  154. #define NE_CSEG(x) (x).ne_cseg
  155. #define NE_CMOD(x) (x).ne_cmod
  156. #define NE_CBNRESTAB(x) (x).ne_cbnrestab
  157. #define NE_SEGTAB(x) (x).ne_segtab
  158. #define NE_RSRCTAB(x) (x).ne_rsrctab
  159. #define NE_RESTAB(x) (x).ne_restab
  160. #define NE_MODTAB(x) (x).ne_modtab
  161. #define NE_IMPTAB(x) (x).ne_imptab
  162. #define NE_NRESTAB(x) (x).ne_nrestab
  163. #define NE_CMOVENT(x) (x).ne_cmovent
  164. #define NE_ALIGN(x) (x).ne_align
  165. #define NE_CRES(x) (x).ne_cres
  166. #define NE_RES(x) (x).ne_res
  167. #define NE_EXETYP(x) (x).ne_exetyp
  168. #define NE_FLAGSOTHERS(x) (x).ne_flagsothers
  169. #define NE_PRETTHUNKS(x) (x).ne_pretthunks
  170. #define NE_PSEGREFBYTES(x) (x).ne_psegrefbytes
  171. #define NE_SWAPAREA(x) (x).ne_swaparea
  172. #define NE_EXPVER(x) (x).ne_expver
  173. #define NE_USAGE(x) (WORD)*((WORD *)(x)+1)
  174. #define NE_PNEXTEXE(x) (WORD)(x).ne_cbenttab
  175. #define NE_ONEWEXE(x) (WORD)(x).ne_crc
  176. #define NE_PFILEINFO(x) (WORD)((DWORD)(x).ne_crc >> 16)
  177. /*
  178. * Target operating systems
  179. */
  180. #define NE_UNKNOWN 0x0 /* Unknown (any "new-format" OS) */
  181. #define NE_OS2 0x1 /* Microsoft/IBM OS/2 (default) */
  182. #define NE_WINDOWS 0x2 /* Microsoft Windows */
  183. #define NE_DOS 0x3 /* Microsoft MS-DOS */
  184. #define NE_DEV386 0x4 /* Microsoft Windows 386 */
  185. /*
  186. * Format of NE_FLAGS(x):
  187. *
  188. * p Not-a-process
  189. * x Unused
  190. * e Errors in image
  191. * x Unused
  192. * b Bound Family/API
  193. * ttt Application type
  194. * f Floating-point instructions
  195. * 3 386 instructions
  196. * 2 286 instructions
  197. * 0 8086 instructions
  198. * P Protected mode only
  199. * p Per-process library initialization
  200. * i Instance data
  201. * s Solo data
  202. */
  203. #define NENOTP 0x8000 /* Not a process */
  204. #define NEPRIVLIB 0x4000 /* A one customer Windows 3.0 library */
  205. #define NEIERR 0x2000 /* Errors in image */
  206. #define NEBOUND 0x0800 /* Bound Family/API */
  207. #define NEAPPLOADER 0x0800 /* Aplication specific loader - valid only for Windows */
  208. #define NEAPPTYP 0x0700 /* Application type mask */
  209. #define NENOTWINCOMPAT 0x0100 /* Not compatible with P.M. Windowing */
  210. #define NEWINCOMPAT 0x0200 /* Compatible with P.M. Windowing */
  211. #define NEWINAPI 0x0300 /* Uses P.M. Windowing API */
  212. #define NEFLTP 0x0080 /* Floating-point instructions */
  213. #define NEI386 0x0040 /* 386 instructions */
  214. #define NEI286 0x0020 /* 286 instructions */
  215. #define NEI086 0x0010 /* 8086 instructions */
  216. #define NEPROT 0x0008 /* Runs in protected mode only */
  217. #define NEPPLI 0x0004 /* Per-Process Library Initialization */
  218. #define NEINST 0x0002 /* Instance data */
  219. #define NESOLO 0x0001 /* Solo data */
  220. /*
  221. * Format of NE_FLAGSOTHERS(x):
  222. *
  223. * 7 6 5 4 3 2 1 0 - bit no
  224. * | | | | |
  225. * | | | | +---------------- Support for EAs and Long filenames
  226. * | | | +------------------ Reserved for Win30
  227. * | | +-------------------- Reserved for Win30
  228. * | +---------------------- Reserved for Win30
  229. * +------------------------ Memory image constructed from PCODE
  230. */
  231. #define NENEWFILES 0x01 /* os/2 app understands eas and longnames */
  232. #define NEINFONT 0x02 /* 2.x app gets proportional font */
  233. #define NEINPROT 0x04 /* 2.x app runs in 3.x prot mode */
  234. #define NEGANGLOAD 0x08 /* Reserved for Win 3.0 */
  235. #define NEHASPCODE 0x10 /* .EXE contains PCODE module */
  236. struct new_seg /* New .EXE segment table entry */
  237. {
  238. unsigned short ns_sector; /* File sector of start of segment */
  239. unsigned short ns_cbseg; /* Number of bytes in file */
  240. unsigned short ns_flags; /* Attribute flags */
  241. unsigned short ns_minalloc; /* Minimum allocation in bytes */
  242. };
  243. #define NS_SECTOR(x) (x).ns_sector
  244. #define NS_CBSEG(x) (x).ns_cbseg
  245. #define NS_FLAGS(x) (x).ns_flags
  246. #define NS_MINALLOC(x) (x).ns_minalloc
  247. /*
  248. * Format of NS_FLAGS(x)
  249. *
  250. * Flag word has the following format:
  251. *
  252. * 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 - bit no
  253. * | | | | | | | | | | | | | | |
  254. * | | | | | | | | | | | | +-+-+--- Segment type DATA/CODE
  255. * | | | | | | | | | | | +--------- Iterated segment
  256. * | | | | | | | | | | +----------- Movable segment
  257. * | | | | | | | | | +------------- Segment can be shared
  258. * | | | | | | | | +--------------- Preload segment
  259. * | | | | | | | +----------------- Execute/read-only for code/data segment
  260. * | | | | | | +------------------- Segment has relocations
  261. * | | | | | +--------------------- Code conforming/Data is expand down
  262. * | | | +--+----------------------- I/O privilege level
  263. * | | +----------------------------- Discardable segment
  264. * | +-------------------------------- 32-bit code segment
  265. * +----------------------------------- Huge segment/GDT allocation requested
  266. *
  267. */
  268. #define NSTYPE 0x0007 /* Segment type mask */
  269. #if !EXE386
  270. #define NSCODE 0x0000 /* Code segment */
  271. #define NSDATA 0x0001 /* Data segment */
  272. #define NSITER 0x0008 /* Iterated segment flag */
  273. #define NSMOVE 0x0010 /* Movable segment flag */
  274. #define NSSHARED 0x0020 /* Shared segment flag */
  275. #define NSPRELOAD 0x0040 /* Preload segment flag */
  276. #define NSEXRD 0x0080 /* Execute-only (code segment), or
  277. * read-only (data segment)
  278. */
  279. #define NSRELOC 0x0100 /* Segment has relocations */
  280. #define NSCONFORM 0x0200 /* Conforming segment */
  281. #define NSEXPDOWN 0x0200 /* Data segment is expand down */
  282. #define NSDPL 0x0C00 /* I/O privilege level (286 DPL bits) */
  283. #define SHIFTDPL 10 /* Left shift count for SEGDPL field */
  284. #define NSDISCARD 0x1000 /* Segment is discardable */
  285. #define NS32BIT 0x2000 /* 32-bit code segment */
  286. #define NSHUGE 0x4000 /* Huge memory segment, length of
  287. * segment and minimum allocation
  288. * size are in segment sector units
  289. */
  290. #define NSGDT 0x8000 /* GDT allocation requested */
  291. #define NSPURE NSSHARED /* For compatibility */
  292. #define NSALIGN 9 /* Segment data aligned on 512 byte boundaries */
  293. #define NSLOADED 0x0004 /* ns_sector field contains memory addr */
  294. #endif
  295. struct new_segdata /* Segment data */
  296. {
  297. union
  298. {
  299. struct
  300. {
  301. unsigned short ns_niter; /* number of iterations */
  302. unsigned short ns_nbytes; /* number of bytes */
  303. char ns_iterdata; /* iterated data bytes */
  304. } ns_iter;
  305. struct
  306. {
  307. char ns_data; /* data bytes */
  308. } ns_noniter;
  309. } ns_union;
  310. };
  311. struct new_rlcinfo /* Relocation info */
  312. {
  313. unsigned short nr_nreloc; /* number of relocation items that */
  314. }; /* follow */
  315. #pragma pack(1)
  316. struct new_rlc /* Relocation item */
  317. {
  318. unsigned char nr_stype; /* Source type */
  319. unsigned char nr_flags; /* Flag byte */
  320. unsigned short nr_soff; /* Source offset */
  321. union
  322. {
  323. struct
  324. {
  325. unsigned char nr_segno; /* Target segment number */
  326. unsigned char nr_res; /* Reserved */
  327. unsigned short nr_entry; /* Target Entry Table offset */
  328. } nr_intref; /* Internal reference */
  329. struct
  330. {
  331. unsigned short nr_mod; /* Index into Module Reference Table */
  332. unsigned short nr_proc; /* Procedure ordinal or name offset */
  333. } nr_import; /* Import */
  334. struct
  335. {
  336. unsigned short nr_ostype; /* OSFIXUP type */
  337. unsigned short nr_osres; /* reserved */
  338. } nr_osfix; /* Operating system fixup */
  339. } nr_union; /* Union */
  340. };
  341. #pragma pack()
  342. #define NR_STYPE(x) (x).nr_stype
  343. #define NR_FLAGS(x) (x).nr_flags
  344. #define NR_SOFF(x) (x).nr_soff
  345. #define NR_SEGNO(x) (x).nr_union.nr_intref.nr_segno
  346. #define NR_RES(x) (x).nr_union.nr_intref.nr_res
  347. #define NR_ENTRY(x) (x).nr_union.nr_intref.nr_entry
  348. #define NR_MOD(x) (x).nr_union.nr_import.nr_mod
  349. #define NR_PROC(x) (x).nr_union.nr_import.nr_proc
  350. #define NR_OSTYPE(x) (x).nr_union.nr_osfix.nr_ostype
  351. #define NR_OSRES(x) (x).nr_union.nr_osfix.nr_osres
  352. /*
  353. * Format of NR_STYPE(x) and R32_STYPE(x):
  354. *
  355. * 7 6 5 4 3 2 1 0 - bit no
  356. * | | | |
  357. * +-+-+-+--- source type
  358. *
  359. */
  360. #define NRSTYP 0x0f /* Source type mask */
  361. #define NRSBYT 0x00 /* lo byte (8-bits)*/
  362. #define NRSSEG 0x02 /* 16-bit segment (16-bits) */
  363. #define NRSPTR 0x03 /* 16:16 pointer (32-bits) */
  364. #define NRSOFF 0x05 /* 16-bit offset (16-bits) */
  365. #define NRPTR48 0x06 /* 16:32 pointer (48-bits) */
  366. #define NROFF32 0x07 /* 32-bit offset (32-bits) */
  367. #define NRSOFF32 0x08 /* 32-bit self-relative offset (32-bits) */
  368. /*
  369. * Format of NR_FLAGS(x) and R32_FLAGS(x):
  370. *
  371. * 7 6 5 4 3 2 1 0 - bit no
  372. * | | |
  373. * | +-+--- Reference type
  374. * +------- Additive fixup
  375. */
  376. #define NRADD 0x04 /* Additive fixup */
  377. #define NRRTYP 0x03 /* Reference type mask */
  378. #define NRRINT 0x00 /* Internal reference */
  379. #define NRRORD 0x01 /* Import by ordinal */
  380. #define NRRNAM 0x02 /* Import by name */
  381. #define NRROSF 0x03 /* Operating system fixup */
  382. #if !EXE386
  383. /* Resource type or name string */
  384. struct rsrc_string
  385. {
  386. unsigned char rs_len; /* number of bytes in string */
  387. unsigned char rs_string[ 1 ]; /* text of string */
  388. };
  389. #define RS_LEN( x ) (x).rs_len
  390. #define RS_STRING( x ) (x).rs_string
  391. /* Resource type information block */
  392. struct rsrc_typeinfo
  393. {
  394. unsigned short rt_id;
  395. unsigned short rt_nres;
  396. long rt_proc;
  397. };
  398. #define RT_ID( x ) (x).rt_id
  399. #define RT_NRES( x ) (x).rt_nres
  400. #define RT_PROC( x ) (x).rt_proc
  401. /* Resource name information block */
  402. struct rsrc_nameinfo
  403. {
  404. /* The following two fields must be shifted left by the value of */
  405. /* the rs_align field to compute their actual value. This allows */
  406. /* resources to be larger than 64k, but they do not need to be */
  407. /* aligned on 512 byte boundaries, the way segments are */
  408. unsigned short rn_offset; /* file offset to resource data */
  409. unsigned short rn_length; /* length of resource data */
  410. unsigned short rn_flags; /* resource flags */
  411. unsigned short rn_id; /* resource name id */
  412. unsigned short rn_handle; /* If loaded, then global handle */
  413. unsigned short rn_usage; /* Initially zero. Number of times */
  414. /* the handle for this resource has */
  415. /* been given out */
  416. };
  417. #define RN_OFFSET( x ) (x).rn_offset
  418. #define RN_LENGTH( x ) (x).rn_length
  419. #define RN_FLAGS( x ) (x).rn_flags
  420. #define RN_ID( x ) (x).rn_id
  421. #define RN_HANDLE( x ) (x).rn_handle
  422. #define RN_USAGE( x ) (x).rn_usage
  423. #define RSORDID 0x8000 /* if high bit of ID set then integer id */
  424. /* otherwise ID is offset of string from
  425. the beginning of the resource table */
  426. /* Ideally these are the same as the */
  427. /* corresponding segment flags */
  428. #define RNMOVE 0x0010 /* Moveable resource */
  429. #define RNPURE 0x0020 /* Pure (read-only) resource */
  430. #define RNPRELOAD 0x0040 /* Preloaded resource */
  431. #define RNDISCARD 0xF000 /* Discard priority level for resource */
  432. /* Resource table */
  433. struct new_rsrc
  434. {
  435. unsigned short rs_align; /* alignment shift count for resources */
  436. struct rsrc_typeinfo rs_typeinfo;
  437. };
  438. #define RS_ALIGN( x ) (x).rs_align
  439. #endif /* !EXE386 */