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.

507 lines
13 KiB

  1. /*++
  2. Copyright (c) Microsoft Corporation. All rights reserved.
  3. Module Name:
  4. vdm.h
  5. Abstract:
  6. This include file defines the usermode visible portions of the vdm support
  7. Author:
  8. Revision History:
  9. --*/
  10. /* XLATOFF */
  11. #ifndef _VDM_H_
  12. #define _VDM_H_
  13. typedef enum _VdmServiceClass {
  14. VdmStartExecution, // is also defined in ntos\ke\i386\biosa.asm
  15. VdmQueueInterrupt,
  16. VdmDelayInterrupt,
  17. VdmInitialize,
  18. VdmFeatures,
  19. VdmSetInt21Handler,
  20. VdmQueryDir,
  21. VdmPrinterDirectIoOpen,
  22. VdmPrinterDirectIoClose,
  23. VdmPrinterInitialize,
  24. VdmSetLdtEntries,
  25. VdmSetProcessLdtInfo,
  26. VdmAdlibEmulation,
  27. VdmPMCliControl,
  28. VdmQueryVdmProcess
  29. } VDMSERVICECLASS, *PVDMSERVICECLASS;
  30. #if defined (_NTDEF_)
  31. NTSYSCALLAPI
  32. NTSTATUS
  33. NtVdmControl(
  34. IN VDMSERVICECLASS Service,
  35. IN OUT PVOID ServiceData
  36. );
  37. typedef struct _VdmQueryDirInfo {
  38. HANDLE FileHandle;
  39. PVOID FileInformation;
  40. ULONG Length;
  41. PUNICODE_STRING FileName;
  42. ULONG FileIndex;
  43. } VDMQUERYDIRINFO, *PVDMQUERYDIRINFO;
  44. //
  45. // Definitions for VdmQueryVdmProcessData
  46. //
  47. typedef struct _VDM_QUERY_VDM_PROCESS_DATA {
  48. HANDLE ProcessHandle;
  49. BOOLEAN IsVdmProcess;
  50. }VDM_QUERY_VDM_PROCESS_DATA, *PVDM_QUERY_VDM_PROCESS_DATA;
  51. #endif
  52. /*
  53. * The Vdm Virtual Ica
  54. * note: this structure definition is duplicated in
  55. * mvdm\softpc\base\inc\ica.c. KEEP IN SYNC
  56. *
  57. */
  58. typedef struct _VdmVirtualIca{
  59. LONG ica_count[8]; /* Count of Irq pending not in irr */
  60. LONG ica_int_line; /* Current pending interrupt */
  61. LONG ica_cpu_int; /* The state of the INT line to the CPU */
  62. USHORT ica_base; /* Interrupt base address for cpu */
  63. USHORT ica_hipri; /* Line no. of highest priority line */
  64. USHORT ica_mode; /* Various single-bit modes */
  65. UCHAR ica_master; /* 1 = Master; 0 = Slave */
  66. UCHAR ica_irr; /* Interrupt Request Register */
  67. UCHAR ica_isr; /* In Service Register */
  68. UCHAR ica_imr; /* Interrupt Mask Register */
  69. UCHAR ica_ssr; /* Slave Select Register */
  70. } VDMVIRTUALICA, *PVDMVIRTUALICA;
  71. //
  72. // copied from softpc\base\system\ica.c
  73. //
  74. #define ICA_AEOI 0x0020
  75. #define ICA_SMM 0x0200
  76. #define ICA_SFNM 0x0100
  77. #if defined(i386)
  78. #define VDM_PM_IRETBOPSEG 0x147
  79. #define VDM_PM_IRETBOPOFF 0x6
  80. #define VDM_PM_IRETBOPSIZE 8
  81. #else
  82. #define VDM_PM_IRETBOPSEG 0xd3
  83. #define VDM_PM_IRETBOPOFF 0x0
  84. #define VDM_PM_IRETBOPSIZE 4
  85. #endif
  86. #define VDM_RM_IRETBOPSIZE 4
  87. // VDM state which was earlier in vdmtib->flags has been moved to
  88. // dos arena at following fixed address.
  89. #ifdef _VDMNTOS_
  90. #define FIXED_NTVDMSTATE_LINEAR VdmFixedStateLinear
  91. #define FIXED_NTVDMSTATE_SIZE 4
  92. #else // _VDMNTOS_
  93. /* XLATON */
  94. #define FIXED_NTVDMSTATE_SEGMENT 0x70
  95. #define FIXED_NTVDMSTATE_OFFSET 0x14
  96. #define FIXED_NTVDMSTATE_LINEAR ((FIXED_NTVDMSTATE_SEGMENT << 4) + FIXED_NTVDMSTATE_OFFSET)
  97. #define FIXED_NTVDMSTATE_SIZE 4
  98. /* XLATOFF */
  99. #endif // _VDMNTOS_
  100. #if defined (i386)
  101. // defined on x86 only since on mips we must reference thru sas
  102. #define pNtVDMState ((PULONG)FIXED_NTVDMSTATE_LINEAR)
  103. #endif
  104. /* XLATON */
  105. //
  106. // Vdm State Flags
  107. //
  108. #define VDM_INT_HARDWARE 0x00000001
  109. #define VDM_INT_TIMER 0x00000002
  110. // defined as VDM_INTS_HOOKED_IN_PM in mvdm\inc\vint.h
  111. #define VDM_INT_HOOK_IN_PM 0x00000004
  112. // A bitMask which includes all interrupts
  113. #define VDM_INTERRUPT_PENDING (VDM_INT_HARDWARE | VDM_INT_TIMER)
  114. #define VDM_BREAK_EXCEPTIONS 0x00000008
  115. #define VDM_BREAK_DEBUGGER 0x00000010
  116. #define VDM_PROFILE 0x00000020
  117. #define VDM_ANALYZE_PROFILE 0x00000040
  118. #define VDM_TRACE_HISTORY 0x00000080
  119. #define VDM_32BIT_APP 0x00000100
  120. #define VDM_VIRTUAL_INTERRUPTS 0x00000200
  121. #define VDM_ON_MIPS 0x00000400
  122. #define VDM_EXEC 0x00000800
  123. #define VDM_RM 0x00001000
  124. #define VDM_USE_DBG_VDMEVENT 0x00004000
  125. #define VDM_WOWBLOCKED 0x00100000
  126. #define VDM_IDLEACTIVITY 0x00200000
  127. #define VDM_TIMECHANGE 0x00400000
  128. #define VDM_WOWHUNGAPP 0x00800000
  129. #define VDM_HANDSHAKE 0x01000000
  130. #define VDM_PE_MASK 0x80000000
  131. /* XLATOFF */
  132. #if DBG
  133. #define INITIAL_VDM_TIB_FLAGS (VDM_USE_DBG_VDMEVENT | VDM_BREAK_DEBUGGER | VDM_TRACE_HISTORY)
  134. #else
  135. #define INITIAL_VDM_TIB_FLAGS (VDM_USE_DBG_VDMEVENT | VDM_BREAK_DEBUGGER)
  136. #endif
  137. //
  138. // bits defined in Eflags
  139. //
  140. #define EFLAGS_TF_MASK 0x00000100
  141. #define EFLAGS_IF_MASK 0x00000200
  142. #define EFLAGS_PL_MASK 0x00003000
  143. #define EFLAGS_NT_MASK 0x00004000
  144. #define EFLAGS_RF_MASK 0x00010000
  145. #define EFLAGS_VM_MASK 0x00020000
  146. #define EFLAGS_AC_MASK 0x00040000
  147. //
  148. // If the size of the structure is changed, ke\i386\instemul.asm must
  149. // be modified too. If not, it will fail to build
  150. //
  151. #pragma pack(1)
  152. typedef struct _Vdm_InterruptHandler {
  153. USHORT CsSelector;
  154. USHORT Flags;
  155. ULONG Eip;
  156. } VDM_INTERRUPTHANDLER, *PVDM_INTERRUPTHANDLER;
  157. #pragma pack()
  158. typedef struct _Vdm_FaultHandler {
  159. USHORT CsSelector;
  160. USHORT SsSelector;
  161. ULONG Eip;
  162. ULONG Esp;
  163. ULONG Flags;
  164. } VDM_FAULTHANDLER, *PVDM_FAULTHANDLER;
  165. #pragma pack(1)
  166. typedef struct _VdmDpmiInfo { /* VDMTIB */
  167. USHORT LockCount;
  168. USHORT Flags;
  169. USHORT SsSelector;
  170. USHORT SaveSsSelector;
  171. ULONG SaveEsp;
  172. ULONG SaveEip;
  173. ULONG DosxIntIret;
  174. ULONG DosxIntIretD;
  175. ULONG DosxFaultIret;
  176. ULONG DosxFaultIretD;
  177. ULONG DosxRmReflector;
  178. } VDM_DPMIINFO, *PVDM_DPMIINFO;
  179. #pragma pack()
  180. //
  181. // Interrupt handler flags
  182. //
  183. #define VDM_INT_INT_GATE 0x00000001
  184. #define VDM_INT_TRAP_GATE 0x00000000
  185. #define VDM_INT_32 0x00000002
  186. #define VDM_INT_16 0x00000000
  187. #define VDM_INT_HOOKED 0x00000004
  188. #pragma pack(1)
  189. //
  190. // CAVEAT: This structure was designed to be exactly 64 bytes in size.
  191. // There is code that assumes that an array of these structures
  192. // will fit neatly into a 4096 byte page.
  193. //
  194. typedef struct _VdmTraceEntry {
  195. USHORT Type;
  196. USHORT wData;
  197. ULONG lData;
  198. ULONG Time;
  199. ULONG eax;
  200. ULONG ebx;
  201. ULONG ecx;
  202. ULONG edx;
  203. ULONG esi;
  204. ULONG edi;
  205. ULONG ebp;
  206. ULONG esp;
  207. ULONG eip;
  208. ULONG eflags;
  209. USHORT cs;
  210. USHORT ds;
  211. USHORT es;
  212. USHORT fs;
  213. USHORT gs;
  214. USHORT ss;
  215. } VDM_TRACEENTRY, *PVDM_TRACEENTRY;
  216. #pragma pack()
  217. #pragma pack(1)
  218. typedef struct _VdmTraceInfo {
  219. PVDM_TRACEENTRY pTraceTable;
  220. UCHAR Flags;
  221. UCHAR NumPages; // size of trace buffer in 4k pages
  222. USHORT CurrentEntry;
  223. LARGE_INTEGER TimeStamp;
  224. } VDM_TRACEINFO, *PVDM_TRACEINFO;
  225. #pragma pack()
  226. //
  227. // Definitions for flags in VDM_TRACEINFO
  228. //
  229. #define VDMTI_TIMER_MODE 3
  230. #define VDMTI_TIMER_TICK 1
  231. #define VDMTI_TIMER_PERFCTR 2
  232. #define VDMTI_TIMER_STAT 3
  233. #define VDMTI_TIMER_PENTIUM 3
  234. //
  235. // Kernel trace entry types
  236. //
  237. #define VDMTR_KERNEL_OP_PM 1
  238. #define VDMTR_KERNEL_OP_V86 2
  239. #define VDMTR_KERNEL_HW_INT 3
  240. #if defined(i386)
  241. typedef struct _VdmIcaUserData {
  242. PVOID pIcaLock; // rtl critical section
  243. PVDMVIRTUALICA pIcaMaster;
  244. PVDMVIRTUALICA pIcaSlave;
  245. PULONG pDelayIrq;
  246. PULONG pUndelayIrq;
  247. PULONG pDelayIret;
  248. PULONG pIretHooked;
  249. PULONG pAddrIretBopTable;
  250. PHANDLE phWowIdleEvent;
  251. PLARGE_INTEGER pIcaTimeout;
  252. PHANDLE phMainThreadSuspended;
  253. }VDMICAUSERDATA, *PVDMICAUSERDATA;
  254. typedef struct _VdmDelayIntsServiceData {
  255. ULONG Delay; /* Delay Time in usecs */
  256. ULONG DelayIrqLine; /* IRQ Number of ints delayed */
  257. HANDLE hThread; /* Thread Handle of CurrentMonitorTeb */
  258. }VDMDELAYINTSDATA, *PVDMDELAYINTSDATA;
  259. typedef struct _VDMSET_INT21_HANDLER_DATA {
  260. ULONG Selector;
  261. ULONG Offset;
  262. BOOLEAN Gate32;
  263. }VDMSET_INT21_HANDLER_DATA, *PVDMSET_INT21_HANDLER_DATA;
  264. typedef struct _VDMSET_LDT_ENTRIES_DATA {
  265. ULONG Selector0;
  266. ULONG Entry0Low;
  267. ULONG Entry0Hi;
  268. ULONG Selector1;
  269. ULONG Entry1Low;
  270. ULONG Entry1Hi;
  271. }VDMSET_LDT_ENTRIES_DATA, *PVDMSET_LDT_ENTRIES_DATA;
  272. typedef struct _VDMSET_PROCESS_LDT_INFO_DATA {
  273. PVOID LdtInformation;
  274. ULONG LdtInformationLength;
  275. }VDMSET_PROCESS_LDT_INFO_DATA, *PVDMSET_PROCESS_LDT_INFO_DATA;
  276. //
  277. // Define the action code of VDM_ADLIB_DATA
  278. //
  279. #define ADLIB_USER_EMULATION 0 // default action
  280. #define ADLIB_DIRECT_IO 1
  281. #define ADLIB_KERNEL_EMULATION 2
  282. typedef struct _VDM_ADLIB_DATA {
  283. USHORT VirtualPortStart;
  284. USHORT VirtualPortEnd;
  285. USHORT PhysicalPortStart;
  286. USHORT PhysicalPortEnd;
  287. USHORT Action;
  288. }VDM_ADLIB_DATA, *PVDM_ADLIB_DATA;
  289. //
  290. // Definitions for Protected Mode DOS apps cli control
  291. //
  292. #define PM_CLI_CONTROL_DISABLE 0
  293. #define PM_CLI_CONTROL_ENABLE 1
  294. #define PM_CLI_CONTROL_CHECK 2
  295. #define PM_CLI_CONTROL_SET 3
  296. #define PM_CLI_CONTROL_CLEAR 4
  297. typedef struct _VDM_PM_CLI_DATA {
  298. ULONG Control;
  299. }VDM_PM_CLI_DATA, *PVDM_PM_CLI_DATA;
  300. //
  301. // Definitions for VdmInitialize
  302. //
  303. typedef struct _VDM_INITIALIZE_DATA {
  304. PVOID TrapcHandler;
  305. PVDMICAUSERDATA IcaUserData;
  306. }VDM_INITIALIZE_DATA, *PVDM_INITIALIZE_DATA;
  307. #if defined (_NTDEF_)
  308. typedef enum _VdmEventClass {
  309. VdmIO,
  310. VdmStringIO,
  311. VdmMemAccess,
  312. VdmIntAck,
  313. VdmBop,
  314. VdmError,
  315. VdmIrq13,
  316. VdmHandShakeAck,
  317. VdmMaxEvent
  318. } VDMEVENTCLASS, *PVDMEVENTCLASS;
  319. // VdmPrinterInfo
  320. #define VDM_NUMBER_OF_LPT 3
  321. #define PRT_MODE_NO_SIMULATION 1
  322. #define PRT_MODE_SIMULATE_STATUS_PORT 2
  323. #define PRT_MODE_DIRECT_IO 3
  324. #define PRT_MODE_VDD_CONNECTED 4
  325. #define PRT_DATA_BUFFER_SIZE 16
  326. typedef struct _Vdm_Printer_Info {
  327. PUCHAR prt_State;
  328. PUCHAR prt_Control;
  329. PUCHAR prt_Status;
  330. PUCHAR prt_HostState;
  331. USHORT prt_PortAddr[VDM_NUMBER_OF_LPT];
  332. HANDLE prt_Handle[VDM_NUMBER_OF_LPT];
  333. UCHAR prt_Mode[VDM_NUMBER_OF_LPT];
  334. USHORT prt_BytesInBuffer[VDM_NUMBER_OF_LPT];
  335. UCHAR prt_Buffer[VDM_NUMBER_OF_LPT][PRT_DATA_BUFFER_SIZE];
  336. ULONG prt_Scratch;
  337. } VDM_PRINTER_INFO, *PVDM_PRINTER_INFO;
  338. typedef struct _VdmIoInfo {
  339. USHORT PortNumber;
  340. USHORT Size;
  341. BOOLEAN Read;
  342. } VDMIOINFO, *PVDMIOINFO;
  343. typedef struct _VdmFaultInfo{
  344. ULONG FaultAddr;
  345. ULONG RWMode;
  346. } VDMFAULTINFO, *PVDMFAULTINFO;
  347. typedef struct _VdmStringIoInfo {
  348. USHORT PortNumber;
  349. USHORT Size;
  350. BOOLEAN Rep;
  351. BOOLEAN Read;
  352. ULONG Count;
  353. ULONG Address;
  354. } VDMSTRINGIOINFO, *PVDMSTRINGIOINFO;
  355. typedef ULONG VDMBOPINFO;
  356. typedef NTSTATUS VDMERRORINFO;
  357. typedef ULONG VDMINTACKINFO;
  358. #define VDMINTACK_RAEOIMASK 0x0000ffff
  359. #define VDMINTACK_SLAVE 0x00010000
  360. #define VDMINTACK_AEOI 0x00020000
  361. // Family table definition for Dynamic Patch Module support
  362. typedef struct _tagFAMILY_TABLE {
  363. int numHookedAPIs; // number of hooked API's in this family
  364. PVOID hModShimEng; // hMod of shim engine
  365. PVOID hMod; // hMod of associated loaded dll.
  366. PVOID *DpmMisc; // ptr to DPM Module specific data
  367. PVOID *pDpmShmTbls; // array of ptrs to API family shim tables
  368. PVOID *pfn; // array of ptrs to hook functions
  369. } FAMILY_TABLE, *PFAMILY_TABLE;
  370. typedef struct _VdmEventInfo {
  371. ULONG Size;
  372. VDMEVENTCLASS Event;
  373. ULONG InstructionSize;
  374. union {
  375. VDMIOINFO IoInfo;
  376. VDMSTRINGIOINFO StringIoInfo;
  377. VDMBOPINFO BopNumber;
  378. VDMFAULTINFO FaultInfo;
  379. VDMERRORINFO ErrorStatus;
  380. VDMINTACKINFO IntAckInfo;
  381. };
  382. } VDMEVENTINFO, *PVDMEVENTINFO;
  383. // Sudeepb 12-Mar-1993
  384. // Scratch areas are used from VDMTib to get user space while
  385. // in kernel. This allows us to make Nt APIs (faster) from kernel
  386. // rather than Zw apis (slower). These are currently being used
  387. // for DOS read/write.
  388. typedef struct _Vdm_Tib {
  389. ULONG Size;
  390. PVDM_INTERRUPTHANDLER VdmInterruptTable;
  391. PVDM_FAULTHANDLER VdmFaultTable;
  392. CONTEXT MonitorContext;
  393. CONTEXT VdmContext;
  394. VDMEVENTINFO EventInfo;
  395. VDM_PRINTER_INFO PrinterInfo;
  396. ULONG TempArea1[2]; // Scratch area
  397. ULONG TempArea2[2]; // Scratch aArea
  398. VDM_DPMIINFO DpmiInfo;
  399. VDM_TRACEINFO TraceInfo;
  400. ULONG IntelMSW;
  401. LONG NumTasks;
  402. PFAMILY_TABLE *pDpmFamTbls; // array of ptrs to API family tables
  403. BOOLEAN ContinueExecution;
  404. } VDM_TIB, *PVDM_TIB;
  405. //
  406. // Feature flags returned by NtVdmControl(VdmFeatures...)
  407. //
  408. // System/processor supports fast emulation for IF instructions
  409. #define V86_VIRTUAL_INT_EXTENSIONS 0x00000001 // in v86 mode
  410. #define PM_VIRTUAL_INT_EXTENSIONS 0x00000002 // in protected mode (non-flat)
  411. #endif // if defined _NTDEF_
  412. #endif
  413. #endif