[WIN32K]
authorJérôme Gardou <jerome.gardou@reactos.org>
Thu, 18 Sep 2014 12:09:19 +0000 (12:09 +0000)
committerJérôme Gardou <jerome.gardou@reactos.org>
Thu, 18 Sep 2014 12:09:19 +0000 (12:09 +0000)
 - Enable all debug channels if DEBUGCHANNEL is set to "+all".
 - Fix GDI objects exclusive locks counting, fixing a memory corruption altogether.
 - Add a missing lock release on error path.
 - Add a debug print.

svn path=/trunk/; revision=64187

reactos/win32ss/gdi/ntgdi/gdidbg.c
reactos/win32ss/gdi/ntgdi/gdiobj.c
reactos/win32ss/user/ntuser/kbdlayout.c
reactos/win32ss/user/ntuser/ntuser.c
reactos/win32ss/user/ntuser/winpos.c

index 92dace0..ef8f629 100644 (file)
@@ -595,6 +595,16 @@ DbgAddDebugChannel(PPROCESSINFO ppi, WCHAR* channel, WCHAR* level, WCHAR op)
     DBG_CHANNEL *ChannelEntry;
     UINT iLevel, iChannel;
 
+    /* Special treatment for the "all" channel */
+    if (wcscmp(channel, L"all") == 0)
+    {
+        for (iChannel = 0; iChannel < DbgChCount; iChannel++)
+        {
+            DbgAddDebugChannel(ppi, DbgChannels[iChannel].Name, level, op);
+        }
+        return TRUE;
+    }
+
     ChannelEntry = (DBG_CHANNEL*)bsearch(channel,
                                          DbgChannels,
                                          DbgChCount,
index 2273dfd..7cfbf47 100644 (file)
 #define NDEBUG
 #include <debug.h>
 
-// Move to gdidbg.h
+
+FORCEINLINE
+void
+INCREASE_THREAD_LOCK_COUNT(
+    _In_ HANDLE hobj)
+{
+    PTHREADINFO pti = PsGetCurrentThreadWin32Thread();
+    DBG_UNREFERENCED_PARAMETER(hobj);
+    if (pti)
+    {
+#if DBG
+        pti->acExclusiveLockCount[((ULONG_PTR)hobj >> 16) & 0x1f]++;
+#endif
+        pti->cExclusiveLocks++;
+    }
+}
+
+FORCEINLINE
+void
+DECREASE_THREAD_LOCK_COUNT(
+    _In_ HANDLE hobj)
+{
+    PTHREADINFO pti = PsGetCurrentThreadWin32Thread();
+    DBG_UNREFERENCED_PARAMETER(hobj);
+    if (pti)
+    {
+#if DBG
+        pti->acExclusiveLockCount[((ULONG_PTR)hobj >> 16) & 0x1f]--;
+#endif
+        pti->cExclusiveLocks--;
+    }
+}
+
 #if DBG
-#define DBG_INCREASE_LOCK_COUNT(pti, hobj) \
-    if (pti) ((PTHREADINFO)pti)->acExclusiveLockCount[((ULONG_PTR)hobj >> 16) & 0x1f]++;
-#define DBG_DECREASE_LOCK_COUNT(pti, hobj) \
-    if (pti) ((PTHREADINFO)pti)->acExclusiveLockCount[((ULONG_PTR)hobj >> 16) & 0x1f]--;
 #define ASSERT_SHARED_OBJECT_TYPE(objt) \
     ASSERT((objt) == GDIObjType_SURF_TYPE || \
            (objt) == GDIObjType_PAL_TYPE || \
@@ -55,8 +83,6 @@
 #define ASSERT_TRYLOCK_OBJECT_TYPE(objt) \
     ASSERT((objt) == GDIObjType_DRVOBJ_TYPE)
 #else
-#define DBG_INCREASE_LOCK_COUNT(ppi, hobj)
-#define DBG_DECREASE_LOCK_COUNT(x, y)
 #define ASSERT_SHARED_OBJECT_TYPE(objt)
 #define ASSERT_EXCLUSIVE_OBJECT_TYPE(objt)
 #define ASSERT_TRYLOCK_OBJECT_TYPE(objt)
@@ -684,7 +710,7 @@ GDIOBJ_TryLockObject(
 
     /* Increase lock count */
     pobj->cExclusiveLock++;
-    DBG_INCREASE_LOCK_COUNT(PsGetCurrentProcessWin32Process(), hobj);
+    INCREASE_THREAD_LOCK_COUNT(hobj);
     DBG_LOGEVENT(&pobj->slhLog, EVENT_LOCK, 0);
 
     /* Return the object */
@@ -735,7 +761,7 @@ GDIOBJ_LockObject(
 
     /* Increase lock count */
     pobj->cExclusiveLock++;
-    DBG_INCREASE_LOCK_COUNT(PsGetCurrentProcessWin32Process(), hobj);
+    INCREASE_THREAD_LOCK_COUNT(hobj);
     DBG_LOGEVENT(&pobj->slhLog, EVENT_LOCK, 0);
 
     /* Return the object */
@@ -751,7 +777,7 @@ GDIOBJ_vUnlockObject(POBJ pobj)
 
     /* Decrease lock count */
     pobj->cExclusiveLock--;
-    DBG_DECREASE_LOCK_COUNT(PsGetCurrentProcessWin32Process(), pobj->hHmgr);
+    DECREASE_THREAD_LOCK_COUNT(pobj->hHmgr);
     DBG_LOGEVENT(&pobj->slhLog, EVENT_UNLOCK, 0);
 
     /* Check if this was the last lock */
@@ -802,7 +828,7 @@ GDIOBJ_hInsertObject(
     ExAcquirePushLockExclusive(&pobj->pushlock);
     pobj->cExclusiveLock = 1;
     pobj->dwThreadId = PtrToUlong(PsGetCurrentThreadId());
-    DBG_INCREASE_LOCK_COUNT(PsGetCurrentProcessWin32Process(), pobj->hHmgr);
+    INCREASE_THREAD_LOCK_COUNT(pobj->hHmgr);
 
     /* Get object type from the hHmgr field */
     objt = ((ULONG_PTR)pobj->hHmgr >> 16) & 0xff;
@@ -1000,7 +1026,7 @@ GDIOBJ_vDeleteObject(POBJ pobj)
             /* Release the pushlock and reenable APCs */
             ExReleasePushLockExclusive(&pobj->pushlock);
             KeLeaveCriticalRegion();
-            DBG_DECREASE_LOCK_COUNT(PsGetCurrentProcessWin32Process(), pobj->hHmgr);
+            DECREASE_THREAD_LOCK_COUNT(pobj->hHmgr);
         }
     }
 
index be7e16f..5d3c633 100644 (file)
@@ -475,7 +475,10 @@ NtUserGetKeyboardLayoutList(
     UserEnterShared();
 
     if (!gspklBaseLayout)
+    {
+        UserLeave();
         return 0;
+    }
     pKl = gspklBaseLayout;
 
     if (nBuff == 0)
index 7b3a4bc..12f389c 100644 (file)
@@ -244,6 +244,7 @@ VOID FASTCALL UserEnterExclusive(VOID)
 VOID FASTCALL UserLeave(VOID)
 {
    ASSERT_NOGDILOCKS();
+   ASSERT(UserIsEntered());
    ExReleaseResourceLite(&UserLock);
    KeLeaveCriticalRegion();
 }
index a55aa35..b434317 100644 (file)
@@ -1258,6 +1258,7 @@ co_WinPosDoWinPosChanging(PWND Window,
 
    if (!(WinPos->flags & SWP_NOSENDCHANGING))
    {
+      TRACE("Sending WM_WINDOWPOSCHANGING to hwnd %p.\n", Window->head.h);
       co_IntSendMessageNoWait(Window->head.h, WM_WINDOWPOSCHANGING, 0, (LPARAM) WinPos);
    }