MmMapLockedPagesSpecifyCache() throws exception 0xC0000141 ( STATUS_INVALID_ADDRESS )

To allocate and map DMA buffer to user space kernel driver use following systems calls on Windows XP x64:

AllocateCommonBuffer();
IoAllocateMdl();
MmBuildMdlForNonPagedPool();
MmMapLockedPagesSpecifyCache();

It works for cached buffer but for non-cached buffer mMapLockedPagesSpecifyCache()
throws exception 0xC0000141 ( STATUS_INVALID_ADDRESS ).

[I use the same system calls in another driver and there I have no problems.]

Is there somebody who can explain to me such a mysterious behaviour ?

Please look at declaration of MmGetSystemAddressForMdlSafe() macro in ntddk.h , so that you will see whether one should call MmMapLockedPagesSpecifyCache() for MDL that specifies a virtual memory buffer in nonpaged pool. There is no need to call this routine, because the virtual buffer is already mapped to non-paged pool. Apparently, when you call this routine and there is no conflict between caching type of the buffer and the one that you are requesting, the system just does not do anything, because, objectively, it does not have to - it does not need to modify PTEs in order to return buffer’s existing virtual address. This is why you get a success when there is no caching type conflict - it just returns without doing anything. However, if there caching type conflict, it has to fail, because you request it to modify PTEs that describe the target buffer…

BTW, IIRC, if you try the same thing on checked built of the OS, you are going to cause an assertion regardless of caching type - the OS asserts that MDL_MAPPED_TO_SYSTEM_VA and
MDL_SOURCE_IS_NONPAGED_POOL flags are clear in MDL that gets passed to MmMapLockedPagesSpecifyCache()…

Anton Bassov

Thanks Anton,
but it still doesn’t solve my problem. I checked macro MmGetSystemAddressForMdlSafe() in ntddk.h , and it returns kernel virtual address.

I am trying to have access to non-cached buffer from user space. If there is no exceptions in MmMapLockedPagesSpecifyCache(), it returns me a user virtual adress. But not always.

Can you help me also with UserMode and non-cached buffer?

PS: I have a physical address and a kernel virtual address from AllocateCommonBuffer().

I believe if you look at the definition of AllocateCommonBuffer() in the
WDK you will see why you can’t map it. From the WDK:

“For these processors, the operating system always allocates
common buffers that are cache-enabled,”

WDK is talking about x86 and x64 chips. So you are trying to map cached
memory as non-cached also, which won’t work if I remember correctly.

-Jeff

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of
xxxxx@daptechnology.com
Sent: Tuesday, June 24, 2008 11:13 AM
To: Windows File Systems Devs Interest List
Subject: RE:[ntfsd] MmMapLockedPagesSpecifyCache() throws exception
0xC0000141 ( STATUS_INVALID_ADDRESS )

Thanks Anton,
but it still doesn’t solve my problem. I checked macro
MmGetSystemAddressForMdlSafe() in ntddk.h , and it returns kernel
virtual address.

I am trying to have access to non-cached buffer from user space. If
there is no exceptions in MmMapLockedPagesSpecifyCache(), it returns me
a user virtual adress. But not always.

Can you help me also with UserMode and non-cached buffer?

PS: I have a physical address and a kernel virtual address from
AllocateCommonBuffer().


NTFSD is sponsored by OSR

For our schedule debugging and file system seminars
(including our new fs mini-filter seminar) visit:
http://www.osr.com/seminars

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

> I am trying to have access to non-cached buffer from user space.

Very bad idea for the security reasons…

Please search the archives, and see what people are told when they say they wan to allocate a buffer in the kernel and map it to the UM…

Anton Bassov

Thanks a lot to all of you !

Now it’s clear to me.
Unfortunately this “bad idea” will remain because of the rest of the software ;-(