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

Sept/Oct 2019 Issue of The NT Insider available


Download PDF here: http://insider.osr.com/2019/ntinsider_2019_01.pdf

It’s a particularly BIG issue, too: 40 pages of technical goodness, ranging from WDF to Minifilters. Check it out.
Before Posting...
Please check out the Community Guidelines in the Announcements and Administration Category.

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: xxxxx@alfasp.com)
http://www.alfasp.com
File system audit, security and encryption kits.

Comments

  • Pavel_APavel_A Member Posts: 2,689
    "Dejan Maksimovic" <xxxxx@alfasp.com> wrote in message news:xxxxx@ntdev...
    >
    > 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: xxxxx@alfasp.com)
    > 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: xxxxx@alfasp.com)
    http://www.alfasp.com
    File system audit, security and encryption kits.
  • Pavel_APavel_A Member Posts: 2,689
    "Dejan Maksimovic" <xxxxx@alfasp.com> wrote in message news:xxxxx@ntdev...
    >> 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" <xxxxx@alfasp.com> wrote in message
    news:xxxxx@ntdev...
    > >> 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: xxxxx@alfasp.com)
    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
Writing WDF Drivers 21 Oct 2019 OSR Seminar Space & ONLINE
Internals & Software Drivers 18 Nov 2019 Dulles, VA
Kernel Debugging 30 Mar 2020 OSR Seminar Space
Developing Minifilters 27 Apr 2020 OSR Seminar Space & ONLINE