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: $subst(‘Recip.EmailAddr’)
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com

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: $subst(‘Recip.EmailAddr’)
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com

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: $subst(‘Recip.EmailAddr’)
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com

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: $subst(‘Recip.EmailAddr’)
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com

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: $subst(‘Recip.EmailAddr’)
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com

It should work if you’re running on passive level but remember you’re
blocking original requestor thread. In some cases it can cause funny
deadlocks if continue in user mode.

Other possibility: can you return pending status to original requestor and
complete request later? If so, you don’t need to wait, just send data to
your app, return pending and complete processing when receive IRP with
results.

BTW, wouldn’t be easier to move all user mode code to your driver? I always
prefer this solution…

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 1:06 AM
To: NT Developers Interest List
Subject: [ntdev] RE: synchronization problem

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]
>


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

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

I didn-'t really understand this method. You say to complete the IRP when I
receive my packet: in fact that’s what I thought to do. Once the IRP has
been returned my application starts executing its code, and later, when the
user function wiill be completed it will call again DEviceIoControl(). The
fact is that in my driver, I’ve to wait for the user function to complete: I
can’t proced without the data coming from the user application. How do I
wait for this event… Of course I will know my user application has
succesfully completed my function since it will send an IOCTL to my
driver…but I have to wait until that IRP is received. How do i do that in
your model?

Thanks
Matteo

----- Original Message -----
From: “George Blat”
To: “NT Developers Interest List”
Sent: Friday, March 09, 2001 4:56 AM
Subject: [ntdev] RE: synchronization problem

> 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: 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: $subst(‘Recip.EmailAddr’)
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com

Well, not really because I’ve to wait for the user mode function to
complete. My KM thread needs to be blocked until my user mode function
completes. I cannot continue in KM without the result coming from the UM
app.

I consodered the option of moving all the code to TCP/IP but that seems too
much time consuming. And moreover i need to hook the UM app to the kernel…
I need to get some packet sent to a protocol driver (TCP/IP) and manging
them from a UM app.

Thanks
Matteo
----- Original Message -----
From: “Vodicka, Michal”
To: “NT Developers Interest List”
Sent: Friday, March 09, 2001 1:33 AM
Subject: [ntdev] RE: synchronization problem

> It should work if you’re running on passive level but remember you’re
> blocking original requestor thread. In some cases it can cause funny
> deadlocks if continue in user mode.
>
> Other possibility: can you return pending status to original requestor and
> complete request later? If so, you don’t need to wait, just send data to
> your app, return pending and complete processing when receive IRP with
> results.
>
> BTW, wouldn’t be easier to move all user mode code to your driver? I
always
> prefer this solution…
>
> 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 1:06 AM
> > To: NT Developers Interest List
> > Subject: [ntdev] RE: synchronization problem
> >
> > 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]
> >
>
> —
> 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: $subst(‘Recip.EmailAddr’)
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com

A) Have your user app include an event handle in the IOCTL. Go figure out
how to convert the process specific event handle into a KEVENT object you
can use in the kernel in an arbitrary process context. Your kernel thread
blocks on the event after completing the IRP, and your user app sets the
event when its task is complete.

B) As each user thread needs no more than one event, you could also use
named events, which are easier to share between user mode and kernel mode
threads. Your user threads would ‘register’ with your driver with a separate
IOCTL providing the name of the named event specific to that thread. Your
driver could then use the documented DDK functions to open named events, and
would be responsible for correlating thread to event for your other IOCTL.

Mark Roddy
Windows 2000/NT Consultant
Hollis Technology Solutions
xxxxx@hollistech.com
603 321 1032
www.hollistech.com

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com]On Behalf Of Matteo Pelati
Sent: Friday, March 09, 2001 5:19 AM
To: NT Developers Interest List
Subject: [ntdev] RE: synchronization problem

Well, not really because I’ve to wait for the user mode function to
complete. My KM thread needs to be blocked until my user mode function
completes. I cannot continue in KM without the result coming from the UM
app.

I consodered the option of moving all the code to TCP/IP but that
seems too
much time consuming. And moreover i need to hook the UM app to
the kernel…
I need to get some packet sent to a protocol driver (TCP/IP) and manging
them from a UM app.

Thanks
Matteo
----- Original Message -----
From: “Vodicka, Michal”
> To: “NT Developers Interest List”
> Sent: Friday, March 09, 2001 1:33 AM
> Subject: [ntdev] RE: synchronization problem
>
>
> > It should work if you’re running on passive level but remember you’re
> > blocking original requestor thread. In some cases it can cause funny
> > deadlocks if continue in user mode.
> >
> > Other possibility: can you return pending status to original
> requestor and
> > complete request later? If so, you don’t need to wait, just send data to
> > your app, return pending and complete processing when receive IRP with
> > results.
> >
> > BTW, wouldn’t be easier to move all user mode code to your driver? I
> always
> > prefer this solution…
> >
> > 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 1:06 AM
> > > To: NT Developers Interest List
> > > Subject: [ntdev] RE: synchronization problem
> > >
> > > 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]
> > >
> >
> > —
> > 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@wattanuck.mv.com
> To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.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

You don’t need to wait for the event. It’s done for you without
programming. When
the application is running because the ioctl was completed the driver is
out ot the picture.
Dead. Kaput. The driver is not affecting anything because it is not being
called. When
the application completes the processing, it calls the driver back with a
brand new irp, but in
this process it can pass to the driver extra information to let the driver
know what packet it
has just been completed. When the driver receives this irp it gets back
into action, finishes the
packet and then you have to put code to make it wait until the next packet
arrives. This code
does run and has to run at PASSIVE_LEVEL in order to allow the driver to
sleep waiting for the next packet.

George

At 11:13 AM 3/9/01 +0100, you wrote:

I didn-'t really understand this method. You say to complete the IRP when I
receive my packet: in fact that’s what I thought to do. Once the IRP has
been returned my application starts executing its code, and later, when the
user function wiill be completed it will call again DEviceIoControl(). The
fact is that in my driver, I’ve to wait for the user function to complete: I
can’t proced without the data coming from the user application. How do I
wait for this event… Of course I will know my user application has
succesfully completed my function since it will send an IOCTL to my
driver…but I have to wait until that IRP is received. How do i do that in
your model?

Thanks
Matteo

----- Original Message -----
From: “George Blat”
>To: “NT Developers Interest List”
>Sent: Friday, March 09, 2001 4:56 AM
>Subject: [ntdev] RE: synchronization problem
>
>
> > 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: 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


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

Yes, that’s very similar to waht i meant. Telling the truth I didn’t think
to share the event object between user and kernel mode. This is what i was
thinking to do:

  • in my driver associate my event with an ioctl code and complete the IRP.
    At this point the app starts executing code.
  • wait on a dinamically allocated event in my driver
  • when the app completes its executin it sends an IOCTL down to my driver
    containing the ioctl code
  • in my dispatch routine receving the new ioctl i set the event so my km
    code can continue

Matteo

----- Original Message -----
From: “Mark Roddy”
To: “NT Developers Interest List”
Sent: Friday, March 09, 2001 1:03 PM
Subject: [ntdev] RE: synchronization problem

> A) Have your user app include an event handle in the IOCTL. Go figure out
> how to convert the process specific event handle into a KEVENT object you
> can use in the kernel in an arbitrary process context. Your kernel thread
> blocks on the event after completing the IRP, and your user app sets the
> event when its task is complete.
>
> B) As each user thread needs no more than one event, you could also use
> named events, which are easier to share between user mode and kernel mode
> threads. Your user threads would ‘register’ with your driver with a
separate
> IOCTL providing the name of the named event specific to that thread. Your
> driver could then use the documented DDK functions to open named events,
and
> would be responsible for correlating thread to event for your other IOCTL.
>
> Mark Roddy
> Windows 2000/NT Consultant
> Hollis Technology Solutions
> xxxxx@hollistech.com
> 603 321 1032
> www.hollistech.com
>
> > -----Original Message-----
> > From: xxxxx@lists.osr.com
> > [mailto:xxxxx@lists.osr.com]On Behalf Of Matteo Pelati
> > Sent: Friday, March 09, 2001 5:19 AM
> > To: NT Developers Interest List
> > Subject: [ntdev] RE: synchronization problem
> >
> >
> > Well, not really because I’ve to wait for the user mode function to
> > complete. My KM thread needs to be blocked until my user mode function
> > completes. I cannot continue in KM without the result coming from the UM
> > app.
> >
> > I consodered the option of moving all the code to TCP/IP but that
> > seems too
> > much time consuming. And moreover i need to hook the UM app to
> > the kernel…
> > I need to get some packet sent to a protocol driver (TCP/IP) and manging
> > them from a UM app.
> >
> > Thanks
> > Matteo
> > ----- Original Message -----
> > From: “Vodicka, Michal”
> > To: “NT Developers Interest List”
> > Sent: Friday, March 09, 2001 1:33 AM
> > Subject: [ntdev] RE: synchronization problem
> >
> >
> > > It should work if you’re running on passive level but remember you’re
> > > blocking original requestor thread. In some cases it can cause funny
> > > deadlocks if continue in user mode.
> > >
> > > Other possibility: can you return pending status to original
> > requestor and
> > > complete request later? If so, you don’t need to wait, just send data
to
> > > your app, return pending and complete processing when receive IRP with
> > > results.
> > >
> > > BTW, wouldn’t be easier to move all user mode code to your driver? I
> > always
> > > prefer this solution…
> > >
> > > 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 1:06 AM
> > > > To: NT Developers Interest List
> > > > Subject: [ntdev] RE: synchronization problem
> > > >
> > > > 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]
> > > >
> > >
> > > —
> > > 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@wattanuck.mv.com
> > 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: $subst(‘Recip.EmailAddr’)
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com

That will work fine as well, call it solution (3). However, as all you want
to do is signal a kernel thread that it can resume execution, sending an
IOCTL from user space so that an event can be signaled in kernel space seems
to be a little excessive, unless you need to send this IO request anyhow
(like to transfer data to kernel space.) I’d share the event between user
mode and kernel mode and have the app set the event, as in solutions (A) and
(B).

Mark Roddy
xxxxx@hollistech.com
www.hollistech.com
603 321 1032
WindowsNT Windows 2000 Consulting Services

-----Original Message-----
From: Matteo Pelati [mailto:xxxxx@dolce.it]
Sent: Friday, March 09, 2001 11:34 AM
To: NT Developers Interest List
Subject: [ntdev] RE: synchronization problem

Yes, that’s very similar to waht i meant. Telling the truth I didn’t think
to share the event object between user and kernel mode. This is what i was
thinking to do:

  • in my driver associate my event with an ioctl code and complete the IRP.
    At this point the app starts executing code.
  • wait on a dinamically allocated event in my driver
  • when the app completes its executin it sends an IOCTL down to my driver
    containing the ioctl code
  • in my dispatch routine receving the new ioctl i set the event so my km
    code can continue

Matteo

----- Original Message -----
From: “Mark Roddy”
To: “NT Developers Interest List”
Sent: Friday, March 09, 2001 1:03 PM
Subject: [ntdev] RE: synchronization problem

> A) Have your user app include an event handle in the IOCTL. Go figure out
> how to convert the process specific event handle into a KEVENT object you
> can use in the kernel in an arbitrary process context. Your kernel thread
> blocks on the event after completing the IRP, and your user app sets the
> event when its task is complete.
>
> B) As each user thread needs no more than one event, you could also use
> named events, which are easier to share between user mode and kernel mode
> threads. Your user threads would ‘register’ with your driver with a
separate
> IOCTL providing the name of the named event specific to that thread. Your
> driver could then use the documented DDK functions to open named events,
and
> would be responsible for correlating thread to event for your other IOCTL.
>
> Mark Roddy
> Windows 2000/NT Consultant
> Hollis Technology Solutions
> xxxxx@hollistech.com
> 603 321 1032
> www.hollistech.com
>
> > -----Original Message-----
> > From: xxxxx@lists.osr.com
> > [mailto:xxxxx@lists.osr.com]On Behalf Of Matteo Pelati
> > Sent: Friday, March 09, 2001 5:19 AM
> > To: NT Developers Interest List
> > Subject: [ntdev] RE: synchronization problem
> >
> >
> > Well, not really because I’ve to wait for the user mode function to
> > complete. My KM thread needs to be blocked until my user mode function
> > completes. I cannot continue in KM without the result coming from the UM
> > app.
> >
> > I consodered the option of moving all the code to TCP/IP but that
> > seems too
> > much time consuming. And moreover i need to hook the UM app to
> > the kernel…
> > I need to get some packet sent to a protocol driver (TCP/IP) and manging
> > them from a UM app.
> >
> > Thanks
> > Matteo
> > ----- Original Message -----
> > From: “Vodicka, Michal”
> > To: “NT Developers Interest List”
> > Sent: Friday, March 09, 2001 1:33 AM
> > Subject: [ntdev] RE: synchronization problem
> >
> >
> > > It should work if you’re running on passive level but remember you’re
> > > blocking original requestor thread. In some cases it can cause funny
> > > deadlocks if continue in user mode.
> > >
> > > Other possibility: can you return pending status to original
> > requestor and
> > > complete request later? If so, you don’t need to wait, just send data
to
> > > your app, return pending and complete processing when receive IRP with
> > > results.
> > >
> > > BTW, wouldn’t be easier to move all user mode code to your driver? I
> > always
> > > prefer this solution…
> > >
> > > 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 1:06 AM
> > > > To: NT Developers Interest List
> > > > Subject: [ntdev] RE: synchronization problem
> > > >
> > > > 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]
> > > >
> > >
> > > —
> > > 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@wattanuck.mv.com
> > 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@stratus.com
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.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

> Dead. Kaput. The driver is not affecting anything because it is not being

called. When
the application completes the processing, it calls the driver back with a
brand new irp, but in
this process it can pass to the driver extra information to let the driver
know what packet it
has just been completed. When the driver receives this irp it gets back

Exactly so. We have a rather well debugged code using this technique.
Note: the driver must protect itself from the app which will specify
intentionally wrong “completion key” value. It must not BSOD in this case.

Max


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