- Add missing locks in monitors API
- Set proper last error when allocation fails

svn path=/trunk/; revision=54195
This commit is contained in:
Rafal Harabien 2011-10-18 23:01:29 +00:00
parent 9368b91f31
commit 4ba68ec5ab
2 changed files with 39 additions and 32 deletions

View file

@ -5,7 +5,6 @@ typedef struct _MONITOR
{ {
HEAD head; HEAD head;
// //
FAST_MUTEX Lock; /* R/W lock */
UNICODE_STRING DeviceName; /* name of the monitor */ UNICODE_STRING DeviceName; /* name of the monitor */
PDEVOBJ *GdiDevice; /* pointer to the GDI device to PDEVOBJ *GdiDevice; /* pointer to the GDI device to
which this monitor is attached */ which this monitor is attached */
@ -21,7 +20,7 @@ typedef struct _MONITOR
RECT rcMonitor; RECT rcMonitor;
RECT rcWork; RECT rcWork;
HRGN hrgnMonitor; HRGN hrgnMonitor;
SHORT Spare0; SHORT cFullScreen;
SHORT cWndStack; SHORT cWndStack;
HDEV hDev; HDEV hDev;
HDEV hDevReal; HDEV hDevReal;

View file

@ -46,8 +46,6 @@ IntCreateMonitorObject()
return NULL; return NULL;
} }
ExInitializeFastMutex(&Monitor->Lock);
return Monitor; return Monitor;
} }
@ -187,9 +185,7 @@ IntDetachMonitor(IN PDEVOBJ *pGdiDevice)
{ {
PMONITOR NewPrimaryMonitor = (Monitor->Prev != NULL) ? (Monitor->Prev) : (Monitor->Next); PMONITOR NewPrimaryMonitor = (Monitor->Prev != NULL) ? (Monitor->Prev) : (Monitor->Next);
ExEnterCriticalRegionAndAcquireFastMutexUnsafe(&NewPrimaryMonitor->Lock);
NewPrimaryMonitor->IsPrimary = TRUE; NewPrimaryMonitor->IsPrimary = TRUE;
ExReleaseFastMutexUnsafeAndLeaveCriticalRegion(&NewPrimaryMonitor->Lock);
} }
if (gMonitorList == Monitor) if (gMonitorList == Monitor)
@ -332,9 +328,7 @@ IntGetMonitorsFromRect(OPTIONAL IN LPCRECTL pRect,
{ {
RECTL MonitorRect, IntersectionRect; RECTL MonitorRect, IntersectionRect;
ExEnterCriticalRegionAndAcquireFastMutexUnsafe(&Monitor->Lock);
MonitorRect = Monitor->rcMonitor; MonitorRect = Monitor->rcMonitor;
ExReleaseFastMutexUnsafeAndLeaveCriticalRegion(&Monitor->Lock);
TRACE("MonitorRect: left = %d, top = %d, right = %d, bottom = %d\n", TRACE("MonitorRect: left = %d, top = %d, right = %d, bottom = %d\n",
MonitorRect.left, MonitorRect.top, MonitorRect.right, MonitorRect.bottom); MonitorRect.left, MonitorRect.top, MonitorRect.right, MonitorRect.bottom);
@ -524,13 +518,15 @@ NtUserEnumDisplayMonitors(
else else
myRect = ▭ myRect = ▭
UserEnterShared();
/* find intersecting monitors */ /* find intersecting monitors */
numMonitors = IntGetMonitorsFromRect(myRect, NULL, NULL, 0, 0); numMonitors = IntGetMonitorsFromRect(myRect, NULL, NULL, 0, 0);
if (numMonitors == 0 || listSize == 0 || if (numMonitors == 0 || listSize == 0 ||
(hMonitorList == NULL && monitorRectList == NULL)) (hMonitorList == NULL && monitorRectList == NULL))
{ {
TRACE("numMonitors = %d\n", numMonitors); TRACE("numMonitors = %d\n", numMonitors);
return numMonitors; goto cleanup;
} }
if (hMonitorList != NULL && listSize != 0) if (hMonitorList != NULL && listSize != 0)
@ -538,8 +534,9 @@ NtUserEnumDisplayMonitors(
safeHMonitorList = ExAllocatePoolWithTag(PagedPool, sizeof (HMONITOR) * listSize, USERTAG_MONITORRECTS); safeHMonitorList = ExAllocatePoolWithTag(PagedPool, sizeof (HMONITOR) * listSize, USERTAG_MONITORRECTS);
if (safeHMonitorList == NULL) if (safeHMonitorList == NULL)
{ {
/* FIXME: EngSetLastError? */ EngSetLastError(ERROR_NOT_ENOUGH_MEMORY);
return -1; numMonitors = -1;
goto cleanup;
} }
} }
if (monitorRectList != NULL && listSize != 0) if (monitorRectList != NULL && listSize != 0)
@ -548,8 +545,9 @@ NtUserEnumDisplayMonitors(
if (safeRectList == NULL) if (safeRectList == NULL)
{ {
ExFreePoolWithTag(safeHMonitorList, USERTAG_MONITORRECTS); ExFreePoolWithTag(safeHMonitorList, USERTAG_MONITORRECTS);
/* FIXME: EngSetLastError? */ EngSetLastError(ERROR_NOT_ENOUGH_MEMORY);
return -1; numMonitors = -1;
goto cleanup;
} }
} }
@ -570,12 +568,13 @@ NtUserEnumDisplayMonitors(
if (hMonitorList != NULL && listSize != 0) if (hMonitorList != NULL && listSize != 0)
{ {
status = MmCopyToCaller(hMonitorList, safeHMonitorList, sizeof (HMONITOR) * listSize); status = MmCopyToCaller(hMonitorList, safeHMonitorList, sizeof (HMONITOR) * listSize);
ExFreePool(safeHMonitorList); ExFreePoolWithTag(safeHMonitorList, USERTAG_MONITORRECTS);
if (!NT_SUCCESS(status)) if (!NT_SUCCESS(status))
{ {
ExFreePoolWithTag(safeRectList, USERTAG_MONITORRECTS); ExFreePoolWithTag(safeRectList, USERTAG_MONITORRECTS);
SetLastNtError(status); SetLastNtError(status);
return -1; numMonitors = -1;
goto cleanup;
} }
} }
if (monitorRectList != NULL && listSize != 0) if (monitorRectList != NULL && listSize != 0)
@ -585,10 +584,12 @@ NtUserEnumDisplayMonitors(
if (!NT_SUCCESS(status)) if (!NT_SUCCESS(status))
{ {
SetLastNtError(status); SetLastNtError(status);
return -1; numMonitors = -1;
} }
} }
cleanup:
UserLeave();
return numMonitors; return numMonitors;
} }
@ -725,13 +726,14 @@ NtUserMonitorFromPoint(
InRect.top = point.y; InRect.top = point.y;
InRect.bottom = point.y + 1; InRect.bottom = point.y + 1;
UserEnterShared();
/* find intersecting monitor */ /* find intersecting monitor */
NumMonitors = IntGetMonitorsFromRect(&InRect, &hMonitor, NULL, 1, dwFlags); NumMonitors = IntGetMonitorsFromRect(&InRect, &hMonitor, NULL, 1, dwFlags);
if (NumMonitors < 0) if (NumMonitors < 0)
{ hMonitor = NULL;
return (HMONITOR)NULL;
}
UserLeave();
return hMonitor; return hMonitor;
} }
@ -759,8 +761,8 @@ NtUserMonitorFromRect(
IN DWORD dwFlags) IN DWORD dwFlags)
{ {
ULONG numMonitors, iLargestArea = 0, i; ULONG numMonitors, iLargestArea = 0, i;
PRECTL rectList; PRECTL rectList = NULL;
HMONITOR *hMonitorList; HMONITOR *hMonitorList = NULL;
HMONITOR hMonitor = NULL; HMONITOR hMonitor = NULL;
RECTL rect; RECTL rect;
NTSTATUS status; NTSTATUS status;
@ -773,11 +775,13 @@ NtUserMonitorFromRect(
return (HMONITOR)NULL; return (HMONITOR)NULL;
} }
UserEnterShared();
/* find intersecting monitors */ /* find intersecting monitors */
numMonitors = IntGetMonitorsFromRect(&rect, &hMonitor, NULL, 1, dwFlags); numMonitors = IntGetMonitorsFromRect(&rect, &hMonitor, NULL, 1, dwFlags);
if (numMonitors <= 1) if (numMonitors <= 1)
{ {
return hMonitor; goto cleanup;
} }
hMonitorList = ExAllocatePoolWithTag(PagedPool, hMonitorList = ExAllocatePoolWithTag(PagedPool,
@ -785,8 +789,9 @@ NtUserMonitorFromRect(
USERTAG_MONITORRECTS); USERTAG_MONITORRECTS);
if (hMonitorList == NULL) if (hMonitorList == NULL)
{ {
/* FIXME: EngSetLastError? */ EngSetLastError(ERROR_NOT_ENOUGH_MEMORY);
return (HMONITOR)NULL; hMonitor = NULL;
goto cleanup;
} }
rectList = ExAllocatePoolWithTag(PagedPool, rectList = ExAllocatePoolWithTag(PagedPool,
@ -794,9 +799,9 @@ NtUserMonitorFromRect(
USERTAG_MONITORRECTS); USERTAG_MONITORRECTS);
if (rectList == NULL) if (rectList == NULL)
{ {
ExFreePoolWithTag(hMonitorList, USERTAG_MONITORRECTS); EngSetLastError(ERROR_NOT_ENOUGH_MEMORY);
/* FIXME: EngSetLastError? */ hMonitor = NULL;
return (HMONITOR)NULL; goto cleanup;
} }
/* get intersecting monitors */ /* get intersecting monitors */
@ -804,9 +809,8 @@ NtUserMonitorFromRect(
numMonitors, 0); numMonitors, 0);
if (numMonitors == 0) if (numMonitors == 0)
{ {
ExFreePoolWithTag(hMonitorList, USERTAG_MONITORRECTS); hMonitor = NULL;
ExFreePoolWithTag(rectList, USERTAG_MONITORRECTS); goto cleanup;
return (HMONITOR)NULL;
} }
/* find largest intersection */ /* find largest intersection */
@ -820,8 +824,12 @@ NtUserMonitorFromRect(
} }
} }
ExFreePoolWithTag(hMonitorList, USERTAG_MONITORRECTS); cleanup:
ExFreePoolWithTag(rectList, USERTAG_MONITORRECTS); if (hMonitorList)
ExFreePoolWithTag(hMonitorList, USERTAG_MONITORRECTS);
if (rectList)
ExFreePoolWithTag(rectList, USERTAG_MONITORRECTS);
UserLeave();
return hMonitor; return hMonitor;
} }