INFO: MmMapLockedPages Returns Actual Virtual Address In SP4

Article translations Article translations
Article ID: 199311 - View products that this article applies to.
This article was previously published under Q199311
Expand all | Collapse all

SUMMARY

In the Windows NT 4.0 Service Pack 3 and earlier versions, MmMapLockedPages returns the base virtual address (a page-aligned address) that maps the locked pages for the range described by the MDL. However, this has been changed in Service Pack 4 and later versions to return the actual virtual address including the byte offset within a page of the buffer described by the MDL.

MORE INFORMATION

In Windows NT 4.0 Service Pack 3 and earlier versions, if the buffer described by the MDL is not page-aligned then you have to add the offset stored in the MDL with the base virtual address returned by the function to get the actual address as shown here:

VirtualAddress = (PVOID) (((ULONG) MmMapLockedPages(Mdl, Mode)) +  MmGetMdlByteOffset(Mdl));
				


In Service Pack 4 and later versions, this function has been altered to consider the byte offset stored in the MDL and returns the actual virtual address as shown here:

VirtualAddress = (PVOID) MmMapLockedPages(Mdl, Mode);
				


To fix the above mentioned inconsistencies and make the code portable across all versions of Windows NT, use the following:

VirtualAddress = (PVOID) (((ULONG) MmMapLockedPages(Mdl, Mode)) | MmGetMdlByteOffset(Mdl));
				


or

VirtualAddress = (PVOID)(((ULONG)PAGE_ALIGN(MmMapLockedPages(Mdl, Mode))) + MmGetMdlByteOffset(Mdl));
				


Microsoft has confirmed the pre-Service Pack 4 behavior of this function to be a bug and has fixed it in order to resolve memory addressing issues on future releases of Windows NT; Windows NT 64-bit in particular.

REFERENCES

Properties

Article ID: 199311 - Last Review: February 12, 2007 - Revision: 2.2
APPLIES TO
  • Microsoft Win32 Device Driver Kit for Windows NT 3.5
  • Microsoft Win32 Device Driver Kit for Windows NT 3.51
  • Microsoft Win32 Device Driver Kit for Windows NT 4.0
  • Microsoft Win32 Device Driver Kit for Windows 2000
Keywords: 
kbinfo kbkmode kboswinnt400fix KB199311

Give Feedback

 

Contact us for more help

Contact us for more help
Connect with Answer Desk for expert help.
Get more support from smallbusiness.support.microsoft.com