Hi,
I have code that has run fine on Windows2000, XP, and EmbeddedXP.
When I run it on Windows Server 2003, it fails.
I have a hardware device with a dynamic PCI aperture that can be
programmed to map physical memory. The device can then directly
read/write into the main systems memory.
The driver code uses AllocateCommonBuffer to allocate a contiguous block
of non-cached memory. It programs the PCI device with the LogicalAddress.
I then give a UserMode program a pointer to this memory, so he can
read/write directly into this memory that the device is accessing.
I do this by calling IoAllocateMdl, MmBuildMdlForNonPagedPool, and
finally MmMapLockedPagesSpecifyCache to obtain a UserVirtualAddress to
the buffer.
This code has run fine for years on 2000, XP, and EmbeddedXP. However,
with Windows 2003 server (both std & enterprise), I get an exception
when calling MmMapLockedPagesSpecifyCache. The exception returned is
0xC0000141, STATUS_INVALID_ADDRESS
Here’s code snippet:
ulLength = 0x20000;
pKernelVA = pDevExt->pMyAdapter->DmaOperations->AllocateCommonBuffer
(pDevExt->pMyAdapter,
ulLength,
&pLogicalAddress,
FALSE);
pMdl = IoAllocateMdl(pKernelVA, ulLength, FALSE, FALSE, NULL);
if (pMdl == NULL)
{
return STATUS_INSUFFICIENT_RESOURCES;
}
//*------------------------------------------------------------------------
//* Update the MDL that specifies our virtual memory buffer in nonpaged
//* pool to describe the underlying physical pages.
//*------------------------------------------------------------------------
try
{
MmBuildMdlForNonPagedPool (pMdl);
}
except (EXCEPTION_EXECUTE_HANDLER)
{
IoFreeMdl (pMdl);
return STATUS_INSUFFICIENT_RESOURCES;
}
//*------------------------------------------------------------------------
//* Map physical pages described by MDL and return UserVA.
//*------------------------------------------------------------------------
try
{
pUserVA = MmMapLockedPagesSpecifyCache (pMdl, UserMode,
MmNonCached, NULL, FALSE, NormalPagePriority);
}
except (EXCEPTION_EXECUTE_HANDLER)
{
status = GetExceptionCode();
CallDdk IoFreeMdl (zpvMdl);
return status;
}
Any hints would be appreciated,
John