Need help with TDI filter (how to stop NO_MORE_IRP_STACK_LOCATIONS)

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi,
I’m doing a tdi filter which filters TCP device … I’m aware of the fact
that netbt sends irp with not enough stack locations, and i’m finding a way
on how to stop the BSOD when
i need to set a completion routine on the irp.

I’ve tried to reuse my own stack location, in this way :

if (Irp->CurrentLocation == 1)
{
// this way IoSetCompletionRoutine set the completion routine in my own
stack location
IoSkipCurrentIrpStackLocation ();
// ProtectStackContext is (among other things) a copy of my own stack
location which i then use in the completion routine
IoSetCompletionRoutine (Irp, TcpConnectCompletion, &ProtectStackContext,
TRUE,TRUE,TRUE);
}
else
{
// set completion normally

}

Now the problem arises in the completion routine :
Here, if ProtectStackContext->NotEnoughStackLocations (a variable i set in
the dispatch routine), i :

  1. rearrange the irp and stacklocation to the original :
    (irp.tail.overlay.currentstacklocation-- and irp->currentlocation–)
  2. copy back the stack location i saved to the current stack location
  3. execute the completion routine in this stack location if there’s one
  4. set an event and return STATUS_MORE_PROCESSING_REQUIRED (my request is
    synchronous)

But it still doesnt work … it bugchecks telling either multiple complete
requests or irql not less or equal…

What’s wrong, in your opinion ? (if i do not execute the old completion
routine, nor i copy back the old stack location, it works … but in this
way i miss a completion routine)

Other solution could be allocate my own irp, forward that and in the
completion routine complete the original irp also. But i’m not sure how to
copy the original irp.
Can’t you point me in a direction, either fix my reuse-stack routine or tell
me how to properly allocate a new irp ?

Thanx,
Valerio

-----BEGIN PGP SIGNATURE-----
Version: PGP 8.0

iQA/AwUBP5SAK2Gxr2U3nc5EEQIvpwCgsiW70cb5sz+E5XkQAxdYQwoObk4AoKoN
82VXFmtMCL1Eb0rJcm0FAnlk
=H5Ev
-----END PGP SIGNATURE-----