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.

391 lines
17 KiB

  1. New Executable Format
  2. DOS 2.0 Windows will define a new executable format for .EXE files
  3. that is a superset of the current DOS 2.0 .EXE format. The purpose
  4. of this new format is to provide the additional information needed
  5. to support the new dynamic linking and segmentation facilities provided
  6. by DOS 2.0 Windows and DOS 4.0. In order for Windows and DOS 4.0
  7. to recognize the new executable format, the existing .EXE format
  8. will be used with a slight modification:
  9. - the word at offset 18h in the existing .EXE file contains the
  10. relative byte offset to the relocation table. If this offset
  11. is 40h, then that identifies this as a new format .EXE file and
  12. The word at offset 24h is the relative byte offset from the
  13. beginning of the file to the beginning of the new format
  14. executable header. The remainder of the old format header will
  15. describe a small program that will either print an error message
  16. or bring in a loader that can handle the job. See the picture
  17. below for the actual file layout.
  18. - this format will only be used for .EXE files that use the new
  19. memory model supported by DOS 2.0 Windows and DOS 4.0. Old .EXE
  20. files will continue with the DOS 2.0 file format, as modified
  21. by the DOS 4.0 group. In that format, the DOS 4.0 behavior bits
  22. (2 bytes) are stored at offset 20h.
  23. The format of the new .EXE file format looks like:
  24. 00h -------------------
  25. | |
  26. | Old EXE Header |
  27. | |
  28. -------------------
  29. 20h | DOS 4.0 bbits |
  30. 22h | unused bbits |
  31. 3eh | offset to new | ----
  32. | EXE header | |
  33. 40h ------------------- |
  34. | DOS 2.0 Stub | |
  35. | Program & | |
  36. | Reloc. Table | |
  37. xxh ------------------- <---
  38. | |
  39. | New EXE Header |\
  40. | | \
  41. ------------------- \
  42. | | |
  43. | Segment Table | |
  44. | | |
  45. ------------------- |
  46. | Resource | | DOS4 and Windows keep this
  47. | Table | |-----------part as part of their
  48. ------------------- | MODULE table, currently
  49. | Resident | |
  50. | Name | |
  51. | Table | |
  52. ------------------- /
  53. | Module Ref | /
  54. | Table |/
  55. -------------------
  56. | Imported |
  57. | Names |
  58. | Table |
  59. -------------------
  60. * | Entry |
  61. * | Table |
  62. -------------------
  63. | Non-Resident |
  64. | Name |
  65. | Table |
  66. -------------------
  67. | Seg #1 Data |
  68. | Seg #1 Info |
  69. -------------------
  70. .
  71. .
  72. .
  73. -------------------
  74. | Seg #n Data |
  75. | Seg #n Info |
  76. -------------------
  77. 20h - DW DOS 4.0 behavior bits
  78. * 22h - 3ch - reserved for more behavior info
  79. * 3eh - DW offset to new executable header
  80. Program that DOS 2.0 header points to, that will either print out an
  81. error message or load in a new-EXE loader.
  82. xxh - Beginning of new executable header
  83. DW signature word - can never be too careful
  84. "N" is low order byte
  85. "E" is high order byte
  86. DB version# of LINK that produced this executable
  87. DB revision# of LINK that produced this executable
  88. DW Entry Table file offset relative to beginning of new EXE header
  89. DW #bytes in Entry Table
  90. DD CRC-32 of entire contents of file (with these words taken
  91. as 00 during the calculation)
  92. DW flag word
  93. 0000h = NOAUTODATA
  94. 0001h = SINGLEDATA (SOLO)
  95. 0002h = MULTIPLEDATA (INSTANCE)
  96. 0004h = runs in real mode
  97. 0008h = runs in protected mode (if 0Ch set, runs in either)
  98. 4000h = non-conforming program (a valid stack is not maintained)
  99. 8000h = Library module (SS:SP info is invalid, CS:IP points
  100. to initialization procedure that is called with AX
  101. = the module handle. The procedure must execute a
  102. far return to the caller, with AX != 0 to indicate
  103. success and AX = 0 to indicate failure to
  104. initialize. DS = the library's data segment if the
  105. SINGLEDATA flag is set and the caller's DS
  106. otherwise.
  107. A program can only contain dynamic links to
  108. executables that have this flag set. If this flag
  109. is set, the MULTIPLEDATA flag must be reset. The
  110. SINGLEDATA flag may be set or reset.
  111. DW segment# of automatic data segment (index into segment table)
  112. set to zero if SINGLEDATA and MULTIPLEDATA flag bits are reset
  113. DW initial size (bytes) of dynamic heap added to data segment
  114. (0 if no local alloc)
  115. DW initial size (bytes) of stack added to data segment
  116. (0 if SS!=DS)
  117. DD segment#:offset of CS:IP
  118. DD segment#:offset of SS:SP
  119. Segment# is an index into the module's segment table.
  120. The first entry in the segment table is segment number 1.
  121. If SS = automatic data segment and SP = 0,
  122. the stack pointer is set to the top of the automatic
  123. data segment just below the additional heap area.
  124. +-------------------------+
  125. | additional dynamic heap |
  126. +-------------------------+ <- SP
  127. | additional stack |
  128. +-------------------------+
  129. | loaded data segment |
  130. +-------------------------+ <- DS, SS
  131. DW #of entries in Segment Table
  132. DW #of entries in Module Ref Table
  133. DW #bytes in Non-Resident Name Table
  134. DW Segment Table file offset relative to beginning of new EXE header
  135. DW Resource Table file offset relative to beginning of new EXE header
  136. DW Resident Name Table file offset relative to beginning of new EXE header
  137. DW Module Ref Table file offset relative to beginning of new EXE header
  138. DW Imported Names Table file offset relative to beginning of new EXE header
  139. DD Non-Resident Name Table offset relative to beginning of file
  140. * DW #moveable entry points
  141. * DW alignment shift count for segment data. Value of zero means
  142. * use the default value of 9 for 512 byte alignment.
  143. * DB 12 DUP (?) - room for growth here
  144. Segment Table
  145. =============
  146. "N" segment table entries:
  147. The first entry in the segment table is segment number 1.
  148. * DW logical sector offset to contents of the segment data
  149. * relative to beginning of file (zero means no file data)
  150. * The alignment field in the header determines the units
  151. * of this offset.
  152. DW length of segment in file (bytes) (zero means 64k bytes)
  153. DW flag word
  154. TYPE_MASK = 0007h ; segment type field
  155. CODE = 0000h ; code segment type
  156. DATA = 0001h ; data segment type
  157. ITERATED = 0008h ; segment data is iterated
  158. MOVABLE = 0010h ; segment is not fixed
  159. PURE = 0020h ; segment can be shared
  160. PRELOAD = 0040h ; segment is not demand loaded
  161. ERONLY = 0080h ; execute only if code segment
  162. ; read only if data segment
  163. RELOCINFO = 0100h ; set if segment has reloc records
  164. DEBUGINFO = 0200h ; set if segment has debug info
  165. SEGDPL = 0C00h ; reserved for 286 DPL bits
  166. DISCARDABLE = F000h ; static discard priority level
  167. DW minimum allocation size (bytes)
  168. Total size of the segment (0 means 65536)
  169. Resource Table
  170. ==============
  171. DW alignment shift count for resource data
  172. "N" iterations of record:
  173. | DW type ID - integer type if high order bit is set (8000h)
  174. | otherwise offset to type string, relative to
  175. | beginning of the resource table
  176. | = 0 marks end of resource records
  177. |
  178. | DW #resources for this type
  179. | DD reserved for runtime use
  180. | |
  181. | | "#resources" copies of Resource Entry (8 bytes)
  182. | |
  183. | | DW file offset to contents of the resource data relative
  184. | | to beginning of file. Offset is in terms of alignment
  185. | | units specified at beginning of resource table.
  186. | | DW length of resource in file (bytes)
  187. | | DW flag word
  188. | | MOVEABLE = 0010h ; resource is not fixed
  189. | | PURE = 0020h ; resource can be shared
  190. | | PRELOAD = 0040h ; resource is not demand loaded
  191. | | DW resource ID - integer type if high order bit is set (8000h)
  192. | | otherwise offset to resource string, relative to beginning
  193. | | of the resource table
  194. | | DD reserved for runtime use
  195. \ \
  196. Resource type and name strings stored at end of resource table
  197. Note that these strings are NOT null terminated
  198. DB length of type or name ; = 0 if end of resource table
  199. DB ASCII text of type or name ; Case sensitive
  200. Module Reference Table
  201. ======================
  202. "N" entries of the form: (1-based)
  203. DW offset within Imported Names Table to module name string
  204. Entry Table (1 based)
  205. ===========
  206. "N" bundles of entry definitions. The ordinal value of an entry
  207. | point is its ordinal within the entry table, counting the
  208. | first entry as ordinal #1. The loader must scan over the
  209. | bundles until it finds the bundle containing the entry point;
  210. | the loader can then multiply by entry size to index the
  211. | proper entry.
  212. |
  213. | The linker forms bundles in the densest manner it can, given
  214. | the restriction that it cannot reorder entry points to improve
  215. | bundling because other EXE files may refer to entry points within
  216. | this one by their ordinal in this table.
  217. |
  218. | DB #entries in this bundle. All records in one bundle are
  219. | either movabe or refer to the same fixed segment.
  220. | =0 if no more bundles in Entry Table
  221. |
  222. | DB segment indicator for this bundle
  223. | | 000 - Unused
  224. | | 0FF - Movable segment, # is in entry
  225. | | otherwise is segment # of fixed segment
  226. | |
  227. | | If fixed segment, entries are 3 bytes:
  228. | | DB flags
  229. | | 0000 0001 - set if entry is exported
  230. | | 0000 0010 - set if entry uses global (shared) data segment
  231. | | "mov ax,#ds-value" must be the 1st
  232. | | instruction in the prolog of this
  233. | | entry. This flag may only be set
  234. | | for SINGLEDATA library modules.
  235. | | nnnn n--- - # of parameter words
  236. | | DW offset
  237. | | Else movable segment, entries are 6 bytes:
  238. | | DB flags
  239. | | 0000 0001 - set if entry is exported
  240. | | 0000 0010 - set if segment uses global (shared) data segment
  241. | | nnnn n--- - # of parameter words
  242. | | int 3Fh
  243. | | DB segment#
  244. \ \ DW offset
  245. Resident or Non-resident Name Table Entry (3 + n bytes)
  246. =========================================
  247. The strings are CASE SENSITIVE and NOT NULL TERMINATED. If the
  248. * .EXE was produced with the /IGNORECASE switch, then all strings
  249. * will be UPPERCASE
  250. DB Length of string ; =0 if no more strings in table
  251. DB ASCII text of string
  252. DW ordinal# (index into entry table)
  253. First string in resident name table is the module name.
  254. First string in non-resident name table is the module description.
  255. Imported Names Table Entry (1 + n bytes)
  256. ==========================
  257. The strings are CASE SENSITIVE and NOT NULL TERMINATED. If the
  258. * .EXE was produced with the /IGNORECASE switch, then all strings
  259. * will be UPPERCASE
  260. DB Length of name ; =0 if no more strings in Table
  261. DB ASCII text of name
  262. Per segment data:
  263. ================
  264. If ITERATED
  265. DW #iterations
  266. DW #bytes of data
  267. DB data bytes
  268. else
  269. DB data bytes
  270. If RELOCINFO
  271. DW #relocation items
  272. |
  273. | Relocation Item: (8 bytes)
  274. |
  275. | DB source type (32 bit address, 16 bit segment, 16 bit offset)
  276. | NRSTYP = 07h ; source type mask
  277. | NRSBYTE = 00h
  278. | NRSSEG = 02h ; 16-bit segment
  279. | NRSPTR = 03h ; 32-bit pointer
  280. | NRSOFF = 05h ; 16-bit offset
  281. | DB flags
  282. | TARGET_MASK = 03h
  283. | INTERNALREF = 00h
  284. | IMPORTORDINAL = 01h
  285. | IMPORTNAME = 02h
  286. | ADDITIVE = 04h
  287. | DW offset within this segment of source chain
  288. | If ADDITIVE flag set, then add target value to source contents,
  289. | instead of replacing source and following the chain.
  290. | The source chain is a 0xFFFF terminated linked list within
  291. | this segment of all references to the target.
  292. | Target
  293. | INTERNALREF
  294. | DB segment# for fixed segment or FF if movable
  295. | DB 0
  296. | DW if moveable segment
  297. * | ordinal# (index into entry table of this module)
  298. | if fixed segment
  299. | offset into segment if fixed
  300. |
  301. | IMPORTNAME
  302. | DW index into module ref table
  303. | DW offset within Imported Names Table to proc. name string
  304. |
  305. | IMPORTORDINAL
  306. | DW index into module ref table
  307. | DW procedure ordinal#
  308. |
  309. | OSFIXUP
  310. | DW Operating system fixup type
  311. |
  312. | floating-point fixups
  313. | 0001h = FIARQQ, FJARQQ
  314. | 0002h = FISRQQ, FJSRQQ
  315. | 0003h = FICRQQ, FJCRQQ
  316. | 0004h = FIERQQ
  317. | 0005h = FIDRQQ
  318. | 0006h = FIWRQQ
  319. | applied by adding the fixup to the coprocessor instr.
  320. | for 1-3, apply the first fixup at the offset, and
  321. | the second fixup at the offset+1. for 4-6, just add
  322. | the fixup at the offset.
  323. |
  324. | NOTE: the linker marks these relocations as NRSOFF, but
  325. | they must be applied differently. in ldreloc.asm, we
  326. | use a flag to discern this case.
  327. |
  328. \ DW 0
  329. If DEBUGINFO
  330. DW # of bytes of debug info
  331. <debug info - not yet defined>
  332. NOTE: this document does not totally agree with version 1.7, dated 5/05/87.