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.

611 lines
20 KiB

  1. .xlist
  2. include kernel.inc
  3. include pdb.inc
  4. include tdb.inc
  5. include newexe.inc
  6. ifdef WOW
  7. include vint.inc
  8. endif
  9. .list
  10. externFP KillLibraries
  11. ifndef WOW
  12. externFP WriteOutProfiles
  13. endif
  14. DataBegin
  15. externB PhantArray
  16. externB kernel_flags
  17. externB fBreak
  18. externB fInt21
  19. ifndef WOW
  20. externB fProfileMaybeStale
  21. endif
  22. externW curTDB
  23. externW headPDB
  24. externW topPDB
  25. externD lpInt21
  26. externD pSftLink
  27. externD lpWinSftLink
  28. externD pSysProc
  29. externD pMouseTermProc
  30. externD pKeyboardTermProc
  31. externD pSystemTermProc
  32. externW MyCSAlias
  33. externD myInt2F
  34. DataEnd
  35. sBegin CODE
  36. assumes CS,CODE
  37. assumes ds, nothing
  38. assumes es, nothing
  39. externD prevInt00Proc
  40. externD prevInt21Proc
  41. externD prevInt24Proc
  42. externD prevInt2FProc
  43. externD prevInt3FProc
  44. externD prevInt67Proc
  45. externD prevInt02Proc
  46. externD prevInt04Proc
  47. externD prevInt06Proc
  48. externD prevInt07Proc
  49. externD prevInt3EProc
  50. externD prevInt75Proc
  51. externD prevInt0CProc
  52. externD prevInt0DProc
  53. externD prevIntx6Proc
  54. externD prevInt0EProc
  55. ifdef WOW
  56. externD prevInt01proc
  57. externD prevInt03proc
  58. externD oldInt00proc
  59. endif
  60. externNP real_DOS
  61. externNP Enter_gmove_stack
  62. externNP TerminatePDB
  63. ;-----------------------------------------------------------------------;
  64. ; InternalEnableDOS
  65. ;
  66. ;
  67. ; Entry:
  68. ; none
  69. ; Returns:
  70. ;
  71. ; Registers Destroyed:
  72. ;
  73. ; History:
  74. ; Thu 21-Sep-1989 20:44:48 -by- David N. Weise [davidw]
  75. ; Added this nifty comment block.
  76. ;-----------------------------------------------------------------------;
  77. SetWinVec MACRO vec
  78. externFP Int&vec&Handler
  79. mov dx, codeoffset Int&vec&Handler
  80. mov ax, 25&vec&h
  81. pushf
  82. call prevInt21Proc
  83. endm
  84. assumes ds, nothing
  85. assumes es, nothing
  86. cProc InternalEnableDOS,<PUBLIC,FAR>
  87. cBegin nogen
  88. push si
  89. push ds
  90. SetKernelDS
  91. mov al,1
  92. xchg al,fInt21 ; set hook count to 1
  93. or al,al ; was it zero?
  94. jz @f
  95. jmp ena21 ; no, just leave
  96. @@:
  97. ; now link back nodes to SFT if kernel had done it before. InternalDisableDOS
  98. ; saves the link in the DWORD variable lpWinSftLink. If this variable is NULL
  99. ; then either this is the first time InternalEnableDOS is being called or
  100. ; else the SFT had not been grown.
  101. cmp lpWinSftLink.sel,0 ;was it allocated ?
  102. jz @f ;no.
  103. push ds ;save
  104. mov cx,lpWinSftLink.sel ;get the selector
  105. mov dx,lpWinSftLink.off ;get the offset
  106. lds bx,[pSftLink] ;place where we hooked new entry
  107. mov word ptr ds:[bx][0],dx ;restore offset
  108. mov word ptr ds:[bx][2],cx ;restore segment
  109. pop ds ;restore data segment
  110. @@:
  111. ; WARNING!! The ^C setting diddle MUST BE FIRST IN HERE......
  112. ; If you do some other INT 21 call before this you will have
  113. ; a "^C window", so don't do it....
  114. mov ax,3301h ; disable ^C checking
  115. mov dl,0
  116. call real_DOS
  117. mov bx,TopPDB
  118. mov ah,50h
  119. call real_DOS ; This way, or TDB_PDB gets set wrong
  120. ifndef WOW
  121. ends1: mov ah,6 ; clean out any pending keys
  122. mov dl,0FFh
  123. call real_DOS
  124. jnz ends1
  125. endif
  126. mov es,curTDB
  127. mov bx,es:[TDB_PDB]
  128. mov ah,50h
  129. int 21h
  130. push ds
  131. lds dx,myInt2F
  132. mov ax,252Fh
  133. int 21h
  134. smov ds,cs ; Pick up executable sel/seg
  135. UnSetKernelDS
  136. SetWinVec 24
  137. SetWinVec 00
  138. SetWinVec 02
  139. SetWinVec 04
  140. SetWinVec 06
  141. SetWinVec 07
  142. SetWinVec 3E
  143. SetWinVec 75
  144. pop ds
  145. ReSetKernelDS
  146. mov bx,2 ; 2 = Enable/Disable one drive logic
  147. xor ax,ax ; FALSE = Disable
  148. cCall [pSysProc],<bx,ax> ; NOTE: destroys ES if DOS < 3.20
  149. ; Set up the PhantArray by calling inquire system for each drive letter
  150. mov bx,dataOffset PhantArray + 25 ; Array index
  151. mov cx,26 ; Drive #
  152. SetPhant:
  153. dec cx
  154. push cx
  155. push bx
  156. mov dx,1 ; InquireSystem
  157. cCall [pSysProc],<dx,cx>
  158. pop bx
  159. pop cx
  160. mov byte ptr [bx],0 ; Assume not Phantom
  161. cmp ax,2
  162. jae NotPhant ; Assumption correct
  163. ; or dx,dx ; Drive just invalid?
  164. ; jz NotPhant ; Yes, assumption correct
  165. mov byte ptr [bx],dl ; Drive is phantom
  166. NotPhant:
  167. dec bx ; Next array element
  168. jcxz phant_done
  169. jmp SetPhant
  170. phant_done:
  171. lds dx,lpInt21
  172. UnSetKernelDS
  173. mov ax,2521h
  174. int 21h
  175. ena21:
  176. pop ds
  177. pop si
  178. ret
  179. cEnd nogen
  180. ;-----------------------------------------------------------------------;
  181. ; InternalDisableDOS ;
  182. ; ;
  183. ; ;
  184. ; Arguments: ;
  185. ; ;
  186. ; Returns: ;
  187. ; ;
  188. ; Error Returns: ;
  189. ; ;
  190. ; Registers Preserved: ;
  191. ; ;
  192. ; Registers Destroyed: ;
  193. ; ;
  194. ; Calls: ;
  195. ; ;
  196. ; History: ;
  197. ; ;
  198. ; Mon Oct 16, 1989 11:04:50 -by- Amit Chatterjee [amitc] ;
  199. ; InternalDisableDOS now takes away any nodes that kernel would have ;
  200. ; added to the SFT. InternalEnableDOS puts the nodes backs. Previously ;
  201. ; the delinking was done by DisableKernel, but no one linked it back! ;
  202. ; ;
  203. ; Sat May 09, 1987 02:00:52p -by- David N. Weise [davidw] ;
  204. ; Added this nifty comment block. ;
  205. ; ;
  206. ; Thu Apr 16, 1987 11:32:00p -by- Raymond E. Ozzie [-iris-] ;
  207. ; Changed InternalDisableDOS to use real dos for 52h function, since ;
  208. ; DosTrap3 doesn't have 52h defined and PassOnThrough will croak if the ;
  209. ; current TDB's signature is 0, as it is during exit after the last ;
  210. ; task has been deleted. ;
  211. ;-----------------------------------------------------------------------;
  212. ReSetDOSVec MACRO vec
  213. lds dx,PrevInt&vec&proc
  214. mov ax,25&vec&h
  215. int 21h
  216. endm
  217. assumes ds, nothing
  218. assumes es, nothing
  219. cProc InternalDisableDOS,<PUBLIC,FAR>
  220. cBegin
  221. SetKernelDS es
  222. xor ax,ax
  223. xchg al,fInt21 ; set hook count to zero
  224. or al,al ; was it non zero?
  225. jnz @F
  226. jmp dis21 ; no, just leave
  227. @@:
  228. mov bx,2 ; 2 = Enable/Disable one drive logic
  229. mov ax,1 ; TRUE = Enable
  230. push es
  231. cCall pSysProc,<bx,ax>
  232. pop es
  233. mov ax,3301h ; disable ^C checking
  234. mov dl,0
  235. pushf
  236. call [prevInt21Proc]
  237. mov ax,2521h
  238. lds dx,prevInt21Proc
  239. pushf
  240. call [prevInt21Proc]
  241. push es
  242. mov ax,352Fh
  243. int 21h
  244. mov ax,es
  245. pop es
  246. mov myInt2F.sel,ax
  247. mov myInt2F.off,bx
  248. ReSetDOSVec 00 ; as a favor in win2 we restored this
  249. ReSetDOSVec 24
  250. ReSetDOSVec 2F
  251. ReSetDOSVec 02
  252. ReSetDOSVec 04
  253. ReSetDOSVec 06
  254. ReSetDOSVec 07
  255. ReSetDOSVec 3E
  256. ReSetDOSVec 75
  257. mov dl,fBreak ; return state of ^C checking
  258. mov ax,3301h
  259. int 21h
  260. dis21:
  261. cEnd
  262. ;------------------------------------------------------------------
  263. ;
  264. ; Ancient WinOldAp hook.
  265. ;
  266. ;------------------------------------------------------------------
  267. public EnableDOS
  268. EnableDOS Label Byte
  269. if kdebug
  270. krDebugOut DEB_WARN, "Don't call EnableDOS"
  271. endif
  272. retf
  273. ;------------------------------------------------------------------
  274. ;
  275. ; Ancient WinOldAp hook.
  276. ;
  277. ;------------------------------------------------------------------
  278. public DisableDOS
  279. DisableDOS Label Byte
  280. if kdebug
  281. krDebugOut DEB_WARN, "Don't call DisableDOS"
  282. endif
  283. retf
  284. ;------------------------------------------------------------------
  285. ;
  286. ; Ancient WinOldAp hook.
  287. ;
  288. ;------------------------------------------------------------------
  289. public EnableKernel
  290. EnableKernel Label Byte
  291. if kdebug
  292. krDebugOut DEB_WARN, "Don't call EnableKernel"
  293. endif
  294. retf
  295. ;-----------------------------------------------------------------------;
  296. ; DisableKernel ;
  297. ; ;
  298. ; This call is provided as a Kernel service to applications that ;
  299. ; wish to totally unhook Windows in order to do something radical ;
  300. ; such as save the state of the world and restore it at a later ;
  301. ; time. This is similar in many ways to the way OLDAPP support ;
  302. ; works, with the addition that it also unhooks the kernel. ;
  303. ; ;
  304. ; Arguments: ;
  305. ; ;
  306. ; Returns: ;
  307. ; ;
  308. ; Error Returns: ;
  309. ; ;
  310. ; Registers Preserved: ;
  311. ; DI,SI,DS ;
  312. ; ;
  313. ; Registers Destroyed: ;
  314. ; ;
  315. ; Calls: ;
  316. ; ;
  317. ; History: ;
  318. ; ;
  319. ; Sat May 09, 1987 02:34:35p -by- David N. Weise [davidw] ;
  320. ; Merged changes in. Most of this came from ExitKernel. ;
  321. ; ;
  322. ; Tue Apr 28, 1987 11:12:00a -by- R.E.O. SpeedWagon [-????-] ;
  323. ; Changed to indirect thru PDB to get JFN under DOS 3.x. ;
  324. ; ;
  325. ; Mon Apr 20, 1987 11:34:00p -by- R.E.O. SpeedWagon [-????-] ;
  326. ; Set PDB to topPDB before final int 21/4C; we were sometimes exiting ;
  327. ; with a task's PDB, and thus we came back to ExitCall2 instead of ;
  328. ; going back to DOS! ;
  329. ;-----------------------------------------------------------------------;
  330. assumes ds, nothing
  331. assumes es, nothing
  332. cProc DisableKernel,<PUBLIC,FAR>,<si,di>
  333. cBegin
  334. SetKernelDS
  335. or Kernel_flags[2],KF2_WIN_EXIT ; prevent int 24h dialogs
  336. cmp prevInt21Proc.sel,0
  337. je nodisable
  338. call InternalDisableDOS
  339. nodisable:
  340. SetKernelDS
  341. mov ax,0203h ; Reset not present fault.
  342. mov bl,0Bh
  343. mov cx,prevInt3Fproc.sel
  344. mov dx,prevInt3Fproc.off
  345. int 31h
  346. mov ax,0203h ; Reset stack fault.
  347. mov bl,0Ch
  348. mov cx,prevInt0Cproc.sel
  349. mov dx,prevInt0Cproc.off
  350. int 31h
  351. mov ax,0203h ; Reset GP fault.
  352. mov bl,0Dh
  353. mov cx,prevInt0Dproc.sel
  354. mov dx,prevInt0Dproc.off
  355. int 31h
  356. mov ax,0203h ; Reset invalid op-code exception.
  357. mov bl,06h
  358. mov cx,prevIntx6proc.sel
  359. mov dx,prevIntx6proc.off
  360. int 31h
  361. mov ax,0203h ; Reset page fault.
  362. mov bl,0Eh
  363. mov cx,prevInt0Eproc.sel
  364. mov dx,prevInt0Eproc.off
  365. int 31h
  366. ifdef WOW
  367. mov ax,0203h ; Reset divide overflow traps
  368. mov bl,00h
  369. mov cx,oldInt00proc.sel
  370. mov dx,oldInt00proc.off
  371. int 31h
  372. mov ax,0203h ; Reset single step traps
  373. mov bl,01h
  374. mov cx,prevInt01proc.sel
  375. mov dx,prevInt01proc.off
  376. int 31h
  377. mov ax,0203h ; Reset breakpoint traps
  378. mov bl,03h
  379. mov cx,prevInt03proc.sel
  380. mov dx,prevInt03proc.off
  381. int 31h
  382. endif
  383. mov dx, [HeadPDB]
  384. SetKernelDS es
  385. UnSetKernelDS
  386. exk1:
  387. mov ds,dx
  388. cmp dx, [topPDB] ; Skip KERNEL, he is about to get
  389. je exk3 ; a 4C stuffed down his throat
  390. push ds
  391. call TerminatePDB
  392. pop ds
  393. exk3:
  394. mov dx,ds:[PDB_Chain] ; move to next PDB in chain
  395. or dx,dx
  396. jnz exk1
  397. mov bx,[topPDB] ; set to initial DOS task PDB
  398. mov ah,50h ; set PDB function
  399. int 21h
  400. and Kernel_flags[2],NOT KF2_WIN_EXIT ; prevent int 24h dialogs
  401. ;
  402. ; Close all files on Kernel's PSP, 'cause we're gonna shrink the SFT and
  403. ; quit ourselves afterwards.
  404. ;
  405. mov ds,[topPDB]
  406. mov cx,ds:[PDB_JFN_Length]
  407. exk4: mov bx,cx ; close all file handles
  408. dec bx
  409. cmp bx,5 ; console-related handle?
  410. jb exk5 ; yup, don't close it (AUX, etc.)
  411. mov ah,3eh
  412. int 21h
  413. exk5: loop exk4
  414. ; kernel could have added some nodes to the SFT. Delink them by removing
  415. ; the link from the last DOS link in the chain. We need to remember the
  416. ; current pointer there so that InternalEnableDOS can put it back.
  417. lds bx,[pSftLink] ;place where we hooked new entry
  418. assumes ds,nothing
  419. mov cx,ds ;this could have been unitialized too
  420. jcxz exk6 ;if unitialized, nothing to do
  421. mov dx,ds:[bx].off ;get the current offset
  422. mov cx,ds:[bx].sel ;get the current segment
  423. mov ds:[bx].off,-1 ;remove windows SFT link
  424. mov ds:[bx].sel, 0 ;remove windows SFT link
  425. mov lpWinSftLink.off,dx ;save the offset
  426. mov lpWinSftLink.sel,cx ;save the segment
  427. exk6:
  428. UnSetKernelDS es
  429. cEnd
  430. ;------------------------------------------------------------------
  431. ;
  432. ; ExitKernel -- Bye, bye.
  433. ;
  434. ;------------------------------------------------------------------
  435. ifndef WOW ; If we are closing down WOW then we don't want to go back to the DOS Prompt
  436. ; We want to kill the NTVDM WOW Process - so we don't need/want this code.
  437. assumes ds, nothing
  438. assumes es, nothing
  439. cProc ExitKernel,<PUBLIC,FAR>
  440. ; parmW exitcode
  441. cBegin nogen
  442. SetKernelDS
  443. or Kernel_flags[2],KF2_WIN_EXIT ; prevent int 24h dialogs
  444. call KillLibraries ; Tell DLLs that the system is exiting
  445. mov si,sp
  446. mov si,ss:[si+4] ; get exit code
  447. ; Call driver termination procs, just to make sure that they have removed
  448. ; their interrupt vectors.
  449. push si
  450. mov ax,word ptr [pMouseTermProc]
  451. or ax,word ptr [pMouseTermProc+2]
  452. jz trm0
  453. call [pMouseTermProc]
  454. CheckKernelDS
  455. trm0: mov ax,word ptr [pKeyboardTermProc]
  456. or ax,word ptr [pKeyboardTermProc+2]
  457. jz trm1
  458. call [pKeyboardTermProc]
  459. CheckKernelDS
  460. trm1: mov ax,word ptr [pSystemTermProc]
  461. or ax,word ptr [pSystemTermProc+2]
  462. jz trm2
  463. call [pSystemTermProc]
  464. CheckKernelDS
  465. trm2: pop si
  466. call WriteOutProfiles
  467. mov fProfileMaybeStale,1 ; Make sure we check the
  468. ; INI file next time around
  469. ;;; cCall CloseCachedFiles,<topPDB>
  470. ; Close open files and unhook kernel hooks
  471. ; get on a stack that's not in EMS land
  472. call Enter_gmove_stack
  473. cCall DisableKernel
  474. CheckKernelDS
  475. cmp si,EW_REBOOTSYSTEM ; Reboot windows?
  476. jnz exitToDos
  477. ifndef WOW
  478. mov ax,1600h
  479. int 2Fh
  480. test al,7Fh
  481. jz NotRunningEnhancedMode
  482. cmp al,1
  483. je exitToDos ;RunningWindows3862x
  484. cmp al,-1
  485. je exitToDos ;RunningWindows3862x
  486. xor di,di ; Zero return regs
  487. mov es,di
  488. mov bx,0009h ; Reboot device ID
  489. mov ax,1684h ; Get device API entry point
  490. int 2Fh
  491. mov ax,es
  492. or ax,di
  493. jz exitToDos ; Reboot vxd not loaded. Exit to dos
  494. ; Call the reboot function
  495. mov ax,0100h
  496. push es
  497. push di
  498. mov bx,sp
  499. call DWORD PTR ss:[bx]
  500. jmp short exitToDos ; Reboot didn't work just exit to dos
  501. NotRunningEnhancedMode:
  502. endif ; WOW
  503. mov ah, 0Dh ; Disk Reset so that Smartdrv etc buffers
  504. int 21h ; are written to disk
  505. mov ax, 0FE03h ; Flush Norton NCache
  506. mov si, "CF"
  507. mov di, "NU"
  508. stc ; Yes! Really set carry too!
  509. int 2Fh
  510. int 19h ; Reboot via int 19h
  511. exitToDos:
  512. mov ax,si
  513. mov ah,4Ch ; Leave Windows.
  514. int 21h
  515. cEnd nogen
  516. endif ; NOT WOW
  517. sEnd CODE
  518. end