diff --git a/reactos/subsystems/win32/win32k/include/gdiobj.h b/reactos/subsystems/win32/win32k/include/gdiobj.h index e736391322e..9882e9dccc6 100644 --- a/reactos/subsystems/win32/win32k/include/gdiobj.h +++ b/reactos/subsystems/win32/win32k/include/gdiobj.h @@ -9,6 +9,9 @@ #include #include "win32.h" +/* apparently the first 10 entries are never used in windows as they are empty */ +#define RESERVE_ENTRIES_COUNT 10 + typedef struct _GDI_HANDLE_TABLE { /* The table must be located at the beginning of this structure so it can be @@ -105,6 +108,19 @@ ULONG FORCEINLINE GDIOBJ_UnlockObjByPtr(POBJ Object) { +#if DBG + PTHREADINFO pti = (PTHREADINFO)PsGetCurrentThreadWin32Thread(); + if (pti) + { + if (pti->cExclusiveLocks < 1) + { + DbgPrint("cExclusiveLocks = %ld, object: %ld\n", + pti->cExclusiveLocks, Object->cExclusiveLock); + ASSERT(FALSE); + } + pti->cExclusiveLocks--; + } +#endif INT cLocks = InterlockedDecrement((PLONG)&Object->cExclusiveLock); ASSERT(cLocks >= 0); return cLocks; @@ -120,6 +136,7 @@ GDIOBJ_ShareUnlockObjByPtr(POBJ Object) ASSERT(cLocks >= 0); if ((flags & BASEFLAG_READY_TO_DIE) && (cLocks == 0)) { + ASSERT(Object->cExclusiveLock == 0); GDIOBJ_SetOwnership(hobj, PsGetCurrentProcess()); GDIOBJ_FreeObjByHandle(hobj, GDI_OBJECT_TYPE_DONTCARE); } diff --git a/reactos/subsystems/win32/win32k/ntuser/ntuser.c b/reactos/subsystems/win32/win32k/ntuser/ntuser.c index d28aa33e2e6..2e9d7eb9b47 100644 --- a/reactos/subsystems/win32/win32k/ntuser/ntuser.c +++ b/reactos/subsystems/win32/win32k/ntuser/ntuser.c @@ -38,7 +38,7 @@ InitUserAtoms(VOID) gpsi->atomSysClass[ICLS_SWITCH] = 32771; gpsi->atomSysClass[ICLS_ICONTITLE] = 32772; gpsi->atomSysClass[ICLS_TOOLTIPS] = 32774; - + /* System Message Atom */ AtomMessage = IntAddGlobalAtom(L"Message", TRUE); gpsi->atomSysClass[ICLS_HWNDMESSAGE] = AtomMessage; @@ -112,7 +112,7 @@ UserInitialize( // { GetW32ThreadInfo(); - + // Callback to User32 Client Thread Setup co_IntClientThreadSetup(); @@ -208,12 +208,14 @@ VOID FASTCALL UserEnterShared(VOID) VOID FASTCALL UserEnterExclusive(VOID) { + ASSERT_NOGDILOCKS(); KeEnterCriticalRegion(); ExAcquireResourceExclusiveLite(&UserLock, TRUE); } VOID FASTCALL UserLeave(VOID) { + ASSERT_NOGDILOCKS(); ExReleaseResourceLite(&UserLock); KeLeaveCriticalRegion(); } diff --git a/reactos/subsystems/win32/win32k/objects/gdiobj.c b/reactos/subsystems/win32/win32k/objects/gdiobj.c index 7d2f7414809..dcf59df39db 100644 --- a/reactos/subsystems/win32/win32k/objects/gdiobj.c +++ b/reactos/subsystems/win32/win32k/objects/gdiobj.c @@ -17,9 +17,6 @@ #define GDI_HANDLE_GET_ENTRY(HandleTable, h) \ (&(HandleTable)->Entries[GDI_HANDLE_GET_INDEX((h))]) -/* apparently the first 10 entries are never used in windows as they are empty */ -#define RESERVE_ENTRIES_COUNT 10 - #define BASE_OBJTYPE_COUNT 32 #define DelayExecution() \ @@ -483,6 +480,9 @@ LockHandle: newObject->ulShareCount = 0; newObject->cExclusiveLock = 1; newObject->Tid = Thread; +#if DBG + if (Thread) Thread->cExclusiveLocks++; +#endif AllocTypeDataDump(TypeInfo); @@ -603,11 +603,11 @@ LockHandle: ((Entry->Type & GDI_ENTRY_BASETYPE_MASK) == (HandleUpper & GDI_ENTRY_BASETYPE_MASK)) ) { POBJ Object; + PTHREADINFO Thread = (PTHREADINFO)PsGetCurrentThreadWin32Thread(); Object = Entry->KernelData; - if ((Object->cExclusiveLock == 0 || - Object->Tid == (PTHREADINFO)PsGetCurrentThreadWin32Thread()) && + if ((Object->cExclusiveLock == 0 || Object->Tid == Thread) && Object->ulShareCount == 0) { BOOL Ret; @@ -623,6 +623,18 @@ LockHandle: InterlockedPushFreeEntry(GDI_ENTRY_TO_INDEX(GdiHandleTable, Entry)); Object->hHmgr = NULL; +#if DBG + if (Thread) + { + if (Thread->cExclusiveLocks < Object->cExclusiveLock) + { + DPRINT1("cExclusiveLocks = %ld, object: %ld\n", + Thread->cExclusiveLocks, Object->cExclusiveLock); + ASSERT(FALSE); + } + Thread->cExclusiveLocks -= Object->cExclusiveLock; + } +#endif if (W32Process != NULL) { @@ -1056,6 +1068,9 @@ GDIOBJ_LockObj(HGDIOBJ hObj, DWORD ExpectedType) Object->Tid = Thread; Object->cExclusiveLock = 1; GDIDBG_CAPTURELOCKER(GDI_HANDLE_GET_INDEX(hObj)) +#if DBG + if (Thread) Thread->cExclusiveLocks++; +#endif } else { @@ -1068,6 +1083,9 @@ GDIOBJ_LockObj(HGDIOBJ hObj, DWORD ExpectedType) continue; } InterlockedIncrement((PLONG)&Object->cExclusiveLock); +#if DBG + if (Thread) Thread->cExclusiveLocks++; +#endif } } else