Windows System Software -- Consulting, Training, Development -- Unique Expertise, Guaranteed Results

Home NTDEV
Before Posting...
Please check out the Community Guidelines in the Announcements and Administration Category.

More Info on Driver Writing and Debugging


The free OSR Learning Library has more than 50 articles on a wide variety of topics about writing and debugging device drivers and Minifilters. From introductory level to advanced. All the articles have been recently reviewed and updated, and are written using the clear and definitive style you've come to expect from OSR over the years.


Check out The OSR Learning Library at: https://www.osr.com/osr-learning-library/


REmnant KeInitializeSpin and Co. unresolved/already defined errors

OSR_Community_UserOSR_Community_User Member Posts: 110,217
This sounds like the old issue. Well, it still remains as very
possible issue with the latest W7 WDK.
If one file includes wdm.h and the other includes ntddk.h or ntifs.h
or FltKernel.h and the code uses KeInitializeSpinLock, there will be
linker errors on both x86.
The problem is with WDM_INCLUDED define. It's defined when WDM.h was
included without ntddk.h or other two before it. The function is forced
non-inline on x86 if ntddk/ntifs/FltKernel are used but is used as
export if wdm is used.
OK, not many will include different header files, but it's a bug
nonetheless. And it just made me rewrite a C++ library that only used
wdm.h because it gave out linker errors :)

FYI for everyone, and I hope MS changes this to the same state
regardless of which header in included (I don't see a reason why it
would not be inline everywhere, can there possibly be anything more the
Ntoskrnl version does for a spin lock apart from tracking?)

--
Kind regards, Dejan (MSN support: [email protected])
http://www.alfasp.com
File system audit, security and encryption kits.

Comments

  • Pavel_APavel_A Member Posts: 2,758
    "Dejan Maksimovic" <[email protected]> wrote in message news:[email protected]
    >
    > This sounds like the old issue. Well, it still remains as very
    > possible issue with the latest W7 WDK.
    > If one file includes wdm.h and the other includes ntddk.h or ntifs.h
    > or FltKernel.h and the code uses KeInitializeSpinLock, there will be
    > linker errors on both x86.
    > The problem is with WDM_INCLUDED define. It's defined when WDM.h was
    > included without ntddk.h or other two before it. The function is forced
    > non-inline on x86 if ntddk/ntifs/FltKernel are used but is used as
    > export if wdm is used.
    > OK, not many will include different header files, but it's a bug
    > nonetheless. And it just made me rewrite a C++ library that only used
    > wdm.h because it gave out linker errors :)

    AFAIK wdm.h should not be included directly for NT platform.
    Just use ntddk.h or fltkernel.h always, and forget wdm.h.

    However if you want to be compatible with win2k, there are some other
    compatibility #defines that can affect libraries.
    Maybe all libraries must be recompiled for specific kernel version to be
    safe.

    Regards,
    --pa

    > FYI for everyone, and I hope MS changes this to the same state
    > regardless of which header in included (I don't see a reason why it
    > would not be inline everywhere, can there possibly be anything more the
    > Ntoskrnl version does for a spin lock apart from tracking?)
    >
    > --
    > Kind regards, Dejan (MSN support: [email protected])
    > http://www.alfasp.com
    > File system audit, security and encryption kits.
    >
    >
    >
  • OSR_Community_UserOSR_Community_User Member Posts: 110,217
    > AFAIK wdm.h should not be included directly for NT platform. Just use ntddk.h or fltkernel.h always, and forget
    > wdm.h.

    Docs suggest wdm.h (as does the name for some). I don't remember why my library has wdm.h included though.

    --
    Kind regards, Dejan (MSN support: [email protected])
    http://www.alfasp.com
    File system audit, security and encryption kits.
  • Pavel_APavel_A Member Posts: 2,758
    "Dejan Maksimovic" <[email protected]> wrote in message news:[email protected]
    >> AFAIK wdm.h should not be included directly for NT platform. Just use
    >> ntddk.h or fltkernel.h always, and forget
    >> wdm.h.
    >
    > Docs suggest wdm.h (as does the name for some). I don't remember
    > why my library has wdm.h included though.

    Most of sample drivers in the wdk use ntddk.h. Some still use wdm.h however.

    --pa
  • James_HarperJames_Harper Member Posts: 1,615
    >
    > "Dejan Maksimovic" <[email protected]> wrote in message
    news:[email protected]
    > >> AFAIK wdm.h should not be included directly for NT platform. Just
    use
    > >> ntddk.h or fltkernel.h always, and forget
    > >> wdm.h.
    > >
    > > Docs suggest wdm.h (as does the name for some). I don't
    remember
    > > why my library has wdm.h included though.
    >
    > Most of sample drivers in the wdk use ntddk.h. Some still use wdm.h
    however.
    >
    > --pa
    >

    The docs I'm looking at
    (http://msdn.microsoft.com/en-us/library/ff552160.aspx) say for
    KeInitializeSpinLock "Header:
    Wdm.h (include Wdm.h, Ntddk.h, or Ntifs.h)", so it seems that including
    wdm.h directly is still correct.

    James
  • OSR_Community_UserOSR_Community_User Member Posts: 110,217
    Yep. One more bug for bug bash :)

    James Harper wrote:

    > The docs I'm looking at
    > (http://msdn.microsoft.com/en-us/library/ff552160.aspx) say for
    > KeInitializeSpinLock "Header:
    > Wdm.h (include Wdm.h, Ntddk.h, or Ntifs.h)", so it seems that including
    > wdm.h directly is still correct.

    --
    Kind regards, Dejan (MSN support: [email protected])
    http://www.alfasp.com
    File system audit, security and encryption kits.
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Upcoming OSR Seminars
OSR has suspended in-person seminars due to the Covid-19 outbreak. But, don't miss your training! Attend via the internet instead!
Writing WDF Drivers 7 Dec 2020 LIVE ONLINE
Internals & Software Drivers 25 Jan 2021 LIVE ONLINE
Developing Minifilters 8 March 2021 LIVE ONLINE