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.

384 lines
8.6 KiB

  1. TITLE LDCACHE - Segment and File Handle Caching procedures
  2. .xlist
  3. include kernel.inc
  4. include newexe.inc
  5. include tdb.inc
  6. .list
  7. DataBegin
  8. externW hExeHead
  9. externW topPDB
  10. externW Win_PDB
  11. externW curTDB
  12. externW cur_dos_PDB
  13. externB fhCache
  14. externW fhCacheLen
  15. externW fhCacheEnd
  16. externW fhcStealNext
  17. DataEnd
  18. externFP MyOpenFile
  19. externFP Int21Handler
  20. sBegin CODE
  21. assumes CS,CODE
  22. assumes DS,NOTHING
  23. assumes ES,NOTHING
  24. externNP real_DOS
  25. ;-----------------------------------------------------------------------;
  26. ; GetCachedFileHandle ;
  27. ; ;
  28. ; Look for the file handle for an EXE file in the cache of file ;
  29. ; handles. Sets current PDB to that of KERNEL to access the file. ;
  30. ; A handle NOT to free in order to satisfy the request can also ;
  31. ; be given. ;
  32. ; ;
  33. ; Arguments: ;
  34. ; parmW hExe handle of EXE file ;
  35. ; parmW keepfh file handle not to change ;
  36. ; parmW fh file handle if file already open ;
  37. ; ;
  38. ; Returns: ;
  39. ; AX == file handle ;
  40. ; ;
  41. ; Error Returns: ;
  42. ; ;
  43. ; Registers Preserved: ;
  44. ; ;
  45. ; Registers Destroyed: ;
  46. ; ;
  47. ; Calls: ;
  48. ; real_DOS ;
  49. ; ;
  50. ; History: ;
  51. ; Wed 18-Oct-1989 20:40:51 -by- David N. Weise [davidw] ;
  52. ; Added the feature of not closing a specified handle. ;
  53. ;-----------------------------------------------------------------------;
  54. assumes ds, nothing
  55. assumes es, nothing
  56. ifdef WOW
  57. .286
  58. else
  59. endif
  60. cProc FarGetCachedFileHandle,<PUBLIC,FAR>
  61. parmW hExe
  62. parmW keepfh
  63. parmW fh
  64. cBegin
  65. cCall GetCachedFileHandle,<hExe,keepfh,fh>
  66. cEnd
  67. cProc GetCachedFileHandle,<PUBLIC,NEAR>,<bx,di,ds,es>
  68. parmW hExe
  69. parmW keepfh
  70. parmW fh ; -1 if file not open
  71. localW fhcFreeEntry
  72. cBegin
  73. SetKernelDS
  74. mov fhcFreeEntry, 0
  75. mov bx, topPDB
  76. ;;; cmp bx, Win_PDB
  77. ;;; je gcfh_okPDB ; Don't bother setting if already this
  78. ;;; mov cur_dos_PDB, bx
  79. ;;; mov Win_PDB, bx ; Run on kernel's PDB for a while
  80. ;;; mov ah, 50h ; set PDB
  81. ;;; call real_DOS
  82. ;;;gcfh_okPDB:
  83. mov Win_PDB, bx ; Run on kernel's PDB for a while
  84. mov ax, hExe ; look for this EXE in the file
  85. mov es, ax ; handle cache
  86. mov cx, fhCacheLen
  87. mov di, dataOffset fhCache
  88. gcfh_searchfh:
  89. mov bx, [di.CacheExe]
  90. cmp ax, bx
  91. jne @F
  92. jmps gcfh_found
  93. @@:
  94. or bx, bx ; Free entry?
  95. jnz gcfh_searchnext
  96. cmp fhcFreeEntry, bx ; already have a free entry?
  97. jne gcfh_searchnext
  98. mov fhcFreeEntry, di ; Save index for free entry
  99. gcfh_searchnext:
  100. add di, size fhCacheStruc
  101. loop gcfh_searchfh
  102. ; EXE not already in the cache
  103. mov di, fhcFreeEntry ; Did we find a free entry?
  104. or di, di
  105. jz gcfh_stealone ; no, steal one
  106. mov fhcFreeEntry, -1 ; Flag to steal one if the open fails
  107. jmps gcfh_openit ; (due to out of file handles)
  108. gcfh_stealone: ; No free entry, pick one on first come,
  109. mov cx, fhcStealNext ; first served basis
  110. gcfh_stealnext:
  111. mov di, cx
  112. add cx, 4 ; Calculate next index in CX
  113. cmp cx, fhCacheEnd
  114. jb gcfh_oknext
  115. mov cx, dataoffset fhCache ; Start back at the beginning
  116. gcfh_oknext:
  117. mov bx, [di.Cachefh]
  118. or bx, bx ; If no file handle,
  119. jz gcfh_stealnext ; on to next cache entry
  120. cmp bx, keepfh ; If handle not to free
  121. jz gcfh_stealnext ; on to next cache entry
  122. mov fhcStealNext, cx
  123. mov ah, 3Eh
  124. DOSCALL ; Close this file handle
  125. mov fhcFreeEntry, di
  126. gcfh_openit:
  127. push ds
  128. mov ax, fh
  129. cmp ax, -1 ; File already open?
  130. jne gcfh_opened ; yes, just put in cache
  131. mov dx,es:[ne_pfileinfo]
  132. regptr esdx,es,dx
  133. ; mov bx,OF_SHARE_DENY_WRITE or OF_REOPEN or OF_PROMPT or OF_VERIFY or OF_CANCEL
  134. ;;; mov bx,OF_REOPEN or OF_PROMPT or OF_VERIFY or OF_CANCEL
  135. if 1
  136. smov ds,es
  137. add dx, opFile
  138. ;;; test es:[ne_flags],NEAPPLOADER
  139. ;;; jnz @F
  140. if SHARE_AWARE
  141. mov ax, 3DA0h ; open for read, deny write, no inherit
  142. else
  143. mov ax, 3D80h ; open for read, no inherit
  144. endif
  145. DOSCALL
  146. jnc gcfh_opened
  147. ;;;@@:
  148. mov ax, 3DC0h ; try share deny none
  149. DOSCALL
  150. jnc gcfh_opened
  151. else
  152. mov bx,OF_REOPEN or OF_VERIFY
  153. push es
  154. cCall MyOpenFile,<esdx,esdx,bx>
  155. pop es
  156. cmp ax, -1
  157. jne gcfh_opened
  158. endif
  159. pop ds
  160. cmp fhcFreeEntry, -1 ; This was a free cache entry?
  161. je gcfh_stealone ; yes, have run out of file handles
  162. mov ax, -1 ; fix bug #6774 donc
  163. jmps gcfh_exit ; no, a real failure
  164. gcfh_found:
  165. mov ax, [di.Cachefh]
  166. jmps gcfh_exit
  167. gcfh_opened:
  168. pop ds
  169. mov [di.Cachefh], ax
  170. mov [di.CacheExe], es
  171. gcfh_exit:
  172. cEnd
  173. ;-----------------------------------------------------------------------;
  174. ; CloseCachedFileHandle ;
  175. ; ;
  176. ; Close the EXE file with the given file handle. ;
  177. ; Actually does delays closing the file until the handle is needed. ;
  178. ; Resets the current PDB to that of the current task. ;
  179. ; ;
  180. ; Arguments: ;
  181. ; parmW fh file handle being 'closed' ;
  182. ; ;
  183. ; Returns: ;
  184. ; none ;
  185. ; ;
  186. ; Error Returns: ;
  187. ; ;
  188. ; Registers Preserved: ;
  189. ; ;
  190. ; Registers Destroyed: ;
  191. ; AX ;
  192. ; ;
  193. ; Calls: ;
  194. ; real_DOS ;
  195. ; ;
  196. ; History: ;
  197. ; ;
  198. ;-----------------------------------------------------------------------;
  199. assumes ds,nothing
  200. assumes es,nothing
  201. cProc CloseCachedFileHandle,<PUBLIC,NEAR>,<bx,ds,es>
  202. parmW fh
  203. cBegin
  204. ;;; SetKernelDS
  205. ;;; mov es, curTDB
  206. ;;; mov bx, es:[TDB_PDB]
  207. ;;; cmp bx, Win_PDB
  208. ;;; je ccfh_okPDB
  209. ;;; mov Win_PDB, bx
  210. ;;; mov cur_dos_PDB, bx
  211. ;;; mov ah, 50h
  212. ;;; call real_DOS
  213. ;;;ccfh_okPDB:
  214. cEnd
  215. ;-----------------------------------------------------------------------;
  216. ; FlushCachedFileHandle ;
  217. ; ;
  218. ; Look for the file handle for an EXE file in the cache of file handles ;
  219. ; If it is found, close the file. ;
  220. ; ;
  221. ; Arguments: ;
  222. ; parmW hExe handle of EXE file ;
  223. ; ;
  224. ; Returns: ;
  225. ; ;
  226. ; Error Returns: ;
  227. ; ;
  228. ; Registers Preserved: ;
  229. ; ;
  230. ; Registers Destroyed: ;
  231. ; ;
  232. ; Calls: ;
  233. ; real_DOS ;
  234. ; ;
  235. ; History: ;
  236. ; ;
  237. ;-----------------------------------------------------------------------;
  238. assumes ds, nothing
  239. assumes es, nothing
  240. cProc FlushCachedFileHandle,<PUBLIC,FAR>,<ax,bx,cx,di>
  241. parmW hExe
  242. cBegin
  243. SetKernelDS
  244. mov ax, hExe
  245. or ax, ax ; make sure we really
  246. jz fcfh_exit ; have a hExe
  247. mov cx, fhCacheLen
  248. mov di, dataOffset fhCache
  249. fcfh_search:
  250. cmp ax, [di.CacheExe]
  251. je fcfh_found
  252. add di, size fhCacheStruc
  253. loop fcfh_search
  254. jmps fcfh_exit ; Not cached, nothing to do
  255. fcfh_found:
  256. ;;; mov bx, topPDB
  257. ;;; cmp bx, cur_dos_PDB
  258. ;;; je fcfh_okPDB
  259. ;;; mov cur_dos_PDB, bx
  260. ;;; mov ah, 50h ; set PDB
  261. ;;; call real_DOS
  262. ;;;fcfh_okPDB:
  263. push Win_PDB ; Save 'current' PDB
  264. mov bx, topPDB
  265. mov Win_PDB, bx ; Run on kernel's PDB for a while
  266. mov bx, [di.Cachefh]
  267. mov ah, 3Eh ; Close the file
  268. DOSCALL
  269. xor ax, ax
  270. mov [di.Cachefh], ax ; mark cache entry free
  271. mov [di.CacheExe], ax
  272. ;;; push es
  273. ;;; mov es, curTDB ; and reset the PDB
  274. ;;; mov bx, es:[TDB_PDB]
  275. ;;; pop es
  276. ;;; cmp bx, Win_PDB
  277. ;;; je fcfh_exit
  278. ;;; mov Win_PDB, bx
  279. ;;; mov cur_dos_PDB, bx
  280. ;;; mov ah, 50h
  281. ;;; call real_DOS
  282. pop Win_PDB ; Restore original PDB
  283. fcfh_exit:
  284. cEnd
  285. ;-----------------------------------------------------------------------;
  286. ; CloseCachedFiles ;
  287. ; ;
  288. ; Close all the cached files on a duplicate PDB ;
  289. ; Leaves PDB set to new PDB ;
  290. ; ;
  291. ; Arguments: ;
  292. ; parmW pdb new PDB ;
  293. ; ;
  294. ; Returns: ;
  295. ; ;
  296. ; Error Returns: ;
  297. ; ;
  298. ; Registers Preserved: ;
  299. ; ;
  300. ; Registers Destroyed: ;
  301. ; ;
  302. ; Calls: ;
  303. ; real_DOS ;
  304. ; ;
  305. ; History: ;
  306. ; ;
  307. ;-----------------------------------------------------------------------;
  308. assumes ds, nothing
  309. assumes es, nothing
  310. cProc CloseCachedFiles,<PUBLIC,FAR>,<ax,bx,cx,di,ds>
  311. parmW pdb
  312. cBegin
  313. SetKernelDS
  314. mov bx, pdb
  315. mov Win_PDB, bx
  316. ;;; mov ah, 50h
  317. ;;; call real_DOS ; Run on the new guy
  318. mov dx, bx
  319. mov cx, fhCacheLen
  320. mov di, dataOffset fhCache
  321. ccf_search:
  322. mov bx, [di.Cachefh]
  323. or bx, bx
  324. je ccf_next
  325. mov ah, 3Eh ; Close the file
  326. call real_DOS
  327. cmp dx,topPDB ; If closing cached files on
  328. jne ccf_next ; the kernel's PDB, mark the
  329. xor ax,ax ; cache entry as free
  330. mov [di.Cachefh], ax
  331. mov [di.CacheExe], ax
  332. ccf_next:
  333. add di, size fhCacheStruc
  334. loop ccf_search
  335. cEnd
  336. sEnd CODE
  337. end