Push into a list. Good ?

Hello,

I returned to STATUS_PENDING when calls IRP_MJ_READ,
and add the IRP and the process ID to the list.

In the thread I read the list and call the function for IoCompleteRequest he returns STATUS_SUCCESS.

I wonder if the some lines of code are consistent (good) and if that this happens if there is a call to CancelIo or IoCancelIrp by another driver or processus
during the execution of thread ?

NTSTATUS vdums_vdisk_control(IN PDEVICE_OBJECT DeviceObject, IN PIRP irp)
{
HANDLE hpid;
NTSTATUS status=STATUS_NOT_IMPLEMENTED;


case IRP_MJ_READ:
IjThread(pvd,irp,&status);
break;


}

typedef struct {
LIST_ENTRY le;
PIRP irp;
HANDLE processID;
}TENTRYL,*PENTRYL;

void IjThread(PPARAMVD pvd,IN PIRP irp,NTSTATUS* status)
{
PENTRYL entryl;
HANDLE hp;

IoMarkIrpPending(irp);

hp=PsGetCurrentProcessId();

entryl=(PENTRYL)ExAllocatePool(NonPagedPool,sizeof (TENTRYL));
if (entryl!=NULL)
{
entryl->irp=irp;
entryl->processID=hp;

ExInterlockedInsertTailList(&pvd->list_head,
&entryl->le,
&pvd->list_lock);

}
else
KdPrint((“Error allocation entryl\n”,NULL));

irp->IoStatus.Status=STATUS_PENDING;
*status= STATUS_PENDING;

}

VOID VDUM_DeviceThread(IN PVOID Context)
{
PENTRYL entryl=NULL;
PPARAMVD pvd=(PPARAMVD)Context;
for (;:wink:
{
request=NULL;
request = ExInterlockedRemoveHeadList(&pvd->list_head,&pvd->list_lock);
if (request!=NULL)
{
entryl=CONTAINING_RECORD(request,TENTRYL,le);
irp=entryl->irp;
hp=entryl->processID;
ExFreePool(entryl);
KdPrint((“ProcessID (%x) (%x)\n”,hp,PsGetCurrentProcessId()));
io_stack = IoGetCurrentIrpStackLocation(irp);
switch (io_stack->MajorFunction)
{


case IRP_MJ_READ:
{
irp->IoStatus.Status=status=STATUS_SUCCESS;
IoCompleteRequest(irp,
NT_SUCCESS(irp->IoStatus.Status) ?
IO_DISK_INCREMENT : IO_NO_INCREMENT);
}
break;


}

}
}

}

First why are you doing this with a legacy driver, in KMDF handling of
cancel would be done for you. There are extremely limited reasons to write
a non-KMDF driver, and in your other questions you have not shown any reason
for your approach. If you are not going to do a KMDF driver, you should at
least use a cancel safe queue (see IoCsqInitialize) rather than roll your
own. Rolling your own is a guaranteed way to mess up on cancel handling, if
you go back through the list archives and the older NT Insiders, you can
find more than you could imagine on problems with rolling your own in the
face of cancel.

So yes push into list is OK, the way you are doing it is NOT.


Don Burn (MVP, Windows DKD)
Windows Filesystem and Driver Consulting
Website: http://www.windrvr.com
Blog: http://msmvps.com/blogs/WinDrvr

wrote in message news:xxxxx@ntdev…
>
> Hello,
>
> I returned to STATUS_PENDING when calls IRP_MJ_READ,
> and add the IRP and the process ID to the list.
>
> In the thread I read the list and call the function for IoCompleteRequest
> he returns STATUS_SUCCESS.
>
> I wonder if the some lines of code are consistent (good) and if that this
> happens if there is a call to CancelIo or IoCancelIrp by another driver or
> processus
> during the execution of thread ?
>
> NTSTATUS vdums_vdisk_control(IN PDEVICE_OBJECT DeviceObject, IN PIRP irp)
> {
> HANDLE hpid;
> NTSTATUS status=STATUS_NOT_IMPLEMENTED;
> …
> …
> case IRP_MJ_READ:
> IjThread(pvd,irp,&status);
> break;
> …
> …
> }
>
> typedef struct {
> LIST_ENTRY le;
> PIRP irp;
> HANDLE processID;
> }TENTRYL,PENTRYL;
>
> void IjThread(PPARAMVD pvd,IN PIRP irp,NTSTATUS
status)
> {
> PENTRYL entryl;
> HANDLE hp;
>
>
> IoMarkIrpPending(irp);
>
>
> hp=PsGetCurrentProcessId();
>
>
>
> entryl=(PENTRYL)ExAllocatePool(NonPagedPool,sizeof (TENTRYL));
> if (entryl!=NULL)
> {
> entryl->irp=irp;
> entryl->processID=hp;
>
> ExInterlockedInsertTailList(&pvd->list_head,
> &entryl->le,
> &pvd->list_lock);
>
>
>
> }
> else
> KdPrint((“Error allocation entryl\n”,NULL));
>
>
> irp->IoStatus.Status=STATUS_PENDING;
> *status= STATUS_PENDING;
>
> }
>
>
>
> VOID VDUM_DeviceThread(IN PVOID Context)
> {
> PENTRYL entryl=NULL;
> PPARAMVD pvd=(PPARAMVD)Context;
> for (;:wink:
> {
> request=NULL;
> request =
> ExInterlockedRemoveHeadList(&pvd->list_head,&pvd->list_lock);
> if (request!=NULL)
> {
> entryl=CONTAINING_RECORD(request,TENTRYL,le);
> irp=entryl->irp;
> hp=entryl->processID;
> ExFreePool(entryl);
> KdPrint((“ProcessID (%x) (%x)\n”,hp,PsGetCurrentProcessId()));
> io_stack = IoGetCurrentIrpStackLocation(irp);
> switch (io_stack->MajorFunction)
> {
> …
> …
> case IRP_MJ_READ:
> {
> irp->IoStatus.Status=status=STATUS_SUCCESS;
> IoCompleteRequest(irp,
> NT_SUCCESS(irp->IoStatus.Status) ?
> IO_DISK_INCREMENT : IO_NO_INCREMENT);
> }
> break;
> …
> …
> }
>
>
> }
> }
>
> }
>
>
> Information from ESET NOD32 Antivirus, version of virus
> signature database 4552 (20091028)

>
> The message was checked by ESET NOD32 Antivirus.
>
> http://www.eset.com
>
>
>

Information from ESET NOD32 Antivirus, version of virus signature database 4552 (20091028)

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com