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

Windows Kernel

Development Platform:

Visual C++

  1. /*****************************************************************************
  2.  *
  3.  *   (C) Copyright MICROSOFT Corp., 1988-1990
  4.  *
  5.  *   Title: VMM.H - Include file for Virtual Machine Manager
  6.  *
  7.  *   Version: 1.00
  8.  *
  9.  *   Date:  05-May-1988
  10.  *
  11.  *   Author: RAL
  12.  *
  13.  *-----------------------------------------------------------------------------
  14.  *
  15.  *   Change log:
  16.  *
  17.  *   DATE    REV DESCRIPTION
  18.  *   ----------- --- -----------------------------------------------------------
  19.  *   05-May-1988 RAL Original
  20.  *   13-Nov-1991 PBS C version
  21.  *   17-Dec-1993     Adds Far East VxDs identifiers
  22.  */
  23. #ifndef _VMM_
  24. #define _VMM_
  25. /*
  26.  *  NON Windows/386 Virtual Device sources can include this file to get
  27.  *  some useful equates by declaring the symbol "Not_VxD" If this symbol
  28.  *  is defined, then everything that has to do with the specifics of the
  29.  *  32 bit environment for virtual devices is removed. Useful equates
  30.  *  include: device ID's, pushad structure, BeginDoc, EndDoc, BeginMsg,
  31.  *  EndMsg, page table equates, etc.
  32.  */
  33. #define FALSE     0     // False
  34. #define VMM_TRUE    (~FALSE) // The opposite of False!
  35. #define DEBLEVELRETAIL 0
  36. #define DEBLEVELNORMAL 1
  37. #define DEBLEVELMAX 2
  38. #ifndef DEBLEVEL
  39. #ifdef DEBUG
  40. #define DEBLEVEL DEBLEVELNORMAL
  41. #else
  42. #define DEBLEVEL DEBLEVELRETAIL
  43. #endif
  44. #endif
  45. #ifndef WIN31COMPAT
  46. #define WIN40SERVICES
  47. #define WIN403SERVICES /*OPK-3 Services*/
  48. #endif
  49. #ifndef WIN40COMPAT
  50. #define WIN41SERVICES
  51. #endif
  52. /* ASM
  53. ifdef MASM6
  54. ifndef NO_MASM6_OPTIONS
  55. ;
  56. ;   option switches necessary to build VMM/VxD sources with MASM 6
  57. ;
  58.     option oldmacros
  59. ifndef NEWSTRUCTS ; define NEWSTRUCTS for MASM6 struct semantics
  60.     option oldstructs
  61. endif
  62.     option noscoped
  63.     option segment:flat
  64.     option offset:flat
  65.     option proc:private
  66. endif
  67. endif
  68. ;
  69. ;   These null macros are recognized by a utility program that produces
  70. ;   documentation files.
  71. ;
  72. IFDEF MASM6
  73. BeginDoc MACRO
  74.      ENDM
  75. EndDoc MACRO
  76.        ENDM
  77. BeginMsg MACRO
  78.      ENDM
  79. EndMsg MACRO
  80.        ENDM
  81. ELSE
  82. BeginDoc EQU <>
  83. EndDoc EQU <>
  84. BeginMsg EQU <>
  85. EndMsg EQU <>
  86. ENDIF
  87. */
  88. /******************************************************************************
  89.  *
  90.  *     EQUATES FOR REQUIRED DEVICES
  91.  *
  92.  *   Device ID formulation note:
  93.  *
  94.  *  The high bit of the device ID is reserved for future use.
  95.  *  Microsoft reserves the device ID's 0-1FFh for standard devices.  If
  96.  *  an OEM VxD is a replacement for a standard VxD, then it must use the
  97.  *  standard VxD ID.
  98.  *
  99.  *  OEMS WHO WANT A VXD DEVICE ID ASSIGNED TO THEM,
  100.  *  PLEASE CONTACT MICROSOFT PRODUCT SUPPORT.  ID's are only required for
  101.  *  devices which provide services, V86 API's or PM API's.  Also, calling
  102.  *  services or API's by VxD name is now supported in version 4.0, so an
  103.  *  ID may not be necessary as long as a unique 8 character name is used.
  104.  *
  105.  *****************************************************************************/
  106. #define UNDEFINED_DEVICE_ID 0x00000
  107. #define VMM_DEVICE_ID     0x00001 /* Used for dynalink table */
  108. #define DEBUG_DEVICE_ID     0x00002
  109. #define VPICD_DEVICE_ID     0x00003
  110. #define VDMAD_DEVICE_ID     0x00004
  111. #define VTD_DEVICE_ID     0x00005
  112. #define V86MMGR_DEVICE_ID   0x00006
  113. #define PAGESWAP_DEVICE_ID  0x00007
  114. #define PARITY_DEVICE_ID    0x00008
  115. #define REBOOT_DEVICE_ID    0x00009
  116. #define VDD_DEVICE_ID     0x0000A
  117. #define VSD_DEVICE_ID     0x0000B
  118. #define VMD_DEVICE_ID     0x0000C
  119. #define VKD_DEVICE_ID     0x0000D
  120. #define VCD_DEVICE_ID     0x0000E
  121. #define VPD_DEVICE_ID     0x0000F
  122. #define BLOCKDEV_DEVICE_ID  0x00010
  123. #define VMCPD_DEVICE_ID     0x00011
  124. #define EBIOS_DEVICE_ID     0x00012
  125. #define BIOSXLAT_DEVICE_ID  0x00013
  126. #define VNETBIOS_DEVICE_ID  0x00014
  127. #define DOSMGR_DEVICE_ID    0x00015
  128. #define WINLOAD_DEVICE_ID   0x00016
  129. #define SHELL_DEVICE_ID     0x00017
  130. #define VMPOLL_DEVICE_ID    0x00018
  131. #define VPROD_DEVICE_ID     0x00019
  132. #define DOSNET_DEVICE_ID    0x0001A
  133. #define VFD_DEVICE_ID     0x0001B
  134. #define VDD2_DEVICE_ID     0x0001C /* Secondary display adapter */
  135. #define WINDEBUG_DEVICE_ID  0x0001D
  136. #define TSRLOAD_DEVICE_ID   0x0001E /* TSR instance utility ID */
  137. #define BIOSHOOK_DEVICE_ID  0x0001F /* Bios interrupt hooker VxD */
  138. #define INT13_DEVICE_ID     0x00020
  139. #define PAGEFILE_DEVICE_ID  0x00021 /* Paging File device */
  140. #define SCSI_DEVICE_ID     0x00022 /* SCSI device */
  141. #define MCA_POS_DEVICE_ID   0x00023 /* MCA_POS device */
  142. #define SCSIFD_DEVICE_ID    0x00024 /* SCSI FastDisk device */
  143. #define VPEND_DEVICE_ID     0x00025 /* Pen device */
  144. #define APM_DEVICE_ID     0x00026 /* Power Management device */
  145. #define VPOWERD_DEVICE_ID   APM_DEVICE_ID   /* We overload APM since we replace it */
  146. #define VXDLDR_DEVICE_ID    0x00027 /* VxD Loader device */
  147. #define NDIS_DEVICE_ID     0x00028 /* NDIS wrapper */
  148. #define BIOS_EXT_DEVICE_ID   0x00029 /* Fix Broken BIOS device */
  149. #define VWIN32_DEVICE_ID 0x0002A /* for new WIN32-VxD */
  150. #define VCOMM_DEVICE_ID  0x0002B /* New COMM device driver */
  151. #define SPOOLER_DEVICE_ID 0x0002C /* Local Spooler */
  152. #define WIN32S_DEVICE_ID    0x0002D /* Win32S on Win 3.1 driver */
  153. #define DEBUGCMD_DEVICE_ID 0x0002E /* Debug command extensions */
  154. /* #define RESERVED_DEVICE_ID 0x0002F /* Not currently in use */
  155. /* #define ATI_HELPER_DEVICE_ID    0x00030 /* grabbed by ATI */
  156. /* 31-32 USED BY WFW NET COMPONENTS */
  157. /* #define VNB_DEVICE_ID    0x00031 /* Netbeui of snowball */
  158. /* #define SERVER_DEVICE_ID    0x00032 /* Server of snowball */
  159. #define CONFIGMG_DEVICE_ID  0x00033 /* Configuration manager (Plug&Play) */
  160. #define DWCFGMG_DEVICE_ID   0x00034 /* Configuration manager for win31 and DOS */
  161. #define SCSIPORT_DEVICE_ID  0x00035 /* Dragon miniport loader/driver */
  162. #define VFBACKUP_DEVICE_ID  0x00036 /* allows backup apps to work with NEC */
  163. #define ENABLE_DEVICE_ID    0x00037 /* for access VxD */
  164. #define VCOND_DEVICE_ID     0x00038 /* Virtual Console Device - check vcond.inc */
  165. /* 39 used by WFW VFat Helper device */
  166. /* 3A used by WFW E-FAX */
  167. /* #define EFAX_DEVICE_ID   0x0003A /* EFAX VxD ID */
  168. /* 3B used by MS-DOS 6.1 for the DblSpace VxD which has APIs */
  169. /* #define DSVXD_DEVICE_ID  0x0003B /* Dbl Space VxD ID */
  170. #define ISAPNP_DEVICE_ID    0x0003C /* ISA P&P Enumerator */
  171. #define BIOS_DEVICE_ID     0x0003D /* BIOS P&P Enumerator */
  172. /* #define WINSOCK_DEVICE_ID    0x0003E  /* WinSockets */
  173. /* #define WSIPX_DEVICE_ID     0x0003F /* WinSockets for IPX */
  174. #define IFSMgr_Device_ID    0x00040 /* Installable File System Manager */
  175. #define VCDFSD_DEVICE_ID    0x00041 /* Static CDFS ID */
  176. #define MRCI2_DEVICE_ID     0x00042 /* DrvSpace compression engine */
  177. #define PCI_DEVICE_ID     0x00043 /* PCI P&P Enumerator */
  178. #define PELOADER_DEVICE_ID  0x00044 /* PE Image Loader */
  179. #define EISA_DEVICE_ID     0x00045 /* EISA P&P Enumerator */
  180. #define DRAGCLI_DEVICE_ID   0x00046 /* Dragon network client */
  181. #define DRAGSRV_DEVICE_ID   0x00047 /* Dragon network server */
  182. #define PERF_DEVICE_ID     0x00048 /* Config/stat info */
  183. #define AWREDIR_DEVICE_ID   0x00049 /* AtWork Network FSD */
  184. #define DDS_DEVICE_ID     0x0004A /* Device driver services */
  185. #define NTKERN_DEVICE_ID    0x0004B /* NT kernel device id */
  186. #define VDOSKEYD_DEVICE_ID  0x0004B /* DOSKEY device id */
  187. /*
  188.  *   Far East DOS support VxD ID
  189.  */
  190. #define ETEN_Device_ID     0x00060 /* ETEN DOS (Taiwan) driver */
  191. #define CHBIOS_Device_ID    0x00061 /* CHBIOS DOS (Korean) driver */
  192. #define VMSGD_Device_ID    0x00062 /* DBCS Message Mode driver */
  193. #define VPPID_Device_ID     0x00063 /* PC-98 System Control PPI */
  194. #define VIME_Device_ID     0x00064 /* Virtual DOS IME */
  195. #define VHBIOSD_Device_ID   0x00065 /* HBIOS (Korean) for HWin31 driver */
  196. #define BASEID_FOR_NAMEBASEDVXD        0xf000 /* Name based VxD IDs start here */
  197. #define BASEID_FOR_NAMEBASEDVXD_MASK   0x0fff /* Mask to get the real vxd id */
  198. /*
  199.  *   Initialization order equates.  Devices are initialized in order from
  200.  *   LOWEST to HIGHEST. If 2 or more devices have the same initialization
  201.  *   order value, then they are initialized in order of occurance, so a
  202.  *   specific order is not guaranteed. Holes have been left to allow maximum
  203.  *   flexibility in ordering devices.
  204.  */
  205. #define VMM_INIT_ORDER     0x000000000
  206. #define DEBUG_INIT_ORDER    0x000000000 /* normally using 0 is bad */
  207. #define DEBUGCMD_INIT_ORDER 0x000000000 /* but debug must be first */
  208. #define PERF_INIT_ORDER     0x000900000
  209. #define APM_INIT_ORDER 0x001000000
  210. #define VPOWERD_INIT_ORDER  APM_INIT_ORDER  /* We overload APM since we replace it */
  211. #define BIOSHOOK_INIT_ORDER 0x006000000
  212. #define VPROD_INIT_ORDER    0x008000000
  213. #define VPICD_INIT_ORDER    0x00C000000
  214. #define VTD_INIT_ORDER     0x014000000
  215. #define VWIN32_INIT_ORDER   0x014100000
  216. #define NTKERN_INIT_ORDER   0x015000000 /* Must be before VxDLdr (so that it is ready for devnodes) */
  217. #define VXDLDR_INIT_ORDER   0x016000000
  218. #define ENUMERATOR_INIT_ORDER 0x016800000 /* Should be before IOS */
  219. #define ISAPNP_INIT_ORDER   ENUMERATOR_INIT_ORDER
  220. #define EISA_INIT_ORDER     ENUMERATOR_INIT_ORDER
  221. #define PCI_INIT_ORDER     ENUMERATOR_INIT_ORDER
  222. #define BIOS_INIT_ORDER     ENUMERATOR_INIT_ORDER+1 /* To simplify reenumeration */
  223. #define CONFIGMG_INIT_ORDER ENUMERATOR_INIT_ORDER+0xFFFF    /* After all enumerators */
  224. #define VCDFSD_INIT_ORDER   0x016F00000
  225. #define IOS_INIT_ORDER     0x017000000
  226. #define PAGEFILE_INIT_ORDER 0x018000000
  227. #define PAGESWAP_INIT_ORDER 0x01C000000
  228. #define PARITY_INIT_ORDER   0x020000000
  229. #define REBOOT_INIT_ORDER   0x024000000
  230. #define EBIOS_INIT_ORDER    0x026000000
  231. #define VDD_INIT_ORDER     0x028000000
  232. #define VSD_INIT_ORDER     0x02C000000
  233. #define VCD_INIT_ORDER     0x030000000
  234. #define COMMDRVR_INIT_ORDER (VCD_INIT_ORDER - 1)
  235. #define PRTCL_INIT_ORDER    (COMMDRVR_INIT_ORDER - 2)
  236. #define MODEM_INIT_ORDER    (COMMDRVR_INIT_ORDER - 3)
  237. #define PORT_INIT_ORDER     (COMMDRVR_INIT_ORDER - 4)
  238. #define VMD_INIT_ORDER     0x034000000
  239. #define VKD_INIT_ORDER     0x038000000
  240. #define VPD_INIT_ORDER     0x03C000000
  241. #define BLOCKDEV_INIT_ORDER 0x040000000
  242. #define MCA_POS_INIT_ORDER  0x041000000
  243. #define SCSIFD_INIT_ORDER   0x041400000
  244. #define SCSIMASTER_INIT_ORDER 0x041800000
  245. #define INT13_INIT_ORDER    0x042000000
  246. #define VMCPD_INIT_ORDER    0x048000000
  247. #define BIOSXLAT_INIT_ORDER 0x050000000
  248. #define VNETBIOS_INIT_ORDER 0x054000000
  249. #define DOSMGR_INIT_ORDER   0x058000000
  250. #define DOSNET_INIT_ORDER   0x05C000000
  251. #define WINLOAD_INIT_ORDER  0x060000000
  252. #define VMPOLL_INIT_ORDER   0x064000000
  253. #define UNDEFINED_INIT_ORDER 0x080000000
  254. #define VCOND_INIT_ORDER    UNDEFINED_INIT_ORDER
  255. #define WINDEBUG_INIT_ORDER 0x081000000
  256. #define VDMAD_INIT_ORDER    0x090000000
  257. #define V86MMGR_INIT_ORDER  0x0A0000000
  258. #define IFSMgr_Init_Order   0x10000 + V86MMGR_Init_Order
  259. #define FSD_Init_Order     0x00100 + IFSMgr_Init_Order
  260. #define VFD_INIT_ORDER     0x50000 + IFSMgr_Init_Order
  261. /* Device that must touch memory in 1st Mb at crit init (after V86mmgr) */
  262. #define UNDEF_TOUCH_MEM_INIT_ORDER  0x0A8000000
  263. #define SHELL_INIT_ORDER    0x0B0000000
  264. /* ASM
  265. ;******************************************************************************
  266. ;
  267. ;   Macro to cause a delay in between I/O accesses to the same device.
  268. ;
  269. ;------------------------------------------------------------------------------
  270. IO_Delay    macro
  271. jmp $+2
  272. ENDM
  273. */
  274. #define VXD_FAILURE 0
  275. #define VXD_SUCCESS 1
  276. typedef ULONG HVM;     /* VM handle typedef */
  277. /*
  278.  *  Registers as they appear on the stack after a PUSHAD.
  279.  */
  280. struct Pushad_Struc {
  281.     ULONG Pushad_EDI; /* Client's EDI */
  282.     ULONG Pushad_ESI; /* Client's ESI */
  283.     ULONG Pushad_EBP; /* Client's EBP */
  284.     ULONG Pushad_ESP; /* ESP before pushad */
  285.     ULONG Pushad_EBX; /* Client's EBX */
  286.     ULONG Pushad_EDX; /* Client's EDX */
  287.     ULONG Pushad_ECX; /* Client's ECX */
  288.     ULONG Pushad_EAX; /* Client's EAX */
  289. };
  290. /* XLATOFF */
  291. #ifdef RC_INVOKED
  292. #define NOBASEDEFS
  293. #endif
  294. #ifndef NOBASEDEFS
  295. #pragma warning (disable:4209) // turn off redefinition warning
  296. typedef unsigned char UCHAR;
  297. typedef unsigned short USHORT;
  298. #pragma warning (default:4209) // turn off redefinition warning
  299. #endif
  300. #define GetVxDServiceOrdinal(service) __##service
  301. #define Begin_Service_Table(device, seg) 
  302.     enum device##_SERVICES { 
  303.     device##_dummy = (device##_DEVICE_ID << 16) - 1,
  304. #define Declare_Service(service, local) 
  305.     GetVxDServiceOrdinal(service),
  306. #define Declare_SCService(service, args, local) 
  307.     GetVxDServiceOrdinal(service),
  308. #define End_Service_Table(device, seg) 
  309.     Num_##device##_Services};
  310. #define VXDINLINE static __inline
  311. /* XLATON */
  312. #ifndef Not_VxD
  313. /* XLATOFF */
  314. #define VxD_LOCKED_CODE_SEG code_seg("_LTEXT", "LCODE")
  315. #define VxD_LOCKED_DATA_SEG data_seg("_LDATA", "LCODE")
  316. #define VxD_INIT_CODE_SEG   code_seg("_ITEXT", "ICODE")
  317. #define VxD_INIT_DATA_SEG   data_seg("_IDATA", "ICODE")
  318. #define VxD_ICODE_SEG     code_seg("_ITEXT", "ICODE")
  319. #define VxD_IDATA_SEG     data_seg("_IDATA", "ICODE")
  320. #define VxD_PAGEABLE_CODE_SEG code_seg("_PTEXT", "PCODE")
  321. #define VxD_PAGEABLE_DATA_SEG data_seg("_PDATA", "PDATA")
  322. #define VxD_STATIC_CODE_SEG code_seg("_STEXT", "SCODE")
  323. #define VxD_STATIC_DATA_SEG data_seg("_SDATA", "SCODE")
  324. #define VxD_DEBUG_ONLY_CODE_SEG code_seg("_DBOCODE", "DBOCODE")
  325. #define VxD_DEBUG_ONLY_DATA_SEG data_seg("_DBODATA", "DBOCODE")
  326. #define VxD_SYSEXIT_CODE_SEG code_seg("SYSEXIT", "SYSEXITCODE")
  327. #define VxD_INT21_CODE_SEG  code_seg("INT21", "INT21CODE")
  328. #define VxD_RARE_CODE_SEG   code_seg("RARE", "RARECODE")
  329. #define VxD_W16_CODE_SEG    code_seg("W16", "W16CODE")
  330. #define VxD_W32_CODE_SEG    code_seg("W32", "W32CODE")
  331. #define VxD_VMCREATE_CODE_SEG code_seg("VMCREATE", "VMCREATECODE")
  332. #define VxD_VMDESTROY_CODE_SEG code_seg("VMDESTROY", "VMDESTROYCODE")
  333. #define VxD_THCREATE_CODE_SEG code_seg("THCREATE", "THCREATECODE")
  334. #define VxD_THDESTROY_CODE_SEG code_seg("THDESTROY", "THDESTROYCODE")
  335. #define VxD_VMSUSPEND_CODE_SEG code_seg("VMSUSPEND", "VMSUSPENDCODE")
  336. #define VxD_VMRESUME_CODE_SEG code_seg("VMRESUME", "VMRESUMECODE")
  337. #define VxD_PNP_CODE_SEG    code_seg("PNP", "PNPCODE")
  338. #define VxD_DOSVM_CODE_SEG  code_seg("DOSVM", "DOSVMCODE")
  339. #define VxD_LOCKABLE_CODE_SEG code_seg("LOCKABLE", "LOCKABLECODE")
  340. /* XLATON */
  341. /* ASM
  342. ??_CUR_CODE_SEG = 0
  343. ??_LCODE    = 1
  344. ??_ICODE    = 2
  345. ??_PCODE    = 3
  346. ??_SCODE    = 4
  347. ??_DBOCODE  = 5
  348. ??_16ICODE  = 6
  349. ??_RCODE    = 7
  350. ??_LOCKABLECODE =   8
  351. ?_LCODE     equ <(??_CUR_CODE_SEG MOD 16) - ??_LCODE>
  352. ?_ICODE     equ <(??_CUR_CODE_SEG MOD 16) - ??_ICODE>
  353. ?_PCODE     equ <(??_CUR_CODE_SEG MOD 16) - ??_PCODE>
  354. ?_SCODE     equ <(??_CUR_CODE_SEG MOD 16) - ??_SCODE>
  355. ?_DBOCODE   equ <(??_CUR_CODE_SEG MOD 16) - ??_DBOCODE>
  356. ?_16ICODE   equ <(??_CUR_CODE_SEG MOD 16) - ??_16ICODE>
  357. ?_RCODE     equ <(??_CUR_CODE_SEG MOD 16) - ??_RCODE>
  358. ?_LOCKABLECODE equ <(??_CUR_CODE_SEG MOD 16) - ??_LOCKABLECODE>
  359. ifndef NO_SEGMENTS
  360. ;
  361. ;  SEGMENT definitions and order
  362. ;
  363. IFDEF MASM6
  364. _FLAT EQU FLAT
  365. ELSE
  366. _FLAT EQU USE32
  367. ENDIF
  368. ;*  32 bit locked code
  369. _LTEXT     SEGMENT DWORD PUBLIC _FLAT 'LCODE'
  370. _LTEXT     ENDS
  371. _TEXT     SEGMENT DWORD PUBLIC _FLAT 'LCODE'
  372. _TEXT     ENDS
  373. ;*  32 bit pageable code
  374. _PTEXT     SEGMENT DWORD PUBLIC _FLAT 'PCODE'
  375. _PTEXT     ENDS
  376. MakeCodeSeg MACRO seglist, classname, grpname, iseg
  377.     IRP segname,<seglist>   ;; For each name in the list
  378. IFNB <classname>
  379.     segname SEGMENT DWORD PUBLIC _FLAT "&classname&CODE"
  380. ELSE
  381.     segname SEGMENT DWORD PUBLIC _FLAT "&segname&CODE"
  382. ENDIF
  383. IFB <iseg>
  384. VxD_&&segname&&_CODE_SEG MACRO
  385. segname  SEGMENT
  386. ??_CUR_CODE_SEG = ??_CUR_CODE_SEG SHL 4 + ??_PCODE
  387.    ASSUME   cs:FLAT, ds:FLAT, es:FLAT, ss:FLAT
  388. ENDM
  389. ELSE
  390. VxD_&&segname&&_CODE_SEG MACRO
  391. segname  SEGMENT
  392. ??_CUR_CODE_SEG = ??_CUR_CODE_SEG SHL 4 + iseg
  393.    ASSUME   cs:FLAT, ds:FLAT, es:FLAT, ss:FLAT
  394. ENDM
  395. ENDIF
  396. VxD_&&segname&&_CODE_ENDS MACRO
  397. ??_CUR_CODE_SEG = ??_CUR_CODE_SEG SHR 4
  398. segname ENDS
  399. ENDM
  400. segname     ENDS
  401. IFNDEF BLD_COFF
  402. IFNB <grpname>
  403.     _&grpname GROUP segname
  404. ELSE
  405.     _&&segname GROUP segname
  406. ENDIF
  407. ENDIF
  408.     ENDM ;; End for each segment
  409.     ENDM
  410. MakeCodeSeg <LOCKABLE_BEGIN, LOCKABLE, LOCKABLE_END>, 
  411.     LOCKABLE, LOCKABLE, ??_LOCKABLECODE
  412. MakeCodeSeg INT21
  413. MakeCodeSeg SYSEXIT
  414. MakeCodeSeg RARE
  415. MakeCodeSeg W16
  416. MakeCodeSeg W32
  417. MakeCodeSeg VMCREATE
  418. MakeCodeSeg VMDESTROY
  419. MakeCodeSeg THCREATE
  420. MakeCodeSeg THDESTROY
  421. MakeCodeSeg VMSUSPEND
  422. MakeCodeSeg VMRESUME
  423. MakeCodeSeg PNP
  424. MakeCodeSeg DOSVM
  425. ;*** DefLockableCodeBegin - define beginning of lockable code
  426. ;
  427. ;   Defines a label with the given name to mark the beginning
  428. ;   of the lockable code area for this VxD.  In the debug version,
  429. ;   also defines a DWORD containing DFS_TEST_BLOCK so that
  430. ;   procedures in the lockable code segment defined with
  431. ;   BeginProc may call _Debug_Flags_Service with flags appropriate
  432. ;   to the code's current state.
  433. DefLockableCodeBegin MACRO name, private
  434. VxD_LOCKABLE_BEGIN_CODE_SEG
  435. IFB <private>
  436.     PUBLIC  name
  437. ENDIF
  438. name LABEL NEAR
  439. VxD_LOCKABLE_BEGIN_CODE_ENDS
  440. ifndef WIN31COMPAT
  441. if DEBLEVEL
  442. VxD_LOCKED_DATA_SEG
  443.     PUBLIC name&_Debug_Flags
  444. name&_Debug_Flags DD DFS_TEST_BLOCK
  445. VxD_LOCKED_DATA_ENDS
  446. ??_debug_flags equ <name&_Debug_Flags>
  447. endif
  448. endif
  449.     ENDM
  450. ;*** DefLockableCodeEnd - define end of lockable code
  451. ;
  452. ;   Defines a label with the given name to mark the end
  453. ;   of the lockable code area for this VxD.  By subtracting
  454. ;   the offset of the beginning label from the offset of
  455. ;   the ending label, the VxD may determine how many bytes
  456. ;   of memory to lock or unlock.
  457. DefLockableCodeEnd MACRO name, private
  458. VxD_LOCKABLE_END_CODE_SEG
  459. IFB <private>
  460.     PUBLIC  name
  461. ENDIF
  462. name LABEL NEAR
  463. VxD_LOCKABLE_END_CODE_ENDS
  464.     ENDM
  465. ;*** CodeLockFlags - declare locked code debug flags
  466. ;
  467. ;   This macro declares the locked code debug flags.
  468. CodeLockFlags MACRO name
  469. ifndef WIN31COMPAT
  470. if DEBLEVEL
  471.     ifndef name&_Debug_Flags
  472.     VxD_LOCKED_DATA_SEG
  473. extrn name&_Debug_Flags:dword
  474.     VxD_LOCKED_DATA_ENDS
  475.     ??_debug_flags equ <name&_Debug_Flags>
  476.     endif
  477. endif
  478. endif
  479.     ENDM
  480. ;*** MarkCodeLocked - signify that lockable code is locked
  481. ;
  482. ;   This macro clears DFS_TEST_BLOCK in the debug flags
  483. ;   DWORD.
  484. MarkCodeLocked MACRO
  485. ifndef WIN31COMPAT
  486. if DEBLEVEL
  487. ifdef ??_debug_flags
  488.     pushfd
  489.     and ??_debug_flags,NOT DFS_TEST_BLOCK
  490.     popfd
  491. endif
  492. endif
  493. endif
  494.     ENDM
  495. ;*** MarkCodeUnlocked - signify that lockable code is unlocked
  496. ;
  497. ;   This macro sets DFS_TEST_BLOCK in the debug flags
  498. ;   DWORD.
  499. MarkCodeUnlocked MACRO
  500. ifndef WIN31COMPAT
  501. if DEBLEVEL
  502. ifdef ??_debug_flags
  503.     pushfd
  504.     or ??_debug_flags,DFS_TEST_BLOCK
  505.     popfd
  506. endif
  507. endif
  508. endif
  509.     ENDM
  510. ;*  32 bit initialization code
  511. _ITEXT     SEGMENT DWORD PUBLIC _FLAT 'ICODE'
  512. _ITEXT     ENDS
  513. ;*  32 bit locked data
  514. _LDATA     SEGMENT DWORD PUBLIC _FLAT 'LCODE'
  515. _LDATA     ENDS
  516. _DATA     SEGMENT DWORD PUBLIC _FLAT 'LCODE'
  517. _DATA     ENDS
  518. ;*  32 bit pageable data
  519. _PDATA     SEGMENT DWORD PUBLIC _FLAT 'PDATA'
  520. _PDATA     ENDS
  521. ;*  32 Bit initialization data
  522. _IDATA     SEGMENT DWORD PUBLIC _FLAT 'ICODE'
  523. _IDATA     ENDS
  524. ;*  Created by C8
  525. _BSS     SEGMENT DWORD PUBLIC _FLAT 'LCODE'
  526. _BSS     ENDS
  527. CONST     SEGMENT DWORD PUBLIC _FLAT 'LCODE'
  528. CONST     ENDS
  529. _TLS     SEGMENT DWORD PUBLIC _FLAT 'LCODE'
  530. _TLS     ENDS
  531. ;*  32 Bit static code for DL-VxDs
  532. _STEXT     SEGMENT DWORD PUBLIC _FLAT 'SCODE'
  533. _STEXT     ENDS
  534. ;*  32 Bit static data for DL-VxDs
  535. _SDATA     SEGMENT DWORD PUBLIC _FLAT 'SCODE'
  536. _SDATA     ENDS
  537. ;* dummy segment for IsDebugOnlyLoaded
  538. _DBOSTART   SEGMENT DWORD PUBLIC _FLAT 'DBOCODE'
  539. _DBOSTART   ENDS
  540. ;* 32 bit debug only code; loaded only if debugger is present
  541. _DBOCODE    SEGMENT DWORD PUBLIC _FLAT 'DBOCODE'
  542. _DBOCODE    ENDS
  543. ;* 32 bit debug only data; loaded only if debugger is present
  544. _DBODATA    SEGMENT DWORD PUBLIC _FLAT 'DBOCODE'
  545. _DBODATA    ENDS
  546. if DEBLEVEL
  547. ;*  Start of 32 bit path coverage data
  548. _PATHSTART  SEGMENT DWORD PUBLIC  _FLAT 'LCODE'
  549. _PATHSTART  ENDS
  550. ;*  32 bit path coverage data
  551. _PATHDATA   SEGMENT DWORD PUBLIC  _FLAT 'LCODE'
  552. _PATHDATA   ENDS
  553. ;*  End of 32 bit path coverage data
  554. _PATHEND    SEGMENT DWORD PUBLIC  _FLAT 'LCODE'
  555. _PATHEND    ENDS
  556. endif
  557. ;*  16 bit code/data that is put into IGROUP automaticly
  558. _16ICODE    SEGMENT WORD USE16 PUBLIC '16ICODE'
  559. _16ICODE    ENDS
  560. ;*  Real Mode initialization code/data for devices
  561. _RCODE     SEGMENT WORD USE16 PUBLIC 'RCODE'
  562. _RCODE     ENDS
  563. IFNDEF BLD_COFF
  564. _LGROUP   GROUP _LTEXT, _TEXT, _LDATA, _DATA, _BSS, CONST, _TLS
  565. _IGROUP   GROUP _ITEXT, _IDATA
  566. _SGROUP   GROUP _STEXT, _SDATA
  567. _DBOGROUP GROUP _DBOSTART, _DBOCODE, _DBODATA
  568. IF DEBLEVEL
  569. _PGROUP   GROUP _PATHSTART, _PATHDATA, _PATHEND
  570. ENDIF
  571. ENDIF
  572. endif ; NO_SEGMENTS
  573.     ASSUME CS:FLAT, DS:FLAT, ES:FLAT, SS:FLAT
  574. OFFSET32 EQU <OFFSET FLAT:>
  575. BeginDoc
  576. ;==============================================================================
  577. ; The following macros are used in defining the routines
  578. ;   in a VxD which are going to be registered with VMM as callable entry
  579. ;   points. Once registered, the entry points can be called by any other
  580. ;   devices via the "VxDCall" macro, defined below. In the comments below,
  581. ;   replace "VxD" with the appropriate device name.
  582. ;
  583. ;*******
  584. ;   In the VxD.INC file, put the following lines, replacing <function_name>
  585. ;   with an appropriate name describing the function of the routine.
  586. ;
  587. ;   Begin_Service_Table VxD[,<segname>]
  588. ;   VxD_Service <function_name>[,<local segname>]
  589. ;   VxD_Service <function_name>[,<local segname>]
  590. ; . . .
  591. ;   VxD_Service <function_name>[,<local segname>]
  592. ;   End_Service_Table VxD[,<segname>]
  593. ;
  594. ;   Note that <segname> is an optional argument and, if specified, the
  595. ;   table is put in the segment defined by the macro "yyy_Data_Seg",
  596. ;   where yyy=segname. Otherwise the segment is defined by the
  597. ;   "VxD_Data_Seg" macro, defined below.
  598. ;   Note that <local segname> is an optional argument and, if specified,
  599. ;   the procedure's segment is defined by the macro "zzz_Code_Seg",
  600. ;   where zzz=segname. Otherwise the segment is defined by the
  601. ;   "VxD_Code_Seg" macro, defined below.
  602. ;
  603. ;*******
  604. ; One VxD module should have the following in order to define the entry points:
  605. ;Create_VxD_Service_Table = 1 ; Only in module where table is
  606. ;   INCLUDE VxD.INC  ; Include the table definition
  607. ;
  608. ;*******
  609. ; All modules that want to call the services defined in the table should include
  610. ;   VxD.INC, but not define the label "Create_VxD_Service_Table". This
  611. ;   will define the service names to be used with the VxDCall macro.
  612. ;
  613. EndDoc
  614. Begin_Service_Table MACRO Device_Name, Def_Segment
  615. IFDEF Device_Name&_Name_Based
  616.  IFNDEF @@NextInternalID
  617.     @@NextInternalID = 0
  618.  ENDIF
  619.  @@NextInternalID = (@@NextInternalID + 1)
  620.  Device_Name&_Internal_ID   = @@NextInternalID + BASEID_FOR_NAMEBASEDVXD
  621.  DefineVxDName Device_Name, %Device_Name&_Internal_ID
  622. ENDIF
  623. IFB <Def_Segment>
  624.     BST2 Device_Name, VxD
  625. ELSE
  626.     BST2 Device_Name, Def_Segment
  627. ENDIF
  628.     ENDM
  629. DefineVxDName MACRO Device_Name, InternalID
  630.  @@VxDName&InternalID EQU   <___&Device_Name&STable>
  631. ENDM
  632. BST2 MACRO Device_Name, Def_Segment
  633. Num_&Device_Name&_Services = 0
  634. IFDEF Create_&Device_Name&_Service_Table
  635. Def_Segment&_LOCKED_DATA_SEG
  636. Device_Name&_Service_Table LABEL DWORD
  637. Device_Name&_Service MACRO Procedure, Local_Seg, Condition, StdCallBytes, fastcall
  638. LOCAL $$&Procedure, extrnproc, tableproc
  639.   extrnproc MACRO
  640.     IFNB <fastcall>
  641.       IFB <StdCallBytes>
  642. .err ;StdCallBytes required
  643.       ENDIF
  644.       EXTRN @&&Procedure&&@&&StdCallBytes:NEAR
  645.     ELSE
  646.       IFNB <StdCallBytes>
  647. EXTRN _&&Procedure&&@&&StdCallBytes:NEAR
  648.       ELSE
  649. EXTRN Procedure:NEAR
  650.       ENDIF
  651.     ENDIF
  652.     ENDM
  653.   tableproc MACRO
  654.     IFNB <fastcall>
  655.       dd  OFFSET32 @&&Procedure&&@&&StdCallBytes
  656.     ELSE
  657.       IFNB <StdCallBytes>
  658. dd  OFFSET32 _&&Procedure&&@&&StdCallBytes
  659.       ELSE
  660. dd  OFFSET32 Procedure
  661.       ENDIF
  662.     ENDIF
  663.     ENDM
  664.   IFNB <Condition>
  665.   $$&&Procedure MACRO extern
  666.     IFDEF &Condition
  667.       IFNB <extern>
  668. extrnproc
  669.       ELSE
  670. tableproc
  671.       ENDIF
  672.     ELSE
  673.       IFB <extern>
  674.       dd      0
  675.       ENDIF
  676.     ENDIF
  677.     ENDM
  678.   ENDIF
  679.   IFDIFI <Procedure>, <RESERVED>
  680.     PUBLIC _&&Procedure
  681.      IF1
  682.     _&&Procedure LABEL DWORD
  683.      IFNB <fastcall>
  684.     PUBLIC __&&Procedure
  685.      __&&Procedure LABEL DWORD
  686.      ENDIF
  687.      ENDIF
  688.      IFDIFI <Local_Seg>, <LOCAL>
  689. IFNB <Local_Seg>
  690. Local_Seg&&_SEG
  691.        ELSE
  692. Def_Segment&_CODE_SEG
  693. ENDIF
  694. IFNB <Condition>
  695.     $$&&Procedure extern
  696.        ELSE
  697. extrnproc
  698. ENDIF
  699. IFNB <Local_Seg>
  700. Local_Seg&&_ENDS
  701. ELSE
  702. Def_Segment&_CODE_ENDS
  703. ENDIF
  704.      ENDIF
  705.       IFNB <Condition>
  706.     $$&&Procedure
  707.       ELSE
  708. tableproc
  709.       ENDIF
  710.   IFDEF Device_Name&_Name_Based
  711. @@&&Procedure = (Device_Name&_Internal_ID SHL 16) + Num_&Device_Name&_Services
  712.   ELSE
  713. @@&&Procedure = (Device_Name&_Device_ID SHL 16) + Num_&Device_Name&_Services
  714.   ENDIF
  715.   ELSE
  716.     dd 0
  717.   ENDIF
  718.     Num_&Device_Name&_Services = Num_&Device_Name&_Services + 1
  719.   IFNB <Condition>
  720.     Purge $$&&Procedure
  721.   ENDIF
  722.     Purge extrnproc
  723.     Purge tableproc
  724.     ENDM
  725.   Device_Name&_StdCall_Service MACRO Procedure, Args, Local_Seg, Condition
  726.     Device_Name&_Service Procedure, Local_Seg, Condition, %Args*4
  727.     ??_standardccall&&_Procedure = Args
  728.     ENDM
  729.   Device_Name&_FastCall_Service MACRO Procedure, Args, Local_Seg, Condition
  730.     Device_Name&_Service Procedure, Local_Seg, Condition, %Args*4, TRUE
  731.     ??_fastcall&&_Procedure = Args
  732.     ENDM
  733. ELSE
  734. ; Local_Seg and Condition are placeholders only in this form
  735. IFDEF Device_Name&_Name_Based
  736. Device_Name&_Service MACRO Procedure, Local_Seg, Condition
  737.   IFDIFI <Procedure>, <RESERVED>
  738.     @@&&Procedure = (Device_Name&_Internal_ID SHL 16) + Num_&Device_Name&_Services
  739.   ENDIF
  740.     Num_&Device_Name&_Services = Num_&Device_Name&_Services + 1
  741.     ENDM
  742. ELSE
  743. Device_Name&_Service MACRO Procedure, Local_Seg, Condition
  744.   IFDIFI <Procedure>, <RESERVED>
  745.     @@&&Procedure = (Device_Name&_Device_ID SHL 16) + Num_&Device_Name&_Services
  746.   ENDIF
  747.     Num_&Device_Name&_Services = Num_&Device_Name&_Services + 1
  748.     ENDM
  749. ENDIF
  750.   Device_Name&_StdCall_Service MACRO Procedure, Args, Local_Seg, Condition
  751.     Device_Name&_Service Procedure, Local_Seg, Condition
  752.     ??_standardccall_&&Procedure = Args
  753.     ENDM
  754.   Device_Name&_FastCall_Service MACRO Procedure, Args, Local_Seg, Condition
  755.     Device_Name&_Service Procedure, Local_Seg, Condition
  756.     ??_fastcall_&&Procedure = Args
  757.     ENDM
  758. ENDIF
  759.     ENDM
  760. ;------------------------------------------------------------------------------
  761. End_Service_Table MACRO Device_Name, Def_Segment
  762.     PURGE   Device_Name&_Service
  763. IFDEF Create_&Device_Name&_Service_Table
  764. IFB <Def_Segment>
  765. VxD_LOCKED_DATA_ENDS
  766. ELSE
  767. Def_Segment&_LOCKED_DATA_ENDS
  768. ENDIF
  769. ENDIF
  770.     ENDM
  771. GetVxDServiceOrdinal macro reg,service
  772.     mov reg,@@&service
  773.     endm
  774. GetVxDServiceAddress macro reg,service
  775.     mov reg,OFFSET32 service
  776.     endm
  777. ;*** Begin_Win32_Services - begin defining Win32 Service Table
  778. ;
  779. ;   This macro is used to begin the definition of the Win32
  780. ;   Service table.  It is modelled after, but not identical
  781. ;   to, the Begin_Service_Table macro. If the the special
  782. ;   symbol Create_Win32_Services is defined to be true, then
  783. ;   the actual table is emitted.  Otherwise, only the service
  784. ;   numbers are defined.
  785. ;
  786. ;   ENTRY   VxDName - the name of the VxD; it is assumed
  787. ;   that a corresponding Device_ID is
  788. ;   also defined.
  789. ;   EXIT    The macro VxDName&_Win32_Sevice is defined; it
  790. ; accepts a service name as its only parameter.
  791. ; This macro is then used to define each service.
  792. Begin_Win32_Services MACRO VxDName
  793. ifndef Create_Win32_Services
  794.     Create_Win32_Services = 0
  795. endif
  796.     .errb <VxDName>, <VxD name missing>
  797.     ??w32svcno = 0
  798. if Create_Win32_Services
  799. VxDName&_Win32_Services label dword
  800.     dd csvc&VxDName, 0
  801. endif
  802.     ??inw32svc = 1
  803.     VxDName&_Win32_Service MACRO Name
  804. .erre ??inw32svc, <Missing Begin_Win32_Services>
  805.     if Create_Win32_Services
  806. dd  OFFSET32 Name,cparm&&Name
  807.     endif
  808. @32&&Name equ ((VxDName&_Device_ID SHL 16) + ??w32svcno)
  809. ??w32svcno = ??w32svcno + 1
  810. ENDM
  811.     ENDM
  812. ;*** End_Win32_Services - mark end of Win32 Service Table
  813. ;
  814. ;   This macro completes initialization of the Win32
  815. ;   Service table.
  816. ;
  817. ;   ENTRY   VxDName - the same name passed to
  818. ;   Begin_Win32_services
  819. End_Win32_Services MACRO VxDName
  820.     .errb <VxDName>, <VxD name misssing>
  821. if Create_Win32_Services
  822.     csvc&VxDName    equ ($ - VxDName&_Win32_Services)/8 - 1
  823. endif
  824.     ??inw32svc = 0
  825.     PURGE VxDName&_Win32_Service
  826.     ENDM
  827. ;*** Declare_Win32_Service - declare an external Win32 Service
  828. ;
  829. ;   This macro is used to declare a Win32 service that
  830. ;   is defined elsewhere, perhaps in a C module.
  831. ;
  832. ;   ENTRY   Name - the service name
  833. ; cParms     - the number of DWORD parameters
  834. ;   EXIT    The name is defined as external
  835. Declare_Win32_Service MACRO Name, cParms
  836. ifndef Create_Win32_Services
  837.     Create_Win32_Services = 0
  838. endif
  839. if Create_Win32_Services
  840.     ?merge  <Name>,,,,<EQU>,<_>,<Name>,<@>,%(cParms*4 + 8)
  841.     ?merge  <cparm>,<Name>,,,<EQU>,<cParms>
  842. VxD_CODE_SEG
  843.     ?merge  <EXTRN>,,,,,<_>,<Name>,<@>,%(cParms*4 + 8),<:NEAR>
  844. VxD_CODE_ENDS
  845. endif
  846.     ENDM
  847. ;*** Win32call - call a Win32 service from a ring 3 thunk
  848. ;
  849. ;   This macro is used to call a Win32 service from
  850. ;   a ring 3 thunk.  Note that control will not return
  851. ;   to the instruction following the call, but to the
  852. ;   instruction following the call to the thunk.
  853. ;
  854. ;   ENTRY   Service - the name of the service
  855. ; CallBack    - the fword containing the callback
  856. Win32call MACRO Service, CallBack
  857. ifndef Create_Win32_Services
  858.     Create_Win32_Services = 0
  859. endif
  860. ife Create_Win32_Services
  861.     mov eax,@32&Service
  862. ifdef IS_16
  863.     movzx   esp,sp
  864. endif
  865.     call    fword ptr [CallBack]
  866. ifdef DEBUG
  867.     int 3
  868. endif
  869. endif
  870.     ENDM
  871. */
  872. /*XLATOFF*/
  873. #define GetVxDServiceAddress(service) service
  874. #define VxDCall(service) 
  875.     _asm _emit 0xcd 
  876.     _asm _emit 0x20 
  877.     _asm _emit (GetVxDServiceOrdinal(service) & 0xff) 
  878.     _asm _emit (GetVxDServiceOrdinal(service) >> 8) & 0xff 
  879.     _asm _emit (GetVxDServiceOrdinal(service) >> 16) & 0xff 
  880.     _asm _emit (GetVxDServiceOrdinal(service) >> 24) & 0xff 
  881. #define VMMCall VxDCall
  882. #define VxDJmp(service) 
  883.     _asm _emit 0xcd 
  884.     _asm _emit 0x20 
  885.     _asm _emit (GetVxDServiceOrdinal(service) & 0xff) 
  886.     _asm _emit ((GetVxDServiceOrdinal(service) >> 8) & 0xff) | 0x80 
  887.     _asm _emit (GetVxDServiceOrdinal(service) >> 16) & 0xff 
  888.     _asm _emit (GetVxDServiceOrdinal(service) >> 24) & 0xff 
  889. #define VMMJmp VxDJmp
  890. #define SERVICE  __cdecl
  891. #define ASYNC_SERVICE __cdecl
  892. #define WIN32_SERVICE void __stdcall
  893. #ifndef FASTCALL
  894. #define FASTCALL __fastcall
  895. #endif
  896. /*XLATON*/
  897. /* ASM
  898. ;******************************************************************************
  899. ;
  900. ;   Dword_Align -- Aligns code to dword boundry by inserting nops
  901. ;
  902. ;------------------------------------------------------------------------------
  903. Dword_Align MACRO Seg_Name
  904.     LOCAL segn
  905. IFDEF MASM6
  906.     align 4
  907. ELSE
  908. IFNB <Seg_Name>
  909.     segn equ Seg_Name
  910. ELSE
  911. IFE ?_LCODE
  912.     segn equ <_LTEXT>
  913. ELSE
  914. IFE ?_ICODE
  915.     segn equ <_ITEXT>
  916. ELSE
  917. IFE ?_PCODE
  918.     segn equ <_PTEXT>
  919. ELSE
  920. IFE ?_SCODE
  921.     segn equ <_STEXT>
  922. ELSE
  923. .err <Dword_Align not supported>
  924. ENDIF
  925. ENDIF
  926. ENDIF
  927. ENDIF
  928. ENDIF
  929. IF (($-OFFSET segn:0) MOD 4)
  930. db 4 - (($-OFFSET segn:0) MOD 4) DUP (90h)
  931. ENDIF
  932. ENDIF
  933. ENDM
  934. BeginDoc
  935. ;******************************************************************************
  936. ;
  937. ;   Fatal_Error
  938. ;
  939. ;   DESCRIPTION:
  940. ;   This macro is used to crash Windows/386 when an unrecoverable error
  941. ;   is detected.  If Msg_Ptr is ommitted then no error message will be
  942. ;   displayed, otherwise Msg_Ptr is the address
  943. ;   when the
  944. ;
  945. ;   PARAMETERS:
  946. ;   Msg_Ptr (OPTIONAL) - Points to an ASCIIZ string to display.
  947. ;
  948. ;   EXIT:
  949. ;   To DOS (hopefully).  This macro never returns.
  950. ;
  951. ;==============================================================================
  952. EndDoc
  953. Fatal_Error MACRO Msg_Ptr, Exit_Flags
  954.     pushad
  955. IFB <Msg_Ptr>
  956.     xor esi, esi
  957. ELSE
  958.     mov esi, Msg_Ptr
  959. IFB <Exit_Flags>
  960.     xor eax, eax
  961. ELSE
  962.     mov eax, Exit_Flags
  963. ENDIF
  964. ENDIF
  965.     VMMCall Fatal_Error_Handler
  966.     ENDM
  967. EF_Hang_On_Exit     EQU     1h
  968. */
  969. /******************************************************************************
  970.  *
  971.  *   The following are control block headers and flags of interest to VxDs.
  972.  *
  973.  *****************************************************************************/
  974. struct cb_s {
  975.     ULONG CB_VM_Status;  /* VM status flags */
  976.     ULONG CB_High_Linear; /* Address of VM mapped high */
  977.     ULONG CB_Client_Pointer;
  978.     ULONG CB_VMID;
  979.     ULONG CB_Signature;
  980. };
  981. #define VMCB_ID 0x62634D56 /* VMcb */
  982. /*
  983.  *  VM status indicates globally interesting VM states
  984.  */
  985. #define VMSTAT_EXCLUSIVE_BIT 0x00 /* VM is exclusive mode */
  986. #define VMSTAT_EXCLUSIVE (1L << VMSTAT_EXCLUSIVE_BIT)
  987. #define VMSTAT_BACKGROUND_BIT 0x01 /* VM runs in background */
  988. #define VMSTAT_BACKGROUND (1L << VMSTAT_BACKGROUND_BIT)
  989. #define VMSTAT_CREATING_BIT 0x02    /* In process of creating */
  990. #define VMSTAT_CREATING  (1L << VMSTAT_CREATING_BIT)
  991. #define VMSTAT_SUSPENDED_BIT 0x03 /* VM not scheduled */
  992. #define VMSTAT_SUSPENDED (1L << VMSTAT_SUSPENDED_BIT)
  993. #define VMSTAT_NOT_EXECUTEABLE_BIT 0x04 /* VM partially destroyed */
  994. #define VMSTAT_NOT_EXECUTEABLE (1L << VMSTAT_NOT_EXECUTEABLE_BIT)
  995. #define VMSTAT_PM_EXEC_BIT  0x05    /* Currently in PM app */
  996. #define VMSTAT_PM_EXEC (1L << VMSTAT_PM_EXEC_BIT)
  997. #define VMSTAT_PM_APP_BIT   0x06    /* PM app present in VM */
  998. #define VMSTAT_PM_APP (1L << VMSTAT_PM_APP_BIT)
  999. #define VMSTAT_PM_USE32_BIT 0x07    /* PM app is 32-bit */
  1000. #define VMSTAT_PM_USE32  (1L << VMSTAT_PM_USE32_BIT)
  1001. #define VMSTAT_VXD_EXEC_BIT 0x08    /* Call from VxD */
  1002. #define VMSTAT_VXD_EXEC  (1L << VMSTAT_VXD_EXEC_BIT)
  1003. #define VMSTAT_HIGH_PRI_BACK_BIT 0x09 /* High pri background */
  1004. #define VMSTAT_HIGH_PRI_BACK (1L << VMSTAT_HIGH_PRI_BACK_BIT)
  1005. #define VMSTAT_BLOCKED_BIT  0x0A    /* Blocked on semaphore */
  1006. #define VMSTAT_BLOCKED (1L << VMSTAT_BLOCKED_BIT)
  1007. #define VMSTAT_AWAKENING_BIT 0x0B /* Woke up after blocked */
  1008. #define VMSTAT_AWAKENING (1L << VMSTAT_AWAKENING_BIT)
  1009. #define VMSTAT_PAGEABLEV86BIT 0x0C /* part of V86 is pageable (PM app) */
  1010. #define VMSTAT_PAGEABLEV86_BIT VMSTAT_PAGEABLEV86BIT
  1011. #define VMSTAT_PAGEABLEV86 (1L << VMSTAT_PAGEABLEV86BIT)
  1012. #define VMSTAT_V86INTSLOCKEDBIT 0x0D /* Locked regardless of pager type */
  1013. #define VMSTAT_V86INTSLOCKED_BIT VMSTAT_V86INTSLOCKEDBIT
  1014. #define VMSTAT_V86INTSLOCKED (1L << VMSTAT_V86INTSLOCKEDBIT)
  1015. #define VMSTAT_IDLE_TIMEOUT_BIT 0x0E /* Scheduled by time-slicer */
  1016. #define VMSTAT_IDLE_TIMEOUT (1L << VMSTAT_IDLE_TIMEOUT_BIT)
  1017. #define VMSTAT_IDLE_BIT  0x0F /* VM has released time slice */
  1018. #define VMSTAT_IDLE (1L << VMSTAT_IDLE_BIT)
  1019. #define VMSTAT_CLOSING_BIT  0x10    /* Close_VM called for VM */
  1020. #define VMSTAT_CLOSING (1L << VMSTAT_CLOSING_BIT)
  1021. #define VMSTAT_TS_SUSPENDED_BIT 0x11 /* VM suspended by */
  1022. #define VMSTAT_TS_SUSPENDED (1L << VMSTAT_TS_SUSPENDED_BIT)
  1023. #define VMSTAT_TS_MAXPRI_BIT 0x12 /* this is fgd_pri 10,000 internally*/
  1024. #define VMSTAT_TS_MAXPRI (1L << VMSTAT_TS_MAXPRI_BIT)
  1025. #define VMSTAT_USE32_MASK   (VMSTAT_PM_USE32 | VMSTAT_VXD_EXEC)
  1026. struct tcb_s {
  1027.     ULONG   TCB_Flags; /* Thread status flags */
  1028.     ULONG   TCB_Reserved1; /* Used internally by VMM */
  1029.     ULONG   TCB_Reserved2; /* Used internally by VMM */
  1030.     ULONG   TCB_Signature;
  1031.     ULONG   TCB_ClientPtr; /* Client registers of thread */
  1032.     ULONG   TCB_VMHandle; /* VM that thread is part of */
  1033.     USHORT  TCB_ThreadId; /* Unique Thread ID */
  1034.     USHORT  TCB_PMLockOrigSS;     /* Original SS:ESP before lock stack */
  1035.     ULONG   TCB_PMLockOrigESP;
  1036.     ULONG   TCB_PMLockOrigEIP;     /* Original CS:EIP before lock stack */
  1037.     ULONG   TCB_PMLockStackCount;
  1038.     USHORT  TCB_PMLockOrigCS;
  1039.     USHORT  TCB_PMPSPSelector;
  1040.     ULONG   TCB_ThreadType; /* dword passed to VMMCreateThread */
  1041.     USHORT  TCB_pad1; /* reusable; for dword align */
  1042.     UCHAR   TCB_pad2; /* reusable; for dword align */
  1043.     UCHAR   TCB_extErrLocus;     /* extended error Locus */
  1044.     USHORT  TCB_extErr;  /* extended error Code */
  1045.     UCHAR   TCB_extErrAction;     /*     "   "   Action */
  1046.     UCHAR   TCB_extErrClass;     /*     "   "   Class */
  1047.     ULONG   TCB_extErrPtr; /* "   pointer */
  1048. };
  1049. typedef struct tcb_s TCB;
  1050. typedef TCB *PTCB;
  1051. #define SCHED_OBJ_ID_THREAD     0x42434854   // THCB in ASCII
  1052. /*
  1053.  *  Thread status indicates globally interesting thread states.
  1054.  *  Flags are for information only and must not be modified.
  1055.  */
  1056. #define THFLAG_SUSPENDED_BIT     0x03   // Thread not scheduled
  1057. #define THFLAG_SUSPENDED    (1L << THFLAG_SUSPENDED_BIT)
  1058. #define THFLAG_NOT_EXECUTEABLE_BIT  0x04   // Thread partially destroyed
  1059. #define THFLAG_NOT_EXECUTEABLE    (1L << THFLAG_NOT_EXECUTEABLE_BIT)
  1060. #define THFLAG_THREAD_CREATION_BIT  0x08   // Thread in status nascendi
  1061. #define THFLAG_THREAD_CREATION    (1L << THFLAG_THREAD_CREATION_BIT)
  1062. #define THFLAG_THREAD_BLOCKED_BIT   0x0A   // Blocked on semaphore
  1063. #define THFLAG_THREAD_BLOCKED    (1L << THFLAG_THREAD_BLOCKED_BIT)
  1064. #define THFLAG_RING0_THREAD_BIT     0x1C   // thread runs only at ring 0
  1065. #define THFLAG_RING0_THREAD    (1L << THFLAG_RING0_THREAD_BIT)
  1066. #define THFLAG_ASYNC_THREAD_BIT     0x1F   // thread is asynchronous
  1067. #define THFLAG_ASYNC_THREAD            (1L << THFLAG_ASYNC_THREAD_BIT)
  1068. #define THFLAG_CHARSET_BITS 0x10   // Default character set
  1069. #define THFLAG_CHARSET_MASK    (3L << THFLAG_CHARSET_BITS)
  1070. #define THFLAG_ANSI        (0L << THFLAG_CHARSET_BITS)
  1071. #define THFLAG_OEM        (1L << THFLAG_CHARSET_BITS)
  1072. #define THFLAG_UNICODE    (2L << THFLAG_CHARSET_BITS)
  1073. #define THFLAG_RESERVED     (3L << THFLAG_CHARSET_BITS)
  1074. #define THFLAG_EXTENDED_HANDLES_BIT 0x12   // Thread uses extended file handles
  1075. #define THFLAG_EXTENDED_HANDLES     (1L << THFLAG_EXTENDED_HANDLES_BIT)
  1076. /* the win32 loader opens win32 exes with this bit set to notify IFS
  1077.  * so a defragger won't move these files
  1078.  * the bit is turned off once the open completes.
  1079.  * file open flags are overloaded which is why this is here
  1080.  */
  1081. #define THFLAG_OPEN_AS_IMMOVABLE_FILE_BIT 0x13  // File thus opened not moved
  1082. #define THFLAG_OPEN_AS_IMMOVABLE_FILE  (1L << THFLAG_OPEN_AS_IMMOVABLE_FILE_BIT)
  1083. /*
  1084.  *   Protected mode application control blocks
  1085.  */
  1086. struct pmcb_s {
  1087.     ULONG PMCB_Flags;
  1088.     ULONG PMCB_Parent;
  1089. };
  1090. /*
  1091.  *  The reference data for fault error codes 1-5 (GSDVME_PRIVINST through
  1092.  *  GSDVME_INVALFLT) is a pointer to the following fault information structure.
  1093.  */
  1094. struct VMFaultInfo {
  1095.     ULONG VMFI_EIP; // faulting EIP
  1096.     WORD  VMFI_CS; // faulting CS
  1097.     WORD  VMFI_Ints; // interrupts in service, if any
  1098. };
  1099. typedef struct VMFaultInfo *PVMFaultInfo;
  1100. /******************************************************************************
  1101.  * V M M S E R V I C E S
  1102.  ******************************************************************************/
  1103. /*XLATOFF*/
  1104. #define VMM_Service Declare_Service
  1105. #define VMM_StdCall_Service Declare_SCService
  1106. #define VMM_FastCall_Service Declare_SCService
  1107. #pragma warning (disable:4003)     // turn off not enough params warning
  1108. /*XLATON*/
  1109. /*MACROS*/
  1110. Begin_Service_Table(VMM, VMM)
  1111. VMM_Service (Get_VMM_Version, LOCAL) // MUST REMAIN SERVICE 0!
  1112. VMM_Service (Get_Cur_VM_Handle)
  1113. VMM_Service (Test_Cur_VM_Handle)
  1114. VMM_Service (Get_Sys_VM_Handle)
  1115. VMM_Service (Test_Sys_VM_Handle)
  1116. VMM_Service (Validate_VM_Handle)
  1117. VMM_Service (Get_VMM_Reenter_Count)
  1118. VMM_Service (Begin_Reentrant_Execution)
  1119. VMM_Service (End_Reentrant_Execution)
  1120. VMM_Service (Install_V86_Break_Point)
  1121. VMM_Service (Remove_V86_Break_Point)
  1122. VMM_Service (Allocate_V86_Call_Back)
  1123. VMM_Service (Allocate_PM_Call_Back)
  1124. VMM_Service (Call_When_VM_Returns)
  1125. VMM_Service (Schedule_Global_Event)
  1126. VMM_Service (Schedule_VM_Event)
  1127. VMM_Service (Call_Global_Event)
  1128. VMM_Service (Call_VM_Event)
  1129. VMM_Service (Cancel_Global_Event)
  1130. VMM_Service (Cancel_VM_Event)
  1131. VMM_Service (Call_Priority_VM_Event)
  1132. VMM_Service (Cancel_Priority_VM_Event)
  1133. VMM_Service (Get_NMI_Handler_Addr)
  1134. VMM_Service (Set_NMI_Handler_Addr)
  1135. VMM_Service (Hook_NMI_Event)
  1136. VMM_Service (Call_When_VM_Ints_Enabled)
  1137. VMM_Service (Enable_VM_Ints)
  1138. VMM_Service (Disable_VM_Ints)
  1139. VMM_Service (Map_Flat)
  1140. VMM_Service (Map_Lin_To_VM_Addr)
  1141. //   Scheduler services
  1142. VMM_Service (Adjust_Exec_Priority)
  1143. VMM_Service (Begin_Critical_Section)
  1144. VMM_Service (End_Critical_Section)
  1145. VMM_Service (End_Crit_And_Suspend)
  1146. VMM_Service (Claim_Critical_Section)
  1147. VMM_Service (Release_Critical_Section)
  1148. VMM_Service (Call_When_Not_Critical)
  1149. VMM_Service (Create_Semaphore)
  1150. VMM_Service (Destroy_Semaphore)
  1151. VMM_Service (Wait_Semaphore)
  1152. VMM_Service (Signal_Semaphore)
  1153. VMM_Service (Get_Crit_Section_Status)
  1154. VMM_Service (Call_When_Task_Switched)
  1155. VMM_Service (Suspend_VM)
  1156. VMM_Service (Resume_VM)
  1157. VMM_Service (No_Fail_Resume_VM)
  1158. VMM_Service (Nuke_VM)
  1159. VMM_Service (Crash_Cur_VM)
  1160. VMM_Service (Get_Execution_Focus)
  1161. VMM_Service (Set_Execution_Focus)
  1162. VMM_Service (Get_Time_Slice_Priority)
  1163. VMM_Service (Set_Time_Slice_Priority)
  1164. VMM_Service (Get_Time_Slice_Granularity)
  1165. VMM_Service (Set_Time_Slice_Granularity)
  1166. VMM_Service (Get_Time_Slice_Info)
  1167. VMM_Service (Adjust_Execution_Time)
  1168. VMM_Service (Release_Time_Slice)
  1169. VMM_Service (Wake_Up_VM)
  1170. VMM_Service (Call_When_Idle)
  1171. VMM_Service (Get_Next_VM_Handle)
  1172. //   Time-out and system timer services
  1173. VMM_Service (Set_Global_Time_Out)
  1174. VMM_Service (Set_VM_Time_Out)
  1175. VMM_Service (Cancel_Time_Out)
  1176. VMM_Service (Get_System_Time)
  1177. VMM_Service (Get_VM_Exec_Time)
  1178. VMM_Service (Hook_V86_Int_Chain)
  1179. VMM_Service (Get_V86_Int_Vector)
  1180. VMM_Service (Set_V86_Int_Vector)
  1181. VMM_Service (Get_PM_Int_Vector)
  1182. VMM_Service (Set_PM_Int_Vector)
  1183. VMM_Service (Simulate_Int)
  1184. VMM_Service (Simulate_Iret)
  1185. VMM_Service (Simulate_Far_Call)
  1186. VMM_Service (Simulate_Far_Jmp)
  1187. VMM_Service (Simulate_Far_Ret)
  1188. VMM_Service (Simulate_Far_Ret_N)
  1189. VMM_Service (Build_Int_Stack_Frame)
  1190. VMM_Service (Simulate_Push)
  1191. VMM_Service (Simulate_Pop)
  1192. // Heap Manager
  1193. VMM_Service (_HeapAllocate)
  1194. VMM_Service (_HeapReAllocate)
  1195. VMM_Service (_HeapFree)
  1196. VMM_Service (_HeapGetSize)
  1197. /*ENDMACROS*/
  1198. /****************************************************
  1199.  *
  1200.  *   Flags for heap allocator calls
  1201.  *
  1202.  *   NOTE: HIGH 8 BITS (bits 24-31) are reserved
  1203.  *
  1204.  ***************************************************/
  1205. //
  1206. // Flags affecting the returned block
  1207. //
  1208. #define HEAPZEROINIT        0x00000001
  1209. #define HEAPZEROREINIT      0x00000002
  1210. #define HEAPNOCOPY          0x00000004
  1211. //
  1212. // Alignment flags
  1213. //
  1214. #define HEAPALIGN_SHIFT     16
  1215. #define HEAPALIGN_MASK      0x000F0000
  1216. #define HEAPALIGN_4         0x00000000                // dword aligned
  1217. #define HEAPALIGN_8         0x00000000                // quadword aligned
  1218. #define HEAPALIGN_16        0x00000000                // paragraph aligned
  1219. #define HEAPALIGN_32        0x00010000                // etc.
  1220. #define HEAPALIGN_64        0x00020000
  1221. #define HEAPALIGN_128       0x00030000
  1222. #define HEAPALIGN_256       0x00040000
  1223. #define HEAPALIGN_512       0x00050000
  1224. #define HEAPALIGN_1K        0x00060000
  1225. #define HEAPALIGN_2K        0x00070000
  1226. #define HEAPALIGN_4K        0x00080000
  1227. #define HEAPALIGN_8K        0x00090000
  1228. #define HEAPALIGN_16K       0x000A0000
  1229. #define HEAPALIGN_32K       0x000B0000
  1230. #define HEAPALIGN_64K       0x000C0000
  1231. #define HEAPALIGN_128K      0x000D0000
  1232. //
  1233. // Flags indicating which system heap to use.  There are four bits reserved
  1234. // to identify the heap to use.  Four are currently defined by the system.
  1235. //
  1236. #define HEAPTYPESHIFT       8
  1237. #define HEAPTYPEMASK        0x00000700
  1238. #define HEAPLOCKEDHIGH      0x00000000
  1239. #define HEAPLOCKEDIFDP      0x00000100
  1240. #define HEAPSWAP            0x00000200
  1241. #define HEAPLOCKEDLOW       0x00000300
  1242. #define HEAPINIT            0x00000400  // will be automatically freed after
  1243.                                         // init complete
  1244. #define HEAPSYSVM           0x00000500
  1245. //
  1246. // other flags
  1247. //
  1248. #define HEAPCLEAN           0x00000800
  1249. #define HEAPCONTIG          0x00001000  // memory must be physically contiguous
  1250. #define HEAPFORGET          0x00002000  // this memory will never be freed
  1251. // Page Manager
  1252. /*MACROS*/
  1253. VMM_Service (_PageAllocate)
  1254. VMM_Service (_PageReAllocate)
  1255. VMM_Service (_PageFree)
  1256. VMM_Service (_PageLock)
  1257. VMM_Service (_PageUnLock)
  1258. VMM_Service (_PageGetSizeAddr)
  1259. VMM_Service (_PageGetAllocInfo)
  1260. VMM_Service (_GetFreePageCount)
  1261. VMM_Service (_GetSysPageCount)
  1262. VMM_Service (_GetVMPgCount)
  1263. VMM_Service (_MapIntoV86)
  1264. VMM_Service (_PhysIntoV86)
  1265. VMM_Service (_TestGlobalV86Mem)
  1266. VMM_Service (_ModifyPageBits)
  1267. VMM_Service (_CopyPageTable)
  1268. VMM_Service (_LinMapIntoV86)
  1269. VMM_Service (_LinPageLock)
  1270. VMM_Service (_LinPageUnLock)
  1271. VMM_Service (_SetResetV86Pageable)
  1272. VMM_Service (_GetV86PageableArray)
  1273. VMM_Service (_PageCheckLinRange)
  1274. VMM_Service (_PageOutDirtyPages)
  1275. VMM_Service (_PageDiscardPages)
  1276. /*ENDMACROS*/
  1277. /****************************************************
  1278.  *
  1279.  *  Flags for other page allocator calls
  1280.  *
  1281.  *  NOTE: HIGH 8 BITS (bits 24-31) are reserved
  1282.  *
  1283.  ***************************************************/
  1284. #define PAGEZEROINIT 0x00000001
  1285. #define PAGEUSEALIGN 0x00000002
  1286. #define PAGECONTIG 0x00000004
  1287. #define PAGEFIXED 0x00000008
  1288. #define PAGEDEBUGNULFAULT 0x00000010
  1289. #define PAGEZEROREINIT 0x00000020
  1290. #define PAGENOCOPY 0x00000040
  1291. #define PAGELOCKED 0x00000080
  1292. #define PAGELOCKEDIFDP 0x00000100
  1293. #define PAGESETV86PAGEABLE 0x00000200
  1294. #define PAGECLEARV86PAGEABLE 0x00000400
  1295. #define PAGESETV86INTSLOCKED 0x00000800
  1296. #define PAGECLEARV86INTSLOCKED 0x00001000
  1297. #define PAGEMARKPAGEOUT  0x00002000
  1298. #define PAGEPDPSETBASE 0x00004000
  1299. #define PAGEPDPCLEARBASE 0x00008000
  1300. #define PAGEDISCARD 0x00010000
  1301. #define PAGEPDPQUERYDIRTY 0x00020000
  1302. #define PAGEMAPFREEPHYSREG 0x00040000
  1303. #define PAGEPHYSONLY 0x04000000
  1304. //efine PAGEDONTUSE 0x08000000  // ;Internal
  1305. #define PAGENOMOVE 0x10000000
  1306. #define PAGEMAPGLOBAL 0x40000000
  1307. #define PAGEMARKDIRTY 0x80000000
  1308. /****************************************************
  1309.  *
  1310.  * Flags for _PhysIntoV86,
  1311.  * _MapIntoV86, and _LinMapIntoV86
  1312.  *
  1313.  ***************************************************/
  1314. #define MAPV86_IGNOREWRAP 0x00000001
  1315. // Informational services
  1316. /*MACROS*/
  1317. VMM_Service (_GetNulPageHandle)
  1318. VMM_Service (_GetFirstV86Page)
  1319. VMM_Service (_MapPhysToLinear)
  1320. VMM_Service (_GetAppFlatDSAlias)
  1321. VMM_Service (_SelectorMapFlat)
  1322. VMM_Service (_GetDemandPageInfo)
  1323. VMM_Service (_GetSetPageOutCount)
  1324. /*ENDMACROS*/
  1325. /*
  1326.  *  Flags bits for _GetSetPageOutCount
  1327.  */
  1328. #define GSPOC_F_GET 0x00000001
  1329. // Device VM page manager
  1330. /*MACROS*/
  1331. VMM_Service (Hook_V86_Page)
  1332. VMM_Service (_Assign_Device_V86_Pages)
  1333. VMM_Service (_DeAssign_Device_V86_Pages)
  1334. VMM_Service (_Get_Device_V86_Pages_Array)
  1335. VMM_Service (MMGR_SetNULPageAddr)
  1336. // GDT/LDT management
  1337. VMM_Service (_Allocate_GDT_Selector)
  1338. VMM_Service (_Free_GDT_Selector)
  1339. VMM_Service (_Allocate_LDT_Selector)
  1340. VMM_Service (_Free_LDT_Selector)
  1341. VMM_Service (_BuildDescriptorDWORDs)
  1342. VMM_Service (_GetDescriptor)
  1343. VMM_Service (_SetDescriptor)
  1344. /*ENDMACROS*/
  1345. /*
  1346.  *  Flag equates for _BuildDescriptorDWORDs
  1347.  */
  1348. #define BDDEXPLICITDPL 0x00000001
  1349. /*
  1350.  *  Flag equates for _Allocate_LDT_Selector
  1351.  */
  1352. #define ALDTSPECSEL 0x00000001
  1353. /*MACROS*/
  1354. VMM_Service (_MMGR_Toggle_HMA)
  1355. /*ENDMACROS*/
  1356. /*
  1357.  *  Flag equates for _MMGR_Toggle_HMA
  1358.  */
  1359. #define MMGRHMAPHYSICAL 0x00000001
  1360. #define MMGRHMAENABLE 0x00000002
  1361. #define MMGRHMADISABLE 0x00000004
  1362. #define MMGRHMAQUERY 0x00000008
  1363. /*MACROS*/
  1364. VMM_Service (Get_Fault_Hook_Addrs)
  1365. VMM_Service (Hook_V86_Fault)
  1366. VMM_Service (Hook_PM_Fault)
  1367. VMM_Service (Hook_VMM_Fault)
  1368. VMM_Service (Begin_Nest_V86_Exec)
  1369. VMM_Service (Begin_Nest_Exec)
  1370. VMM_Service (Exec_Int)
  1371. VMM_Service (Resume_Exec)
  1372. VMM_Service (End_Nest_Exec)
  1373. VMM_Service (Allocate_PM_App_CB_Area, VMM_ICODE)
  1374. VMM_Service (Get_Cur_PM_App_CB)
  1375. VMM_Service (Set_V86_Exec_Mode)
  1376. VMM_Service (Set_PM_Exec_Mode)
  1377. VMM_Service (Begin_Use_Locked_PM_Stack)
  1378. VMM_Service (End_Use_Locked_PM_Stack)
  1379. VMM_Service (Save_Client_State)
  1380. VMM_Service (Restore_Client_State)
  1381. VMM_Service (Exec_VxD_Int)
  1382. VMM_Service (Hook_Device_Service)
  1383. VMM_Service (Hook_Device_V86_API)
  1384. VMM_Service (Hook_Device_PM_API)
  1385. VMM_Service (System_Control)
  1386. //   I/O and software interrupt hooks
  1387. VMM_Service (Simulate_IO)
  1388. VMM_Service (Install_Mult_IO_Handlers)
  1389. VMM_Service (Install_IO_Handler)
  1390. VMM_Service (Enable_Global_Trapping)
  1391. VMM_Service (Enable_Local_Trapping)
  1392. VMM_Service (Disable_Global_Trapping)
  1393. VMM_Service (Disable_Local_Trapping)
  1394. //   Linked List Abstract Data Type Services
  1395. VMM_Service (List_Create)
  1396. VMM_Service (List_Destroy)
  1397. VMM_Service (List_Allocate)
  1398. VMM_Service (List_Attach)
  1399. VMM_Service (List_Attach_Tail)
  1400. VMM_Service (List_Insert)
  1401. VMM_Service (List_Remove)
  1402. VMM_Service (List_Deallocate)
  1403. VMM_Service (List_Get_First)
  1404. VMM_Service (List_Get_Next)
  1405. VMM_Service (List_Remove_First)
  1406. /*ENDMACROS*/
  1407. /*
  1408.  *   Flags used by List_Create
  1409.  */
  1410. #define LF_ASYNC_BIT     0
  1411. #define LF_ASYNC (1 << LF_ASYNC_BIT)
  1412. #define LF_USE_HEAP_BIT     1
  1413. #define LF_USE_HEAP (1 << LF_USE_HEAP_BIT)
  1414. #define LF_ALLOC_ERROR_BIT  2
  1415. #define LF_ALLOC_ERROR     (1 << LF_ALLOC_ERROR_BIT)
  1416. /*
  1417.  * Swappable lists must use the heap.
  1418.  */
  1419. #define LF_SWAP  (LF_USE_HEAP + (1 << 3))
  1420. /******************************************************************************
  1421.  *  I N I T I A L I Z A T I O N   P R O C E D U R E S
  1422.  ******************************************************************************/
  1423. // Instance data manager
  1424. /*MACROS*/
  1425. VMM_Service (_AddInstanceItem)
  1426. // System structure data manager
  1427. VMM_Service (_Allocate_Device_CB_Area)
  1428. VMM_Service (_Allocate_Global_V86_Data_Area, VMM_ICODE)
  1429. VMM_Service (_Allocate_Temp_V86_Data_Area, VMM_ICODE)
  1430. VMM_Service (_Free_Temp_V86_Data_Area, VMM_ICODE)
  1431. /*ENDMACROS*/
  1432. /*
  1433.  *  Flag bits for _Allocate_Global_V86_Data_Area
  1434.  */
  1435. #define GVDAWordAlign     0x00000001
  1436. #define GVDADWordAlign     0x00000002
  1437. #define GVDAParaAlign     0x00000004
  1438. #define GVDAPageAlign     0x00000008
  1439. #define GVDAInstance     0x00000100
  1440. #define GVDAZeroInit     0x00000200
  1441. #define GVDAReclaim 0x00000400
  1442. #define GVDAInquire 0x00000800
  1443. #define GVDAHighSysCritOK   0x00001000
  1444. #define GVDAOptInstance     0x00002000
  1445. #define GVDAForceLow     0x00004000
  1446. /*
  1447.  *  Flag bits for _Allocate_Temp_V86_Data_Area
  1448.  */
  1449. #define TVDANeedTilInitComplete 0x00000001
  1450. // Initialization information calls (win.ini and environment parameters)
  1451. /*MACROS*/
  1452. VMM_Service (Get_Profile_Decimal_Int, VMM_ICODE)
  1453. VMM_Service (Convert_Decimal_String, VMM_ICODE)
  1454. VMM_Service (Get_Profile_Fixed_Point, VMM_ICODE)
  1455. VMM_Service (Convert_Fixed_Point_String, VMM_ICODE)
  1456. VMM_Service (Get_Profile_Hex_Int, VMM_ICODE)
  1457. VMM_Service (Convert_Hex_String, VMM_ICODE)
  1458. VMM_Service (Get_Profile_Boolean, VMM_ICODE)
  1459. VMM_Service (Convert_Boolean_String, VMM_ICODE)
  1460. VMM_Service (Get_Profile_String, VMM_ICODE)
  1461. VMM_Service (Get_Next_Profile_String, VMM_ICODE)
  1462. VMM_Service (Get_Environment_String, VMM_ICODE)
  1463. VMM_Service (Get_Exec_Path, VMM_ICODE)
  1464. VMM_Service (Get_Config_Directory, VMM_ICODE)
  1465. VMM_Service (OpenFile, VMM_ICODE)
  1466. /*ENDMACROS*/
  1467. // OpenFile, if called after init, must point EDI to a buffer of at least
  1468. // this size.
  1469. #define VMM_OPENFILE_BUF_SIZE     260
  1470. /*MACROS*/
  1471. VMM_Service (Get_PSP_Segment, VMM_ICODE)
  1472. VMM_Service (GetDOSVectors, VMM_ICODE)
  1473. VMM_Service (Get_Machine_Info)
  1474. /*ENDMACROS*/
  1475. #define GMIF_80486_BIT 0x10
  1476. #define GMIF_80486  (1 << GMIF_80486_BIT)
  1477. #define GMIF_PCXT_BIT 0x11
  1478. #define GMIF_PCXT   (1 << GMIF_PCXT_BIT)
  1479. #define GMIF_MCA_BIT 0x12
  1480. #define GMIF_MCA    (1 << GMIF_MCA_BIT)
  1481. #define GMIF_EISA_BIT 0x13
  1482. #define GMIF_EISA   (1 << GMIF_EISA_BIT)
  1483. #define GMIF_CPUID_BIT 0x14
  1484. #define GMIF_CPUID  (1 << GMIF_CPUID_BIT)
  1485. // Following service is not restricted to initialization
  1486. /*MACROS*/
  1487. VMM_Service (GetSet_HMA_Info)
  1488. VMM_Service (Set_System_Exit_Code)
  1489. VMM_Service (Fatal_Error_Handler)
  1490. VMM_Service (Fatal_Memory_Error)
  1491. //   Called by VTD only
  1492. VMM_Service (Update_System_Clock)
  1493. /******************************************************************************
  1494.  *     D E B U G G I N G E X T E R N S
  1495.  ******************************************************************************/
  1496. VMM_Service (Test_Debug_Installed) // Valid call in retail also
  1497. VMM_Service (Out_Debug_String)
  1498. VMM_Service (Out_Debug_Chr)
  1499. VMM_Service (In_Debug_Chr)
  1500. VMM_Service (Debug_Convert_Hex_Binary)
  1501. VMM_Service (Debug_Convert_Hex_Decimal)
  1502. VMM_Service (Debug_Test_Valid_Handle)
  1503. VMM_Service (Validate_Client_Ptr)
  1504. VMM_Service (Test_Reenter)
  1505. VMM_Service (Queue_Debug_String)
  1506. VMM_Service (Log_Proc_Call)
  1507. VMM_Service (Debug_Test_Cur_VM)
  1508. VMM_Service (Get_PM_Int_Type)
  1509. VMM_Service (Set_PM_Int_Type)
  1510. VMM_Service (Get_Last_Updated_System_Time)
  1511. VMM_Service (Get_Last_Updated_VM_Exec_Time)
  1512. VMM_Service (Test_DBCS_Lead_Byte) // for DBCS Enabling
  1513. /*ENDMACROS*/
  1514. /* ASM
  1515. .errnz @@Test_DBCS_Lead_Byte - 100D1h  ; VMM service table changed above this service
  1516. */
  1517. /*************************************************************************
  1518.  *************************************************************************
  1519.  * END OF 3.00 SERVICE TABLE MUST NOT SHUFFLE SERVICES BEFORE THIS POINT
  1520.  *  FOR COMPATIBILITY.
  1521.  *************************************************************************
  1522.  *************************************************************************/
  1523. /*MACROS*/
  1524. VMM_Service (_AddFreePhysPage, VMM_ICODE)
  1525. VMM_Service (_PageResetHandlePAddr)
  1526. VMM_Service (_SetLastV86Page, VMM_ICODE)
  1527. VMM_Service (_GetLastV86Page)
  1528. VMM_Service (_MapFreePhysReg)
  1529. VMM_Service (_UnmapFreePhysReg)
  1530. VMM_Service (_XchgFreePhysReg)
  1531. VMM_Service (_SetFreePhysRegCalBk, VMM_ICODE)
  1532. VMM_Service (Get_Next_Arena, VMM_ICODE)
  1533. VMM_Service (Get_Name_Of_Ugly_TSR, VMM_ICODE)
  1534. VMM_Service (Get_Debug_Options, VMM_ICODE)
  1535. /*ENDMACROS*/
  1536. /*
  1537.  *  Flags for AddFreePhysPage
  1538.  */
  1539. #define AFPP_SWAPOUT  0x0001 // physical memory that must be swapped out
  1540. // and subsequently restored at system exit
  1541. /*
  1542.  *  Flags for PageChangePager
  1543.  */
  1544. #define PCP_CHANGEPAGER     0x1 // change the pager for the page range
  1545. #define PCP_CHANGEPAGERDATA 0x2 // change the pager data dword for the pages
  1546. #define PCP_VIRGINONLY     0x4 // make the above changes to virgin pages only
  1547. /*
  1548.  *  Bits for the ECX return of Get_Next_Arena
  1549.  */
  1550. #define GNA_HIDOSLINKED  0x0002 // High DOS arenas linked when WIN386 started
  1551. #define GNA_ISHIGHDOS  0x0004 // High DOS arenas do exist
  1552. /*MACROS*/
  1553. VMM_Service (Set_Physical_HMA_Alias, VMM_ICODE)
  1554. VMM_Service (_GetGlblRng0V86IntBase, VMM_ICODE)
  1555. VMM_Service (_Add_Global_V86_Data_Area, VMM_ICODE)
  1556. VMM_Service (GetSetDetailedVMError)
  1557. /*ENDMACROS*/
  1558. /*
  1559.  *  Error code values for the GetSetDetailedVMError service. PLEASE NOTE
  1560.  *  that all of these error code values need to have bits set in the high
  1561.  *  word. This is to prevent collisions with other VMDOSAPP standard errors.
  1562.  *  Also, the low word must be non-zero.
  1563.  *
  1564.  *  First set of errors (high word = 0001) are intended to be used
  1565.  *  when a VM is CRASHED (VNE_Crashed or VNE_Nuked bit set on
  1566.  *  VM_Not_Executeable).
  1567.  *
  1568.  *  PLEASE NOTE that each of these errors (high word == 0001) actually
  1569.  *  has two forms:
  1570.  *
  1571.  *  0001xxxxh
  1572.  *  8001xxxxh
  1573.  *
  1574.  *  The device which sets the error initially always sets the error with
  1575.  *  the high bit CLEAR. The system will then optionally set the high bit
  1576.  *  depending on the result of the attempt to "nicely" crash the VM. This
  1577.  *  bit allows the system to tell the user whether the crash is likely or
  1578.  *  unlikely to destabalize the system.
  1579.  */
  1580. #define GSDVME_PRIVINST     0x00010001 /* Privledged instruction */
  1581. #define GSDVME_INVALINST    0x00010002 /* Invalid instruction */
  1582. #define GSDVME_INVALPGFLT   0x00010003 /* Invalid page fault */
  1583. #define GSDVME_INVALGPFLT   0x00010004 /* Invalid GP fault */
  1584. #define GSDVME_INVALFLT     0x00010005 /* Unspecified invalid fault */
  1585. #define GSDVME_USERNUKE     0x00010006 /* User requested NUKE of VM */
  1586. #define GSDVME_DEVNUKE     0x00010007 /* Device specific problem */
  1587. #define GSDVME_DEVNUKEHDWR  0x00010008 /* Device specific problem:
  1588.  *   invalid hardware fiddling
  1589.  *   by VM (invalid I/O)
  1590.  */
  1591. #define GSDVME_NUKENOMSG    0x00010009 /* Supress standard messages:
  1592.  *   SHELL_Message used for
  1593.  *   custom msg.
  1594.  */
  1595. #define GSDVME_OKNUKEMASK   0x80000000 /* "Nice nuke" bit */
  1596. /*
  1597.  *  Second set of errors (high word = 0002) are intended to be used
  1598.  *  when a VM start up is failed (VNE_CreateFail, VNE_CrInitFail, or
  1599.  *  VNE_InitFail bit set on VM_Not_Executeable).
  1600.  */
  1601. #define GSDVME_INSMEMV86    0x00020001 /* base V86 mem    - V86MMGR */
  1602. #define GSDVME_INSV86SPACE  0x00020002 /* Kb Req too large - V86MMGR */
  1603. #define GSDVME_INSMEMXMS    0x00020003 /* XMS Kb Req    - V86MMGR */
  1604. #define GSDVME_INSMEMEMS    0x00020004 /* EMS Kb Req    - V86MMGR */
  1605. #define GSDVME_INSMEMV86HI  0x00020005 /* Hi DOS V86 mem   - DOSMGR
  1606.  *      V86MMGR
  1607.  */
  1608. #define GSDVME_INSMEMVID    0x00020006 /* Base Video mem   - VDD */
  1609. #define GSDVME_INSMEMVM     0x00020007 /* Base VM mem    - VMM
  1610.  *   CB, Inst Buffer
  1611.  */
  1612. #define GSDVME_INSMEMDEV    0x00020008 /* Couldn't alloc base VM
  1613.  * memory for device.
  1614.  */
  1615. #define GSDVME_CRTNOMSG     0x00020009 /* Supress standard messages:
  1616.  *   SHELL_Message used for
  1617.  *   custom msg.
  1618.  */
  1619. /*MACROS*/
  1620. VMM_Service (Is_Debug_Chr)
  1621. //   Mono_Out services
  1622. VMM_Service (Clear_Mono_Screen)
  1623. VMM_Service (Out_Mono_Chr)
  1624. VMM_Service (Out_Mono_String)
  1625. VMM_Service (Set_Mono_Cur_Pos)
  1626. VMM_Service (Get_Mono_Cur_Pos)
  1627. VMM_Service (Get_Mono_Chr)
  1628. //   Service locates a byte in ROM
  1629. VMM_Service (Locate_Byte_In_ROM, VMM_ICODE)
  1630. VMM_Service (Hook_Invalid_Page_Fault)
  1631. VMM_Service (Unhook_Invalid_Page_Fault)
  1632. /*ENDMACROS*/
  1633. /*
  1634.  *  Flag bits of IPF_Flags
  1635.  */
  1636. #define IPF_PGDIR   0x00000001 /* Page directory entry not-present */
  1637. #define IPF_V86PG   0x00000002 /* Unexpected not present Page in V86 */
  1638. #define IPF_V86PGH  0x00000004 /* Like IPF_V86PG at high linear */
  1639. #define IPF_INVTYP  0x00000008 /* page has invalid not present type */
  1640. #define IPF_PGERR   0x00000010 /* pageswap device failure */
  1641. #define IPF_REFLT   0x00000020 /* re-entrant page fault */
  1642. #define IPF_VMM     0x00000040 /* Page fault caused by a VxD */
  1643. #define IPF_PM     0x00000080 /* Page fault by VM in Prot Mode */
  1644. #define IPF_V86     0x00000100 /* Page fault by VM in V86 Mode */
  1645. /*MACROS*/
  1646. VMM_Service (Set_Delete_On_Exit_File)
  1647. VMM_Service (Close_VM)
  1648. /*ENDMACROS*/
  1649. /*
  1650.  *   Flags for Close_VM service
  1651.  */
  1652. #define CVF_CONTINUE_EXEC_BIT 0
  1653. #define CVF_CONTINUE_EXEC   (1 << CVF_CONTINUE_EXEC_BIT)
  1654. /*MACROS*/
  1655. VMM_Service (Enable_Touch_1st_Meg) // Debugging only
  1656. VMM_Service (Disable_Touch_1st_Meg) // Debugging only
  1657. VMM_Service (Install_Exception_Handler)
  1658. VMM_Service (Remove_Exception_Handler)
  1659. VMM_Service (Get_Crit_Status_No_Block)
  1660. /*ENDMACROS*/
  1661. /* ASM
  1662. ; Check if VMM service table has changed above this service
  1663. .errnz  @@Get_Crit_Status_No_Block - 100F1h
  1664. */
  1665. #ifdef WIN40SERVICES
  1666. /*************************************************************************
  1667.  *************************************************************************
  1668.  *
  1669.  * END OF 3.10 SERVICE TABLE MUST NOT SHUFFLE SERVICES BEFORE THIS POINT
  1670.  *  FOR COMPATIBILITY.
  1671.  *************************************************************************
  1672.  *************************************************************************/
  1673. /*MACROS*/
  1674. VMM_Service (_GetLastUpdatedThreadExecTime)
  1675. VMM_Service (_Trace_Out_Service)
  1676. VMM_Service (_Debug_Out_Service)
  1677. VMM_Service (_Debug_Flags_Service)
  1678. /*ENDMACROS*/
  1679. #endif /* WIN40SERVICES */
  1680. /*
  1681.  *   Flags for _Debug_Flags_Service service.
  1682.  *
  1683.  *   Don't change these unless you really really know what you're doing.
  1684.  *   We need to define these even if we are in WIN31COMPAT mode.
  1685.  */
  1686. #define DFS_LOG_BIT     0
  1687. #define DFS_LOG      (1 << DFS_LOG_BIT)
  1688. #define DFS_PROFILE_BIT  1
  1689. #define DFS_PROFILE     (1 << DFS_PROFILE_BIT)
  1690. #define DFS_TEST_CLD_BIT 2
  1691. #define DFS_TEST_CLD (1 << DFS_TEST_CLD_BIT)
  1692. #define DFS_NEVER_REENTER_BIT     3
  1693. #define DFS_NEVER_REENTER (1 << DFS_NEVER_REENTER_BIT)
  1694. #define DFS_TEST_REENTER_BIT     4
  1695. #define DFS_TEST_REENTER (1 << DFS_TEST_REENTER_BIT)
  1696. #define DFS_NOT_SWAPPING_BIT     5
  1697. #define DFS_NOT_SWAPPING (1 << DFS_NOT_SWAPPING_BIT)
  1698. #define DFS_TEST_BLOCK_BIT 6
  1699. #define DFS_TEST_BLOCK (1 << DFS_TEST_BLOCK_BIT)
  1700. #define DFS_RARE_SERVICES   0xFFFFFF80
  1701. #define DFS_EXIT_NOBLOCK (DFS_RARE_SERVICES+0)
  1702. #define DFS_ENTER_NOBLOCK (DFS_RARE_SERVICES+DFS_TEST_BLOCK)
  1703. #define DFS_TEST_NEST_EXEC  (DFS_RARE_SERVICES+1)
  1704. #ifdef WIN40SERVICES
  1705. /*MACROS*/
  1706. VMM_Service (VMMAddImportModuleName)
  1707. VMM_Service (VMM_Add_DDB)
  1708. VMM_Service (VMM_Remove_DDB)
  1709. VMM_Service (Test_VM_Ints_Enabled)
  1710. VMM_Service (_BlockOnID)
  1711. VMM_Service (Schedule_Thread_Event)
  1712. VMM_Service (Cancel_Thread_Event)
  1713. VMM_Service (Set_Thread_Time_Out)
  1714. VMM_Service (Set_Async_Time_Out)
  1715. VMM_Service (_AllocateThreadDataSlot)
  1716. VMM_Service (_FreeThreadDataSlot)
  1717. /*ENDMACROS*/
  1718. /*
  1719.  *  Flag equates for _CreateMutex
  1720.  */
  1721. #define MUTEX_MUST_COMPLETE 1L
  1722. #define MUTEX_NO_CLEANUP_THREAD_STATE 2L
  1723. /*MACROS*/
  1724. VMM_Service (_CreateMutex)
  1725. VMM_Service (_DestroyMutex)
  1726. VMM_Service (_GetMutexOwner)
  1727. VMM_Service (Call_When_Thread_Switched)
  1728. VMM_Service (VMMCreateThread)
  1729. VMM_Service (_GetThreadExecTime)
  1730. VMM_Service (VMMTerminateThread)
  1731. VMM_Service (Get_Cur_Thread_Handle)
  1732. VMM_Service (Test_Cur_Thread_Handle)
  1733. VMM_Service (Get_Sys_Thread_Handle)
  1734. VMM_Service (Test_Sys_Thread_Handle)
  1735. VMM_Service (Validate_Thread_Handle)
  1736. VMM_Service (Get_Initial_Thread_Handle)
  1737. VMM_Service (Test_Initial_Thread_Handle)
  1738. VMM_Service (Debug_Test_Valid_Thread_Handle)
  1739. VMM_Service (Debug_Test_Cur_Thread)
  1740. VMM_Service (VMM_GetSystemInitState)
  1741. VMM_Service (Cancel_Call_When_Thread_Switched)
  1742. VMM_Service (Get_Next_Thread_Handle)
  1743. VMM_Service (Adjust_Thread_Exec_Priority)
  1744. VMM_Service (_Deallocate_Device_CB_Area)
  1745. VMM_Service (Remove_IO_Handler)
  1746. VMM_Service (Remove_Mult_IO_Handlers)
  1747. VMM_Service (Unhook_V86_Int_Chain)
  1748. VMM_Service (Unhook_V86_Fault)
  1749. VMM_Service (Unhook_PM_Fault)
  1750. VMM_Service (Unhook_VMM_Fault)
  1751. VMM_Service (Unhook_Device_Service)
  1752. VMM_Service (_PageReserve)
  1753. VMM_Service (_PageCommit)
  1754. VMM_Service (_PageDecommit)
  1755. VMM_Service (_PagerRegister)
  1756. VMM_Service (_PagerQuery)
  1757. VMM_Service (_PagerDeregister)
  1758. VMM_Service (_ContextCreate)
  1759. VMM_Service (_ContextDestroy)
  1760. VMM_Service (_PageAttach)
  1761. VMM_Service (_PageFlush)
  1762. VMM_Service (_SignalID)
  1763. VMM_Service (_PageCommitPhys)
  1764. VMM_Service (_Register_Win32_Services)
  1765. VMM_Service (Cancel_Call_When_Not_Critical)
  1766. VMM_Service (Cancel_Call_When_Idle)
  1767. VMM_Service (Cancel_Call_When_Task_Switched)
  1768. VMM_Service (_Debug_Printf_Service)
  1769. VMM_Service (_EnterMutex)
  1770. VMM_Service (_LeaveMutex)
  1771. VMM_Service (Simulate_VM_IO)
  1772. VMM_Service (Signal_Semaphore_No_Switch)
  1773. VMM_Service (_ContextSwitch)
  1774. VMM_Service (_PageModifyPermissions)
  1775. VMM_Service (_PageQuery)
  1776. VMM_Service (_EnterMustComplete)
  1777. VMM_Service (_LeaveMustComplete)
  1778. VMM_Service (_ResumeExecMustComplete)
  1779. /*ENDMACROS*/
  1780. /*
  1781.  *  Flag equates for _GetThreadTerminationStatus
  1782.  */
  1783. #define THREAD_TERM_STATUS_CRASH_PEND     1L
  1784. #define THREAD_TERM_STATUS_NUKE_PEND     2L
  1785. #define THREAD_TERM_STATUS_SUSPEND_PEND     4L
  1786. /*MACROS*/
  1787. VMM_Service (_GetThreadTerminationStatus)
  1788. VMM_Service (_GetInstanceInfo)
  1789. /*ENDMACROS*/
  1790. /*
  1791.  *  Return values for _GetInstanceInfo
  1792.  */
  1793. #define INSTINFO_NONE 0 /* no data instanced in range */
  1794. #define INSTINFO_SOME 1 /* some data instanced in range */
  1795. #define INSTINFO_ALL 2 /* all data instanced in range */
  1796. /*MACROS*/
  1797. VMM_Service (_ExecIntMustComplete)
  1798. VMM_Service (_ExecVxDIntMustComplete)
  1799. VMM_Service (Begin_V86_Serialization)
  1800. VMM_Service (Unhook_V86_Page)
  1801. VMM_Service (VMM_GetVxDLocationList)
  1802. VMM_Service (VMM_GetDDBList)
  1803. VMM_Service (Unhook_NMI_Event)
  1804. VMM_Service (Get_Instanced_V86_Int_Vector)
  1805. VMM_Service (Get_Set_Real_DOS_PSP)
  1806. /*ENDMACROS*/
  1807. #define GSRDP_Set   0x0001
  1808. /*MACROS*/
  1809. VMM_Service (Call_Priority_Thread_Event)
  1810. VMM_Service (Get_System_Time_Address)
  1811. VMM_Service (Get_Crit_Status_Thread)
  1812. VMM_Service (Get_DDB)
  1813. VMM_Service (Directed_Sys_Control)
  1814. /*ENDMACROS*/
  1815. // Registry APIs for VxDs
  1816. /*MACROS*/
  1817. VMM_Service (_RegOpenKey)
  1818. VMM_Service (_RegCloseKey)
  1819. VMM_Service (_RegCreateKey)
  1820. VMM_Service (_RegDeleteKey)
  1821. VMM_Service (_RegEnumKey)
  1822. VMM_Service (_RegQueryValue)
  1823. VMM_Service (_RegSetValue)
  1824. VMM_Service (_RegDeleteValue)
  1825. VMM_Service (_RegEnumValue)
  1826. VMM_Service (_RegQueryValueEx)
  1827. VMM_Service (_RegSetValueEx)
  1828. /*ENDMACROS*/
  1829. #ifndef REG_SZ     // define only if not there already
  1830. #define REG_SZ     0x0001
  1831. #define REG_BINARY  0x0003
  1832. #endif
  1833. #ifndef HKEY_LOCAL_MACHINE  // define only if not there already
  1834. #define HKEY_CLASSES_ROOT 0x80000000
  1835. #define HKEY_CURRENT_USER 0x80000001
  1836. #define HKEY_LOCAL_MACHINE 0x80000002
  1837. #define HKEY_USERS 0x80000003
  1838. #define HKEY_PERFORMANCE_DATA 0x80000004
  1839. #define HKEY_CURRENT_CONFIG 0x80000005
  1840. #define HKEY_DYN_DATA 0x80000006
  1841. #endif
  1842. /*MACROS*/
  1843. VMM_Service (_CallRing3)
  1844. VMM_Service (Exec_PM_Int)
  1845. VMM_Service (_RegFlushKey)
  1846. VMM_Service (_PageCommitContig)
  1847. VMM_Service (_GetCurrentContext)
  1848. VMM_Service (_LocalizeSprintf)
  1849. VMM_Service (_LocalizeStackSprintf)
  1850. VMM_Service (Call_Restricted_Event)
  1851. VMM_Service (Cancel_Restricted_Event)
  1852. VMM_Service (Register_PEF_Provider, VMM_ICODE)
  1853. VMM_Service (_GetPhysPageInfo)
  1854. VMM_Service (_RegQueryInfoKey)
  1855. VMM_Service (MemArb_Reserve_Pages)
  1856. /*ENDMACROS*/
  1857. /*
  1858.  *  Return values for _GetPhysPageInfo
  1859.  */
  1860. #define PHYSINFO_NONE 0 /* no pages in the specified range exist */
  1861. #define PHYSINFO_SOME 1 /* some pages in the specified range exist */
  1862. #define PHYSINFO_ALL 2 /* all pages in the specified range exist */
  1863. // New timeslicer services
  1864. /*MACROS*/
  1865. VMM_Service (Time_Slice_Sys_VM_Idle)
  1866. VMM_Service (Time_Slice_Sleep)
  1867. VMM_Service (Boost_With_Decay)
  1868. VMM_Service (Set_Inversion_Pri)
  1869. VMM_Service (Reset_Inversion_Pri)
  1870. VMM_Service (Release_Inversion_Pri)
  1871. VMM_Service (Get_Thread_Win32_Pri)
  1872. VMM_Service (Set_Thread_Win32_Pri)
  1873. VMM_Service (Set_Thread_Static_Boost)
  1874. VMM_Service (Set_VM_Static_Boost)
  1875. VMM_Service (Release_Inversion_Pri_ID)
  1876. VMM_Service (Attach_Thread_To_Group)
  1877. VMM_Service (Detach_Thread_From_Group)
  1878. VMM_Service (Set_Group_Static_Boost)
  1879. VMM_Service (_GetRegistryPath, VMM_ICODE)
  1880. VMM_Service (_GetRegistryKey)
  1881. /*ENDMACROS*/
  1882. // TYPE definitions for _GetRegistryKey
  1883. #define REGTYPE_ENUM 0
  1884. #define REGTYPE_CLASS 1
  1885. #define REGTYPE_VXD 2
  1886. // Flag definitions for _GetRegistryKey
  1887. #define REGKEY_OPEN     0
  1888. #define REGKEY_CREATE_IFNOTEXIST    1
  1889. // Flag definitions for _Assert_Range
  1890. #define ASSERT_RANGE_NULL_BAD     0x00000000
  1891. #define ASSERT_RANGE_NULL_OK     0x00000001
  1892. #define ASSERT_RANGE_IS_ASCIIZ     0x00000002
  1893. #define ASSERT_RANGE_IS_NOT_ASCIIZ  0x00000000
  1894. #define ASSERT_RANGE_NO_DEBUG     0x80000000
  1895. #define ASSERT_RANGE_BITS     0x80000003
  1896. /*MACROS*/
  1897. VMM_Service (Cleanup_Thread_State)
  1898. VMM_Service (_RegRemapPreDefKey)
  1899. VMM_Service (End_V86_Serialization)
  1900. VMM_Service (_Assert_Range)
  1901. VMM_Service (_Sprintf)
  1902. VMM_Service (_PageChangePager)
  1903. VMM_Service (_RegCreateDynKey)
  1904. VMM_Service (_RegQueryMultipleValues)
  1905. // Additional timeslicer services
  1906. VMM_Service (Boost_Thread_With_VM)
  1907. /*ENDMACROS*/
  1908. // Flag definitions for Get_Boot_Flags
  1909. #define BOOT_CLEAN 0x00000001
  1910. #define BOOT_DOSCLEAN 0x00000002
  1911. #define BOOT_NETCLEAN 0x00000004
  1912. #define BOOT_INTERACTIVE 0x00000008
  1913. /*MACROS*/
  1914. VMM_Service (Get_Boot_Flags)
  1915. VMM_Service (Set_Boot_Flags)
  1916. // String and memory services
  1917. VMM_Service (_lstrcpyn)
  1918. VMM_Service (_lstrlen)
  1919. VMM_Service (_lmemcpy)
  1920. VMM_Service (_GetVxDName)
  1921. // For vwin32 use only
  1922. VMM_Service (Force_Mutexes_Free)
  1923. VMM_Service (Restore_Forced_Mutexes)
  1924. /*ENDMACROS*/
  1925. // Reclaimable low memory services
  1926. /*MACROS*/
  1927. VMM_Service (_AddReclaimableItem)
  1928. VMM_Service (_SetReclaimableItem)
  1929. VMM_Service (_EnumReclaimableItem)
  1930. /*ENDMACROS*/
  1931. // completely wake sys VM from idle state
  1932. /*MACROS*/
  1933. VMM_Service (Time_Slice_Wake_Sys_VM)
  1934. VMM_Service (VMM_Replace_Global_Environment)
  1935. VMM_Service (Begin_Non_Serial_Nest_V86_Exec)
  1936. VMM_Service (Get_Nest_Exec_Status)
  1937. /*ENDMACROS*/
  1938. // Bootlogging services
  1939. /*MACROS*/
  1940. VMM_Service (Open_Boot_Log)
  1941. VMM_Service (Write_Boot_Log)
  1942. VMM_Service (Close_Boot_Log)
  1943. VMM_Service (EnableDisable_Boot_Log)
  1944. VMM_Service (_Call_On_My_Stack)
  1945. /*ENDMACROS*/
  1946. // Another instance data service
  1947. /*MACROS*/
  1948. VMM_Service (Get_Inst_V86_Int_Vec_Base)
  1949. /*ENDMACROS*/
  1950. // Case insensitive functions -- SEE WARNINGS IN DOCS BEFORE USING!
  1951. /*MACROS*/
  1952. VMM_Service (_lstrcmpi)
  1953. VMM_Service (_strupr)
  1954. /*ENDMACROS*/
  1955. /*MACROS*/
  1956. VMM_Service (Log_Fault_Call_Out)
  1957. VMM_Service (_AtEventTime)
  1958. /*ENDMACROS*/
  1959. #endif /* WIN40SERVICES */
  1960. #ifdef WIN403SERVICES
  1961. //
  1962. // 4.03 Services
  1963. //
  1964. /*MACROS*/
  1965. VMM_Service (_PageOutPages)
  1966. /*ENDMACROS*/
  1967. // Flag definitions for _PageOutPages
  1968. #define PAGEOUT_PRIVATE 0x00000001
  1969. #define PAGEOUT_SHARED 0x00000002
  1970. #define PAGEOUT_SYSTEM 0x00000004
  1971. #define PAGEOUT_REGION 0x00000008
  1972. #define PAGEOUT_ALL (PAGEOUT_PRIVATE | PAGEOUT_SHARED | PAGEOUT_SYSTEM)
  1973. /*MACROS*/
  1974. VMM_Service (_Call_On_My_Not_Flat_Stack)
  1975. VMM_Service (_LinRegionLock)
  1976. VMM_Service (_LinRegionUnLock)
  1977. VMM_Service (_AttemptingSomethingDangerous)
  1978. VMM_Service (_Vsprintf)
  1979. VMM_Service (_Vsprintfw)
  1980. VMM_Service (Load_FS_Service)
  1981. VMM_Service (Assert_FS_Service)
  1982. VMM_StdCall_Service (RtlUnwind, 4)
  1983. VMM_StdCall_Service (RtlRaiseException, 1)
  1984. VMM_StdCall_Service (RtlRaiseStatus, 1)
  1985. VMM_StdCall_Service (KeGetCurrentIrql, 0)
  1986. VMM_FastCall_Service (KfRaiseIrql, 1)
  1987. VMM_FastCall_Service (KfLowerIrql, 1)
  1988. VMM_Service (_Begin_Preemptable_Code)
  1989. VMM_Service (_End_Preemptable_Code)
  1990. VMM_FastCall_Service (Set_Preemptable_Count, 1)
  1991. VMM_StdCall_Service (KeInitializeDpc, 3)
  1992. VMM_StdCall_Service (KeInsertQueueDpc, 3)
  1993. VMM_StdCall_Service (KeRemoveQueueDpc, 1)
  1994. VMM_StdCall_Service (HeapAllocateEx, 4)
  1995. VMM_StdCall_Service (HeapReAllocateEx, 5)
  1996. VMM_StdCall_Service (HeapGetSizeEx, 2)
  1997. VMM_StdCall_Service (HeapFreeEx, 2)
  1998. //VMM_Service (_Get_CPUID_Flags)
  1999. /*ENDMACROS*/
  2000. #endif /* WIN403SERVICES */
  2001. /*MACROS*/
  2002. End_Service_Table(VMM, VMM)
  2003. /*ENDMACROS*/
  2004. /*XLATOFF*/
  2005. #pragma warning (default:4003) // turn on not enough params warning
  2006. #ifndef try
  2007. #define try __try
  2008. #define except __except
  2009. #define finally  __finally
  2010. #define leave __leave
  2011. #define exception_code __exception_code
  2012. #endif
  2013. #ifndef EXCEPTION_EXECUTE_HANDLER
  2014. #define EXCEPTION_EXECUTE_HANDLER 1
  2015. #define EXCEPTION_CONTINUE_SEARCH 0
  2016. #define EXCEPTION_CONTINUE_EXECUTION -1
  2017. #endif
  2018. /*XLATON*/
  2019. #define COMNFS_FLAT 0xFFFFFFFF
  2020. #define ASD_MAX_REF_DATA    64     // If bigger than this, a checksum is used
  2021. struct _vmmguid {
  2022. unsigned long Data1;
  2023. unsigned short Data2;
  2024. unsigned short Data3;
  2025. unsigned char Data4[8];
  2026. };
  2027. typedef struct _vmmguid VMMGUID;
  2028. typedef VMMGUID     *VMMREFIID;
  2029. typedef DWORD ASD_RESULT;
  2030. #define ASD_ERROR_NONE     0x00000000
  2031. #define ASD_CHECK_FAIL     0x00000001 // The flag is set that this failed before
  2032. #define ASD_CHECK_SUCCESS   0x00000002 // The flag is set that this succeeded before
  2033. #define ASD_CHECK_UNKNOWN   0x00000003 // No flag is set
  2034. #define ASD_ERROR_BAD_TIME  0x00000004 // Under cli
  2035. #define ASD_REGISTRY_ERROR  0x00000005 // Unknown registry error
  2036. #define ASD_CLEAN_BOOT     0x00000006 // Clean booting fails everything
  2037. #define ASD_OUT_OF_MEMORY   0x00000007 // Ran out of memory (extremely rare)
  2038. #define ASD_FILE_ERROR     0x00000008 // Int 21 to flush the info file failed
  2039. #define ASD_ALREADY_SET     0x00000009 // ASD_CHECK* done twice on same vgOperation/pRefData
  2040. #define ASD_MISSING_CHECK   0x0000000A // ASD_DONE* on something not set
  2041. #define ASD_BAD_PARAMETER   0x0000000B // Invalid operation, refiid or ref pointer
  2042. #define ASD_OP_CHECK_AND_WRITE_FAIL_IF_UNKNOWN 0x00000000
  2043. #define ASD_OP_CHECK_AND_ALWAYS_WRITE_FAIL 0x00000001
  2044. #define ASD_OP_CHECK 0x00000002
  2045. #define ASD_OP_DONE_AND_SET_SUCCESS 0x00000003
  2046. #define ASD_OP_SET_FAIL  0x00000004
  2047. #define ASD_OP_SET_SUCCESS 0x00000005
  2048. #define ASD_OP_SET_UNKNOWN 0x00000006
  2049. #define ASD_OP_DONE 0x00000007
  2050. // Flag definitions for _Add/_Set/_EnumReclaimableItem
  2051. #define RS_RECLAIM 0x00000001
  2052. #define RS_RESTORE 0x00000002
  2053. #define RS_DOSARENA 0x00000004
  2054. // Structure definition for _EnumReclaimableItem
  2055. struct ReclaimStruc {
  2056.     ULONG   RS_Linear; // low (< 1meg) address of item
  2057.     ULONG   RS_Bytes; // size of item in bytes
  2058.     ULONG   RS_CallBack; // callback, if any (zero if none)
  2059.     ULONG   RS_RefData;  // reference data for callback, if any
  2060.     ULONG   RS_HookTable; // real-mode hook table (zero if none)
  2061.     ULONG   RS_Flags; // 0 or more of the RS_* equates
  2062. };
  2063. typedef struct ReclaimStruc *PReclaimStruc;
  2064. //
  2065. // Structures for Force_Mutexes_Free/Restore_Forced_Mutexes
  2066. //
  2067. typedef struct frmtx {
  2068.     struct frmtx *frmtx_pfrmtxNext;
  2069.     DWORD frmtx_hmutex;
  2070.     DWORD frmtx_cEnterCount;
  2071.     DWORD frmtx_pthcbOwner;
  2072.     DWORD frmtx_htimeout;
  2073. } FRMTX;
  2074. typedef struct vmmfrinfo {
  2075.     struct frmtx vmmfrinfo_frmtxDOS;
  2076.     struct frmtx vmmfrinfo_frmtxV86;
  2077.     struct frmtx vmmfrinfo_frmtxOther;
  2078. } VMMFRINFO;
  2079. /*
  2080.  *  Data structure for _GetDemandPageInfo
  2081.  */
  2082. struct DemandInfoStruc {
  2083.     ULONG DILin_Total_Count; /* # pages in linear address space */
  2084.     ULONG DIPhys_Count;  /* Count of phys pages */
  2085.     ULONG DIFree_Count;  /* Count of free phys pages */
  2086.     ULONG DIUnlock_Count; /* Count of unlocked Phys Pages */
  2087.     ULONG DILinear_Base_Addr; /* Base of pageable address space */
  2088.     ULONG DILin_Total_Free; /* Total Count of free linear pages */
  2089.     /*
  2090.      * The following 5 fields are all running totals, kept from the time
  2091.      * the system was started
  2092.      */
  2093.     ULONG DIPage_Faults; /* total page faults */
  2094.     ULONG DIPage_Ins; /* calls to pagers to page in a page */
  2095.     ULONG DIPage_Outs; /* calls to pagers to page out a page*/
  2096.     ULONG DIPage_Discards; /* pages discarded w/o calling pager */
  2097.     ULONG DIInstance_Faults; /* instance page faults */
  2098.     ULONG DIPagingFileMax; /* maximum # of pages that could be in paging file */
  2099.     ULONG DIPagingFileInUse; /* # of pages of paging file currently in use */
  2100.     ULONG DICommit_Count; /* Total committed memory, in pages */
  2101.     ULONG DIReserved[2]; /* Reserved for expansion */
  2102. };
  2103. /*
  2104.  *  Data structure for _AddInstanceItem
  2105.  */
  2106. struct InstDataStruc {
  2107.     ULONG InstLinkF;     /* INIT <0> RESERVED */
  2108.     ULONG InstLinkB;     /* INIT <0> RESERVED */
  2109.     ULONG InstLinAddr;     /* Linear address of start of block */
  2110.     ULONG InstSize;     /* Size of block in bytes */
  2111.     ULONG InstType;     /* Type of block */
  2112. };
  2113. /*
  2114.  *  Values for InstType
  2115.  */
  2116. #define INDOS_FIELD 0x100 /* Bit indicating INDOS switch requirements */
  2117. #define ALWAYS_FIELD 0x200 /* Bit indicating ALWAYS switch requirements */
  2118. #define OPTIONAL_FIELD 0x400 /* Bit indicating optional instancing requirements */
  2119. /*
  2120.  *  Data structure for Hook_Invalid_Page_Fault handlers.
  2121.  *
  2122.  *  This is the structure of the "invalid page fault information"
  2123.  *  which is pointed to by EDI when Invalid page fault hookers
  2124.  *  are called.
  2125.  *
  2126.  *  Page faults can occur on a VM which is not current by touching the VM at
  2127.  *  its high linear address.  In this case, IPF_FaultingVM may not be the
  2128.  *  current VM, it will be set to the VM whos high linear address was touched.
  2129.  */
  2130. struct IPF_Data {
  2131.     ULONG IPF_LinAddr;     /* CR2 address of fault */
  2132.     ULONG IPF_MapPageNum;   /* Possible converted page # of fault */
  2133.     ULONG IPF_PTEEntry;     /* Contents of PTE that faulted */
  2134.     ULONG IPF_FaultingVM;   /* May not = Current VM (IPF_V86PgH set) */
  2135.     ULONG IPF_Flags;     /* Flags */
  2136. };
  2137. /*
  2138.  *
  2139.  * Install_Exception_Handler data structure
  2140.  *
  2141.  */
  2142. struct Exception_Handler_Struc {
  2143.     ULONG EH_Reserved;
  2144.     ULONG EH_Start_EIP;
  2145.     ULONG EH_End_EIP;
  2146.     ULONG EH_Handler;
  2147. };
  2148. /*
  2149.  *  Flags passed in new memory manager functions
  2150.  */
  2151. /* PageReserve arena values */
  2152. #define PR_PRIVATE  0x80000400 /* anywhere in private arena */
  2153. #define PR_SHARED   0x80060000 /* anywhere in shared arena */
  2154. #define PR_SYSTEM   0x80080000 /* anywhere in system arena */
  2155. /* PageReserve flags */
  2156. #define PR_FIXED    0x00000008 /* don't move during PageReAllocate */
  2157. #define PR_4MEG     0x00000001 /* allocate on 4mb boundary */
  2158. #define PR_STATIC   0x00000010 /* see PageReserve documentation */
  2159. /* PageCommit default pager handle values */
  2160. #define PD_ZEROINIT 0x00000001 /* swappable zero-initialized pages */
  2161. #define PD_NOINIT   0x00000002 /* swappable uninitialized pages */
  2162. #define PD_FIXEDZERO 0x00000003  /* fixed zero-initialized pages */
  2163. #define PD_FIXED    0x00000004 /* fixed uninitialized pages */
  2164. /* PageCommit flags */
  2165. #define PC_FIXED    0x00000008 /* pages are permanently locked */
  2166. #define PC_LOCKED   0x00000080 /* pages are made present and locked*/
  2167. #define PC_LOCKEDIFDP 0x00000100  /* pages are locked if swap via DOS */
  2168. #define PC_WRITEABLE 0x00020000  /* make the pages writeable */
  2169. #define PC_USER     0x00040000 /* make the pages ring 3 accessible */
  2170. #define PC_INCR     0x40000000 /* increment "pagerdata" each page */
  2171. #define PC_PRESENT  0x80000000 /* make pages initially present */
  2172. #define PC_STATIC   0x20000000 /* allow commit in PR_STATIC object */
  2173. #define PC_DIRTY    0x08000000 /* make pages initially dirty */
  2174. #define PC_CACHEDIS 0x00100000  /* Allocate uncached pages - new for WDM */
  2175. #define PC_CACHEWT  0x00080000  /* Allocate write through cache pages - new for WDM */
  2176. /* PageCommitContig additional flags */
  2177. #define PCC_ZEROINIT 0x00000001  /* zero-initialize new pages */
  2178. #define PCC_NOLIN   0x10000000 /* don't map to any linear address */
  2179. /*MTRR type flags */
  2180. #define MTRR_UC 0
  2181. #define MTRR_WC 1
  2182. #define MTRR_WT 4
  2183. #define MTRR_WP 5
  2184. #define MTRR_WB 6
  2185. /*
  2186.  *  Structure and flags for PageQuery
  2187.  */
  2188. #ifndef _WINNT_
  2189. typedef struct _MEMORY_BASIC_INFORMATION {
  2190.     ULONG mbi_BaseAddress;
  2191.     ULONG mbi_AllocationBase;
  2192.     ULONG mbi_AllocationProtect;
  2193.     ULONG mbi_RegionSize;
  2194.     ULONG mbi_State;
  2195.     ULONG mbi_Protect;
  2196.     ULONG mbi_Type;
  2197. } MEMORY_BASIC_INFORMATION, *PMEMORY_BASIC_INFORMATION;
  2198. #define PAGE_NOACCESS        0x01
  2199. #define PAGE_READONLY        0x02
  2200. #define PAGE_READWRITE        0x04
  2201. #define MEM_COMMIT      0x1000
  2202. #define MEM_RESERVE      0x2000
  2203. #define MEM_FREE     0x10000
  2204. #define MEM_PRIVATE     0x20000
  2205. #endif
  2206. /***ET+ PD - Pager Descriptor
  2207.  *
  2208.  *  A PD describes a set of routines to call to bring a page into
  2209.  *  the system or to get it out.  Each committed page in the system
  2210.  *  has an associated PD, a handle to which is stored in the page's
  2211.  *  VP.
  2212.  *
  2213.  *  For any field that is 0, the pager will not be notified
  2214.  *  when that action takes place.
  2215.  *
  2216.  *  For the purpose of pagers, a page can be in one of the two states
  2217.  *  describing its current contents:
  2218.  *
  2219.  * clean - page has not been written to since its last page out
  2220.  * dirty - page has been written to since its last page out
  2221.  *
  2222.  *  A page also is in one of two persistent states:
  2223.  *
  2224.  * virgin - page has never been written to since it was committed
  2225.  * tainted - page has been written to since it was committed
  2226.  *
  2227.  *  Note that a tainted page may be either dirty or clean, but a
  2228.  *  virgin page is by definition clean.
  2229.  *
  2230.  *  Examples of PDs:
  2231.  *
  2232.  * For 32-bit EXE code or read-only data:
  2233.  *
  2234.  *   pd_virginin = routine to load page from an exe file
  2235.  *   pd_taintedin = 0
  2236.  *   pd_cleanout = 0
  2237.  *   pd_dirtyout = 0
  2238.  *   pd_virginfree = 0
  2239.  *    pd_taintedfree = 0
  2240.  *    pd_dirty = 0
  2241.  *   pd_type = PD_PAGERONLY
  2242.  *
  2243.  * For 32-bit EXE writeable data:
  2244.  *
  2245.  *   pd_virginin = routine to load page from an exe file
  2246.  *   pd_taintedin = routine to load page from swap file
  2247.  *   pd_cleanout = 0
  2248.  *   pd_dirtyout = routine to write a page out to the swap file
  2249.  *   pd_virginfree = 0
  2250.  *   pd_taintedfree = routine to free page from the swap file
  2251.  *   pd_dirty = routine to free page from the swap file
  2252.  *   pd_type = PD_SWAPPER
  2253.  *
  2254.  * For zero-initialized swappable data:
  2255.  *
  2256.  *   pd_virginin = routine to zero-fill a page
  2257.  *   pd_taintedin = routine to load page from swap file
  2258.  *   pd_cleanout = 0
  2259.  *   pd_dirtyout = routine to write a page out to the swap file
  2260.  *   pd_virginfree = 0
  2261.  *   pd_taintedfree = routine to free page from the swap file
  2262.  *   pd_dirty = routine to free page from the swap file
  2263.  *   pd_type = PD_SWAPPER
  2264.  */
  2265. /* typedefs for various pager functions */
  2266. typedef ULONG _cdecl FUNPAGE(PULONG ppagerdata, PVOID ppage, ULONG faultpage);
  2267. typedef FUNPAGE * PFUNPAGE;
  2268. struct pd_s {
  2269.     /*
  2270.      * The following four fields are entry points in the pager which
  2271.      * we call to page in or page out a page. The following parameters
  2272.      * are passed to the pager during these calls:
  2273.      *
  2274.      * ppagerdata - pointer to the pager-specific dword of data
  2275.      *  stored with the virtual page. The pager is
  2276.      *  free to modify the contents of this dword
  2277.      *  DURING the page in or out, but not afterwards.
  2278.      *
  2279.      * ppage - pointer to page going in or out (a ring 0 alias
  2280.      *     to the physical page).  The pager should use this
  2281.      *     address to access the contents of the page.
  2282.      *
  2283.      * faultpage - faulting linear page number for page-ins, -1 for
  2284.      * page-outs.  This address should not be accessed
  2285.      * by the pager.  It is provided for information
  2286.      * only.  Note that a single page can be mapped at
  2287.      * more than one linear address because of the
  2288.      * MapIntoV86 and LinMapIntoV86 services.
  2289.      *
  2290.      * The pager should return non-0 if the page was successfully
  2291.      * paged, or 0 if it failed.
  2292.      */
  2293.     PFUNPAGE pd_virginin;   /* in - while page has never been written to */
  2294.     PFUNPAGE pd_taintedin;  /* in - page written to at least once */
  2295.     PFUNPAGE pd_cleanout;   /* out - page not written to since last out */
  2296.     PFUNPAGE pd_dirtyout;   /* out - page was written to since last out */
  2297.     /*
  2298.      * The pd_*free routines are used to inform the pager when the last
  2299.      * reference to a virtual page controlled by the pager is
  2300.      * decommitted.  A common use of this notification is to
  2301.      * free space in a backing file, or write the page contents
  2302.      * into the backing file.
  2303.      *
  2304.      * These calls take the same parameters as the page-out and -in
  2305.      * functions, but no return value is recognized.  The "ppage"
  2306.      * and "faultpage" parameters will always be 0.
  2307.      */
  2308.     PFUNPAGE pd_virginfree;  /* decommit of never-written-to page */
  2309.     PFUNPAGE pd_taintedfree; /* decommit of page written to at least once*/
  2310.     /*
  2311.      * The pd_dirty routine is used to inform the pager when the
  2312.      * memory manager detects that a page has been written to.  The memory
  2313.      * manager does not detect the write at the instant it occurs, so
  2314.      * the pager should not depend upon prompt notification.  A common
  2315.      * use of this notification might be to invalidate cached data.
  2316.      * If the page was dirtied in more than one memory context,
  2317.      * the pager's pd_dirty routine will be called once for each
  2318.      * context.
  2319.      *
  2320.      * These calls take the same parameters as the page-out and -in
  2321.      * functions except that the "ppage" parameter isn't valid and
  2322.      * no return value is recognized.
  2323.      */
  2324.     PFUNPAGE pd_dirty;
  2325.     /*
  2326.      * The pd_type field gives the sytem information about the
  2327.      * overcommit characteristics of pages controlled by this pager.
  2328.      * The following are allowable values for the field:
  2329.      *
  2330.      * PD_SWAPPER - under some conditions, pages of this type
  2331.      *     may be paged out into the swap file
  2332.      * PD_PAGERONLY - pages controlled by this pager will never
  2333.      *     be paged out to the swap file
  2334.      *
  2335.      * In addition, the following value may be or'ed in to the pd_type field:
  2336.      *
  2337.      * PD_NESTEXEC - must be specified if either the pd_cleanout or pd_dirtyout
  2338.      *     functions perform nested excecution or block using the
  2339.      *     BLOCK_SVC_INTS flag.  To be safe, this flag should always be
  2340.      *     specified if the pager does any sort of file i/o to anything
  2341.      *     other than the default paging file.
  2342.      */
  2343.     ULONG pd_type;
  2344. };
  2345. typedef struct pd_s PD;
  2346. typedef PD * PPD;
  2347. /* values for pd_type */
  2348. #define PD_SWAPPER  0 /* pages need direct accounting in swap file */
  2349. #define PD_PAGERONLY 1   /* pages will never be swapped */
  2350. #define PD_NESTEXEC 2 /* page out funtion uses nested execution */
  2351. #endif // Not_VxD
  2352. /*
  2353.  *  The size of a page of memory
  2354.  */
  2355. #define PAGESHIFT   12
  2356. #define PAGESIZE    (1 << PAGESHIFT)
  2357. #define PAGEMASK    (PAGESIZE - 1)
  2358. #define PAGE(p) ((DWORD)(p) >> PAGESHIFT)
  2359. #define NPAGES(cb) (((DWORD)(cb) + PAGEMASK) >> PAGESHIFT)
  2360. /*
  2361.  *  Address space (arena) boundaries
  2362.  */
  2363. #define MAXSYSTEMLADDR     ((ULONG) 0xffbfffff)    /* 4 gig - 4meg */
  2364. #define MINSYSTEMLADDR     ((ULONG) 0xc0000000)    /* 3 gig */
  2365. #define MAXSHAREDLADDR     ((ULONG) 0xbfffffff)
  2366. #define MINSHAREDLADDR     ((ULONG) 0x80000000)    /* 2   gig */
  2367. #define MAXPRIVATELADDR     ((ULONG) 0x7fffffff)
  2368. #define MINPRIVATELADDR     ((ULONG) 0x00400000)    /* 4 meg */
  2369. #define MAXDOSLADDR ((ULONG) 0x003fffff)
  2370. #define MINDOSLADDR ((ULONG) 0x00000000)
  2371. #define MAXSYSTEMPAGE     (MAXSYSTEMLADDR >> PAGESHIFT)
  2372. #define MINSYSTEMPAGE     (MINSYSTEMLADDR >> PAGESHIFT)
  2373. #define MAXSHAREDPAGE     (MAXSHAREDLADDR >> PAGESHIFT)
  2374. #define MINSHAREDPAGE     (MINSHAREDLADDR >> PAGESHIFT)
  2375. #define MAXPRIVATEPAGE     (MAXPRIVATELADDR >> PAGESHIFT)
  2376. #define MINPRIVATEPAGE     (MINPRIVATELADDR >> PAGESHIFT)
  2377. #define MAXDOSPAGE (MAXDOSLADDR >> PAGESHIFT)
  2378. #define MINDOSPAGE (MINDOSLADDR >> PAGESHIFT)
  2379. #define CBPRIVATE (1 + MAXPRIVATELADDR - MINPRIVATELADDR)
  2380. #define CBSHARED (1 + MAXSHAREDLADDR - MINSHAREDLADDR)
  2381. #define CBSYSTEM (1 + MAXSYSTEMLADDR - MINSYSTEMLADDR)
  2382. #define CBDOS (1 + MAXDOSLADDR - MINDOSLADDR)
  2383. #define CPGPRIVATE (1 + MAXPRIVATEPAGE - MINPRIVATEPAGE)
  2384. #define CPGSHARED (1 + MAXSHAREDPAGE - MINSHAREDPAGE)
  2385. #define CPGSYSTEM (1 + MAXSYSTEMPAGE - MINSYSTEMPAGE)
  2386. #define CPGDOS (1 + MAXDOSPAGE - MINDOSPAGE)
  2387. /*XLATOFF*/
  2388. /*
  2389.  *  Largest object that could theoretically be allocated
  2390.  */
  2391. #define CBMAXALLOC (max(CBSHARED,max(CBPRIVATE, CBSYSTEM)))
  2392. #define CPGMAXALLOC (max(CPGSHARED,max(CPGPRIVATE, CPGSYSTEM)))
  2393. /*XLATON*/
  2394. /* ASM
  2395. IFDEF DEBUG
  2396. DebFar EQU NEAR PTR
  2397. ELSE
  2398. DebFar EQU SHORT
  2399. ENDIF
  2400. */
  2401. #ifndef Not_VxD
  2402. /******************************************************************************
  2403.  *
  2404.  *      EQUATES FOR SYSTEM_CONTROL CALLS
  2405.  *
  2406.  *****************************************************************************/
  2407. /*
  2408.  *  SYS_CRITICAL_INIT is a device init call.  Devices that have a
  2409.  *  critical function that needs initializing before interrupts are
  2410.  *  enabled should do it at Sys_Critical_Init. Devices which REQUIRE a
  2411.  *  certain range of V86 pages to operate (such as the VDD video memory)
  2412.  *  should claim them at Sys_Critical_Init.  SYS VM Simulate_Int,
  2413.  *  Exec_Int ACTIVITY IS NOT ALLOWED.  Returning carry aborts device
  2414.  *  load only.
  2415.  */
  2416. #define SYS_CRITICAL_INIT   0x0000 /* Devices req'd for virt mode */
  2417. /*
  2418.  *  DEVICE_INIT is where most devices do the bulk of their initialization.
  2419.  *  SYS VM Simulate_Int, Exec_Int activity is allowed. Returning carry
  2420.  *  aborts device load only.
  2421.  */
  2422. #define DEVICE_INIT 0x0001     /* All other devices init */
  2423. /*
  2424.  *  INIT_COMPLETE is the final phase of device init called just before the
  2425.  *  WIN386 INIT pages are released and the Instance snapshot is taken.
  2426.  *  Devices which wish to search for a region of V86 pages >= A0h to use
  2427.  *  should do it at INIT_COMPLETE.
  2428.  *  SYS VM Simulate_Int, Exec_Int activity is allowed. Returning carry
  2429.  *  aborts device load only.
  2430.  */
  2431. #define INIT_COMPLETE     0x0002 /* All devices initialized */
  2432. /* --------------- INITIALIZATION CODE AND DATA DISCARDED ------------------ */
  2433. /*
  2434.  *  Same as VM_Init, except for SYS VM.
  2435.  */
  2436. #define SYS_VM_INIT 0x0003     /* Execute the system VM */
  2437. /*
  2438.  *  Same as VM_Terminate, except for SYS VM (Normal WIN386 exit ONLY, on a crash
  2439.  *  exit this call is not made).  SYS VM Simulate_Int, Exec_Int activity is
  2440.  *  allowed.  This and Sys_VM_Terminate2 are your last chances to access
  2441.  *  and/or lock pageable data.
  2442.  */
  2443. #define SYS_VM_TERMINATE    0x0004 /* System VM terminated */
  2444. /*
  2445.  *  System_Exit call is made when WIN386 is exiting either normally or via
  2446.  *  a crash.  INTERRUPTS ARE ENABLED.  Instance snapshot has been restored.
  2447.  *  SYS VM Simulate_Int, Exec_Int ACTIVITY IS NOT ALLOWED.
  2448.  */
  2449. #define SYSTEM_EXIT 0x0005     /* Devices prepare to exit */
  2450. /*
  2451.  *  SYS_CRITICAL_EXIT call is made when WIN386 is exiting either normally or via
  2452.  *  a crash.  INTERRUPTS ARE DISABLED. SYS VM Simulate_Int, Exec_Int ACTIVITY
  2453.  *   IS NOT ALLOWED.
  2454.  */
  2455. #define SYS_CRITICAL_EXIT   0x0006 /* System critical devices reset */
  2456. /*
  2457.  *  Create_VM creates a new VM.  EBX = VM handle of new VM.  Returning
  2458.  *  Carry will fail the Create_VM.
  2459.  */
  2460. #define CREATE_VM 0x0007
  2461. /*
  2462.  *  Second phase of Create_VM. EBX = VM handle of new VM.  Returning
  2463.  *  Carry will cause the VM to go Not_Executeable, then be destroyed.
  2464.  *  VM Simulate_Int, Exec_Int activity is NOT allowed.
  2465.  */
  2466. #define VM_CRITICAL_INIT    0x0008
  2467. /*
  2468.  *  Third phase of Create_VM.  EBX = VM handle of new VM.  Returning
  2469.  *  Carry will cause the VM to go Not_Executeable, then be destroyed.
  2470.  *  VM Simulate_Int, Exec_Int activity is allowed.
  2471.  */
  2472. #define VM_INIT  0x0009
  2473. /*
  2474.  *  NORMAL (First phase) of Destroy_VM.  EBX = VM Hanlde.  This occurs
  2475.  *  on normal termination of the VM.  Call cannot be failed.  VM
  2476.  *  Simulate_Int, Exec_Int activity is allowed.
  2477.  */
  2478. #define VM_TERMINATE     0x000A /* Still in VM -- About to die */
  2479. /*
  2480.  *  Second phase of Destroy_VM.  EBX = VM Handle, EDX = Flags (see
  2481.  *  below).  Note that in the case of destroying a running VM, this is
  2482.  *  the first call made (VM_Terminate call does not occur).  Call cannot
  2483.  *  be failed. VM Simulate_Int, Exec_Int activity is NOT allowed.
  2484.  */
  2485. #define VM_NOT_EXECUTEABLE  0x000B /* Most devices die (except VDD) */
  2486. /*
  2487.  *  Final phase of Destroy_VM. EBX = VM Handle.  Note that considerable
  2488.  *  time can elaps between the VM_Not_Executeable call and this call.
  2489.  *  Call cannot be failed.  VM Simulate_Int, Exec_Int activity is NOT
  2490.  *  allowed.
  2491.  */
  2492. #define DESTROY_VM 0x000C     /* VM's control block about to go */
  2493. /*
  2494.  *  Flags for VM_Not_Executeable control call (passed in EDX)
  2495.  */
  2496. #define VNE_CRASHED_BIT     0x00 /* VM was crashed */
  2497. #define VNE_CRASHED (1 << VNE_CRASHED_BIT)
  2498. #define VNE_NUKED_BIT     0x01 /* VM was destroyed while active */
  2499. #define VNE_NUKED (1 << VNE_NUKED_BIT)
  2500. #define VNE_CREATEFAIL_BIT  0x02 /* Some device failed Create_VM */
  2501. #define VNE_CREATEFAIL     (1 << VNE_CREATEFAIL_BIT)
  2502. #define VNE_CRINITFAIL_BIT  0x03 /* Some device failed VM_Critical_Init */
  2503. #define VNE_CRINITFAIL     (1 << VNE_CRINITFAIL_BIT)
  2504. #define VNE_INITFAIL_BIT    0x04 /* Some device failed VM_Init */
  2505. #define VNE_INITFAIL     (1 << VNE_INITFAIL_BIT)
  2506. #define VNE_CLOSED_BIT     0x05
  2507. #define VNE_CLOSED (1 << VNE_CLOSED_BIT)
  2508. /*
  2509.  *  EBX = VM Handle. Call cannot be failed.
  2510.  */
  2511. #define VM_SUSPEND 0x000D     /* VM not runnable until resume */
  2512. /*
  2513.  *  EBX = VM Handle. Returning carry fails and backs out the resume.
  2514.  */
  2515. #define VM_RESUME 0x000E     /* VM is leaving suspended state */
  2516. /*
  2517.  *  EBX = VM Handle to set device focus to.  EDX = Device ID if device
  2518.  *  specific setfocus, == 0 if device critical setfocus (all devices).
  2519.  *  THIS CALL CANNOT BE FAILED.
  2520.  *
  2521.  *  NOTE: In case where EDX == 0, ESI is a FLAG word that indicates
  2522.  *  special functions. Currently Bit 0 being set indicates that this
  2523.  *  Device critical set focus is also "VM critical".  It means that we
  2524.  *  do not want some other VM to take the focus from this app now.  This
  2525.  *  is primarily used when doing a device critical set focus to Windows
  2526.  *  (the SYS VM) it is interpreted by the SHELL to mean "if an old app
  2527.  *  currently has the Windows activation, set the activation to the
  2528.  *  Windows Shell, not back to the old app".  ALSO in the case where Bit
  2529.  *  0 is set, EDI = The VM handle of the VM that is "having trouble".
  2530.  *  Set this to 0 if there is no specific VM associated with the
  2531.  *  problem.
  2532.  */
  2533. #define SET_DEVICE_FOCUS    0x000F
  2534. /*
  2535.  *  EBX = VM Handle going into message mode.  THIS CALL CANNOT BE FAILED.
  2536.  */
  2537. #define BEGIN_MESSAGE_MODE  0x0010
  2538. /*
  2539.  *  EBX = VM Handle leaving message mode.  THIS CALL CANNOT BE FAILED.
  2540.  */
  2541. #define END_MESSAGE_MODE    0x0011
  2542. /* ----------------------- SPECIAL CONTROL CALLS --------------------------- */
  2543. /*
  2544.  *  Request for reboot.  Call cannot be failed.
  2545.  */
  2546. #define REBOOT_PROCESSOR    0x0012 /* Request a machine reboot */
  2547. /*
  2548.  *  Query_Destroy is an information call made by the SHELL device before
  2549.  *  an attempt is made to initiate a destroy VM sequence on a running VM
  2550.  *  which has not exited normally.  EBX = VM Handle.  Returning carry
  2551.  *  indicates that a device "has a problem" with allowing this.  THE
  2552.  *  DESTROY SEQUENCE CANNOT BE ABORTED HOWEVER, this decision is up to
  2553.  *  the user.  All this does is indicate that there is a "problem" with
  2554.  *  allowing the destroy.  The device which returns carry should call
  2555.  *  the SHELL_Message service to post an informational dialog about the
  2556.  *  reason for the problem.
  2557.  */
  2558. #define QUERY_DESTROY     0x0013 /* OK to destroy running VM? */
  2559. /* ----------------------- DEBUGGING CONTROL CALL -------------------------- */
  2560. /*
  2561.  *  Special call for device specific DEBUG information display and activity.
  2562.  */
  2563. #define DEBUG_QUERY 0x0014
  2564. /* -------- CALLS FOR BEGIN/END OF PROTECTED MODE VM EXECUTION ------------- */
  2565. /*
  2566.  *   About to run a protected mode application.
  2567.  *   EBX = Current VM handle.
  2568.  *   EDX = Flags
  2569.  *   EDI -> Application Control Block
  2570.  *   Returning with carry set fails the call.
  2571.  */
  2572. #define BEGIN_PM_APP     0x0015
  2573. /*
  2574.  *  Flags for Begin_PM_App (passed in EDX)
  2575.  */
  2576. #define BPA_32_BIT 0x01
  2577. #define BPA_32_BIT_FLAG     1
  2578. /*
  2579.  *  Protected mode application is terminating.
  2580.  *  EBX = Current VM handle.  THIS CALL CAN NOT FAIL.
  2581.  *  EDI -> Application Control Block
  2582.  */
  2583. #define END_PM_APP 0x0016
  2584. /*
  2585.  *  Called whenever system is about to be rebooted.  Allows VxDs to clean
  2586.  *  up in preperation for reboot.
  2587.  */
  2588. #define DEVICE_REBOOT_NOTIFY 0x0017
  2589. #define CRIT_REBOOT_NOTIFY  0x0018
  2590. /*
  2591.  *  Called when VM is about to be terminated using the Close_VM service
  2592.  *  EBX = Current VM handle (Handle of VM to close)
  2593.  *  EDX = Flags
  2594.  *   CVNF_CRIT_CLOSE = 1 if VM is in critical section while closing
  2595.  */
  2596. #define CLOSE_VM_NOTIFY     0x0019
  2597. #define CVNF_CRIT_CLOSE_BIT 0
  2598. #define CVNF_CRIT_CLOSE     (1 << CVNF_CRIT_CLOSE_BIT)
  2599. /*
  2600.  *  Power management event notification.
  2601.  *  EBX = 0
  2602.  *  ESI = event notification message
  2603.  *  EDI -> DWORD return value; VxD's modify the DWORD to return info, not EDI
  2604.  *  EDX is reserved
  2605.  */
  2606. #define POWER_EVENT 0x001A
  2607. #define SYS_DYNAMIC_DEVICE_INIT 0x001B
  2608. #define SYS_DYNAMIC_DEVICE_EXIT 0x001C
  2609. /*
  2610.  *  Create_THREAD creates a new thread.  EDI = handle of new thread.
  2611.  *  Returning Carry will fail the Create_THREAD. Message is sent in the
  2612.  *  context of the creating thread.
  2613.  *
  2614.  */
  2615. #define  CREATE_THREAD 0x001D
  2616. /*
  2617.  *  Second phase of creating a thread. EDI = handle of new thread.  Call cannot
  2618.  *  be failed. VM Simulate_Int, Exec_Int activity is not allowed (because
  2619.  *  never allowed in non-initial threads). Message is sent in the context
  2620.  *  of the newly created thread.
  2621.  *
  2622.  */
  2623. #define  THREAD_INIT 0x001E
  2624. /*
  2625.  *  Normal (first) phase of Destroy_THREAD. EDI = handle of thread.
  2626.  *  This occurs on normal termination of the thread.  Call cannot be failed.
  2627.  *  Simulate_Int, Exec_Int activity is allowed.
  2628.  */
  2629. #define  TERMINATE_THREAD  0x001F
  2630. /*
  2631.  *  Second phase of Destroy_THREAD.  EDI = Handle of thread,