ReactOS  0.4.15-dev-2359-g0dedb9b
gdiobj.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  _GDI_HANDLE_TABLE
 
struct  _BASEOBJECT
 
struct  _CLIENTOBJ
 

Macros

#define GDI_OBJECT_STACK_LEVELS   20
 

Typedefs

typedef struct _GDI_HANDLE_TABLE GDI_HANDLE_TABLE
 
typedef struct _GDI_HANDLE_TABLEPGDI_HANDLE_TABLE
 
typedef PVOID PGDIOBJ
 
typedef VOID(NTAPIGDICLEANUPPROC) (PVOID ObjectBody)
 
typedef VOID(NTAPIGDIOBJDELETEPROC) (PVOID ObjectBody)
 
typedef struct _BASEOBJECT BASEOBJECT
 
typedef struct _BASEOBJECTPOBJ
 
typedef struct _CLIENTOBJ CLIENTOBJ
 
typedef struct _CLIENTOBJPCLIENTOBJ
 

Enumerations

enum  BASEFLAGS { BASEFLAG_LOOKASIDE = 0x80, BASEFLAG_READY_TO_DIE = 0x1000 }
 
enum  _GDIOBJLAGS { GDIOBJFLAG_DEFAULT = 0x00, GDIOBJFLAG_IGNOREPID = 0x01, GDIOBJFLAG_IGNORELOCK = 0x02 }
 

Functions

NTSTATUS NTAPI InitGdiHandleTable (VOID)
 
BOOL NTAPI GreIsHandleValid (HGDIOBJ hobj)
 
BOOL NTAPI GreDeleteObject (HGDIOBJ hObject)
 
ULONG NTAPI GreGetObjectOwner (HGDIOBJ hobj)
 
BOOL NTAPI GreSetObjectOwner (HGDIOBJ hobj, ULONG ulOwner)
 
BOOL NTAPI GreSetObjectOwnerEx (HGDIOBJ hobj, ULONG ulOwner, ULONG Flags)
 
INT NTAPI GreGetObject (IN HGDIOBJ hobj, IN INT cbCount, OUT PVOID pvBuffer)
 
POBJ NTAPI GDIOBJ_AllocateObject (UCHAR objt, ULONG cjSize, FLONG fl)
 
VOID NTAPI GDIOBJ_vDeleteObject (POBJ pobj)
 
POBJ NTAPI GDIOBJ_ReferenceObjectByHandle (HGDIOBJ hobj, UCHAR objt)
 
VOID NTAPI GDIOBJ_vReferenceObjectByPointer (POBJ pobj)
 
VOID NTAPI GDIOBJ_vDereferenceObject (POBJ pobj)
 
PGDIOBJ NTAPI GDIOBJ_LockObject (HGDIOBJ hobj, UCHAR objt)
 
PGDIOBJ NTAPI GDIOBJ_TryLockObject (HGDIOBJ hobj, UCHAR objt)
 
VOID NTAPI GDIOBJ_vUnlockObject (POBJ pobj)
 
VOID NTAPI GDIOBJ_vSetObjectOwner (POBJ pobj, ULONG ulOwner)
 
BOOL NTAPI GDIOBJ_bLockMultipleObjects (ULONG ulCount, HGDIOBJ *ahObj, PGDIOBJ *apObj, UCHAR objt)
 
HGDIOBJ NTAPI GDIOBJ_hInsertObject (POBJ pobj, ULONG ulOwner)
 
VOID NTAPI GDIOBJ_vFreeObject (POBJ pobj)
 
VOID NTAPI GDIOBJ_vSetObjectAttr (POBJ pobj, PVOID pvObjAttr)
 
PVOID NTAPI GDIOBJ_pvGetObjectAttr (POBJ pobj)
 
BOOL NTAPI GDIOBJ_ConvertToStockObj (HGDIOBJ *hObj)
 
POBJ NTAPI GDIOBJ_AllocObjWithHandle (ULONG ObjectType, ULONG cjSize)
 
PGDIOBJ NTAPI GDIOBJ_ShareLockObj (HGDIOBJ hObj, DWORD ObjectType)
 
PVOID NTAPI GDI_MapHandleTable (PEPROCESS Process)
 

Variables

static const unsigned RESERVE_ENTRIES_COUNT = 10
 
PGDI_HANDLE_TABLE GdiHandleTable
 

Macro Definition Documentation

◆ GDI_OBJECT_STACK_LEVELS

#define GDI_OBJECT_STACK_LEVELS   20

Definition at line 8 of file gdiobj.h.

Typedef Documentation

◆ BASEOBJECT

◆ CLIENTOBJ

◆ GDI_HANDLE_TABLE

◆ GDICLEANUPPROC

typedef VOID(NTAPI * GDICLEANUPPROC) (PVOID ObjectBody)

Definition at line 33 of file gdiobj.h.

◆ GDIOBJDELETEPROC

typedef VOID(NTAPI * GDIOBJDELETEPROC) (PVOID ObjectBody)

Definition at line 34 of file gdiobj.h.

◆ PCLIENTOBJ

◆ PGDI_HANDLE_TABLE

◆ PGDIOBJ

typedef PVOID PGDIOBJ

Definition at line 31 of file gdiobj.h.

◆ POBJ

typedef struct _BASEOBJECT * POBJ

Enumeration Type Documentation

◆ _GDIOBJLAGS

Enumerator
GDIOBJFLAG_DEFAULT 
GDIOBJFLAG_IGNOREPID 
GDIOBJFLAG_IGNORELOCK 

Definition at line 69 of file gdiobj.h.

◆ BASEFLAGS

Enumerator
BASEFLAG_LOOKASIDE 
BASEFLAG_READY_TO_DIE 

Definition at line 56 of file gdiobj.h.

57 {
58  BASEFLAG_LOOKASIDE = 0x80,
59 
60  /* ReactOS specific: */
61  BASEFLAG_READY_TO_DIE = 0x1000
62 };

Function Documentation

◆ GDI_MapHandleTable()

PVOID NTAPI GDI_MapHandleTable ( PEPROCESS  Process)

Definition at line 1518 of file gdiobj.c.

1519 {
1520  PVOID pvMappedView = NULL;
1521  NTSTATUS Status;
1522  LARGE_INTEGER liOffset;
1523  SIZE_T cjViewSize = sizeof(GDI_HANDLE_TABLE);
1524 
1525  liOffset.QuadPart = 0;
1526 
1528  ASSERT(pProcess != NULL);
1529 
1531  pProcess,
1532  &pvMappedView,
1533  0,
1534  0,
1535  &liOffset,
1536  &cjViewSize,
1537  ViewUnmap,
1538  SEC_NO_CHANGE,
1539  PAGE_READONLY);
1540 
1541  if (!NT_SUCCESS(Status))
1542  return NULL;
1543 
1544  return pvMappedView;
1545 }
LONG NTSTATUS
Definition: precomp.h:26
NTSTATUS NTAPI MmMapViewOfSection(IN PVOID SectionObject, IN PEPROCESS Process, IN OUT PVOID *BaseAddress, IN ULONG_PTR ZeroBits, IN SIZE_T CommitSize, IN OUT PLARGE_INTEGER SectionOffset OPTIONAL, IN OUT PSIZE_T ViewSize, IN SECTION_INHERIT InheritDisposition, IN ULONG AllocationType, IN ULONG Protect)
Definition: section.c:3851
Status
Definition: gdiplustypes.h:24
#define ASSERT(a)
Definition: mode.c:45
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
struct _GDI_HANDLE_TABLE GDI_HANDLE_TABLE
static PVOID gpvGdiHdlTblSection
Definition: gdiobj.c:148
ULONG_PTR SIZE_T
Definition: typedefs.h:80
#define NULL
Definition: types.h:112
#define PAGE_READONLY
Definition: compat.h:138
#define SEC_NO_CHANGE
Definition: mmtypes.h:94
LONGLONG QuadPart
Definition: typedefs.h:114

Referenced by GdiProcessCreate().

◆ GDIOBJ_AllocateObject()

POBJ NTAPI GDIOBJ_AllocateObject ( UCHAR  objt,
ULONG  cjSize,
FLONG  fl 
)

Definition at line 562 of file gdiobj.c.

563 {
564  POBJ pobj;
565 
566  if (fl & BASEFLAG_LOOKASIDE)
567  {
568  /* Allocate the object from a lookaside list */
569  pobj = ExAllocateFromPagedLookasideList(&gpaLookasideList[objt & 0x1f]);
570  }
571  else
572  {
573  /* Allocate the object from paged pool */
575  }
576 
577  if (!pobj) return NULL;
578 
579  /* Initialize the object */
580  RtlZeroMemory(pobj, cjSize);
581  pobj->hHmgr = (HGDIOBJ)((ULONG_PTR)objt << 16);
582  pobj->cExclusiveLock = 0;
583  pobj->ulShareCount = 1;
584  pobj->BaseFlags = fl & 0xffff;
585  DBG_INITLOG(&pobj->slhLog);
586  DBG_LOGEVENT(&pobj->slhLog, EVENT_ALLOCATE, 0);
587 #if DBG_ENABLE_GDIOBJ_BACKTRACES
588  DbgCaptureStackBackTace(pobj->apvBackTrace, 1, GDI_OBJECT_STACK_LEVELS);
589 #endif /* GDI_DEBUG */
590 
591  return pobj;
592 }
ULONG NTAPI DbgCaptureStackBackTace(_Out_writes_(cFramesToCapture) PVOID *ppvFrames, _In_ ULONG cFramesToSkip, _In_ ULONG cFramesToCapture)
ULONG ulShareCount
Definition: gdiobj.h:42
#define DBG_INITLOG(pslh)
Definition: gdidebug.h:110
static PPAGED_LOOKASIDE_LIST gpaLookasideList
Definition: gdiobj.c:153
USHORT cExclusiveLock
Definition: gdiobj.h:45
HGDIOBJ hHmgr
Definition: gdiobj.h:40
USHORT BaseFlags
Definition: gdiobj.h:46
uint32_t ULONG_PTR
Definition: typedefs.h:65
#define GDIOBJ_POOL_TAG(type)
Definition: gdiobj.c:134
_In_ FLONG fl
Definition: winddi.h:1279
#define DBG_LOGEVENT(pslh, type, val)
Definition: gdidebug.h:109
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
#define GDI_OBJECT_STACK_LEVELS
Definition: gdiobj.h:8
void * HGDIOBJ
Definition: windef.h:252
#define NULL
Definition: types.h:112
_In_ ULONG cjSize
Definition: winddi.h:3634
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262

Referenced by DC_AllocDcWithHandle(), GDIOBJ_AllocObjWithHandle(), IntSysCreateRectpRgn(), NtGdiCreateClientObj(), PALETTE_AllocPalette(), and REGION_AllocRgnWithHandle().

◆ GDIOBJ_AllocObjWithHandle()

POBJ NTAPI GDIOBJ_AllocObjWithHandle ( ULONG  ObjectType,
ULONG  cjSize 
)

Definition at line 1488 of file gdiobj.c.

1489 {
1490  POBJ pobj;
1491  FLONG fl = 0;
1492  UCHAR objt = (ObjectType >> 16) & 0xFF;
1493 
1494  if ((objt == GDIObjType_DC_TYPE && cjSize == sizeof(DC)) ||
1495  (objt == GDIObjType_PAL_TYPE && cjSize == sizeof(PALETTE)) ||
1496  (objt == GDIObjType_RGN_TYPE && cjSize == sizeof(REGION)) ||
1497  (objt == GDIObjType_SURF_TYPE && cjSize == sizeof(SURFACE)) ||
1498  (objt == GDIObjType_PATH_TYPE && cjSize == sizeof(PATH)))
1499  {
1501  }
1502 
1503  pobj = GDIOBJ_AllocateObject(objt, cjSize, fl);
1504  if (!pobj)
1505  {
1506  return NULL;
1507  }
1508 
1510  {
1511  GDIOBJ_vFreeObject(pobj);
1512  return NULL;
1513  }
1514  return pobj;
1515 }
ObjectType
Definition: metafile.c:80
struct _PALETTE PALETTE
_In_ FLONG fl
Definition: winddi.h:1279
unsigned long FLONG
Definition: ntbasedef.h:366
Definition: polytest.cpp:40
unsigned char UCHAR
Definition: xmlstorage.h:181
struct _PATH PATH
#define GDI_OBJ_HMGR_POWNED
Definition: ntgdihdl.h:117
struct _REGION REGION
#define NULL
Definition: types.h:112
struct _SURFACE SURFACE
_In_ ULONG cjSize
Definition: winddi.h:3634
POBJ NTAPI GDIOBJ_AllocateObject(UCHAR objt, ULONG cjSize, FLONG fl)
Definition: gdiobj.c:562
VOID NTAPI GDIOBJ_vFreeObject(POBJ pobj)
Definition: gdiobj.c:596
HGDIOBJ NTAPI GDIOBJ_hInsertObject(POBJ pobj, ULONG ulOwner)
Definition: gdiobj.c:912

Referenced by NtGdiCreateServerMetaFile(), PEN_AllocExtPenWithHandle(), PEN_AllocPenWithHandle(), and SURFACE_AllocSurface().

◆ GDIOBJ_bLockMultipleObjects()

BOOL NTAPI GDIOBJ_bLockMultipleObjects ( ULONG  ulCount,
HGDIOBJ ahObj,
PGDIOBJ apObj,
UCHAR  objt 
)

◆ GDIOBJ_ConvertToStockObj()

BOOL NTAPI GDIOBJ_ConvertToStockObj ( HGDIOBJ hObj)

Definition at line 1455 of file gdiobj.c.

1456 {
1457  PENTRY pentry;
1458  POBJ pobj;
1459 
1460  /* Reference the handle entry */
1461  pentry = ENTRY_ReferenceEntryByHandle(*phObj, 0);
1462  if (!pentry)
1463  {
1464  DPRINT1("GDIOBJ: Requested handle 0x%p is not valid.\n", *phObj);
1465  return FALSE;
1466  }
1467 
1468  /* Update the entry */
1469  pentry->FullUnique |= GDI_ENTRY_STOCK_MASK;
1470  pentry->ObjectOwner.ulObj = 0;
1471 
1472  /* Get the pointer to the BASEOBJECT */
1473  pobj = pentry->einfo.pobj;
1474 
1475  /* Calculate the new handle */
1476  pobj->hHmgr = (HGDIOBJ)((ULONG_PTR)pobj->hHmgr | GDI_HANDLE_STOCK_MASK);
1477 
1478  /* Return the new handle */
1479  *phObj = pobj->hHmgr;
1480 
1481  /* Dereference the handle */
1483 
1484  return TRUE;
1485 }
#define TRUE
Definition: types.h:120
struct _BASEOBJECT * pobj
Definition: ntgdihdl.h:234
VOID NTAPI GDIOBJ_vDereferenceObject(POBJ pobj)
Definition: gdiobj.c:631
#define GDI_ENTRY_STOCK_MASK
Definition: ntgdihdl.h:33
HGDIOBJ hHmgr
Definition: gdiobj.h:40
union _ENTRY::_EINFO einfo
uint32_t ULONG_PTR
Definition: typedefs.h:65
static PENTRY ENTRY_ReferenceEntryByHandle(HGDIOBJ hobj, FLONG fl)
Definition: gdiobj.c:478
#define FALSE
Definition: types.h:117
ULONG ulObj
Definition: ntgdihdl.h:245
void * HGDIOBJ
Definition: windef.h:252
USHORT FullUnique
Definition: ntgdihdl.h:248
#define DPRINT1
Definition: precomp.h:8
union _ENTRY::_OBJECTOWNER ObjectOwner
Definition: ntgdihdl.h:230
#define GDI_HANDLE_STOCK_MASK
Definition: gdi.h:19

Referenced by CreateStockObjects(), and CreateSysColorObjects().

◆ GDIOBJ_hInsertObject()

HGDIOBJ NTAPI GDIOBJ_hInsertObject ( POBJ  pobj,
ULONG  ulOwner 
)

Definition at line 912 of file gdiobj.c.

915 {
916  PENTRY pentry;
917  UCHAR objt;
918 
919  /* Must have no handle and only one reference */
920  ASSERT(GDI_HANDLE_GET_INDEX(pobj->hHmgr) == 0);
921  ASSERT(pobj->cExclusiveLock == 0);
922  ASSERT(pobj->ulShareCount == 1);
923 
924  /* Get a free handle entry */
925  pentry = ENTRY_pentPopFreeEntry();
926  if (!pentry)
927  {
928  DPRINT1("GDIOBJ: Could not get a free entry.\n");
929  return NULL;
930  }
931 
932  /* Make the object exclusively locked */
936  pobj->cExclusiveLock = 1;
939 
940  /* Get object type from the hHmgr field */
941  objt = ((ULONG_PTR)pobj->hHmgr >> 16) & 0xff;
942  ASSERT(objt != GDIObjType_DEF_TYPE);
943 
944  /* Check if current process is requested owner */
945  if (ulOwner == GDI_OBJ_HMGR_POWNED)
946  {
947  /* Increment the process handle count */
949 
950  /* Use Process id */
952  }
953 
954  /* Insert the object into the handle table */
955  pobj->hHmgr = ENTRY_hInsertObject(pentry, pobj, objt, ulOwner);
956 
957  /* Return the handle */
958  DPRINT("GDIOBJ: Created handle: %p\n", pobj->hHmgr);
959  DBG_LOGEVENT(&pobj->slhLog, EVENT_CREATE_HANDLE, 0);
960  return pobj->hHmgr;
961 }
#define GDI_HANDLE_GET_INDEX(h)
Definition: gdi.h:28
FORCEINLINE VOID ExAcquirePushLockExclusive(PEX_PUSH_LOCK PushLock)
Definition: ex.h:1010
ULONG ulShareCount
Definition: gdiobj.h:42
#define HandleToUlong(h)
Definition: basetsd.h:79
DWORD dwThreadId
Definition: gdiobj.h:43
USHORT cExclusiveLock
Definition: gdiobj.h:45
HGDIOBJ hHmgr
Definition: gdiobj.h:40
#define DBG_LOGEVENT(pslh, type, val)
Definition: gdidebug.h:109
EX_PUSH_LOCK pushlock
Definition: gdiobj.h:47
#define ExInitializePushLock
Definition: ex.h:987
PsGetCurrentThreadId
Definition: CrNtStubs.h:7
#define PtrToUlong(u)
Definition: config.h:107
FORCEINLINE void INCREASE_THREAD_LOCK_COUNT(_In_ HANDLE hobj)
Definition: gdiobj.c:63
#define ASSERT(a)
Definition: mode.c:45
static PENTRY ENTRY_pentPopFreeEntry(VOID)
Definition: gdiobj.c:382
FORCEINLINE VOID IncrementCurrentProcessGdiHandleCount(void)
Definition: gdiobj.c:332
unsigned char UCHAR
Definition: xmlstorage.h:181
#define KeEnterCriticalRegion()
Definition: ke_x.h:83
static HGDIOBJ ENTRY_hInsertObject(PENTRY pentry, POBJ pobj, UCHAR objt, ULONG ulOwner)
Definition: gdiobj.c:539
#define GDI_OBJ_HMGR_POWNED
Definition: ntgdihdl.h:117
HANDLE NTAPI PsGetCurrentProcessId(VOID)
Definition: process.c:1123
#define NULL
Definition: types.h:112
#define DPRINT1
Definition: precomp.h:8
#define ULONG_PTR
Definition: config.h:101
Definition: ntgdihdl.h:230
#define DPRINT
Definition: sndvol32.h:71

Referenced by DC_AllocDcWithHandle(), EngCreatePalette(), GDIOBJ_AllocObjWithHandle(), BASEOBJECT::hInsertObject(), NtGdiCreateClientObj(), PALETTE_AllocPalWithHandle(), and REGION_AllocRgnWithHandle().

◆ GDIOBJ_LockObject()

PGDIOBJ NTAPI GDIOBJ_LockObject ( HGDIOBJ  hobj,
UCHAR  objt 
)

Definition at line 826 of file gdiobj.c.

829 {
830  PENTRY pentry;
831  POBJ pobj;
833 
834  /* Check if the handle type matches */
836  if ((((ULONG_PTR)hobj >> 16) & 0x1f) != objt)
837  {
838  DPRINT("Wrong object type: hobj=0x%p, objt=0x%x\n", hobj, objt);
839  return NULL;
840  }
841 
842  /* Make sure lock order is correct */
843  ASSERT_LOCK_ORDER(objt);
844 
845  /* Reference the handle entry */
846  pentry = ENTRY_ReferenceEntryByHandle(hobj, 0);
847  if (!pentry)
848  {
849  DPRINT("GDIOBJ: Requested handle 0x%p is not valid.\n", hobj);
850  return NULL;
851  }
852 
853  /* Get the pointer to the BASEOBJECT */
854  pobj = pentry->einfo.pobj;
855 
856  /* Check if we already own the lock */
858  if (pobj->dwThreadId != dwThreadId)
859  {
860  /* Disable APCs and acquire the push lock */
863 
864  /* Set us as lock owner */
865  ASSERT(pobj->dwThreadId == 0);
866  pobj->dwThreadId = dwThreadId;
867  }
868 
869  /* Increase lock count */
870  pobj->cExclusiveLock++;
872  DBG_LOGEVENT(&pobj->slhLog, EVENT_LOCK, 0);
873 
874  /* Return the object */
875  return pobj;
876 }
FORCEINLINE VOID ExAcquirePushLockExclusive(PEX_PUSH_LOCK PushLock)
Definition: ex.h:1010
struct _BASEOBJECT * pobj
Definition: ntgdihdl.h:234
DWORD dwThreadId
Definition: gdiobj.h:43
USHORT cExclusiveLock
Definition: gdiobj.h:45
union _ENTRY::_EINFO einfo
uint32_t ULONG_PTR
Definition: typedefs.h:65
static PENTRY ENTRY_ReferenceEntryByHandle(HGDIOBJ hobj, FLONG fl)
Definition: gdiobj.c:478
#define DBG_LOGEVENT(pslh, type, val)
Definition: gdidebug.h:109
EX_PUSH_LOCK pushlock
Definition: gdiobj.h:47
PsGetCurrentThreadId
Definition: CrNtStubs.h:7
#define PtrToUlong(u)
Definition: config.h:107
FORCEINLINE void INCREASE_THREAD_LOCK_COUNT(_In_ HANDLE hobj)
Definition: gdiobj.c:63
#define ASSERT(a)
Definition: mode.c:45
unsigned long DWORD
Definition: ntddk_ex.h:95
#define ASSERT_LOCK_ORDER(hobj)
Definition: gdiobj.c:124
DWORD dwThreadId
Definition: fdebug.c:31
#define ASSERT_EXCLUSIVE_OBJECT_TYPE(objt)
Definition: gdiobj.c:126
#define KeEnterCriticalRegion()
Definition: ke_x.h:83
#define NULL
Definition: types.h:112
Definition: ntgdihdl.h:230
#define DPRINT
Definition: sndvol32.h:71

Referenced by DC_LockDc(), GDIOBJ_bLockMultipleObjects(), NtGdiGetServerMetaFileBits(), and REGION_LockRgn().

◆ GDIOBJ_pvGetObjectAttr()

PVOID NTAPI GDIOBJ_pvGetObjectAttr ( POBJ  pobj)

Definition at line 1088 of file gdiobj.c.

1089 {
1091  return gpentHmgr[ulIndex].pUser;
1092 }
#define GDI_HANDLE_GET_INDEX(h)
Definition: gdi.h:28
PVOID pUser
Definition: ntgdihdl.h:251
HGDIOBJ hHmgr
Definition: gdiobj.h:40
PENTRY gpentHmgr
Definition: gdiobj.c:149
ULONG ulIndex
Definition: symbols.c:92
unsigned int ULONG
Definition: retypes.h:1

◆ GDIOBJ_ReferenceObjectByHandle()

POBJ NTAPI GDIOBJ_ReferenceObjectByHandle ( HGDIOBJ  hobj,
UCHAR  objt 
)

Definition at line 691 of file gdiobj.c.

694 {
695  PENTRY pentry;
696  POBJ pobj;
697 
698  /* Check if the handle type matches */
700  if ((((ULONG_PTR)hobj >> 16) & 0x1f) != objt)
701  {
702  DPRINT("GDIOBJ: Wrong type. handle=%p, type=%x\n", hobj, objt);
703  return NULL;
704  }
705 
706  /* Reference the handle entry */
707  pentry = ENTRY_ReferenceEntryByHandle(hobj, 0);
708  if (!pentry)
709  {
710  DPRINT("GDIOBJ: Requested handle 0x%p is not valid.\n", hobj);
711  return NULL;
712  }
713 
714  /* Get the pointer to the BASEOBJECT */
715  pobj = pentry->einfo.pobj;
716 
717  /* Check if the object is exclusively locked */
718  if (pobj->cExclusiveLock != 0)
719  {
720  DPRINT1("GDIOBJ: Cannot reference object %p with exclusive lock.\n", hobj);
722  DBG_DUMP_EVENT_LIST(&pobj->slhLog);
723  return NULL;
724  }
725 
726  DBG_LOGEVENT(&pobj->slhLog, EVENT_REFERENCE, gpaulRefCount[pentry - gpentHmgr]);
727 
728  /* All is well, return the object */
729  return pobj;
730 }
struct _BASEOBJECT * pobj
Definition: ntgdihdl.h:234
VOID NTAPI GDIOBJ_vDereferenceObject(POBJ pobj)
Definition: gdiobj.c:631
USHORT cExclusiveLock
Definition: gdiobj.h:45
union _ENTRY::_EINFO einfo
uint32_t ULONG_PTR
Definition: typedefs.h:65
static PENTRY ENTRY_ReferenceEntryByHandle(HGDIOBJ hobj, FLONG fl)
Definition: gdiobj.c:478
#define DBG_LOGEVENT(pslh, type, val)
Definition: gdidebug.h:109
PULONG gpaulRefCount
Definition: gdiobj.c:150
#define ASSERT_SHARED_OBJECT_TYPE(objt)
Definition: gdiobj.c:125
#define DBG_DUMP_EVENT_LIST(pslh)
Definition: gdidebug.h:111
PENTRY gpentHmgr
Definition: gdiobj.c:149
#define NULL
Definition: types.h:112
#define DPRINT1
Definition: precomp.h:8
Definition: ntgdihdl.h:230
#define DPRINT
Definition: sndvol32.h:71

Referenced by GDIOBJ_ShareLockObj(), GreGetObject(), and PEN_ShareLockPen().

◆ GDIOBJ_ShareLockObj()

PGDIOBJ NTAPI GDIOBJ_ShareLockObj ( HGDIOBJ  hObj,
DWORD  ObjectType 
)

Definition at line 1443 of file gdiobj.c.

1444 {
1445  if (ExpectedType == GDI_OBJECT_TYPE_DONTCARE)
1446  ExpectedType = GDI_HANDLE_GET_TYPE(hObj);
1447  return GDIOBJ_ReferenceObjectByHandle(hObj, (ExpectedType >> 16) & 0x1f);
1448 }
POBJ NTAPI GDIOBJ_ReferenceObjectByHandle(HGDIOBJ hobj, UCHAR objt)
Definition: gdiobj.c:691
#define GDI_HANDLE_GET_TYPE(h)
Definition: gdi.h:31
#define GDI_OBJECT_TYPE_DONTCARE
Definition: gdi.h:64

Referenced by BASEOBJECT::LockShared().

◆ GDIOBJ_TryLockObject()

PGDIOBJ NTAPI GDIOBJ_TryLockObject ( HGDIOBJ  hobj,
UCHAR  objt 
)

Definition at line 757 of file gdiobj.c.

760 {
761  PENTRY pentry;
762  POBJ pobj;
764 
765  /* Check if the handle type matches */
767  if ((((ULONG_PTR)hobj >> 16) & 0x1f) != objt)
768  {
769  DPRINT("Wrong object type: hobj=0x%p, objt=0x%x\n", hobj, objt);
770  return NULL;
771  }
772 
773  /* Make sure lock order is correct */
774  ASSERT_LOCK_ORDER(objt);
775 
776  /* Reference the handle entry */
777  pentry = ENTRY_ReferenceEntryByHandle(hobj, 0);
778  if (!pentry)
779  {
780  DPRINT("GDIOBJ: Requested handle 0x%p is not valid.\n", hobj);
781  return NULL;
782  }
783 
784  /* Get the pointer to the BASEOBJECT */
785  pobj = pentry->einfo.pobj;
786 
787  /* Check if we already own the lock */
789  if (pobj->dwThreadId != dwThreadId)
790  {
791  /* Disable APCs and try acquiring the push lock */
794  {
795  ULONG cRefs, ulIndex;
796  /* Already owned. Clean up and leave. */
798 
799  /* Calculate the index */
801 
802  /* Decrement reference count */
805  ASSERT(cRefs & REF_MASK_VALID);
806 
807  return NULL;
808  }
809 
810  /* Set us as lock owner */
811  ASSERT(pobj->dwThreadId == 0);
812  pobj->dwThreadId = dwThreadId;
813  }
814 
815  /* Increase lock count */
816  pobj->cExclusiveLock++;
818  DBG_LOGEVENT(&pobj->slhLog, EVENT_LOCK, 0);
819 
820  /* Return the object */
821  return pobj;
822 }
#define GDI_HANDLE_GET_INDEX(h)
Definition: gdi.h:28
#define ASSERT_TRYLOCK_OBJECT_TYPE(objt)
Definition: gdiobj.c:127
struct _BASEOBJECT * pobj
Definition: ntgdihdl.h:234
DWORD dwThreadId
Definition: gdiobj.h:43
USHORT cExclusiveLock
Definition: gdiobj.h:45
HGDIOBJ hHmgr
Definition: gdiobj.h:40
union _ENTRY::_EINFO einfo
uint32_t ULONG_PTR
Definition: typedefs.h:65
static PENTRY ENTRY_ReferenceEntryByHandle(HGDIOBJ hobj, FLONG fl)
Definition: gdiobj.c:478
long LONG
Definition: pedump.c:60
#define DBG_LOGEVENT(pslh, type, val)
Definition: gdidebug.h:109
PULONG gpaulRefCount
Definition: gdiobj.c:150
EX_PUSH_LOCK pushlock
Definition: gdiobj.h:47
PsGetCurrentThreadId
Definition: CrNtStubs.h:7
#define PtrToUlong(u)
Definition: config.h:107
FORCEINLINE void INCREASE_THREAD_LOCK_COUNT(_In_ HANDLE hobj)
Definition: gdiobj.c:63
#define ASSERT(a)
Definition: mode.c:45
unsigned long DWORD
Definition: ntddk_ex.h:95
#define ASSERT_LOCK_ORDER(hobj)
Definition: gdiobj.c:124
DWORD dwThreadId
Definition: fdebug.c:31
#define InterlockedDecrement
Definition: armddk.h:52
#define KeEnterCriticalRegion()
Definition: ke_x.h:83
ULONG ulIndex
Definition: symbols.c:92
#define KeLeaveCriticalRegion()
Definition: ke_x.h:114
#define NULL
Definition: types.h:112
unsigned int ULONG
Definition: retypes.h:1
Definition: ntgdihdl.h:230
#define DPRINT
Definition: sndvol32.h:71
FORCEINLINE BOOLEAN ExTryAcquirePushLockExclusive(PEX_PUSH_LOCK PushLock)
Definition: misc.h:98

Referenced by DRIVEROBJ_TryLockObject().

◆ GDIOBJ_vDeleteObject()

VOID NTAPI GDIOBJ_vDeleteObject ( POBJ  pobj)

Definition at line 1111 of file gdiobj.c.

1112 {
1113  ULONG ulIndex;
1114 
1115  /* Set the object's delete flag */
1117  DBG_LOGEVENT(&pobj->slhLog, EVENT_DELETE, 0);
1118 
1119  /* Get the handle index */
1121  if (ulIndex)
1122  {
1123  /* Reset the handle valid bit */
1125 
1126  /* Check if the object is exclusively locked */
1127  if (pobj->cExclusiveLock != 0)
1128  {
1129  /* Reset lock owner and lock count */
1130  pobj->dwThreadId = 0;
1131  pobj->cExclusiveLock = 0;
1132 
1133  /* Release the pushlock and reenable APCs */
1137  }
1138  }
1139 
1140  /* Dereference the object (will take care of deletion) */
1142 }
#define GDI_HANDLE_GET_INDEX(h)
Definition: gdi.h:28
#define InterlockedAnd
Definition: interlocked.h:62
DWORD dwThreadId
Definition: gdiobj.h:43
VOID NTAPI GDIOBJ_vDereferenceObject(POBJ pobj)
Definition: gdiobj.c:631
USHORT cExclusiveLock
Definition: gdiobj.h:45
HGDIOBJ hHmgr
Definition: gdiobj.h:40
USHORT BaseFlags
Definition: gdiobj.h:46
long LONG
Definition: pedump.c:60
#define DBG_LOGEVENT(pslh, type, val)
Definition: gdidebug.h:109
short SHORT
Definition: pedump.c:59
FORCEINLINE void DECREASE_THREAD_LOCK_COUNT(_In_ HANDLE hobj)
Definition: gdiobj.c:79
FORCEINLINE VOID ExReleasePushLockExclusive(PEX_PUSH_LOCK PushLock)
Definition: ex.h:1226
PULONG gpaulRefCount
Definition: gdiobj.c:150
EX_PUSH_LOCK pushlock
Definition: gdiobj.h:47
ULONG ulIndex
Definition: symbols.c:92
#define KeLeaveCriticalRegion()
Definition: ke_x.h:114
unsigned int ULONG
Definition: retypes.h:1
#define InterlockedOr16
Definition: interlocked.h:239

Referenced by EngDeleteDriverObj(), EngDeletePalette(), EngDeletePath(), EngDeleteSurface(), GDI_CleanupForProcess(), GreDeleteObject(), IntEngMaskBlt(), IntGdiExtCreatePen(), NtGdiCreateBitmap(), NtGdiCreatePaletteInternal(), NtGdiCreateServerMetaFile(), NtGdiGetPixel(), PATH_Delete(), REGION_AllocRgnWithHandle(), REGION_Delete(), SURFACE_AllocSurface(), and UserDrawIconEx().

◆ GDIOBJ_vDereferenceObject()

VOID NTAPI GDIOBJ_vDereferenceObject ( POBJ  pobj)

Definition at line 631 of file gdiobj.c.

632 {
633  ULONG cRefs, ulIndex;
634 
635  /* Calculate the index */
637 
638  /* Check if the object has a handle */
639  if (ulIndex)
640  {
641  /* Decrement reference count */
642  if ((gpaulRefCount[ulIndex] & REF_MASK_COUNT) == 0)
643  {
644  DBG_DUMP_EVENT_LIST(&pobj->slhLog);
645  }
648  DBG_LOGEVENT(&pobj->slhLog, EVENT_DEREFERENCE, cRefs);
649 
650  /* Check if we reached 0 and handle bit is not set */
651  if ((cRefs & REF_MASK_INUSE) == 0)
652  {
653  /* Make sure it's ok to delete the object */
655 
656  /* Check if the handle was process owned */
657  if (gpentHmgr[ulIndex].ObjectOwner.ulObj != GDI_OBJ_HMGR_PUBLIC &&
659  {
660  /* Decrement the process handle count */
661  ASSERT(gpentHmgr[ulIndex].ObjectOwner.ulObj ==
664  }
665 
666  /* Push entry to the free list */
668 
669  /* Free the object */
670  GDIOBJ_vFreeObject(pobj);
671  }
672  }
673  else
674  {
675  /* Decrement the objects reference count */
676  ASSERT(pobj->ulShareCount > 0);
677  cRefs = InterlockedDecrement((LONG*)&pobj->ulShareCount);
678  DBG_LOGEVENT(&pobj->slhLog, EVENT_DEREFERENCE, cRefs);
679 
680  /* Check if we reached 0 */
681  if (cRefs == 0)
682  {
683  /* Free the object */
684  GDIOBJ_vFreeObject(pobj);
685  }
686  }
687 }
#define GDI_HANDLE_GET_INDEX(h)
Definition: gdi.h:28
ULONG ulShareCount
Definition: gdiobj.h:42
#define HandleToUlong(h)
Definition: basetsd.h:79
HGDIOBJ hHmgr
Definition: gdiobj.h:40
FORCEINLINE VOID DecrementCurrentProcessGdiHandleCount(void)
Definition: gdiobj.c:340
USHORT BaseFlags
Definition: gdiobj.h:46
static VOID ENTRY_vPushFreeEntry(PENTRY pentFree)
Definition: gdiobj.c:439
long LONG
Definition: pedump.c:60
#define DBG_LOGEVENT(pslh, type, val)
Definition: gdidebug.h:109
PULONG gpaulRefCount
Definition: gdiobj.c:150
#define ASSERT(a)
Definition: mode.c:45
ULONG ulObj
Definition: ntgdihdl.h:245
#define DBG_DUMP_EVENT_LIST(pslh)
Definition: gdidebug.h:111
#define InterlockedDecrement
Definition: armddk.h:52
PENTRY gpentHmgr
Definition: gdiobj.c:149
ULONG ulIndex
Definition: symbols.c:92
#define GDI_OBJ_HMGR_PUBLIC
Definition: ntgdihdl.h:116
HANDLE NTAPI PsGetCurrentProcessId(VOID)
Definition: process.c:1123
#define GDI_OBJ_HMGR_NONE
Definition: ntgdihdl.h:118
unsigned int ULONG
Definition: retypes.h:1
union _ENTRY::_OBJECTOWNER ObjectOwner
VOID NTAPI GDIOBJ_vFreeObject(POBJ pobj)
Definition: gdiobj.c:596

Referenced by GDIOBJ_ConvertToStockObj(), GDIOBJ_ReferenceObjectByHandle(), GDIOBJ_vDeleteObject(), GreDeleteObject(), GreGetObject(), GreIsHandleValid(), GreSetObjectOwnerEx(), NtGdiSetColorSpace(), SURFACE_vSetPalette(), and BASEOBJECT::vUnlock().

◆ GDIOBJ_vFreeObject()

VOID NTAPI GDIOBJ_vFreeObject ( POBJ  pobj)

Definition at line 596 of file gdiobj.c.

597 {
598  UCHAR objt;
599 
600  DBG_CLEANUP_EVENT_LIST(&pobj->slhLog);
601 
602  /* Get the object type */
603  objt = ((ULONG_PTR)pobj->hHmgr >> 16) & 0x1f;
604 
605  /* Check if we have a delete procedure (for C++ based objects) */
606  if (apfnDelete[objt] != NULL)
607  {
608  /* Invoke the delete procedure */
609  apfnDelete[objt](pobj);
610  }
611  else
612  {
613  /* Call the cleanup procedure */
614  NT_ASSERT(apfnCleanup[objt]);
615  apfnCleanup[objt](pobj);
616 
617  /* Check if the object is allocated from a lookaside list */
618  if (pobj->BaseFlags & BASEFLAG_LOOKASIDE)
619  {
620  ExFreeToPagedLookasideList(&gpaLookasideList[objt], pobj);
621  }
622  else
623  {
624  ExFreePoolWithTag(pobj, GDIOBJ_POOL_TAG(objt));
625  }
626  }
627 }
static PPAGED_LOOKASIDE_LIST gpaLookasideList
Definition: gdiobj.c:153
HGDIOBJ hHmgr
Definition: gdiobj.h:40
USHORT BaseFlags
Definition: gdiobj.h:46
#define GDIOBJ_POOL_TAG(type)
Definition: gdiobj.c:134
static const GDIOBJDELETEPROC apfnDelete[]
Definition: gdiobj.c:197
unsigned char UCHAR
Definition: xmlstorage.h:181
#define NULL
Definition: types.h:112
#define DBG_CLEANUP_EVENT_LIST(pslh)
Definition: gdidebug.h:112
#define ULONG_PTR
Definition: config.h:101
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1099
static const GDICLEANUPPROC apfnCleanup[]
Definition: gdiobj.c:159
#define NT_ASSERT
Definition: rtlfuncs.h:3312

Referenced by DC_AllocDcWithHandle(), EngCreatePalette(), GDIOBJ_AllocObjWithHandle(), GDIOBJ_vDereferenceObject(), NtGdiCreateClientObj(), PALETTE_AllocPalWithHandle(), and REGION_AllocRgnWithHandle().

◆ GDIOBJ_vReferenceObjectByPointer()

VOID NTAPI GDIOBJ_vReferenceObjectByPointer ( POBJ  pobj)

Definition at line 734 of file gdiobj.c.

735 {
736  ULONG cRefs;
737 
738  /* Check if the object has a handle */
739  if (GDI_HANDLE_GET_INDEX(pobj->hHmgr))
740  {
741  /* Increase the handle's reference count */
745  }
746  else
747  {
748  /* Increase the object's reference count */
749  cRefs = InterlockedIncrement((LONG*)&pobj->ulShareCount);
750  }
751 
752  DBG_LOGEVENT(&pobj->slhLog, EVENT_REFERENCE, cRefs);
753 }
#define GDI_HANDLE_GET_INDEX(h)
Definition: gdi.h:28
ULONG ulShareCount
Definition: gdiobj.h:42
HGDIOBJ hHmgr
Definition: gdiobj.h:40
long LONG
Definition: pedump.c:60
#define DBG_LOGEVENT(pslh, type, val)
Definition: gdidebug.h:109
PULONG gpaulRefCount
Definition: gdiobj.c:150
#define ASSERT(a)
Definition: mode.c:45
ULONG ulIndex
Definition: symbols.c:92
#define InterlockedIncrement
Definition: armddk.h:53
unsigned int ULONG
Definition: retypes.h:1

Referenced by DC_vCopyState(), DC_vSelectFillBrush(), DC_vSelectLineBrush(), DC_vSelectPalette(), DC_vSelectSurface(), EBRUSHOBJ_vInit(), InitPaletteImpl(), PDEVOBJ_pSurface(), SURFACE_ShareLockByPointer(), and SURFACE_vSetPalette().

◆ GDIOBJ_vSetObjectAttr()

VOID NTAPI GDIOBJ_vSetObjectAttr ( POBJ  pobj,
PVOID  pvObjAttr 
)

Definition at line 1096 of file gdiobj.c.

1097 {
1098  ULONG ulIndex;
1099 
1100  ASSERT(pobj->hHmgr);
1101 
1102  /* Get the handle index */
1104 
1105  /* Set pointer to the usermode attribute */
1106  gpentHmgr[ulIndex].pUser = pvObjAttr;
1107 }
#define GDI_HANDLE_GET_INDEX(h)
Definition: gdi.h:28
PVOID pUser
Definition: ntgdihdl.h:251
HGDIOBJ hHmgr
Definition: gdiobj.h:40
#define ASSERT(a)
Definition: mode.c:45
PENTRY gpentHmgr
Definition: gdiobj.c:149
ULONG ulIndex
Definition: symbols.c:92
unsigned int ULONG
Definition: retypes.h:1

Referenced by DC_bAllocDcAttr(), DC_vFreeDcAttr(), IntGdiSetRegionOwner(), REGION_bAllocRgnAttr(), and BASEOBJECT::vSetObjectAttr().

◆ GDIOBJ_vSetObjectOwner()

VOID NTAPI GDIOBJ_vSetObjectOwner ( POBJ  pobj,
ULONG  ulOwner 
)

Definition at line 965 of file gdiobj.c.

968 {
969  PENTRY pentry;
970  ULONG ulOldOwner;
971 
972  /* This is a ugly HACK, needed to fix IntGdiSetDCOwnerEx */
973  if (GDI_HANDLE_IS_STOCKOBJ(pobj->hHmgr))
974  {
975  DPRINT("Trying to set ownership of stock object %p to %lx\n", pobj->hHmgr, ulNewOwner);
976  return;
977  }
978 
979  /* Get the handle entry */
981  pentry = &gpentHmgr[GDI_HANDLE_GET_INDEX(pobj->hHmgr)];
982 
983  /* Check if the new owner is the same as the old one */
984  ulOldOwner = pentry->ObjectOwner.ulObj;
985  if (ulOldOwner == ulNewOwner)
986  {
987  /* Nothing to do */
988  return;
989  }
990 
991  /* Is the current process requested? */
992  if (ulNewOwner == GDI_OBJ_HMGR_POWNED)
993  {
994  /* Use process id */
995  ulNewOwner = HandleToUlong(PsGetCurrentProcessId());
996  }
997 
998  // HACK
999  if (ulNewOwner == GDI_OBJ_HMGR_NONE)
1000  ulNewOwner = GDI_OBJ_HMGR_PUBLIC;
1001 
1002  /* Was the object process owned? */
1003  if ((ulOldOwner != GDI_OBJ_HMGR_PUBLIC) &&
1004  (ulOldOwner != GDI_OBJ_HMGR_NONE))
1005  {
1006  /* Decrement the previous owners handle count */
1007  DecrementGdiHandleCount(ulOldOwner);
1008  }
1009 
1010  /* Is the new owner a process? */
1011  if ((ulNewOwner != GDI_OBJ_HMGR_PUBLIC) &&
1012  (ulNewOwner != GDI_OBJ_HMGR_NONE))
1013  {
1014  /* Increment the new owners handle count */
1015  IncrementGdiHandleCount(ulNewOwner);
1016  }
1017  else
1018  {
1019  /* Make sure we don't leak user mode memory */
1020  NT_ASSERT(pentry->pUser == NULL);
1021  }
1022 
1023  /* Set new owner */
1024  pentry->ObjectOwner.ulObj = ulNewOwner;
1025  DBG_LOGEVENT(&pobj->slhLog, EVENT_SET_OWNER, 0);
1026 }
#define GDI_HANDLE_GET_INDEX(h)
Definition: gdi.h:28
PVOID pUser
Definition: ntgdihdl.h:251
static VOID DecrementGdiHandleCount(ULONG ulProcessId)
Definition: gdiobj.c:365
#define HandleToUlong(h)
Definition: basetsd.h:79
HGDIOBJ hHmgr
Definition: gdiobj.h:40
#define DBG_LOGEVENT(pslh, type, val)
Definition: gdidebug.h:109
#define GDI_HANDLE_IS_STOCKOBJ(h)
Definition: gdi.h:37
ULONG ulObj
Definition: ntgdihdl.h:245
#define GDI_OBJ_HMGR_POWNED
Definition: ntgdihdl.h:117
PENTRY gpentHmgr
Definition: gdiobj.c:149
#define GDI_OBJ_HMGR_PUBLIC
Definition: ntgdihdl.h:116
HANDLE NTAPI PsGetCurrentProcessId(VOID)
Definition: process.c:1123
#define NULL
Definition: types.h:112
static VOID IncrementGdiHandleCount(ULONG ulProcessId)
Definition: gdiobj.c:348
#define GDI_OBJ_HMGR_NONE
Definition: ntgdihdl.h:118
unsigned int ULONG
Definition: retypes.h:1
union _ENTRY::_OBJECTOWNER ObjectOwner
Definition: ntgdihdl.h:230
#define DPRINT
Definition: sndvol32.h:71
#define NT_ASSERT
Definition: rtlfuncs.h:3312

Referenced by DC_vSetOwner(), EngCreateBitmap(), EngCreateDeviceBitmap(), EngCreateDeviceSurface(), GreSetObjectOwnerEx(), NtGdiCreateServerMetaFile(), and NtGdiSaveDC().

◆ GDIOBJ_vUnlockObject()

VOID NTAPI GDIOBJ_vUnlockObject ( POBJ  pobj)

Definition at line 880 of file gdiobj.c.

881 {
882  ULONG cRefs, ulIndex;
883  ASSERT(pobj->cExclusiveLock > 0);
884 
885  /* Decrease lock count */
886  pobj->cExclusiveLock--;
888  DBG_LOGEVENT(&pobj->slhLog, EVENT_UNLOCK, 0);
889 
890  /* Check if this was the last lock */
891  if (pobj->cExclusiveLock == 0)
892  {
893  /* Reset lock owner */
894  pobj->dwThreadId = 0;
895 
896  /* Release the pushlock and reenable APCs */
899  }
900 
901  /* Calculate the index */
903 
904  /* Decrement reference count */
907  ASSERT(cRefs & REF_MASK_VALID);
908 }
#define GDI_HANDLE_GET_INDEX(h)
Definition: gdi.h:28
DWORD dwThreadId
Definition: gdiobj.h:43
USHORT cExclusiveLock
Definition: gdiobj.h:45
HGDIOBJ hHmgr
Definition: gdiobj.h:40
long LONG
Definition: pedump.c:60
#define DBG_LOGEVENT(pslh, type, val)
Definition: gdidebug.h:109
FORCEINLINE void DECREASE_THREAD_LOCK_COUNT(_In_ HANDLE hobj)
Definition: gdiobj.c:79
FORCEINLINE VOID ExReleasePushLockExclusive(PEX_PUSH_LOCK PushLock)
Definition: ex.h:1226
PULONG gpaulRefCount
Definition: gdiobj.c:150
EX_PUSH_LOCK pushlock
Definition: gdiobj.h:47
#define ASSERT(a)
Definition: mode.c:45
#define InterlockedDecrement
Definition: armddk.h:52
ULONG ulIndex
Definition: symbols.c:92
#define KeLeaveCriticalRegion()
Definition: ke_x.h:114
unsigned int ULONG
Definition: retypes.h:1

Referenced by DC_UnlockDc(), GDIOBJ_bLockMultipleObjects(), GreStretchBltMask(), NtGdiAlphaBlend(), NtGdiCreateClientObj(), NtGdiCreateServerMetaFile(), NtGdiGetServerMetaFileBits(), NtGdiTransparentBlt(), PATH_CreatePath(), REGION_UnlockRgn(), and BASEOBJECT::vUnlock().

◆ GreDeleteObject()

BOOL NTAPI GreDeleteObject ( HGDIOBJ  hObject)

Definition at line 1158 of file gdiobj.c.

1159 {
1160  PENTRY pentry;
1161 
1162  /* Check for stock objects */
1163  if (GDI_HANDLE_IS_STOCKOBJ(hobj))
1164  {
1165  DPRINT1("GreDeleteObject: Cannot delete stock object %p.\n", hobj);
1166  return FALSE;
1167  }
1168 
1169  /* Reference the handle entry */
1170  pentry = ENTRY_ReferenceEntryByHandle(hobj, 0);
1171  if (!pentry)
1172  {
1173  DPRINT1("GreDeleteObject: Trying to delete invalid object %p\n", hobj);
1174  return FALSE;
1175  }
1176 
1177  /* Check for public owner */
1178  if (pentry->ObjectOwner.ulObj == GDI_OBJ_HMGR_PUBLIC)
1179  {
1180  DPRINT1("GreDeleteObject: Trying to delete global object %p\n", hobj);
1182  return FALSE;
1183  }
1184 
1185  /* Delete the object */
1186  GDIOBJ_vDeleteObject(pentry->einfo.pobj);
1187  return TRUE;
1188 }
#define TRUE
Definition: types.h:120
struct _BASEOBJECT * pobj
Definition: ntgdihdl.h:234
VOID NTAPI GDIOBJ_vDereferenceObject(POBJ pobj)
Definition: gdiobj.c:631
union _ENTRY::_EINFO einfo
static PENTRY ENTRY_ReferenceEntryByHandle(HGDIOBJ hobj, FLONG fl)
Definition: gdiobj.c:478
#define FALSE
Definition: types.h:117
#define GDI_HANDLE_IS_STOCKOBJ(h)
Definition: gdi.h:37
VOID NTAPI GDIOBJ_vDeleteObject(POBJ pobj)
Definition: gdiobj.c:1111
ULONG ulObj
Definition: ntgdihdl.h:245
#define GDI_OBJ_HMGR_PUBLIC
Definition: ntgdihdl.h:116
#define DPRINT1
Definition: precomp.h:8
union _ENTRY::_OBJECTOWNER ObjectOwner
Definition: ntgdihdl.h:230

Referenced by BITMAP_CopyBitmap(), co_IntDrawCaret(), co_IntPaintWindows(), co_UserExcludeUpdateRgn(), co_UserFreeWindow(), co_UserGetUpdateRgn(), co_WinPosSetWindowPos(), CreateBrushInternal(), DC_vRestoreDC(), DceDeleteClipRgn(), DceFreeDCE(), DefWndDoSizeMove(), DIB_CreateDIBSection(), DrawTextExWorker(), ForceNCPaintErase(), FreeCurIconObject(), GdiFlushUserBatch(), GreGetDIBitsInternal(), IntBeginPaint(), IntDefWindowProc(), IntDestroyMonitorObject(), IntEndDesktopGraphics(), IntFreeElementData(), IntGdiCreateMaskFromRLE(), IntGdiDeleteColorSpace(), IntGdiDeleteDC(), IntGetNCUpdateRgn(), IntInvalidateWindows(), IntPaintDesktop(), IntSetDIBits(), IntUpdateLayeredWindowI(), MENU_DrawPopupGlyph(), MenuInit(), NC_HandleNCActivate(), NtGdiDeleteClientObj(), NtGdiDeleteObjectApp(), NtGdiExtCreateRegion(), NtGdiFrameRgn(), NtGdiStretchDIBitsInternal(), PaintSuspendedWindow(), REGION_XorRegion(), SelectWindowRgn(), SnapWindow(), SpiSetWallpaper(), TEXT_DrawUnderscore(), UITOOLS95_DFC_ButtonCheckRadio(), UITOOLS95_DrawFrameCaption(), UITOOLS95_DrawFrameMenu(), UITOOLS95_DrawFrameScroll(), UserDrawCaptionText(), UserGetDCEx(), UserUpdateMonitorSize(), and BRUSH::~BRUSH().

◆ GreGetObject()

INT NTAPI GreGetObject ( IN HGDIOBJ  hobj,
IN INT  cbCount,
OUT PVOID  pvBuffer 
)

Definition at line 1264 of file gdiobj.c.

1268 {
1269  PVOID pvObj;
1270  UCHAR objt;
1271  INT iResult = 0;
1272 
1273  /* Verify object type */
1274  objt = ((ULONG_PTR)hobj >> 16) & 0x1f;
1275  if (objt != GDIObjType_BRUSH_TYPE &&
1276  objt != GDIObjType_SURF_TYPE &&
1277  objt != GDIObjType_LFONT_TYPE &&
1278  objt != GDIObjType_PAL_TYPE)
1279  {
1280  DPRINT1("GreGetObject: Invalid object type\n");
1281  return 0;
1282  }
1283 
1284  pvObj = GDIOBJ_ReferenceObjectByHandle(hobj, objt);
1285  if (!pvObj)
1286  {
1287  DPRINT("GreGetObject: Could not lock object\n");
1288  return 0;
1289  }
1290 
1291  switch (GDI_HANDLE_GET_TYPE(hobj))
1292  {
1295  iResult = PEN_GetObject(pvObj, cbCount, pvBuffer);
1296  break;
1297 
1299  iResult = BRUSH_GetObject(pvObj, cbCount, pvBuffer);
1300  break;
1301 
1303  iResult = BITMAP_GetObject(pvObj, cbCount, pvBuffer);
1304  break;
1305 
1307  iResult = FontGetObject(pvObj, cbCount, pvBuffer);
1308  break;
1309 
1311  iResult = PALETTE_GetObject(pvObj, cbCount, pvBuffer);
1312  break;
1313 
1314  default:
1315  DPRINT1("GDI object type of 0x%p not implemented\n", hobj);
1316  break;
1317  }
1318 
1320  return iResult;
1321 }
POBJ NTAPI GDIOBJ_ReferenceObjectByHandle(HGDIOBJ hobj, UCHAR objt)
Definition: gdiobj.c:691
static int cbCount
Definition: fiber.c:42
INT APIENTRY BITMAP_GetObject(SURFACE *psurf, INT Count, LPVOID buffer)
Definition: bitmaps.c:766
INT FASTCALL BRUSH_GetObject(PBRUSH pbr, INT cjBuffer, LPLOGBRUSH plbBuffer)
Definition: brush.cpp:260
VOID NTAPI GDIOBJ_vDereferenceObject(POBJ pobj)
Definition: gdiobj.c:631
int32_t INT
Definition: typedefs.h:58
INT FASTCALL PALETTE_GetObject(PPALETTE ppal, INT cbCount, LPLOGBRUSH lpBuffer)
Definition: palette.c:247
#define GDI_HANDLE_GET_TYPE(h)
Definition: gdi.h:31
unsigned char UCHAR
Definition: xmlstorage.h:181
INT APIENTRY PEN_GetObject(PBRUSH pbrushPen, INT cbCount, PLOGPEN pBuffer)
Definition: pen.c:255
#define DPRINT1
Definition: precomp.h:8
ULONG FASTCALL FontGetObject(PTEXTOBJ plfont, ULONG cjBuffer, PVOID pvBuffer)
Definition: font.c:293
#define ULONG_PTR
Definition: config.h:101
#define DPRINT
Definition: sndvol32.h:71

Referenced by IntTMWFixUp(), IntUpdateLayeredWindowI(), MENU_DrawBitmapItem(), MENU_GetBitmapItemSize(), NtGdiExtGetObjectW(), and PATH_WidenPath().

◆ GreGetObjectOwner()

ULONG NTAPI GreGetObjectOwner ( HGDIOBJ  hobj)

Definition at line 1192 of file gdiobj.c.

1193 {
1194  ULONG ulIndex, ulOwner;
1195 
1196  /* Get the handle index */
1197  ulIndex = GDI_HANDLE_GET_INDEX(hobj);
1198 
1199  /* Check if the handle is valid */
1200  if (ulIndex >= GDI_HANDLE_COUNT ||
1202  ((ULONG_PTR)hobj >> 16) != gpentHmgr[ulIndex].FullUnique)
1203  {
1204  DPRINT1("GreGetObjectOwner: invalid handle 0x%p.\n", hobj);
1205  return GDI_OBJ_HMGR_RESTRICTED;
1206  }
1207 
1208  /* Get the object owner */
1209  ulOwner = gpentHmgr[ulIndex].ObjectOwner.ulObj;
1210 
1211  if (ulOwner == HandleToUlong(PsGetCurrentProcessId()))
1212  return GDI_OBJ_HMGR_POWNED;
1213 
1214  if (ulOwner == GDI_OBJ_HMGR_PUBLIC)
1215  return GDI_OBJ_HMGR_PUBLIC;
1216 
1217  return GDI_OBJ_HMGR_RESTRICTED;
1218 }
#define GDI_HANDLE_GET_INDEX(h)
Definition: gdi.h:28
#define GDI_OBJ_HMGR_RESTRICTED
Definition: ntgdihdl.h:119
#define HandleToUlong(h)
Definition: basetsd.h:79
uint32_t ULONG_PTR
Definition: typedefs.h:65
ULONG ulObj
Definition: ntgdihdl.h:245
#define GDI_OBJ_HMGR_POWNED
Definition: ntgdihdl.h:117
PENTRY gpentHmgr
Definition: gdiobj.c:149
ULONG ulIndex
Definition: symbols.c:92
#define GDI_HANDLE_COUNT
Definition: gdi.h:12
#define GDI_OBJ_HMGR_PUBLIC
Definition: ntgdihdl.h:116
HANDLE NTAPI PsGetCurrentProcessId(VOID)
Definition: process.c:1123
#define DPRINT1
Definition: precomp.h:8
unsigned int ULONG
Definition: retypes.h:1
union _ENTRY::_OBJECTOWNER ObjectOwner

Referenced by DceFreeDCE(), GreSetBitmapOwner(), NtGdiDeleteObjectApp(), REGION_UnlockRgn(), and REGION_vSyncRegion().

◆ GreIsHandleValid()

BOOL NTAPI GreIsHandleValid ( HGDIOBJ  hobj)

Definition at line 1146 of file gdiobj.c.

1147 {
1148  PENTRY pentry;
1149 
1150  pentry = ENTRY_ReferenceEntryByHandle(hobj, 0);
1151  if (!pentry) return FALSE;
1153  return TRUE;
1154 }
#define TRUE
Definition: types.h:120
struct _BASEOBJECT * pobj
Definition: ntgdihdl.h:234
VOID NTAPI GDIOBJ_vDereferenceObject(POBJ pobj)
Definition: gdiobj.c:631
union _ENTRY::_EINFO einfo
static PENTRY ENTRY_ReferenceEntryByHandle(HGDIOBJ hobj, FLONG fl)
Definition: gdiobj.c:478
#define FALSE
Definition: types.h:117
Definition: ntgdihdl.h:230

Referenced by co_IntPaintWindows(), co_UserFreeWindow(), DceFreeDCE(), DceResetActiveDCEs(), GetControlColor(), IntBeginPaint(), IntGdiDeleteDC(), NC_HandleNCActivate(), NtGdiEqualRgn(), NtGdiFlushUserBatch(), NtUserSetWindowRgn(), PaintSuspendedWindow(), UserGetDCEx(), and BRUSH::~BRUSH().

◆ GreSetObjectOwner()

BOOL NTAPI GreSetObjectOwner ( HGDIOBJ  hobj,
ULONG  ulOwner 
)

◆ GreSetObjectOwnerEx()

BOOL NTAPI GreSetObjectOwnerEx ( HGDIOBJ  hobj,
ULONG  ulOwner,
ULONG  Flags 
)

Definition at line 1222 of file gdiobj.c.

1226 {
1227  PENTRY pentry;
1228 
1229  /* Check for stock objects */
1230  if (GDI_HANDLE_IS_STOCKOBJ(hobj))
1231  {
1232  DPRINT("GreSetObjectOwner: Got stock object %p\n", hobj);
1233  return FALSE;
1234  }
1235 
1236  /* Reference the handle entry */
1237  pentry = ENTRY_ReferenceEntryByHandle(hobj, Flags);
1238  if (!pentry)
1239  {
1240  DPRINT("GreSetObjectOwner: Invalid handle 0x%p.\n", hobj);
1241  return FALSE;
1242  }
1243 
1244  /* Call internal function */
1245  GDIOBJ_vSetObjectOwner(pentry->einfo.pobj, ulOwner);
1246 
1247  /* Dereference the object */
1249 
1250  return TRUE;
1251 }
#define TRUE
Definition: types.h:120
struct _BASEOBJECT * pobj
Definition: ntgdihdl.h:234
VOID NTAPI GDIOBJ_vDereferenceObject(POBJ pobj)
Definition: gdiobj.c:631
union _ENTRY::_EINFO einfo
static PENTRY ENTRY_ReferenceEntryByHandle(HGDIOBJ hobj, FLONG fl)
Definition: gdiobj.c:478
#define FALSE
Definition: types.h:117
#define GDI_HANDLE_IS_STOCKOBJ(h)
Definition: gdi.h:37
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170
VOID NTAPI GDIOBJ_vSetObjectOwner(POBJ pobj, ULONG ulNewOwner)
Definition: gdiobj.c:965
Definition: ntgdihdl.h:230
#define DPRINT
Definition: sndvol32.h:71

Referenced by GreSetObjectOwner(), and NtUserConsoleControl().

◆ InitGdiHandleTable()

NTSTATUS NTAPI InitGdiHandleTable ( VOID  )

Definition at line 259 of file gdiobj.c.

260 {
262  LARGE_INTEGER liSize;
263  PVOID pvSection;
264  SIZE_T cjViewSize = 0;
265 
266  /* Create a section for the shared handle table */
267  liSize.QuadPart = sizeof(GDI_HANDLE_TABLE); // GDI_HANDLE_COUNT * sizeof(ENTRY);
270  NULL,
271  &liSize,
273  SEC_COMMIT | 0x1,
274  NULL,
275  NULL);
276  if (!NT_SUCCESS(status))
277  {
278  DPRINT1("INITGDI: Could not allocate a GDI handle table.\n");
279  return status;
280  }
281 
282  /* Map the section in session space */
284  (PVOID*)&gpentHmgr,
285  &cjViewSize);
286  if (!NT_SUCCESS(status))
287  {
288  DPRINT1("INITGDI: Failed to map handle table section\n");
290  return status;
291  }
292 
293  /* Allocate memory for the reference counter table */
294  gpaulRefCount = EngAllocSectionMem(&pvSection,
296  GDI_HANDLE_COUNT * sizeof(ULONG),
297  'frHG');
298  if (!gpaulRefCount)
299  {
300  DPRINT1("INITGDI: Failed to allocate reference table.\n");
303  }
304 
305  gulFirstFree = 0;
307 
309 
310  /* Initialize the lookaside lists */
314  if(!gpaLookasideList)
315  return STATUS_NO_MEMORY;
316 
326 
327  return STATUS_SUCCESS;
328 }
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
volatile ULONG gulFirstUnused
Definition: gdiobj.c:152
static PPAGED_LOOKASIDE_LIST gpaLookasideList
Definition: gdiobj.c:153
_In_ CLIPOBJ _In_ BRUSHOBJ _In_ LONG x1
Definition: winddi.h:3706
LONG NTSTATUS
Definition: precomp.h:26
Definition: path.h:34
static VOID InitLookasideList(UCHAR objt, ULONG cjSize)
Definition: gdiobj.c:245
volatile ULONG gulFirstFree
Definition: gdiobj.c:151
#define SECTION_ALL_ACCESS
Definition: nt_native.h:1293
#define SEC_COMMIT
Definition: mmtypes.h:99
Definition: text.h:59
PULONG gpaulRefCount
Definition: gdiobj.c:150
PGDI_HANDLE_TABLE GdiHandleTable
Definition: gdiobj.c:1440
Definition: region.h:7
void * PVOID
Definition: retypes.h:9
Definition: polytest.cpp:40
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
NTSTATUS NTAPI MmCreateSection(OUT PVOID *Section, IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes OPTIONAL, IN PLARGE_INTEGER MaximumSize, IN ULONG SectionPageProtection, IN ULONG AllocationAttributes, IN HANDLE FileHandle OPTIONAL, IN PFILE_OBJECT FileObject OPTIONAL)
Definition: section.c:4341
Definition: brush.hpp:15
struct _GDI_HANDLE_TABLE GDI_HANDLE_TABLE
#define ObDereferenceObject
Definition: obfuncs.h:203
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
#define FL_ZERO_MEMORY
Definition: polytest.cpp:58
PENTRY gpentHmgr
Definition: gdiobj.c:149
static PVOID gpvGdiHdlTblSection
Definition: gdiobj.c:148
static const unsigned RESERVE_ENTRIES_COUNT
Definition: gdiobj.h:11
#define TAG_GDIHNDTBLE
Definition: tags.h:16
ULONG_PTR SIZE_T
Definition: typedefs.h:80
struct LOOKASIDE_ALIGN _PAGED_LOOKASIDE_LIST PAGED_LOOKASIDE_LIST
#define GDI_HANDLE_COUNT
Definition: gdi.h:12
#define STATUS_NO_MEMORY
Definition: ntstatus.h:260
#define NULL
Definition: types.h:112
#define DPRINT1
Definition: precomp.h:8
unsigned int ULONG
Definition: retypes.h:1
#define STATUS_SUCCESS
Definition: shellext.h:65
NTSTATUS NTAPI MmMapViewInSessionSpace(IN PVOID Section, OUT PVOID *MappedBase, IN OUT PSIZE_T ViewSize)
Definition: section.c:3044
static SERVICE_STATUS status
Definition: service.c:31
LONGLONG QuadPart
Definition: typedefs.h:114
#define PAGE_READWRITE
Definition: nt_native.h:1304
Definition: ps.c:97

Referenced by DriverEntry().

Variable Documentation

◆ GdiHandleTable

◆ RESERVE_ENTRIES_COUNT

const unsigned RESERVE_ENTRIES_COUNT = 10
static

Definition at line 11 of file gdiobj.h.

Referenced by GDI_CleanupForProcess(), InitGdiHandleTable(), and KdbCommand_Gdi_dumpht().