佚名通过本文主要向大家介绍了女子监狱男管教张帆,张帆,女子监狱当管教张帆,监狱风云小说张帆,张帆个人资料等相关知识,希望对您有所帮助,也希望大家支持linkedu.com www.linkedu.com
问题:急!求讲解张帆《Windows驱动开发技术详解》的虚拟串口驱动,求讲解
描述:
需要讲解的代码如下:
NTSTATUS HelloWDMRead(IN PDEVICE_OBJECT fdo,
IN PIRP Irp)
{
KdPrint(("HelloWDMRead\n"));
NTSTATUS ntStatus = STATUS_SUCCESS;// Assume success
PDEVICE_EXTENSION pExtension = (PDEVICE_EXTENSION)fdo->DeviceExtension;
PIO_STACK_LOCATION irpSp = IoGetCurrentIrpStackLocation( Irp );
ULONG BufLen = irpSp->Parameters.Read.Length;
PCHAR pBuf = (PCHAR)Irp->AssociatedIrp.SystemBuffer;
KIRQL OldIrql;
PDRIVER_CANCEL pOldCancelRoutine;
Irp->IoStatus.Information = 0;
DbgPrint("DeviceObject:%08X Read\n",fdo);
if (BufLen == 0)
{
ntStatus = STATUS_SUCCESS;
}
else
{
KeAcquireSpinLock(&pExtension->WriteSpinLock, &OldIrql);
RtlCopyMemory(pBuf,pExtension->Buffer,BufLen);
Irp->IoStatus.Information = BufLen;
if (BufLen==0 && pExtension->pReadIrp==NULL) // nothing, store
{
pExtension->pReadIrp = Irp;
Irp->IoStatus.Status = ntStatus = STATUS_PENDING;
IoSetCancelRoutine(Irp, DriverCancelCurrentReadIrp);
if (Irp->Cancel)
{
pOldCancelRoutine = IoSetCancelRoutine(Irp, NULL);
if (pOldCancelRoutine != NULL)
{
// Nein, also IRP hier abbrechen
Irp->IoStatus.Status = ntStatus = STATUS_CANCELLED;
pExtension->pReadIrp = NULL;
}
else
{
// Ja, Cancel-Routine wird Request beenden
IoMarkIrpPending(Irp);
}
}
else
{
IoMarkIrpPending(Irp);
}
}
KeReleaseSpinLock(&pExtension->WriteSpinLock, OldIrql);
}
Irp->IoStatus.Status = ntStatus;
if (ntStatus != STATUS_PENDING)
IoCompleteRequest( Irp, IO_NO_INCREMENT );
return ntStatus;
}
NTSTATUS HelloWDMWrite(IN PDEVICE_OBJECT fdo,
IN PIRP Irp)
{
KdPrint(("HelloWDMWrite\n"));
NTSTATUS ntStatus = STATUS_SUCCESS;// Assume success
PDEVICE_EXTENSION pdx = (PDEVICE_EXTENSION)fdo->DeviceExtension;
PIO_STACK_LOCATION irpSp = IoGetCurrentIrpStackLocation( Irp );
ULONG DataLen = irpSp->Parameters.Write.Length;
PUCHAR pData = (PUCHAR)Irp->AssociatedIrp.SystemBuffer;
KIRQL OldIrql;
PIRP pOldReadIrp = NULL;
PDRIVER_CANCEL pOldCancelRoutine;
Irp->IoStatus.Information = 0;
ntStatus = STATUS_SUCCESS;
if (DataLen == 0)
{
ntStatus = STATUS_SUCCESS;
}else if (DataLen>COMBUFLEN)
{
ntStatus = STATUS_INVALID_PARAMETER;
}
else
{
KdPrint(("Write\n"));
KeAcquireSpinLock(&pdx->WriteSpinLock, &OldIrql);
RtlCopyMemory(pdx->Buffer,pData,DataLen);
pdx->uReadWrite = DataLen;
if (pdx->pReadIrp != NULL) // drop it out
{
pOldReadIrp = pdx->pReadIrp;
pOldCancelRoutine = IoSetCancelRoutine(pOldReadIrp, NULL);
if (pOldCancelRoutine != NULL)
{
pOldReadIrp->IoStatus.Information = 0;
pOldReadIrp->IoStatus.Status = STATUS_SUCCESS;
pdx->pReadIrp = NULL;
}
else
{
pOldReadIrp = NULL;
}
}
DriverCheckEvent(pdx, SERIAL_EV_RXCHAR | SERIAL_EV_RX80FULL);
// DriverCheckEvent(pdx, SERIAL_EV_TXEMPTY);
KeReleaseSpinLock(&pdx->WriteSpinLock, OldIrql);
if (pOldReadIrp != NULL)
IoCompleteRequest(pOldReadIrp, IO_NO_INCREMENT);
}
Irp->IoStatus.Status = ntStatus;
Irp->IoStatus.Information = DataLen;
IoCompleteRequest( Irp, IO_NO_INCREMENT );
return ntStatus;
}
解决方案1:
描述:
驱动开发张帆windows
第19章,虚拟串口驱动,求讲解。有意的加我qq:545039712.我出钱。需要讲解的代码如下:
NTSTATUS HelloWDMRead(IN PDEVICE_OBJECT fdo,
IN PIRP Irp)
{
KdPrint(("HelloWDMRead\n"));
NTSTATUS ntStatus = STATUS_SUCCESS;// Assume success
PDEVICE_EXTENSION pExtension = (PDEVICE_EXTENSION)fdo->DeviceExtension;
PIO_STACK_LOCATION irpSp = IoGetCurrentIrpStackLocation( Irp );
ULONG BufLen = irpSp->Parameters.Read.Length;
PCHAR pBuf = (PCHAR)Irp->AssociatedIrp.SystemBuffer;
KIRQL OldIrql;
PDRIVER_CANCEL pOldCancelRoutine;
Irp->IoStatus.Information = 0;
DbgPrint("DeviceObject:%08X Read\n",fdo);
if (BufLen == 0)
{
ntStatus = STATUS_SUCCESS;
}
else
{
KeAcquireSpinLock(&pExtension->WriteSpinLock, &OldIrql);
RtlCopyMemory(pBuf,pExtension->Buffer,BufLen);
Irp->IoStatus.Information = BufLen;
if (BufLen==0 && pExtension->pReadIrp==NULL) // nothing, store
{
pExtension->pReadIrp = Irp;
Irp->IoStatus.Status = ntStatus = STATUS_PENDING;
IoSetCancelRoutine(Irp, DriverCancelCurrentReadIrp);
if (Irp->Cancel)
{
pOldCancelRoutine = IoSetCancelRoutine(Irp, NULL);
if (pOldCancelRoutine != NULL)
{
// Nein, also IRP hier abbrechen
Irp->IoStatus.Status = ntStatus = STATUS_CANCELLED;
pExtension->pReadIrp = NULL;
}
else
{
// Ja, Cancel-Routine wird Request beenden
IoMarkIrpPending(Irp);
}
}
else
{
IoMarkIrpPending(Irp);
}
}
KeReleaseSpinLock(&pExtension->WriteSpinLock, OldIrql);
}
Irp->IoStatus.Status = ntStatus;
if (ntStatus != STATUS_PENDING)
IoCompleteRequest( Irp, IO_NO_INCREMENT );
return ntStatus;
}
NTSTATUS HelloWDMWrite(IN PDEVICE_OBJECT fdo,
IN PIRP Irp)
{
KdPrint(("HelloWDMWrite\n"));
NTSTATUS ntStatus = STATUS_SUCCESS;// Assume success
PDEVICE_EXTENSION pdx = (PDEVICE_EXTENSION)fdo->DeviceExtension;
PIO_STACK_LOCATION irpSp = IoGetCurrentIrpStackLocation( Irp );
ULONG DataLen = irpSp->Parameters.Write.Length;
PUCHAR pData = (PUCHAR)Irp->AssociatedIrp.SystemBuffer;
KIRQL OldIrql;
PIRP pOldReadIrp = NULL;
PDRIVER_CANCEL pOldCancelRoutine;
Irp->IoStatus.Information = 0;
ntStatus = STATUS_SUCCESS;
if (DataLen == 0)
{
ntStatus = STATUS_SUCCESS;
}else if (DataLen>COMBUFLEN)
{
ntStatus = STATUS_INVALID_PARAMETER;
}
else
{
KdPrint(("Write\n"));
KeAcquireSpinLock(&pdx->WriteSpinLock, &OldIrql);
RtlCopyMemory(pdx->Buffer,pData,DataLen);
pdx->uReadWrite = DataLen;
if (pdx->pReadIrp != NULL) // drop it out
{
pOldReadIrp = pdx->pReadIrp;
pOldCancelRoutine = IoSetCancelRoutine(pOldReadIrp, NULL);
if (pOldCancelRoutine != NULL)
{
pOldReadIrp->IoStatus.Information = 0;
pOldReadIrp->IoStatus.Status = STATUS_SUCCESS;
pdx->pReadIrp = NULL;
}
else
{
pOldReadIrp = NULL;
}
}
DriverCheckEvent(pdx, SERIAL_EV_RXCHAR | SERIAL_EV_RX80FULL);
// DriverCheckEvent(pdx, SERIAL_EV_TXEMPTY);
KeReleaseSpinLock(&pdx->WriteSpinLock, OldIrql);
if (pOldReadIrp != NULL)
IoCompleteRequest(pOldReadIrp, IO_NO_INCREMENT);
}
Irp->IoStatus.Status = ntStatus;
Irp->IoStatus.Information = DataLen;
IoCompleteRequest( Irp, IO_NO_INCREMENT );
return ntStatus;
}
解决方案1:
读写的 操作 解释什么呢? 难道是需要 逐行代码注释?