Re: Help!!! Memory allocation!!!



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.



.



Relevant Pages

  • Re: Assigning data structures to certain memory locations during porting
    ... "Dynamically allocating and freeing memory is often discouraged in ... there's no possibility of running ouf of memory later on." ... I thought the primary reason for dynamic allocation was to allocate ... The pool is just a preallocated chunk of memory which is ...
    (comp.arch.embedded)
  • Re: Pagefile use increase when repeatedly executing programs
    ... Using Performance Monitor to Identify a Pool Leak ... as my pagefile use steadily increases, ... scanner, updated my computer bios, defragmented memory and pagefile, ... You could confirm that by doing a perfmon on the Nonpaged Pool objects ...
    (microsoft.public.windowsxp.general)
  • Re: User mode APCs, paged or non-paged heap?
    ... application chunk of memory managed by the alloc, malloc, calloc, etc. used ... non-paged pool and the other the paged pool. ... You can allocate from either ... I think 'heap' is not to be used in kernel mode. ...
    (microsoft.public.development.device.drivers)
  • Re: kernel memory
    ... Kernel virtual address space is used for a number of things. ... Pat of this are the memory pools, from which you can allocate memory for your drivers. ... You can allocate physical memory using a DDI like MmAllocatePagesForMdl and then map those into the system address space. ... That's probably the easiest way to explain why you cannot allocate 1GB of non-paged pool for yourself:) ...
    (microsoft.public.development.device.drivers)
  • Re: [RFC][PATCH 0/3] TCP/IP Critical socket communication mechanism
    ... - allocate from the global critical receive pool on receive ... where we now completely deadlock and never recover, including shutting off the router and firewall, because they don't have enough memory to recv packets either. ...
    (Linux-Kernel)