Executive spin locks

I have one question: how ExInterlockedInsertHeadList() function can be
called at raised IRQL (above DISPATCH_LEVEL) with executive spin lock as a
parameter??? As I know executive spin locks can be acquired at IRQL <=
DISPATCH_LEVEL. I quickly looked thru asm code of the
ExfInterlockedInsertHeadList() function and I saw that this function uses
own methods to operate with passed spin lock but I saw it in NTOSKRNL.EXE
for uniprocessor configuration. How does it really work? Moreover I heard
some info where executive spinlocks were used in ISRs. It really confused me
too much… Many thanks in advance.

Konstantin Manurin
Programmer
Nival Interactive
mailto:xxxxx@nival.com

10a bld. 5, 1st Volokolamsky proezd
Moscow 123060 Russia
Tel: +7 (095) 363-9630
Fax: +7 (095) 363-9631
http://www.nival.com
http://www.etherlords.com
http://www.evil-islands.com

This subject was discussed several times in the past, try to search archives
for ExInterlocked*. SMP version looks like:

_ExInterlockedInsertHeadList
0008:804FE9D0 MOV EDX,[ESP+0C]
0008:804FE9D4 PUSHFD
0008:804FE9D5 CLI
0008:804FE9D6 LOCK BTS DWORD PTR [EDX],00
0008:804FE9DB JB 804FEA04
0008:804FE9DD MOV EAX,[ESP+08]
0008:804FE9E1 MOV ECX,[ESP+0C]
0008:804FE9E5 MOV EDX,[EAX]
0008:804FE9E7 MOV [ECX],EDX
0008:804FE9E9 MOV [ECX+04],EAX
0008:804FE9EC MOV [EAX],ECX
0008:804FE9EE MOV [EDX+04],ECX
0008:804FE9F1 MOV ECX,[ESP+10]
0008:804FE9F5 MOV BYTE PTR [ECX],00
0008:804FE9F8 POPFD
0008:804FE9F9 XOR EAX,EDX
0008:804FE9FB JZ 804FE9FF
0008:804FE9FD MOV EAX,EDX
0008:804FE9FF RET 000C
0008:804FEA02 MOV EDI,EDI
0008:804FEA04 POPFD
0008:804FEA05 TEST DWORD PTR [EDX],00000001
0008:804FEA0B JZ 804FE9D4
0008:804FEA0D REPZ NOP
0008:804FEA0F JMP 804FEA05

Yes, it uses spinlocks own way. As you can see, it disables interrupts,
tries grab spinlock and if successful, performs action, releases spionlock
and enables interrupts (more precisely, restores original flags). If can’t
grab spinlock, enables interrupts and spins until spinlock is available and
then starts from begin. Basically, spinlock is used for multiprocessor
synchronization here and interrupts have to be disabled to avoid deadlock on
current CPU (if an interrupt occurs when spinlock is acquired and tries to
grab the same spinlock, interrupted spinlock owner can’t release it).

Best regards,

Michal Vodicka
STMicroelectronics Design and Application s.r.o.
[michal.vodicka@st.com, http:://www.st.com]


From:
xxxxx@nival.com[SMTP:xxxxx@nival.com]
Reply To: xxxxx@lists.osr.com
Sent: Friday, May 24, 2002 9:52 AM
To: xxxxx@lists.osr.com
Subject: [ntdev] Executive spin locks

I have one question: how ExInterlockedInsertHeadList() function can be
called at raised IRQL (above DISPATCH_LEVEL) with executive spin lock as
a
parameter??? As I know executive spin locks can be acquired at IRQL <=
DISPATCH_LEVEL. I quickly looked thru asm code of the
ExfInterlockedInsertHeadList() function and I saw that this function uses
own methods to operate with passed spin lock but I saw it in NTOSKRNL.EXE
for uniprocessor configuration. How does it really work? Moreover I heard
some info where executive spinlocks were used in ISRs. It really confused
me
too much… Many thanks in advance.

Konstantin Manurin
Programmer
Nival Interactive
mailto:xxxxx@nival.com

10a bld. 5, 1st Volokolamsky proezd
Moscow 123060 Russia
Tel: +7 (095) 363-9630
Fax: +7 (095) 363-9631
http://www.nival.com
http://www.etherlords.com
http://www.evil-islands.com


You are currently subscribed to ntdev as: michal.vodicka@st.com
To unsubscribe send a blank email to %%email.unsub%%