spinlock & event question

Hi all,

Is it possible to both release a spinlock and wait for a notification
event, atomically, as a single operation?
Does the kernel offer such support, and if yes, with which routine?

thank you very much,

Sandor LUKACS
Virus Analyst, SOFTWIN

ps. it might be a very simple question, but I’m looking for
such a function for over a hour and just doesn’t see it :frowning:

Is not possible to wait for anything as a atomic operation.

----- Original Message -----
From:
To: “Windows System Software Devs Interest List”
Sent: Monday, November 06, 2006 10:47 AM
Subject: [ntdev] spinlock & event question

> Hi all,
>
> Is it possible to both release a spinlock and wait for a notification
> event, atomically, as a single operation?
> Does the kernel offer such support, and if yes, with which routine?
>
> thank you very much,
>
> Sandor LUKACS
> Virus Analyst, SOFTWIN
>
> ps. it might be a very simple question, but I’m looking for
> such a function for over a hour and just doesn’t see it :frowning:
>
> —
> Questions? First check the Kernel Driver FAQ at
> http://www.osronline.com/article.cfm?id=256
>
> To unsubscribe, visit the List Server section of OSR Online at
> http://www.osronline.com/page.cfm?name=ListServer

Hi,

Is not possible to wait for anything as a atomic operation.

AFAIK it IS possible to wait atomically for semaphores; take a look at
KeReleaseSemaphore, if you call it with Wait = TRUE, then you can
release the semaphore and call immediatly a KeWaitFor… function
in atomical fashion;

but I would need to do such a thing, but with releasing a spinlock
instead of a semaphore; any other ideas?

thank you,

Sandor LUKACS
Virus Analyst, SOFTWIN

Don;t think you can find a solution for this.

~Sisimon

On 11/6/06, xxxxx@bitdefender.com wrote:
>
> Hi all,
>
> Is it possible to both release a spinlock and wait for a notification
> event, atomically, as a single operation?
> Does the kernel offer such support, and if yes, with which routine?
>
> thank you very much,
>
> Sandor LUKACS
> Virus Analyst, SOFTWIN
>
> ps. it might be a very simple question, but I’m looking for
> such a function for over a hour and just doesn’t see it :frowning:
>
> —
> Questions? First check the Kernel Driver FAQ at
> http://www.osronline.com/article.cfm?id=256
>
> To unsubscribe, visit the List Server section of OSR Online at
> http://www.osronline.com/page.cfm?name=ListServer
>


GCS d+ s: a- c++++ U> B+ L++>$ w++++$ W++(+++) PGP+N+ t PS+PE++ tv+(++) b+++
G+++ e++>(++++) h-- r
Don’t know this? See http://www.geekcode.com/geek.html

I understand that you are trying to build the same posix semantics for
your spinlocks.
You can try the following (AT YOUR RISK!!) with a caveat that you cannot
use MYSPINLOCK_SLEEP at dispatch level.

Declare your spinlock struct as
typedef struct {
KSPIN_LOCK SpinLock; /* spin lock */
KSEMAPHORE Sem; /* semaphore object */
ULONG nsleepers; /* # of threads sleeping
*/
ULONG nwakeups; /* # of wakeups */
} my_spinlock_t;

MYSPINLOCK_LOCK simply aquires the SpinLock and MYSPINLOCK_UNLOCK
releases the SpinLock

MYSPINLOCK_SLEEP(lock) macro /* assumes that lock is already aquired */
do {
KIRQL zopri;
++(lock)->nsleepers; \
zopri = PASSIVE_LEVEL; \
MYSPINLOCK_UNLOCK(lock, zopri); \
KeWaitForSingleObject(&(lock)->Sem, \
Executive, KernelMode, FALSE, NULL);\
MYSPINLOCK_LOCK(lock, zopri); \
–(lock)->nsleepers; \
–(lock)->nwakeups; \
} while (0)

MYSPINLOCK_WAKEUP(lock) macro to wakeup all those sleeping
do {
if ((lock)->nsleepers > (lock)->nwakeups) { \
KeReleaseSemaphore(&(lock)->Sem, \
IO_NO_INCREMENT, \
(lock)->nsleepers - \
(lock)->nwakeups, FALSE); \
(lock)->nwakeups = (lock)->nsleepers; \
} \
} while (0)

MYSPINLOCK_WAKEUP_ONE would be a variant in which you would release only
1 Semaphore resource.

-----Original Message-----
From: xxxxx@lists.osr.com [mailto:bounce-268957-
xxxxx@lists.osr.com] On Behalf Of xxxxx@bitdefender.com
Sent: Monday, November 06, 2006 12:47 AM
To: Windows System Software Devs Interest List
Subject: [ntdev] spinlock & event question

Hi all,

Is it possible to both release a spinlock and wait for a notification
event, atomically, as a single operation?
Does the kernel offer such support, and if yes, with which routine?

thank you very much,

Sandor LUKACS
Virus Analyst, SOFTWIN

ps. it might be a very simple question, but I’m looking for
such a function for over a hour and just doesn’t see it :frowning:


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

To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer

On Nov 6, 2006, at 12:46 PM, Harish Arora wrote:

I understand that you are trying to build the same posix semantics for
your spinlocks.
You can try the following (AT YOUR RISK!!) with a caveat that you
cannot
use MYSPINLOCK_SLEEP at dispatch level.

Declare your spinlock struct as
typedef struct {
KSPIN_LOCK SpinLock; /* spin lock */
KSEMAPHORE Sem; /* semaphore object */
ULONG nsleepers; /* # of threads sleeping
*/
ULONG nwakeups; /* # of wakeups */
} my_spinlock_t;

MYSPINLOCK_LOCK simply aquires the SpinLock and MYSPINLOCK_UNLOCK
releases the SpinLock

MYSPINLOCK_SLEEP(lock) macro /* assumes that lock is already
aquired */
do {
KIRQL zopri;
++(lock)->nsleepers; \
zopri = PASSIVE_LEVEL; \
MYSPINLOCK_UNLOCK(lock, zopri); \
KeWaitForSingleObject(&(lock)->Sem, \
Executive, KernelMode, FALSE, NULL);\
MYSPINLOCK_LOCK(lock, zopri); \
–(lock)->nsleepers; \
–(lock)->nwakeups; \
} while (0)

This looks broken to me; you release the spin lock before you wait;
that’s not atomic at all. You’re going to need OS support for this.

-sd

Hi all,

Can anyone tell me if and how could I check from a driver, that a process which tries to connect to a communication port of the driver is digitally signed or not, if the signature if valid, who signed that process and so on. This could be a quite effective way to prevent unauthorized processes to connect to the driver.

Any comments on this subject are welcomed.

thank you very much,

Sandor LUKACS
Virus Analyst, SOFTWIN

sorry about the prior post, should have been a NEW topic,

Sandor LUKACS

How do you know that someone hasn’t injected code into your process with a
signed .exe?

This approach is flawed.


Ken Johnson (Skywing)
Windows SDK MVP
http://www.nynaeve.net

wrote in message news:xxxxx@ntdev…
> Hi all,
>
> Can anyone tell me if and how could I check from a driver, that a process
> which tries to connect to a communication port of the driver is digitally
> signed or not, if the signature if valid, who signed that process and so
> on. This could be a quite effective way to prevent unauthorized processes
> to connect to the driver.
>
> Any comments on this subject are welcomed.
>
> thank you very much,
>
> Sandor LUKACS
> Virus Analyst, SOFTWIN
>