[WIN32K]
authorTimo Kreuzer <timo.kreuzer@reactos.org>
Sat, 19 Feb 2011 22:03:34 +0000 (22:03 +0000)
committerTimo Kreuzer <timo.kreuzer@reactos.org>
Sat, 19 Feb 2011 22:03:34 +0000 (22:03 +0000)
- add tracing of exclusive gdi locks
- add some asserts

svn path=/trunk/; revision=50825

reactos/subsystems/win32/win32k/include/gdiobj.h
reactos/subsystems/win32/win32k/ntuser/ntuser.c
reactos/subsystems/win32/win32k/objects/gdiobj.c

index e736391..9882e9d 100644 (file)
@@ -9,6 +9,9 @@
 #include <win32k/ntgdihdl.h>
 #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);
     }
index d28aa33..2e9d7eb 100644 (file)
@@ -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();
 }
index 7d2f741..dcf59df 100644 (file)
@@ -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