diff --git a/reactos/apps/tests/gditest/gditest.c b/reactos/apps/tests/gditest/gditest.c index 1d9d9fa9670..4a8cd1b1614 100644 --- a/reactos/apps/tests/gditest/gditest.c +++ b/reactos/apps/tests/gditest/gditest.c @@ -18,12 +18,12 @@ void __stdcall Background (HDC Desktop) MoveToEx (Desktop, 0, 0, NULL); LineTo (Desktop, 640, 480); - for (y = 479, x = 0; x < 640; x+=2) + for (y = 479, x = 0; x < 640; x+=42) { MoveToEx (Desktop, 0, 0, NULL); LineTo (Desktop, x, y); } - for (y = 0, x = 639; y < 480; y+=2) + for (y = 0, x = 639; y < 480; y+=42) { MoveToEx (Desktop, 0, 0, NULL); LineTo (Desktop, x, y); diff --git a/reactos/iface/addsys/w32ksvc.db b/reactos/iface/addsys/w32ksvc.db index c7b9d0298e8..b1190ea2ecf 100644 --- a/reactos/iface/addsys/w32ksvc.db +++ b/reactos/iface/addsys/w32ksvc.db @@ -58,6 +58,7 @@ W32kDeleteDC 1 W32kDeleteEnhMetaFile 1 W32kDeleteMetaFile 1 W32kDeleteObject 1 +W32kCleanupForProcess 1 W32kDescribePixelFormat 4 #W32kDeviceCapabilitiesEx ? W32kDrawEscape 4 diff --git a/reactos/include/win32k/bitmaps.h b/reactos/include/win32k/bitmaps.h index 7121140a2eb..e504a025a92 100644 --- a/reactos/include/win32k/bitmaps.h +++ b/reactos/include/win32k/bitmaps.h @@ -30,7 +30,7 @@ typedef struct _BITMAPOBJ #define BITMAPOBJ_AllocBitmap() \ ((HBITMAP) GDIOBJ_AllocObj (sizeof (BITMAPOBJ), GO_BITMAP_MAGIC)) #define BITMAPOBJ_FreeBitmap(hBMObj) \ - GDIOBJ_FreeObj((HGDIOBJ) hBMObj, GO_BITMAP_MAGIC) + GDIOBJ_FreeObj((HGDIOBJ) hBMObj, GO_BITMAP_MAGIC, GDIOBJFLAG_DEFAULT) #define BITMAPOBJ_HandleToPtr(hBMObj) \ ((PBITMAPOBJ) GDIOBJ_LockObj ((HGDIOBJ) hBMObj, GO_BITMAP_MAGIC)) #define BITMAPOBJ_ReleasePtr(hBMObj) \ diff --git a/reactos/include/win32k/brush.h b/reactos/include/win32k/brush.h index fb34f0ab95b..ea52c9361a5 100644 --- a/reactos/include/win32k/brush.h +++ b/reactos/include/win32k/brush.h @@ -9,7 +9,7 @@ #define BRUSHOBJ_AllocBrush() \ ((HBRUSH) GDIOBJ_AllocObj (sizeof (BRUSHOBJ), GO_BRUSH_MAGIC)) -#define BRUSHOBJ_FreeBrush(hBrush) GDIOBJ_FreeObj((HGDIOBJ)hBrush, GO_BRUSH_MAGIC) +#define BRUSHOBJ_FreeBrush(hBrush) GDIOBJ_FreeObj((HGDIOBJ)hBrush, GO_BRUSH_MAGIC, GDIOBJFLAG_DEFAULT) /*#define BRUSHOBJ_HandleToPtr(hBrush) \ ((PBRUSHOBJ) GDIOBJ_HandleToPtr ((HGDIOBJ) hBrush, GO_BRUSH_MAGIC)) #define BRUSHOBJ_PtrToHandle(pBrushObj) \ diff --git a/reactos/include/win32k/gdiobj.h b/reactos/include/win32k/gdiobj.h index 419d0454a9b..1b5fbbdd51b 100644 --- a/reactos/include/win32k/gdiobj.h +++ b/reactos/include/win32k/gdiobj.h @@ -76,11 +76,16 @@ typedef struct _GDI_HANDLE_TABLE } GDI_HANDLE_TABLE, *PGDI_HANDLE_TABLE; HGDIOBJ GDIOBJ_AllocObj(WORD Size, WORD Magic); -BOOL GDIOBJ_FreeObj (HGDIOBJ Obj, WORD Magic); +BOOL GDIOBJ_FreeObj (HGDIOBJ Obj, WORD Magic, DWORD Flag); PGDIOBJ GDIOBJ_LockObj (HGDIOBJ Obj, WORD Magic); BOOL GDIOBJ_UnlockObj (HGDIOBJ Obj, WORD Magic); WORD GDIOBJ_GetHandleMagic (HGDIOBJ ObjectHandle); VOID STDCALL W32kDumpGdiObjects( INT Process ); +BOOL STDCALL W32kCleanupForProcess( INT Process ); + +#define GDIOBJFLAG_DEFAULT (0x0) +#define GDIOBJFLAG_IGNOREPID (0x1) +#define GDIOBJFLAG_IGNORELOCK (0x2) #endif diff --git a/reactos/include/win32k/pen.h b/reactos/include/win32k/pen.h index 468427212c9..0c317e67af3 100644 --- a/reactos/include/win32k/pen.h +++ b/reactos/include/win32k/pen.h @@ -14,7 +14,7 @@ typedef struct #define PENOBJ_AllocPen() \ ((HPEN) GDIOBJ_AllocObj (sizeof (PENOBJ), GO_PEN_MAGIC)) -#define PENOBJ_FreePen(hBMObj) GDIOBJ_FreeObj((HGDIOBJ) hBMObj) +#define PENOBJ_FreePen(hBMObj) GDIOBJ_FreeObj((HGDIOBJ) hBMObj, GO_PEN_MAGIC, GDIOBJFLAG_DEFAULT) /* #define PENOBJ_HandleToPtr(hBMObj) \ ((PPENOBJ) GDIOBJ_HandleToPtr ((HGDIOBJ) hBMObj, GO_PEN_MAGIC)) diff --git a/reactos/include/win32k/region.h b/reactos/include/win32k/region.h index 6ee4ea49bf8..6650718333a 100644 --- a/reactos/include/win32k/region.h +++ b/reactos/include/win32k/region.h @@ -11,7 +11,7 @@ typedef struct _ROSRGNDATA { } ROSRGNDATA, *PROSRGNDATA, *LPROSRGNDATA; -#define RGNDATA_FreeRgn(hRgn) GDIOBJ_FreeObj((HGDIOBJ)hRgn, GO_REGION_MAGIC) +#define RGNDATA_FreeRgn(hRgn) GDIOBJ_FreeObj((HGDIOBJ)hRgn, GO_REGION_MAGIC, GDIOBJFLAG_DEFAULT) #define RGNDATA_LockRgn(hRgn) ((PROSRGNDATA)GDIOBJ_LockObj((HGDIOBJ)hRgn, GO_REGION_MAGIC)) #define RGNDATA_UnlockRgn(hRgn) GDIOBJ_UnlockObj((HGDIOBJ)hRgn, GO_REGION_MAGIC) HRGN RGNDATA_AllocRgn(INT n); diff --git a/reactos/include/win32k/text.h b/reactos/include/win32k/text.h index 31ff77b41a3..fc1be707317 100644 --- a/reactos/include/win32k/text.h +++ b/reactos/include/win32k/text.h @@ -12,7 +12,7 @@ typedef struct #define TEXTOBJ_AllocText() \ ((HFONT) GDIOBJ_AllocObj (sizeof (TEXTOBJ), GO_FONT_MAGIC)) -#define TEXTOBJ_FreeText(hBMObj) GDIOBJ_FreeObj((HGDIOBJ) hBMObj, GO_FONT_MAGIC) +#define TEXTOBJ_FreeText(hBMObj) GDIOBJ_FreeObj((HGDIOBJ) hBMObj, GO_FONT_MAGIC, GDIOBJFLAG_DEFAULT) /* #define TEXTOBJ_HandleToPtr(hBMObj) \ ((PTEXTOBJ) GDIOBJ_HandleToPtr ((HGDIOBJ) hBMObj, GO_FONT_MAGIC)) diff --git a/reactos/subsys/csrss/api/process.c b/reactos/subsys/csrss/api/process.c index 926abdcfb65..f6360bd5aed 100644 --- a/reactos/subsys/csrss/api/process.c +++ b/reactos/subsys/csrss/api/process.c @@ -1,4 +1,4 @@ -/* $Id: process.c,v 1.19 2002/09/08 10:23:45 chorns Exp $ +/* $Id: process.c,v 1.20 2002/10/01 06:41:56 ei Exp $ * * reactos/subsys/csrss/api/process.c * @@ -15,6 +15,8 @@ #include #include "api.h" +BOOL STDCALL W32kCleanupForProcess( INT Process ); + #define LOCK RtlEnterCriticalSection(&ProcessDataLock) #define UNLOCK RtlLeaveCriticalSection(&ProcessDataLock) @@ -58,7 +60,7 @@ PCSRSS_PROCESS_DATA STDCALL CsrGetProcessData(ULONG ProcessId) for (i=0; iProcessId == Pid ) { + //DbgPrint("CsrFreeProcessData pid: %d\n", Pid); + W32kCleanupForProcess( Pid ); //should check if win32k process if( ProcessData[i]->HandleTable ) { int c; @@ -119,17 +123,17 @@ CSR_API(CsrCreateProcess) NTSTATUS Status; HANDLE Process; - Reply->Header.DataSize = sizeof(CSRSS_API_REPLY) - + Reply->Header.DataSize = sizeof(CSRSS_API_REPLY) - sizeof(LPC_MESSAGE_HEADER); Reply->Header.MessageSize = sizeof(CSRSS_API_REPLY); - + NewProcessData = CsrGetProcessData(Request->Data.CreateProcessRequest.NewProcessId); if (NewProcessData == NULL) { Reply->Status = STATUS_NO_MEMORY; return(STATUS_NO_MEMORY); } - + if (Request->Data.CreateProcessRequest.Flags & DETACHED_PROCESS) { NewProcessData->Console = NULL; @@ -192,7 +196,7 @@ CSR_API(CsrCreateProcess) NtClose( Process ); } else Reply->Data.CreateProcessReply.OutputHandle = Reply->Data.CreateProcessReply.InputHandle = INVALID_HANDLE_VALUE; - + return(STATUS_SUCCESS); } @@ -200,7 +204,7 @@ CSR_API(CsrTerminateProcess) { NTSTATUS Status; - Reply->Header.MessageSize = sizeof(CSRSS_API_REPLY) + Reply->Header.MessageSize = sizeof(CSRSS_API_REPLY) - sizeof(LPC_MESSAGE_HEADER); Reply->Header.DataSize = sizeof(CSRSS_API_REPLY); @@ -213,11 +217,11 @@ CSR_API(CsrTerminateProcess) CSR_API(CsrConnectProcess) { Reply->Header.MessageSize = sizeof(CSRSS_API_REPLY); - Reply->Header.DataSize = sizeof(CSRSS_API_REPLY) - + Reply->Header.DataSize = sizeof(CSRSS_API_REPLY) - sizeof(LPC_MESSAGE_HEADER); - + Reply->Status = STATUS_SUCCESS; - + return(STATUS_SUCCESS); } diff --git a/reactos/subsys/win32k/eng/handle.c b/reactos/subsys/win32k/eng/handle.c index 90a2f70af2a..dd0700bc2b6 100644 --- a/reactos/subsys/win32k/eng/handle.c +++ b/reactos/subsys/win32k/eng/handle.c @@ -11,7 +11,7 @@ #include #include "handle.h" -//#define NDEBUG +#define NDEBUG #include diff --git a/reactos/subsys/win32k/include/dce.h b/reactos/subsys/win32k/include/dce.h index 1fd417bf5cd..54c76b3ec6e 100644 --- a/reactos/subsys/win32k/include/dce.h +++ b/reactos/subsys/win32k/include/dce.h @@ -35,7 +35,7 @@ typedef struct tagDCE #define DCEOBJ_AllocDCE() \ ((HDCE) GDIOBJ_AllocObj (sizeof (DCE), GO_DCE_MAGIC)) -#define DCEOBJ_FreeDCE(hDCE) GDIOBJ_FreeObj((HGDIOBJ)hDCE, GO_DCE_MAGIC) +#define DCEOBJ_FreeDCE(hDCE) GDIOBJ_FreeObj((HGDIOBJ)hDCE, GO_DCE_MAGIC, GDIOBJFLAG_DEFAULT) #define DCEOBJ_LockDCE(hDCE) ((PDCE)GDIOBJ_LockObj((HGDIOBJ)hDCE, GO_DCE_MAGIC)) #define DCEOBJ_UnlockDCE(hDCE) GDIOBJ_UnlockObj((HGDIOBJ)hDCE, GO_DCE_MAGIC) diff --git a/reactos/subsys/win32k/objects/bitmaps.c b/reactos/subsys/win32k/objects/bitmaps.c index c80db98bf7a..f8d37caaae1 100644 --- a/reactos/subsys/win32k/objects/bitmaps.c +++ b/reactos/subsys/win32k/objects/bitmaps.c @@ -5,7 +5,7 @@ //#include #include "../eng/handle.h" -//#define NDEBUG +#define NDEBUG #include BOOL STDCALL W32kBitBlt(HDC hDCDest, @@ -169,7 +169,8 @@ HBITMAP STDCALL W32kCreateBitmap(INT Width, BOOL Bitmap_InternalDelete( PBITMAPOBJ pBmp ) { ASSERT( pBmp ); - ExFreePool(pBmp->bitmap.bmBits); + if( pBmp->bitmap.bmBits ) + ExFreePool(pBmp->bitmap.bmBits); return TRUE; } @@ -184,7 +185,7 @@ HBITMAP STDCALL W32kCreateCompatibleBitmap(HDC hDC, hbmpRet = 0; dc = DC_HandleToPtr (hDC); - DbgPrint("W32kCreateCompatibleBitmap(%04x,%d,%d, bpp:%d) = \n", hDC, Width, Height, dc->w.bitsPerPixel); + DPRINT("W32kCreateCompatibleBitmap(%04x,%d,%d, bpp:%d) = \n", hDC, Width, Height, dc->w.bitsPerPixel); if (!dc) { diff --git a/reactos/subsys/win32k/objects/dc.c b/reactos/subsys/win32k/objects/dc.c index 4e68234581f..7e528e662c8 100644 --- a/reactos/subsys/win32k/objects/dc.c +++ b/reactos/subsys/win32k/objects/dc.c @@ -1,4 +1,4 @@ -/* $Id: dc.c,v 1.42 2002/09/24 20:22:10 jfilby Exp $ +/* $Id: dc.c,v 1.43 2002/10/01 06:41:55 ei Exp $ * * DC.C - Device context functions * @@ -236,7 +236,7 @@ BOOL STDCALL W32kCreatePrimarySurface(LPCWSTR Driver, DPRINT("Enabling PDev\n"); - PrimarySurface.PDev = + PrimarySurface.PDev = PrimarySurface.DriverFunctions.EnablePDev(&PrimarySurface.DMW, L"", HS_DDI_MAX, @@ -257,7 +257,7 @@ BOOL STDCALL W32kCreatePrimarySurface(LPCWSTR Driver, DPRINT("calling completePDev\n"); /* Complete initialization of the physical device */ - PrimarySurface.DriverFunctions.CompletePDev(PrimarySurface.PDev, + PrimarySurface.DriverFunctions.CompletePDev(PrimarySurface.PDev, &PrimarySurface); DPRINT("calling DRIVER_ReferenceDriver\n"); @@ -267,8 +267,8 @@ BOOL STDCALL W32kCreatePrimarySurface(LPCWSTR Driver, DPRINT("calling EnableSurface\n"); /* Enable the drawing surface */ - PrimarySurface.Handle = - PrimarySurface.DriverFunctions.EnableSurface(PrimarySurface.PDev); + PrimarySurface.Handle = + PrimarySurface.DriverFunctions.EnableSurface(PrimarySurface.PDev); SurfObj = (PSURFOBJ)AccessUserObject(PrimarySurface.Handle); SurfObj->dhpdev = PrimarySurface.PDev; @@ -278,10 +278,10 @@ HDC STDCALL W32kCreateDC(LPCWSTR Driver, LPCWSTR Device, LPCWSTR Output, CONST PDEVMODEW InitData) -{ +{ HDC hNewDC; PDC NewDC; - HDC hDC = NULL; + HDC hDC = NULL; /* Check for existing DC object */ if ((hNewDC = DC_FindOpenDC(Driver)) != NULL) @@ -333,8 +333,8 @@ HDC STDCALL W32kCreateDC(LPCWSTR Driver, NewDC->DMW.dmDisplayFrequency = 0; NewDC->w.bitsPerPixel = 4; // FIXME: set this here?? - - NewDC->w.hPalette = NewDC->DevInfo.hpalDefault; + + NewDC->w.hPalette = NewDC->DevInfo.hpalDefault; DPRINT("Bits per pel: %u\n", NewDC->w.bitsPerPixel); @@ -378,7 +378,8 @@ BOOL STDCALL W32kDeleteDC(HDC DCHandle) DCToDelete->DriverFunctions.AssertMode( DCToDelete->PDev, FALSE ); CHECKPOINT; DCToDelete->DriverFunctions.DisablePDev(DCToDelete->PDev); - } + PrimarySurfaceCreated = FALSE; + } } CHECKPOINT; /* First delete all saved DCs */ @@ -972,7 +973,7 @@ HGDIOBJ STDCALL W32kSelectObject(HDC hDC, HGDIOBJ hGDIObj) if( PalGDI ){ XlateObj = (PXLATEOBJ)EngCreateXlate(PalGDI->Mode, PAL_RGB, dc->w.hPalette, NULL); brush = GDIOBJ_LockObj(dc->w.hBrush, GO_BRUSH_MAGIC); - brush->iSolidColor = XLATEOBJ_iXlate(XlateObj, + brush->iSolidColor = XLATEOBJ_iXlate(XlateObj, brush->logbrush.lbColor); GDIOBJ_UnlockObj( dc->w.hBrush, GO_BRUSH_MAGIC); } @@ -1234,7 +1235,7 @@ void DC_InitDC(HDC DCHandle) void DC_FreeDC(HDC DCToFree) { - if (!GDIOBJ_FreeObj(DCToFree, GO_DC_MAGIC)) + if (!GDIOBJ_FreeObj(DCToFree, GO_DC_MAGIC, GDIOBJFLAG_DEFAULT)) { DPRINT("DC_FreeDC failed\n"); } @@ -1242,7 +1243,8 @@ void DC_FreeDC(HDC DCToFree) BOOL DC_InternalDeleteDC( PDC DCToDelete ) { - ExFreePool(DCToDelete->DriverName); + if( DCToDelete->DriverName ) + ExFreePool(DCToDelete->DriverName); return TRUE; } diff --git a/reactos/subsys/win32k/objects/dib.c b/reactos/subsys/win32k/objects/dib.c index 3864719fb41..a78f63c9dfe 100644 --- a/reactos/subsys/win32k/objects/dib.c +++ b/reactos/subsys/win32k/objects/dib.c @@ -540,7 +540,7 @@ HBITMAP DIB_CreateDIBSection( if (dib) { ExFreePool(dib); dib = NULL; } if (bmp) { bmp = NULL; } - if (res) { GDIOBJ_FreeObj(res, GO_BITMAP_MAGIC); res = 0; } + if (res) { GDIOBJ_FreeObj(res, GO_BITMAP_MAGIC, GDIOBJFLAG_DEFAULT); res = 0; } } // Install fault handler, if possible diff --git a/reactos/subsys/win32k/objects/gdiobj.c b/reactos/subsys/win32k/objects/gdiobj.c index 9fae31a4879..960b56375c1 100644 --- a/reactos/subsys/win32k/objects/gdiobj.c +++ b/reactos/subsys/win32k/objects/gdiobj.c @@ -1,7 +1,7 @@ /* * GDIOBJ.C - GDI object manipulation routines * - * $Id: gdiobj.c,v 1.18 2002/09/08 10:23:53 chorns Exp $ + * $Id: gdiobj.c,v 1.19 2002/10/01 06:41:55 ei Exp $ * */ @@ -169,6 +169,7 @@ HGDIOBJ GDIOBJ_AllocObj(WORD Size, WORD Magic) newObject = ExAllocatePool (PagedPool, Size + sizeof (GDIOBJHDR)); if (newObject == NULL) { + DPRINT("GDIOBJ_AllocObj: failed\n"); return NULL; } RtlZeroMemory (newObject, Size + sizeof (GDIOBJHDR)); @@ -183,7 +184,7 @@ HGDIOBJ GDIOBJ_AllocObj(WORD Size, WORD Magic) return (HGDIOBJ) newObject->wTableIndex; } -BOOL GDIOBJ_FreeObj(HGDIOBJ hObj, WORD Magic) +BOOL GDIOBJ_FreeObj(HGDIOBJ hObj, WORD Magic, DWORD Flag) { PGDIOBJHDR objectHeader; PGDI_HANDLE_ENTRY handleEntry; @@ -191,24 +192,28 @@ BOOL GDIOBJ_FreeObj(HGDIOBJ hObj, WORD Magic) BOOL bRet = TRUE; handleEntry = GDIOBJ_iGetHandleEntryForIndex ((WORD)hObj & 0xffff); - DPRINT("GDIOBJ_FreeObj: hObj: %d, magic: %x, handleEntry: %x\n", hObj, Magic, handleEntry ); - if (handleEntry == 0 || (handleEntry->wMagic != Magic && handleEntry->wMagic != GO_MAGIC_DONTCARE ) - || handleEntry->hProcessId != PsGetCurrentProcessId ()) + DPRINT("GDIOBJ_FreeObj: hObj: %d, magic: %x, handleEntry: %x\n", (WORD)hObj & 0xffff, Magic, handleEntry ); + if (handleEntry == 0 || (handleEntry->wMagic != Magic && Magic != GO_MAGIC_DONTCARE ) + || ((handleEntry->hProcessId != PsGetCurrentProcessId()) && !(Flag & GDIOBJFLAG_IGNOREPID))){ + DPRINT("Can't Delete hObj: %d, magic: %x, pid:%d\n currpid:%d, flag:%d, hmm:%d\n",(WORD)hObj & 0xffff, handleEntry->wMagic, handleEntry->hProcessId, PsGetCurrentProcessId(), (Flag&GDIOBJFLAG_IGNOREPID), ((handleEntry->hProcessId != PsGetCurrentProcessId()) && !(Flag&GDIOBJFLAG_IGNOREPID)) ); return FALSE; + } objectHeader = (PGDIOBJHDR) handleEntry->pObject; ASSERT(objectHeader); - - // check that the reference count is zero. if not then set flag - // and delete object when releaseobj is called - ExAcquireFastMutex(&RefCountHandling); - if( ( objectHeader->dwCount & ~0x80000000 ) > 0 ){ - objectHeader->dwCount |= 0x80000000; - DPRINT("GDIOBJ_FreeObj: delayed object deletion"); + DPRINT("FreeObj: locks: %x\n", objectHeader->dwCount ); + if( !(Flag & GDIOBJFLAG_IGNORELOCK) ){ + // check that the reference count is zero. if not then set flag + // and delete object when releaseobj is called + ExAcquireFastMutex(&RefCountHandling); + if( ( objectHeader->dwCount & ~0x80000000 ) > 0 ){ + DPRINT("GDIOBJ_FreeObj: delayed object deletion: count %d\n", objectHeader->dwCount); + objectHeader->dwCount |= 0x80000000; + ExReleaseFastMutex(&RefCountHandling); + return TRUE; + } ExReleaseFastMutex(&RefCountHandling); - return TRUE; - } - ExReleaseFastMutex(&RefCountHandling); + } //allow object to delete internal data Obj = (PGDIOBJ)((PCHAR)handleEntry->pObject + sizeof(GDIOBJHDR)); @@ -216,14 +221,14 @@ BOOL GDIOBJ_FreeObj(HGDIOBJ hObj, WORD Magic) case GO_REGION_MAGIC: bRet = RGNDATA_InternalDelete( (PROSRGNDATA) Obj ); break; - case GO_PEN_MAGIC: - case GO_PALETTE_MAGIC: case GO_BITMAP_MAGIC: bRet = Bitmap_InternalDelete( (PBITMAPOBJ) Obj ); break; case GO_DC_MAGIC: bRet = DC_InternalDeleteDC( (PDC) Obj ); break; + case GO_PEN_MAGIC: + case GO_PALETTE_MAGIC: case GO_DISABLED_DC_MAGIC: case GO_META_DC_MAGIC: case GO_METAFILE_MAGIC: @@ -251,10 +256,12 @@ PGDIOBJ GDIOBJ_LockObj( HGDIOBJ hObj, WORD Magic ) PGDIOBJHDR objectHeader; DPRINT("GDIOBJ_LockObj: hObj: %d, magic: %x, \n handleEntry: %x, mag %x\n", hObj, Magic, handleEntry, handleEntry->wMagic); - if (handleEntry == 0 || (handleEntry->wMagic != Magic && handleEntry->wMagic != GO_MAGIC_DONTCARE ) + if (handleEntry == 0 || (handleEntry->wMagic != Magic && Magic != GO_MAGIC_DONTCARE ) || (handleEntry->hProcessId != (HANDLE)0xFFFFFFFF && - handleEntry->hProcessId != PsGetCurrentProcessId ())) + handleEntry->hProcessId != PsGetCurrentProcessId ())){ + DPRINT("GDIBOJ_LockObj failed for %d, magic: %d, reqMagic\n",(WORD) hObj & 0xffff, handleEntry->wMagic, Magic); return NULL; + } objectHeader = (PGDIOBJHDR) handleEntry->pObject; ASSERT(objectHeader); @@ -273,10 +280,12 @@ BOOL GDIOBJ_UnlockObj( HGDIOBJ hObj, WORD Magic ) PGDIOBJHDR objectHeader; DPRINT("GDIOBJ_UnlockObj: hObj: %d, magic: %x, \n handleEntry: %x\n", hObj, Magic, handleEntry); - if (handleEntry == 0 || (handleEntry->wMagic != Magic && handleEntry->wMagic != GO_MAGIC_DONTCARE ) + if (handleEntry == 0 || (handleEntry->wMagic != Magic && Magic != GO_MAGIC_DONTCARE ) || (handleEntry->hProcessId != (HANDLE)0xFFFFFFFF && - handleEntry->hProcessId != PsGetCurrentProcessId ())) - return FALSE; + handleEntry->hProcessId != PsGetCurrentProcessId ())){ + DPRINT( "GDIOBJ_UnLockObj: failed\n"); + return FALSE; + } objectHeader = (PGDIOBJHDR) handleEntry->pObject; ASSERT(objectHeader); @@ -297,7 +306,7 @@ BOOL GDIOBJ_UnlockObj( HGDIOBJ hObj, WORD Magic ) objectHeader->dwCount = 0; ExReleaseFastMutex(&RefCountHandling); DPRINT("GDIOBJ_UnlockObj: delayed delete\n"); - return GDIOBJ_FreeObj( hObj, Magic ); + return GDIOBJ_FreeObj( hObj, Magic, GDIOBJFLAG_DEFAULT ); } ExReleaseFastMutex(&RefCountHandling); return TRUE; @@ -369,7 +378,7 @@ PGDIOBJ GDIOBJ_HandleToPtr (HGDIOBJ ObjectHandle, WORD Magic) handleEntry = GDIOBJ_iGetHandleEntryForIndex ((WORD)ObjectHandle & 0xffff); if (handleEntry == 0 || - (Magic != GO_MAGIC_DONTCARE && handleEntry->wMagic != Magic) || + (Magic != GO_MAGIC_DONTCARE && Magic != Magic) || handleEntry->hProcessId != PsGetCurrentProcessId () ) return NULL; @@ -451,7 +460,7 @@ VOID CreateStockObjects(void) GDIOBJ_MarkObjectGlobal(StockObjects[ANSI_FIXED_FONT]); StockObjects[SYSTEM_FONT] = W32kCreateFontIndirect(&SystemFont); GDIOBJ_MarkObjectGlobal(StockObjects[SYSTEM_FONT]); - StockObjects[DEVICE_DEFAULT_FONT] = + StockObjects[DEVICE_DEFAULT_FONT] = W32kCreateFontIndirect(&DeviceDefaultFont); GDIOBJ_MarkObjectGlobal(StockObjects[DEVICE_DEFAULT_FONT]); StockObjects[SYSTEM_FIXED_FONT] = W32kCreateFontIndirect(&SystemFixedFont); @@ -477,7 +486,24 @@ HGDIOBJ STDCALL W32kGetStockObject(INT Object) BOOL STDCALL W32kDeleteObject(HGDIOBJ hObject) { - return GDIOBJ_FreeObj( hObject, GO_MAGIC_DONTCARE ); + return GDIOBJ_FreeObj( hObject, GO_MAGIC_DONTCARE, GDIOBJFLAG_DEFAULT ); +} + +BOOL STDCALL W32kCleanupForProcess( INT Process ) +{ + DWORD i; + PGDI_HANDLE_ENTRY handleEntry; + PGDIOBJHDR objectHeader; + + for( i=1; i < GDI_HANDLE_NUMBER; i++ ){ + handleEntry = GDIOBJ_iGetHandleEntryForIndex ((WORD) i & 0xffff); + if( handleEntry && handleEntry->wMagic != 0 && handleEntry->hProcessId == Process){ + objectHeader = (PGDIOBJHDR) handleEntry->pObject; + DPRINT("\nW32kCleanup: %d, magic: %x \n process: %d, locks: %d", i, handleEntry->wMagic, handleEntry->hProcessId, objectHeader->dwCount); + GDIOBJ_FreeObj( (WORD) i & 0xffff, GO_MAGIC_DONTCARE, GDIOBJFLAG_IGNOREPID|GDIOBJFLAG_IGNORELOCK ); + } + } + return TRUE; } // dump all the objects for process. if process == 0 dump all the objects diff --git a/reactos/subsys/win32k/objects/objconv.c b/reactos/subsys/win32k/objects/objconv.c index 9dbbe03e076..c3582a130b7 100644 --- a/reactos/subsys/win32k/objects/objconv.c +++ b/reactos/subsys/win32k/objects/objconv.c @@ -22,6 +22,8 @@ PBRUSHOBJ PenToBrushObj(PDC dc, PENOBJ *pen) BRUSHOBJ *BrushObj; XLATEOBJ *RGBtoVGA16; + ASSERT( pen ); + BrushObj = ExAllocatePool(NonPagedPool, sizeof(BRUSHOBJ)); BrushObj->iSolidColor = pen->logpen.lopnColor; diff --git a/reactos/subsys/win32k/objects/region.c b/reactos/subsys/win32k/objects/region.c index dc4959a64b6..161b8adae65 100644 --- a/reactos/subsys/win32k/objects/region.c +++ b/reactos/subsys/win32k/objects/region.c @@ -1429,7 +1429,7 @@ HRGN RGNDATA_AllocRgn(INT n) } else - GDIOBJ_FreeObj( hReg, GO_REGION_MAGIC ); + GDIOBJ_FreeObj( hReg, GO_REGION_MAGIC, GDIOBJFLAG_DEFAULT ); } return NULL; } @@ -1694,7 +1694,7 @@ UnsafeW32kGetRgnBox(HRGN hRgn, *pRect = rgn->rdh.rcBound; ret = rgn->rdh.iType; RGNDATA_UnlockRgn( hRgn ); - + return ret; } return 0; //if invalid region return zero @@ -1717,10 +1717,10 @@ W32kGetRgnBox(HRGN hRgn, SafeRect.bottom = rgn->rdh.rcBound.bottom; ret = rgn->rdh.iType; RGNDATA_UnlockRgn( hRgn ); - + if(!NT_SUCCESS(MmCopyToCaller(pRect, &SafeRect, sizeof(RECT)))) return 0; - + return ret; } return 0; //if invalid region return zero