Calling TdiBuildQueryInformation in Completion Routine...

Hi,

In my Tdi filter driver i need to call TdiBuildQueryInformation in order to ectract address information from FileObject Associated with the IRP.When I try to do this the call to TdiBuildQueryInformation Generates a bug check always with different bug codes.
1-ATTEMPTED_SWITCH_FROM_DPC
2-PFN_LIST_CORRUPT
3-Access Violation

I guess from the above that there is some problem with calling this functions from within the Completion Routine which is being called in arbitary thread context and at probably DISPATCH_LEVEL .Or it is something else ??
Do i need to put the code and allocate a WorkQueue item in order to get this info.
But the question is when the worker thread will get a chance to execute this code at that point of time will this FileObject and Irp be Valid ???
What is the correct way to do this???
Any Help is appreciated…
The Code is here –
PIRP pQueryIrp;
IO_STATUS_BLOCK IoStatusBlock;
PMDL pMdlForAddressInfo;
PVOID TdiAddressInfo;
TRANSPORT_ADDRESS TransportAddress;

TA_ADDRESS AddressArray;

PTDI_ADDRESS_IP pOneIPAddress;

TdiAddressInfo = ExAllocatePoolWithTag(NonPagedPool,

sizeof(TDI_ADDRESS_INFO),

‘QADR’);

if(!TdiAddressInfo )
{
DbgPrint(“Allocation Failed \n”);
return status;
}

pMdlForAddressInfo = IoAllocateMdl(TdiAddressInfo,

sizeof(TDI_ADDRESS_INFO),
FALSE,
FALSE,NULL);

if(pMdlForAddressInfo == NULL)
{
DbgPrint(“Mdl Allocation Failed…\n”);
ExFreePool(TdiAddressInfo);
return status;

}
__try
{
MmProbeAndLockPages(pMdlForAddressInfo,
KernelMode ,
IoModifyAccess);

}
__except(EXCEPTION_EXECUTE_HANDLER)
{
IoFreeMdl(pMdlForAddressInfo);
pMdlForAddressInfo = NULL;

}

pQueryIrp = TdiBuildInternalDeviceControlIrp (
TDI_QUERY_INFORMATION ,
pDeviceObject,
pIrpStackLocation->FileObject ,
NULL,
&IoStatusBlock
);

if(pQueryIrp == NULL)
{
DbgPrint(“Building Internal DeviceControlIrp Failed \n”);
return status;
}

MmBuildMdlForNonPagedPool(pMdlForAddressInfo);

TdiBuildQueryInformation ( pQueryIrp,
pTCPDevObj,
pIrpStackLocation->FileObject,
NULL, // No Comp Routine
NULL, // No Context
TDI_QUERY_ADDRESS_INFO,
pMdlForAddressInfo
);

DbgPrint(“Calling TCP \n”);
status = IoCallDriver(pTCPDevObj,pQueryIrp);

–Subodh

Now i have put the code for querying address info in the work queue item routine but still the call IoCallDriver(pTCPDevObj,pQueryIrp) generating a page fault ?? what could be wrong here??
Any Help is appreciated…
–Subodh
----- Original Message -----
From: subodh gupta
To: NT Developers Interest List
Sent: Tuesday, October 29, 2002 5:49 PM
Subject: [ntdev] Calling TdiBuildQueryInformation in Completion Routine…

Hi,

In my Tdi filter driver i need to call TdiBuildQueryInformation in order to ectract address information from FileObject Associated with the IRP.When I try to do this the call to TdiBuildQueryInformation Generates a bug check always with different bug codes.
1-ATTEMPTED_SWITCH_FROM_DPC
2-PFN_LIST_CORRUPT
3-Access Violation

I guess from the above that there is some problem with calling this functions from within the Completion Routine which is being called in arbitary thread context and at probably DISPATCH_LEVEL .Or it is something else ??
Do i need to put the code and allocate a WorkQueue item in order to get this info.
But the question is when the worker thread will get a chance to execute this code at that point of time will this FileObject and Irp be Valid ???
What is the correct way to do this???
Any Help is appreciated…
The Code is here –
PIRP pQueryIrp;
IO_STATUS_BLOCK IoStatusBlock;
PMDL pMdlForAddressInfo;
PVOID TdiAddressInfo;
TRANSPORT_ADDRESS TransportAddress;

TA_ADDRESS AddressArray;

PTDI_ADDRESS_IP pOneIPAddress;

TdiAddressInfo = ExAllocatePoolWithTag(NonPagedPool,

sizeof(TDI_ADDRESS_INFO),

‘QADR’);

if(!TdiAddressInfo )
{
DbgPrint(“Allocation Failed \n”);
return status;
}

pMdlForAddressInfo = IoAllocateMdl(TdiAddressInfo,

sizeof(TDI_ADDRESS_INFO),
FALSE,
FALSE,NULL);

if(pMdlForAddressInfo == NULL)
{
DbgPrint(“Mdl Allocation Failed…\n”);
ExFreePool(TdiAddressInfo);
return status;

}
__try
{
MmProbeAndLockPages(pMdlForAddressInfo,
KernelMode ,
IoModifyAccess);

}
__except(EXCEPTION_EXECUTE_HANDLER)
{
IoFreeMdl(pMdlForAddressInfo);
pMdlForAddressInfo = NULL;

}

pQueryIrp = TdiBuildInternalDeviceControlIrp (
TDI_QUERY_INFORMATION ,
pDeviceObject,
pIrpStackLocation->FileObject ,
NULL,
&IoStatusBlock
);

if(pQueryIrp == NULL)
{
DbgPrint(“Building Internal DeviceControlIrp Failed \n”);
return status;
}

MmBuildMdlForNonPagedPool(pMdlForAddressInfo);

TdiBuildQueryInformation ( pQueryIrp,
pTCPDevObj,
pIrpStackLocation->FileObject,
NULL, // No Comp Routine
NULL, // No Context
TDI_QUERY_ADDRESS_INFO,
pMdlForAddressInfo
);

DbgPrint(“Calling TCP \n”);
status = IoCallDriver(pTCPDevObj,pQueryIrp);

–Subodh


You are currently subscribed to ntdev as: xxxxx@softhome.net
To unsubscribe send a blank email to %%email.unsub%%

There is no need to call MmProbeAndLockPages as the subsequent call to MmBuildMdlForNonPagedPool is sufficient.? TdiBuildInternalDeviceControlIrp is safe only at passive level.? IoAllocateIrp is safe at dispatch level.? It would be good to zero out your TdiAddressInfo structure before sending it down the stack. - Eric
?
?
This posting is provided "AS IS" with no warranties, and confers no rights
?

-----Original Message-----
From: subodh gupta [mailto:xxxxx@softhome.net]
Sent: Tuesday, October 29, 2002 6:42 AM
To: NT Developers Interest List
Subject: [ntdev] Re: Calling TdiBuildQueryInformation in Completion Routine...

Now i have put the code for querying address info in the work queue item routine but still the call?IoCallDriver(pTCPDevObj,pQueryIrp) generating a page fault ?? what could be wrong here??
Any Help is appreciated..
--Subodh
----- Original Message -----
From: subodh gupta
To: NT Developers Interest List
Sent: Tuesday, October 29, 2002 5:49 PM
Subject: [ntdev] Calling TdiBuildQueryInformation in Completion Routine...

Hi,
?
In my Tdi filter driver i need to call TdiBuildQueryInformation in order to ectract address information from FileObject Associated with the IRP.When I try to do this the call to TdiBuildQueryInformation Generates a bug check always with different bug codes.
1-ATTEMPTED_SWITCH_FROM_DPC
2-PFN_LIST_CORRUPT
3-Access Violation
?
I guess from the above that there is some problem with calling this functions from within the Completion Routine which is being called in arbitary thread context and at probably DISPATCH_LEVEL .Or it is something else ??
Do i need to put the code and allocate a WorkQueue item in order to get this info.
But the question is when the worker thread will get a chance to execute this code at that point of time will this FileObject and Irp be Valid ???
What is the correct way to do this???
Any Help is appreciated...
The Code is here --
PIRP pQueryIrp;
IO_STATUS_BLOCK IoStatusBlock;
PMDL pMdlForAddressInfo;
PVOID TdiAddressInfo;
TRANSPORT_ADDRESS TransportAddress;
?
TA_ADDRESS AddressArray;
?
PTDI_ADDRESS_IP? pOneIPAddress;
?
?
?
TdiAddressInfo = ExAllocatePoolWithTag(NonPagedPool,
?
?????????????????????????????????? sizeof(TDI_ADDRESS_INFO),
?
?????????????????????????????????? 'QADR');
?
?
?
?if(!TdiAddressInfo )
?{
??DbgPrint("Allocation Failed \n");
??return status;
?? }
?
??
?? pMdlForAddressInfo = IoAllocateMdl(TdiAddressInfo,
?
?????sizeof(TDI_ADDRESS_INFO),
?????FALSE,
?????FALSE,NULL);
?
?
??? if(pMdlForAddressInfo == NULL)
?{
??DbgPrint("Mdl Allocation Failed..\n");????
??ExFreePool(TdiAddressInfo);
??return status;
?
?}
?__try
?{
??MmProbeAndLockPages(pMdlForAddressInfo,
???????KernelMode ,
???????IoModifyAccess);
?
?}
?__except(EXCEPTION_EXECUTE_HANDLER)
?{
??IoFreeMdl(pMdlForAddressInfo);
??pMdlForAddressInfo = NULL;
?
?}
??
?? pQueryIrp = TdiBuildInternalDeviceControlIrp (
???????? TDI_QUERY_INFORMATION ,
???????? pDeviceObject,
???????? pIrpStackLocation->FileObject ,
???????? NULL,
???????? &IoStatusBlock
??????? );
?

?if(pQueryIrp == NULL)
?{
??DbgPrint("Building Internal DeviceControlIrp Failed \n");
??return status;
?}
?
?
?? MmBuildMdlForNonPagedPool(pMdlForAddressInfo);
?
?? TdiBuildQueryInformation (? pQueryIrp,
????????? pTCPDevObj,
????????? pIrpStackLocation->FileObject,
????????? NULL, // No Comp Routine
????????? NULL, // No Context
????????? TDI_QUERY_ADDRESS_INFO,
????????? pMdlForAddressInfo
???????? );
?
?? DbgPrint("Calling TCP \n");
?? status = IoCallDriver(pTCPDevObj,pQueryIrp);
?
--Subodh
?

You are currently subscribed to ntdev as: xxxxx@softhome.net
To unsubscribe send a blank email to %%email.unsub%%

You are currently subscribed to ntdev as: xxxxx@microsoft.com
To unsubscribe send a blank email to %%email.unsub%%