From b13d9595019d9677783762eea3fb2af373c338fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A9=20van=20Geldorp?= Date: Fri, 26 Sep 2003 10:45:45 +0000 Subject: [PATCH] Handle some out of resource situations svn path=/trunk/; revision=6145 --- reactos/subsys/win32k/eng/mem.c | 4 +-- reactos/subsys/win32k/eng/xlate.c | 50 ++++++++++++++++++-------- reactos/subsys/win32k/objects/dc.c | 11 ++++-- reactos/subsys/win32k/objects/dib.c | 21 ++++++++++- reactos/subsys/win32k/objects/gdiobj.c | 18 +++++----- 5 files changed, 75 insertions(+), 29 deletions(-) diff --git a/reactos/subsys/win32k/eng/mem.c b/reactos/subsys/win32k/eng/mem.c index 8c9f7b1c606..3fff378f21b 100644 --- a/reactos/subsys/win32k/eng/mem.c +++ b/reactos/subsys/win32k/eng/mem.c @@ -16,7 +16,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -/* $Id: mem.c,v 1.11 2003/07/11 15:59:37 royce Exp $ +/* $Id: mem.c,v 1.12 2003/09/26 10:45:44 gvg Exp $ * * COPYRIGHT: See COPYING in the top level directory * PROJECT: ReactOS kernel @@ -53,7 +53,7 @@ EngAllocMem(ULONG Flags, newMem = ExAllocatePoolWithTag(NonPagedPool, MemSize, Tag); // FIXME: Use PagedPool when it is implemented - if(Flags == FL_ZERO_MEMORY) + if (Flags == FL_ZERO_MEMORY && NULL != newMem) { RtlZeroMemory(newMem, MemSize); } diff --git a/reactos/subsys/win32k/eng/xlate.c b/reactos/subsys/win32k/eng/xlate.c index b565a1574c8..c386630f705 100644 --- a/reactos/subsys/win32k/eng/xlate.c +++ b/reactos/subsys/win32k/eng/xlate.c @@ -16,7 +16,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -/* $Id: xlate.c,v 1.24 2003/08/31 07:56:24 gvg Exp $ +/* $Id: xlate.c,v 1.25 2003/09/26 10:45:44 gvg Exp $ * * COPYRIGHT: See COPYING in the top level directory * PROJECT: ReactOS kernel @@ -202,6 +202,28 @@ static INT FASTCALL CalculateShift(ULONG Mask) return Shift; } +VOID FASTCALL EngDeleteXlate(XLATEOBJ *XlateObj) +{ + XLATEGDI *XlateGDI; + HANDLE HXlate; + + if (NULL == XlateObj) + { + DPRINT1("Trying to delete NULL XLATEOBJ\n"); + return; + } + + XlateGDI = (XLATEGDI *) AccessInternalObjectFromUserObject(XlateObj); + HXlate = (HANDLE) AccessHandleFromUserObject(XlateObj); + + if(NULL != XlateGDI->translationTable) + { + EngFreeMem(XlateGDI->translationTable); + } + + FreeGDIHandle((ULONG)HXlate); +} + XLATEOBJ * STDCALL IntEngCreateXlate(USHORT DestPalType, USHORT SourcePalType, HPALETTE PaletteDest, HPALETTE PaletteSource) { @@ -319,6 +341,19 @@ XLATEOBJ * STDCALL IntEngCreateXlate(USHORT DestPalType, USHORT SourcePalType, else if (DestPalType == PAL_INDEXED) { IndexedColors = DestPalGDI->NumColors; } XlateGDI->translationTable = EngAllocMem(FL_ZERO_MEMORY, sizeof(ULONG)*IndexedColors, 0); + if (NULL == XlateGDI->translationTable) + { + if (NULL != PaletteSource) + { + PALETTE_UnlockPalette(PaletteSource); + } + if (NULL != PaletteDest && PaletteDest != PaletteSource) + { + PALETTE_UnlockPalette(PaletteDest); + } + EngDeleteXlate(XlateObj); + return NULL; + } } // Source palette is indexed @@ -375,19 +410,6 @@ XLATEOBJ * STDCALL IntEngCreateXlate(USHORT DestPalType, USHORT SourcePalType, return XlateObj; } -VOID FASTCALL EngDeleteXlate(XLATEOBJ *XlateObj) -{ - HANDLE HXlate = (HANDLE)AccessHandleFromUserObject(XlateObj); - XLATEGDI *XlateGDI = (XLATEGDI*)AccessInternalObject((ULONG)HXlate); - - if(XlateGDI->translationTable!=NULL) - { - EngFreeMem(XlateGDI->translationTable); - } - - FreeGDIHandle((ULONG)HXlate); -} - /* * @implemented */ diff --git a/reactos/subsys/win32k/objects/dc.c b/reactos/subsys/win32k/objects/dc.c index 88e4f7947fe..68919ea4256 100644 --- a/reactos/subsys/win32k/objects/dc.c +++ b/reactos/subsys/win32k/objects/dc.c @@ -16,7 +16,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -/* $Id: dc.c,v 1.81 2003/09/21 06:44:51 gvg Exp $ +/* $Id: dc.c,v 1.82 2003/09/26 10:45:45 gvg Exp $ * * DC.C - Device context functions * @@ -42,6 +42,7 @@ #include #include "../eng/clip.h" #include "../eng/handle.h" +#include #include #include #include @@ -1486,13 +1487,17 @@ NtGdiSelectObject(HDC hDC, HGDIOBJ hGDIObj) case GDI_OBJECT_TYPE_BITMAP: // must be memory dc to select bitmap if (!(dc->w.flags & DC_MEMORY)) return NULL; + pb = BITMAPOBJ_LockBitmap(hGDIObj); + if (NULL == pb) + { + SetLastWin32Error(ERROR_INVALID_HANDLE); + return NULL; + } objOrg = (HGDIOBJ)dc->w.hBitmap; /* Release the old bitmap, lock the new one and convert it to a SURF */ EngDeleteSurface(dc->Surface); dc->w.hBitmap = hGDIObj; - pb = BITMAPOBJ_LockBitmap(hGDIObj); - ASSERT(pb); dc->Surface = BitmapToSurf(pb); // if we're working with a DIB, get the palette [fixme: only create if the selected palette is null] diff --git a/reactos/subsys/win32k/objects/dib.c b/reactos/subsys/win32k/objects/dib.c index d153fbbf661..9191989ce18 100644 --- a/reactos/subsys/win32k/objects/dib.c +++ b/reactos/subsys/win32k/objects/dib.c @@ -1,5 +1,5 @@ /* - * $Id: dib.c,v 1.33 2003/09/25 14:40:42 fireball Exp $ + * $Id: dib.c,v 1.34 2003/09/26 10:45:45 gvg Exp $ * * ReactOS W32 Subsystem * Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003 ReactOS Team @@ -164,9 +164,28 @@ NtGdiSetDIBits( // Source palette obtained from the BITMAPINFO DIB_Palette = BuildDIBPalette ( (PBITMAPINFO)bmi, (PINT)&DIB_Palette_Type ); + if (NULL == DIB_Palette) + { + EngDeleteSurface(SourceBitmap); + EngDeleteSurface(DestBitmap); + BITMAPOBJ_UnlockBitmap(hBitmap); + DC_UnlockDc(hDC); + SetLastWin32Error(ERROR_NO_SYSTEM_RESOURCES); + return 0; + } // Determine XLATEOBJ for color translation XlateObj = IntEngCreateXlate(DDB_Palette_Type, DIB_Palette_Type, DDB_Palette, DIB_Palette); + if (NULL == XlateObj) + { + PALETTE_FreePalette(DIB_Palette); + EngDeleteSurface(SourceBitmap); + EngDeleteSurface(DestBitmap); + BITMAPOBJ_UnlockBitmap(hBitmap); + DC_UnlockDc(hDC); + SetLastWin32Error(ERROR_NO_SYSTEM_RESOURCES); + return 0; + } // Zero point ZeroPoint.x = 0; diff --git a/reactos/subsys/win32k/objects/gdiobj.c b/reactos/subsys/win32k/objects/gdiobj.c index fb61119f9b0..d14cd5230fc 100644 --- a/reactos/subsys/win32k/objects/gdiobj.c +++ b/reactos/subsys/win32k/objects/gdiobj.c @@ -19,7 +19,7 @@ /* * GDIOBJ.C - GDI object manipulation routines * - * $Id: gdiobj.c,v 1.43 2003/09/24 16:01:32 weiden Exp $ + * $Id: gdiobj.c,v 1.44 2003/09/26 10:45:45 gvg Exp $ * */ @@ -41,9 +41,15 @@ #define NDEBUG #include +/*! Size of the GDI handle table + * http://www.windevnet.com/documents/s=7290/wdj9902b/9902b.htm + * gdi handle table can hold 0x4000 handles +*/ +#define GDI_HANDLE_COUNT 0x4000 + #define GDI_GLOBAL_PROCESS ((HANDLE) 0xffffffff) -#define GDI_HANDLE_INDEX_MASK 0x00003fff +#define GDI_HANDLE_INDEX_MASK (GDI_HANDLE_COUNT - 1) #define GDI_HANDLE_TYPE_MASK 0x007f0000 #define GDI_HANDLE_STOCK_MASK 0x00800000 @@ -140,12 +146,6 @@ static PGDI_HANDLE_TABLE HandleTable = 0; static FAST_MUTEX HandleTableMutex; static FAST_MUTEX RefCountHandling; -/*! Size of the GDI handle table - * http://www.windevnet.com/documents/s=7290/wdj9902b/9902b.htm - * gdi handle table can hold 0x4000 handles -*/ -#define GDI_HANDLE_NUMBER 0x4000 - /*! * Allocate GDI object table. * \param Size - number of entries in the object table. @@ -471,7 +471,7 @@ InitGdiObjectHandleTable (VOID) ExInitializeFastMutex (&HandleTableMutex); ExInitializeFastMutex (&RefCountHandling); - HandleTable = GDIOBJ_iAllocHandleTable (GDI_HANDLE_NUMBER); + HandleTable = GDIOBJ_iAllocHandleTable (GDI_HANDLE_COUNT); DPRINT("HandleTable: %x\n", HandleTable ); InitEngHandleTable();