> Hi All,
// Windows NT
In the IRP data-structure, there is a DriverContext with the following
comment.
//The following are available to the driver to use in
// whatever manner is desired, while the driver owns the
// packet.
PVOID DriverContext[4];
Can we use it to store info we need at the time of completion processing?
Scenario:
We have a kernel mode driver exporting functions just like a DLL.
The client driver invokes the DDI (Driver To Driver Interface) and the
kernel dll hides the details of creating IRPs and communicate to the real
driver which performs the work.
The client driver may supply a callback function pointer and the kernel
mode dll need to invoke the callback when the results are ready. Can we
set completion routines when creating IRPs (from inside the kernel mode
dll) and store the callback pointer (the client supplied) in the
DriverContext? Later from inside the completion routine, we shall
access the same callback pointer …to invoke the callback…
The psudo code is something like
// File for the kernel mode driver exporting functions
// kernel_dll.c
_declspec(dllexport)
void ProcessPkt(PKT* pkt)
{
Build the IRP
Set the completion routine.
Save the callback pointer context in irp’s DriverContext
IoCallDriver to send the IRP to the target.
}
//Completion routine
{
extract the callback pointer from IRP’s DriverContext
pCallback(); //invoke the callback
return success;
}
We tried the above method. It seems working. Are we missing something?
Please comment
TIA
Balan
Balakrishnan R.
Sr.Software Engineer
Device Driver Group
NeST
www.nesttech.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 are counting on the ‘target’ not using DriverContext. As any driver is
allowed to use DriverContext while it ‘owns’ the IRP, you are basing your
design on an unsafe assumption. If you are in control of both drivers, then
you can of course enforce a restriction on the target driver, and your
design is safe as long as your constraints are clearly documented and
rigorously enforced.
If all you need is one PVOID worth of information, then why not use the
Context parameter of your completion handler? This is safe, as the value is
stored in an IO_STACK_LOCATION for your driver’s exclusive use, rather than
shared by all drivers processing the IRP.
If you need more than a single PVOID, I would allocate an object from heap
to store the information and pass a pointer to that object through the
completion handler context parameter.
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 BALAN
Sent: Wednesday, March 07, 2001 6:48 AM
To: NT Developers Interest List
Subject: [ntdev] DriverContext inside IRP
> Hi All,
>
> // Windows NT
>
> In the IRP data-structure, there is a DriverContext with the following
> comment.
>
> //The following are available to the driver to use in
> // whatever manner is desired, while the driver owns the
// packet.
> PVOID DriverContext[4];
>
> Can we use it to store info we need at the time of completion
processing?
>
> Scenario:
> We have a kernel mode driver exporting functions just like a DLL.
> The client driver invokes the DDI (Driver To Driver Interface) and the
> kernel dll hides the details of creating IRPs and communicate
to the real
> driver which performs the work.
> The client driver may supply a callback function pointer and the kernel
> mode dll need to invoke the callback when the results are ready. Can we
> set completion routines when creating IRPs (from inside the kernel mode
> dll) and store the callback pointer (the client supplied) in the
> DriverContext? Later from inside the completion routine, we shall
> access the same callback pointer …to invoke the callback…
>
> The psudo code is something like
>
> // File for the kernel mode driver exporting functions
> // kernel_dll.c
>
> _declspec(dllexport)
> void ProcessPkt(PKT* pkt)
> {
> Build the IRP
> Set the completion routine.
> Save the callback pointer context in irp’s DriverContext
> IoCallDriver to send the IRP to the target.
> }
>
> //Completion routine
> {
> extract the callback pointer from IRP’s DriverContext
> pCallback(); //invoke the callback
> return success;
> }
>
We tried the above method. It seems working. Are we missing something?
Please comment
TIA
Balan
> ----------------------------------------------
> Balakrishnan R.
> Sr.Software Engineer
> Device Driver Group
> NeST
> www.nesttech.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