I am trying to write a Tdi client to receive UDP packets. I set the
TDI_EVENT_RECEIVE_DATAGRAM event properly. Here is the piece of code of
this event handler:
static NTSTATUS ClientEventRceiveDatagram( IN PVOID EventContext,
IN LONG AddressLength,
IN PTRANSPORT_ADDRESS
TaAddress,
IN LONG OptionsLength,
IN PVOID Options,
IN ULONG ReceiveDatagramFlags,
IN ULONG BytesIndicated,
IN ULONG BytesAvailable,
OUT ULONG *BytesTaken,
IN PVOID Tsdu,
OUT PIRP *IoRequestPacket )
{
…
PIRP irp;
PMDL mdlBuffer;
if ( BytesIndicated >= BytesAvailable )
{
/* handle full Tsdi case here */
…
}
…
/*
* Build the TDI_RECEIVE_DATAGRAM irp for the remainder of TSDU
*/
irp = TdiBuildInternalDeviceControlIrp( TDI_RECEIVE_DATAGRAM,
deviceObject,
fileObject,
NULL,
NULL );
if ( irp == NULL )
{
ExFreePool( remainderBuf );
return STATUS_DATA_NOT_ACCEPTED;
}
/*
* Get the mdl for the remainder buffer
*/
mdlBuffer = IoAllocateMdl(
remainderBuf,
remainderLen, /* length of buffer */
FALSE, /* not secondary */
FALSE, /* don’t charge quota */
NULL ); /* don’t use irp */
if ( mdlBuffer )
{
try
{
/* probe & lock the buffer */
MmProbeAndLockPages( mdlBuffer, KernelMode, IoModifyAccess );
}
except ( EXCEPTION_EXECUTE_HANDLER )
{
IoFreeMdl( mdlBuffer );
ExFreePool( remainderBuf );
remainderBuf = NULL;
return STATUS_DATA_NOT_ACCEPTED;
}
}
TdiBuildReceiveDatagra(irp,
deviceObject,
fileObject,
PartialRecvComplete,
context, /* completeion context */
mdlBuffer, /* pointer to data (MDL) */
0,/* use the whole buffer mapped at mdlBuffer
*/
receiveInfo,
NULL,
TDI_RECEIVE_NORMAL | TDI_RECEIVE_EXPEDITED );
/* since we don’t call IoCallDriver here directly */
IoSetNextIrpStackLocation( irp );
*IoRequestPacket = irp;
return STATUS_MORE_PROCESSING_REQUIRED;
} /* ClientEventRceiveDatagram */
I got :
Access violation - code c0000005 (!!! second chance !!!)
nt!FsRtlAllocatePoolWithTag+1:
8041cb2b 897704 mov [edi+0x4],esi
In the call of TdiBuildInternalDeviceControlIrp():
My questions are:
- Why it crash?
- Is this the right way to create the irp for receiving the remainder
tsdu? - Can I use a local irp in this case?
I appreciate your help.
Lin