From: ysht on
Hi,
I'm Yot and I'm writing a driver.

Here is my driver code:
===
DeviceExtension->SystemVirtualAddress = ExAllocatePool( NonPagedPool , Size6M );
DeviceExtension->Mdl = IoAllocateMdl( DeviceExtension->SystemVirtualAddress,
Size6M, FALSE, FALSE, NULL );
DeviceExtension->UserVirtualAddress = MmMapLockedPagesSpecifyCache(
DeviceExtension->Mdl,
UserMode, MmNonCached, NULL,
FALSE, NormalPagePriority);
===

This code code works well in WindowsXP Professional Version 2002 SP3.
(MmMapLockedPagesSpecifyCache returns non-NULL value.)

But in Windows Server 2003 R2 Standard Edition SP3,
MmMapLockedPagesSpecifyCache returns NULL.

Therefore I use WindowsXP,but want to actually Windows Server 2003 now.

Can anyone provide suggestions ?
Any help or guidance would be appreciated.

Thanks!


From: Maxim S. Shatskih on
> But in Windows Server 2003 R2 Standard Edition SP3,
> MmMapLockedPagesSpecifyCache returns NULL.

So what? you're out of system PTEs, just handle such a thing properly.

--
Maxim S. Shatskih
Windows DDK MVP
maxim(a)storagecraft.com
http://www.storagecraft.com

From: ysht on
Thanks,Maxim.

Could you answer one more ?

Did you mean that MmMapLockedPagesSpecificCache failed
(returned NULL) for lack of system PTEs ?


Yot.

(2010/07/06 4:32), Maxim S. Shatskih wrote:
>> But in Windows Server 2003 R2 Standard Edition SP3,
>> MmMapLockedPagesSpecifyCache returns NULL.
>
> So what? you're out of system PTEs, just handle such a thing properly.
>

From: Pavel Lebedinsky [MSFT] on
> DeviceExtension->SystemVirtualAddress = ExAllocatePool( NonPagedPool ,
> Size6M );
> DeviceExtension->Mdl = IoAllocateMdl(
> DeviceExtension->SystemVirtualAddress,
> Size6M, FALSE, FALSE, NULL );
> DeviceExtension->UserVirtualAddress = MmMapLockedPagesSpecifyCache(
> DeviceExtension->Mdl,
> UserMode, MmNonCached, NULL,
> FALSE, NormalPagePriority);
> ===
>
> This code code works well in WindowsXP Professional Version 2002 SP3.
> (MmMapLockedPagesSpecifyCache returns non-NULL value.)
>
> But in Windows Server 2003 R2 Standard Edition SP3,
> MmMapLockedPagesSpecifyCache returns NULL.


Two problems here:

1. You need to call MmBuildMdlForNonPagedPool before attempting to
map the pages.

2. Nonpaged pool memory is fully cached, and mapping it as MmNonCached
is not allowed. You need to either a) use MmCached when mapping the MDL,
or b) if you really need a non-cached mapping, use
MmAllocatePagesForMdlEx (instead of ExAllocatePool) to allocate pages
with the MmNonCached attribute.

--
Pavel Lebedinsky/Windows Fundamentals Test
This posting is provided "AS IS" with no warranties, and confers no rights.


From: ysht on
Pavel,Thanks a lot.

I will take your advice into account and try it.

Thank you very much.
(Pavel-san,domo arigatou.)

Yot.

(2010/07/06 13:56), Pavel Lebedinsky [MSFT] wrote:
>> DeviceExtension->SystemVirtualAddress = ExAllocatePool( NonPagedPool ,
>> Size6M );
>> DeviceExtension->Mdl = IoAllocateMdl(
>> DeviceExtension->SystemVirtualAddress,
>> Size6M, FALSE, FALSE, NULL );
>> DeviceExtension->UserVirtualAddress = MmMapLockedPagesSpecifyCache(
>> DeviceExtension->Mdl,
>> UserMode, MmNonCached, NULL,
>> FALSE, NormalPagePriority);
>> ===
>>
>> This code code works well in WindowsXP Professional Version 2002 SP3.
>> (MmMapLockedPagesSpecifyCache returns non-NULL value.)
>>
>> But in Windows Server 2003 R2 Standard Edition SP3,
>> MmMapLockedPagesSpecifyCache returns NULL.
>
>
> Two problems here:
>
> 1. You need to call MmBuildMdlForNonPagedPool before attempting to
> map the pages.
>
> 2. Nonpaged pool memory is fully cached, and mapping it as MmNonCached
> is not allowed. You need to either a) use MmCached when mapping the MDL,
> or b) if you really need a non-cached mapping, use
> MmAllocatePagesForMdlEx (instead of ExAllocatePool) to allocate pages
> with the MmNonCached attribute.
>