From: SourceForge.net <no...@so...> - 2004-10-14 20:20:56
|
Bugs item #1009559, was opened at 2004-08-15 17:02 Message generated for change (Comment added) made by rwruck You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=102435&aid=1009559&group_id=2435 Category: w32api Group: None Status: Open Resolution: None Priority: 5 Submitted By: Robert Wruck (rwruck) Assigned to: Nobody/Anonymous (nobody) Summary: DDK SList handling Initial Comment: I found some incorrect behaviour in ddk/winddk.h: Any driver for win2k that uses lists can't be loaded due to unresolved references in ntoskrnl.exe. It appears that ExAllocateFromPagedLookasideList and ExFreeToPagedLookaside list are implemented as inline functions though those are part of ntoskrnl.exe (at least for win2k and winxp). Those inline functions (ExAllocateFromNPagedLookasideList and ExFreeToNPagedLookasideList, too) use InterlockedPushEntrySList and InterlockedPopEntrySList, which are NOT part of ntoskrnl in win2k (but added in winxp). The functions that should be used are ExInterlocked (Push|Pop)EntrySList, but those in turn are not in libntoskrnl.a. Also, these require a kernel spin lock while Interlocked (Push|Pop)EntrySList doesn't. I suppose the kernel stores a spin lock inside the list structure, but i don't have the original DDK headers to verify this. BTW: earlier this year i submitted some patches to win32api that should have been committed to CVS but i can't find them there (e.g. patch #933676). Am i missing something? ---------------------------------------------------------------------- >Comment By: Robert Wruck (rwruck) Date: 2004-10-14 22:20 Message: Logged In: YES user_id=632713 Hi, seems to work just fine. there's only one thing left i'm missing: the object types exported by ntoskrnl.exe are declared in winddk.h but commented out in ntoskrnl.def. Simply removing the comments seems to be enough. -Robert ExDesktopObjectType DATA ExEventObjectType DATA ExSemaphoreObjectType DATA ExWindowStationObjectType DATA IoAdapterObjectType DATA IoDeviceHandlerObjectSize DATA IoDeviceHandlerObjectType DATA IoDeviceObjectType DATA IoDriverObjectType DATA IoFileObjectType DATA LpcPortObjectType DATA MmSectionObjectType DATA SeTokenObjectType DATA ---------------------------------------------------------------------- Comment By: Danny Smith (dannysmith) Date: 2004-10-13 00:53 Message: Logged In: YES user_id=11494 Here is another iteration, that atempts to avoid some of the problems that would occur in winbase.h is included before winddk.h. I'm assuming that ntddk.h is that toplevel header that would normally be included before anything else. = include/winbase.h (InitializeSListHead, Interlocked*): Guard with ! __USE_NTOSKRNL__. * include/ddk/ntddk.h (__USE_NTOSKRNL__): Define. * include/ddk/winddk.h (InitializeSListHead, Interlocked*): Guard with __USE_NTOSKRNL__. (ExInterlockedPopEntrySList, ExInterlockedPushEntrySList): Add prototypes. Guard macro definition with __USE_NTOSKRNL__ && _WIN32_WINNT >= 0x0501 (ExAllocateFromNPagedLookasideList, ExAllocateFromPagedLookasideList, ExFreeToNPagedLookasideList, ExFreeToPagedLookasideList): Replace calts to InterlockedPopEntrySList, InterlockedPushEntrySList with ExInterlockedPopEntrySList, ExInterlockedPushEntrySList. * lib/ddk/ntosknl.def (ExInterlockedPopEntrySList, ExInterlockedPushEntrySList) Add stubs. ---------------------------------------------------------------------- Comment By: Robert Wruck (rwruck) Date: 2004-10-11 21:18 Message: Logged In: YES user_id=632713 Hi, you were right with your first comment about ExInterlockedXYZ. I attached a modified patch that should now also use the exact line numbers. With the latest comment, note that kernel32.dll is the component which exports Interlocked(Push|Pop)EntrySList to user mode. These are NOT fastcall. But functions with the same name are exported by ntoskrnl.exe to kernel mode, and those ARE fastcall. I verified this by compiling my driver (the cause of all my patches...) on WinXP. The bad thing is that you have to be careful about which file to #include first of <windows.h> and <ddk/ntddk.h> with _WIN32_WINNT set to 0x501 since then the compiler might complain about exactly these functions being defined twice... ---------------------------------------------------------------------- Comment By: Danny Smith (dannysmith) Date: 2004-10-11 09:30 Message: Logged In: YES user_id=11494 Hi, I ve committed this bit: 2004-10-11 Robert Wruck <wr...@tw...> * include/ddk/winddk.h (IoReleaseRemoveLockAndWait): Fix definition (IoReleaseRemoveLock): Add definition. But need more info on the other hunks: This (currently in winddl.k) #if !defined(_WINBASE_H) || _WIN32_WINNT < 0x0501 NTOSAPI PSLIST_ENTRY DDKFASTAPI InterlockedPopEntrySList( IN PSLIST_HEADER ListHead); NTOSAPI PSLIST_ENTRY DDKFASTAPI InterlockedPushEntrySList( IN PSLIST_HEADER ListHead, IN PSLIST_ENTRY ListEntry); #endif looks bogus to me. MSDN says these are exported from kernel32.dll on XP and higher. I can't find any evidence that they are exported anywhere else as fastcall symbols. And if that is bogus, so are the inline definitions that use it. My preference would be to simplify this whole mess and just declare the library functions NTOSAPI PSINGLE_LIST_ENTRY DDKFASTAPI ExInterlockedPopEntrySList( IN PSLIST_HEADER ListHead, IN PKSPIN_LOCK Lock); NTOSAPI PSINGLE_LIST_ENTRY DDKFASTAPI ExInterlockedPushEntrySList( IN PSLIST_HEADER ListHead, IN PSINGLE_LIST_ENTRY ListEntry, IN PKSPIN_LOCK Lock); NTOSAPI PVOID DDKAPI ExAllocateFromNPagedLookasideList( IN PNPAGED_LOOKASIDE_LIST Lookaside); NTOSAPI PVOID DDKAPI ExAllocateFromPagedLookasideList( IN PPAGED_LOOKASIDE_LIST Lookaside); NTOSAPI VOID DDKAPI ExFreeToNPagedLookasideList( IN PNPAGED_LOOKASIDE_LIST Lookaside, IN PVOID Entry); NTOSAPI VOID DDKAPI ExFreeToPagedLookasideList( IN PPAGED_LOOKASIDE_LIST Lookaside, IN PVOID Entry); and #if 0 out all the inline versions of these until someone can come up with some evidence that they are correct. Danny ---------------------------------------------------------------------- Comment By: Danny Smith (dannysmith) Date: 2004-10-11 01:03 Message: Logged In: YES user_id=11494 Thanks One comment. Since ExInterlocked[Push|Pop]EntrySList are defined as macros FOR 0x501, expanding to the kernel32.dll functions, can't we remove these conditionals +#if (_WIN32_WINNT <= 0x0500) + Entry = ExInterlockedPopEntrySList(&Lookaside->ListHead, &Lookaside->Obsoleted); +#else + Entry = InterlockedPopEntrySList(&Lookaside->ListHead); +#endif and just use ExInterlocked[Push|Pop]EntrySList Danny ---------------------------------------------------------------------- Comment By: Robert Wruck (rwruck) Date: 2004-10-11 00:16 Message: Logged In: YES user_id=632713 Sorry, forgot the upload checkbox.. How about this: 2004-10-10 Robert Wruck <wr...@tw...> * include/ddk/winddk.h (ExInterlockedPushEntrySList, ExInterlockedPopEntrySList): Choose inline version vs. exported version only if _WIN32_WINNT > 0x500 * include/ddk/winddk.h (ExAllocateFromNPagedLookasideList, ExFreeToNPagedLookasideList): Choose usage of InterlockedPopEntrySList vs. ExInterlockedPopEntrySList if _WIN32_WINNT > 0x500 * include/ddk/winddk.h (ExAllocateFromPagedLookasideList, ExFreeToPagedLookasideList): Choose inline version vs. exported version only if _WIN32_WINNT > 0x500 * include/ddk/winddk.h (IoReleaseRemoveLockAndWait): Fix definition * include/ddk/winddk.h (IoReleaseRemoveLock): Add definition ---------------------------------------------------------------------- Comment By: Danny Smith (dannysmith) Date: 2004-10-10 22:20 Message: Logged In: YES user_id=11494 > My previous patches were apparently committed in the cygwin > CVS. What is the right place to report those bugs? Here. The primary CVS repository for w32api is the winsup one. In last few years, most of the patches and bug reports have gone through the mingw sourceforge "trackers", but they still get committed to winsup CVS. When submmitting patches, please provide a correctly formatted ChangeLog entry (see ChangeLog for examples) > Would you have a look at that? Where is the patch that you want me to look at? Danny ---------------------------------------------------------------------- Comment By: Robert Wruck (rwruck) Date: 2004-10-10 21:58 Message: Logged In: YES user_id=632713 Thanks for the reply. Meanwhile, I have made a patch myself, which fixes some more issues. My previous patches were apparently committed in the cygwin CVS. What is the right place to report those bugs? Anyway, winddk.h.patch fixes the following things: - Add #if that checks _WIN32_WINNT (in my patch, i originally used WINVER, but _WIN32_WINNT is probably better) and uses the ExInterlockedPushEntrySList and ExInterlockedPopEntrySList exported by ntoskrnl.exe instead of inline versions. - Altered ExAllocateFromNPagedLookasideList and ExFreeToNPagedLookasideList to use ExInterlockedX #if on w2k. - Since ExInterlockedX are now used in the inline functions, I moved the Ex..NPagedLookasideList definitions down so that ExInterlockedX is declared above them (otherwise the compiler won't call them as fastcall, and that results in a blue screen). - Corrected definitions of IoReleaseRemoveLockXXX: IoReleaseRemoveLockAndWait was #defined as IoReleaseRemoveLockEx (instead of IoReleaseRemoveLockAndWaitEx) and IoReleaseRemoveLockAndWait was not #defined at all. Would you have a look at that? Robert ---------------------------------------------------------------------- Comment By: Danny Smith (dannysmith) Date: 2004-10-10 11:55 Message: Logged In: YES user_id=11494 Could you please try the attached patch on win2k. It only defines the static inlines for _WIN32_WINNT >= 0x0501, esle uses the library functions in ntoskrnl.exe/ Danny ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=102435&aid=1009559&group_id=2435 |