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.

524 lines
16 KiB

  1. PAGE 58,132
  2. ;******************************************************************************
  3. TITLE SAGE - SAGE VxD
  4. ;******************************************************************************
  5. ;
  6. ; Title: SAGE.ASM - SAGE VxD
  7. ;
  8. ; Version: 0.060
  9. ;
  10. ; Date: 04/18/95
  11. ;
  12. ; Author: Bob Eichenlaub
  13. ;
  14. ;------------------------------------------------------------------------------
  15. ;
  16. ; Change log:
  17. ;
  18. ; DATE REV DESCRIPTION
  19. ; ----------- --- -----------------------------------------------------------
  20. ; 04/18/95 Initial version - be
  21. ; 07/06/95 serial IRQ detection - be; credit to rjc for the basic approach
  22. ; 05/23/97 [darrenmi] major clean-up and support multiple clients
  23. ; for IE4
  24. ;
  25. ;==============================================================================
  26. .386p
  27. ;******************************************************************************
  28. ; I N C L U D E S
  29. ;******************************************************************************
  30. .XLIST
  31. INCLUDE VMM.Inc
  32. INCLUDE VWIN32.Inc
  33. INCLUDE VPICD.Inc
  34. WIN41SERVICES equ 1 ; need _SHELL_Update_User_Activity_Ex service
  35. INCLUDE SHELL.Inc
  36. INCLUDE VXDLDR.Inc
  37. INCLUDE regdef.Inc
  38. INCLUDE Debug.Inc
  39. INCLUDE Sage.Inc
  40. .LIST
  41. ;public SAGE_Update_User_Activity
  42. ;******************************************************************************
  43. ; V I R T U A L D E V I C E D E C L A R A T I O N
  44. ;------------------------------------------------------------------------------
  45. ; The VxD declaration statement defines the VxD name, version number,
  46. ; control proc entry point, VxD ID, initialization order, and VM API
  47. ; entry points.
  48. ;
  49. ; - Defined VxD ID: See VXDID.TXT for more information
  50. ; - Init order: If serial port detection is enabled then this Vxd MUST loaded
  51. ; before VCOMM.VxD and after VPICD.VxD,
  52. ; See VMM.INC for the complete
  53. ; definition of the init order of the standard devices.
  54. ;
  55. ;******************************************************************************
  56. Declare_Virtual_Device sage, 1, 0, SAGE_Control, VSageID, UNDEFINED_INIT_ORDER
  57. ;******************************************************************************
  58. ; D A T A
  59. ;******************************************************************************
  60. ;
  61. ; Locked data
  62. ;
  63. VxD_LOCKED_DATA_SEG
  64. Window_List dd 0, 0, 0, 0, 0, 0, 0, 0
  65. cClients dd 0 ; number of valid windows in window list
  66. Time_Out_Idle dd 10000 ; the interval between message posts
  67. Time_Out_Handle dd 0 ; Handle to the global time out we create
  68. PtrSHELL_SUUAE_INFO dd 0 ; pointer to the SHELL_SUUAE_INFO structure
  69. PrevActiveDisplay dd 0 ; last screen or user input activity
  70. PrevActiveSystem dd 0 ; last system activity
  71. Hooked_Proc dd 0 ; shell's user_activity entry that we hooked
  72. ; Fake user activity info structure in case on Win95.
  73. FakeSUUAE_INFO _SHELL_SUUAE_INFO <0,0,0,0,0>
  74. VxD_LOCKED_DATA_ENDS
  75. ;******************************************************************************
  76. ; C O D E
  77. ;------------------------------------------------------------------------------
  78. ; The 'body' of the VxD is in the standard code segment.
  79. ;******************************************************************************
  80. VxD_CODE_SEG
  81. BeginProc SAGE_Start_Idle_Timer
  82. push esi
  83. ; check to see if we've already got a timer
  84. mov esi, [Time_Out_Handle]
  85. test esi, esi
  86. jnz start1
  87. ; get a timer
  88. mov eax, [Time_Out_Idle]
  89. mov esi, OFFSET32 SAGE_User_Idle_Check
  90. VMMCall Set_Global_Time_Out
  91. mov [Time_Out_Handle], esi
  92. start1:
  93. pop esi
  94. ret
  95. EndProc SAGE_Start_Idle_Timer
  96. BeginProc SAGE_Stop_Idle_Timer
  97. push esi
  98. ; check to see if we have a timer
  99. mov esi, [Time_Out_Handle]
  100. test esi, esi
  101. jz stop1
  102. ; kill it
  103. VMMCall Cancel_Time_Out
  104. xor esi, esi
  105. mov [Time_Out_Handle], esi
  106. stop1:
  107. pop esi
  108. ret
  109. EndProc SAGE_Stop_Idle_Timer
  110. ;******************************************************************************
  111. ;
  112. ; SAGE_Device_IO
  113. ;
  114. ; DESCRIPTION:
  115. ; This is the routine that is called when the CreateFile or
  116. ; DeviceIoControl is made
  117. ;
  118. ; ENTRY:
  119. ; ESI = Pointer to args (see VWIN32.INC for struct definition)
  120. ;
  121. ; EXIT:
  122. ; EAX = return value
  123. ;
  124. ; USES:
  125. ; flags
  126. ;
  127. ;==============================================================================
  128. BeginProc SAGE_Device_IO
  129. mov ecx, [esi.dwIOControlCode]
  130. test ecx, ecx
  131. jnz next1
  132. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  133. ;
  134. ; DIOC_GETVERSION
  135. ;
  136. ; obtain a pointer to the shell vxd's activity timer info
  137. cmp [PtrSHELL_SUUAE_INFO], 0
  138. jne short getver1
  139. VxDCall SHELL_Get_Version
  140. cmp eax, 040Ah
  141. jae short haveSUUAEX
  142. ; Running on Win95 so we don't have SHELL_Update_User_Activty_Ex service,
  143. ; hook the shell vxd's activity service to watch activity.
  144. mov esi, offset32 SAGE_Update_User_Activity
  145. GetVxDServiceOrdinal eax, SHELL_Update_User_Activity
  146. VMMCall Hook_Device_Service
  147. mov eax, offset32 FakeSUUAE_INFO
  148. jmp short setSUUAE_INFO
  149. haveSUUAEX:
  150. VxDCall _SHELL_Update_User_Activity_Ex, <SUUAE_CONTINUOUS OR SUUAE_CONTINUOUS_CHECK>
  151. setSUUAE_INFO:
  152. mov [PtrSHELL_SUUAE_INFO], eax ; (eax) = ptr to SHELL_SUAAE_INFO structure
  153. getver1:
  154. xor eax, eax ; success
  155. ret
  156. next1:
  157. cmp ecx,-1
  158. jne next2
  159. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  160. ;
  161. ; DIOC_CLOSE
  162. ;
  163. ; see if we have clients to close
  164. cmp [cClients], 0
  165. jz close1
  166. ; we do... see if it's the last one...
  167. dec [cClients]
  168. cmp [cClients], 0
  169. jnz close1
  170. ; last client going away - clean up
  171. call SAGE_Stop_Idle_Timer
  172. cmp [PtrSHELL_SUUAE_INFO], offset32 FakeSUUAE_INFO
  173. jne short close1
  174. ; unhook activity service
  175. GetVxDServiceOrdinal eax,SHELL_Update_User_Activity
  176. mov esi, offset32 SAGE_Update_User_Activity
  177. VMMCall Unhook_Device_Service
  178. xor eax, eax
  179. mov [PtrSHELL_SUUAE_INFO], eax ; clear pointer
  180. close1:
  181. xor eax,eax ; success
  182. ret
  183. next2:
  184. cmp ecx,1
  185. jne next3
  186. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  187. ;
  188. ; Set handle and timeout
  189. ;
  190. mov ebx, [esi.lpvInBuffer]
  191. ; Try to find window handle
  192. mov eax, [ebx]
  193. mov ecx, [cClients]
  194. test ecx, ecx
  195. jz addtolist
  196. ioloop:
  197. cmp eax, [Window_List + 4 * ecx - 4]
  198. je timeout
  199. dec ecx
  200. jnz ioloop
  201. ; Can't find it - add it to window list
  202. mov ecx, [cClients]
  203. cmp ecx, 8
  204. jnl timeout
  205. addtolist:
  206. inc [cClients]
  207. mov [Window_List + 4 * ecx], eax
  208. timeout:
  209. ; update timeout if specified
  210. mov eax, [ebx+8]
  211. test eax, eax
  212. jz config1
  213. mov [Time_Out_Idle], eax
  214. config1:
  215. call SAGE_Start_Idle_Timer
  216. xor eax, eax ; success
  217. ret
  218. next3:
  219. cmp ecx, 2
  220. jne next4
  221. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  222. ;
  223. ; Query last activity
  224. ;
  225. mov ebx, [esi.lpvInBuffer]
  226. mov edx, [PtrSHELL_SUUAE_INFO]
  227. .errnz ssiHoldSystem-ssiHoldDisplay-1
  228. cmp word ptr [edx].ssiHoldDisplay, 0
  229. jne short lact1 ; system or display in "hold" state
  230. mov eax, [edx].ssiTimeLastActiveDisplay
  231. cmp eax, [edx].ssiTimeLastActiveSystem
  232. jae short lact2
  233. mov eax, [edx].ssiTimeLastActiveSystem
  234. jmp short lact2
  235. lact1: VMMCall Get_Last_Updated_System_Time
  236. lact2: mov [ebx], eax
  237. xor eax, eax
  238. ret
  239. next4:
  240. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  241. ;
  242. ; some unsupported value...
  243. ;
  244. mov eax, ERROR_NOT_SUPPORTED
  245. ret
  246. EndProc SAGE_Device_IO
  247. VxD_CODE_ENDS
  248. ;******************************************************************************
  249. ; P A G E L O C K E D C O D E
  250. ;------------------------------------------------------------------------------
  251. ; Memory is a scarce resource. Use this only where necessary.
  252. ;******************************************************************************
  253. VxD_LOCKED_CODE_SEG
  254. ;******************************************************************************
  255. ;
  256. ; SAGE_Control
  257. ;
  258. ; DESCRIPTION:
  259. ;
  260. ; This is a call-back routine to handle the messages that are sent
  261. ; to VxD's to control system operation. Every VxD needs this function
  262. ; regardless if messages are processed or not. The control proc must
  263. ; be in the LOCKED code segment.
  264. ;
  265. ; The Control_Dispatch macro used in this procedure simplifies
  266. ; the handling of messages. To handle a particular message, add
  267. ; a Control_Dispatch statement with the message name, followed
  268. ; by the procedure that should handle the message.
  269. ;
  270. ; ENTRY:
  271. ; EAX = Message number
  272. ; EBX = VM Handle
  273. ;
  274. ;==============================================================================
  275. BeginProc SAGE_Control
  276. Control_Dispatch W32_DEVICEIOCONTROL, SAGE_Device_IO
  277. clc
  278. ret
  279. EndProc SAGE_Control
  280. BeginDoc
  281. ;******************************************************************************
  282. ;
  283. ; SAGE_Update_User_Activity
  284. ;
  285. ; DESCRIPTION:
  286. ;
  287. ; This service is called by VMD, VKD to tell us that user input occured
  288. ; ENTRY: None
  289. ; EXIT: None
  290. ; USES: NONE
  291. ;==============================================================================
  292. EndDoc
  293. BeginProc SAGE_Update_User_Activity, HOOK_PROC, Hooked_Proc
  294. push eax
  295. ; save off the time
  296. VMMCall Get_Last_Updated_System_Time
  297. mov [FakeSUUAE_INFO.ssiTimeLastActiveDisplay], eax
  298. pop eax
  299. jmp Hooked_Proc
  300. EndProc SAGE_Update_User_Activity
  301. VxD_LOCKED_CODE_ENDS
  302. VxD_PAGEABLE_CODE_SEG
  303. ;******************************************************************************
  304. ;
  305. ; SAGE_User_Idle_Check
  306. ;
  307. ; DESCRIPTION:
  308. ;
  309. ; This checks if key/mouse or serial port (comm) event has occurred.
  310. ;
  311. ; Entry:
  312. ; None
  313. ; Exit:
  314. ; None
  315. ; Uses:
  316. ; ALL
  317. ;******************************************************************************
  318. BeginProc SAGE_User_Idle_Check,High_Freq,PUBLIC
  319. ;
  320. ; clear handle
  321. ;
  322. xor ecx, ecx
  323. mov [Time_Out_Handle], ecx
  324. ;
  325. ; check for idleness
  326. ;
  327. mov eax, [PtrSHELL_SUUAE_INFO] ; (eax) = ptr to SHELL_SUAAE_INFO structure
  328. .errnz ssiHoldSystem-ssiHoldDisplay-1
  329. cmp word ptr [eax].ssiHoldDisplay, 0
  330. jne short holdActive ; system or display in "hold" state
  331. mov ecx, [eax].ssiTimeLastActiveDisplay
  332. mov edx, [eax].ssiTimeLastActiveSystem
  333. cmp ecx, [PrevActiveDisplay]
  334. jne notIdle ; display activity changed
  335. cmp edx, [PrevActiveSystem]
  336. je ResetTimer ; no display or system activity since last time
  337. ;
  338. ; Not idle so post a message to all clients who want to know
  339. ;
  340. notIdle:
  341. mov [PrevActiveDisplay], ecx ; update idle times for next time
  342. mov [PrevActiveSystem], edx
  343. holdActive:
  344. xor eax, eax
  345. mov ecx, [cClients]
  346. test ecx, ecx
  347. jz ResetTimer
  348. loop0:
  349. ; get next window
  350. mov ebx, [4 * ecx + Window_List - 4]
  351. ; skip if it's -1
  352. cmp ebx, -1
  353. je loop1
  354. ; post message
  355. push ecx
  356. VxDCall _SHELL_PostMessage, <ebx, WM_SAGE_MSG, eax, eax, eax, eax>
  357. pop ecx
  358. loop1:
  359. dec ecx
  360. jnz loop0
  361. ;
  362. ; reset the timer so we check again later
  363. ;
  364. ResetTimer:
  365. call SAGE_Start_Idle_Timer
  366. ret
  367. EndProc SAGE_User_Idle_Check
  368. VxD_PAGEABLE_CODE_ENDS
  369. ;******************************************************************************
  370. ; R E A L M O D E C O D E
  371. ;******************************************************************************
  372. ;******************************************************************************
  373. ;
  374. ; Real mode initialization code
  375. ;
  376. ; DESCRIPTION:
  377. ; This code is called when the system is still in real mode, and
  378. ; the VxDs are being loaded.
  379. ;
  380. ; This routine as coded shows how a VxD (with a defined VxD ID)
  381. ; could check to see if it was being loaded twice, and abort the
  382. ; second without an error message. Note that this would require
  383. ; that the VxD have an ID other than Undefined_Device_ID. See
  384. ; the file VXDID.TXT more details.
  385. ;
  386. ; ENTRY:
  387. ; AX = VMM Version
  388. ; BX = Flags
  389. ; Bit 0: duplicate device ID already loaded
  390. ; Bit 1: duplicate ID was from the INT 2F device list
  391. ; Bit 2: this device is from the INT 2F device list
  392. ; EDX = Reference data from INT 2F response, or 0
  393. ; SI = Environment segment, passed from MS-DOS
  394. ;
  395. ; EXIT:
  396. ; BX = ptr to list of pages to exclude (0, if none)
  397. ; SI = ptr to list of instance data items (0, if none)
  398. ; EDX = DWORD of reference data to be passed to protect mode init
  399. ;
  400. ;==============================================================================
  401. VxD_REAL_INIT_SEG
  402. BeginProc SAGE_Real_Init_Proc
  403. test bx, Duplicate_Device_ID ; check for already loaded
  404. jnz short duplicate ; jump if so
  405. xor bx, bx ; no exclusion table
  406. xor si, si ; no instance data table
  407. xor edx, edx ; no reference data
  408. mov ax, Device_Load_Ok
  409. ret
  410. duplicate:
  411. mov ax, Abort_Device_Load + No_Fail_Message
  412. ret
  413. EndProc SAGE_Real_Init_Proc
  414. VxD_REAL_INIT_ENDS
  415. END