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.

334 lines
6.9 KiB

  1. TITLE LDFILE - Loader file I/O procedures
  2. .xlist
  3. include kernel.inc
  4. include newexe.inc
  5. .list
  6. externFP GlobalAlloc
  7. externFP GlobalFree
  8. externFP MyOpenFile
  9. externFP Int21Handler
  10. sBegin CODE
  11. assumes CS,CODE
  12. externNP MyLock
  13. ;-----------------------------------------------------------------------;
  14. ; LoadNRTable ;
  15. ; ;
  16. ; Returns the segment address of the non-resident name table. ;
  17. ; ;
  18. ; Arguments: ;
  19. ; parmW hexe exeheader to load NRTable from ;
  20. ; parmW fh file handle, -1 if none ;
  21. ; parmD oNRTable if batching, this is where we left off ;
  22. ; parmD lpNRbuffer if batching, this is buffer to use ;
  23. ; parmW cbNRbuffer if batching, this is size of buffer ;
  24. ; ;
  25. ; Returns: ;
  26. ; DX:AX = pointer to non-resident table ;
  27. ; CX:BX = if batching this is where to pick up from ;
  28. ; ;
  29. ; Error Returns: ;
  30. ; DX:AX = NULL ;
  31. ; ;
  32. ; Registers Preserved: ;
  33. ; ;
  34. ; Registers Destroyed: ;
  35. ; ;
  36. ; Calls: ;
  37. ; MyOpenFile ;
  38. ; GlobalAlloc ;
  39. ; MyLock ;
  40. ; ;
  41. ; History: ;
  42. ; ;
  43. ; Tue 09-May-1989 18:38:04 -by- David N. Weise [davidw] ;
  44. ; Added the batching if out of memory. ;
  45. ; ;
  46. ; Thu Oct 08, 1987 10:11:42p -by- David N. Weise [davidw] ;
  47. ; Added this nifty comment block and fixed it for fastboot. ;
  48. ;-----------------------------------------------------------------------;
  49. cProc LoadNRTable,<PUBLIC,NEAR>,<si,di>
  50. parmW hexe
  51. parmW fh
  52. parmD oNRTable
  53. parmD lpNRbuffer
  54. parmW cbNRbuffer
  55. localD lt_ExeoNRTable ; the real offset in the Exe
  56. localD lt_oNRTable
  57. localB fBatching
  58. localB fFirstTime
  59. localW cbnrestab
  60. localW pfileinfo ; used for debugging only
  61. cBegin
  62. mov cx,oNRTable.hi ; Are we batching?
  63. or cx,oNRTable.lo
  64. or cl,ch
  65. mov fBatching,cl
  66. xor di,di
  67. mov fFirstTime,0
  68. if KDEBUG
  69. mov pfileinfo,di
  70. endif
  71. mov es,hexe
  72. mov si,ne_nrestab
  73. mov bx,fh
  74. mov dx,es:[si][2] ; Get potential segment address
  75. mov ax,es:[si][0]
  76. inc bx ; Were we passed a file handle
  77. jnz ltopen ; Yes, go read then
  78. mov dx,es:[di].ne_pfileinfo ; No, then open the file
  79. if SHARE_AWARE
  80. mov bx,OF_REOPEN or OF_PROMPT or OF_CANCEL or OF_VERIFY or OF_NO_INHERIT or OF_SHARE_DENY_WRITE
  81. else
  82. mov bx,OF_REOPEN or OF_PROMPT or OF_CANCEL or OF_VERIFY or OF_NO_INHERIT
  83. endif
  84. if KDEBUG
  85. mov pfileinfo,dx
  86. krDebugOut <DEB_TRACE or DEB_krLoadSeg>, "Non-Res name table of @ES:DX"
  87. endif
  88. regptr esdx,es,dx
  89. push dx
  90. push es
  91. cCall MyOpenFile,<esdx,esdx,bx>
  92. pop es
  93. pop dx
  94. ;;; cmp ax, -1
  95. ;;; jne @F
  96. ;;;
  97. ;;; mov bx,OF_REOPEN or OF_VERIFY or OF_NO_INHERIT
  98. ;;; cCall MyOpenFile,<esdx,esdx,bx>
  99. ;;;
  100. ;;;@@:
  101. mov es,hexe
  102. inc bx
  103. jnz ltopen
  104. jmp ltfail
  105. ltopen:
  106. krDebugOut <DEB_TRACE or DEB_krLoadSeg>, "Loading %es2 Nonresident name table"
  107. dec bx
  108. mov dx,es:[si][0] ; AX:DX = file address of table
  109. mov ax,es:[si][2]
  110. cmp es:[di].ne_pfileinfo,di ; Is the NRTable in WIN200.OVL?
  111. jnz lt_seek
  112. mov cx,4 ; Shift left AX:DX by 4.
  113. lt_winovl:
  114. shl dx,1
  115. rcl ax,1
  116. loop lt_winovl
  117. lt_seek:
  118. mov lt_ExeoNRTable.hi,ax
  119. mov lt_ExeoNRTable.lo,dx
  120. cmp fBatching,0 ; Are we batching?
  121. jz lt_not_batching
  122. mov ax,oNRTable.hi
  123. mov dx,oNRTable.lo
  124. lt_not_batching:
  125. mov lt_oNRTable.hi,ax
  126. mov lt_oNRTable.lo,dx
  127. mov cx,ax ; CX:DX = file address of table
  128. mov ax,4200h ; Seek to beginning of the table
  129. DOSCALL
  130. jnc @F
  131. jmp ltfail
  132. @@: push es
  133. push bx
  134. cmp fBatching,0
  135. jz lt_first_time
  136. lt_got_no_space:
  137. mov es,hexe
  138. mov dx,oNRTable.hi
  139. mov ax,oNRTable.lo
  140. sub ax,lt_ExeoNRTable.lo ; compute the bytes read so far
  141. sbb dx,lt_ExeoNRTable.hi
  142. sub ax,es:[di].ne_cbnrestab
  143. neg ax
  144. cmp ax,cbNRbuffer
  145. jbe @F
  146. mov ax,cbNRbuffer
  147. @@: mov cbnrestab,ax
  148. les di,lpNRbuffer
  149. mov ax,es
  150. mov dx,ax
  151. jmps lt_share_your_space
  152. lt_first_time:
  153. mov fFirstTime,1 ; make non-zero
  154. mov ax,es:[ne_cbnrestab] ; first time through
  155. mov cbnrestab,ax
  156. add ax,4
  157. mov bx,GA_MOVEABLE or GA_NODISCARD
  158. xor cx,cx
  159. cCall GlobalAlloc,<bx,cx,ax>
  160. xor dx,dx
  161. or ax,ax
  162. jnz lt_got_space
  163. mov ax,lt_oNRTable.hi
  164. mov oNRTable.hi,ax
  165. mov ax,lt_oNRTable.lo
  166. mov oNRTable.lo,ax
  167. mov fBatching,1
  168. jmp lt_got_no_space
  169. lt_got_space:
  170. cCall MyLock,<ax>
  171. xor di,di
  172. lt_share_your_space:
  173. pop bx
  174. mov cx,ds ; Save DS
  175. pop ds
  176. push cx ; after alloc
  177. mov es,ax
  178. cmp fBatching,0
  179. jnz @F
  180. xor ax,ax ; Set table loaded indicator
  181. xchg ds:[si],ax
  182. cld
  183. stosw ; Save file offset
  184. mov ax,dx
  185. xchg ds:[si+2],ax ; Set segment handle
  186. stosw ; Save file offset
  187. @@: mov cx,cbnrestab
  188. smov ds,es
  189. push dx
  190. mov dx,di
  191. mov ah,3Fh ; Read in the table
  192. DOSCALL
  193. pop dx
  194. pop ds
  195. jc ltfail ; did the DOS call fail?
  196. cmp ax,cx ; did we get all the bytes?
  197. jne ltfail
  198. cmp fBatching,0 ; are we batching?
  199. jz ltdone
  200. std ; truncate to whole strings
  201. push bx
  202. xor ax,ax
  203. xor bx,bx
  204. mov dx,cbNRbuffer
  205. dec dx
  206. @@: cmp byte ptr es:[di][bx],0 ; are we at end of NRTable?
  207. jnz lt_not_buffer_end
  208. xor ax,ax
  209. mov oNRTable.hi,ax
  210. mov oNRTable.lo,ax
  211. jmps lt_return_buffer
  212. lt_not_buffer_end:
  213. mov cx,bx
  214. mov al,byte ptr es:[di][bx]
  215. add bx,ax
  216. add bx,3
  217. cmp bx,dx
  218. jb @B
  219. mov bx,cx
  220. mov byte ptr es:[di][bx],0
  221. add oNRTable.lo,bx
  222. adc oNRTable.hi,0
  223. lt_return_buffer:
  224. pop bx
  225. les ax,lpNRbuffer
  226. mov dx,es
  227. cmp fFirstTime,0
  228. jnz ltdone_0
  229. jmps ltexit
  230. ltdone:
  231. push bx
  232. cCall MyLock,<dx>
  233. pop bx
  234. mov dx,ax
  235. mov ax,4
  236. ltdone_0:
  237. mov es,dx
  238. mov si,ax
  239. xor ax,ax
  240. mov al,es:[si]
  241. add ax,si
  242. add ax,3
  243. jmps ltexit
  244. ltfail:
  245. if KDEBUG
  246. push bx
  247. ifdef WOW
  248. mov bx, hexe
  249. krDebugOut DEB_ERROR, "Unable to load non-resident name table from mod #BX. "
  250. else
  251. kerror ERR_LDNRTABLE,<Unable to load non-resident name table from >,hexe,pfileinfo
  252. ;;; kerror ERR_LDNRTABLE,<(TRY FILES=30 to fix this) Unable to load non-resident name table from >,hexe,pfileinfo
  253. endif
  254. pop bx
  255. endif
  256. xor ax,ax
  257. xor dx,dx
  258. ltexit: cmp bx,fh
  259. je ltx1
  260. push ax
  261. mov ah,3Eh
  262. DOSCALL
  263. pop ax
  264. ltx1:
  265. mov cx,oNRTable.hi
  266. mov bx,oNRTable.lo
  267. cld ; we'll be polite
  268. cEnd
  269. ;
  270. ; GetStringPtr( hExe, offset ) - Procedure to return the far address of a
  271. ; string in the passed new EXE file's string table
  272. ;
  273. cProc GetStringPtr,<PUBLIC,NEAR>,<si,di>
  274. parmW hExe
  275. parmW fh
  276. parmW soffset
  277. cBegin
  278. mov es,hExe
  279. mov dx,es
  280. mov ax,es:[ne_imptab]
  281. add ax,soffset
  282. cEnd
  283. ; FreeNRTable( lptable ) - Procedure to free table allocated by LoadNRTable
  284. ; and restore the new EXE header information.
  285. cProc FreeNRTable,<PUBLIC,FAR>,<si,di>
  286. parmW hexe
  287. parmW tblid
  288. cBegin
  289. mov es,hexe
  290. mov di,tblid
  291. xor ax,ax
  292. mov cx,es:[di+2]
  293. cmp word ptr es:[di],0
  294. jne lfexit
  295. jcxz lfexit
  296. push cx
  297. cCall MyLock,<cx>
  298. pop cx
  299. mov es,hexe
  300. push ds
  301. mov ds,ax
  302. xor si,si
  303. cld
  304. movsw
  305. movsw
  306. pop ds
  307. cCall GlobalFree,<cx>
  308. lfexit:
  309. cEnd
  310. sEnd CODE
  311. end