[ros-diffs] [tkreuzer] 32109: - remove GDIOB_XxxDbg functions - enhance backtracing and debug output for GDI_DEBUG - implement GDIOBJ_ValidateHandle() Stack record dumping is commented out atm due to missing support from ntoskrnl

tkreuzer at svn.reactos.org tkreuzer at svn.reactos.org
Mon Feb 4 04:17:38 CET 2008


Author: tkreuzer
Date: Mon Feb  4 06:17:37 2008
New Revision: 32109

URL: http://svn.reactos.org/svn/reactos?rev=32109&view=rev
Log:
- remove GDIOB_XxxDbg functions
- enhance backtracing and debug output for GDI_DEBUG
- implement GDIOBJ_ValidateHandle()
Stack record dumping is commented out atm due to missing support from ntoskrnl

Modified:
    trunk/reactos/subsystems/win32/win32k/include/gdiobj.h
    trunk/reactos/subsystems/win32/win32k/objects/gdiobj.c

Modified: trunk/reactos/subsystems/win32/win32k/include/gdiobj.h
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/subsystems/win32/win32k/include/gdiobj.h?rev=32109&r1=32108&r2=32109&view=diff
==============================================================================
--- trunk/reactos/subsystems/win32/win32k/include/gdiobj.h (original)
+++ trunk/reactos/subsystems/win32/win32k/include/gdiobj.h Mon Feb  4 06:17:37 2008
@@ -72,27 +72,11 @@
 #define GDIOBJ_GetObjectType(Handle) \
   GDI_HANDLE_GET_TYPE(Handle)
 
-#ifdef GDI_DEBUG
-
-/* a couple macros for debugging GDIOBJ locking */
-#define GDIOBJ_AllocObj(ht,ty) GDIOBJ_AllocObjDbg(ht,__FILE__,__LINE__,ty)
-#define GDIOBJ_FreeObj(ht,obj,ty) GDIOBJ_FreeObjDbg(ht,__FILE__,__LINE__,obj,ty)
-#define GDIOBJ_LockObj(ht,obj,ty) GDIOBJ_LockObjDbg(ht,__FILE__,__LINE__,obj,ty)
-#define GDIOBJ_ShareLockObj(ht,obj,ty) GDIOBJ_ShareLockObjDbg(ht,__FILE__,__LINE__,obj,ty)
-
-HGDIOBJ INTERNAL_CALL GDIOBJ_AllocObjDbg(PGDI_HANDLE_TABLE HandleTable, const char* file, int line, ULONG ObjectType);
-BOOL    INTERNAL_CALL GDIOBJ_FreeObjDbg (PGDI_HANDLE_TABLE HandleTable, const char* file, int line, HGDIOBJ hObj, DWORD ObjectType);
-PGDIOBJ INTERNAL_CALL GDIOBJ_LockObjDbg (PGDI_HANDLE_TABLE HandleTable, const char* file, int line, HGDIOBJ hObj, DWORD ObjectType);
-PGDIOBJ INTERNAL_CALL GDIOBJ_ShareLockObjDbg (PGDI_HANDLE_TABLE HandleTable, const char* file, int line, HGDIOBJ hObj, DWORD ObjectType);
-
-#else /* !GDI_DEBUG */
-
+BOOL    INTERNAL_CALL GDIOBJ_ValidateHandle(HGDIOBJ hObj, ULONG ObjectType);
 HGDIOBJ INTERNAL_CALL GDIOBJ_AllocObj(PGDI_HANDLE_TABLE HandleTable, ULONG ObjectType);
 BOOL    INTERNAL_CALL GDIOBJ_FreeObj (PGDI_HANDLE_TABLE HandleTable, HGDIOBJ hObj, DWORD ObjectType);
 PGDIOBJ INTERNAL_CALL GDIOBJ_LockObj (PGDI_HANDLE_TABLE HandleTable, HGDIOBJ hObj, DWORD ObjectType);
 PGDIOBJ INTERNAL_CALL GDIOBJ_ShareLockObj (PGDI_HANDLE_TABLE HandleTable, HGDIOBJ hObj, DWORD ObjectType);
-
-#endif /* GDI_DEBUG */
 
 PVOID   INTERNAL_CALL GDI_MapHandleTable(PSECTION_OBJECT SectionObject, PEPROCESS Process);
 

Modified: trunk/reactos/subsystems/win32/win32k/objects/gdiobj.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/subsystems/win32/win32k/objects/gdiobj.c?rev=32109&r1=32108&r2=32109&view=diff
==============================================================================
--- trunk/reactos/subsystems/win32/win32k/objects/gdiobj.c (original)
+++ trunk/reactos/subsystems/win32/win32k/objects/gdiobj.c Mon Feb  4 06:17:37 2008
@@ -28,12 +28,11 @@
 #include <debug.h>
 
 /* FIXME include right header for KeRosDumpStackFrames */
-VOID
-NTAPI
-KeRosDumpStackFrames(
-    PULONG Frame,
-    ULONG FrameCount
-);
+VOID NTAPI KeRosDumpStackFrames(PULONG, ULONG);
+
+#ifdef GDI_DEBUG
+BOOLEAN STDCALL KiRosPrintAddress(PVOID Address);
+#endif
 
 #define GDI_ENTRY_TO_INDEX(ht, e)                                              \
   (((ULONG_PTR)(e) - (ULONG_PTR)&((ht)->Entries[0])) / sizeof(GDI_TABLE_ENTRY))
@@ -109,11 +108,6 @@
   DPRINT("%s:%i: Delay\n", __FILE__, __LINE__); \
   KeDelayExecutionThread(KernelMode, FALSE, &ShortDelay)
 
-#ifdef GDI_DEBUG
-BOOLEAN STDCALL KiRosPrintAddress(PVOID Address);
-VOID STDCALL KeRosDumpStackFrames(PULONG Frame, ULONG FrameCount);
-#endif
-
 /*!
  * Allocate GDI object table.
  * \param	Size - number of entries in the object table.
@@ -207,6 +201,7 @@
 static int leak_reported = 0;
 #define GDI_STACK_LEVELS 12
 static ULONG GDIHandleAllocator[GDI_HANDLE_COUNT][GDI_STACK_LEVELS];
+static ULONG GDIHandleLocker[GDI_HANDLE_COUNT][GDI_STACK_LEVELS];
 struct DbgOpenGDIHandle
 {
 	ULONG idx;
@@ -383,6 +378,23 @@
 }
 
 
+BOOL
+INTERNAL_CALL
+GDIOBJ_ValidateHandle(HGDIOBJ hObj, ULONG ObjectType)
+{
+  PGDI_TABLE_ENTRY Entry = GDI_HANDLE_GET_ENTRY(GdiHandleTable, hObj);
+  if((((ULONG_PTR)hObj & GDI_HANDLE_TYPE_MASK) == ObjectType) &&
+     (Entry->Type << GDI_ENTRY_UPPER_SHIFT) == GDI_HANDLE_GET_UPPER(hObj))
+  {
+    HANDLE pid = (HANDLE)((ULONG_PTR)Entry->ProcessId & ~0x1);
+    if(pid == NULL || pid == PsGetCurrentProcessId())
+    {
+      return TRUE;
+    }
+  }
+  return FALSE;
+}
+
 /*!
  * Allocate memory for GDI object and return handle to it.
  *
@@ -394,11 +406,7 @@
  * \todo return the object pointer and lock it by default.
 */
 HGDIOBJ INTERNAL_CALL
-#ifdef GDI_DEBUG
-GDIOBJ_AllocObjDbg(PGDI_HANDLE_TABLE HandleTable, const char* file, int line, ULONG ObjectType)
-#else /* !GDI_DEBUG */
 GDIOBJ_AllocObj(PGDI_HANDLE_TABLE HandleTable, ULONG ObjectType)
-#endif /* GDI_DEBUG */
 {
   PW32PROCESS W32Process;
   PGDIOBJHDR  newObject = NULL;
@@ -445,13 +453,6 @@
     newObject->LockingThread = NULL;
     newObject->Locks = 0;
 
-#ifdef GDI_DEBUG
-    newObject->createdfile = file;
-    newObject->createdline = line;
-    newObject->lockfile = NULL;
-    newObject->lockline = 0;
-#endif
-
     ObjectBody = GDIHdrToBdy(newObject);
 
     RtlZeroMemory(ObjectBody, GetObjectSize(TypeIndex));
@@ -487,8 +488,8 @@
         (void)InterlockedExchangePointer(&Entry->ProcessId, CurrentProcessId);
 
 #ifdef GDI_DEBUG
-        memset ( GDIHandleAllocator[Index], 0xcd, GDI_STACK_LEVELS * sizeof(ULONG) );
-        RtlCaptureStackBackTrace(2, GDI_STACK_LEVELS, (PVOID*)GDIHandleAllocator[Index], NULL);
+        memset ( GDIHandleAllocator[Index], 0x00, GDI_STACK_LEVELS * sizeof(ULONG) );
+        RtlCaptureStackBackTrace(1, GDI_STACK_LEVELS, (PVOID*)GDIHandleAllocator[Index], NULL);
 #endif /* GDI_DEBUG */
 
         if(W32Process != NULL)
@@ -548,11 +549,7 @@
  * to the calling process.
 */
 BOOL INTERNAL_CALL
-#ifdef GDI_DEBUG
-GDIOBJ_FreeObjDbg(PGDI_HANDLE_TABLE HandleTable, const char* file, int line, HGDIOBJ hObj, DWORD ExpectedType)
-#else /* !GDI_DEBUG */
 GDIOBJ_FreeObj(PGDI_HANDLE_TABLE HandleTable, HGDIOBJ hObj, DWORD ExpectedType)
-#endif /* GDI_DEBUG */
 {
   PGDI_TABLE_ENTRY Entry;
   PPAGED_LOOKASIDE_LIST LookasideList;
@@ -569,7 +566,8 @@
   {
     DPRINT1("GDIOBJ_FreeObj() failed, can't delete stock object handle: 0x%x !!!\n", hObj);
 #ifdef GDI_DEBUG
-    DPRINT1("-> called from %s:%i\n", file, line);
+    DPRINT1("-> called from:\n");
+    KeRosDumpStackFrames(NULL, 20);
 #endif
     return FALSE;
   }
@@ -655,7 +653,8 @@
          */
         DPRINT1("GdiHdr->Locks: %d\n", GdiHdr->Locks);
 #ifdef GDI_DEBUG
-        DPRINT1("Locked from: %s:%d\n", GdiHdr->lockfile, GdiHdr->lockline);
+//        DPRINT1("Locked from:\n");
+//        KeRosDumpStackFrames(GDIHandleLocker[GDI_HANDLE_GET_INDEX(hObj)], GDI_STACK_LEVELS);
 #endif
         ASSERT(FALSE);
       }
@@ -688,15 +687,16 @@
       {
         DPRINT1("Attempted to free global gdi handle 0x%x, caller needs to get ownership first!!!\n", hObj);
         DPRINT1("Type = 0x%lx, KernelData = 0x%p, ProcessId = 0x%p\n", Entry->Type, Entry->KernelData, Entry->ProcessId);
-        KeRosDumpStackFrames(NULL, 20);
       }
       else
       {
         DPRINT1("Attempted to free foreign handle: 0x%x Owner: 0x%x from Caller: 0x%x\n", hObj, (ULONG_PTR)PrevProcId & ~0x1, (ULONG_PTR)ProcessId & ~0x1);
+      }
+#ifdef GDI_DEBUG
+      DPRINT1("-> called from:\n");
       KeRosDumpStackFrames(NULL, 20);
-      }
-#ifdef GDI_DEBUG
-      DPRINT1("-> called from %s:%i\n", file, line);
+//      DPRINT1("Allocated from:\n");
+//      KeRosDumpStackFrames(GDIHandleAllocator[GDI_HANDLE_GET_INDEX(hObj)], GDI_STACK_LEVELS);
 #endif
     }
   }
@@ -818,11 +818,7 @@
  * \todo Get rid of the ExpectedType parameter!
 */
 PGDIOBJ INTERNAL_CALL
-#ifdef GDI_DEBUG
-GDIOBJ_LockObjDbg (PGDI_HANDLE_TABLE HandleTable, const char* file, int line, HGDIOBJ hObj, DWORD ExpectedType)
-#else /* !GDI_DEBUG */
 GDIOBJ_LockObj (PGDI_HANDLE_TABLE HandleTable, HGDIOBJ hObj, DWORD ExpectedType)
-#endif /* GDI_DEBUG */
 {
    ULONG HandleIndex;
    PGDI_TABLE_ENTRY Entry;
@@ -847,6 +843,11 @@
    {
       DPRINT1("Attempted to lock object 0x%x of wrong type (Handle: 0x%x, requested: 0x%x)\n",
               hObj, HandleType, ExpectedType);
+#ifdef GDI_DEBUG
+        KeRosDumpStackFrames(NULL, 20);
+//        DPRINT1("Allocated from:\n");
+//        KeRosDumpStackFrames(GDIHandleAllocator[GDI_HANDLE_GET_INDEX(hObj)], GDI_STACK_LEVELS);
+#endif
       return NULL;
    }
 
@@ -898,8 +899,8 @@
                GdiHdr->LockingThread = Thread;
                GdiHdr->Locks = 1;
 #ifdef GDI_DEBUG
-               GdiHdr->lockfile = file;
-               GdiHdr->lockline = line;
+               memset(GDIHandleLocker[GDI_HANDLE_GET_INDEX(hObj)], 0x00, GDI_STACK_LEVELS * sizeof(ULONG));
+               RtlCaptureStackBackTrace(1, GDI_STACK_LEVELS, (PVOID*)GDIHandleLocker[GDI_HANDLE_GET_INDEX(hObj)], NULL);
 #endif
                Object = Entry->KernelData;
             }
@@ -928,7 +929,8 @@
             LockErrorDebugOutput(hObj, Entry, "GDIOBJ_LockObj");
 
 #ifdef GDI_DEBUG
-            DPRINT1("-> called from %s:%i\n", file, line);
+            DPRINT1("-> called from:\n");
+            KeRosDumpStackFrames(NULL, 20);
 #endif
          }
 
@@ -966,11 +968,7 @@
  * \todo Get rid of the ExpectedType parameter!
 */
 PGDIOBJ INTERNAL_CALL
-#ifdef GDI_DEBUG
-GDIOBJ_ShareLockObjDbg (PGDI_HANDLE_TABLE HandleTable, const char* file, int line, HGDIOBJ hObj, DWORD ExpectedType)
-#else /* !GDI_DEBUG */
 GDIOBJ_ShareLockObj (PGDI_HANDLE_TABLE HandleTable, HGDIOBJ hObj, DWORD ExpectedType)
-#endif /* GDI_DEBUG */
 {
    ULONG HandleIndex;
    PGDI_TABLE_ENTRY Entry;
@@ -1043,8 +1041,8 @@
 #ifdef GDI_DEBUG
             if (InterlockedIncrement((PLONG)&GdiHdr->Locks) == 1)
             {
-               GdiHdr->lockfile = file;
-               GdiHdr->lockline = line;
+                 memset(GDIHandleLocker[HandleIndex], 0x00, GDI_STACK_LEVELS * sizeof(ULONG));
+                 RtlCaptureStackBackTrace(1, GDI_STACK_LEVELS, (PVOID*)GDIHandleLocker[HandleIndex], NULL);
             }
 #else
             InterlockedIncrement((PLONG)&GdiHdr->Locks);
@@ -1060,7 +1058,8 @@
             LockErrorDebugOutput(hObj, Entry, "GDIOBJ_ShareLockObj");
 
 #ifdef GDI_DEBUG
-            DPRINT1("-> called from %s:%i\n", file, line);
+            DPRINT1("-> called from:\n");
+            KeRosDumpStackFrames(NULL, 20);
 #endif
          }
 
@@ -1099,8 +1098,8 @@
 #ifdef GDI_DEBUG
    if (InterlockedDecrement((PLONG)&GdiHdr->Locks) == 0)
    {
-      GdiHdr->lockfile = NULL;
-      GdiHdr->lockline = 0;
+        memset(GDIHandleLocker[GDI_HANDLE_GET_INDEX(Object)], 0x00, GDI_STACK_LEVELS * sizeof(ULONG));
+        RtlCaptureStackBackTrace(1, GDI_STACK_LEVELS, (PVOID*)GDIHandleLocker[GDI_HANDLE_GET_INDEX(Object)], NULL);
    }
 #else
    if (InterlockedDecrement((PLONG)&GdiHdr->Locks) < 0)
@@ -1234,7 +1233,7 @@
           {
             if(GdiHdr->lockfile != NULL)
             {
-              DPRINT1("[%d]Locked %s:%i by 0x%x (we're 0x%x)\n", Attempts, GdiHdr->lockfile, GdiHdr->lockline, PrevThread, Thread);
+              DPRINT1("[%d]Locked by 0x%x (we're 0x%x)\n", Attempts, PrevThread, Thread);
             }
           }
 #endif
@@ -1356,10 +1355,7 @@
 #ifdef GDI_DEBUG
           if(++Attempts > 20)
           {
-            if(GdiHdr->lockfile != NULL)
-            {
-              DPRINT1("[%d]Locked from %s:%i by 0x%x (we're 0x%x)\n", Attempts, GdiHdr->lockfile, GdiHdr->lockline, PrevThread, Thread);
-            }
+            DPRINT1("[%d]Locked by 0x%x (we're 0x%x)\n", Attempts, PrevThread, Thread);
           }
 #endif
           /* WTF?! The object is already locked by a different thread!
@@ -1475,10 +1471,7 @@
 #ifdef GDI_DEBUG
           if(++Attempts > 20)
           {
-            if(GdiHdr->lockfile != NULL)
-            {
-              DPRINT1("[%d]Locked from %s:%i by 0x%x (we're 0x%x)\n", Attempts, GdiHdr->lockfile, GdiHdr->lockline, PrevThread, Thread);
-            }
+            DPRINT1("[%d]Locked by 0x%x (we're 0x%x)\n", Attempts, PrevThread, Thread);
           }
 #endif
           /* WTF?! The object is already locked by a different thread!




More information about the Ros-diffs mailing list