IOCTL

Hi ppl

Something’s puzzling me. Suppose I have a driver that has one device
object registered. Now there are lets say 3 different programs calling the
IOCTL interface of the driver(using createfile() and deviceiocontrol()).

Now my question is , how would the driver manage its variables? Since only
one instance of driver is running, wouldnt the variables(local to the
driver) be shared by each of the three programs? If so, how to get over
it. Would creating different device objects help(which i really doubt)?

It would be really helpful if someone can give the internal calling
mechanism for deviceiocontrol()(what actually happens??)

Thank you very much
Looking for some insight

Arijit

It depends on what the data is that each of the 3 programs are competing
for. If it is shared data, you must provide synchronization around that
data and hand it out appropriately. If each program has its own set of
data, you can allocate a structure while processing IRP_MJ_CREATE and
store it in PFILE_OBJECT->FsContext. You would free it in IRP_MJ_CLOSE
for the same PFILE_OBJECT. Usage of FxContext (or FsContext2 for that
matter) assumes that you are in the device stack by yourself, other
stacks like file systems or HID use this field.

d

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Arijit
Bhattacharyya
Sent: Tuesday, September 21, 2004 11:17 AM
To: Windows System Software Devs Interest List
Subject: [ntdev] IOCTL

Hi ppl

Something’s puzzling me. Suppose I have a driver that has one device
object registered. Now there are lets say 3 different programs calling
the
IOCTL interface of the driver(using createfile() and deviceiocontrol()).

Now my question is , how would the driver manage its variables? Since
only
one instance of driver is running, wouldnt the variables(local to the
driver) be shared by each of the three programs? If so, how to get over
it. Would creating different device objects help(which i really doubt)?

It would be really helpful if someone can give the internal calling
mechanism for deviceiocontrol()(what actually happens??)

Thank you very much
Looking for some insight

Arijit


Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

You are currently subscribed to ntdev as: unknown lmsubst tag argument:
‘’
To unsubscribe send a blank email to xxxxx@lists.osr.com

If you are using a proprietary interface;i.e. you open the device up via a
symlink and pass the IOCtls to this handle, then you can track the per open
instance information from each app via the FileObject->FsContext pointer.
You can initialize this structure in the IRP_MJ_CREATE handling and then you
can track per instance variables via this structure since the same
FileObject will be passed to your device control dispatch handler. The nice
thing is then you can perform all your clean up in the IRP_MJ_CLEANUP
handler.

Of course this won’t work for a filesystem filter driver, without some more
work, but I can only assume you are talking about a different type driver
from the forum you posted to.

Pete

xxxxx@KernelDrivers.com
www.KernelDrivers.com
1-866-263-9295

-----Original Message-----
From: xxxxx@lists.osr.com [mailto:bounce-188122-
xxxxx@lists.osr.com] On Behalf Of Arijit Bhattacharyya
Sent: Tuesday, September 21, 2004 12:17 PM
To: Windows System Software Devs Interest List
Subject: [ntdev] IOCTL

Hi ppl

Something’s puzzling me. Suppose I have a driver that has one device
object registered. Now there are lets say 3 different programs calling the
IOCTL interface of the driver(using createfile() and deviceiocontrol()).

Now my question is , how would the driver manage its variables? Since only
one instance of driver is running, wouldnt the variables(local to the
driver) be shared by each of the three programs? If so, how to get over
it. Would creating different device objects help(which i really doubt)?

It would be really helpful if someone can give the internal calling
mechanism for deviceiocontrol()(what actually happens??)

Thank you very much
Looking for some insight

Arijit


Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

You are currently subscribed to ntdev as: unknown lmsubst tag argument: ‘’
To unsubscribe send a blank email to xxxxx@lists.osr.com

You need to go study multi-threaded programming concepts.

The internal calling mechanism for the dispatch functions is not an issue.
Your DeviceIoControl dispatch routine is just another function that can be
called from multiple threads of execution. Its local variables are generally
instantiated on the stack belonging to each thread invoking the function, so
each thread has its own copy of these variables and there is no
multi-threaded shared data issue with these variables. The driver
programming architecture steers your design towards using a per-device
object shared data structure (your device extension) for state that is
common to a device object. You do have to worry about concurrent access to
that data structure and, where appropriate, using locking (or other
concurrency mechanisms) to control access.

=====================
Mark Roddy

-----Original Message-----
From: Arijit Bhattacharyya [mailto:xxxxx@fht-esslingen.de]
Sent: Tuesday, September 21, 2004 2:17 PM
To: Windows System Software Devs Interest List
Subject: [ntdev] IOCTL

Hi ppl

Something’s puzzling me. Suppose I have a driver that has one device object
registered. Now there are lets say 3 different programs calling the IOCTL
interface of the driver(using createfile() and deviceiocontrol()).

Now my question is , how would the driver manage its variables? Since only
one instance of driver is running, wouldnt the variables(local to the
driver) be shared by each of the three programs? If so, how to get over it.
Would creating different device objects help(which i really doubt)?

It would be really helpful if someone can give the internal calling
mechanism for deviceiocontrol()(what actually happens??)

Thank you very much
Looking for some insight

Arijit


Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

You are currently subscribed to ntdev as: unknown lmsubst tag argument: ‘’
To unsubscribe send a blank email to xxxxx@lists.osr.com

When the CREATE IRP comes in, allocate a structure for all your “private”
stuff and store a pointer to it in the DriverContext fields of the
FILE_OBJECT. The FILE_OBJECT represents the “file handle” to your driver,
so everytime someone calls CreateFile() to “open” your driver he’ll get a
new FILE_OBJECT. Since it’s a “handle” to your driver you’re free to use
the DriverContext fields. So that’s the “per file-handle” way. I’m afraid
I don’t know any “per process” way.
Ah yes, of course be sure to free that block of memory in the
cleanup/close handlers…

Bye,

Paul Groke

“Arijit Bhattacharyya”
Gesendet von: xxxxx@lists.osr.com
21.09.2004 20:16
Bitte antworten an “Windows System Software Devs Interest List”

An: “Windows System Software Devs Interest List”

Kopie:
Thema: [ntdev] IOCTL

Hi ppl

Something’s puzzling me. Suppose I have a driver that has one device
object registered. Now there are lets say 3 different programs calling the
IOCTL interface of the driver(using createfile() and deviceiocontrol()).

Now my question is , how would the driver manage its variables? Since only
one instance of driver is running, wouldnt the variables(local to the
driver) be shared by each of the three programs? If so, how to get over
it. Would creating different device objects help(which i really doubt)?

It would be really helpful if someone can give the internal calling
mechanism for deviceiocontrol()(what actually happens??)

Thank you very much
Looking for some insight

Arijit


Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

You are currently subscribed to ntdev as: unknown lmsubst tag argument: ‘’
To unsubscribe send a blank email to xxxxx@lists.osr.com

Please visit us: www.tab.at www.championsnet.net
www.silverball.com

The per-fileobject approach is useful if state has to be persisted across
multiple IO requests. Generally the issue is resolved much more simply by
allocating some context information for the particular request itself and
associating the IRP with the context.

=====================
Mark Roddy

-----Original Message-----
From: Peter Scott [mailto:xxxxx@kerneldrivers.com]
Sent: Tuesday, September 21, 2004 2:36 PM
To: Windows System Software Devs Interest List
Subject: RE: [ntdev] IOCTL

If you are using a proprietary interface;i.e. you open the device up via a
symlink and pass the IOCtls to this handle, then you can track the per open
instance information from each app via the FileObject->FsContext pointer.
You can initialize this structure in the IRP_MJ_CREATE handling and then you
can track per instance variables via this structure since the same
FileObject will be passed to your device control dispatch handler. The nice
thing is then you can perform all your clean up in the IRP_MJ_CLEANUP
handler.

Of course this won’t work for a filesystem filter driver, without some more
work, but I can only assume you are talking about a different type driver
from the forum you posted to.

Pete

xxxxx@KernelDrivers.com
www.KernelDrivers.com
1-866-263-9295

-----Original Message-----
From: xxxxx@lists.osr.com [mailto:bounce-188122-
xxxxx@lists.osr.com] On Behalf Of Arijit Bhattacharyya
Sent: Tuesday, September 21, 2004 12:17 PM
To: Windows System Software Devs Interest List
Subject: [ntdev] IOCTL

Hi ppl

Something’s puzzling me. Suppose I have a driver that has one device
object registered. Now there are lets say 3 different programs calling
the IOCTL interface of the driver(using createfile() and
deviceiocontrol()).

Now my question is , how would the driver manage its variables? Since
only one instance of driver is running, wouldnt the variables(local to
the
driver) be shared by each of the three programs? If so, how to get
over it. Would creating different device objects help(which i really
doubt)?

It would be really helpful if someone can give the internal calling
mechanism for deviceiocontrol()(what actually happens??)

Thank you very much
Looking for some insight

Arijit


Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

You are currently subscribed to ntdev as: unknown lmsubst tag argument: ‘’
To unsubscribe send a blank email to xxxxx@lists.osr.com


Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

You are currently subscribed to ntdev as: xxxxx@stratus.com To
unsubscribe send a blank email to xxxxx@lists.osr.com

> stuff and store a pointer to it in the DriverContext fields of the

FILE_OBJECT.

More exactly: FileObject->FsContext2.

Do not use ->FsContext. Leave it to be NULL, unless you will want to support
the memory mapping of your files. I saw some strange BSODs if ->FsContext is
set to non-NULL and not to a valid FCB header.

Maxim Shatskih, Windows DDK MVP
StorageCraft Corporation
xxxxx@storagecraft.com
http://www.storagecraft.com