HELP: Disabling Interrupts in multiple process environment

K

kindsol

Hello.

I maintain a WDM driver that get's instantiated/created by multiple
processes. Problem is that any process could possible call my
DISABLE_INTERRUPTS ioctl call which would disable interrupts for all
remaining processes.

Is there a way to disable interrupts only if the calling process is the only
process that has created an instance of the driver? Any suggestions?

I was think of something similar to a counting semaphore, but this semaphore
counter would need to be decremented even if a process died without a
"clean" exit. Is there a way to tell how many processes are attached (or
have created a handle to) a given device driver?

thank you for any guidance
 
A

Alexander Grigoriev

You definitely should NOT do that. Your design is fundamentally flawed if
you need such DISABLE_INTERRUPTS call.

Tell what you're using DISABLE_INTERRUPTS for. Are you serializing access to
the device? You can use a mutex. Mutex has 'ownership' semantics. You can
also track ownership by handle (FILE_OBJECT).
 
D

Don Burn

First what do you mean by disable interrupts? Providing control of
interrupts from user space is almost never a good idea.

The IRP_MJ_CREATE call will be called for each process that creates a
handle, and the IRP_MJ_CLOSE will indicate the close of a handle. You will
get an IRP_MJ_CLOSE even if the process dies, the problem here is that it
may be a while after the process dies for the close to come.
 
A

Alexander Grigoriev

IRP_MJ_CLEANUP and IRP cancellation should be used instead. IRP_MJ_CLOSE is
not issued until all the references to the FILE_OBJECT (including those held
by the pending IRPs) are released.
 
P

pkk

Alexander Grigoriev said:
You can also track ownership by handle (FILE_OBJECT).
I can't find any Reference Count field in FILE_OBJECT.
How does a FILE_OBJECT keeps count of open handles on itself?
Thanks
 
A

Alexander Grigoriev

You can set a pointer to your own context structure in
FILE_OBJECT::FsContext2, and keep there whatever per-handle state you need.
 
S

Slava M. Usov

I can't find any Reference Count field in FILE_OBJECT.
How does a FILE_OBJECT keeps count of open handles on itself?

Why do you care? The system does that for you, so you concentrate on your
task. But if it is just curiosity, then here's the answer: all Object
Manager's allocated objects have a prefix, which is _before_ the object you
have a pointer to, and the refcount is a field in that prefix.

S
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top