> 1. the
difference between MDL and MDL chain.can I build directly a
MDL chain?
An MDL describes a single virtually contiguous buffer and associates it with the (probably, but not necessarily) series of physical page numbers which ācontainā those virtual addresses.
In normal use (if weāre not building our own MDLs) the fact that the MDL exists is also evidence that the buffer is locked into those physical pages (āpinnedā is the usual Unix term) so that it canāt move until itās unlocked. When you complete an IO that has an MDL attached to its IRP, the buffer will be unlocked and the MDL deallocated, āall at onceā from our point of view.
An MDL chain is simply multiple MDLs in a singly-linked list. Each describes a different virtually contiguous buffer.
We normally donāt see MDL chains coming to us with IRPs from normal application IO requests, because the normal application IO APIs only permit the specification of a single buffer that will be set up for ādirect IOā. MDL chains are usually (I hesitate to say āalwaysā, but certainly āusuallyā) built by other drivers. The NDIS stack uses
The first MDL in an MDL chain is normally pointed to by the MdlAddress pointer in an IRP. I donāt think thereās provision for MDL chains not pointed to by an IRP. The data structures certainly allow it, but thereās nothing that would automatically
Can you build your own MDL chain? Sure - just call IoAllocateMdl with a non-null Irp pointer, where the Irp already has an MDL that it points to. Your new MDL gets added to the tail of the list, or to the head if you specified False for the SecondaryBuffer argument.
- Can i define a instance of MDL and then map it to some memory? How?
One of my pet topics. The āhowā depends on where the memory came from. If itās originally a per-process address you use IoAllocateMdl, then MmProbeAndLockPages. Same if itās in pageable system-wide memory like the paged pool. If itās a system-space address for something in nonpaged pool, you can use IoAllocateMdl and then MmBuildMdlForNonPagedPool.
- ExAllocatePool VS IoAllocateMdl
Pools are like heaps. ExAllocatePool allocates a chunk of āheapā storage. The result is a pointer to memory that you can dereference and store stuff in, just like the result of HeapAlloc out in user mode (or āmallocā in Unix terms).
IoAllocateMdl allocates space (from the nonpaged pool, though weāre not supposed to know that) for an MDL, initializes its header and various field members, and links it to an IRP if the Irp pointer is non-null. It does not however fill in the Pfn array that follows the fixed-szied portion of the MDL. Thatās the job of MmProbeAndLockPages or MmBuildMdlForNonPagedPool.
- when to use MmBuildMdlForNonPagedPool?
When you have an MDL that you have previously allocated and initialized with IoInitializeMdl, or allocated some other way and initialized with MmInitializeMdl - and which was initialized with the virtual address of a buffer that was previously allocated out of nonpaged pool. It will actually work on any nonpageable memory, but weāre not supposed to rely on that.
- use of MmInitializeMdl?
Unnecessary if youāve used IoAllocateMdl. However if you were allocating your own MDLs with ExAllocatePool, MmInitializeMdl would be a likely next step.
ā Jamie Hanrahan
Azius Developer Training http://www.azius.com/
Kernel Mode Systems http://www.cmkrnl.com/
Windows Driver Consulting and Training
-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Comstar Yan
Sent: Thursday, March 20, 2003 21:21
To: NT Developers Interest List
Subject: [ntdev] About MDL
Hi,all
I am a newbie to NT kernel device develop,and I am
confused about MDL (Memory descriptor list). 1. the
difference between MDL and MDL chain.can I build directly a
MDL chain? 2. Can i define a instance of MDL and then map it
to some memory?How? 3. ExAllocatePool VS IoAllocateMdl ? 4.
when to use MmBuildMdlForNonPagedPool? 5. use of MmInitializeMdl?
Maybe too many questions, 
thanks
bå«®ē» č\å¤?včÆč²čå§yīé¬{.n?å£ēwZnVīé
å„«hęē¾{]zīéÆéč¼ā¹