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.

459 lines
13 KiB

  1. /******************************************************************************
  2. *
  3. * (C) Copyright MICROSOFT Corp. All Rights Reserved, 1989-1995
  4. *
  5. * Title: vwin32.h -
  6. *
  7. * Version: 4.00
  8. *
  9. * Date: 24-May-1993
  10. *
  11. ******************************************************************************/
  12. /*INT32*/
  13. #ifndef _VWIN32_H_
  14. #define _VWIN32_H_
  15. // ;BeginInternal
  16. // Note that this ID has been reserved for us in VMM.H
  17. #define VWIN32_DEVICE_ID 0x0002A
  18. #define VWIN32_VER_MAJOR 0x04
  19. #define VWIN32_VER_MINOR 0x0A
  20. // ;EndInternal
  21. #define THREAD_TYPE_WIN32 VWIN32_DEVICE_ID
  22. #ifndef Not_VxD
  23. /*XLATOFF*/
  24. #define VWIN32_Service Declare_Service
  25. #define VWIN32_StdCall_Service Declare_SCService
  26. #pragma warning (disable:4003) // turn off not enough params warning
  27. /*XLATON*/
  28. /*MACROS*/
  29. Begin_Service_Table(VWIN32)
  30. VWIN32_Service (VWIN32_Get_Version, LOCAL)
  31. VWIN32_Service (VWIN32_DIOCCompletionRoutine, LOCAL)
  32. VWIN32_Service (_VWIN32_QueueUserApc)
  33. VWIN32_Service (_VWIN32_Get_Thread_Context)
  34. VWIN32_Service (_VWIN32_Set_Thread_Context)
  35. VWIN32_Service (_VWIN32_CopyMem, LOCAL)
  36. VWIN32_Service (_VWIN32_Npx_Exception)
  37. VWIN32_Service (_VWIN32_Emulate_Npx)
  38. VWIN32_Service (_VWIN32_CheckDelayedNpxTrap)
  39. VWIN32_Service (VWIN32_EnterCrstR0)
  40. VWIN32_Service (VWIN32_LeaveCrstR0)
  41. VWIN32_Service (_VWIN32_FaultPopup)
  42. VWIN32_Service (VWIN32_GetContextHandle)
  43. VWIN32_Service (VWIN32_GetCurrentProcessHandle, LOCAL)
  44. VWIN32_Service (_VWIN32_SetWin32Event)
  45. VWIN32_Service (_VWIN32_PulseWin32Event)
  46. VWIN32_Service (_VWIN32_ResetWin32Event)
  47. VWIN32_Service (_VWIN32_WaitSingleObject)
  48. VWIN32_Service (_VWIN32_WaitMultipleObjects)
  49. VWIN32_Service (_VWIN32_CreateRing0Thread)
  50. VWIN32_Service (_VWIN32_CloseVxDHandle)
  51. VWIN32_Service (VWIN32_ActiveTimeBiasSet, LOCAL)
  52. VWIN32_Service (VWIN32_GetCurrentDirectory, LOCAL)
  53. VWIN32_Service (VWIN32_BlueScreenPopup)
  54. VWIN32_Service (VWIN32_TerminateApp)
  55. VWIN32_Service (_VWIN32_QueueKernelAPC)
  56. VWIN32_Service (VWIN32_SysErrorBox)
  57. VWIN32_Service (_VWIN32_IsClientWin32)
  58. VWIN32_Service (VWIN32_IFSRIPWhenLev2Taken, LOCAL)
  59. VWIN32_Service (_VWIN32_InitWin32Event)
  60. VWIN32_Service (_VWIN32_InitWin32Mutex)
  61. VWIN32_Service (_VWIN32_ReleaseWin32Mutex)
  62. VWIN32_Service (_VWIN32_BlockThreadEx)
  63. VWIN32_Service (VWIN32_GetProcessHandle, LOCAL)
  64. VWIN32_Service (_VWIN32_InitWin32Semaphore)
  65. VWIN32_Service (_VWIN32_SignalWin32Sem)
  66. VWIN32_Service (_VWIN32_QueueUserApcEx)
  67. VWIN32_Service (_VWIN32_OpenVxDHandle)
  68. VWIN32_Service (_VWIN32_CloseWin32Handle)
  69. VWIN32_Service (_VWIN32_AllocExternalHandle)
  70. VWIN32_Service (_VWIN32_UseExternalHandle)
  71. VWIN32_Service (_VWIN32_UnuseExternalHandle)
  72. VWIN32_StdCall_Service (KeInitializeTimer, 1)
  73. VWIN32_StdCall_Service (KeSetTimer, 4)
  74. VWIN32_StdCall_Service (KeCancelTimer, 1)
  75. VWIN32_StdCall_Service (KeReadStateTimer, 1)
  76. VWIN32_Service (_VWIN32_ReferenceObject)
  77. VWIN32_Service (_VWIN32_GetExternalHandle)
  78. VWIN32_StdCall_Service (VWIN32_ConvertNtTimeout, 1)
  79. VWIN32_Service (_VWIN32_SetWin32EventBoostPriority)
  80. VWIN32_Service (_VWIN32_GetRing3Flat32Selectors)
  81. VWIN32_Service (_VWIN32_GetCurThreadCondition)
  82. VWIN32_Service (VWIN32_Init_FP)
  83. VWIN32_StdCall_Service (R0SetWaitableTimer, 5)
  84. End_Service_Table(VWIN32)
  85. /*ENDMACROS*/
  86. /*XLATOFF*/
  87. #pragma warning (default:4003) // turn on not enough params warning
  88. PVOID VXDINLINE
  89. VWIN32OpenVxDHandle(ULONG Handle,ULONG dwType)
  90. {
  91. PVOID ul;
  92. _asm push [dwType]
  93. _asm push [Handle]
  94. VxDCall(_VWIN32_OpenVxDHandle)
  95. _asm add esp, 8
  96. _asm mov [ul], eax
  97. return(ul);
  98. }
  99. WORD VXDINLINE
  100. VWIN32_Get_Version(VOID)
  101. {
  102. WORD w;
  103. VxDCall(VWIN32_Get_Version);
  104. _asm mov [w], ax
  105. return(w);
  106. }
  107. /*XLATON*/
  108. #endif // Not_VxD
  109. //
  110. // For _VWIN32_GetCurThreadCondition
  111. //
  112. #define THREAD_CONDITION_DOS_BOX 0x00000000l
  113. #define THREAD_CONDITION_V86_NEST 0x00000001l
  114. #define THREAD_CONDITION_WDM 0x00000002l
  115. #define THREAD_CONDITION_INDETERMINATE 0x00000003l
  116. #define THREAD_CONDITION_LOCKED_STACK 0x00000004l
  117. #define THREAD_CONDITION_PURE_WIN16 0x00000005l
  118. #define THREAD_CONDITION_THUNKED_WIN16 0x00000006l
  119. #define THREAD_CONDITION_THUNKED_WIN32 0x00000007l
  120. #define THREAD_CONDITION_PURE_WIN32 0x00000008l
  121. #define THREAD_CONDITION_APPY_TIME 0x00000009l
  122. #define THREAD_CONDITION_RING0_APPY_TIME 0x0000000Al
  123. #define THREAD_CONDITION_EXIT 0x0000000Bl
  124. #define THREAD_CONDITION_INVALID_FLAGS 0xFFFFFFFFl
  125. #define THREAD_CONDITION_NORMAL_FLAGS 0x00000000l
  126. // ;BeginInternal
  127. // PM API list
  128. #define VWIN32_GET_VER 0
  129. #define VWIN32_THREAD_SWITCH 1 // ECX = wake param, EBX = ring 0 handle
  130. #define VWIN32_DPMI_FAULT 2 // SS:BP = FAULTSTACKFRAME, AL = ignore
  131. #define VWIN32_MMGR_FUNCTIONS 3
  132. #define VWIN32_EVENT_CREATE 4
  133. #define VWIN32_EVENT_DESTROY 5
  134. #define VWIN32_EVENT_WAIT 6
  135. #define VWIN32_EVENT_SET 7
  136. #define VWIN32_RealNetx_Info 8
  137. #define VWIN32_THREAD_BOOST_PRI 9
  138. #define VWIN32_WAIT_CRST 10
  139. #define VWIN32_WAKE_CRST 11
  140. #define VWIN32_SET_FAULT_INFO 12
  141. #define VWIN32_EXIT_TIME 13
  142. #define VWIN32_BOOST_THREAD_GROUP 14
  143. #define VWIN32_BOOST_THREAD_STATIC 15
  144. #define VWIN32_WAKE_IDLE_SYS 16
  145. #define VWIN32_MAKE_IDLE_SYS 17
  146. #define VWIN32_DELIVER_PENDING_KERNEL_APCS 18
  147. #define VWIN32_SYS_ERROR_BOX 19
  148. #define VWIN32_GET_IFSMGR_XLAT_PTR 20
  149. #define VWIN32_BOOST_THREAD_DECAY 21
  150. #define VWIN32_LAST_CMD 21
  151. #define VWIN32_MMGR_RESERVE ((VWIN32_MMGR_FUNCTIONS << 8) + 0)
  152. #define VWIN32_MMGR_COMMIT ((VWIN32_MMGR_FUNCTIONS << 8) + 1)
  153. #define VWIN32_MMGR_DECOMMIT ((VWIN32_MMGR_FUNCTIONS << 8) + 2)
  154. #define VWIN32_MMGR_PAGEFREE ((VWIN32_MMGR_FUNCTIONS << 8) + 3)
  155. //
  156. // Current Win32 thread/process handles.
  157. //
  158. // Updated every context switch.
  159. //
  160. #ifndef WOW
  161. typedef struct _K32CURRENT {
  162. DWORD CurThreadHandle; // win32 thread handle
  163. DWORD CurProcessHandle; // win32 process handle
  164. DWORD CurTDBX; // current TDBX
  165. DWORD pCurK16Task; // flat pointer to kernel 16 CurTDB
  166. DWORD CurContextHandle; // win32 memory context handle
  167. } K32CURRENT;
  168. #endif // ndef WOW
  169. //
  170. // Flag values for CreateThread
  171. //
  172. #define VWIN32_CT_EMULATE_NPX 0x01 // set EM bit in CR0 for thread
  173. #define VWIN32_CT_WIN32_NPX 0x02 // use Win32 FP exception model
  174. #define VWIN32_CT_WIN32 0x04 // thread is Win32 (not Win16)
  175. //
  176. // Return values from VWIN32_CheckDelayedNpxTrap
  177. //
  178. #define CX_RAISE 0 // instruction raises exception
  179. #define CX_IGNORE 1 // instruction ignores exception
  180. #define CX_CLEAR 2 // instruction clears or masks exception
  181. // flags to use for win32 blocking
  182. #define WIN32_BLOCK_FLAGS (BLOCK_FORCE_SVC_INTS+BLOCK_SVC_INTS+BLOCK_THREAD_IDLE+BLOCK_ENABLE_INTS)
  183. //
  184. // Flags for VWIN32_BlueScreenPopup
  185. //
  186. #define VBSP_CANCEL 0x00000001
  187. #define VBSP_DISPLAY_VXD_NAME 0x00000002
  188. //
  189. // Fault stack frame structure
  190. //
  191. typedef struct fsf_s {
  192. WORD fsf_GS;
  193. WORD fsf_FS;
  194. WORD fsf_ES;
  195. WORD fsf_DS;
  196. DWORD fsf_EDI;
  197. DWORD fsf_ESI;
  198. DWORD fsf_EBP;
  199. DWORD fsf_locked_ESP;
  200. DWORD fsf_EBX;
  201. DWORD fsf_EDX;
  202. DWORD fsf_ECX;
  203. DWORD fsf_EAX;
  204. WORD fsf_num; // Fault number
  205. WORD fsf_prev_IP; // IP of previous fault handler
  206. WORD fsf_prev_CS; // CS of previous fault handler
  207. WORD fsf_ret_IP; // DPMI fault handler frame follows
  208. WORD fsf_ret_CS;
  209. WORD fsf_err_code;
  210. WORD fsf_faulting_IP;
  211. WORD fsf_faulting_CS;
  212. WORD fsf_flags;
  213. WORD fsf_SP;
  214. WORD fsf_SS;
  215. } FAULTSTACKFRAME;
  216. typedef FAULTSTACKFRAME *PFAULTSTACKFRAME;
  217. // ;EndInternal
  218. //
  219. // structure for VWIN32_SysErrorBox
  220. //
  221. typedef struct vseb_s {
  222. DWORD vseb_resp;
  223. WORD vseb_b3;
  224. WORD vseb_b2;
  225. WORD vseb_b1;
  226. DWORD vseb_pszCaption;
  227. DWORD vseb_pszText;
  228. } VSEB;
  229. typedef VSEB *PVSEB;
  230. #define SEB_ANSI 0x4000 // ANSI strings if set on vseb_b1
  231. #define SEB_TERMINATE 0x2000 // forces termination if button pressed
  232. // VWIN32_QueueKernelAPC flags
  233. #define KERNEL_APC_IGNORE_MC 0x00000001
  234. #define KERNEL_APC_STATIC 0x00000002
  235. #define KERNEL_APC_WAKE 0x00000004
  236. // for DeviceIOControl support
  237. // On a DeviceIOControl call vWin32 will pass following parameters to
  238. // the Vxd that is specified by hDevice. hDevice is obtained thru an
  239. // earlier call to hDevice = CreateFile("\\.\vxdname", ...);
  240. // ESI = DIOCParams STRUCT (defined below)
  241. typedef struct DIOCParams {
  242. DWORD Internal1; // ptr to client regs
  243. DWORD VMHandle; // VM handle
  244. DWORD Internal2; // DDB
  245. DWORD dwIoControlCode;
  246. DWORD lpvInBuffer;
  247. DWORD cbInBuffer;
  248. DWORD lpvOutBuffer;
  249. DWORD cbOutBuffer;
  250. DWORD lpcbBytesReturned;
  251. DWORD lpoOverlapped;
  252. DWORD hDevice;
  253. DWORD tagProcess;
  254. } DIOCPARAMETERS;
  255. typedef DIOCPARAMETERS *PDIOCPARAMETERS;
  256. // dwIoControlCode values for vwin32's DeviceIOControl Interface
  257. // all VWIN32_DIOC_DOS_ calls require lpvInBuffer abd lpvOutBuffer to be
  258. // struct * DIOCRegs
  259. #define VWIN32_DIOC_GETVERSION DIOC_GETVERSION
  260. #define VWIN32_DIOC_DOS_IOCTL 1
  261. #define VWIN32_DIOC_DOS_INT25 2
  262. #define VWIN32_DIOC_DOS_INT26 3
  263. #define VWIN32_DIOC_DOS_INT13 4
  264. #define VWIN32_DIOC_SIMCTRLC 5
  265. #define VWIN32_DIOC_DOS_DRIVEINFO 6
  266. #define VWIN32_DIOC_CLOSEHANDLE DIOC_CLOSEHANDLE
  267. // DIOCRegs
  268. // Structure with i386 registers for making DOS_IOCTLS
  269. // vwin32 DIOC handler interprets lpvInBuffer , lpvOutBuffer to be this struc.
  270. // and does the int 21
  271. // reg_flags is valid only for lpvOutBuffer->reg_Flags
  272. typedef struct DIOCRegs {
  273. DWORD reg_EBX;
  274. DWORD reg_EDX;
  275. DWORD reg_ECX;
  276. DWORD reg_EAX;
  277. DWORD reg_EDI;
  278. DWORD reg_ESI;
  279. DWORD reg_Flags;
  280. } DIOC_REGISTERS;
  281. // if we are not included along with winbase.h
  282. #ifndef FILE_FLAG_OVERLAPPED
  283. // OVERLAPPED structure for DeviceIOCtl VxDs
  284. typedef struct _OVERLAPPED {
  285. DWORD O_Internal;
  286. DWORD O_InternalHigh;
  287. DWORD O_Offset;
  288. DWORD O_OffsetHigh;
  289. HANDLE O_hEvent;
  290. } OVERLAPPED;
  291. #endif
  292. // Parameters for _VWIN32_OpenVxDHandle to validate the Win32 handle type.
  293. #define OPENVXD_TYPE_SEMAPHORE 0
  294. #define OPENVXD_TYPE_EVENT 1
  295. #define OPENVXD_TYPE_MUTEX 2
  296. #define OPENVXD_TYPE_ANY 3
  297. // ;BeginInternal
  298. #define OPENVXD_TYPE_MAXIMUM 3
  299. // ;EndInternal
  300. //
  301. // Object type table declaration for _VWIN32_AllocExternalHandle
  302. //
  303. /*XLATOFF*/
  304. #define R0OBJCALLBACK __stdcall
  305. typedef VOID (R0OBJCALLBACK *R0OBJFREE)(PVOID pR0ObjBody);
  306. typedef PVOID (R0OBJCALLBACK *R0OBJDUP)(PVOID pR0ObjBody, DWORD hDestProc);
  307. /*XLATON*/
  308. /* ASM
  309. R0OBJFREE TYPEDEF DWORD
  310. R0OBJDUP TYPEDEF DWORD
  311. */
  312. typedef struct _R0OBJTYPETABLE {
  313. DWORD ott_dwSize; // sizeof(R0OBJTYPETABLE)
  314. R0OBJFREE ott_pfnFree; // called by Win32 CloseHandle
  315. R0OBJDUP ott_pfnDup; // called by Win32 DuplicateHandle
  316. } R0OBJTYPETABLE, *PR0OBJTYPETABLE;
  317. /* ASM
  318. R0OBJTYPETABLE typedef _R0OBJTYPETABLE;
  319. */
  320. #define R0EHF_INHERIT 0x00000001 // Handle is inheritable
  321. #define R0EHF_GLOBAL 0x00000002 // Handle is valid in all contexts
  322. // ;BeginInternal
  323. #define R0EHF_ALL (R0EHF_INHERIT | R0EHF_GLOBAL)
  324. // ;EndInternal
  325. // ;BeginInternal
  326. /* ASM
  327. FSF_CLEANUP_RETURN EQU fsf_ret_IP - fsf_num
  328. FSF_CLEANUP_CHAIN EQU fsf_prev_IP - fsf_num
  329. ifndef WOW
  330. K32CURRENT typedef _K32CURRENT
  331. endif
  332. ;***LT W32Fun - macro to make a function callable from Kernel32
  333. ;
  334. ; This macro will create a stub of the format that the Ring0/Ring3
  335. ; Win32 calling interface likes.
  336. ; It plays around with the stack so that the arguments are set
  337. ; up right and clean off right and it also sets the ring 3
  338. ; registers to reflect the outcome of the operation.
  339. ;
  340. ; This macro is taken from VMM's memory manager, file: mma.asm
  341. ;
  342. ; ENTRY: fun - function name
  343. ; cargs - number of dword arguments it has
  344. ; prefix - prefix for function
  345. ; EXIT: none
  346. ;
  347. ; Note that when the function is called:
  348. ; EBX is the VM handle
  349. ; ESI points to client registers
  350. ; EDI points to the return address
  351. ; THESE REGISTERS MUST NOT BE TRASHED!
  352. ;
  353. W32Fun MACRO fun, cbargs, prefix
  354. BeginProc VW32&fun, esp, W32SVC, public
  355. ArgVar pcrs,dword
  356. ArgVar hvm,dword
  357. x = 0
  358. REPT cbargs
  359. x = x + 1
  360. ArgVar arg&x,dword
  361. ENDM
  362. EnterProc
  363. pop edi ;Save and remove return address
  364. pop esi ;Save and remove client regs
  365. pop ebx ;Save and remove hvm
  366. call prefix&fun ;Call function somewhere in VxD
  367. ;Note that this function may be a C function
  368. mov [esi].Client_EAX,eax ;Put return values into client regs
  369. push ebx ;Put hvm back on stack
  370. push esi ;Put client regs back on stack
  371. push edi ;Restore return address
  372. LeaveProc
  373. Return
  374. EndProc VW32&fun
  375. ENDM
  376. */
  377. // ;EndInternal
  378. // ;BeginInternal
  379. //
  380. // Used by SetPriorityClass API in priority.c
  381. //
  382. typedef struct _ThreadNewPriority{
  383. HANDLE R0ThHandle;
  384. int NewPriority;
  385. } TH_NEW_PRIORITY, *PTH_NEW_PRIORITY;
  386. // ;EndInternal
  387. #endif // _VWIN32_H_