I will map a memory between a driver and a user-mode application in my driver

The pseudo code
Step 1: MmAllocateContiguousMemor
Step 2: IoAllocateMd
Step 3: MmProbeAndLockPage


Is any potential dangerous when map memory is in non â??paged pool

Thank

Re: Is any potential dangerous when driver use "MmProbeAndLockPages" for non-page pool? by Eliyas

Eliyas
Mon May 03 23:49:19 CDT 2004

http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&oe=UTF-8&th=3a62fb006d14157d&rnum=2

--
--
-Eliyas
This posting is provided "AS IS" with no warranties, and confers no rights.




"wei" <anonymous@discussions.microsoft.com> wrote in message
news:B99187B8-C8F4-4160-9B26-C6B5A18FC749@microsoft.com...
> I will map a memory between a driver and a user-mode application in my
driver.
>
>
> The pseudo code:
> Step 1: MmAllocateContiguousMemory
> Step 2: IoAllocateMdl
> Step 3: MmProbeAndLockPages
>
>
> Is any potential dangerous when map memory is in non -paged pool?
>
> Thanks
>



Re: Is any potential dangerous when driver use ?MmProbeAndLockPages? for non-page pool? by Tim

Tim
Tue May 04 00:35:31 CDT 2004

wei <anonymous@discussions.microsoft.com> wrote:

>I will map a memory between a driver and a user-mode application in my driver.
>
>The pseudo code:
>Step 1: MmAllocateContiguousMemory
>Step 2: IoAllocateMdl
>Step 3: MmProbeAndLockPages

Instead of steps 2 and 3, you should call MmBuildMdlForNonPagedPool. When
you allocate from non-paged pool, the pages are already probed and locked.

>Is any potential dangerous when map memory is in non ?paged pool?

Well, it depends on the reason you are exposing it to user space.
--
- Tim Roberts, timr@probo.com
Providenza & Boekelheide, Inc

Re: Is any potential dangerous when driver use "MmProbeAndLockPages" for non-page pool? by Maxim

Maxim
Tue May 04 07:24:47 CDT 2004

You do not need contiguous memory for this.

The general principle is:

- the memory allocator inside the kernel is ExAllocatePoolWithTag or - for
DMAable memory - ->AllocateCommonBuffer.

- forget about MmAllocate funcitons, they are for VERY special uses only.

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


"wei" <anonymous@discussions.microsoft.com> wrote in message
news:B99187B8-C8F4-4160-9B26-C6B5A18FC749@microsoft.com...
> I will map a memory between a driver and a user-mode application in my
driver.
>
>
> The pseudo code:
> Step 1: MmAllocateContiguousMemory
> Step 2: IoAllocateMdl
> Step 3: MmProbeAndLockPages
>
>
> Is any potential dangerous when map memory is in non -paged pool?
>
> Thanks
>



Re: Is any potential dangerous when driver use "MmProbeAndLockPages" for non-page pool? by Maxim

Maxim
Tue May 04 07:26:05 CDT 2004

> But I am confused about MmProbeAndLockPagesand MmBuildMdlForNonPagedPool?
>
> They seem have the same function to fill the MDL information. What different
about two
functions?

The first one addrefs the reference counts on the pages. The second does not.
The first requires MmUnlockPages for undo. The second has no undo.
The first can be used on any memory kind. The second is for NPP only.

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



Re: Is any potential dangerous when driver use ?MmProbeAndLockPages? for non-page pool? by Tim

Tim
Wed May 05 22:03:23 CDT 2004

wei <anonymous@discussions.microsoft.com> wrote:

>
>Thank you so much.
>
>But I am confused about MmProbeAndLockPagesand MmBuildMdlForNonPagedPool?
>
>They seem have the same function to fill the MDL information.
>What different about two functions?

MmProbeAndLockPages is used when you have a buffer that has been handed to
you from a user-mode process. Such a buffer is unreliable; it might be
paged out, it might have been freed, etc. MmProbeAndLockPages tests every
page in the range to make sure it is still valid and still in memory, then
locks the pages into memory so they cannot be paged out, and then builds an
MDL to describe the locked pages.

MmBuildMdlForNonPagedPool is used when you want to build an MDL for a piece
of kernel memory from the non-paged pool. Such a buffer is guaranteed to
be available and permanently resident in memory. Thus, although
MmProbeAndLockPages will probably still work, everything it does is a waste
of time.
--
- Tim Roberts, timr@probo.com
Providenza & Boekelheide, Inc