vwin32.h
Upload User: xhy777
Upload Date: 2007-02-14
Package Size: 24088k
Code Size: 12k
Category:

Windows Kernel

Development Platform:

Visual C++

  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    1
  19. #define VWIN32_VER_MINOR    4
  20. #define THREAD_TYPE_WIN32 VWIN32_DEVICE_ID
  21. // ;EndInternal
  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. End_Service_Table(VWIN32)
  79. /*ENDMACROS*/
  80. /*XLATOFF*/
  81. #pragma warning (default:4003)      // turn on not enough params warning
  82. /*XLATON*/
  83. #endif // Not_VxD
  84. // ;BeginInternal
  85. // PM API list
  86. #define VWIN32_GET_VER      0
  87. #define VWIN32_THREAD_SWITCH    1   // ECX = wake param, EBX = ring 0 handle
  88. #define VWIN32_DPMI_FAULT   2   // SS:BP = FAULTSTACKFRAME, AL = ignore
  89. #define VWIN32_MMGR_FUNCTIONS   3
  90. #define VWIN32_EVENT_CREATE 4
  91. #define VWIN32_EVENT_DESTROY    5
  92. #define VWIN32_EVENT_WAIT   6
  93. #define VWIN32_EVENT_SET    7
  94. #define VWIN32_RealNetx_Info    8
  95. #define VWIN32_THREAD_BOOST_PRI 9
  96. #define VWIN32_WAIT_CRST    10
  97. #define VWIN32_WAKE_CRST    11
  98. #define VWIN32_SET_FAULT_INFO   12
  99. #define VWIN32_EXIT_TIME    13
  100. #define VWIN32_BOOST_THREAD_GROUP 14
  101. #define VWIN32_BOOST_THREAD_STATIC 15
  102. #define VWIN32_WAKE_IDLE_SYS    16
  103. #define VWIN32_MAKE_IDLE_SYS    17
  104. #define VWIN32_DELIVER_PENDING_KERNEL_APCS 18
  105. #define VWIN32_SYS_ERROR_BOX    19
  106. #define VWIN32_GET_IFSMGR_XLAT_PTR 20
  107. #define VWIN32_BOOST_THREAD_DECAY 21
  108. #define VWIN32_LAST_CMD     21
  109. #define VWIN32_MMGR_RESERVE ((VWIN32_MMGR_FUNCTIONS << 8) + 0)
  110. #define VWIN32_MMGR_COMMIT  ((VWIN32_MMGR_FUNCTIONS << 8) + 1)
  111. #define VWIN32_MMGR_DECOMMIT    ((VWIN32_MMGR_FUNCTIONS << 8) + 2)
  112. #define VWIN32_MMGR_PAGEFREE    ((VWIN32_MMGR_FUNCTIONS << 8) + 3)
  113. //
  114. // Current Win32 thread/process handles.
  115. //
  116. // Updated every context switch.
  117. //
  118. typedef struct _K32CURRENT {
  119.     DWORD   CurThreadHandle;    // win32 thread handle
  120.     DWORD   CurProcessHandle;   // win32 process handle
  121.     DWORD   CurTDBX;        // current TDBX
  122.     DWORD   pCurK16Task;        // flat pointer to kernel 16 CurTDB
  123.     DWORD   CurContextHandle;   // win32 memory context handle
  124. } K32CURRENT;
  125. //
  126. // Flag values for CreateThread
  127. //
  128. #define VWIN32_CT_EMULATE_NPX   0x01    // set EM bit in CR0 for thread
  129. #define VWIN32_CT_WIN32_NPX 0x02    // use Win32 FP exception model
  130. #define VWIN32_CT_WIN32     0x04    // thread is Win32 (not Win16)
  131. //
  132. // Return values from VWIN32_CheckDelayedNpxTrap
  133. //
  134. #define CX_RAISE    0       // instruction raises exception
  135. #define CX_IGNORE   1       // instruction ignores exception
  136. #define CX_CLEAR    2       // instruction clears or masks exception
  137. // flags to use for win32 blocking
  138. #define WIN32_BLOCK_FLAGS (BLOCK_FORCE_SVC_INTS+BLOCK_SVC_INTS+BLOCK_THREAD_IDLE+BLOCK_ENABLE_INTS)
  139. //
  140. // Flags for VWIN32_BlueScreenPopup
  141. //
  142. #define VBSP_CANCEL     0x00000001
  143. #define VBSP_DISPLAY_VXD_NAME   0x00000002
  144. //
  145. // Fault stack frame structure
  146. //
  147. typedef struct fsf_s {
  148.     WORD fsf_GS;
  149.     WORD fsf_FS;
  150.     WORD fsf_ES;
  151.     WORD fsf_DS;
  152.     DWORD fsf_EDI;
  153.     DWORD fsf_ESI;
  154.     DWORD fsf_EBP;
  155.     DWORD fsf_locked_ESP;
  156.     DWORD fsf_EBX;
  157.     DWORD fsf_EDX;
  158.     DWORD fsf_ECX;
  159.     DWORD fsf_EAX;
  160.     WORD fsf_num;       // Fault number
  161.     WORD fsf_prev_IP;   // IP of previous fault handler
  162.     WORD fsf_prev_CS;   // CS of previous fault handler
  163.     WORD fsf_ret_IP;    // DPMI fault handler frame follows
  164.     WORD fsf_ret_CS;
  165.     WORD fsf_err_code;
  166.     WORD fsf_faulting_IP;
  167.     WORD fsf_faulting_CS;
  168.     WORD fsf_flags;
  169.     WORD fsf_SP;
  170.     WORD fsf_SS;
  171. } FAULTSTACKFRAME;
  172. typedef FAULTSTACKFRAME *PFAULTSTACKFRAME;
  173. // ;EndInternal
  174. //
  175. // structure for VWIN32_SysErrorBox
  176. //
  177. typedef struct vseb_s {
  178.     DWORD vseb_resp;
  179.     WORD vseb_b3;
  180.     WORD vseb_b2;
  181.     WORD vseb_b1;
  182.     DWORD vseb_pszCaption;
  183.     DWORD vseb_pszText;
  184. } VSEB;
  185. typedef VSEB *PVSEB;
  186. #define SEB_ANSI    0x4000      // ANSI strings if set on vseb_b1
  187. #define SEB_TERMINATE   0x2000      // forces termination if button pressed
  188. // VWIN32_QueueKernelAPC flags
  189. #define KERNEL_APC_IGNORE_MC        0x00000001
  190. #define KERNEL_APC_STATIC       0x00000002
  191. #define KERNEL_APC_WAKE         0x00000004
  192. // for DeviceIOControl support
  193. // On a DeviceIOControl call vWin32 will pass following parameters to
  194. // the Vxd that is specified by hDevice. hDevice is obtained thru an
  195. // earlier call to hDevice = CreateFile("\.vxdname", ...);
  196. // ESI = DIOCParams STRUCT (defined below)
  197. typedef struct DIOCParams   {
  198.     DWORD   Internal1;      // ptr to client regs
  199.     DWORD   VMHandle;       // VM handle
  200.     DWORD   Internal2;      // DDB
  201.     DWORD   dwIoControlCode;
  202.     DWORD   lpvInBuffer;
  203.     DWORD   cbInBuffer;
  204.     DWORD   lpvOutBuffer;
  205.     DWORD   cbOutBuffer;
  206.     DWORD   lpcbBytesReturned;
  207.     DWORD   lpoOverlapped;
  208.     DWORD   hDevice;
  209.     DWORD   tagProcess;
  210. } DIOCPARAMETERS;
  211. typedef DIOCPARAMETERS *PDIOCPARAMETERS;
  212. // dwIoControlCode values for vwin32's DeviceIOControl Interface
  213. // all VWIN32_DIOC_DOS_ calls require lpvInBuffer abd lpvOutBuffer to be
  214. // struct * DIOCRegs
  215. #define VWIN32_DIOC_GETVERSION DIOC_GETVERSION
  216. #define VWIN32_DIOC_DOS_IOCTL       1
  217. #define VWIN32_DIOC_DOS_INT25       2
  218. #define VWIN32_DIOC_DOS_INT26       3
  219. #define VWIN32_DIOC_DOS_INT13       4
  220. #define VWIN32_DIOC_SIMCTRLC        5
  221. #define VWIN32_DIOC_DOS_DRIVEINFO   6
  222. #define VWIN32_DIOC_CLOSEHANDLE DIOC_CLOSEHANDLE
  223. // DIOCRegs
  224. // Structure with i386 registers for making DOS_IOCTLS
  225. // vwin32 DIOC handler interprets lpvInBuffer , lpvOutBuffer to be this struc.
  226. // and does the int 21
  227. // reg_flags is valid only for lpvOutBuffer->reg_Flags
  228. typedef struct DIOCRegs {
  229.     DWORD   reg_EBX;
  230.     DWORD   reg_EDX;
  231.     DWORD   reg_ECX;
  232.     DWORD   reg_EAX;
  233.     DWORD   reg_EDI;
  234.     DWORD   reg_ESI;
  235.     DWORD   reg_Flags;      
  236. } DIOC_REGISTERS;
  237. // if we are not included along with winbase.h
  238. #ifndef FILE_FLAG_OVERLAPPED
  239.   // OVERLAPPED structure for DeviceIOCtl VxDs
  240.   typedef struct _OVERLAPPED {
  241.           DWORD O_Internal;
  242.           DWORD O_InternalHigh;
  243.           DWORD O_Offset;
  244.           DWORD O_OffsetHigh;
  245.           HANDLE O_hEvent;
  246.   } OVERLAPPED;
  247. #endif
  248. //  Parameters for _VWIN32_OpenVxDHandle to validate the Win32 handle type.
  249. #define OPENVXD_TYPE_SEMAPHORE  0
  250. #define OPENVXD_TYPE_EVENT      1
  251. #define OPENVXD_TYPE_MUTEX      2
  252. #define OPENVXD_TYPE_ANY 3
  253.   
  254. // ;BeginInternal
  255. #define OPENVXD_TYPE_MAXIMUM    3
  256. // ;EndInternal
  257. //
  258. //  Object type table declaration for _VWIN32_AllocExternalHandle
  259. //
  260. /*XLATOFF*/
  261. #define R0OBJCALLBACK           __stdcall
  262. typedef VOID    (R0OBJCALLBACK *R0OBJFREE)(PVOID pR0ObjBody);
  263. typedef PVOID   (R0OBJCALLBACK *R0OBJDUP)(PVOID pR0ObjBody, DWORD hDestProc);
  264. /*XLATON*/
  265. /* ASM
  266. R0OBJFREE   TYPEDEF     DWORD
  267. R0OBJDUP    TYPEDEF     DWORD
  268. */
  269. typedef struct _R0OBJTYPETABLE {
  270.     DWORD       ott_dwSize;             //  sizeof(R0OBJTYPETABLE)
  271.     R0OBJFREE   ott_pfnFree;            //  called by Win32 CloseHandle
  272.     R0OBJDUP    ott_pfnDup;             //  called by Win32 DuplicateHandle
  273. } R0OBJTYPETABLE, *PR0OBJTYPETABLE;
  274. /* ASM
  275. R0OBJTYPETABLE  typedef _R0OBJTYPETABLE;
  276. */
  277. #define R0EHF_INHERIT   0x00000001      //  Handle is inheritable
  278. #define R0EHF_GLOBAL    0x00000002      //  Handle is valid in all contexts
  279. // ;BeginInternal
  280. #define R0EHF_ALL       (R0EHF_INHERIT | R0EHF_GLOBAL)
  281. // ;EndInternal
  282. // ;BeginInternal
  283. /* ASM
  284. FSF_CLEANUP_RETURN  EQU fsf_ret_IP - fsf_num
  285. FSF_CLEANUP_CHAIN   EQU fsf_prev_IP - fsf_num
  286. K32CURRENT typedef _K32CURRENT
  287. ;***LT  W32Fun - macro to make a function callable from Kernel32
  288. ;
  289. ;   This macro will create a stub of the format that the Ring0/Ring3
  290. ;   Win32 calling interface likes.
  291. ;   It plays around with the stack so that the arguments are set
  292. ;   up right and clean off right and it also sets the ring 3
  293. ;   registers to reflect the outcome of the operation.
  294. ;
  295. ;   This macro is taken from VMM's memory manager, file: mma.asm
  296. ;
  297. ;   ENTRY:  fun - function name
  298. ;       cargs - number of dword arguments it has
  299. ;       prefix - prefix for function
  300. ;   EXIT:   none
  301. ;
  302. ;   Note that when the function is called:
  303. ;       EBX is the VM handle
  304. ;       ESI points to client registers
  305. ;       EDI points to the return address
  306. ;   THESE REGISTERS MUST NOT BE TRASHED!
  307. ;
  308. W32Fun  MACRO   fun, cbargs, prefix
  309. BeginProc   VW32&fun, esp, W32SVC, public
  310.     ArgVar  pcrs,dword
  311.     ArgVar  hvm,dword
  312.     x = 0
  313.     REPT    cbargs
  314.         x = x + 1
  315.         ArgVar  arg&x,dword
  316.     ENDM
  317.     EnterProc
  318.     pop edi     ;Save and remove return address
  319.     pop esi     ;Save and remove client regs
  320.     pop ebx     ;Save and remove hvm
  321.     call    prefix&fun  ;Call function somewhere in VxD
  322.                 ;Note that this function may be a C function
  323.     mov [esi].Client_EAX,eax    ;Put return values into client regs
  324.     push    ebx     ;Put hvm back on stack
  325.     push    esi     ;Put client regs back on stack
  326.     push    edi     ;Restore return address
  327.     LeaveProc
  328.     Return
  329. EndProc VW32&fun
  330. ENDM
  331. */
  332. // ;EndInternal
  333. #endif  // _VWIN32_H_