Leaked source code of windows server 2003
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.

362 lines
15 KiB

  1. /*static char *SCCSID = "@(#)newexe.h:2.9";*/
  2. /*
  3. * Title
  4. *
  5. * newexe.h
  6. * (C) Copyright Microsoft Corp 1984-1994
  7. * 17 August 1984
  8. *
  9. * Description
  10. *
  11. * Data structure definitions for the DOS 4.0/Windows 2.0
  12. * executable file format.
  13. *
  14. */
  15. #define EMAGIC 0x5A4D /* Old magic number */
  16. #define ENEWEXE sizeof(struct exe_hdr)
  17. /* Value of E_LFARLC for new .EXEs */
  18. #define ENEWHDR 0x003C /* Offset in old hdr. of ptr. to new */
  19. #define ERESWDS 0x0010 /* No. of reserved words in header */
  20. #define ECP 0x0004 /* Offset in struct of E_CP */
  21. #define ECBLP 0x0002 /* Offset in struct of E_CBLP */
  22. #define EMINALLOC 0x000A /* Offset in struct of E_MINALLOC */
  23. struct exe_hdr /* DOS 1, 2, 3 .EXE header */
  24. {
  25. unsigned short e_magic; /* Magic number */
  26. unsigned short e_cblp; /* Bytes on last page of file */
  27. unsigned short e_cp; /* Pages in file */
  28. unsigned short e_crlc; /* Relocations */
  29. unsigned short e_cparhdr; /* Size of header in paragraphs */
  30. unsigned short e_minalloc; /* Minimum extra paragraphs needed */
  31. unsigned short e_maxalloc; /* Maximum extra paragraphs needed */
  32. unsigned short e_ss; /* Initial (relative) SS value */
  33. unsigned short e_sp; /* Initial SP value */
  34. unsigned short e_csum; /* Checksum */
  35. unsigned short e_ip; /* Initial IP value */
  36. unsigned short e_cs; /* Initial (relative) CS value */
  37. unsigned short e_lfarlc; /* File address of relocation table */
  38. unsigned short e_ovno; /* Overlay number */
  39. unsigned short e_res[ERESWDS]; /* Reserved words */
  40. long e_lfanew; /* File address of new exe header */
  41. };
  42. #define E_MAGIC(x) (x).e_magic
  43. #define E_CBLP(x) (x).e_cblp
  44. #define E_CP(x) (x).e_cp
  45. #define E_CRLC(x) (x).e_crlc
  46. #define E_CPARHDR(x) (x).e_cparhdr
  47. #define E_MINALLOC(x) (x).e_minalloc
  48. #define E_MAXALLOC(x) (x).e_maxalloc
  49. #define E_SS(x) (x).e_ss
  50. #define E_SP(x) (x).e_sp
  51. #define E_CSUM(x) (x).e_csum
  52. #define E_IP(x) (x).e_ip
  53. #define E_CS(x) (x).e_cs
  54. #define E_LFARLC(x) (x).e_lfarlc
  55. #define E_OVNO(x) (x).e_ovno
  56. #define E_RES(x) (x).e_res
  57. #define E_LFANEW(x) (x).e_lfanew
  58. #define NEMAGIC 0x454E /* New magic number */
  59. #define NERESBYTES 0
  60. struct new_exe /* New .EXE header */
  61. {
  62. unsigned short int ne_magic; /* Magic number NE_MAGIC */
  63. char ne_ver; /* Version number */
  64. char ne_rev; /* Revision number */
  65. unsigned short int ne_enttab; /* Offset of Entry Table */
  66. unsigned short int ne_cbenttab; /* Number of bytes in Entry Table */
  67. long ne_crc; /* Checksum of whole file */
  68. unsigned short int ne_flags; /* Flag word */
  69. unsigned short int ne_autodata; /* Automatic data segment number */
  70. unsigned short int ne_heap; /* Initial heap allocation */
  71. unsigned short int ne_stack; /* Initial stack allocation */
  72. long ne_csip; /* Initial CS:IP setting */
  73. long ne_sssp; /* Initial SS:SP setting */
  74. unsigned short int ne_cseg; /* Count of file segments */
  75. unsigned short int ne_cmod; /* Entries in Module Reference Table */
  76. unsigned short int ne_cbnrestab; /* Size of non-resident name table */
  77. unsigned short int ne_segtab; /* Offset of Segment Table */
  78. unsigned short int ne_rsrctab; /* Offset of Resource Table */
  79. unsigned short int ne_restab; /* Offset of resident name table */
  80. unsigned short int ne_modtab; /* Offset of Module Reference Table */
  81. unsigned short int ne_imptab; /* Offset of Imported Names Table */
  82. long ne_nrestab; /* Offset of Non-resident Names Table */
  83. unsigned short int ne_cmovent; /* Count of movable entries */
  84. unsigned short int ne_align; /* Segment alignment shift count */
  85. unsigned short int ne_cres; /* Count of resource segments */
  86. unsigned char ne_exetyp; /* Target Operating system */
  87. unsigned char ne_flagsothers; /* Other .EXE flags */
  88. unsigned short int ne_pretthunks; /* offset to return thunks */
  89. unsigned short int ne_psegrefbytes;/* offset to segment ref. bytes */
  90. unsigned short int ne_swaparea; /* Minimum code swap area size */
  91. unsigned short int ne_expver; /* Expected Windows version number */
  92. };
  93. #define NE_MAGIC(x) (x).ne_magic
  94. #define NE_VER(x) (x).ne_ver
  95. #define NE_REV(x) (x).ne_rev
  96. #define NE_ENTTAB(x) (x).ne_enttab
  97. #define NE_CBENTTAB(x) (x).ne_cbenttab
  98. #define NE_CRC(x) (x).ne_crc
  99. #define NE_FLAGS(x) (x).ne_flags
  100. #define NE_AUTODATA(x) (x).ne_autodata
  101. #define NE_HEAP(x) (x).ne_heap
  102. #define NE_STACK(x) (x).ne_stack
  103. #define NE_CSIP(x) (x).ne_csip
  104. #define NE_SSSP(x) (x).ne_sssp
  105. #define NE_CSEG(x) (x).ne_cseg
  106. #define NE_CMOD(x) (x).ne_cmod
  107. #define NE_CBNRESTAB(x) (x).ne_cbnrestab
  108. #define NE_SEGTAB(x) (x).ne_segtab
  109. #define NE_RSRCTAB(x) (x).ne_rsrctab
  110. #define NE_RESTAB(x) (x).ne_restab
  111. #define NE_MODTAB(x) (x).ne_modtab
  112. #define NE_IMPTAB(x) (x).ne_imptab
  113. #define NE_NRESTAB(x) (x).ne_nrestab
  114. #define NE_CMOVENT(x) (x).ne_cmovent
  115. #define NE_ALIGN(x) (x).ne_align
  116. #define NE_RES(x) (x).ne_res
  117. #define NE_EXETYPE(x) (x).ne_exetyp
  118. #define NE_USAGE(x) (WORD)*((WORD FAR *)(x)+1)
  119. #define NE_PNEXTEXE(x) (WORD)(x).ne_cbenttab
  120. #define NE_PAUTODATA(x) (WORD)(x).ne_crc
  121. #define NE_PFILEINFO(x) (WORD)((DWORD)(x).ne_crc >> 16)
  122. #ifdef DOS5
  123. #define NE_MTE(x) (x).ne_psegcsum /* DOS 5 MTE handle for this module */
  124. #endif
  125. /*
  126. * Format of NE_FLAGS(x):
  127. *
  128. * p Not-a-process
  129. * c Non-conforming
  130. * e Errors in image
  131. * xxxxxxxxx Unused
  132. * P Runs in protected mode
  133. * r Runs in real mode
  134. * i Instance data
  135. * s Solo data
  136. */
  137. #define NENOTP 0x8000 /* Not a process */
  138. #define NENONC 0x4000 /* Non-conforming program */
  139. #define NEIERR 0x2000 /* Errors in image */
  140. #define NEPROT 0x0008 /* Runs in protected mode */
  141. #define NEREAL 0x0004 /* Runs in real mode */
  142. #define NEINST 0x0002 /* Instance data */
  143. #define NESOLO 0x0001 /* Solo data */
  144. struct new_seg /* New .EXE segment table entry */
  145. {
  146. unsigned short ns_sector; /* File sector of start of segment */
  147. unsigned short ns_cbseg; /* Number of bytes in file */
  148. unsigned short ns_flags; /* Attribute flags */
  149. unsigned short ns_minalloc; /* Minimum allocation in bytes */
  150. };
  151. struct new_seg1 /* New .EXE segment table entry */
  152. {
  153. unsigned short ns_sector; /* File sector of start of segment */
  154. unsigned short ns_cbseg; /* Number of bytes in file */
  155. unsigned short ns_flags; /* Attribute flags */
  156. unsigned short ns_minalloc; /* Minimum allocation in bytes */
  157. unsigned short ns_handle; /* Handle of segment */
  158. };
  159. #define NS_SECTOR(x) (x).ns_sector
  160. #define NS_CBSEG(x) (x).ns_cbseg
  161. #define NS_FLAGS(x) (x).ns_flags
  162. #define NS_MINALLOC(x) (x).ns_minalloc
  163. /*
  164. * Format of NS_FLAGS(x):
  165. *
  166. * xxxx Unused
  167. * DD 286 DPL bits
  168. * d Segment has debug info
  169. * r Segment has relocations
  170. * e Execute/read only
  171. * p Preload segment
  172. * P Pure segment
  173. * m Movable segment
  174. * i Iterated segment
  175. * ttt Segment type
  176. */
  177. #define NSTYPE 0x0007 /* Segment type mask */
  178. #define NSCODE 0x0000 /* Code segment */
  179. #define NSDATA 0x0001 /* Data segment */
  180. #define NSITER 0x0008 /* Iterated segment flag */
  181. #define NSMOVE 0x0010 /* Movable segment flag */
  182. #define NSPURE 0x0020 /* Pure segment flag */
  183. #define NSPRELOAD 0x0040 /* Preload segment flag */
  184. #define NSEXRD 0x0080 /* Execute-only (code segment), or
  185. * read-only (data segment)
  186. */
  187. #define NSRELOC 0x0100 /* Segment has relocations */
  188. #define NSDEBUG 0x0200 /* Segment has debug info */
  189. #define NSDPL 0x0C00 /* 286 DPL bits */
  190. #define NSDISCARD 0x1000 /* Discard bit for segment */
  191. #define NSALIGN 9 /* Segment data aligned on 512 byte boundaries */
  192. struct new_segdata /* Segment data */
  193. {
  194. union
  195. {
  196. struct
  197. {
  198. unsigned short ns_niter; /* number of iterations */
  199. unsigned short ns_nbytes; /* number of bytes */
  200. char ns_iterdata; /* iterated data bytes */
  201. } ns_iter;
  202. struct
  203. {
  204. char ns_data; /* data bytes */
  205. } ns_noniter;
  206. } ns_union;
  207. };
  208. struct new_rlcinfo /* Relocation info */
  209. {
  210. unsigned short nr_nreloc; /* number of relocation items that */
  211. }; /* follow */
  212. struct new_rlc /* Relocation item */
  213. {
  214. char nr_stype; /* Source type */
  215. char nr_flags; /* Flag byte */
  216. unsigned short nr_soff; /* Source offset */
  217. union
  218. {
  219. struct
  220. {
  221. char nr_segno; /* Target segment number */
  222. char nr_res; /* Reserved */
  223. unsigned short nr_entry; /* Target Entry Table offset */
  224. } nr_intref; /* Internal reference */
  225. struct
  226. {
  227. unsigned short nr_mod; /* Index into Module Reference Table */
  228. unsigned short nr_proc; /* Procedure ordinal or name offset */
  229. } nr_import; /* Import */
  230. } nr_union; /* Union */
  231. };
  232. #define NR_STYPE(x) (x).nr_stype
  233. #define NR_FLAGS(x) (x).nr_flags
  234. #define NR_SOFF(x) (x).nr_soff
  235. #define NR_SEGNO(x) (x).nr_union.nr_intref.nr_segno
  236. #define NR_RES(x) (x).nr_union.nr_intref.nr_res
  237. #define NR_ENTRY(x) (x).nr_union.nr_intref.nr_entry
  238. #define NR_MOD(x) (x).nr_union.nr_import.nr_mod
  239. #define NR_PROC(x) (x).nr_union.nr_import.nr_proc
  240. /*
  241. * Format of NR_STYPE(x):
  242. *
  243. * xxxxx Unused
  244. * sss Source type
  245. */
  246. #define NRSTYP 0x07 /* Source type mask */
  247. #define NRSSEG 0x02 /* 16-bit segment */
  248. #define NRSPTR 0x03 /* 32-bit pointer */
  249. #define NRSOFF 0x05 /* 16-bit offset */
  250. /*
  251. * Format of NR_FLAGS(x):
  252. *
  253. * xxxxx Unused
  254. * a Additive fixup
  255. * rr Reference type
  256. */
  257. #define NRADD 0x04 /* Additive fixup */
  258. #define NRRTYP 0x03 /* Reference type mask */
  259. #define NRRINT 0x00 /* Internal reference */
  260. #define NRRORD 0x01 /* Import by ordinal */
  261. #define NRRNAM 0x02 /* Import by name */
  262. #define OSFIXUP 0x03 /* Floating point fixup */
  263. /* Resource type or name string */
  264. struct rsrc_string
  265. {
  266. char rs_len; /* number of bytes in string */
  267. char rs_string[ 1 ]; /* text of string */
  268. };
  269. #define RS_LEN( x ) (x).rs_len
  270. #define RS_STRING( x ) (x).rs_string
  271. /* Resource type information block */
  272. struct rsrc_typeinfo
  273. {
  274. unsigned short rt_id;
  275. unsigned short rt_nres;
  276. long rt_proc;
  277. };
  278. #define RT_ID( x ) (x).rt_id
  279. #define RT_NRES( x ) (x).rt_nres
  280. #define RT_PROC( x ) (x).rt_proc
  281. /* Resource name information block */
  282. struct rsrc_nameinfo
  283. {
  284. /* The following two fields must be shifted left by the value of */
  285. /* the rs_align field to compute their actual value. This allows */
  286. /* resources to be larger than 64k, but they do not need to be */
  287. /* aligned on 512 byte boundaries, the way segments are */
  288. unsigned short rn_offset; /* file offset to resource data */
  289. unsigned short rn_length; /* length of resource data */
  290. unsigned short rn_flags; /* resource flags */
  291. unsigned short rn_id; /* resource name id */
  292. unsigned short rn_handle; /* If loaded, then global handle */
  293. unsigned short rn_usage; /* Initially zero. Number of times */
  294. /* the handle for this resource has */
  295. /* been given out */
  296. };
  297. #define RN_OFFSET( x ) (x).rn_offset
  298. #define RN_LENGTH( x ) (x).rn_length
  299. #define RN_FLAGS( x ) (x).rn_flags
  300. #define RN_ID( x ) (x).rn_id
  301. #define RN_HANDLE( x ) (x).rn_handle
  302. #define RN_USAGE( x ) (x).rn_usage
  303. #define RSORDID 0x8000 /* if high bit of ID set then integer id */
  304. /* otherwise ID is offset of string from
  305. the beginning of the resource table */
  306. /* Ideally these are the same as the */
  307. /* corresponding segment flags */
  308. #define RNMOVE 0x0010 /* Moveable resource */
  309. #define RNPURE 0x0020 /* Pure (read-only) resource */
  310. #define RNPRELOAD 0x0040 /* Preloaded resource */
  311. #define RNDISCARD 0x1000 /* Discard bit for resource */
  312. #define RNLOADED 0x0004 /* True if handler proc return handle */
  313. #define RNCOMPR 0x0200 /* Resource is compressed in ROM */
  314. /* Resource table */
  315. struct new_rsrc
  316. {
  317. unsigned short rs_align; /* alignment shift count for resources */
  318. struct rsrc_typeinfo rs_typeinfo;
  319. };
  320. #define RS_ALIGN( x ) (x).rs_align
  321. /* Target operating systems: Possible values of ne_exetyp field */
  322. #define NE_UNKNOWN 0 /* Unknown (any "new-format" OS) */
  323. #define NE_OS2 1 /* Microsoft/IBM OS/2 (default) */
  324. #define NE_WINDOWS 2 /* Microsoft Windows */
  325. #define NE_DOS4 3 /* Microsoft MS-DOS 4.x */
  326. #define NE_DEV386 4 /* Microsoft Windows 386 */