MmMapLockedPagesSpecifyCache in W2k3

Hello.
When starting my filter driver on Windows 2003 Server SP1, then after I
start the DriverVerifier tester, the function MmMapLockedPagesSpecifyCache
runs smoothly.
Doing the same, but without DriverVerifier, this function raises Exception
0xC0000141[STATUS_INVALID_ADDRESS].
I have tested this also on WindowsXP Professional SP2. Here this function
runs smoothly in both cases, independently on DriverVerifier.
Any idea where might be the problem ?


pMdlBuffer = IoAllocateMdl (pBuffer,
nBufferLen,
FALSE,
FALSE,
NULL);
if (pMdlBuffer == NULL) {
return STATUS_INSUFFICIENT_RESOURCES;
}

_try {
MmProbeAndLockPages (pMdlBuffer,
KernelMode,
IoModifyAccess);
}
_except (EXCEPTION_EXECUTE_HANDLER) {
IoFreeMdl (pMdlBuffer);
return GetExceptionCode ();
}

KeStackAttachProcess (g_G.sharedProcess, &ApcState);

_try {
pUserBuffer = MmMapLockedPagesSpecifyCache (pMdlBuffer, UserMode,
MmNonCached, NULL, FALSE, NormalPagePriority);
// ^^^ this function fails
}
_except(EXCEPTION_EXECUTE_HANDLER) {
status = GetExceptionCode ();
}

KeUnstackDetachProcess (&ApcState);

Thanks for your suggestions,
VPR

You specify MmNonCached as CacheType.
If the buffer is already mapped with a different cache type the functions
fails. Regular memory is mapped as cached; are you sure that you really need
“MmNonCached”?

Alexei.

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com]On Behalf Of Vladimir Pribyl
Sent: Friday, May 27, 2005 7:17 AM
To: Windows File Systems Devs Interest List
Subject: [ntfsd] MmMapLockedPagesSpecifyCache in W2k3

Hello.
When starting my filter driver on Windows 2003 Server SP1, then after I
start the DriverVerifier tester, the function MmMapLockedPagesSpecifyCache
runs smoothly.
Doing the same, but without DriverVerifier, this function raises Exception
0xC0000141[STATUS_INVALID_ADDRESS].
I have tested this also on WindowsXP Professional SP2. Here this function
runs smoothly in both cases, independently on DriverVerifier.
Any idea where might be the problem ?


pMdlBuffer = IoAllocateMdl (pBuffer,
nBufferLen,
FALSE,
FALSE,
NULL);
if (pMdlBuffer == NULL) {
return STATUS_INSUFFICIENT_RESOURCES;
}

_try {
MmProbeAndLockPages (pMdlBuffer,
KernelMode,
IoModifyAccess);
}
_except (EXCEPTION_EXECUTE_HANDLER) {
IoFreeMdl (pMdlBuffer);
return GetExceptionCode ();
}

KeStackAttachProcess (g_G.sharedProcess, &ApcState);

_try {
pUserBuffer = MmMapLockedPagesSpecifyCache (pMdlBuffer, UserMode,
MmNonCached, NULL, FALSE, NormalPagePriority);
// ^^^ this function fails
}
_except(EXCEPTION_EXECUTE_HANDLER) {
status = GetExceptionCode ();
}

KeUnstackDetachProcess (&ApcState);

Thanks for your suggestions,
VPR


Questions? First check the IFS FAQ at
https://www.osronline.com/article.cfm?id=17

You are currently subscribed to ntfsd as: xxxxx@vmware.com
To unsubscribe send a blank email to xxxxx@lists.osr.com

Vladimir Pribyl wrote:

When starting my filter driver on Windows 2003 Server SP1, then after I
start the DriverVerifier tester, the function MmMapLockedPagesSpecifyCache
runs smoothly.
Doing the same, but without DriverVerifier, this function raises Exception
0xC0000141[STATUS_INVALID_ADDRESS].
I have tested this also on WindowsXP Professional SP2. Here this function
>

This looks to be a tough one to me.

The most obvious (like anything about this is obvious?) thing to check
is that the caching attributes match for the memory mappings (you can’t
map the same pages cached in one place and non-cached elsewhere, for
example).

To debug this, obviously, try it on the checked kernel and hal (how many
times a week do I write this, I wonder), and breakpoint when the
exception is raised if at all possible. You’ll almost certainly be in
MmMapUserAddressesToPage. All I can suggest is that if you can
determine the code path through this function, we can probably help you
figure out the reason for the failure.

But, I’d definitely start by being quite sure that the cachine
attributes were in order.

Peter
OSR

Forget about SpecifyCache. When you map the MDL, the caching mode of the
mapping must match the caching mode of the original pages, which are - as all
user mode pages - are cached. The OS bugchecks on mismatch, since such a
mapping violates the cache coherence.

In fact, you NEVER need NonCached for RAM. You only need NonCached on
device memory-mapped registers (i.e. in MmMapIoSpace), and they are never
described by the MDL in practice.

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

----- Original Message -----
From: “Vladimir Pribyl”
Newsgroups: ntfsd
To: “Windows File Systems Devs Interest List”
Sent: Friday, May 27, 2005 6:16 PM
Subject: [ntfsd] MmMapLockedPagesSpecifyCache in W2k3

> Hello.
> When starting my filter driver on Windows 2003 Server SP1, then after I
> start the DriverVerifier tester, the function MmMapLockedPagesSpecifyCache
> runs smoothly.
> Doing the same, but without DriverVerifier, this function raises Exception
> 0xC0000141[STATUS_INVALID_ADDRESS].
> I have tested this also on WindowsXP Professional SP2. Here this function
> runs smoothly in both cases, independently on DriverVerifier.
> Any idea where might be the problem ?
>
> …
> pMdlBuffer = IoAllocateMdl (pBuffer,
> nBufferLen,
> FALSE,
> FALSE,
> NULL);
> if (pMdlBuffer == NULL) {
> return STATUS_INSUFFICIENT_RESOURCES;
> }
>
> _try {
> MmProbeAndLockPages (pMdlBuffer,
> KernelMode,
> IoModifyAccess);
> }
> _except (EXCEPTION_EXECUTE_HANDLER) {
> IoFreeMdl (pMdlBuffer);
> return GetExceptionCode ();
> }
>
> KeStackAttachProcess (g_G.sharedProcess, &ApcState);
>
> _try {
> pUserBuffer = MmMapLockedPagesSpecifyCache (pMdlBuffer, UserMode,
> MmNonCached, NULL, FALSE, NormalPagePriority);
> // ^^^ this function fails
> }
> _except(EXCEPTION_EXECUTE_HANDLER) {
> status = GetExceptionCode ();
> }
>
> KeUnstackDetachProcess (&ApcState);
> …
>
> Thanks for your suggestions,
> VPR
>
>
>
> —
> Questions? First check the IFS FAQ at
https://www.osronline.com/article.cfm?id=17
>
> You are currently subscribed to ntfsd as: xxxxx@storagecraft.com
> To unsubscribe send a blank email to xxxxx@lists.osr.com

Many thanks for your suggestion.
Changing the MmNonCached parameter to MmCached helped.

So one small final comment - it’s interesting that this is affected by
DriverVerifier settings. I thought this should be checked by DriverVerifier,
but it seems he “corrects” this, but he doesn’t reports it to the user.

Best regards,
VPR

Vladimir Pribyl wrote:

Many thanks for your suggestion.
Changing the MmNonCached parameter to MmCached helped.

So one small final comment - it’s interesting that this is affected by
DriverVerifier settings. I thought this should be checked by DriverVerifier,
but it seems he “corrects” this, but he doesn’t reports it to the user.

Interesting. I don’t see how/why this wouldn’t raise the same exception
when Verifier is enabled. After checking a few parameters, verifier
simply passes the call to MmMapLockedPagesSpecifyCache using your
parameter for CacheType.

Hmmmm…

Peter
OSR