Matteo:
You first create a thread in the application that sends an ioctl to your
driver. When
your driver receives the corresponding irp it stores it somewhere, pends it
and returns
without completing the irp. When the driver receives the packet, it puts
suitable data in the
output buffer and then completes the irp which you have stored conveniently
perhaps
in the device extension.
At the application level, on return from the call to DeviceIoControl() you
do whatever
processing you need and then loop back to the point of the call to
DeviceIoControl .and pass the results in the output buffer.
One advantage of this method versus using events is that here you can pass
all kinds of relevant
data in the input and output buffers, thus facilitating synchronization.
With events you never
know which packet of data you are processing.
This is how the application looks like, more or less:
// here create new thread
new thread code()
{
struct inputbuffer {
data passed to driver
};
struct outputbuffer {
data from driver to application
}
initialize data;
while (TRUE) {
if (handle invalid)
finish the thread
call deviceiocontrol(…,inputbuffer, ni, outputbuffer,
no, bytes, …)
if (cancelled)
finish the thread
process packet and get result
put result in the input buffer for deviceiocontrol
}
…
One important factor in any pending irp is to implement a good cancel
strategy and routine.
When cancelling, the driver should put special value in the output buffer
before the aborted
completion. The application will know that this is the time to close and
destroy the thread.
I have implemented all this before and it worked like a charm. You don’t
need any event for this.
Paul Lever, from Bluewater Systems, now BSquare, recommended me this approach.
Thanks,
George
At 01:06 AM 3/9/01 +0100, you wrote:
Ok.
I’ve a packet of data in my driver. I received that packet with an IOCTL/TDI
request. I’ve to process this packet, partly using kernel functions (in my
driver) and partly using my application’s functions. Now, suppose I’ve to
pass that packet of data to my application up in user mode, so that the app
can modify it and when it returns, depending how the packet has been
modified it can follow different paths. I use a pending (more than one if
necessary) to send data to user mode to my app…then I’ve to wait until my
app completes the operation so i can receive the modified packet and
continue processing. So, I will have to wait until my application’s function
modify the data and complete the operation…that is, complete the operation
and send down an IOCTL -> so, I’ll have to wait for an IOCTL from my app. My
question is how do i do that? The only thing thet come up to my mind righ
now is by creating an event object (I’m running at PASSIVE IRQL…so no
problem) before sending the request to user mode, that wait on that event.
When I will receive an IOCTL from the app, in my Dispatch function I can set
the event to allow the code to continue…it should work… better ideas?
Thanks
Matteo
----- Original Message -----
From: “Vodicka, Michal”
>To: “NT Developers Interest List”
>Sent: Friday, March 09, 2001 12:43 AM
>Subject: [ntdev] RE: synchronization problem
>
>
> > It depends on the reason why and where you need wait. In some situations
>you
> > can just do nothing and continue processing when receive an IRP with
> > results. If you have a worker thread, you can wait for an event and set it
> > in dispatch function when receive results. All depends on actual
>conditions
> > (IRQL…), write more details.
> >
> > Best regards,
> >
> > Michal Vodicka
> > Veridicom
> > (RKK - Skytale)
> > [WWW: http://www.veridicom.com , http://www.skytale.com]
> >
> > > ----------
> > > From: Matteo Pelati[SMTP:xxxxx@dolce.it]
> > > Reply To: NT Developers Interest List
> > > Sent: Friday, March 09, 2001 12:28 AM
> > > To: NT Developers Interest List
> > > Subject: [ntdev] RE: synchronization problem
> > >
> > > Yes, but how would you wait for the user app function to complete in the
> > > driver ? Using an event (or multiple events)?
> > >
> > > Matteo
> > >
> > >
> > > ----- Original Message -----
> > > From: “Vodicka, Michal”
> > > To: “NT Developers Interest List”
> > > Sent: Thursday, March 08, 2001 11:37 PM
> > > Subject: [ntdev] RE: synchronization problem
> > >
> > >
> > > > Send another IRP with results when your application completes the
> > > function.
> > > >
> > > > Best regards,
> > > >
> > > > Michal Vodicka
> > > > Veridicom
> > > > (RKK - Skytale)
> > > > [WWW: http://www.veridicom.com , http://www.skytale.com]
> > > >
> > > >
> > > >
> > > > > ----------
> > > > > From: Matteo Pelati[SMTP:xxxxx@dolce.it]
> > > > > Reply To: NT Developers Interest List
> > > > > Sent: Thursday, March 08, 2001 11:26 PM
> > > > > To: NT Developers Interest List
> > > > > Subject: [ntdev] synchronization problem
> > > > >
> > > > > I’ve the following problem. I’ve a driver that has to notify a user
> > > > > application to execute a function and return the result to the
>kernel
> > > mode
> > > > > driver. At first I thought to implementi it using LPC. The problem
> > > with
> > > LP
> > > > > is the fact it serializes all the messages …so I can’t have
>multiple
> > > > > threds working in user mode unless I create more than a port.
> > > > >
> > > > > Another solution I tried is initializing some user mode threads that
> > > send
> > > > > an IRP to the driver. The driver queues these IRPs and whenever it
>has
> > > to
> > > > > notify the app, it completes an IRP taken from the queue specifying
> > > the
> > > > > operation code. The problem is that now my application is executing
> > > the
> > > > > desired function, but my driver has to wait for that function to
> > > complete
> > > > > and receive a result from it.
> > > > >
> > > > > Any idea?
> > > > >
> > > > > Thanks
> > > > > Matteo
> > > > > —
> > > > > You are currently subscribed to ntdev as: xxxxx@rkk.cz
> > > > > To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com
> > > > >
> > > >
> > > > —
> > > > You are currently subscribed to ntdev as: xxxxx@dolce.it
> > > > To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com
> > >
> > >
> > > —
> > > You are currently subscribed to ntdev as: xxxxx@rkk.cz
> > > To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com
> > >
> >
> > —
> > You are currently subscribed to ntdev as: xxxxx@dolce.it
> > To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com
>
>
>—
>You are currently subscribed to ntdev as: xxxxx@brd.com
>To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com
-------------------------------------------
George Blat
BRD Corp
8016 188th SW, Edmonds, WA 98026
phone: 425-775-7475
fax: 781-998-5940
mailto:xxxxx@brd.com
http://www.brd.com
—
You are currently subscribed to ntdev as: $subst(‘Recip.EmailAddr’)
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com