OSRLogoOSRLogoOSRLogo x Seminar Ad

Everything Windows Driver Development

GoToHomePage xLoginx

    Thu, 14 Mar 2019     118020 members


  Online Dump Analyzer
OSR Dev Blog
The NT Insider
The Basics
File Systems
ListServer / Forum
  Express Links
  · The NT Insider Digital Edition - May-June 2016 Now Available!
  · Windows 8.1 Update: VS Express Now Supported
  · HCK Client install on Windows N versions
  · There's a WDFSTRING?
  · When CAN You Call WdfIoQueueP...ously

Beware of KeAcquireSpinLockRaiseToSynch(...)!

Starting with Windows 2000®, the NTDDK.H included the definition of a function named KeAcquireSpinLockRaiseToSynch(…). This function was never documented in the DDK documentation, and (quite frankly) was probably exposed unintentionally.

What made this function particularly interesting was that in Win2K, SYNCH_LEVEL was defined as IPI_LEVEL-1, which is at least as high as the highest device IRQL.  Thus, I've seen developers who use this function as the equivalent of "KeAcquire A Spin Lock That's At Least As High As the highest DIRQL."

This is a Very Bad Idea.

IRQL SYNCH_LEVEL was never intended to be equal to "at least as high as the highest DIRQL."  Thus, in Windows XP®, you can see SYNCH_LEVEL was changed as follows:

#if defined(NT_UP)

    #define SYNCH_LEVEL DISPATCH_LEVEL // synchronization level - UP system


    #define SYNCH_LEVEL (IPI_LEVEL-2) // synchronization level - MP system


I'm thinkin' that if you intended KeAcquireSpinLockRaiseToSynch(…) to raise to at least the highest DIRQL, the definition of SYNCH_LEVEL in Windows XP would mean that you're in big trouble.  Your driver would work correctly on Win2K and potentially hang on Windows XP.

So, in short, if you use this function in your driver remove it ASAP.  I wouldn't be at all surprised if Microsoft removed this prototype entirely from the Windows .NET DDK.

User Comments
Rate this article and give us feedback. Do you find anything missing? Share your opinion with the community!
Post Your Comment

Post Your Comments.
Print this article.
Email this article.
bottom nav links