From 44c92af3c68dfd4181b48816e82bce2296d104b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A9=20van=20Geldorp?= Date: Mon, 20 Oct 2003 17:57:05 +0000 Subject: [PATCH] Partial fix for handling GDIOBJs between different processes svn path=/trunk/; revision=6387 --- reactos/include/win32k/gdiobj.h | 2 ++ reactos/subsys/win32k/ntuser/windc.c | 25 ++++++++++++++++- reactos/subsys/win32k/objects/dc.c | 3 +- reactos/subsys/win32k/objects/gdiobj.c | 39 ++++++++++++++++++++++++-- 4 files changed, 65 insertions(+), 4 deletions(-) diff --git a/reactos/include/win32k/gdiobj.h b/reactos/include/win32k/gdiobj.h index 19d8dc90d60..d558ca5db03 100644 --- a/reactos/include/win32k/gdiobj.h +++ b/reactos/include/win32k/gdiobj.h @@ -66,6 +66,8 @@ BOOL FASTCALL GDIOBJ_LockMultipleObj(PGDIMULTILOCK pList, INT nObj); BOOL FASTCALL GDIOBJ_UnlockObj (HGDIOBJ Obj, DWORD ObjectType); BOOL FASTCALL GDIOBJ_UnlockMultipleObj(PGDIMULTILOCK pList, INT nObj); DWORD FASTCALL GDIOBJ_GetObjectType(HGDIOBJ ObjectHandle); +BOOL FASTCALL GDIOBJ_OwnedByCurrentProcess(HGDIOBJ ObjectHandle); +void FASTCALL GDIOBJ_TakeOwnership(HGDIOBJ ObjectHandle); /* a couple macros for debugging GDIOBJ locking */ #define GDIOBJ_LockObj(obj,ty) GDIOBJ_LockObjDbg(__FILE__,__LINE__,obj,ty) diff --git a/reactos/subsys/win32k/ntuser/windc.c b/reactos/subsys/win32k/ntuser/windc.c index cc7d63cd1e4..53c5730647d 100644 --- a/reactos/subsys/win32k/ntuser/windc.c +++ b/reactos/subsys/win32k/ntuser/windc.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: windc.c,v 1.32 2003/10/17 21:35:45 gvg Exp $ +/* $Id: windc.c,v 1.33 2003/10/20 17:57:05 gvg Exp $ * * COPYRIGHT: See COPYING in the top level directory * PROJECT: ReactOS kernel @@ -266,6 +266,7 @@ NtUserGetDCEx(HWND hWnd, HANDLE ClipRegion, ULONG Flags) BOOL UpdateVisRgn = TRUE; BOOL UpdateClipOrigin = FALSE; HANDLE hRgnVisible = NULL; + PDC DC; if (NULL == hWnd) { @@ -380,6 +381,28 @@ NtUserGetDCEx(HWND hWnd, HANDLE ClipRegion, ULONG Flags) { Dce = DceAllocDCE(NULL, DCE_CACHE_DC); } + else if (! GDIOBJ_OwnedByCurrentProcess(Dce->Self)) + { + GDIOBJ_TakeOwnership(Dce->Self); + GDIOBJ_TakeOwnership(Dce->hDC); + DC = DC_LockDc(Dce->hDC); + if (NULL != DC) + { + if (NULL != DC->w.hClipRgn) + { + GDIOBJ_TakeOwnership(DC->w.hClipRgn); + } + if (NULL != DC->w.hVisRgn) + { + GDIOBJ_TakeOwnership(DC->w.hVisRgn); + } + if (NULL != DC->w.hGCClipRgn) + { + GDIOBJ_TakeOwnership(DC->w.hGCClipRgn); + } + DC_UnlockDc(Dce->hDC); + } + } } else { diff --git a/reactos/subsys/win32k/objects/dc.c b/reactos/subsys/win32k/objects/dc.c index 9b51606cdf7..dcdc4710c74 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.88 2003/10/12 20:23:25 gvg Exp $ +/* $Id: dc.c,v 1.89 2003/10/20 17:57:05 gvg Exp $ * * DC.C - Device context functions * @@ -413,6 +413,7 @@ NtGdiCreatePrimarySurface(LPCWSTR Driver, DPRINT("Adjusting GDIInfo.ulLogPixelsY\n"); PrimarySurface.GDIInfo.ulLogPixelsY = 96; } + GDIOBJ_MarkObjectGlobal(PrimarySurface.DevInfo.hpalDefault); DPRINT("calling completePDev\n"); diff --git a/reactos/subsys/win32k/objects/gdiobj.c b/reactos/subsys/win32k/objects/gdiobj.c index c7b4ef47fc4..8f6a80bf6b7 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.47 2003/10/16 03:26:51 vizzini Exp $ + * $Id: gdiobj.c,v 1.48 2003/10/20 17:57:05 gvg Exp $ * */ @@ -63,6 +63,8 @@ #define GDI_TYPE_TO_MAGIC(t) ((WORD) ((t) >> 16)) #define GDI_MAGIC_TO_TYPE(m) ((DWORD)(m) << 16) +/* FIXME Ownership of GDI objects by processes not properly implemented yet */ +#if 0 #define GDI_VALID_OBJECT(h, obj, t, f) \ (NULL != (obj) \ && (GDI_MAGIC_TO_TYPE((obj)->Magic) == (t) || GDI_OBJECT_TYPE_DONTCARE == (t)) \ @@ -70,6 +72,12 @@ && (((obj)->hProcessId == PsGetCurrentProcessId()) \ || (GDI_GLOBAL_PROCESS == (obj)->hProcessId) \ || ((f) & GDIOBJFLAG_IGNOREPID))) +#else +#define GDI_VALID_OBJECT(h, obj, t, f) \ + (NULL != (obj) \ + && (GDI_MAGIC_TO_TYPE((obj)->Magic) == (t) || GDI_OBJECT_TYPE_DONTCARE == (t)) \ + && (GDI_HANDLE_GET_TYPE((h)) == GDI_MAGIC_TO_TYPE((obj)->Magic))) +#endif typedef struct _GDI_HANDLE_TABLE { @@ -438,7 +446,7 @@ GDIOBJ_UnmarkObjectGlobal(HGDIOBJ ObjectHandle) DPRINT("GDIOBJ_MarkObjectGlobal handle 0x%08x\n", ObjectHandle); ObjHdr = GDIOBJ_iGetObjectForIndex(GDI_HANDLE_GET_INDEX(ObjectHandle)); - if (NULL == ObjHdr || GDI_GLOBAL_PROCESS != ObjHdr->hProcessId) + if (NULL == ObjHdr /*|| GDI_GLOBAL_PROCESS != ObjHdr->hProcessId*/) { return; } @@ -620,6 +628,8 @@ GDIOBJ_LockObjDbg (const char* file, int line, HGDIOBJ hObj, DWORD ObjectType) else if (ObjHdr->hProcessId != GDI_GLOBAL_PROCESS && ObjHdr->hProcessId != PsGetCurrentProcessId()) { +DPRINT1("object proc 0x%x current proc 0x%x\n", ObjHdr->hProcessId, PsGetCurrentProcessId()); +__asm__("int $3\n"); reason = 3; } else if (GDI_HANDLE_GET_TYPE(hObj) != ObjectType && ObjectType != GDI_OBJECT_TYPE_DONTCARE) @@ -755,4 +765,29 @@ GDIOBJ_UnlockObj(HGDIOBJ hObj, DWORD ObjectType) return TRUE; } +BOOL FASTCALL +GDIOBJ_OwnedByCurrentProcess(HGDIOBJ ObjectHandle) +{ + PGDIOBJHDR ObjHdr = GDIOBJ_iGetObjectForIndex(GDI_HANDLE_GET_INDEX(ObjectHandle)); + + DPRINT("GDIOBJ_OwnedByCurrentProcess: ObjectHandle: 0x%08x\n", ObjectHandle); + ASSERT(GDI_VALID_OBJECT(ObjectHandle, ObjHdr, GDI_OBJECT_TYPE_DONTCARE, GDIOBJFLAG_IGNOREPID)); + + return ObjHdr->hProcessId == PsGetCurrentProcessId(); +} + +void FASTCALL +GDIOBJ_TakeOwnership(HGDIOBJ ObjectHandle) +{ + PGDIOBJHDR ObjHdr = GDIOBJ_iGetObjectForIndex(GDI_HANDLE_GET_INDEX(ObjectHandle)); + + DPRINT("GDIOBJ_OwnedByCurrentProcess: ObjectHandle: 0x%08x\n", ObjectHandle); + ASSERT(GDI_VALID_OBJECT(ObjectHandle, ObjHdr, GDI_OBJECT_TYPE_DONTCARE, GDIOBJFLAG_IGNOREPID)); + + if (GDI_GLOBAL_PROCESS != ObjHdr->hProcessId) + { + ObjHdr->hProcessId = PsGetCurrentProcessId(); + } +} + /* EOF */