for help: MDL with non paged buffers..problem while communicating with TDI

Hi All,
Please help me in fixing the following problem,
I am writing a driver which will communicate with TDI.
while running my driver i am getting exception (0xc00000a1) and some
times getting Bug check: PFN_LIST_CORRUPT (4e)
Here to send a buffer to the TDI i prepared the following steps,

  1. Allocate a 64KB buffer from non paged pool.
    SendDataBuffer = ExAllocatePoolWithTag(NonPagedPool,
    MAX_DATA_SIZE,BUSENUM_POOL_TAG);
  2. Copy the DATA whatevere i want to send down to TDI.
    RtlCopyMemory(SendDataBuffer,pBuf,Len);
  3. Prepared an MDL with the above nonpaged pool buffer.
    pMdl = IoAllocateMdl((PCHAR )SendDataBuffer , MAX_DATA_SIZE, FALSE,
    FALSE, NULL);
  4. Building the mdl for non paged pool.
    MmBuildMdlForNonPagedPool(pMdl);
    5.preparing the TDI SEND Irp.
    TdiBuildSend(pIrp, pTdiDevice, pfoConnection, CompRoutine,NULL,
    pSendIrp->pMdl, 0, Len);
  5. Send the TDI SEND Irp Down to TDI.
    IoCallDriver(pTdiDevice, pIrp);
    Iam comleting this TDI SEND Irp Asynchronously,for that i passed
    CompRoutine a
    completion routine in previous step.
    now when ever the TDI SEND Irp compltes my CompRoutine will be called
    and in this routine i am doing like this.
  6. here iam freeing the MDL that i was allocated in step 3.
    if(pIrp->pMdl)
    {
    IoFreeMdl(pIrp->pMdl);
    pIrp->pMdl= NULL;
    }
    after this i am reinitializing(filling eith zeros) the
    SendDataBuffer (64 KB) and issuing one more TDI SEND Irp Down to TDI
    ,that means i am doing again step 2 to step 6.and this will be
    contineous for a long time.
    Can any one please find any thing wrong in my implementation! or tell
    me how to communicate with TDI using MDLs and Non paged buffer.

Stay in the know. Pulse on the new Yahoo.com. Check it out.

>Building the mdl for non paged pool. MmBuildMdlForNonPagedPool(pMdl);

Use the checked version of the kernel with the driver verifier, you will receive an error message if an Mdl with MDL_SOURCE_IS_NONPAGED_POOL flag is sent to MmProbeAndLockPages or MmUnlockPages.
Instead MmBuildMdlForNonPagedPool try to use IoAllocateMdl() and MmProbeAndlockPages() and do not free this Mdl in your completion routine, the page frames will be unlocked and Mdl will be freed by the IO Manager( your completion routine must return STATUS_SUCCESS ). I suspect that an underlying driver( filter ) changes the Irp->MdlAddress.


Slava Imameyev, xxxxx@hotmail.com

“aare ravinder” wrote in message news:xxxxx@ntdev…
Hi All,

Please help me in fixing the following problem,
I am writing a driver which will communicate with TDI.

while running my driver i am getting exception (0xc00000a1) and some
times getting Bug check: PFN_LIST_CORRUPT (4e)

Here to send a buffer to the TDI i prepared the following steps,

1. Allocate a 64KB buffer from non paged pool.
SendDataBuffer = ExAllocatePoolWithTag(NonPagedPool,
MAX_DATA_SIZE,BUSENUM_POOL_TAG);

2. Copy the DATA whatevere i want to send down to TDI.
RtlCopyMemory(SendDataBuffer,pBuf,Len);

3. Prepared an MDL with the above nonpaged pool buffer.
pMdl = IoAllocateMdl((PCHAR )SendDataBuffer , MAX_DATA_SIZE, FALSE,
FALSE, NULL);

4. Building the mdl for non paged pool.
MmBuildMdlForNonPagedPool(pMdl);

5.preparing the TDI SEND Irp.
TdiBuildSend(pIrp, pTdiDevice, pfoConnection, CompRoutine,NULL,
pSendIrp->pMdl, 0, Len);

6. Send the TDI SEND Irp Down to TDI.
IoCallDriver(pTdiDevice, pIrp);

Iam comleting this TDI SEND Irp Asynchronously,for that i passed
CompRoutine a
completion routine in previous step.

now when ever the TDI SEND Irp compltes my CompRoutine will be called
and in this routine i am doing like this.

7. here iam freeing the MDL that i was allocated in step 3.
if(pIrp->pMdl)
{
IoFreeMdl(pIrp->pMdl);
pIrp->pMdl= NULL;
}

after this i am reinitializing(filling eith zeros) the
SendDataBuffer (64 KB) and issuing one more TDI SEND Irp Down to TDI
,that means i am doing again step 2 to step 6.and this will be
contineous for a long time.

Can any one please find any thing wrong in my implementation! or tell
me how to communicate with TDI using MDLs and Non paged buffer.

------------------------------------------------------------------------------
Stay in the know. Pulse on the new Yahoo.com. Check it out.

Hi Slava,
Thanks a lot ,its working fine.
now i am using MmProbeAndlockPages insteadof MmBuildMdlForNonPagedPool and modified my completion routines…