This section describes how paging works using the Windows 3.1 model. Then, changes to the model for Windows 95 are described.
Under Windows 3.1, VxD code segments are always locked. This implies that VxD code is normally not preempted, with the following exceptions:
The terms pageable and swappable are synonymous. The VMM uses paging as its form of memory management. It does not swap segments or tasks. Where you see the word swap or a derivative thereof, substitute the corresponding form of the word page.
Windows 95 supports VxD with pageable code segments. While this has the benefits of allowing rarely-used code segments to get paged out, thus freeing up memory, it does come at the cost of adding more rules to follow.
Here are additional rules that apply to Windows 95 pageable VxDs. They are in addition to the existing rules from Windows 3.1.
pushfd ; Disable interrupts to protect a global
cli ; variable, so that the update is atomic
mov eax, pHead ; Get the head of the list
mov ecx, [eax].pNext ; And delete it from the list
mov pHead, ecx
popfd ; End of critical section
If this code fragment resides in pageable memory, then it may be possible for code to interrupt this sequence and corrupt the linked list. Using standard synchronization techniques such as semaphores, you can serialize access to the data structure, but since there are hidden possibilities for deadlocks, the safest way to guarantee the correctness of the code is to keep it in locked memory. Furthermore, the data in which the linked list resides should also reside in locked memory.
If Windows 95 is paging through MS-DOS, allowing VxD code segments to be paged out would be catastrophic. In such situations, the VMM automatically locks all VxD code segments (and VxDLdr does the same for dynamically-loaded VxDs).