Hello,
In a TDI client driver, I set an event handler which calls a routine each
time data is received. The routine is just below.
The DDK says that the TSDU parameter “Points to an MDL, possibly the
initial MDL in a chain, mapping the buffer containing the received TSDU
data”. However, I cannot access the buffer pointed by the MDL without
having a BSOD (IRQL_NOT_LESS_OR_EQUAL) when RtlCopyMemory() is called.
The documentation says that RtlCopyMemory() can be running at any IRQL if
both memory blocks are resident. How can I know if the memory blocks are
resident ? If the blocks are not resident, which function should I use to
copy my buffer ? Should I lock, probe, map or do anything else before
copying the buffer ?
Thanks for your help
NTSTATUS ClientEventReceiveDatagram(IN PDEVICE_EXTENSION
DeviceExtension,IN LONG SourceAddressLength,
IN PVOID SourceAddress,IN LONG
OptionsLength,IN PVOID Options,
IN ULONG ReceiveDatagramFlags,IN ULONG
BytesIndicated,
IN ULONG BytesAvailable,OUT ULONG
*BytesTaken,IN PVOID Tsdu,
OUT PIRP *IoRequestPacket)
{
NTSTATUS Status; // Return value
ULONG BytesToCopy, // Bytes to copy
BytesCopied, // Bytes truly copied
BufferSize; // MDL’s buffer size
PMDL MdlAddress; // MDL pointer
PUCHAR Buffer; // Buffer receiving the data
…
// Data reception
BytesToCopy=DeviceExtension->Read.Size -
DeviceExtension->Read.BytesReceived;
BytesToCopy=BytesToCopy>BytesIndicated ? BytesIndicated : BytesToCopy;
MdlAddress=(PMDL)Tsdu;
BytesCopied=0;
// Scan MDL buffers
while(MdlAddress!=NULL && BytesCopied {
Buffer=MmGetSystemAddressForMdl((PMDL)MdlAddress);
BufferSize=MmGetMdlByteCount(MdlAddress);
BufferSize=BufferSize
<=(BytesToCopy-BytesCopied) ? BufferSize : (BytesToCopy-BytesCopied);
RtlCopyMemory(&DeviceExtension->Read.Buffer[DeviceExtension->Read.BytesReceived],Buffer,BufferSize);
BytesCopied+=BufferSize;
MdlAddress=MdlAddress->Next;
}
DeviceExtension->Read.BytesReceived+=BytesCopied;
*BytesTaken=BytesCopied;
IoRequestPacket=NULL;
Status=STATUS_SUCCESS;
…
return Status;
}