Using MmMapLockedPagesSpecifyCache when MDL_MAPPED_TO_SYSTEM_VA

I have a MDL which another component, which I don’t control,
has already mapped to a system va (at least MDL_MAPPED_TO_SYSTEM_VA
is set.)

I wanted to map the MDL into a helper process, so I called
MmMapLockedPagesSpecifyCache, but I’m getting an
ASSERT() because MDL_MAPPED_TO_SYSTEM_VA is set.

I tried copying the Mdl using IoAllocateMdl() and
IoBuildPartialMdl(), however, this appears to have
preserved the MDL_MAPPED_TO_SYSTEM_VA flag.

Is there a way I can get this memory mapped into
my helper process, or do I just need a completely
different solution?

Is their a better way to copy the MDL?

Would it be a stupid thing to clear MDL_MAPPED_TO_SYSTEM_VA
and MappedSystemVa fields? (I can gaurentee that the original
MDL will still be valid when I IoFreeMdl() my copy.)

Thanks for any insight,

  • Joseph

Have you tried calling MmProbeAndLockPages with the system address or
using MmBuildMdlForNonPagedPool to initialize the new Mdl using the
system address?

-p

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Joseph Galbraith
Sent: Wednesday, August 18, 2004 11:05 AM
To: Windows System Software Devs Interest List
Subject: [ntdev] Using MmMapLockedPagesSpecifyCache when
MDL_MAPPED_TO_SYSTEM_VA

I have a MDL which another component, which I don’t control, has already
mapped to a system va (at least MDL_MAPPED_TO_SYSTEM_VA is set.)

I wanted to map the MDL into a helper process, so I called
MmMapLockedPagesSpecifyCache, but I’m getting an
ASSERT() because MDL_MAPPED_TO_SYSTEM_VA is set.

I tried copying the Mdl using IoAllocateMdl() and IoBuildPartialMdl(),
however, this appears to have preserved the MDL_MAPPED_TO_SYSTEM_VA
flag.

Is there a way I can get this memory mapped into my helper process, or
do I just need a completely different solution?

Is their a better way to copy the MDL?

Would it be a stupid thing to clear MDL_MAPPED_TO_SYSTEM_VA and
MappedSystemVa fields? (I can gaurentee that the original MDL will
still be valid when I IoFreeMdl() my copy.)

Thanks for any insight,

  • Joseph

Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

You are currently subscribed to ntdev as: xxxxx@windows.microsoft.com
To unsubscribe send a blank email to xxxxx@lists.osr.com

Build a new MDL from scratch from the mapped system-space region.

Maxim Shatskih, Windows DDK MVP
StorageCraft Corporation
xxxxx@storagecraft.com
http://www.storagecraft.com

----- Original Message -----
From: “Joseph Galbraith”
To: “Windows System Software Devs Interest List”
Sent: Wednesday, August 18, 2004 10:05 PM
Subject: [ntdev] Using MmMapLockedPagesSpecifyCache when
MDL_MAPPED_TO_SYSTEM_VA

> I have a MDL which another component, which I don’t control,
> has already mapped to a system va (at least MDL_MAPPED_TO_SYSTEM_VA
> is set.)
>
> I wanted to map the MDL into a helper process, so I called
> MmMapLockedPagesSpecifyCache, but I’m getting an
> ASSERT() because MDL_MAPPED_TO_SYSTEM_VA is set.
>
> I tried copying the Mdl using IoAllocateMdl() and
> IoBuildPartialMdl(), however, this appears to have
> preserved the MDL_MAPPED_TO_SYSTEM_VA flag.
>
> Is there a way I can get this memory mapped into
> my helper process, or do I just need a completely
> different solution?
>
> Is their a better way to copy the MDL?
>
> Would it be a stupid thing to clear MDL_MAPPED_TO_SYSTEM_VA
> and MappedSystemVa fields? (I can gaurentee that the original
> MDL will still be valid when I IoFreeMdl() my copy.)
>
> Thanks for any insight,
>
> - Joseph
>
>
>
> —
> Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256
>
> You are currently subscribed to ntdev as: xxxxx@storagecraft.com
> To unsubscribe send a blank email to xxxxx@lists.osr.com

Maxim S. Shatskih wrote:

Build a new MDL from scratch from the mapped system-space region.

Thanks. That is exactly what I was looking for.

When I build the new MDL, do I have to call MmProbeAndLockPages?

I suspect so, but I was wondering if I could call
MmBuildMdlForNonPagedPool() instead, since I know the pages
are paged in and locked already?

Thanks,

Joseph

> When I build the new MDL, do I have to call MmProbeAndLockPages?

No, use MmBuildMdlForNonPagedPool.
Just be careful to not destroy the master MDL before this MDL.

Maxim Shatskih, Windows DDK MVP
StorageCraft Corporation
xxxxx@storagecraft.com
http://www.storagecraft.com

Okay, I did this, and it works pretty well, except that I just
got this assert in MmProbeAndLockPages():

*** Assertion failed: Pfn1->u3.e1.LockCharged == 1
*** Source File: d:\xpsp1\base\ntos\mm\iosup.c, line 1083

Does anyone have any clue what I did wrong?? I’ve
got no clue what this means.

The code snippet follows:

// Extract system buffer address and length
void* pRxBuffer = ::RxLowIoGetBufferAddress(RxContext);
ULONG uLength = RxContext->LowIoContext.ParamsFor.ReadWrite.ByteCount;

// Build meself a new MDL that I can use to map the memory
// into the helper process…
info.pMdl = ::IoAllocateMdl(pRxBuffer, uLength, FALSE, FALSE, 0);
if ( info.pMdl == 0 )
::ExRaiseStatus(STATUS_INSUFFICIENT_RESOURCES);

::MmProbeAndLockPages(info.pMdl, KernelMode, IoWriteAccess);

void* pBuffer = ::MmMapLockedPagesSpecifyCache(info.pMdl,
UserMode,
MmCached,
NULL,
FALSE,
NormalPagePriority);

Thanks,

Joseph

Maxim S. Shatskih wrote:

Build a new MDL from scratch from the mapped system-space region.

Maxim Shatskih, Windows DDK MVP
StorageCraft Corporation
xxxxx@storagecraft.com
http://www.storagecraft.com

----- Original Message -----
From: “Joseph Galbraith”
> To: “Windows System Software Devs Interest List”
> Sent: Wednesday, August 18, 2004 10:05 PM
> Subject: [ntdev] Using MmMapLockedPagesSpecifyCache when
> MDL_MAPPED_TO_SYSTEM_VA
>
>
>
>>I have a MDL which another component, which I don’t control,
>>has already mapped to a system va (at least MDL_MAPPED_TO_SYSTEM_VA
>>is set.)
>>
>>I wanted to map the MDL into a helper process, so I called
>>MmMapLockedPagesSpecifyCache, but I’m getting an
>>ASSERT() because MDL_MAPPED_TO_SYSTEM_VA is set.
>>
>>I tried copying the Mdl using IoAllocateMdl() and
>>IoBuildPartialMdl(), however, this appears to have
>>preserved the MDL_MAPPED_TO_SYSTEM_VA flag.
>>
>>Is there a way I can get this memory mapped into
>>my helper process, or do I just need a completely
>>different solution?
>>
>>Is their a better way to copy the MDL?
>>
>>Would it be a stupid thing to clear MDL_MAPPED_TO_SYSTEM_VA
>>and MappedSystemVa fields? (I can gaurentee that the original
>>MDL will still be valid when I IoFreeMdl() my copy.)
>>
>>Thanks for any insight,