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.

557 lines
13 KiB

  1. .xlist
  2. include kernel.inc
  3. include newexe.inc
  4. include tdb.inc
  5. .list
  6. ;externFP GlobalCompact
  7. externFP GlobalFreeAll
  8. externFP GetExePtr
  9. externFP FarMyFree
  10. externFP Far_genter
  11. externFP FlushCachedFileHandle
  12. externFP GetProcAddress
  13. externFP FarUnlinkObject
  14. externFP CallWEP
  15. externFP lstrcpy
  16. if SDEBUG
  17. externFP FarDebugDelModule
  18. endif
  19. DataBegin
  20. externB fBooting
  21. ;externW EMScurPID
  22. externW curTDB
  23. externW loadTDB
  24. externW headTDB
  25. externW hExeHead
  26. externW pGlobalHeap
  27. externW MyCSDS
  28. externD pSignalProc
  29. ifdef WOW
  30. externW hWinnetDriver
  31. externW hUser
  32. endif ; WOW
  33. DataEnd
  34. sBegin CODE
  35. assumes CS,CODE
  36. assumes DS,NOTHING
  37. assumes ES,NOTHING
  38. ;-----------------------------------------------------------------------;
  39. ; UnlinkObject ;
  40. ; ;
  41. ; Removes an object from a singly linked list of objects. ;
  42. ; ;
  43. ; Arguments: ;
  44. ; CS:BX = head of chain ;
  45. ; ES = object to delete ;
  46. ; DX = offset of next pointer in object ;
  47. ; ;
  48. ; Returns: ;
  49. ; AX = deleted object ;
  50. ; ;
  51. ; Error Returns: ;
  52. ; none ;
  53. ; ;
  54. ; Registers Preserved: ;
  55. ; BX,DI,SI,BP,DS ;
  56. ; ;
  57. ; Registers Destroyed: ;
  58. ; CX,DX,ES ;
  59. ; ;
  60. ; Calls: ;
  61. ; ;
  62. ; History: ;
  63. ; ;
  64. ; Mon Sep 29, 1986 11:29:32a -by- Charles Whitmer [chuckwh] ;
  65. ; Wrote it to remove this code from the three different places where ;
  66. ; it was included inline. ;
  67. ;-----------------------------------------------------------------------;
  68. assumes ds,nothing
  69. assumes es,nothing
  70. cProc UnlinkObject,<PUBLIC,NEAR>
  71. cBegin nogen
  72. push di
  73. mov di,dx
  74. ; keep DX = next object
  75. mov dx,es:[di]
  76. ; see if the object is at the head
  77. push ds
  78. SetKernelDS
  79. mov cx,ds:[bx] ; start CX at head
  80. mov ax,es ; AX = object to delete
  81. cmp ax,cx
  82. jnz not_at_head
  83. mov ds:[bx],dx
  84. pop ds
  85. UnSetKernelDS
  86. jmp short unlink_done
  87. not_at_head:
  88. pop ds
  89. UnSetKernelDS
  90. ; run down the chain looking for the object
  91. unlink_loop:
  92. jcxz unlink_done
  93. mov es,cx
  94. mov cx,es:[di]
  95. cmp ax,cx
  96. jnz unlink_loop
  97. mov es:[di],dx
  98. unlink_done:
  99. pop di
  100. ret
  101. cEnd nogen
  102. sEnd CODE
  103. sBegin NRESCODE
  104. assumes CS,NRESCODE
  105. assumes DS,NOTHING
  106. assumes ES,NOTHING
  107. externNP MapDStoDATA
  108. externNP DecExeUsage
  109. externNP FlushPatchAppCache
  110. IFNDEF NO_APPLOADER
  111. externNP ExitAppl
  112. ENDIF ;!NO_APPLOADER
  113. ;-----------------------------------------------------------------------;
  114. ; KillLibraries ;
  115. ; ;
  116. ; Scans the list of EXEs looking for Libraries. For all Libraries ;
  117. ; it looks for a procedure called 'WEP'. If found, WEP is called with ;
  118. ; fSystemExit set. ;
  119. ; ;
  120. ; Arguments: ;
  121. ; None ;
  122. ; ;
  123. ; Returns: ;
  124. ; None ;
  125. ; ;
  126. ; Error Returns: ;
  127. ; none ;
  128. ; ;
  129. ; Registers Preserved: ;
  130. ; DI,SI,BP,DS ;
  131. ; ;
  132. ; Registers Destroyed: ;
  133. ; BX,CX,DX,ES ;
  134. ; ;
  135. ; Calls: ;
  136. ; GetProcAddress ;
  137. ; ;
  138. ; History: ;
  139. ; ;
  140. ;-----------------------------------------------------------------------;
  141. assumes ds,nothing
  142. assumes es,nothing
  143. cProc KillLibraries,<PUBLIC,FAR>,<DS>
  144. localW hExe
  145. cBegin
  146. SetKernelDSNRes
  147. mov cx, hExeHead
  148. kl_NextExe:
  149. UnSetKernelDS
  150. mov ds, cx ; This skips first module (kernel)
  151. mov cx, ds:[ne_pnextexe]
  152. jcxz kl_done
  153. push cx
  154. cCall CallWEP, <cx, 1> ; Call for any module (call is fast)
  155. pop cx
  156. jmp kl_NextExe
  157. kl_done:
  158. cEnd
  159. ;-----------------------------------------------------------------------;
  160. ; AddModule ;
  161. ; ;
  162. ; Adds a module to the end of the list of modules. ;
  163. ; ;
  164. ; Arguments: ;
  165. ; parmW hExe seg of module to add ;
  166. ; ;
  167. ; Returns: ;
  168. ; AX != 0 if successful ;
  169. ; ;
  170. ; Error Returns: ;
  171. ; AX == 0 if error detected ;
  172. ; ;
  173. ; Registers Preserved: ;
  174. ; DI,SI,DS ;
  175. ; ;
  176. ; Registers Destroyed: ;
  177. ; AX,BX,CX,DX,ES ;
  178. ; ;
  179. ; Calls: ;
  180. ; GlobalCompact ;
  181. ; CalcMaxNRSeg ;
  182. ; FarRedo_library_entries ;
  183. ; ;
  184. ; History: ;
  185. ; Wed 24-Jul-1991 -by- Don Corbitt [donc] ;
  186. ; Finish removal of Real mode code, dead code. Remove module from ;
  187. ; list if insufficient memory. Directly set DS on entry. ;
  188. ; ;
  189. ; Thu 23-Mar-1989 23:00:40 -by- David N. Weise [davidw] ;
  190. ; Made tasks and libraries be separate on the module chain. ;
  191. ; ;
  192. ; Thu Feb 25, 1988 08:00:00a -by- Tim Halvorsen [iris] ;
  193. ; Check new error return from Redo_library_entries, returned when ;
  194. ; we totally run out of space for another library's entry table ;
  195. ; in EMS (the entry table is for ALL tasks, not just this task). ;
  196. ; Fix comments above to reflect correct returns from this routine. ;
  197. ; ;
  198. ; Wed May 06, 1987 00:07:20a -by- David N. Weise [davidw] ;
  199. ; Added support for EMS and library entrys. ;
  200. ; ;
  201. ; Thu Dec 11, 1986 12:10:26p -by- David N. Weise [davidw] ;
  202. ; Added this nifty comment block, and made it set calculate and set ;
  203. ; ne_swaparea. ;
  204. ;-----------------------------------------------------------------------;
  205. assumes ds,nothing
  206. assumes es,nothing
  207. cProc AddModule,<PUBLIC,NEAR>,<ds>
  208. parmW hExe
  209. localW hLast ; last module in current list
  210. cBegin
  211. SetKernelDSNRes
  212. xor bx,bx
  213. mov cx,hExeHead
  214. am0: mov es,cx ; find end of linked list of exe's
  215. mov cx,es:[bx].ne_pnextexe
  216. or cx, cx
  217. jnz am0
  218. ; Here to add a module to the end of the chain. BX == 0.
  219. mov hLast, es ; so we can remove hExe on failure
  220. mov ax,hExe
  221. mov es:[bx].ne_pnextexe,ax
  222. mov es,ax
  223. mov es:[bx].ne_pnextexe,bx
  224. xor bx,bx
  225. am_done:
  226. mov ax,hExe
  227. am_exit:
  228. cEnd
  229. ;-----------------------------------------------------------------------;
  230. ; DelModule ;
  231. ; ;
  232. ; Deletes a module from the list of modules. ;
  233. ; ;
  234. ; Arguments: ;
  235. ; parmW hExe seg of module to delete ;
  236. ; ;
  237. ; Returns: ;
  238. ; AX = 0 ;
  239. ; ;
  240. ; Error Returns: ;
  241. ; ;
  242. ; Registers Preserved: ;
  243. ; DI,SI,DS ;
  244. ; ;
  245. ; Registers Destroyed: ;
  246. ; AX,BX,CX,DX,ES ;
  247. ; ;
  248. ; Calls: ;
  249. ; FarUnlinkObject ;
  250. ; GlobalFreeAll ;
  251. ; CalcMaxNRSeg ;
  252. ; EMSDelModule ;
  253. ; ;
  254. ; History: ;
  255. ; ;
  256. ; Wed May 06, 1987 00:07:20a -by- David N. Weise [davidw] ;
  257. ; Added support for EMS and library entrys. ;
  258. ; ;
  259. ; Tue May 05, 1987 10:36:29p -by- David N. Weise [davidw] ;
  260. ; Added this nifty comment block. ;
  261. ;-----------------------------------------------------------------------;
  262. assumes ds,nothing
  263. assumes es,nothing
  264. cProc DelModule,<PUBLIC,NEAR>,<ds,di>
  265. parmW pExe
  266. cBegin
  267. SetKernelDSNRes
  268. if SDEBUG
  269. mov es, pExe
  270. call FarDebugDelModule ; is ES preserved?
  271. endif
  272. cCall CallWEP,<pExe,0>
  273. mov es, pExe
  274. test es:[ne_flags],NENOTP
  275. jz dm_not_a_lib
  276. ; call user to clean up any stuff
  277. test es:[ne_flags],NEPROT ; OS/2 app? is this necessary???
  278. jnz no_user_yet
  279. cmp pSignalProc.sel,0
  280. jz no_user_yet
  281. xor ax,ax
  282. mov bx,80h
  283. mov es:[ne_usage],1
  284. push es
  285. cCall pSignalProc,<pExe,bx,ax,ax,ax>
  286. pop es
  287. mov es:[ne_usage],0
  288. no_user_yet:
  289. dm_not_a_lib:
  290. ; Following code moved here
  291. ; from FreeModule 1/18/89
  292. mov es,pExe
  293. mov bx,es:[ne_pautodata]
  294. or bx,bx
  295. jz fm00
  296. cCall FarMyFree,<es:[bx].ns_handle> ; Free DS separately to free thunks
  297. fm00:
  298. IFNDEF NO_APPLOADER
  299. mov es,pExe
  300. test es:[ne_flags],NEAPPLOADER
  301. jz normal_unload
  302. ;* * special unload for AppLoader
  303. cCall ExitAppl,<es>
  304. normal_unload:
  305. ENDIF ;!NO_APPLOADER ; END code from FreeModule
  306. cCall FlushPatchAppCache, <pExe> ; Flush out Module Patch cache
  307. cCall FlushCachedFileHandle,<pExe> ; Flush out of file handle cache
  308. cCall Far_genter ; so we don't interfere with lrusweep
  309. SetKernelDSNRes
  310. mov es,pExe
  311. mov dx,ne_pnextexe
  312. mov bx,dataOffset hExeHead
  313. call FarUnlinkObject
  314. mov es,pGlobalHeap
  315. xor di,di
  316. dec es:[di].gi_lrulock
  317. mov es,pExe ; Make sure no one mistakes this for
  318. mov es:[di].ne_magic,di ; an exe header anymore.
  319. cCall GlobalFreeAll,<pExe>
  320. xor ax,ax
  321. cEnd
  322. ;-----------------------------------------------------------------------;
  323. ; FreeModule ;
  324. ; ;
  325. ; Deletes the given module from the system. First it decs the usage ;
  326. ; count checking to see if this is the last instance, ( this may ;
  327. ; indirectly free other modules). If this is the last instance then ;
  328. ; it frees the automatic data segment to free any thunks associated ;
  329. ; with this module. Then the module is deleted. If this was not the ;
  330. ; last instance then the ns_handle for the automatic data seg may have ;
  331. ; to be updated. ;
  332. ; ;
  333. ; Arguments: ;
  334. ; parmW hInstance ;
  335. ; ;
  336. ; Returns: ;
  337. ; ;
  338. ; Error Returns: ;
  339. ; ;
  340. ; Registers Preserved: ;
  341. ; ;
  342. ; Registers Destroyed: ;
  343. ; ;
  344. ; Calls: ;
  345. ; ;
  346. ; History: ;
  347. ; ;
  348. ; Mon 03-Apr-1989 22:22:01 -by- David N. Weise [davidw] ;
  349. ; Removed the GlobalCompact at the end of this routine. ;
  350. ; ;
  351. ; Fri Jul 10, 1987 11:54:51p -by- David N. Weise [davidw] ;
  352. ; Added this nifty comment block. ;
  353. ;-----------------------------------------------------------------------;
  354. labelFP <PUBLIC, IFreeLibrary>
  355. assumes ds,nothing
  356. assumes es,nothing
  357. cProc IFreeModule,<PUBLIC,FAR>,<si,di>
  358. parmW hInstance
  359. cBegin
  360. cCall GetExePtr,<hInstance> ; Get exe header address
  361. or ax,ax
  362. jz fmexit1
  363. mov si,ax
  364. ifdef WOW
  365. ; we can't allow anybody except user.exe take the ref count for 16-bit net
  366. ; driver down to 0 (see pNetInfo in user16\net.c winnet.asm) bug #393078
  367. mov es,si
  368. cmp es:[ne_usage],1
  369. jnz fmNoProb ; if usage ref count isn't 1 -- no worries
  370. mov dx,word ptr [bp+4] ; selector of calling module
  371. ; See if it is user.exe freeing the net driver.
  372. cCall <far ptr IsOKToFreeThis>,<dx,ax>
  373. or ax,ax ; Will be 0 if & only if the module being freed is
  374. ; 16-bit net driver & the module freeing it is NOT
  375. ; user.exe. Otherwise ax will = si
  376. jz fmexit1 ; lie & say we freed 16-bit net driver & return ref count = 0
  377. fmNoProb:
  378. endif ; WOW
  379. cCall DecExeUsage,<si> ; Decrement usage count
  380. jnz fmfree ; If non-zero, then just free inst.
  381. ifdef WOW
  382. ; Word Perfect v5.2 needs DX to contain a number >= 0x17 inorder
  383. ; to print properly. Since on Win 3.1, the DX value came from
  384. ; this point, lets save it for them. (On Win 3,1, the printer
  385. ; driver was being free'd here, but not deleted, GDI or spooler
  386. ; still has it open).
  387. push dx
  388. endif
  389. cCall DelModule,<si> ; If zero, free entire module
  390. ifdef WOW
  391. pop dx
  392. endif
  393. fmexit1:
  394. jmps fmexit
  395. fmfree:
  396. mov es,si
  397. test byte ptr es:[ne_flags],NEINST
  398. jz fmexit ; All done if not a multiple inst
  399. mov bx,es:[ne_pautodata]
  400. push es:[bx].ns_handle
  401. cCall FarMyFree,<hInstance> ; Free instance
  402. pop dx
  403. cmp dx,hInstance ; Did we free current instance?
  404. jne fmexit ; No, then continue
  405. cCall MapDStoDATA
  406. ReSetKernelDS
  407. xor ax,ax
  408. xor bx,bx
  409. mov cx,headTDB ; Yes, search TDBs looking for
  410. UnSetKernelDS
  411. fm0: jcxz fm1 ; another instance handle
  412. mov es,cx
  413. cmp si,es:[bx].TDB_pModule
  414. mov cx,es:[bx].TDB_next
  415. jnz fm0
  416. mov ax,es:[bx].TDB_module
  417. cmp ax,hInstance ; Is this the instance we're quitting?
  418. jz fm0
  419. fm1: mov es,si
  420. mov bx,es:[bx].ne_pautodata
  421. mov es:[bx].ns_handle,ax ; Remember handle of data seg
  422. fmexit:
  423. cEnd
  424. sEnd NRESCODE
  425. ifdef WOW
  426. sBegin CODE
  427. assumes CS,CODE
  428. assumes DS,NOTHING
  429. assumes ES,NOTHING
  430. ;
  431. ; called by user.exe\net.c\LW_InitNetInfo()
  432. ;
  433. ; Arguments:
  434. ; parmW hInstNetDrv - hInstance of net driver library loaded by user.exe
  435. ;
  436. ; Returns:
  437. ; nothing
  438. ;
  439. cProc TellKrnlWhoNetDrvIs, <PUBLIC,FAR>,<si,di>
  440. parmW hInstNetDrv
  441. cBegin
  442. SetKernelDS
  443. cCall getexeptr,<hInstNetDrv>
  444. mov hWinnetDriver,ax ; save hMod of net driver
  445. UnSetKernelDS
  446. cEnd
  447. ;
  448. ; Should only be called if the ref (usage) count for module being freed is 1.
  449. ; (ie. about to go to zero)
  450. ;
  451. ; Arguments:
  452. ; parmW modsel - selector of code calling FreeModule
  453. ; parmW hModFree - hModule of module being freed
  454. ;
  455. ; Returns:
  456. ; 0 if & only if the module being freed is hWinnetDriver as set by user.exe
  457. ; AND the module calling FreeModule is NOT user.exe
  458. ; Otherwise: the hMod of the module being freed
  459. ;
  460. cProc IsOKToFreeThis, <PRIVATE,FAR>,<si,di>
  461. parmW modsel
  462. parmW hModFree
  463. cBegin
  464. SetKernelDS
  465. mov ax,hModFree
  466. cmp ax,hWinnetDriver ; is hMod of the net driver module?
  467. jnz IOKExit ; Exit if not -- no worries
  468. ; Danger! hMod being freed is the net driver
  469. cCall getexeptr,<modsel> ; get hMod of caller
  470. cmp ax,hUser ; See if caller is user.exe
  471. jz IOK2FT1 ; yep, that's OK
  472. xor ax,ax ; ret 0 so we don't free the net driver
  473. jmp IOKExit
  474. IOK2FT1:
  475. mov ax,hModFree
  476. IOKExit:
  477. UnSetKernelDS
  478. cEnd
  479. endif ; WOW
  480. sEnd CODE
  481. end