Author: rharabien
Date: Tue Oct 18 23:01:29 2011
New Revision: 54195

URL: http://svn.reactos.org/svn/reactos?rev=54195&view=rev
Log:
[WIN32K]
- Add missing locks in monitors API
- Set proper last error when allocation fails

Modified:
    trunk/reactos/subsystems/win32/win32k/include/monitor.h
    trunk/reactos/subsystems/win32/win32k/ntuser/monitor.c

Modified: trunk/reactos/subsystems/win32/win32k/include/monitor.h
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/subsystems/win32/win32k/include/monitor.h?rev=54195&r1=54194&r2=54195&view=diff
==============================================================================
--- trunk/reactos/subsystems/win32/win32k/include/monitor.h [iso-8859-1] 
(original)
+++ trunk/reactos/subsystems/win32/win32k/include/monitor.h [iso-8859-1] Tue 
Oct 18 23:01:29 2011
@@ -5,7 +5,6 @@
 {
     HEAD head;
 //
-    FAST_MUTEX     Lock;       /* R/W lock */
     UNICODE_STRING DeviceName; /* name of the monitor */
     PDEVOBJ     *GdiDevice;    /* pointer to the GDI device to
                                  which this monitor is attached */
@@ -21,7 +20,7 @@
     RECT    rcMonitor;
     RECT    rcWork;
     HRGN    hrgnMonitor;
-    SHORT   Spare0;
+    SHORT   cFullScreen;
     SHORT   cWndStack;
     HDEV    hDev;
     HDEV    hDevReal;

Modified: trunk/reactos/subsystems/win32/win32k/ntuser/monitor.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/subsystems/win32/win32k/ntuser/monitor.c?rev=54195&r1=54194&r2=54195&view=diff
==============================================================================
--- trunk/reactos/subsystems/win32/win32k/ntuser/monitor.c [iso-8859-1] 
(original)
+++ trunk/reactos/subsystems/win32/win32k/ntuser/monitor.c [iso-8859-1] Tue Oct 
18 23:01:29 2011
@@ -46,8 +46,6 @@
         return NULL;
     }
 
-    ExInitializeFastMutex(&Monitor->Lock);
-
     return Monitor;
 }
 
@@ -187,9 +185,7 @@
     {
         PMONITOR NewPrimaryMonitor = (Monitor->Prev != NULL) ? (Monitor->Prev) 
: (Monitor->Next);
 
-        
ExEnterCriticalRegionAndAcquireFastMutexUnsafe(&NewPrimaryMonitor->Lock);
         NewPrimaryMonitor->IsPrimary = TRUE;
-        
ExReleaseFastMutexUnsafeAndLeaveCriticalRegion(&NewPrimaryMonitor->Lock);
     }
 
     if (gMonitorList == Monitor)
@@ -332,9 +328,7 @@
     {
         RECTL MonitorRect, IntersectionRect;
 
-        ExEnterCriticalRegionAndAcquireFastMutexUnsafe(&Monitor->Lock);
         MonitorRect = Monitor->rcMonitor;
-        ExReleaseFastMutexUnsafeAndLeaveCriticalRegion(&Monitor->Lock);
 
         TRACE("MonitorRect: left = %d, top = %d, right = %d, bottom = %d\n",
                MonitorRect.left, MonitorRect.top, MonitorRect.right, 
MonitorRect.bottom);
@@ -524,13 +518,15 @@
     else
         myRect = ▭
 
+    UserEnterShared();
+
     /* find intersecting monitors */
     numMonitors = IntGetMonitorsFromRect(myRect, NULL, NULL, 0, 0);
     if (numMonitors == 0 || listSize == 0 ||
             (hMonitorList == NULL && monitorRectList == NULL))
     {
         TRACE("numMonitors = %d\n", numMonitors);
-        return numMonitors;
+        goto cleanup;
     }
 
     if (hMonitorList != NULL && listSize != 0)
@@ -538,8 +534,9 @@
         safeHMonitorList = ExAllocatePoolWithTag(PagedPool, sizeof (HMONITOR) 
* listSize, USERTAG_MONITORRECTS);
         if (safeHMonitorList == NULL)
         {
-            /* FIXME: EngSetLastError? */
-            return -1;
+            EngSetLastError(ERROR_NOT_ENOUGH_MEMORY);
+            numMonitors = -1;
+            goto cleanup;
         }
     }
     if (monitorRectList != NULL && listSize != 0)
@@ -548,8 +545,9 @@
         if (safeRectList == NULL)
         {
             ExFreePoolWithTag(safeHMonitorList, USERTAG_MONITORRECTS);
-            /* FIXME: EngSetLastError? */
-            return -1;
+            EngSetLastError(ERROR_NOT_ENOUGH_MEMORY);
+            numMonitors = -1;
+            goto cleanup;
         }
     }
 
@@ -570,12 +568,13 @@
     if (hMonitorList != NULL && listSize != 0)
     {
         status = MmCopyToCaller(hMonitorList, safeHMonitorList, sizeof 
(HMONITOR) * listSize);
-        ExFreePool(safeHMonitorList);
+        ExFreePoolWithTag(safeHMonitorList, USERTAG_MONITORRECTS);
         if (!NT_SUCCESS(status))
         {
             ExFreePoolWithTag(safeRectList, USERTAG_MONITORRECTS);
             SetLastNtError(status);
-            return -1;
+            numMonitors = -1;
+            goto cleanup;
         }
     }
     if (monitorRectList != NULL && listSize != 0)
@@ -585,10 +584,12 @@
         if (!NT_SUCCESS(status))
         {
             SetLastNtError(status);
-            return -1;
-        }
-    }
-
+            numMonitors = -1;
+        }
+    }
+
+cleanup:
+    UserLeave();
     return numMonitors;
 }
 
@@ -725,13 +726,14 @@
     InRect.top = point.y;
     InRect.bottom = point.y + 1;
 
+    UserEnterShared();
+
     /* find intersecting monitor */
     NumMonitors = IntGetMonitorsFromRect(&InRect, &hMonitor, NULL, 1, dwFlags);
     if (NumMonitors < 0)
-    {
-        return (HMONITOR)NULL;
-    }
-
+        hMonitor = NULL;
+
+    UserLeave();
     return hMonitor;
 }
 
@@ -759,8 +761,8 @@
     IN DWORD dwFlags)
 {
     ULONG numMonitors, iLargestArea = 0, i;
-    PRECTL rectList;
-    HMONITOR *hMonitorList;
+    PRECTL rectList = NULL;
+    HMONITOR *hMonitorList = NULL;
     HMONITOR hMonitor = NULL;
     RECTL rect;
     NTSTATUS status;
@@ -773,11 +775,13 @@
         return (HMONITOR)NULL;
     }
 
+    UserEnterShared();
+
     /* find intersecting monitors */
     numMonitors = IntGetMonitorsFromRect(&rect, &hMonitor, NULL, 1, dwFlags);
     if (numMonitors <= 1)
     {
-        return hMonitor;
+        goto cleanup;
     }
 
     hMonitorList = ExAllocatePoolWithTag(PagedPool,
@@ -785,8 +789,9 @@
                                          USERTAG_MONITORRECTS);
     if (hMonitorList == NULL)
     {
-        /* FIXME: EngSetLastError? */
-        return (HMONITOR)NULL;
+        EngSetLastError(ERROR_NOT_ENOUGH_MEMORY);
+        hMonitor = NULL;
+        goto cleanup;
     }
 
     rectList = ExAllocatePoolWithTag(PagedPool,
@@ -794,9 +799,9 @@
                                      USERTAG_MONITORRECTS);
     if (rectList == NULL)
     {
-        ExFreePoolWithTag(hMonitorList, USERTAG_MONITORRECTS);
-        /* FIXME: EngSetLastError? */
-        return (HMONITOR)NULL;
+        EngSetLastError(ERROR_NOT_ENOUGH_MEMORY);
+        hMonitor = NULL;
+        goto cleanup;
     }
 
     /* get intersecting monitors */
@@ -804,9 +809,8 @@
                                          numMonitors, 0);
     if (numMonitors == 0)
     {
-        ExFreePoolWithTag(hMonitorList, USERTAG_MONITORRECTS);
-        ExFreePoolWithTag(rectList, USERTAG_MONITORRECTS);
-        return (HMONITOR)NULL;
+        hMonitor = NULL;
+        goto cleanup;
     }
 
     /* find largest intersection */
@@ -820,8 +824,12 @@
         }
     }
 
-    ExFreePoolWithTag(hMonitorList, USERTAG_MONITORRECTS);
-    ExFreePoolWithTag(rectList, USERTAG_MONITORRECTS);
+cleanup:
+    if (hMonitorList)
+        ExFreePoolWithTag(hMonitorList, USERTAG_MONITORRECTS);
+    if (rectList)
+        ExFreePoolWithTag(rectList, USERTAG_MONITORRECTS);
+    UserLeave();
 
     return hMonitor;
 }


Reply via email to