Re: Help!!! Memory allocation!!!
- From: Danial.F <DanialF@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Wed, 18 Jun 2008 09:25:03 -0700
Acturally, I'm trying to map the continuous memory to user space address. I
dont know if the MmAllocateContiguousMemory didnt allocate the continuous
memory from non-paged pool but from paged pool or some other places, what
should I do? Lock it first whatever it is allocated from nonpaged pool or not
and then map it to user mode? or call MmBuildMdlForNonPagedPool even it is
not allocated from the nonpaged pool?
"Dan Mihai [MSFT]" wrote:
Also, unless you are trying to map these physical pages into a UserMode.
virtual address, don't call MmMapLockedPages either for an MDL created with
MmBuildMdlForNonPagedPool. MmMapLockedPages (AccessMode == KernelMode) would
waste another KernelMode virtual address mapping, because you already have a
KernelMode virtual address from the MmAllocateContiguousMemory call. Use
the VA returned by MmAllocateContiguousMemory.
I recommend testing this driver after "verifier.exe /standard /driver
mydriver.sys" on Windows Vista. Verifier will check all of these rules for
these API calls and will complain in case they are incorrect/wasteful.
http://msdn.microsoft.com/en-us/library/ms792871.aspx has information about
this.
Dan
--
This posting is provided "AS IS" with no warranties, and confers no rights.
"Pavel Lebedinsky [MSFT]" <pavel@xxxxxxxxxxxxxxxxxxxx> wrote in message
news:uaYoSIG0IHA.2068@xxxxxxxxxxxxxxxxxxxxxxx
Q1. In MSDN, it says that MmAllocateContiguousMemory first attemps to
allocate a continuous range of memory from Nonpaged pool, if it fails,
then
allocates from unused pages. So, here, if it fails allcating from
Nonpaged
pool and then successfully allocates the continuous range of memory, is
this
continuous range of memory still nonpaged or not?
It is.
Q2. MmBuildMdlForNonPagedPool, this routine receives an MDL that
specifies a
virtual memory buffer in nonpaged pool, and updates it to describe the
underlying physical pages. And the MDL virtual address that is input must
be
within the nonpaged portion of system space. So, here, if
MmAllocateContiguousMemory fails to allocate the continuous memory in
nonpaged pool but successfully allocates from unused pages, can I still
call
MmBuildMdlForNonPagedPool to build my MDL?
Yes.
Q3. If a memory is allcated from nonpaged pool, do I still call
MmProbeAndLockPages
Non-paged memory is already locked, there is no need to explicitly
lock it. MmProbeAndLockPages will actually assert on checked builds
if you give it an MDL with MDL_SOURCE_IS_NONPAGED_POOL
flag set.
If I want the access rights to be read, write and modify, how should I
do?
Set the third parameter as IoReadAccess | IoWriteAccess | IoModifyAccess
or
otherwise?
Specify IoWriteAccess.
- References:
- Re: Help!!! Memory allocation!!!
- From: Pavel Lebedinsky [MSFT]
- Re: Help!!! Memory allocation!!!
- From: Dan Mihai [MSFT]
- Re: Help!!! Memory allocation!!!
- Prev by Date: Re: Help!!! Memory allocation!!!
- Next by Date: Re: Contact for digitally signing Vista32 and 64 drivers
- Previous by thread: Re: Help!!! Memory allocation!!!
- Next by thread: Re: Help!!! Memory allocation!!!
- Index(es):
Relevant Pages
|