Virtual Expanded Memory Manager

EMS services are implemented under MVDM using a virtual device driver known as the Virtual Expanded Memory Manager (VEMM), which offers a separate EMS emulation to each VDM. This implementation is accomplished by placing most VEMM control structures in a per-VDM data area outside the V86 mode address space. Each VDM has up to 255 handles, 15 alternate register sets, remappable conventional memory for operating system use, and a 16KB "raw" block size.

VEMM prehooks interrupt vector 67h through a VDH service to catch software interrupts for EMS services. Prehooking means that VEMM gains control before the V86 mode interrupt vector is called. VEMM also provides a V86 mode stub driver used to indicate to DOS applications that EMS is available. This stub must hook INT 67h so that applications can find a particular string in the header to determine if EMS is available. When, as in the typical case, applications have not also hooked INT 67h, VEMM handles service requests at prehook time. When INT 67 has been hooked, VEMM handles requests when the stub's hook calls it by doing an INT 67h from inside the stub.

To prevent VDM's from grabbing large amounts of EMS memory, there is a configurable default per VDM limit. VEMM depends heavily upon the memory manager. EMS object allocation, reallocation, or deallocation is accomplished by requesting corresponding services from VDH services. Most VEMM creation time setup is postponed until the first INT 67h service request is made. Figure "Expanded Memory Manager Control Flow" shows the flow of control when a DOS application makes an EMS service request from within a VDM:

  • INT 67h service requests are trapped by the Virtual DOS Machine Manager and routed to VEMM.

  • The VEMM makes the appropriate requests to VDH services to allocate or manipulate the EMS object.

    Expanded Memory Manager Control Flow

    During the initialization of the VDM the VDM Manager loads and initializes the EMS DOS stub device driver into the VDM address space.

    The VDM Application can use either of two methods to test for the existence of the VEMM:

  • Issue an open request (INT 21h Function 3DH) using the guaranteed device name of the VEMM driver. If the open function succeeds, either the driver is present or a file with the same name coincidentally exists on the default disk drive. To rule out the latter, the application can use IOCTL(INT 21h Function 44H) subfunctions 00h and 07h to ensure that VEMM is present. Don't forget to use INT 21H Function 3Eh to close the handle that was obtained from the open function, so that the handle can be reused for another file or device.

  • Look for a special signature in the EMS DOS stub device driver which signals the VDM Application that EMS is available. This search is done by using the address that is found in the INT 67h vector to inspect the device header of the presumed VEMM which is, in this case, the fooling EMS DOS stub device driver. Interrupt handlers and device drivers must use this method. If the VEMM seems to be present, the name field at a special offset of the device header contains a special string. This method is not only avoiding the relatively high overhead of an VDM DOS open function but is nearly foolproof. However, it is somewhat less well behaved because it involves inspection of memory that does not belong to the application.

    The only task of the EMS DOS stub device driver is to tell the VDM DOS application that EMS is available. As soon as this is done the regular EMS business can start as explained in the following points:

  • The VDM Application issues a INT 67h service request.

  • The VDM Manager loads the VEMM.

  • The VDM Manager initialization, creation, termination calls for EMM-objects.

  • The VDM Manager traps the VDM application's INT 67h service request and routes it to VEMM.

  • The VDM callback for V86 call with far return.

  • The VEMM requests corresponding services from the VDH services: