Source code of Windows XP (NT5)
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.

1371 lines
40 KiB

  1. page ,132
  2. title CONTEXT - task event procedures.
  3. .xlist
  4. include gpfix.inc
  5. include kernel.inc
  6. include tdb.inc
  7. include pdb.inc
  8. include eems.inc
  9. ifdef WOW
  10. include vint.inc
  11. include wowcmpat.inc
  12. endif
  13. .list
  14. externFP CloseCachedFiles
  15. externFP Int21Handler
  16. externFP Far_real_dos
  17. externFP GlobalAlloc
  18. externFP GlobalFree
  19. externFP GlobalLock
  20. externFP GlobalUnlock
  21. externFP GetAppCompatFlags
  22. ifdef FE_SB
  23. externFP FarMyIsDBCSLeadByte
  24. endif
  25. ifdef WOW
  26. externFP IGetModuleFileName
  27. endif
  28. DataBegin
  29. externB Kernel_Flags
  30. externW cpLowHeap
  31. externW selLowHeap
  32. externW selHighHeap
  33. externW selWoaPdb
  34. externB InScheduler
  35. externB DOS_version
  36. externB DOS_revision
  37. externB lpszFileName
  38. ;externW pGlobalHeap
  39. externW winVer
  40. externW topPDB
  41. externW cur_dos_PDB
  42. externW Win_PDB
  43. externW curTDB
  44. externW WinFlags
  45. externW FileEntrySize
  46. externW shell_file_TDB
  47. externD shell_file_proc
  48. if ROM
  49. externD pYieldProc
  50. endif
  51. externD ptrace_DLL_entry
  52. externD ptrace_app_entry
  53. externD lpfnToolHelpProc
  54. externD dressed_for_success
  55. IF PMODE32
  56. externB fTaskSwitchCalled
  57. externW LockTDB
  58. ENDIF
  59. DataEnd
  60. sBegin CODE
  61. assumes ds,NOTHING
  62. assumes cs,CODE
  63. ife ROM
  64. externD pYieldProc
  65. endif
  66. ifndef WOW
  67. externNP Reschedule
  68. externNP DeleteTask
  69. externNP InsertTask
  70. endif ; WOW
  71. ifdef WOW
  72. externFP MyGetAppWOWCompatFlagsEx
  73. endif
  74. ifndef WOW
  75. ;-----------------------------------------------------------------------;
  76. ; WaitEvent ;
  77. ; ;
  78. ; If an event is waiting on taskID, suspend the current task until ;
  79. ; an event is ready. Returns if an event was ready and no reschedule ;
  80. ; occured. Otherwise returns true to indicate a reschedule has occured.;
  81. ; ;
  82. ; Arguments: ;
  83. ; ;
  84. ; Returns: ;
  85. ; ;
  86. ; Error Returns: ;
  87. ; ;
  88. ; Registers Preserved: ;
  89. ; ;
  90. ; Registers Destroyed: ;
  91. ; ;
  92. ; Calls: ;
  93. ; ;
  94. ; History: ;
  95. ; ;
  96. ; Sat Mar 28, 1987 05:13:50p -by- David N. Weise [davidw] ;
  97. ; Wrote it. ;
  98. ;-----------------------------------------------------------------------;
  99. assumes ds, nothing
  100. assumes es, nothing
  101. cProc WaitEvent,<PUBLIC,FAR>,<bx,ds>
  102. parmW taskID
  103. cBegin
  104. IF PMODE32
  105. push ds
  106. SetKernelDS
  107. cmp LockTDB, 0 ;Do we have a locked task
  108. jne @F ;Yes, we want to be able to reboot
  109. mov fTaskSwitchCalled, 1 ;Tell Reboot VxD that we're scheduling
  110. @@:
  111. pop ds
  112. ENDIF
  113. mov ax,taskID
  114. call GetTaskHandle0
  115. mov ds,ax
  116. xor ax,ax
  117. wait_test:
  118. pushf
  119. FCLI
  120. dec ds:[TDB_nEvents]
  121. jge wait_exit
  122. mov ds:[TDB_nEvents],0
  123. ; go uncritical
  124. pop bx
  125. test bh,02 ; the interrupt flag
  126. jz leave_int_off
  127. FSTI
  128. leave_int_off:
  129. smov es, 0
  130. if PMODE32
  131. .386
  132. smov fs, 0
  133. smov gs, 0
  134. .286
  135. endif
  136. push cs
  137. call Reschedule
  138. mov al,-1
  139. jmp wait_test
  140. wait_exit:
  141. pop bx
  142. test bh,02 ; the interrupt flag
  143. jz leave_ints_off
  144. FSTI
  145. leave_ints_off:
  146. cEnd
  147. ;-----------------------------------------------------------------------;
  148. ; DirectedYield ;
  149. ; ;
  150. ; This does a yield and attempts to yield to the specific yo-yo. ;
  151. ; In reschedule is checked the event count of the target task, if ;
  152. ; non-zero then that task is started. Else the task queue is searched ;
  153. ; as normal. ;
  154. ; ;
  155. ; Arguments: ;
  156. ; parmW yield_to ;
  157. ; ;
  158. ; Returns: ;
  159. ; nothing ;
  160. ; ;
  161. ; Error Returns: ;
  162. ; ;
  163. ; Registers Preserved: ;
  164. ; All ;
  165. ; ;
  166. ; Registers Destroyed: ;
  167. ; ;
  168. ; Calls: ;
  169. ; ;
  170. ; History: ;
  171. ; ;
  172. ; Sat Mar 28, 1987 06:14:17p -by- David N. Weise [davidw] ;
  173. ; Fixed it for aaronr. ;
  174. ; ;
  175. ; Fri Feb 06, 1987 00:00:11a -by- David N. Weise [davidw] ;
  176. ; Wrote it for aaronr. ;
  177. ;-----------------------------------------------------------------------;
  178. assumes ds, nothing
  179. assumes es, nothing
  180. cProc DirectedYield,<PUBLIC,FAR>
  181. ; parmW yield_to
  182. cBegin nogen
  183. push bp
  184. mov bp,sp
  185. push ax
  186. push ds
  187. ; get rid of the argument on the stack
  188. mov ax,[bp][2] ; move IP up
  189. xchg [bp][4],ax
  190. xchg [bp][6],ax ; move CS up
  191. SetKernelDS
  192. if ROM ;----------------------------------------------------------------
  193. push pYieldProc.sel ; safe assumption we're going to
  194. push pYieldProc.off ; USER's yield proc
  195. mov ds,curTDB
  196. assumes ds,nothing
  197. mov ds:[TDB_Yield_to],ax
  198. ifdef DISABLE
  199. cmp ds:[TDB_QUEUE],0
  200. jnz dy_away
  201. endif
  202. dy_OldYield:
  203. mov word ptr [bp][-8],codeOffset OldYield ; assumption incorrect
  204. mov [bp][-6],cs
  205. dy_away:
  206. mov ds,[bp][-4] ; 'pop' ds
  207. mov ax,[bp][-2] ; .. ax ..
  208. mov bp,[bp] ; .. bp ..
  209. retf 8 ; 'jmp' to yield proc & clear stack
  210. else ;ROM ---------------------------------------------------------
  211. mov ds,curTDB
  212. assumes ds,nothing
  213. mov ds:[TDB_Yield_to],ax
  214. ;
  215. ; Since this function is used by SendMessage() to switch directly
  216. ; to and from the destination app, we don't want to call USER to recieve
  217. ; any messages, since that causes unnecessary and inefficient recursion.
  218. ;
  219. ifdef DISABLE
  220. cmp ds:[TDB_QUEUE],0
  221. pop ds
  222. pop ax
  223. pop bp
  224. jz dy_OldYield
  225. add sp,2 ; waste the space
  226. jmp cs:pYieldProc ; Jump through CS VARIABLE
  227. else
  228. pop ds
  229. pop ax
  230. pop bp
  231. endif
  232. dy_OldYield:
  233. add sp,2 ; waste the space
  234. jmps OldYield ; If no task queue, do OLD Yield.
  235. endif ;ROM ---------------------------------------------------------
  236. cEnd nogen
  237. ;-----------------------------------------------------------------------;
  238. ; Yield ;
  239. ; ;
  240. ; Does what it says. ;
  241. ; ;
  242. ; Arguments: ;
  243. ; ;
  244. ; Returns: ;
  245. ; ;
  246. ; Error Returns: ;
  247. ; ;
  248. ; Registers Preserved: ;
  249. ; ;
  250. ; Registers Destroyed: ;
  251. ; ;
  252. ; Calls: ;
  253. ; ;
  254. ; History: ;
  255. ; ;
  256. ; Sat May 09, 1987 12:21:13p -by- David N. Weise [davidw] ;
  257. ; Added this nifty comment block. ;
  258. ; ;
  259. ; Wed Apr 15, 1987 12:13:00p -by- Raymond E. Ozzie [-iris-] ;
  260. ; Changed Yield to work for tasks that don't ever do an INITAPP, and ;
  261. ; thus don't have a task queue. These are presumably tasks that do ;
  262. ; some sort of background computational activity that don't have a ;
  263. ; window associated with them. ;
  264. ; ;
  265. ;-----------------------------------------------------------------------;
  266. assumes ds, nothing
  267. assumes es, nothing
  268. cProc Yield,<PUBLIC,FAR>
  269. cBegin nogen
  270. if ROM ;----------------------------------------------------------------
  271. push bp
  272. mov bp,sp
  273. push ds
  274. SetKernelDS
  275. push pYieldProc.sel ; safe assumption we're going to
  276. push pYieldProc.off ; USER's yield proc
  277. mov ds,curTDB
  278. assumes ds, nothing
  279. mov ds:[TDB_Yield_to],0
  280. cmp ds:[TDB_QUEUE],0
  281. jz y_oldyield
  282. y_away:
  283. mov ds,[bp][-2] ; 'pop' ds
  284. mov bp,[bp] ; .. and bp ..
  285. retf 4 ; off to yield proc & clean stack
  286. y_oldyield:
  287. mov word ptr [bp][-6],codeOffset OldYield ; bad assumption
  288. mov [bp][-4],cs
  289. jmps y_away
  290. else ;ROM ---------------------------------------------------------
  291. push ds
  292. SetKernelDS
  293. mov ds,curTDB
  294. assumes ds, nothing
  295. mov ds:[TDB_Yield_to],0
  296. cmp ds:[TDB_QUEUE],0
  297. pop ds
  298. jz OldYield ; If no task queue, do OLD Yield.
  299. jmp cs:pYieldProc ; Pass to USER Jump through CS VARIABLE
  300. endif ;ROM ---------------------------------------------------------
  301. cEnd nogen
  302. assumes ds, nothing
  303. assumes es, nothing
  304. cProc OldYield,<PUBLIC,FAR>,<ds>
  305. cBegin
  306. SetKernelDS
  307. xor ax,ax
  308. cmp InScheduler,al ; can't yield if inside scheduler
  309. jnz yld3 ; just return false
  310. cmp CurTDB,0 ; did it kill itself?
  311. jz @F
  312. mov ds,CurTDB
  313. assumes ds, nothing
  314. inc ds:[TDB_nEvents]
  315. @@: smov es, ax
  316. if PMODE32
  317. .386
  318. smov fs, ax
  319. smov gs, ax
  320. .286
  321. endif
  322. push cs
  323. call Reschedule
  324. dec ds:[TDB_nEvents]
  325. mov ax,-1 ; TRUE
  326. yld3:
  327. cEnd
  328. endif ; !WOW
  329. assumes ds, nothing
  330. assumes es, nothing
  331. GetTaskHandle2:
  332. mov bx,sp
  333. mov ax,ss:[bx+8]
  334. mov bx,ss:[bx+6]
  335. jmps GetTaskHandle0
  336. GetTaskHandle1:
  337. mov bx,sp
  338. mov ax,ss:[bx+6]
  339. GetTaskHandle0:
  340. or ax,ax
  341. jnz gt1
  342. SetKernelDS es
  343. mov ax,curTDB
  344. gt1: mov es,ax
  345. assumes es, nothing
  346. ; cmp es:[TDB_sig],TDB_SIGNATURE
  347. ; jne gt2
  348. ret
  349. ;gt2: kerror ERR_TASKID,<GetTaskHandle: Invalid task handle>
  350. ; ret
  351. ifndef WOW
  352. ;;
  353. ;; PostEvent( taskID ) - increment the event counter for a task. Return
  354. ;; false if invalid task handle passed. Otherwise return true, after
  355. ;; setting the scheduler flag that says a new task might be ready to
  356. ;; run.
  357. ;;
  358. assumes ds, nothing
  359. assumes es, nothing
  360. cProc PostEvent,<PUBLIC,FAR>
  361. ; parmW taskID
  362. cBegin nogen
  363. call GetTaskHandle1
  364. inc es:[TDB_nEvents] ; indicate one more event
  365. ret 2
  366. cEnd nogen
  367. endif ; !WOW
  368. ;-------------------------------------------------------
  369. ;
  370. ; Get the Task pull model event queue handle
  371. ;
  372. assumes ds, nothing
  373. assumes es, nothing
  374. cProc GetTaskQueue,<PUBLIC,FAR>
  375. ; parmW taskID
  376. cBegin nogen
  377. call GetTaskHandle1
  378. mov ax,es:[TDB_queue]
  379. ret 2
  380. cEnd nogen
  381. ;-------------------------------------------------------
  382. ;
  383. ; Get the Task pull model event queue handle into DS
  384. ;
  385. assumes ds, nothing
  386. assumes es, nothing
  387. cProc GetTaskQueueDS,<PUBLIC,FAR>
  388. cBegin nogen
  389. SetKernelDS
  390. mov ds,curTDB
  391. assumes ds, nothing
  392. mov ds,ds:[TDB_queue]
  393. ret
  394. cEnd nogen
  395. ;-------------------------------------------------------
  396. ;
  397. ; Get the Task pull model event queue handle into ES
  398. ;
  399. assumes ds, nothing
  400. assumes es, nothing
  401. cProc GetTaskQueueES,<PUBLIC,FAR>
  402. cBegin nogen
  403. SetKernelDS es
  404. mov es,curTDB
  405. assumes es,nothing
  406. mov es,es:[TDB_queue]
  407. ret
  408. cEnd nogen
  409. assumes ds, nothing
  410. assumes es, nothing
  411. cProc SetTaskSignalProc,<PUBLIC,FAR>
  412. ; parmW taskID
  413. ; parmD signalProc
  414. cBegin nogen
  415. mov bx,sp
  416. mov ax,ss:[bx+8]
  417. call GetTaskHandle0
  418. mov ax,ss:[bx+4]
  419. mov dx,ss:[bx+6]
  420. xchg ax,es:[TDB_USignalProc].off
  421. xchg dx,es:[TDB_USignalProc].sel
  422. ret 6
  423. cEnd nogen
  424. ;--------------------------------------------------------
  425. ;
  426. ; Set (and Get) the Task pull model event queue handle
  427. ;
  428. assumes ds, nothing
  429. assumes es, nothing
  430. cProc SetTaskQueue,<PUBLIC,FAR>
  431. ; parmW taskID
  432. ; parmW hQueue
  433. cBegin nogen
  434. call GetTaskHandle2
  435. mov ax,bx
  436. xchg ax,es:[TDB_queue]
  437. ret 4
  438. cEnd nogen
  439. ifndef WOW
  440. ;--------------------------------------------------------
  441. ;
  442. ; Set (and Get) Task Priority
  443. ;
  444. assumes ds, nothing
  445. assumes es, nothing
  446. cProc SetPriority,<PUBLIC,FAR>
  447. ; parmW taskID
  448. ; parmW newPri
  449. cBegin nogen
  450. call GetTaskHandle2
  451. add bl,es:[TDB_priority]
  452. cmp bl,-32
  453. jge stp1
  454. mov bl,-32
  455. stp1: cmp bl,15
  456. jle stp2
  457. mov bl,15
  458. stp2: push bx
  459. mov bh,1 ; put at back of priority queue
  460. cmp es:[TDB_priority],bl ; SetPriority( 0 )?
  461. jne stp3 ; No, continue
  462. mov ax,es ; Yes, is this the current task?
  463. push ds
  464. SetKernelDS
  465. cmp ax,curTDB
  466. pop ds
  467. assumes ds, nothing
  468. je stp4 ; Yes, exit without doing anything
  469. mov bh,0 ; No, put at front of priority queue
  470. stp3:
  471. add bl,bh
  472. mov es:[TDB_priority],bl
  473. push bx
  474. push es
  475. cCall DeleteTask,<es>
  476. cCall InsertTask,<ax>
  477. pop es
  478. pop ax
  479. sub es:[TDB_priority],ah
  480. stp4:
  481. pop ax
  482. cbw
  483. ret 4
  484. cEnd nogen
  485. endif ; WOW - the above code is not required in WOW
  486. ;;
  487. ;; Aaron Reynolds 7/20/87 - Added so folks like USER can ask if this is Winoldap
  488. ;;
  489. ;; IsWinoldapTask( taskID ) - Is this a Winoldap Task?
  490. ;; false if not a Winoldap task, else true
  491. ;; This works by returning the low bit in the Global Heap pointer of the task's
  492. ;; PDB. Nobody in KERNEL sets this bit (it is always initialized to 0). It is
  493. ;; up to WINOLDAP to mark its tasks by setting the low bit itself.
  494. ;;
  495. assumes ds, nothing
  496. assumes es, nothing
  497. cProc IsWinoldapTask,<PUBLIC,FAR>
  498. ; parmW taskID
  499. cBegin nogen
  500. ifdef WOW
  501. xor ax, ax ; always return false
  502. else
  503. call GetTaskHandle1
  504. mov es,es:[TDB_PDB] ; Get PDB pointer from task handle
  505. mov ax,word ptr es:[PDB_GlobalHeap] ; Get low word of Global heap ptr
  506. and ax,0000000000000001B ; Mask to low bit
  507. endif
  508. ret 2
  509. cEnd nogen
  510. ;----------------------------------------------------------------------------;
  511. ; IsTask
  512. ;
  513. ; OLE 1.0 DLLs check whether the task they are talking to is a genuine one
  514. ; or not. This they do by calling IsTask(). So, I look for -1 as the hTask,
  515. ; which was returned from GetWindowTask() as BOGUSGDT for the 32 bit tasks
  516. ; and for the 16 bit tasks a correct value was returned.
  517. ;
  518. ; So, if we find hTask on this function as -1, we should return TRUE to
  519. ; keep OLE DLLs happy.
  520. ;
  521. ; ChandanC Feb 9th 1993.
  522. ;
  523. ;----------------------------------------------------------------------------;
  524. ; Validate a task handle
  525. ; davidds
  526. cProc IsTask,<PUBLIC, FAR>
  527. ; parmW taskID
  528. cBegin nogen
  529. mov bx,sp
  530. mov ax,ss:[bx+4]
  531. or ax,ax
  532. jz IT_err
  533. ifdef WOW
  534. test al, 0100b ; Check for task aliases (see WOLE2.C) or BOGUSGDT
  535. jnz task_check
  536. task_ok:
  537. mov ax, 1
  538. jmp SHORT IT_exit
  539. task_check:
  540. endif
  541. .286p
  542. lsl bx,ax
  543. jnz IT_err
  544. cmp bx,size TDB
  545. jl IT_err
  546. mov es,ax
  547. cmp es:[TDB_sig],TDB_SIGNATURE
  548. jne IT_err
  549. jmp short IT_exit
  550. IT_err:
  551. xor ax,ax
  552. IT_exit:
  553. ret 2
  554. cEnd nogen
  555. ;-----------------------------------------------------------------------;
  556. ; CVW_Hack
  557. ;
  558. ; This is a little hack for the next rev of CVW. This is a cheap
  559. ; way to break into an app just before it really starts up. We
  560. ; call off to the ptrace DLL and then jump off to the real entry
  561. ; point.
  562. ;
  563. ; Entry:
  564. ; none
  565. ;
  566. ; Returns:
  567. ; none
  568. ;
  569. ; Registers Preserved:
  570. ; all
  571. ;
  572. ; Registers Destroyed:
  573. ;
  574. ; History:
  575. ;
  576. ; Mon 27-Feb-1989 20:22:06 -by- David N. Weise [davidw]
  577. ; Wrote it.
  578. ;-----------------------------------------------------------------------;
  579. assumes ds,nothing
  580. assumes es,nothing
  581. cProc CVW_Hack,<PUBLIC,FAR>
  582. cBegin nogen
  583. sub sp, 4
  584. ;** See if we should call the TOOLHELP hook first
  585. push ds
  586. SetKernelDS
  587. test Kernel_Flags[2],KF2_TOOLHELP ;TOOLHELP.DLL?
  588. jz st_NoToolHelp ;Nope
  589. push ax ;Save regs we use
  590. push cx
  591. push bx
  592. push Win_PDB ; Preserve Win_TDB across ToolHelp call
  593. cmp curTDB,0
  594. jz @F
  595. push es
  596. mov es,curTDB
  597. push es:[TDB_PDB]
  598. pop ds:Win_PDB
  599. pop es
  600. @@:
  601. mov ax,SDM_LOADTASK
  602. mov bx,WORD PTR ptrace_app_entry[0] ;Task start address in CX:DX
  603. mov cx,WORD PTR ptrace_app_entry[2]
  604. call lpfnToolHelpProc ;Do it
  605. pop Win_PDB
  606. pop bx
  607. pop cx
  608. pop ax
  609. ;** Since we got here, we know that at least one of the two
  610. ;** (WINDEBUG, TOOLHELP) or both are here. Since we know
  611. ;** TOOLHELP is here, we still need to check for WINDEBUG.
  612. ;** If it's here, act as if TOOLHELP were not
  613. cmp WORD PTR ptrace_DLL_entry[2],0 ;WINDEBUG present?
  614. jnz st_NoToolHelp ;Yes, give it a turn
  615. ;** Since we have no one else to call, simply start the task
  616. ;** Stack: AX[-2] BP[0] DS[2] RETFIP[4] RETFCS[6]
  617. push bp
  618. mov bp,sp
  619. push ax
  620. mov ax,WORD PTR ptrace_app_entry[0] ;Get the IP value
  621. mov [bp + 4],ax ;Put in place of RETFIP
  622. mov ax,WORD PTR ptrace_app_entry[2] ;Get the CS value
  623. mov [bp + 6],ax ;Put in place of RETFCS
  624. pop ax ;Clean up and start up the task
  625. pop bp
  626. pop ds
  627. retf
  628. st_NoToolHelp:
  629. pop ds
  630. add sp, 4
  631. ;** Now call CVW's hook (WINDEBUG.DLL)
  632. push ax
  633. push bx
  634. push cx
  635. push ds
  636. mov bx,ds
  637. SetKernelDS
  638. push ptrace_app_entry.sel ; push real app entry point
  639. push ptrace_app_entry.off
  640. push cs ; push return to return
  641. push codeOffset cvwh_clever
  642. push ptrace_DLL_entry.sel ; push call into ptrace
  643. push ptrace_DLL_entry.off
  644. push ptrace_app_entry.sel
  645. push ptrace_app_entry.off
  646. mov ds,bx
  647. UnsetKernelDS
  648. mov ax,59h
  649. pop bx
  650. pop cx
  651. retf ; 'call' ptrace
  652. cvwh_clever:
  653. mov bx,sp
  654. mov ax,ss:[bx].10
  655. mov cx,ss:[bx].06
  656. mov bx,ss:[bx].08
  657. retf 8 ; return to real entry point
  658. cEnd nogen
  659. ;-----------------------------------------------------------------------;
  660. ; FileCDR_notify
  661. ;
  662. ;
  663. ; Entry:
  664. ;
  665. ; Returns:
  666. ;
  667. ; Registers Destroyed:
  668. ;
  669. ; History:
  670. ; Thu 08-Jun-1989 17:04:49 -by- David N. Weise [davidw]
  671. ; Wrote it!
  672. ;-----------------------------------------------------------------------;
  673. assumes ds,nothing
  674. assumes es,nothing
  675. cProc FileCDR_notify,<PUBLIC,FAR>,<ax,bx,cx,dx,si,di,ds,es>
  676. localW hHunkOMemory
  677. localD lpDestFile
  678. cBegin
  679. mov hHunkOMemory, 0 ; Handle/flag for RENAME
  680. mov SEG_lpDestFile, es
  681. mov OFF_lpDestFile, di
  682. mov si,dx ; DS:SI points to [source] file
  683. SetKernelDS es
  684. cmp word ptr shell_file_proc[2],0
  685. jnz @F
  686. fcdr_no_exitj:
  687. jmp fcdr_no_exit
  688. @@:
  689. mov di,dataOffset lpszFileName ; Where we will copy filename
  690. cmp ah, 56h ; RENAME?
  691. jne fcdr_no_alloc
  692. mov ax, 256 ; Get enough for two filenames
  693. xor bx, bx
  694. mov cx, (GA_SHAREABLE SHL 8)+GA_MOVEABLE+GA_NOCOMPACT+GA_NODISCARD
  695. cCall GlobalAlloc,<cx, bx, ax>
  696. or ax, ax
  697. jz fcdr_no_exitj
  698. mov hHunkOMemory, ax
  699. cCall GlobalLock,<ax>
  700. mov es, dx
  701. UnSetKernelDS es
  702. mov di, ax
  703. mov ah, 56h
  704. fcdr_no_alloc:
  705. cld
  706. push ax ; push arguments to call
  707. push es
  708. push di
  709. cmp byte ptr ds:[si][1],':'
  710. jnz nodrive
  711. ifdef FE_SB
  712. mov al, byte ptr ds:[si][0]
  713. call FarMyIsDBCSLeadByte
  714. jnc nodrive
  715. endif
  716. lodsb
  717. inc si
  718. or al,20h ; convert to lower case
  719. sub al,'a' ; convert to number
  720. jmps gotdrive
  721. nodrive:
  722. mov ah,19h
  723. DOSCALL
  724. gotdrive:
  725. mov dl,al
  726. inc dl
  727. add al,'A' ; convert to ascii
  728. mov ah,':'
  729. stosw
  730. mov bx,'/' shl 8 + '\'
  731. mov al,ds:[si]
  732. cmp al,bh
  733. jz getpath
  734. cmp al,bl
  735. jz getpath
  736. mov al,bl
  737. stosb
  738. mov cx,ds
  739. xchg si,di
  740. smov ds,es
  741. mov ah,47h
  742. DOSCALL
  743. mov ds,cx
  744. xchg si,di
  745. xor al,al
  746. ifdef FE_SB
  747. ; seek pointer to final byte of path.
  748. xor ah,ah ; flag to indicate last char is dbc
  749. bsl_1:
  750. mov al,es:[di]
  751. test al,al ; end of string?
  752. jz bsl_2 ; jump if so
  753. inc di
  754. xor ah,ah
  755. call FarMyIsDBCSLeadByte ; DBC?
  756. jc bsl_1 ; jump if not
  757. inc ah ; indicate 'DBC'
  758. jmp bsl_1
  759. bsl_2:
  760. test ah,ah ; last char is DBC?
  761. jnz getpath ; yes - don't test '\/'
  762. else
  763. mov cx,-1
  764. repnz scasb
  765. dec di
  766. endif
  767. mov al,es:[di-1]
  768. cmp al,bh
  769. je getpath
  770. cmp al,bl
  771. je getpath
  772. mov al,bl
  773. stosb
  774. getpath:
  775. @@: lodsb
  776. or al,al
  777. stosb
  778. jnz @B
  779. cmp hHunkOMemory, 0
  780. jz no_second_file
  781. lds si, lpDestFile ; Tack destination file name
  782. copy_second: ; after source file name
  783. lodsb
  784. stosb
  785. or al, al
  786. jnz copy_second
  787. no_second_file:
  788. SetKernelDS es
  789. if KDEBUG
  790. call shell_file_proc
  791. else ; KDEBUG
  792. ;
  793. ; The call to shell_file_proc can blow up if the variable has not
  794. ; been updated properly, and we generate an invalid call fault.
  795. ;
  796. beg_fault_trap bad_shell_file_proc
  797. call shell_file_proc
  798. jmps good_shell_file_proc
  799. bad_shell_file_proc:
  800. fault_fix_stack
  801. ;
  802. ; If shell_file_proc has a bad non-zero value, then zero it out
  803. ; so USER doesn't get confused.
  804. ;
  805. xor si,si
  806. mov word ptr [shell_file_proc],si
  807. mov word ptr [shell_file_proc+2],si
  808. end_fault_trap
  809. good_shell_file_proc:
  810. endif ; KDEBUG
  811. mov si, hHunkOMemory ; Free up memory if necessary
  812. or si, si
  813. jz fcdr_no_exit
  814. cCall GlobalUnlock,<si>
  815. cCall GlobalFree,<si>
  816. fcdr_no_exit:
  817. cEnd
  818. ;-----------------------------------------------------------------------;
  819. ; InitTask1
  820. ;
  821. ;
  822. ; Entry:
  823. ;
  824. ; Returns:
  825. ;
  826. ; Registers Destroyed:
  827. ;
  828. ; History:
  829. ; Sun 04-Feb-1990 23:47:37 -by- David N. Weise [davidw]
  830. ; Wrote it!
  831. ;-----------------------------------------------------------------------;
  832. assumes ds,nothing
  833. assumes es,nothing
  834. cProc InitTask1,<PUBLIC,FAR>
  835. ; parmD callback
  836. cBegin nogen
  837. mov bx,sp
  838. push ds
  839. SetKernelDS
  840. mov ax,ss:[bx].4
  841. mov dressed_for_success.off,ax
  842. mov ax,ss:[bx].6
  843. mov dressed_for_success.sel,ax
  844. pop ds
  845. ret 4
  846. cEnd nogen
  847. ifdef WOW
  848. ;-----------------------------------------------------------------------;
  849. ; IsTaskLocked ;
  850. ; ;
  851. ; Another hack procedure to determine if the current task is locked. ;
  852. ; A non-NULL value is returned if the task is locked and NULL is ;
  853. ; returned is the task is not locked. ;
  854. ; ;
  855. ; This will always return null, because we will always have more than ;
  856. ; one WOW app. (wowexec is always running ;
  857. ; ;
  858. ; This api is used by QuickC ;
  859. ; - Nanduri ;
  860. ;-----------------------------------------------------------------------;
  861. assumes ds, nothing
  862. assumes es, nothing
  863. cProc IsTaskLocked,<PUBLIC,FAR>
  864. cBegin nogen
  865. xor ax,ax
  866. ret
  867. cEnd nogen
  868. endif ; WOW
  869. assumes ds, nothing
  870. assumes es, nothing
  871. cProc GetVersion,<PUBLIC,FAR>
  872. cBegin nogen
  873. push ds
  874. SetKernelDS
  875. cCall GetAppCompatFlags,<0>
  876. test dx, HIW_GACF_WINVER31
  877. jz gv0
  878. mov ax, 0a03h ; Win ver 3.10 if app hack set
  879. jmps gv1
  880. gv0:
  881. mov ax, 5f03h ; Win ver 3.95
  882. ; mov ax,winVer
  883. ; xchg ah,al
  884. gv1:
  885. mov dh,DOS_version
  886. mov dl,DOS_revision
  887. pop ds
  888. UnSetKernelDS
  889. ret
  890. cEnd nogen
  891. sEnd CODE
  892. sBegin MISCCODE
  893. assumes cs, misccode
  894. assumes ds, nothing
  895. assumes es, nothing
  896. ExternNP MISCMapDStoDATA
  897. ;-----------------------------------------------------------------------;
  898. ;
  899. ; SetErrorMode - set the current task's error mode
  900. ;
  901. ; Entry:
  902. ; parmW errMode 0001h = fail critical errors to app
  903. ; 0002h = don't put up pmode fault message
  904. ; 8000h = don't promt for file in OpenFile
  905. ;
  906. ; Returns:
  907. ; AX = old flags
  908. ;
  909. ; History:
  910. ; Sun 11-Feb-1990 19:01:12 -by- David N. Weise [davidw]
  911. ; Added this nifty comment block.
  912. ;-----------------------------------------------------------------------;
  913. assumes ds, nothing
  914. assumes es, nothing
  915. cProc ISetErrorMode,<PUBLIC,FAR>
  916. parmW errMode
  917. cBegin
  918. cCall MISCMapDStoDATA
  919. ResetKernelDS
  920. mov ax,errMode
  921. mov ds,CurTDB
  922. UnSetKernelDS
  923. xchg ds:[TDB_ErrMode],ax
  924. cEnd
  925. ;-----------------------------------------------------------------------;
  926. ; GetWinFlags
  927. ;
  928. ; Gets the WinFlags for those wimps that can't import
  929. ; __WinFlags properly!
  930. ;
  931. ; Entry:
  932. ; none
  933. ;
  934. ; Returns:
  935. ; AX = WinFlags
  936. ;
  937. ; History:
  938. ; Wed 05-Jul-1989 20:19:46 -by- David N. Weise [davidw]
  939. ; Wrote it!
  940. ;-----------------------------------------------------------------------;
  941. assumes ds,nothing
  942. assumes es,nothing
  943. cProc GetWinFlags,<PUBLIC,FAR>
  944. cBegin nogen
  945. push ds
  946. cCall MISCMapDStoDATA
  947. ResetKernelDS
  948. ; Comment out this app hack since toolbook is no longer hacked...
  949. ; above is from Win95 source, why is toolbook no longer hacked? -DaveHart
  950. xor ax, ax
  951. push ax ; NULL => current task
  952. cCall GetAppCompatFlags
  953. test ax, GACF_HACKWINFLAGS
  954. mov ax,WinFlags
  955. jz @f
  956. ifdef WOW
  957. ; fixes toolbook for WOW -BobDay
  958. ; and ah, not ( WF1_WINNT or WF1_PAGING )
  959. and ah, not WF1_WINNT ; fixes some apps that think they can't run on NT
  960. else
  961. and ah, not WF1_PAGING ; fixes toolbook
  962. endif
  963. @@:
  964. xor dx,dx
  965. pop ds
  966. ret
  967. cEnd nogen
  968. ;--------------------------------------------------------
  969. ;
  970. ; GetExeVersion - return the current task's expected Windows version
  971. ;
  972. assumes ds, nothing
  973. assumes es, nothing
  974. cProc GetExeVersion,<PUBLIC,FAR>
  975. cBegin nogen
  976. push ds
  977. call MISCMapDStoDATA
  978. ReSetKernelDS
  979. mov ds, CurTDB
  980. UnSetKernelDS
  981. mov ax, ds:[TDB_ExpWinVer]
  982. pop ds
  983. ret
  984. cEnd nogen
  985. ifndef WOW
  986. ;-----------------------------------------------------------------------;
  987. ; WinOldApCall ;
  988. ; ;
  989. ; This gives WinOldAp the information it needs to run in Expanded ;
  990. ; Memory. ;
  991. ; ;
  992. ; Arguments: ;
  993. ; none ;
  994. ; ;
  995. ; Returns: ;
  996. ; (Real Mode) ;
  997. ; BX = XMS Handle of segment cache block ;
  998. ; CX = Size (in K bytes) of segment cache block ;
  999. ; DS:SI = pointer to original Int 21h handler ;
  1000. ; DI = DOS System File Table Entry size ;
  1001. ; ;
  1002. ; (Protected Mode) ;
  1003. ; AX = Selector to low (lower 640k) heap block ;
  1004. ; BX = paragraph count of low heap block ;
  1005. ; CX = Selector to high (above 1024k & HMA) heap block ;
  1006. ; DX = Selector to fixed low PDB block for WOA use ;
  1007. ; DS:SI = pointer to original Int 21h handler ;
  1008. ; DI = DOS System File Table Entry size ;
  1009. ; ;
  1010. ; Error Returns: ;
  1011. ; ;
  1012. ; Registers Preserved: ;
  1013. ; ;
  1014. ; Registers Destroyed: ;
  1015. ; ;
  1016. ; Calls: ;
  1017. ; nothing ;
  1018. ; ;
  1019. ; History: ;
  1020. ; ;
  1021. ; Wed Mar 25, 1987 03:03:57p -by- David N. Weise [davidw] ;
  1022. ; Wrote it. ;
  1023. ;-----------------------------------------------------------------------;
  1024. assumes ds, nothing
  1025. assumes es, nothing
  1026. cProc WinOldApCall,<PUBLIC,FAR>
  1027. ; parmW func
  1028. cBegin nogen
  1029. push ds
  1030. call MISCMapDStoDATA
  1031. ReSetKernelDS
  1032. mov bx,sp ; check function code
  1033. cmp word ptr ss:[bx+6],0 ; 0 - get WOA info call
  1034. jz get_info ; !0 - close cached files call
  1035. push Win_PDB ; Save current PDB
  1036. cCall CloseCachedFiles,<topPDB> ; close the cached files--really
  1037. pop Win_PDB ; 'Set' it back
  1038. ;;; mov bx, Win_PDB
  1039. ;;; mov ah, 50h ; Reset the PDB
  1040. ;;; call far_real_DOS
  1041. ;;; mov cur_dos_PDB, bx ; Keep variables in sync
  1042. jmps woa_exit ; closes them when passed topPDB
  1043. get_info:
  1044. mov ax,selLowHeap
  1045. mov bx,cpLowHeap
  1046. mov cx,selHighHeap
  1047. mov dx,selWoaPdb
  1048. mov di,FileEntrySize ;DOS version specific SFT entry size
  1049. woa_exit:
  1050. pop ds
  1051. ret 2
  1052. cEnd nogen
  1053. endif
  1054. ;-----------------------------------------------------------------------;
  1055. ; RegisterPtrace
  1056. ;
  1057. ; The ptrace engine DLL gets calls on behalf of the KERNEL.
  1058. ;
  1059. ; Entry:
  1060. ;
  1061. ; Returns:
  1062. ;
  1063. ; Registers Destroyed:
  1064. ;
  1065. ; History:
  1066. ; Fri 02-Feb-1990 23:41:54 -by- David N. Weise [davidw]
  1067. ; We'll get this right one of these days.
  1068. ;
  1069. ; Mon 27-Feb-1989 20:22:06 -by- David N. Weise [davidw]
  1070. ; Wrote it!
  1071. ;-----------------------------------------------------------------------;
  1072. assumes ds,nothing
  1073. assumes es,nothing
  1074. cProc RegisterPtrace,<PUBLIC,FAR>
  1075. ; parmD ptrace_proc
  1076. cBegin nogen
  1077. push ds
  1078. call MISCMapDStoDATA
  1079. ReSetKernelDS
  1080. mov bx,sp
  1081. or Kernel_flags[2],KF2_PTRACE
  1082. mov ax,ss:[bx][6]
  1083. mov ptrace_DLL_entry.off,ax
  1084. or ax,ss:[bx][8] ; is there one?
  1085. mov ax,ss:[bx][8]
  1086. mov ptrace_DLL_entry.sel,ax
  1087. jnz rp_done
  1088. ;** If TOOLHELP's still installed, we don't really want to clear the
  1089. ;** flag. If it's unhooked, clear the flag
  1090. test Kernel_flags[2], KF2_TOOLHELP
  1091. jnz rp_done
  1092. and Kernel_flags[2],NOT KF2_PTRACE
  1093. rp_done:
  1094. pop ds
  1095. ret 4
  1096. cEnd nogen
  1097. ;-----------------------------------------------------------------------;
  1098. ; ToolHelpHook
  1099. ;
  1100. ; Allows TOOLHELP.DLL to get PTrace notifications BEFORE the
  1101. ; normal PTrace hook used by WINDEBUG.DLL. The WINDEBUG.DLL
  1102. ; hook is now obsolete and is maintained only for backward
  1103. ; compatibility.
  1104. ;
  1105. ; TOOLHELP calls this function with a valid lpfn or with NULL
  1106. ; when it is ready to unhook.
  1107. ;
  1108. ; July 25, 1991 [jont]
  1109. ;-----------------------------------------------------------------------;
  1110. cProc ToolHelpHook,<PUBLIC,FAR>, <ds,si,di>
  1111. parmD lpfn
  1112. cBegin
  1113. SetKernelDSMisc
  1114. ;** Set/clear the ToolHelp hook installed flag + we also set the
  1115. ;* PTrace flag because the ToolHelp hook is just a new
  1116. ;* PTrace hook. We can only clear it, though, if BOTH PTrace
  1117. ;** hooks are now clear.
  1118. or Kernel_Flags[2],KF2_TOOLHELP OR KF2_PTRACE ;Set the flags
  1119. mov ax,WORD PTR lpfn[0] ;Get the offset
  1120. mov dx,WORD PTR lpfn[2] ; and the selector
  1121. mov bx,ax ;Get a copy to trash
  1122. or bx,dx ;NULL?
  1123. jnz THH_Installed ;No
  1124. and Kernel_Flags[2],NOT KF2_TOOLHELP ;Clear the flag
  1125. cmp WORD PTR ptrace_dll_entry[2],0 ;WINDEBUG.DLL lurking?
  1126. jnz THH_Installed ;Yes, don't clear PTrace flag
  1127. and Kernel_Flags[2],NOT KF2_PTRACE ;Clear the flag
  1128. THH_Installed:
  1129. ;** Install the hook and return the old one
  1130. xchg ax,WORD PTR lpfnToolHelpProc[0]
  1131. xchg dx,WORD PTR lpfnToolHelpProc[2]
  1132. cEnd
  1133. ;-----------------------------------------------------------------------;
  1134. ; FileCDR
  1135. ;
  1136. ; Allows the shell to set a procedure that gets called when
  1137. ; a file or directory is created, moved, or destroyed.
  1138. ;
  1139. ; Entry:
  1140. ; parmD lpNotifyProc call back function
  1141. ;
  1142. ; Returns:
  1143. ; AX != 0 success
  1144. ;
  1145. ; History:
  1146. ; Mon 05-Jun-1989 22:59:33 -by- David N. Weise [davidw]
  1147. ; Wrote it!
  1148. ;-----------------------------------------------------------------------;
  1149. assumes ds,nothing
  1150. assumes es,nothing
  1151. cProc FileCDR,<PUBLIC,FAR>
  1152. ; parmD lpNotifyProc
  1153. cBegin nogen
  1154. mov bx,sp
  1155. push ds
  1156. call MISCMapDStoDATA
  1157. ReSetKernelDS
  1158. mov ax,ss:[bx][6]
  1159. cmp ax,-1 ; is sel == -1, return current
  1160. jne @F ; proc
  1161. mov ax,shell_file_proc.off
  1162. mov dx,shell_file_proc.sel
  1163. jmps fcdr_exit
  1164. @@:
  1165. xchg shell_file_proc.sel,ax
  1166. or ax,ax
  1167. jz @F
  1168. mov cx,curTDB
  1169. cmp cx,shell_file_TDB
  1170. jnz fcdr_error
  1171. @@: mov ax,ss:[bx][4]
  1172. mov shell_file_proc.off,ax
  1173. mov ax,curTDB
  1174. mov shell_file_TDB,ax
  1175. mov ax,1
  1176. jmps fcdr_exit
  1177. fcdr_error:
  1178. xchg shell_file_proc.sel,ax ; replace what was there
  1179. xor ax,ax
  1180. fcdr_exit:
  1181. pop ds
  1182. UnSetKernelDS
  1183. retf 4
  1184. cEnd nogen
  1185. sEnd MISCCODE
  1186. end