Hi,
would it be legal (and possible) to modify the dispatch table of a running
driver? To be more specific, what I’d like to do is to have one function
called the very first time IRP_MJ_CREATE is dispatched, and another for all
subsequent ones. This is to have specific initialization the first time any
app opens the device, and avoid having a synchronization mechanism combined
with a test for initialization for each following create irp.
The driver will have one device object only, which is created during driver
load, so I’m considering using an executive spinlock inside the device
extension for synchronization, something along the following lines:
*****************
struct MY_DEVICE_EXTENSION
{
…
KSPIN_LOCK CreateDispatchSpinLock; // Initialized during
creation of device
BOOLEAN CreateInitiallyCalled; // Initialized during
creation of device to FALSE
…
};
NTSTATUS
DriverEntry(…)
{
…
pDriverObject->MajorFunction[IRP_MJ_CREATE] = InitialCreate;
…
};
NTSTATUS
InitialCreate(…)
{
… get device extension …
… get spinlock from extension …
… acquire spinlock …
if (FALSE == pDeviceExtension->CreateInitiallyCalled)
{
… do one time initialization …
pDeviceExtension->CreateInitiallyCalled = TRUE;
… get driver object …
pDriverObject->MajorFunction[IRP_MJ_CREATE] = NormalCreate;
}
… release spinlock
… complete IRP
return NT_SUCCESS;
}
NTSTATUS
NormalCreate(…)
{
… complete IRP
return NT_SUCCESS;
}
**************************************
// Johan Nilsson
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
Hi,
NT Maintains only one Linked list ( I mean DEVICE_OBJECT ) with all
information related to Device Driver.
If u Aquare Spin lock and Change this structure it should Work. This is just
like changing a Global Variable in ur Driver.
This is what i Feel …
Regards,
Satish K.S
----- Original Message -----
From:
To: “NT Developers Interest List”
Sent: Wednesday, January 03, 2001 3:17 PM
Subject: [ntdev] Modify drivers dispatch table
> Hi,
>
> would it be legal (and possible) to modify the dispatch table of a running
> driver? To be more specific, what I’d like to do is to have one function
> called the very first time IRP_MJ_CREATE is dispatched, and another for
all
> subsequent ones. This is to have specific initialization the first time
any
> app opens the device, and avoid having a synchronization mechanism
combined
> with a test for initialization for each following create irp.
>
> The driver will have one device object only, which is created during
driver
> load, so I’m considering using an executive spinlock inside the device
> extension for synchronization, something along the following lines:
>
>
>
> struct MY_DEVICE_EXTENSION
> {
> …
> KSPIN_LOCK CreateDispatchSpinLock; // Initialized during
> creation of device
> BOOLEAN CreateInitiallyCalled; // Initialized during
> creation of device to FALSE
> …
> };
>
> NTSTATUS
> DriverEntry(…)
> {
> …
> pDriverObject->MajorFunction[IRP_MJ_CREATE] = InitialCreate;
> …
> };
>
> NTSTATUS
> InitialCreate(…)
> {
> … get device extension …
> … get spinlock from extension …
> … acquire spinlock …
>
> if (FALSE == pDeviceExtension->CreateInitiallyCalled)
> {
> … do one time initialization …
> pDeviceExtension->CreateInitiallyCalled = TRUE;
> … get driver object …
> pDriverObject->MajorFunction[IRP_MJ_CREATE] = NormalCreate;
> }
>
> … release spinlock
> … complete IRP
>
> return NT_SUCCESS;
> }
>
> NTSTATUS
> NormalCreate(…)
> {
> … complete IRP
>
> return NT_SUCCESS;
> }
>
>
>*********************
>
>
> // Johan Nilsson
>
> —
> You are currently subscribed to ntdev as: xxxxx@aalayance.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
It would be much simpler to have a static local LONG in your dispatch
routine that is Interlock test and set and if zero when tested you call
function x else you call function y. There are reasons why you might want to
modify the dispatch table of a driver ‘on the fly’ but this is not one of
them.
Mark Roddy
xxxxx@hollistech.com
www.hollistech.com
WindowsNT Windows 2000 Consulting Services
-----Original Message-----
From: Satish [mailto:xxxxx@aalayance.com]
Sent: Wednesday, January 03, 2001 5:15 AM
To: NT Developers Interest List
Subject: [ntdev] Re: Modify drivers dispatch table
Hi,
NT Maintains only one Linked list ( I mean DEVICE_OBJECT ) with all
information related to Device Driver.
If u Aquare Spin lock and Change this structure it should
Work. This is just
like changing a Global Variable in ur Driver.
This is what i Feel …
Regards,
Satish K.S
----- Original Message -----
From:
> To: “NT Developers Interest List”
> Sent: Wednesday, January 03, 2001 3:17 PM
> Subject: [ntdev] Modify drivers dispatch table
>
>
> > Hi,
> >
> > would it be legal (and possible) to modify the dispatch
> table of a running
> > driver? To be more specific, what I’d like to do is to have
> one function
> > called the very first time IRP_MJ_CREATE is dispatched, and
> another for
> all
> > subsequent ones. This is to have specific initialization
> the first time
> any
> > app opens the device, and avoid having a synchronization mechanism
> combined
> > with a test for initialization for each following create irp.
> >
> > The driver will have one device object only, which is created during
> driver
> > load, so I’m considering using an executive spinlock inside
> the device
> > extension for synchronization, something along the following lines:
> >
> >
> >
> > struct MY_DEVICE_EXTENSION
> > {
> > …
> > KSPIN_LOCK CreateDispatchSpinLock; // Initialized during
> > creation of device
> > BOOLEAN CreateInitiallyCalled; // Initialized during
> > creation of device to FALSE
> > …
> > };
> >
> > NTSTATUS
> > DriverEntry(…)
> > {
> > …
> > pDriverObject->MajorFunction[IRP_MJ_CREATE] = InitialCreate;
> > …
> > };
> >
> > NTSTATUS
> > InitialCreate(…)
> > {
> > … get device extension …
> > … get spinlock from extension …
> > … acquire spinlock …
> >
> > if (FALSE == pDeviceExtension->CreateInitiallyCalled)
> > {
> > … do one time initialization …
> > pDeviceExtension->CreateInitiallyCalled = TRUE;
> > … get driver object …
> > pDriverObject->MajorFunction[IRP_MJ_CREATE] = NormalCreate;
> > }
> >
> > … release spinlock
> > … complete IRP
> >
> > return NT_SUCCESS;
> > }
> >
> > NTSTATUS
> > NormalCreate(…)
> > {
> > … complete IRP
> >
> > return NT_SUCCESS;
> > }
> >
> >
> >*********************
> >
> >
> > // Johan Nilsson
> >
> > —
> > You are currently subscribed to ntdev as: xxxxx@aalayance.com
> > 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