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.

1402 lines
34 KiB

  1. .xlist
  2. include kernel.inc
  3. include tdb.inc
  4. include pdb.inc
  5. include kdos.inc
  6. include protect.inc
  7. ifdef WOW
  8. include vint.inc
  9. endif
  10. .list
  11. externFP LoadLibrary
  12. externFP LoadModule
  13. externFP GlobalFree,
  14. externFP GlobalFreeAll
  15. externFP GlobalCompact
  16. externFP FreeModule
  17. externFP GlobalDOSFree
  18. externFP FreeSelector
  19. externFP GetProcAddress ; WIN32S
  20. externFP ISetErrorMode ; WIN32S
  21. externFP ISetHandleCount
  22. externFP ExitKernelThunk
  23. externNP DPMIProc
  24. extrn BUNNY_351:FAR
  25. ifdef WOW
  26. DRIVE_REMOTE equ 4
  27. externW headTDB
  28. externFP lstrlen
  29. externFP WOWSetIdleHook
  30. externFP GetDriveType
  31. externFP WowShutdownTimer
  32. externFP WowTrimWorkingSet
  33. externB fShutdownTimerStarted
  34. externW cur_drive_owner
  35. endif
  36. externW pStackBot
  37. ;externW pStackMin
  38. externW pStackTop
  39. DataBegin
  40. externB Kernel_flags
  41. externB num_tasks
  42. externB Kernel_InDOS
  43. externB Kernel_InINT24
  44. externB WOAName
  45. externB grab_name
  46. externB fBooting
  47. externB graphics
  48. externB fExitOnLastApp
  49. externW cur_dos_PDB
  50. externW Win_PDB
  51. externW headPDB
  52. externW topPDB
  53. externW curTDB
  54. externW curDTA
  55. externW PHTcount
  56. externW gmove_stack
  57. externW MyCSSeg
  58. externW wExitingTDB
  59. externD lpSystemDir
  60. if KDEBUG
  61. externW allocTask
  62. endif
  63. externD lpint21
  64. externD pExitProc
  65. externD pDisplayCritSec
  66. externW PagingFlags
  67. externD lpReboot
  68. ifdef FE_SB
  69. ifndef KOREA
  70. externD pJpnSysProc
  71. endif
  72. endif
  73. DataEnd
  74. sBegin DATA
  75. externW gmove_stack
  76. ifndef WOW
  77. WIN32S = 1 ; enable code for Win32S support
  78. endif
  79. ifdef WIN32S
  80. ; Win32S support
  81. selExecPE DW 0
  82. offExecPE DW 0
  83. endif
  84. sEnd DATA
  85. assumes DS,NOTHING
  86. sBegin CODE
  87. assumes CS,CODE
  88. externD prevInt21Proc
  89. externNP Real_DOS
  90. externNP PathDrvDSDX
  91. externNP SetErrorDrvDSDX
  92. externNP SetCarryRet
  93. externNP ExitSchedule
  94. externNP UnlinkObject
  95. externNP final_call_for_DOS
  96. externNP cmp_sel_address
  97. externNP free_sel
  98. externNP SegToSelector
  99. if SDEBUG
  100. externNP DebugExitCall
  101. endif
  102. externNP DeleteTask
  103. ;-----------------------------------------------------------------------;
  104. ; Set_DTA (DOS Call 1Ah) ;
  105. ; ;
  106. ; Simply records on a task basis the DTA. ;
  107. ; ;
  108. ; Arguments: ;
  109. ; ;
  110. ; Returns: ;
  111. ; ;
  112. ; Error Returns: ;
  113. ; ;
  114. ; Registers Preserved: ;
  115. ; ;
  116. ; Registers Destroyed: ;
  117. ; ;
  118. ; Calls: ;
  119. ; ;
  120. ; History: ;
  121. ; ;
  122. ; Sat Jan 10, 1987 09:19:36p -by- David N. Weise [davidw] ;
  123. ; Wrote it. ;
  124. ;-----------------------------------------------------------------------;
  125. assumes ds, nothing
  126. assumes es, nothing
  127. cProc Set_DTA,<PUBLIC,NEAR>
  128. cBegin nogen
  129. push es
  130. SetKernelDS es
  131. mov curDTA.off,dx
  132. mov curDTA.sel,ds
  133. mov es,curTDB
  134. UnSetKernelDS es
  135. cmp es:[TDB_sig],TDB_SIGNATURE
  136. jne Set_DTA_noTDB
  137. mov es:[TDB_DTA].off,dx
  138. mov es:[TDB_DTA].sel,ds
  139. Set_DTA_noTDB:
  140. pop es
  141. jmp final_call_for_DOS
  142. cEnd nogen
  143. ;-----------------------------------------------------------------------;
  144. ; SaveRegs ;
  145. ; ;
  146. ; Does what it says. ;
  147. ; ;
  148. ; Arguments: ;
  149. ; ;
  150. ; Returns: ;
  151. ; ;
  152. ; Error Returns: ;
  153. ; ;
  154. ; Registers Preserved: ;
  155. ; ;
  156. ; Registers Destroyed: ;
  157. ; ;
  158. ; Calls: ;
  159. ; ;
  160. ; History: ;
  161. ; ;
  162. ; Fri Jan 16, 1987 09:57:49p -by- David N. Weise [davidw] ;
  163. ; Added this nifty comment block. ;
  164. ;-----------------------------------------------------------------------;
  165. assumes ds, nothing
  166. assumes es, nothing
  167. cProc SaveRegs,<PUBLIC,NEAR>
  168. cBegin nogen
  169. xchg dx, user_DX ; Return address in DX
  170. push es
  171. push bx
  172. push ax
  173. push cx
  174. push si
  175. push di
  176. and USER_FL,11111110b ; clc flag
  177. push dx
  178. mov dx, user_DX ; Rescue DX for what it's worth
  179. cld
  180. ret
  181. cEnd nogen
  182. ;-----------------------------------------------------------------------;
  183. ; RestoreRegs ;
  184. ; ;
  185. ; Does what it says and (used to cli). ;
  186. ; ;
  187. ; Arguments: ;
  188. ; ;
  189. ; Returns: ;
  190. ; ;
  191. ; Error Returns: ;
  192. ; ;
  193. ; Registers Preserved: ;
  194. ; ;
  195. ; Registers Destroyed: ;
  196. ; ;
  197. ; Calls: ;
  198. ; ;
  199. ; History: ;
  200. ; ;
  201. ; Fri Jan 16, 1987 10:00:41p -by- David N. Weise [davidw] ;
  202. ; Added this nifty comment block. ;
  203. ;-----------------------------------------------------------------------;
  204. assumes ds, nothing
  205. assumes es, nothing
  206. cProc RestoreRegs,<PUBLIC,NEAR>
  207. cBegin nogen
  208. pop di ; Return address
  209. xchg di, user_BP ; Insert for ret later, get saved BP
  210. mov bp, di
  211. dec bp
  212. pop di
  213. pop si
  214. pop cx
  215. pop ax
  216. pop bx
  217. pop es
  218. pop dx
  219. pop ds
  220. ret ; SP points to user_BP
  221. cEnd nogen
  222. ;-----------------------------------------------------------------------;
  223. ; ;
  224. ; Handle the Int21 func 67 call "Set Maximum Handle Count" ;
  225. ; ;
  226. ;-----------------------------------------------------------------------;
  227. cProc SetMaxHandleCount,<PUBLIC,NEAR>
  228. cBegin nogen
  229. pop ds
  230. pop bp ; clean up stack
  231. dec bp
  232. cmp bx, 255
  233. ja smhc_err1
  234. push bx
  235. push cx
  236. push dx
  237. cCall ISetHandleCount,<bx>
  238. pop dx
  239. pop cx
  240. pop bx
  241. cmp ax, bx ; did we get everything?
  242. jne smhc_err2
  243. clc
  244. jmp smhcexit
  245. smhc_err1:
  246. mov ax,4 ; too many open files
  247. stc ; set carry flag
  248. jmp smhcexit
  249. smhc_err2:
  250. mov ax,8 ; not enough memory
  251. stc ; set carry flag
  252. smhcexit:
  253. STIRET
  254. ret
  255. cEnd nogen
  256. ;-----------------------------------------------------------------------;
  257. ; Set_Vector (DOS Call 25h) ;
  258. ; Get_Vector (DOS Call 35h) ;
  259. ; ;
  260. ; ;
  261. ; Arguments: ;
  262. ; ;
  263. ; Returns: ;
  264. ; ;
  265. ; Error Returns: ;
  266. ; ;
  267. ; Registers Preserved: ;
  268. ; ;
  269. ; Registers Destroyed: ;
  270. ; ;
  271. ; Calls: ;
  272. ; ;
  273. ; History: ;
  274. ; ;
  275. ; Sat Jan 17, 1987 01:48:29a -by- David N. Weise [davidw] ;
  276. ; Added this nifty comment block. ;
  277. ;-----------------------------------------------------------------------;
  278. assumes ds, nothing
  279. assumes es, nothing
  280. cProc Set_Vector,<PUBLIC,NEAR>
  281. cBegin nogen
  282. push di
  283. push es
  284. call IsItIntercepted
  285. jnz notintercepted
  286. SetKernelDS es
  287. mov es, CurTDB ; We intercepted it, change
  288. UnSetKernelDS es ; vector in the TDB
  289. mov es:[di].off, dx
  290. mov es:[di].sel, ds
  291. jmps sv_done ; And just return
  292. notintercepted:
  293. SetKernelDS es
  294. cmp fBooting,1
  295. jz sv_no_restrictions
  296. cmp graphics,0 ; in the stand alone OS/2 box?
  297. jz @F
  298. ;ifdef JAPAN
  299. ifdef NOT_USE_BY_NT_JAPANESE
  300. push ax
  301. push bx ; 04/23/91 -yukini
  302. mov bx,0
  303. cCall [pJpnSysProc], <bx,ax> ; call System.JapanInquireSystem to
  304. ; get vector can be modified or not.
  305. test ax,ax
  306. pop bx
  307. pop ax
  308. jz sv_done ; jump if cannot be modified
  309. else
  310. cmp al,1Bh
  311. jz sv_done
  312. cmp al,1Ch
  313. jz sv_done
  314. endif
  315. @@: cmp al,21h ; trying to reset our traps?
  316. jz sv_done
  317. cmp al,24h ; trying to reset our traps?
  318. jz sv_done
  319. cmp al,2fh ; setting idle detect vector?
  320. jnz sv_no_restrictions ; no, proceed normally
  321. push ax
  322. push dx
  323. push ds
  324. cCall WOWSetIdleHook ; set the real hook back in Win32
  325. pop ds
  326. pop dx
  327. pop ax
  328. jmp bodacious_cowboys
  329. sv_no_restrictions:
  330. cmp al,21h
  331. jnz bodacious_cowboys
  332. mov lpint21.off,dx
  333. mov lpint21.sel,ds
  334. bodacious_cowboys:
  335. call real_DOS
  336. sv_done:
  337. pop es
  338. pop di
  339. pop ds
  340. pop bp ; clean up stack
  341. dec bp
  342. STIRET
  343. cEnd nogen
  344. assumes ds, nothing
  345. assumes es, nothing
  346. cProc Get_Vector,<PUBLIC,NEAR>
  347. cBegin nogen
  348. pop ds
  349. pop bp ; clean up stack
  350. dec bp
  351. push di
  352. call IsItIntercepted
  353. jnz notintercepted1
  354. push ds ; We intercepted it, get the
  355. SetKernelDS ; vector from the TDB
  356. mov ds, CurTDB
  357. UnSetKernelDS
  358. mov bx, [di]
  359. mov es, [di+2]
  360. pop ds
  361. pop di
  362. jmps gv_done
  363. notintercepted1:
  364. pop di
  365. call real_DOS
  366. gv_done:
  367. STIRET
  368. cEnd nogen
  369. cProc IsItIntercepted,<PUBLIC,NEAR>
  370. cBegin nogen
  371. mov di, TDB_INTVECS
  372. cmp al, 00h
  373. je yes_intercepted
  374. add di, 4
  375. cmp al, 02h
  376. je yes_intercepted
  377. add di, 4
  378. cmp al, 04h
  379. je yes_intercepted
  380. add di, 4
  381. cmp al, 06h
  382. je yes_intercepted
  383. add di, 4
  384. cmp al, 07h
  385. je yes_intercepted
  386. add di, 4
  387. cmp al, 3Eh
  388. je yes_intercepted
  389. add di, 4
  390. cmp al, 75h
  391. yes_intercepted:
  392. ret
  393. cEnd nogen
  394. ;-----------------------------------------------------------------------;
  395. ; ExecCall (DOS Call 4Bh) ;
  396. ; ;
  397. ; ;
  398. ; Arguments: ;
  399. ; ;
  400. ; Returns: ;
  401. ; ;
  402. ; Error Returns: ;
  403. ; ;
  404. ; Registers Preserved: ;
  405. ; ;
  406. ; Registers Destroyed: ;
  407. ; ;
  408. ; Calls: ;
  409. ; ;
  410. ; History: ;
  411. ; ;
  412. ; Mon 07-Aug-1989 23:39:59 -by- David N. Weise [davidw] ;
  413. ; Added support for long command lines to WinOldApp. ;
  414. ; ;
  415. ; Sat Jan 17, 1987 01:39:44a -by- David N. Weise [davidw] ;
  416. ; Added this nifty comment block. ;
  417. ;-----------------------------------------------------------------------;
  418. assumes ds, nothing
  419. assumes es, nothing
  420. cProc ExecCall,<PUBLIC,NEAR>
  421. cBegin nogen
  422. call PathDrvDSDX ; Check drive
  423. jnc EC1 ; Drive OK
  424. call SetErrorDrvDSDX ; Set up errors
  425. jmp SetCarryRet ; Error
  426. EC1: call SaveRegs
  427. call far ptr FarExecCall
  428. call RestoreRegs
  429. STIRET
  430. cEnd nogen
  431. ;-----------------------------------------------------------------------;
  432. ; TerminatePDB ;
  433. ; ;
  434. ; It calls DOS to terminate the current task. ;
  435. ; ;
  436. ; Arguments: ;
  437. ; DI = exit code ;
  438. ; Returns: ;
  439. ; nothing ;
  440. ; Error Returns: ;
  441. ; nothing ;
  442. ; Registers Preserved: ;
  443. ; none ;
  444. ; Registers Destroyed: ;
  445. ; ;
  446. ; Calls: ;
  447. ; ;
  448. ; History: ;
  449. ; ;
  450. ;-----------------------------------------------------------------------;
  451. assumes ds, nothing
  452. assumes es, nothing
  453. cProc TerminatePDB,<PUBLIC,NEAR>
  454. cBegin nogen
  455. SetKernelDS ES
  456. mov bx, ds ; DS is PDB being terminated
  457. cmp cur_dos_PDB, bx ; Ensure DOS/anyone on the
  458. je short @F ; int 21h chain has correct PDB
  459. mov ah, 50h
  460. pushf
  461. call prevInt21Proc
  462. @@:
  463. mov ax, ds:[PDB_Parent_PID] ; Parent PDB
  464. mov Win_PDB, ax ; These will be changed by DOS
  465. mov cur_dos_PDB, ax
  466. or Kernel_Flags[2],KF2_WIN_EXIT
  467. mov ax,di ; AL = exit code
  468. mov ah, 0 ; Alternative exit for PMODE which returns
  469. call real_DOS ; let DOS clean up
  470. UnSetKernelDS es
  471. errn$ DosExitReturn
  472. cEnd nogen
  473. ;
  474. ; The DOS terminate call above will return to
  475. ; the following label, DosExitReturn. This is
  476. ; a separate procedure in order to be declared FAR.
  477. ;
  478. assumes ds, nothing
  479. assumes es, nothing
  480. cProc DosExitReturn,<PUBLIC,FAR>
  481. cBegin nogen
  482. SetKernelDS ES
  483. mov Kernel_InDOS,0
  484. mov Kernel_InINT24,0
  485. and Kernel_Flags[2],NOT KF2_WIN_EXIT
  486. retn
  487. cEnd nogen
  488. ;-----------------------------------------------------------------------;
  489. ; ExitCall (DOS Call 4Ch) ;
  490. ; ;
  491. ; It terminates the current task. ;
  492. ; ;
  493. ; Arguments: ;
  494. ; AL = exit code ;
  495. ; Returns: ;
  496. ; nothing ;
  497. ; Error Returns: ;
  498. ; nothing ;
  499. ; Registers Preserved: ;
  500. ; none ;
  501. ; Registers Destroyed: ;
  502. ; none ;
  503. ; Calls: ;
  504. ; TerminatePDB ;
  505. ; GlobalFreeAll ;
  506. ; UnlinkObject ;
  507. ; DeleteTask ;
  508. ; GlobalFree ;
  509. ; FreeModule ;
  510. ; History: ;
  511. ; ;
  512. ; Mon 07-Aug-1989 23:39:59 -by- David N. Weise [davidw] ;
  513. ; Removed WinOldApp support. ;
  514. ; ;
  515. ; Sun Apr 26, 1987 03:20:05p -by- David N. Weise [davidw] ;
  516. ; Made it switch stacks to the temp_stack because of EMS. ;
  517. ; ;
  518. ; Mon Sep 29, 1986 04:06:08p -by- Charles Whitmer [chuckwh] ;
  519. ; Made it kill all threads in the current process. ;
  520. ; ;
  521. ; Mon Sep 29, 1986 03:27:12p -by- Charles Whitmer [chuckwh] ;
  522. ; Made it call UnlinkObject rather than do the work inline. ;
  523. ; ;
  524. ; Mon Sep 29, 1986 09:22:08a -by- Charles Whitmer [chuckwh] ;
  525. ; Documented it. ;
  526. ;-----------------------------------------------------------------------;
  527. assumes ds, nothing
  528. assumes es, nothing
  529. cProc ExitCall,<PUBLIC,NEAR>
  530. cBegin nogen
  531. ifdef WOW
  532. ; Set to a Known DIR so that if an app was running over the network
  533. ; the user can disconnect once the app terminates.
  534. ; This also allows a subdirectory to be removed after a Win16 app
  535. ; had that dir as the current dir, but was terminated.
  536. SetKernelDS
  537. push ax
  538. push si
  539. push dx
  540. push ds
  541. lds si,lpSystemDir ; ds:si points to system directory
  542. mov dl,[si] ; put drive letter into AL
  543. add dl,-65 ; subtract 'A' to get drive number
  544. mov ah,0Eh
  545. call real_DOS ; select disk
  546. add si,2 ; let SI point to the first '\' past d:
  547. mov al,[si + 1] ; save first character after '\'
  548. push ax
  549. mov byte ptr [si + 1],0 ; null-terminate string after root dir
  550. mov dx,si
  551. mov ah,3Bh
  552. call real_DOS ; select directory
  553. pop ax
  554. mov [si + 1],al ; restore string to its original state
  555. ;
  556. ; During task exit/abort ntdos $abort notifies the debugger of the
  557. ; "module unload" of the EXE using the full path to the EXE that
  558. ; follows the environment block. We don't want ntdos to make the
  559. ; module unload callout because we do it ourself during our
  560. ; DelModule of the EXE module. So we have a protocol, we zero
  561. ; the environment selector in our PDB, DPMI translates this to
  562. ; segment zero properly, and ntdos skips the callout if the environment
  563. ; segment is zero.
  564. ;
  565. pop ds
  566. ReSetKernelDS
  567. mov es,[curTDB] ; DS = current TDB
  568. mov es, es:[TDB_PDB]
  569. xor ax,ax
  570. mov word ptr es:[PDB_environ], ax
  571. pop dx
  572. pop si
  573. pop ax
  574. endif
  575. if SDEBUG
  576. ;** Save the TDB of the currently exiting task. We check for this
  577. ;** in DebugWrite so that we don't get recursive
  578. ;** debug strings at task exit time. This is a gross hack
  579. ;** for QCWin and their numerous param validation errors.
  580. mov bx,curTDB ;Get current task handle
  581. mov wExitingTDB,bx ;Save as exiting TDB
  582. cCall DebugExitCall ;Passes exit code in AL
  583. endif ; SDEBUG
  584. .386
  585. smov fs, 0
  586. smov gs, 0
  587. .286p
  588. xchg di,ax ; DI = exit code
  589. cmp graphics,1 ; is there a display driver around?
  590. jnz @F
  591. mov ax,1
  592. ifndef WOW ; WOW doesn't have a display dirver to call
  593. cCall pDisplayCritSec,<ax> ; tell display driver to shut up
  594. endif
  595. or Kernel_Flags[2],KF2_WIN386CRAZINESS
  596. @@: mov ds,curTDB ; DS = current TDB
  597. assumes ds,nothing
  598. ; We may have gotten here due to stack checking. Let's make sure
  599. ; that we are on a stack we can deal with.
  600. test ds:[TDB_flags],TDBF_OS2APP
  601. jz @F
  602. mov ax,sp
  603. mov ss:[pStackBot],ax
  604. @@: xor ax,ax
  605. mov ss:[pStackTop],ax
  606. ; remove the PDB from the chain
  607. mov es,ds:[TDB_PDB]
  608. mov dx,PDB_Chain
  609. mov bx,dataOffset HeadPDB
  610. call UnlinkObject
  611. xor si,si ; source of zero
  612. ; Dec total # of tasks, if last task in system, then quit Windows completely.
  613. smov es,ds
  614. assumes es,nothing
  615. SetKernelDS
  616. ifdef WOW
  617. cmp fExitOnLastApp,0 ; Quit WOW when the last app dies ?
  618. jz @f
  619. cmp num_tasks,2 ; Last Task (ingnoring WOWEXEC) ?
  620. jz last_task
  621. @@:
  622. endif
  623. dec num_tasks
  624. jnz not_the_last_task
  625. last_task:
  626. ;** Unhook local reboot VxD stuff
  627. cmp WORD PTR lpReboot[2], 0 ;Reboot handler installed?
  628. je @F ;No
  629. push es
  630. mov ax, 0201h ;Reboot VxD #201: Set callback addr
  631. xor di, di ;Zero CS means no SYS VM local
  632. mov es, di
  633. call [lpReboot] ; reboot handler
  634. pop es
  635. @@:
  636. call BUNNY_351
  637. ifndef WOW ; For WOW ex just want to get out of here - no need to call USER16 or GDI16
  638. cCall pExitProc,<si,si> ; this does not return
  639. endif
  640. cCall ExitKernelThunk,<si>
  641. assumes es, nothing
  642. not_the_last_task:
  643. ; Signal( hTask, SG_EXIT, ExitCode, 0, Queue ) if we have a user signal proc
  644. push es
  645. cmp es:[si].TDB_USignalProc.sel,si
  646. jz no_signal_proc
  647. mov bx,SG_EXIT
  648. cCall es:[si].TDB_USignalProc,<es,bx,di,es:[si].TDB_Module,es:[si].TDB_Queue>
  649. no_signal_proc:
  650. pop es
  651. mov bl,6
  652. DPMICALL 0202h ; DPMI get exception handler vector
  653. push cx
  654. push dx
  655. mov cx,cs
  656. lea dx,exit_call_guts
  657. mov bl,6
  658. DPMICALL 0203h ; DPMI set exception handler vector
  659. pop dx
  660. pop cx
  661. ;
  662. ; Generate an invalid opcode exception fault. This causes DPMI to call
  663. ; our "exception handler."
  664. ;
  665. db 0fh,0ffh
  666. exit_call_guts:
  667. FSTI ; we're called with ints disabled
  668. mov bp,sp ; BP -> RETIP RETCS EC IP CS FL SP SS
  669. ;
  670. ; Restore the previous invalid exception handler vector.
  671. ;
  672. mov bl,6
  673. DPMICALL 0203h
  674. ;
  675. ; Point the return stack at Kernel's temporary stack.
  676. ;
  677. mov ax,dataOffset gmove_stack
  678. mov [bp+12],ax
  679. mov ax,seg gmove_stack
  680. mov [bp+14],ax
  681. ;
  682. ; Replace the return address on the DPMI fault handler routine with
  683. ; our exit code.
  684. ;
  685. lea ax,ExitSchedule
  686. mov [bp+6],ax
  687. mov [bp+8],cs
  688. push es
  689. cCall GlobalFreeAll,<si> ; free up all task data
  690. pop es
  691. ; Remove from queue.
  692. push es
  693. cCall DeleteTask,<es>
  694. pop es
  695. mov ds,es:[TDB_PDB] ; DS = current PDB
  696. UnsetKernelDS ; DS is PDB to terminate
  697. call TerminatePDB ; Call DOS to close down files etc.
  698. ReSetKernelDS ES ; TerminatePDB returned with ES set
  699. xor bp,bp ; set up valid frame
  700. mov ds,curTDB
  701. ; If this task has a PHT, decrement the PHT count and clear the pointer
  702. ; and zap the PHT pointer so we don't look at it anymore.
  703. ; NOTE - BP contains a convenient zero.
  704. mov ax,ds:[TDB_PHT].sel
  705. or ax,ds:[TDB_PHT].off
  706. jz no_PHT
  707. mov ds:[TDB_PHT].sel,bp
  708. mov ds:[TDB_PHT].off,bp
  709. dec PHTcount ; dec # tasks with PHT's
  710. no_PHT:
  711. UnSetKernelDS es
  712. cCall FreeModule,<ds:[TDB_Module]> ; Free the module for this task
  713. xor ax,ax
  714. mov ds:[TDB_sig],ax ; Mark TDB as invalid
  715. ;** Nuke any JFN that is outside the PDB. We can tell that the
  716. ;** JFN points outside the PDB if the offset is zero. PDB
  717. ;** JFN's never have a zero offset and outside ones always do.
  718. push ds
  719. mov ds, ds:[TDB_PDB]
  720. cmp WORD PTR ds:[PDB_JFN_Pointer][0], 0 ;JFN pointer into PDB?
  721. jne EC_NoFreeJFN ;Yes, don't free anything
  722. push WORD PTR ds:[PDB_JFN_Table] ;Get our selector
  723. call GlobalDOSFree
  724. EC_NoFreeJFN:
  725. SetKernelDS
  726. cmp num_tasks,1 ; Last task? (except wowexec)
  727. jne @f ; branch if not last task
  728. if 0
  729. ; This code is unneeded because if we're a separate VDM, we exit above when
  730. ; the last task exited.
  731. cmp fExitOnLastApp, 0 ; Shared WOW?
  732. jne @F ; branch if not shared WOW
  733. endif
  734. cCall WowShutdownTimer, <1> ; start shutdown timer
  735. mov fShutdownTimerStarted, 1
  736. cCall GlobalCompact,<-1, -1> ; free up as many pages as possible
  737. cCall WowTrimWorkingSet ; trim working set to minimum
  738. @@:
  739. mov bx, topPDB
  740. mov Win_PDB, bx
  741. mov cur_dos_PDB, bx
  742. mov ah, 50h
  743. pushf
  744. call prevInt21Proc ; Set PDB to KERNEL's
  745. pop ds
  746. UnSetKernelDS
  747. xchg bx, ds:[TDB_PDB]
  748. cCall free_sel,<bx> ; Free the PDB selector
  749. call far ptr FreeTDB ; Tosses PDB's memory
  750. SetKernelDS
  751. ifndef WOW
  752. mov curTDB,0 ; We can use this, setting curTDB = 0
  753. else
  754. ;; We do this a little later - see tasking.asm exitschedule
  755. endif
  756. or PagingFlags, 8 ; to save a few bytes.
  757. ;** Task has been nuked. Clear the DebugWrite task exiting flag
  758. mov wExitingTDB,0
  759. ; fix current drive owner
  760. mov ax, cur_drive_owner
  761. cmp ax, curTDB
  762. jnz @f
  763. ; so it is the owner of a current drive -- nuke it
  764. mov cur_drive_owner, 0
  765. @@:
  766. if 0 ; We could call this on every task exit -- need to see if
  767. ; it slows down Winstone 94, if it's needed after we use MEM_RESET
  768. ; If you enable this call, disable the similar call just above.
  769. cCall WowTrimWorkingSet ; trim working set to minimum
  770. endif
  771. retf ; To ExitSchedule
  772. cEnd nogen
  773. assumes ds, nothing
  774. assumes es, nothing
  775. cProc FreeTDB, <PUBLIC,FAR>
  776. cBegin nogen
  777. cCall FreeSelector,<ds:[TDB_MPI_Sel]>
  778. mov ax,ds
  779. if KDEBUG
  780. ;
  781. ; If we're freeing the alloc break task, zero out the global.
  782. ;
  783. SetKernelDS
  784. cmp ax,allocTask
  785. jnz @F
  786. mov allocTask,0
  787. @@:
  788. UnSetKernelDS
  789. endif
  790. smov ds,0
  791. cCall GlobalDOSFree,<ax>
  792. ret
  793. cEnd nogen
  794. ;-----------------------------------------------------------------------;
  795. ; set_PDB (DOS Call 50h) ;
  796. ; ;
  797. ; This is an undocumented DOS call to set the current PDB. ;
  798. ; DOS does not check for ^C's on this call, in fact it never turns ;
  799. ; on the interrupts. ;
  800. ; ;
  801. ; Arguments: ;
  802. ; ;
  803. ; Returns: ;
  804. ; ;
  805. ; Error Returns: ;
  806. ; ;
  807. ; Registers Preserved: ;
  808. ; ;
  809. ; Registers Destroyed: ;
  810. ; ;
  811. ; Calls: ;
  812. ; ;
  813. ; History: ;
  814. ; ;
  815. ; Fri Jan 23, 1987 07:07:14p -by- David N. Weise [davidw] ;
  816. ; Wrote it. ;
  817. ;-----------------------------------------------------------------------;
  818. assumes ds, nothing
  819. assumes es, nothing
  820. cProc set_PDB,<PUBLIC,NEAR>
  821. cBegin nogen
  822. SetKernelDS
  823. mov cur_dos_PDB,bx
  824. mov Win_PDB,bx
  825. mov ds,curTDB
  826. assumes ds,nothing
  827. mov ds:[TDB_PDB],bx
  828. call real_DOS
  829. pop ds
  830. pop bp ; clean up stack
  831. dec bp
  832. STIRET
  833. cEnd nogen
  834. ;-----------------------------------------------------------------------;
  835. ; get_PDB ;
  836. ; ;
  837. ; This is an undocumented DOS call to set the current PDB. ;
  838. ; DOS does not check for ^C's on this call, in fact it never turns ;
  839. ; on the interrupts. ;
  840. ; Trapping this is superfluous is real mode but necessary in protect ;
  841. ; mode since the DOS extender may not be doing the segment ;
  842. ; translation properly. ;
  843. ; ;
  844. ; Entry: ;
  845. ; ;
  846. ; Returns: ;
  847. ; ;
  848. ; Registers Destroyed: ;
  849. ; ;
  850. ; History: ;
  851. ; Tue 13-Jun-1989 18:22:16 -by- David N. Weise [davidw] ;
  852. ; Wrote it. ;
  853. ;-----------------------------------------------------------------------;
  854. assumes ds,nothing
  855. assumes es,nothing
  856. cProc get_PDB,<PUBLIC,NEAR>
  857. cBegin nogen
  858. SetKernelDS
  859. call real_DOS
  860. mov bx,cur_dos_PDB
  861. pop ds
  862. pop bp ; clean up stack
  863. dec bp
  864. STIRET
  865. cEnd nogen
  866. sEnd code
  867. sBegin NRESCODE
  868. assumes cs, NRESCODE
  869. assumes ds, nothing
  870. assumes es, nothing
  871. externNP MapDStoDATA
  872. ;-----------------------------------------------------------------------;
  873. ; BuildPDB ;
  874. ; ;
  875. ; ;
  876. ; Arguments: ;
  877. ; ;
  878. ; Returns: ;
  879. ; ;
  880. ; Error Returns: ;
  881. ; ;
  882. ; Registers Preserved: ;
  883. ; ;
  884. ; Registers Destroyed: ;
  885. ; ;
  886. ; Calls: ;
  887. ; ;
  888. ; History: ;
  889. ; ;
  890. ; Thu 04-Jan-1990 20:15:27 -by- David N. Weise [davidw] ;
  891. ; Made it avoid closing cached files if the PDB being copied is not ;
  892. ; the topPDB. This is for supporting inheriting a parents files. ;
  893. ; ;
  894. ; Mon 11-Sep-1989 19:13:52 -by- David N. Weise [davidw] ;
  895. ; Removed returning validity in AX, and removed copying of FCBs. ;
  896. ; ;
  897. ; Mon 07-Aug-1989 23:39:59 -by- David N. Weise [davidw] ;
  898. ; Added support for long command lines to WinOldApp. ;
  899. ; ;
  900. ; Sun Jan 18, 1987 00:27:52a -by- David N. Weise [davidw] ;
  901. ; Added this nifty comment block. ;
  902. ;-----------------------------------------------------------------------;
  903. assumes ds, nothing
  904. assumes es, nothing
  905. cProc BuildPDB,<PUBLIC,FAR>,<si,di>
  906. ParmW oldPDB
  907. ParmW newPDB
  908. ParmD ParmBlock
  909. ParmW newSize
  910. ParmW fWOA
  911. cBegin
  912. call MapDStoDATA
  913. ReSetKernelDS
  914. push Win_PDB ; Save current PDB
  915. mov bx,oldPDB ; set current PDB for copy
  916. mov Win_PDB, bx
  917. mov dx,newPDB
  918. mov si,newSize
  919. mov ah,55h ; duplicate PDB
  920. int 21h
  921. mov bx, oldPDB
  922. mov dx, newPDB
  923. mov cur_dos_PDB, dx ; DOS call 55h sets the PDB to this
  924. nothing_to_close:
  925. pop Win_PDB ; restore former PDB
  926. xor di,di
  927. mov cx, MyCSSeg
  928. mov ds,dx
  929. UnSetKernelDS
  930. mov es,dx
  931. add si,dx
  932. mov ax,oldPDB
  933. mov [di].PDB_Parent_PID,ax ; parent = OldPDB
  934. mov [di].PDB_Block_Len,si
  935. mov [di].PDB_Exit.off,codeOffset DosExitReturn
  936. mov [di].PDB_Exit.sel, cx
  937. ; No private global heap yet.
  938. mov [di].PDB_GlobalHeap.lo,di
  939. mov [di].PDB_GlobalHeap.hi,di
  940. ; Set up proper command line stuff.
  941. lds si,ParmBlock
  942. lds si,ds:[si].lpcmdline ; command line
  943. mov di,PDB_DEF_DTA
  944. mov cx,di
  945. cmp fWOA,0
  946. jz @F ; Winoldap can have long command line
  947. mov cx,ds:[si] ; get byte count
  948. cld
  949. movsb ; copy count byte
  950. inc cx
  951. inc si
  952. @@: rep movsb ; Store command line.
  953. cEnd
  954. cProc FarExecCall,<PUBLIC,FAR>
  955. cBegin nogen
  956. ; Check if file extension is .COM, .BAT, .PIF, if so it needs emulation...
  957. cld
  958. les di,User_DSDX
  959. ifdef WOW
  960. ;
  961. ; Wow LoadModule handles all forms of exec including
  962. ; pe images, com, bat, pif files etc.
  963. ;
  964. lds si,User_ESBX
  965. regptr esdx,es,dx
  966. regptr dssi,ds,si
  967. cCall LoadModule,<esdx,dssi>
  968. cmp ax, LME_MAXERR ; check for error...
  969. jae ex8
  970. jmp short ex7 ; no, return error
  971. else
  972. mov cx,-1
  973. xor al,al
  974. repnz scasb ; scan to end of string
  975. neg cx
  976. dec cx ; cx has length (including null)
  977. mov ax,es:[di-5]
  978. or ah,20h
  979. mov bx,es:[di-3] ; complete check for .COM
  980. or bx,2020h ; convert to lower case
  981. cmp ax,'c.' ; check for .COM file extension
  982. jnz ex1b ; no match...attempt load module
  983. cmp bx,'mo'
  984. jz ex4 ; yes! go immediatly to GO
  985. ex1b: cmp ax,'b.' ; check for .BAT extension...
  986. jnz ex1c
  987. cmp bx,'ta'
  988. jz ex4
  989. ex1c: cmp ax,'p.' ; check for .PIF extension...
  990. jnz ex2
  991. cmp bx,'fi'
  992. jz ex4
  993. ex2: lds si,User_ESBX
  994. regptr esdx,es,dx
  995. regptr dssi,ds,si
  996. push cx ; save length of string
  997. cCall LoadModule,<esdx,dssi>
  998. pop cx
  999. cmp ax, LME_MAXERR ; check for error...
  1000. jb ex3
  1001. jmp ex8
  1002. ex3: cmp ax, LME_INVEXE ; wrong format?
  1003. jz ex4
  1004. cmp ax, LME_EXETYPE ; quick basic app
  1005. jz ex4
  1006. cmp ax, LME_PE ; Win32 PE format
  1007. jz @F
  1008. jmp ex7 ; no, return error
  1009. @@:
  1010. ifdef WIN32S
  1011. push cx
  1012. ; Win32S support - (AviN) 11-19-91
  1013. lds si,User_DSDX
  1014. push ds
  1015. push si
  1016. lds si,User_ESBX
  1017. push ds:[si+4] ; CmdLine sel
  1018. push ds:[si+2] ; offset
  1019. les bx, ds:[si+6] ; FCB1
  1020. push es:[bx+2] ; nCmdShow
  1021. call FAR PTR ExecPE
  1022. pop cx
  1023. cmp ax, 32
  1024. jbe @F
  1025. jmp ex8
  1026. @@:
  1027. cmp ax, 11 ; NOT PE
  1028. je @F
  1029. jmp ex7
  1030. @@:
  1031. ; end of Win32S support
  1032. endif
  1033. ex4:
  1034. ; Run an old application
  1035. ;
  1036. ; If we are running in the OS/2 3x box, we do not support running old
  1037. ; apps. If someone trys this, put up a nasty message and return with
  1038. ; an error. (Thu 12-Nov-1987 : bobgu)
  1039. mov dx,cx ; save length of file name
  1040. sub sp,256 ; make room for command line
  1041. smov es,ss
  1042. mov di,sp
  1043. lds si,User_ESBX
  1044. lds si,ds:[si].lpcmdline
  1045. xor ax,ax
  1046. xor cx,cx
  1047. mov cl,ds:[si]
  1048. inc cx
  1049. movsb
  1050. stosb
  1051. rep movsb
  1052. mov cx,dx
  1053. lds si,User_DSDX
  1054. rep movsb
  1055. mov byte ptr es:[di][-1],10 ; terminate with line feed
  1056. mov di,sp
  1057. add es:[di],dx
  1058. mov bx,es
  1059. push ds
  1060. call MapDStoDATA
  1061. smov es, ds
  1062. pop ds
  1063. ReSetKernelDS es
  1064. test Kernel_flags[2],KF2_DOSX ; DOSX winoldap doesn't need special
  1065. jnz @F ; special handling
  1066. mov ax,dataOffset grab_name
  1067. push bx
  1068. push dx
  1069. push es
  1070. cCall LoadLibrary,<es,ax>
  1071. pop es
  1072. pop dx
  1073. pop bx
  1074. cmp ax,32
  1075. jae @F
  1076. add sp, 256 ; undo damage to stack
  1077. jmps ex7
  1078. @@:
  1079. or Kernel_flags[1],KF1_WINOLDAP
  1080. lds si,User_ESBX
  1081. mov ds:[si].lpcmdline.off,di
  1082. mov ds:[si].lpcmdline.sel,bx
  1083. mov dx,dataOffset WOAName
  1084. regptr esdx,es,dx
  1085. regptr dssi,ds,si
  1086. cCall LoadModule,<esdx,dssi>
  1087. assumes es, nothing
  1088. add sp,256
  1089. cmp ax,32 ; check for error...
  1090. jae ex8
  1091. cmp ax,2 ; file not found?
  1092. jnz ex7 ; no, return error
  1093. mov al,23 ; flag WINOLDAP error
  1094. ;; ndef wow
  1095. endif
  1096. ex7: or User_FL,1 ; set carry flag
  1097. or ax,ax ; out of memory?
  1098. jnz ex8
  1099. mov ax,8h ; yes, return proper error code
  1100. ex8: mov User_AX,ax ; return AX value
  1101. ret
  1102. cEnd nogen
  1103. ifdef WIN32S
  1104. SZW32SYS db "W32SYS.DLL", 0
  1105. ExecPEOrd equ 3
  1106. ;-----------------------------------------------------------------------;
  1107. ; ExecPE
  1108. ; Get ExecPE address in W32SYS.DLL, and call it
  1109. ; 11-13-91 AviN created
  1110. ;-----------------------------------------------------------------------;
  1111. cProc ExecPE,<PUBLIC,FAR>
  1112. cBegin nogen
  1113. push ds
  1114. mov ax, SEG selExecPE
  1115. mov ds, ax
  1116. assumes DS, DATA
  1117. mov dx, selExecPE ; check for a valid address
  1118. or dx, dx
  1119. jnz ep_x
  1120. mov ax, offExecPE
  1121. or ax, ax
  1122. jnz ep_err ; already failed, don't try again
  1123. cCall ISetErrorMode, <8000h>
  1124. push ax
  1125. lea ax, SZW32SYS
  1126. cCall LoadLibrary,<cs, ax>
  1127. pop dx
  1128. push ax
  1129. cCall ISetErrorMode,<dx> ; restore original error mode
  1130. pop ax
  1131. cmp ax, 32
  1132. jbe ep_err
  1133. push ax
  1134. push 0
  1135. push ExecPEOrd
  1136. cCall GetProcAddress
  1137. or dx,dx
  1138. jz ep_err
  1139. mov selExecPE, dx
  1140. mov offExecPE, ax
  1141. ep_x:
  1142. pop ax ; saved DS
  1143. push selExecPE ; jmp to ExecPE
  1144. push offExecPE
  1145. mov ds, ax
  1146. retf
  1147. ep_err:
  1148. ; if w32sys support no available return
  1149. mov ax, 11 ; invalid module format
  1150. mov offExecPE, ax ; and record for next time
  1151. pop ds
  1152. retf 10 ; pop ExecPE parameters
  1153. assumes DS,NOTHING
  1154. cEnd nogen
  1155. endif
  1156. sEnd NRESCODE
  1157. sBegin MISCCODE
  1158. assumes cs, misccode
  1159. assumes ds, nothing
  1160. assumes es, nothing
  1161. externNP MISCMapDStoDATA
  1162. ;-----------------------------------------------------------------------;
  1163. ; ;
  1164. ; Get the Current PDB without doing a DOS call. ;
  1165. ; ;
  1166. ;-----------------------------------------------------------------------;
  1167. cProc GetCurrentPDB,<PUBLIC,FAR>
  1168. cBegin nogen
  1169. push ds
  1170. call MISCMapDStoDATA
  1171. ReSetKernelDS
  1172. mov dx,TopPDB
  1173. mov ds,curTDB
  1174. UnSetKernelDS
  1175. mov ax,ds:[TDB_PDB]
  1176. pop ds
  1177. ret
  1178. cEnd nogen
  1179. sEnd MISCCODE
  1180. end
  1181.