MDL/ GetScatterGatherList problems.

Tech-Archive recommends: Fix windows errors by optimizing your registry

From: Christian Sturt (christiansturt_at_yahoo.co.uk)
Date: 07/02/04


Date: Fri, 2 Jul 2004 15:07:31 +0100

I am trying to build a scatter gather list for an area of user memory after
locking it down. To do this I use the following (with bits removed):

//allocate an MDL to describe the user buffer
mdl = IoAllocateMdl(pDmaBuffer, pdx->nbytes, FALSE, TRUE, NULL);

//this should initialise the MDL headers etc?
MmInitializeMdl(mdl , pDmaBuffer, pdx->nbytes );

//want to lock memory for access.
MmProbeAndLockPages(pdx->theDmaTransfer.theDmaBuffer.mdl , UserMode,
IoModifyAccess);

//get a vadd for use.
vaddr = MmGetSystemAddressForMdlSafe(mdl , NormalPagePriority );

 status = GetScatterGatherList (MyadapterObject, fdo, mdl , vaddr,
pdx->nbytes, (PDRIVER_LIST_CONTROL) DmaExecutionRoutine, pdx, FALSE);
//call get scatter gather list.

GetScatterGatherList always returns success, but the list returned is trash.
Some addresses are repeated etc.

I think that the problem must be my MDL (there isn't much else to go
wrong!).

Do I need to use MmInitializeMdl, or does MmProbeAndLockPages fill in the
MDL header?

When I removed it I have the same problem. Am I calling them in the correct
order? They seem logical to me.

Any suggestions why I would get a dodgy SG list?

Thanks