Anton,
Watch carefully. These are the 2 examples I pasted from the thread in other NG. They are not from ntoskrnl.exe
//
// Example A:
//
NTSTATUS CompRoutineA(irp)
{
//do whatever with the IRP
return STATUS_CONTINUE_COMPLETION;
}
NTSTATUS
Xyz_call_drv_and_potentially_alter_the_return_status (
IN PDEVICE_OBJECT DeviceObject,
IN PIRP Irp,
IN PVOID Context
)
{
IoMarkIrpPending(Irp);
IoSetCompletionRoutine(Irp,CompRoutineA,…);
IoCallDriver(DeviceObject,Irp);
return STATUS_PENDING;
}
Your first reply:
“As you will see below, the above code (CompletionRoutineA) has quite insidious bug in it…”
After Eliyas told you why the code is correct and presented the snippet of IoCompleteRequest. you then replied:
" Indeed, as it turns out,
IoMarkIrpPending()
call by the driver is unnecessary, simply because, unless the completion
routine returns STATUS_MORE_PROCESSING_REQUIRED, IoCompleteRequest() calls
IoMarkIrpPending() anyway if Irp->PendingReturned is set. In other words,
IoCompleteRequest() does something that, according to the doc I quoted,
should be done by the completion routine, so that doing the same thing in the
completion routine is simply unnecessary. However, officially all the above is undocumented behaviour, so that MSFT
can change it at whenever it wants - after all, if some problem arises, they
can always say that you just haven’t followed their guidelines…"
Quiz 1:
Anton, are you aware of the MULTIPLE errors in your statement? I suggest you do your homework before you attempt to defend yourself.
//
// Example B:
//
VOID func_a()
{
IoGetDeviceObjectPointer(…,&pDevObject);
irp = IoAllocateIrp(); // with no extra stack;
/// setup IRP stack.
IoSetCompetionRoutineB(irp,CompRoutineB,…);
IoCallDriver();
return;
}
NTSTATUS
CompRoutineB(irp)
{
if (Irp->PendingReturned)
{
/// do NOT mark pending regardless what code you return,
}
ObDereferenceObject(devobj);
IoFreeIrp(Irp);
return SMPR;
}
Anton, you seemed to believe marking IRP pending in example is “harmless”. Let me tell ya, marking irp pending in CompRoutineB is wrong and completely unnecessary.
Quiz 2: Why marking IRP pending is a fatal error here?
If you don’t know the answer to the quizs, and ask nicely, someone in the list or I would probably tell you.
Calvin Guan (expiring DDK MVP)
Sr. Staff Engineer
NetXtreme NTX Miniport
Broadcom Corp. - Top 2 America’s Most Admired Semiconductor Company
Connecting Everything(r)
----- Original Message ----
From: “xxxxx@hotmail.com”
To: Windows System Software Devs Interest List
Sent: Sunday, March 18, 2007 12:45:46 PM
Subject: RE:[ntdev] Is it possible to call NdisOpenConfiguration from outside MiniportInitialize?
> >implementation of IoCompleteRequest(). However, the one that we have
>> discovered on this particular thread is already a serious bug that may
> > lead you to making mistakes in your code…
> [CG] It’s not “we”. It’s you-Anton. You obviously still don’t understand
> Eliyas’s (Mr. Toaster) correction to your post. I’m not going to repeat
> the education. The code snippet is taken from some field proven mass
> production drivers. It survived days of MSFT internal stress test matrix
> which you have never heard of.
Please read my previous post carefully - I said that " a serious bug that may lead you to making mistakes in your code" is the one that we discuss on this thread, and the one that we discussed in another NG is just harmless discrepancy. If you follow MSDN there and make unnecessary call to IoMarlIrpPending() in your completion routine, nothing is going to happen, apart from few wasted CPU cycles. However, if follow MSDN here and mistake a handle that gets passed to your MiniportInitialize() for the one returned by NdisMInitializeWrapper(), it will hardly do you any good…
BTW, the code snippet your speak about is taken from IoCompteleRequest() implementation, so that it is taken from ntoskrnl.exe, rather than from any driver…
> Don’t think I’m that stupid
Actually, I never thought anything like that - I really don’t know what the above suspicion is based upon…
Anton Bassov
—
Questions? First check the Kernel Driver FAQ at http://www.osronline.com/article.cfm?id=256
To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com