ReactOS  0.4.14-dev-49-gfb4591c
gdiobj.c File Reference
#include <win32k.h>
#include <debug.h>
Include dependency graph for gdiobj.c:

Go to the source code of this file.

Macros

#define NDEBUG
 
#define ASSERT_LOCK_ORDER(hobj)
 
#define ASSERT_SHARED_OBJECT_TYPE(objt)
 
#define ASSERT_EXCLUSIVE_OBJECT_TYPE(objt)
 
#define ASSERT_TRYLOCK_OBJECT_TYPE(objt)
 
#define GDIOBJ_POOL_TAG(type)   ('00hG' + (((type) & 0x1f) << 24))
 

Enumerations

enum  {
  REF_MASK_REUSE = 0xff000000, REF_INC_REUSE = 0x01000000, REF_MASK_VALID = 0x00800000, REF_MASK_COUNT = 0x007fffff,
  REF_MASK_INUSE = 0x00ffffff
}
 

Functions

FORCEINLINE ULONG InterlockedReadUlong (_In_ _Interlocked_operand_ ULONG volatile *Source)
 
FORCEINLINE void INCREASE_THREAD_LOCK_COUNT (_In_ HANDLE hobj)
 
FORCEINLINE void DECREASE_THREAD_LOCK_COUNT (_In_ HANDLE hobj)
 
static VOID NTAPI GDIOBJ_vCleanup (PVOID ObjectBody)
 
static VOID InitLookasideList (UCHAR objt, ULONG cjSize)
 
INIT_FUNCTION NTSTATUS NTAPI InitGdiHandleTable (void)
 
FORCEINLINE VOID IncrementCurrentProcessGdiHandleCount (void)
 
FORCEINLINE VOID DecrementCurrentProcessGdiHandleCount (void)
 
FORCEINLINE VOID IncrementGdiHandleCount (ULONG ulProcessId)
 
FORCEINLINE VOID DecrementGdiHandleCount (ULONG ulProcessId)
 
static PENTRY ENTRY_pentPopFreeEntry (VOID)
 
static VOID ENTRY_vPushFreeEntry (PENTRY pentFree)
 
static PENTRY ENTRY_ReferenceEntryByHandle (HGDIOBJ hobj, FLONG fl)
 
static HGDIOBJ ENTRY_hInsertObject (PENTRY pentry, POBJ pobj, UCHAR objt, ULONG ulOwner)
 
POBJ NTAPI GDIOBJ_AllocateObject (UCHAR objt, ULONG cjSize, FLONG fl)
 
VOID NTAPI GDIOBJ_vFreeObject (POBJ pobj)
 
VOID NTAPI GDIOBJ_vDereferenceObject (POBJ pobj)
 
POBJ NTAPI GDIOBJ_ReferenceObjectByHandle (HGDIOBJ hobj, UCHAR objt)
 
VOID NTAPI GDIOBJ_vReferenceObjectByPointer (POBJ pobj)
 
PGDIOBJ NTAPI GDIOBJ_TryLockObject (HGDIOBJ hobj, UCHAR objt)
 
PGDIOBJ NTAPI GDIOBJ_LockObject (HGDIOBJ hobj, UCHAR objt)
 
VOID NTAPI GDIOBJ_vUnlockObject (POBJ pobj)
 
HGDIOBJ NTAPI GDIOBJ_hInsertObject (POBJ pobj, ULONG ulOwner)
 
VOID NTAPI GDIOBJ_vSetObjectOwner (POBJ pobj, ULONG ulNewOwner)
 
BOOL NTAPI GDIOBJ_bLockMultipleObjects (IN ULONG ulCount, IN HGDIOBJ *ahObj, OUT PGDIOBJ *apObj, IN UCHAR objt)
 
PVOID NTAPI GDIOBJ_pvGetObjectAttr (POBJ pobj)
 
VOID NTAPI GDIOBJ_vSetObjectAttr (POBJ pobj, PVOID pvObjAttr)
 
VOID NTAPI GDIOBJ_vDeleteObject (POBJ pobj)
 
BOOL NTAPI GreIsHandleValid (HGDIOBJ hobj)
 
BOOL NTAPI GreDeleteObject (HGDIOBJ hobj)
 
ULONG NTAPI GreGetObjectOwner (HGDIOBJ hobj)
 
BOOL NTAPI GreSetObjectOwnerEx (HGDIOBJ hobj, ULONG ulOwner, ULONG Flags)
 
BOOL NTAPI GreSetObjectOwner (HGDIOBJ hobj, ULONG ulOwner)
 
INT NTAPI GreGetObject (IN HGDIOBJ hobj, IN INT cbCount, OUT PVOID pvBuffer)
 
W32KAPI INT APIENTRY NtGdiExtGetObjectW (IN HANDLE hobj, IN INT cjBufferSize, OUT LPVOID lpBuffer)
 
W32KAPI HANDLE APIENTRY NtGdiCreateClientObj (IN ULONG ulType)
 
W32KAPI BOOL APIENTRY NtGdiDeleteClientObj (IN HANDLE hobj)
 
PGDIOBJ NTAPI GDIOBJ_ShareLockObj (HGDIOBJ hObj, DWORD ExpectedType)
 
BOOL NTAPI GDIOBJ_ConvertToStockObj (HGDIOBJ *phObj)
 
POBJ NTAPI GDIOBJ_AllocObjWithHandle (ULONG ObjectType, ULONG cjSize)
 
PVOID NTAPI GDI_MapHandleTable (PEPROCESS pProcess)
 
BOOL NTAPI GDI_CleanupForProcess (struct _EPROCESS *Process)
 
PGDI_POOL GetBrushAttrPool (VOID)
 HACK! More...
 

Variables

static PVOID gpvGdiHdlTblSection = NULL
 
PENTRY gpentHmgr
 
PULONG gpaulRefCount
 
volatile ULONG gulFirstFree
 
volatile ULONG gulFirstUnused
 
static PPAGED_LOOKASIDE_LIST gpaLookasideList
 
static const GDICLEANUPPROC apfnCleanup []
 
static const GDIOBJDELETEPROC apfnDelete []
 
PGDI_HANDLE_TABLE GdiHandleTable = NULL
 

Macro Definition Documentation

◆ ASSERT_EXCLUSIVE_OBJECT_TYPE

#define ASSERT_EXCLUSIVE_OBJECT_TYPE (   objt)

Definition at line 126 of file gdiobj.c.

◆ ASSERT_LOCK_ORDER

#define ASSERT_LOCK_ORDER (   hobj)

Definition at line 124 of file gdiobj.c.

◆ ASSERT_SHARED_OBJECT_TYPE

#define ASSERT_SHARED_OBJECT_TYPE (   objt)

Definition at line 125 of file gdiobj.c.

◆ ASSERT_TRYLOCK_OBJECT_TYPE

#define ASSERT_TRYLOCK_OBJECT_TYPE (   objt)

Definition at line 127 of file gdiobj.c.

◆ GDIOBJ_POOL_TAG

#define GDIOBJ_POOL_TAG (   type)    ('00hG' + (((type) & 0x1f) << 24))

Definition at line 134 of file gdiobj.c.

◆ NDEBUG

#define NDEBUG

Definition at line 50 of file gdiobj.c.

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
REF_MASK_REUSE 
REF_INC_REUSE 
REF_MASK_VALID 
REF_MASK_COUNT 
REF_MASK_INUSE 

Definition at line 136 of file gdiobj.c.

137 {
138  REF_MASK_REUSE = 0xff000000,
139  REF_INC_REUSE = 0x01000000,
140  REF_MASK_VALID = 0x00800000,
141  REF_MASK_COUNT = 0x007fffff,
142  REF_MASK_INUSE = 0x00ffffff,
143 };

Function Documentation

◆ DECREASE_THREAD_LOCK_COUNT()

FORCEINLINE void DECREASE_THREAD_LOCK_COUNT ( _In_ HANDLE  hobj)

Definition at line 79 of file gdiobj.c.

81 {
84  if (pti)
85  {
86 #if DBG
87  pti->acExclusiveLockCount[((ULONG_PTR)hobj >> 16) & 0x1f]--;
88 #endif
89  pti->cExclusiveLocks--;
90  }
91 }
#define DBG_UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:325
PVOID NTAPI PsGetCurrentThreadWin32Thread(VOID)
Definition: thread.c:805
ULONG cExclusiveLocks
Definition: win32.h:152
#define ULONG_PTR
Definition: config.h:101

Referenced by GDIOBJ_vDeleteObject(), and GDIOBJ_vUnlockObject().

◆ DecrementCurrentProcessGdiHandleCount()

FORCEINLINE VOID DecrementCurrentProcessGdiHandleCount ( void  )

Definition at line 340 of file gdiobj.c.

341 {
343  if (ppi) InterlockedDecrement((LONG*)&ppi->GDIHandleCount);
344 }
long LONG
Definition: pedump.c:60
#define InterlockedDecrement
Definition: armddk.h:52
PVOID NTAPI PsGetCurrentProcessWin32Process(VOID)
Definition: process.c:1183

Referenced by GDIOBJ_vDereferenceObject().

◆ DecrementGdiHandleCount()

FORCEINLINE VOID DecrementGdiHandleCount ( ULONG  ulProcessId)

Definition at line 365 of file gdiobj.c.

366 {
367  PEPROCESS pep;
368  PPROCESSINFO ppi;
370 
371  Status = PsLookupProcessByProcessId(ULongToHandle(ulProcessId), &pep);
374 
375  ppi = PsGetProcessWin32Process(pep);
376  if (ppi) InterlockedDecrement((LONG*)&ppi->GDIHandleCount);
378 }
#define ULongToHandle(h)
Definition: basetsd.h:81
PVOID NTAPI PsGetProcessWin32Process(PEPROCESS Process)
Definition: process.c:1193
LONG NTSTATUS
Definition: precomp.h:26
VOID NTAPI ObDereferenceObject(IN PVOID Object)
Definition: obref.c:375
long LONG
Definition: pedump.c:60
#define __analysis_assume(expr)
Definition: sal.h:2893
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
NTSTATUS NTAPI PsLookupProcessByProcessId(IN HANDLE ProcessId, OUT PEPROCESS *Process)
Definition: process.c:919
#define InterlockedDecrement
Definition: armddk.h:52
Status
Definition: gdiplustypes.h:24
#define NT_ASSERT
Definition: rtlfuncs.h:3312

Referenced by GDIOBJ_vSetObjectOwner().

◆ ENTRY_hInsertObject()

static HGDIOBJ ENTRY_hInsertObject ( PENTRY  pentry,
POBJ  pobj,
UCHAR  objt,
ULONG  ulOwner 
)
static

Definition at line 536 of file gdiobj.c.

537 {
538  ULONG ulIndex;
539 
540  /* Calculate the handle index */
541  ulIndex = pentry - gpentHmgr;
542 
543  /* Update the fields in the ENTRY */
544  pentry->einfo.pobj = pobj;
545  pentry->Objt = objt & 0x1f;
546  pentry->FullUnique = (pentry->FullUnique & 0xff00) | objt;
547  pentry->ObjectOwner.ulObj = ulOwner;
548 
549  /* Make the handle valid with 1 reference */
552 
553  /* Return the handle */
554  return (HGDIOBJ)(((ULONG_PTR)pentry->FullUnique << 16) | ulIndex);
555 }
UCHAR Objt
Definition: ntgdihdl.h:249
struct _BASEOBJECT * pobj
Definition: ntgdihdl.h:234
union _ENTRY::_EINFO einfo
long LONG
Definition: pedump.c:60
PULONG gpaulRefCount
Definition: gdiobj.c:150
ULONG ulObj
Definition: ntgdihdl.h:245
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define InterlockedOr
Definition: interlocked.h:224
PENTRY gpentHmgr
Definition: gdiobj.c:149
ULONG ulIndex
Definition: symbols.c:92
USHORT FullUnique
Definition: ntgdihdl.h:248
unsigned int ULONG
Definition: retypes.h:1
#define ULONG_PTR
Definition: config.h:101
union _ENTRY::_OBJECTOWNER ObjectOwner

Referenced by GDIOBJ_hInsertObject().

◆ ENTRY_pentPopFreeEntry()

static PENTRY ENTRY_pentPopFreeEntry ( VOID  )
static

Definition at line 382 of file gdiobj.c.

383 {
384  ULONG iFirst, iNext, iPrev;
385  PENTRY pentFree;
386 
387  DPRINT("Enter InterLockedPopFreeEntry\n");
388 
389  do
390  {
391  /* Get the index and sequence number of the first free entry */
393 
394  /* Check if we have a free entry */
395  if (!(iFirst & GDI_HANDLE_INDEX_MASK))
396  {
397  /* Increment FirstUnused and get the new index */
398  iFirst = InterlockedIncrement((LONG*)&gulFirstUnused) - 1;
399 
400  /* Check if we have unused entries left */
401  if (iFirst >= GDI_HANDLE_COUNT)
402  {
403  DPRINT1("No more GDI handles left!\n");
404 #if DBG_ENABLE_GDIOBJ_BACKTRACES
405  DbgDumpGdiHandleTableWithBT();
406 #endif
408  return 0;
409  }
410 
411  /* Return the old entry */
412  return &gpentHmgr[iFirst];
413  }
414 
415  /* Get a pointer to the first free entry */
416  pentFree = &gpentHmgr[iFirst & GDI_HANDLE_INDEX_MASK];
417 
418  /* Create a new value with an increased sequence number */
419  iNext = GDI_HANDLE_GET_INDEX(pentFree->einfo.hFree);
420  iNext |= (iFirst & ~GDI_HANDLE_INDEX_MASK) + 0x10000;
421 
422  /* Try to exchange the FirstFree value */
424  iNext,
425  iFirst);
426  }
427  while (iPrev != iFirst);
428 
429  /* Sanity check: is entry really free? */
430  ASSERT(((ULONG_PTR)pentFree->einfo.pobj & ~GDI_HANDLE_INDEX_MASK) == 0);
431 
432  return pentFree;
433 }
#define GDI_HANDLE_GET_INDEX(h)
Definition: gdi.h:28
volatile ULONG gulFirstUnused
Definition: gdiobj.c:152
#define GDI_HANDLE_INDEX_MASK
Definition: gdi.h:16
#define InterlockedCompareExchange
Definition: interlocked.h:104
struct _BASEOBJECT * pobj
Definition: ntgdihdl.h:234
volatile ULONG gulFirstFree
Definition: gdiobj.c:151
union _ENTRY::_EINFO einfo
uint32_t ULONG_PTR
Definition: typedefs.h:63
long LONG
Definition: pedump.c:60
FORCEINLINE ULONG InterlockedReadUlong(_In_ _Interlocked_operand_ ULONG volatile *Source)
Definition: gdiobj.c:55
void DPRINT(...)
Definition: polytest.cpp:61
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define InterlockedDecrement
Definition: armddk.h:52
PENTRY gpentHmgr
Definition: gdiobj.c:149
HGDIOBJ hFree
Definition: ntgdihdl.h:235
#define InterlockedIncrement
Definition: armddk.h:53
#define GDI_HANDLE_COUNT
Definition: gdi.h:12
#define DPRINT1
Definition: precomp.h:8
unsigned int ULONG
Definition: retypes.h:1
Definition: ntgdihdl.h:230

Referenced by GDIOBJ_hInsertObject().

◆ ENTRY_ReferenceEntryByHandle()

static PENTRY ENTRY_ReferenceEntryByHandle ( HGDIOBJ  hobj,
FLONG  fl 
)
static

Definition at line 478 of file gdiobj.c.

479 {
480  ULONG ulIndex, cNewRefs, cOldRefs;
481  PENTRY pentry;
482 
483  /* Get the handle index and check if its too big */
485 
486  /* Get pointer to the entry */
487  pentry = &gpentHmgr[ulIndex];
488 
489  /* Get the current reference count */
490  cOldRefs = gpaulRefCount[ulIndex];
491 
492  do
493  {
494  /* Check if the slot is deleted */
495  if ((cOldRefs & REF_MASK_VALID) == 0)
496  {
497  DPRINT("GDIOBJ: Slot is not valid: 0x%lx, hobh=%p\n", cOldRefs, hobj);
498  return NULL;
499  }
500 
501  /* Check if the unique value matches */
502  if (pentry->FullUnique != (USHORT)((ULONG_PTR)hobj >> 16))
503  {
504  DPRINT("GDIOBJ: Wrong unique value. Handle: 0x%4x, entry: 0x%4x\n",
505  (USHORT)((ULONG_PTR)hobj >> 16), pentry->FullUnique);
506  return NULL;
507  }
508 
509  /* Check if the object owner is this process or public */
510  if (!(fl & GDIOBJFLAG_IGNOREPID) &&
513  {
514  DPRINT("GDIOBJ: Cannot reference foreign handle %p, pentry=%p:%lx.\n",
515  hobj, pentry, pentry->ObjectOwner.ulObj);
516  return NULL;
517  }
518 
519  /* Try to atomically increment the reference count */
520  cNewRefs = cOldRefs + 1;
522  cNewRefs,
523  cOldRefs);
524  }
525  while (cNewRefs != cOldRefs + 1);
526 
527  /* Integrity checks */
528  ASSERT((pentry->FullUnique & 0x1f) == pentry->Objt);
529  ASSERT(pentry->einfo.pobj && pentry->einfo.pobj->hHmgr == hobj);
530 
531  return pentry;
532 }
#define GDI_HANDLE_GET_INDEX(h)
Definition: gdi.h:28
UCHAR Objt
Definition: ntgdihdl.h:249
#define InterlockedCompareExchange
Definition: interlocked.h:104
struct _BASEOBJECT * pobj
Definition: ntgdihdl.h:234
union _ENTRY::_EINFO einfo
uint32_t ULONG_PTR
Definition: typedefs.h:63
_In_ FLONG fl
Definition: winddi.h:1279
PULONG gpaulRefCount
Definition: gdiobj.c:150
smooth NULL
Definition: ftsmooth.c:416
void DPRINT(...)
Definition: polytest.cpp:61
#define PtrToUlong(u)
Definition: config.h:107
ULONG ulObj
Definition: ntgdihdl.h:245
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
PENTRY gpentHmgr
Definition: gdiobj.c:149
ULONG ulIndex
Definition: symbols.c:92
unsigned short USHORT
Definition: pedump.c:61
USHORT FullUnique
Definition: ntgdihdl.h:248
#define GDI_OBJ_HMGR_PUBLIC
Definition: ntgdihdl.h:116
HANDLE NTAPI PsGetCurrentProcessId(VOID)
Definition: process.c:1123
unsigned int ULONG
Definition: retypes.h:1
union _ENTRY::_OBJECTOWNER ObjectOwner
Definition: ntgdihdl.h:230
signed int * PLONG
Definition: retypes.h:5

Referenced by GDIOBJ_ConvertToStockObj(), GDIOBJ_LockObject(), GDIOBJ_ReferenceObjectByHandle(), GDIOBJ_TryLockObject(), GreDeleteObject(), GreIsHandleValid(), and GreSetObjectOwnerEx().

◆ ENTRY_vPushFreeEntry()

static VOID ENTRY_vPushFreeEntry ( PENTRY  pentFree)
static

Definition at line 439 of file gdiobj.c.

440 {
441  ULONG iToFree, iFirst, iPrev, idxToFree;
442 
443  DPRINT("Enter ENTRY_vPushFreeEntry\n");
444 
445  idxToFree = pentFree - gpentHmgr;
446  ASSERT((gpaulRefCount[idxToFree] & REF_MASK_INUSE) == 0);
447 
448  /* Initialize entry */
449  pentFree->Objt = GDIObjType_DEF_TYPE;
450  pentFree->ObjectOwner.ulObj = 0;
451  pentFree->pUser = NULL;
452 
453  /* Increase reuse counter in entry and reference counter */
455  pentFree->FullUnique += 0x0100;
456 
457  do
458  {
459  /* Get the current first free index and sequence number */
461 
462  /* Set the einfo.pobj member to the index of the first free entry */
463  pentFree->einfo.pobj = UlongToPtr(iFirst & GDI_HANDLE_INDEX_MASK);
464 
465  /* Combine new index and increased sequence number in iToFree */
466  iToFree = idxToFree | ((iFirst & ~GDI_HANDLE_INDEX_MASK) + 0x10000);
467 
468  /* Try to atomically update the first free entry */
470  iToFree,
471  iFirst);
472  }
473  while (iPrev != iFirst);
474 }
PVOID pUser
Definition: ntgdihdl.h:251
UCHAR Objt
Definition: ntgdihdl.h:249
#define GDI_HANDLE_INDEX_MASK
Definition: gdi.h:16
#define InterlockedCompareExchange
Definition: interlocked.h:104
struct _BASEOBJECT * pobj
Definition: ntgdihdl.h:234
volatile ULONG gulFirstFree
Definition: gdiobj.c:151
union _ENTRY::_EINFO einfo
long LONG
Definition: pedump.c:60
FORCEINLINE ULONG InterlockedReadUlong(_In_ _Interlocked_operand_ ULONG volatile *Source)
Definition: gdiobj.c:55
PULONG gpaulRefCount
Definition: gdiobj.c:150
smooth NULL
Definition: ftsmooth.c:416
void DPRINT(...)
Definition: polytest.cpp:61
#define InterlockedExchangeAdd
Definition: interlocked.h:181
#define UlongToPtr(u)
Definition: config.h:106
ULONG ulObj
Definition: ntgdihdl.h:245
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
PENTRY gpentHmgr
Definition: gdiobj.c:149
USHORT FullUnique
Definition: ntgdihdl.h:248
unsigned int ULONG
Definition: retypes.h:1
union _ENTRY::_OBJECTOWNER ObjectOwner

Referenced by GDIOBJ_vDereferenceObject().

◆ GDI_CleanupForProcess()

BOOL NTAPI GDI_CleanupForProcess ( struct _EPROCESS Process)

Definition at line 1545 of file gdiobj.c.

1546 {
1547  PENTRY pentry;
1548  ULONG ulIndex;
1549  DWORD dwProcessId;
1550  PPROCESSINFO ppi;
1551 
1552  DPRINT("CleanupForProcess prochandle %p Pid %p\n",
1553  Process, Process->UniqueProcessId);
1554 
1556 
1557  /* Get the current process Id */
1558  dwProcessId = PtrToUlong(PsGetCurrentProcessId());
1559 
1560  /* Loop all handles in the handle table */
1562  {
1563  pentry = &gpentHmgr[ulIndex];
1564 
1565  /* Check if the object is owned by the process */
1566  if (pentry->ObjectOwner.ulObj == dwProcessId)
1567  {
1568  ASSERT(pentry->einfo.pobj->cExclusiveLock == 0);
1569 
1570  /* Reference the object and delete it */
1572  GDIOBJ_vDeleteObject(pentry->einfo.pobj);
1573  }
1574  }
1575 
1576 #if DBG
1578 #endif
1579 
1581  DPRINT("Completed cleanup for process %p\n", Process->UniqueProcessId);
1582  if (ppi->GDIHandleCount != 0)
1583  {
1584  DPRINT1("Leaking %d handles!\n", ppi->GDIHandleCount);
1585  ASSERT(FALSE);
1586  }
1587 
1588  /* Loop all handles in the handle table */
1590  {
1591  pentry = &gpentHmgr[ulIndex];
1592 
1593  /* Check if the object is owned by the process */
1594  if (pentry->ObjectOwner.ulObj == dwProcessId)
1595  {
1596  DPRINT1("Leaking object. Index=%lx, type=0x%x, refcount=%lx\n",
1597  ulIndex, pentry->Objt, gpaulRefCount[ulIndex]);
1598  DBG_DUMP_EVENT_LIST(&pentry->einfo.pobj->slhLog);
1599  //DBG_CLEANUP_EVENT_LIST(&pentry->einfo.pobj->slhLog);
1600  ASSERT(FALSE);
1601  }
1602  }
1603 
1604  return TRUE;
1605 }
#define TRUE
Definition: types.h:120
volatile ULONG gulFirstUnused
Definition: gdiobj.c:152
UCHAR Objt
Definition: ntgdihdl.h:249
struct _BASEOBJECT * pobj
Definition: ntgdihdl.h:234
union _ENTRY::_EINFO einfo
BOOL NTAPI DbgGdiHTIntegrityCheck(VOID)
long LONG
Definition: pedump.c:60
#define PsGetCurrentProcess
Definition: psfuncs.h:17
PULONG gpaulRefCount
Definition: gdiobj.c:150
void DPRINT(...)
Definition: polytest.cpp:61
#define PtrToUlong(u)
Definition: config.h:107
VOID NTAPI GDIOBJ_vDeleteObject(POBJ pobj)
Definition: gdiobj.c:1108
unsigned long DWORD
Definition: ntddk_ex.h:95
ULONG ulObj
Definition: ntgdihdl.h:245
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define DBG_DUMP_EVENT_LIST(pslh)
Definition: gdidebug.h:111
PENTRY gpentHmgr
Definition: gdiobj.c:149
static const unsigned RESERVE_ENTRIES_COUNT
Definition: gdiobj.h:11
ULONG ulIndex
Definition: symbols.c:92
#define InterlockedIncrement
Definition: armddk.h:53
HANDLE NTAPI PsGetCurrentProcessId(VOID)
Definition: process.c:1123
PVOID NTAPI PsGetCurrentProcessWin32Process(VOID)
Definition: process.c:1183
#define DPRINT1
Definition: precomp.h:8
_Must_inspect_result_ _In_ PLARGE_INTEGER _In_ PLARGE_INTEGER _In_ ULONG _In_ PFILE_OBJECT _In_ PVOID Process
Definition: fsrtlfuncs.h:219
unsigned int ULONG
Definition: retypes.h:1
union _ENTRY::_OBJECTOWNER ObjectOwner
Definition: ntgdihdl.h:230

Referenced by GdiProcessDestroy().

◆ GDI_MapHandleTable()

PVOID NTAPI GDI_MapHandleTable ( PEPROCESS  pProcess)

Definition at line 1515 of file gdiobj.c.

1516 {
1517  PVOID pvMappedView = NULL;
1518  NTSTATUS Status;
1519  LARGE_INTEGER liOffset;
1520  SIZE_T cjViewSize = sizeof(GDI_HANDLE_TABLE);
1521 
1522  liOffset.QuadPart = 0;
1523 
1525  ASSERT(pProcess != NULL);
1526 
1528  pProcess,
1529  &pvMappedView,
1530  0,
1531  0,
1532  &liOffset,
1533  &cjViewSize,
1534  ViewUnmap,
1535  SEC_NO_CHANGE,
1536  PAGE_READONLY);
1537 
1538  if (!NT_SUCCESS(Status))
1539  return NULL;
1540 
1541  return pvMappedView;
1542 }
LONG NTSTATUS
Definition: precomp.h:26
smooth NULL
Definition: ftsmooth.c:416
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:4502
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
struct _GDI_HANDLE_TABLE GDI_HANDLE_TABLE
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
static PVOID gpvGdiHdlTblSection
Definition: gdiobj.c:148
Status
Definition: gdiplustypes.h:24
ULONG_PTR SIZE_T
Definition: typedefs.h:78
#define PAGE_READONLY
Definition: compat.h:127
#define SEC_NO_CHANGE
Definition: mmtypes.h:94
LONGLONG QuadPart
Definition: typedefs.h:112

Referenced by GdiProcessCreate().

◆ GDIOBJ_AllocateObject()

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

Definition at line 559 of file gdiobj.c.

560 {
561  POBJ pobj;
562 
563  if (fl & BASEFLAG_LOOKASIDE)
564  {
565  /* Allocate the object from a lookaside list */
566  pobj = ExAllocateFromPagedLookasideList(&gpaLookasideList[objt & 0x1f]);
567  }
568  else
569  {
570  /* Allocate the object from paged pool */
572  }
573 
574  if (!pobj) return NULL;
575 
576  /* Initialize the object */
577  RtlZeroMemory(pobj, cjSize);
578  pobj->hHmgr = (HGDIOBJ)((ULONG_PTR)objt << 16);
579  pobj->cExclusiveLock = 0;
580  pobj->ulShareCount = 1;
581  pobj->BaseFlags = fl & 0xffff;
582  DBG_INITLOG(&pobj->slhLog);
583  DBG_LOGEVENT(&pobj->slhLog, EVENT_ALLOCATE, 0);
584 #if DBG_ENABLE_GDIOBJ_BACKTRACES
585  DbgCaptureStackBackTace(pobj->apvBackTrace, 1, GDI_OBJECT_STACK_LEVELS);
586 #endif /* GDI_DEBUG */
587 
588  return pobj;
589 }
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:63
#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
smooth NULL
Definition: ftsmooth.c:416
#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
_In_ ULONG cjSize
Definition: winddi.h:3634
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261

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 1485 of file gdiobj.c.

1486 {
1487  POBJ pobj;
1488  FLONG fl = 0;
1489  UCHAR objt = (ObjectType >> 16) & 0xFF;
1490 
1491  if ((objt == GDIObjType_DC_TYPE && cjSize == sizeof(DC)) ||
1492  (objt == GDIObjType_PAL_TYPE && cjSize == sizeof(PALETTE)) ||
1493  (objt == GDIObjType_RGN_TYPE && cjSize == sizeof(REGION)) ||
1494  (objt == GDIObjType_SURF_TYPE && cjSize == sizeof(SURFACE)) ||
1495  (objt == GDIObjType_PATH_TYPE && cjSize == sizeof(PATH)))
1496  {
1498  }
1499 
1500  pobj = GDIOBJ_AllocateObject(objt, cjSize, fl);
1501  if (!pobj)
1502  {
1503  return NULL;
1504  }
1505 
1507  {
1508  GDIOBJ_vFreeObject(pobj);
1509  return NULL;
1510  }
1511  return pobj;
1512 }
ObjectType
Definition: metafile.c:80
struct _PALETTE PALETTE
_In_ FLONG fl
Definition: winddi.h:1279
smooth NULL
Definition: ftsmooth.c:416
unsigned long FLONG
Definition: ntbasedef.h:373
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
struct _SURFACE SURFACE
_In_ ULONG cjSize
Definition: winddi.h:3634
POBJ NTAPI GDIOBJ_AllocateObject(UCHAR objt, ULONG cjSize, FLONG fl)
Definition: gdiobj.c:559
VOID NTAPI GDIOBJ_vFreeObject(POBJ pobj)
Definition: gdiobj.c:593
HGDIOBJ NTAPI GDIOBJ_hInsertObject(POBJ pobj, ULONG ulOwner)
Definition: gdiobj.c:909

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

◆ GDIOBJ_bLockMultipleObjects()

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

Definition at line 1028 of file gdiobj.c.

1033 {
1034  UINT auiIndices[3] = {0, 1, 2};
1035  UINT i, j, tmp;
1036 
1037  ASSERT(ulCount <= 3);
1038 
1039  /* Sort the handles */
1040  for (i = 0; i < ulCount - 1; i++)
1041  {
1042  for (j = i + 1; j < ulCount; j++)
1043  {
1044  if ((ULONG_PTR)ahObj[auiIndices[i]] <
1045  (ULONG_PTR)ahObj[auiIndices[j]])
1046  {
1047  tmp = auiIndices[i];
1048  auiIndices[i] = auiIndices[j];
1049  auiIndices[j] = tmp;
1050  }
1051  }
1052  }
1053 
1054  /* Lock the objects in safe order */
1055  for (i = 0; i < ulCount; i++)
1056  {
1057  /* Skip NULL handles */
1058  if (ahObj[auiIndices[i]] == NULL)
1059  {
1060  apObj[auiIndices[i]] = NULL;
1061  continue;
1062  }
1063 
1064  /* Lock the object */
1065  apObj[auiIndices[i]] = GDIOBJ_LockObject(ahObj[auiIndices[i]], objt);
1066 
1067  /* Check for failure */
1068  if (apObj[auiIndices[i]] == NULL)
1069  {
1070  /* Cleanup */
1071  while (i--)
1072  {
1073  if (apObj[auiIndices[i]])
1074  GDIOBJ_vUnlockObject(apObj[auiIndices[i]]);
1075  }
1076  return FALSE;
1077  }
1078  }
1079 
1080  return TRUE;
1081 }
PGDIOBJ NTAPI GDIOBJ_LockObject(HGDIOBJ hobj, UCHAR objt)
Definition: gdiobj.c:823
#define TRUE
Definition: types.h:120
uint32_t ULONG_PTR
Definition: typedefs.h:63
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
smooth NULL
Definition: ftsmooth.c:416
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint GLint GLint j
Definition: glfuncs.h:250
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
VOID NTAPI GDIOBJ_vUnlockObject(POBJ pobj)
Definition: gdiobj.c:877
unsigned int UINT
Definition: ndis.h:50

Referenced by GreStretchBltMask(), NtGdiAlphaBlend(), NtGdiCombineRgn(), NtGdiEqualRgn(), NtGdiMaskBlt(), and NtGdiTransparentBlt().

◆ GDIOBJ_ConvertToStockObj()

BOOL NTAPI GDIOBJ_ConvertToStockObj ( HGDIOBJ phObj)

Definition at line 1452 of file gdiobj.c.

1453 {
1454  PENTRY pentry;
1455  POBJ pobj;
1456 
1457  /* Reference the handle entry */
1458  pentry = ENTRY_ReferenceEntryByHandle(*phObj, 0);
1459  if (!pentry)
1460  {
1461  DPRINT1("GDIOBJ: Requested handle 0x%p is not valid.\n", *phObj);
1462  return FALSE;
1463  }
1464 
1465  /* Update the entry */
1466  pentry->FullUnique |= GDI_ENTRY_STOCK_MASK;
1467  pentry->ObjectOwner.ulObj = 0;
1468 
1469  /* Get the pointer to the BASEOBJECT */
1470  pobj = pentry->einfo.pobj;
1471 
1472  /* Calculate the new handle */
1473  pobj->hHmgr = (HGDIOBJ)((ULONG_PTR)pobj->hHmgr | GDI_HANDLE_STOCK_MASK);
1474 
1475  /* Return the new handle */
1476  *phObj = pobj->hHmgr;
1477 
1478  /* Dereference the handle */
1480 
1481  return TRUE;
1482 }
#define TRUE
Definition: types.h:120
struct _BASEOBJECT * pobj
Definition: ntgdihdl.h:234
VOID NTAPI GDIOBJ_vDereferenceObject(POBJ pobj)
Definition: gdiobj.c:628
#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:63
static PENTRY ENTRY_ReferenceEntryByHandle(HGDIOBJ hobj, FLONG fl)
Definition: gdiobj.c:478
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 909 of file gdiobj.c.

912 {
913  PENTRY pentry;
914  UCHAR objt;
915 
916  /* Must have no handle and only one reference */
917  ASSERT(GDI_HANDLE_GET_INDEX(pobj->hHmgr) == 0);
918  ASSERT(pobj->cExclusiveLock == 0);
919  ASSERT(pobj->ulShareCount == 1);
920 
921  /* Get a free handle entry */
922  pentry = ENTRY_pentPopFreeEntry();
923  if (!pentry)
924  {
925  DPRINT1("GDIOBJ: Could not get a free entry.\n");
926  return NULL;
927  }
928 
929  /* Make the object exclusively locked */
933  pobj->cExclusiveLock = 1;
936 
937  /* Get object type from the hHmgr field */
938  objt = ((ULONG_PTR)pobj->hHmgr >> 16) & 0xff;
939  ASSERT(objt != GDIObjType_DEF_TYPE);
940 
941  /* Check if current process is requested owner */
942  if (ulOwner == GDI_OBJ_HMGR_POWNED)
943  {
944  /* Increment the process handle count */
946 
947  /* Use Process id */
949  }
950 
951  /* Insert the object into the handle table */
952  pobj->hHmgr = ENTRY_hInsertObject(pentry, pobj, objt, ulOwner);
953 
954  /* Return the handle */
955  DPRINT("GDIOBJ: Created handle: %p\n", pobj->hHmgr);
956  DBG_LOGEVENT(&pobj->slhLog, EVENT_CREATE_HANDLE, 0);
957  return pobj->hHmgr;
958 }
#define GDI_HANDLE_GET_INDEX(h)
Definition: gdi.h:28
FORCEINLINE VOID ExAcquirePushLockExclusive(PEX_PUSH_LOCK PushLock)
Definition: ex.h:1022
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
smooth NULL
Definition: ftsmooth.c:416
EX_PUSH_LOCK pushlock
Definition: gdiobj.h:47
void DPRINT(...)
Definition: polytest.cpp:61
#define ExInitializePushLock
Definition: ex.h:999
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
static PENTRY ENTRY_pentPopFreeEntry(VOID)
Definition: gdiobj.c:382
FORCEINLINE VOID IncrementCurrentProcessGdiHandleCount(void)
Definition: gdiobj.c:332
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
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:536
#define GDI_OBJ_HMGR_POWNED
Definition: ntgdihdl.h:117
HANDLE NTAPI PsGetCurrentProcessId(VOID)
Definition: process.c:1123
#define DPRINT1
Definition: precomp.h:8
#define ULONG_PTR
Definition: config.h:101
Definition: ntgdihdl.h:230

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 823 of file gdiobj.c.

826 {
827  PENTRY pentry;
828  POBJ pobj;
830 
831  /* Check if the handle type matches */
833  if ((((ULONG_PTR)hobj >> 16) & 0x1f) != objt)
834  {
835  DPRINT("Wrong object type: hobj=0x%p, objt=0x%x\n", hobj, objt);
836  return NULL;
837  }
838 
839  /* Make sure lock order is correct */
840  ASSERT_LOCK_ORDER(objt);
841 
842  /* Reference the handle entry */
843  pentry = ENTRY_ReferenceEntryByHandle(hobj, 0);
844  if (!pentry)
845  {
846  DPRINT("GDIOBJ: Requested handle 0x%p is not valid.\n", hobj);
847  return NULL;
848  }
849 
850  /* Get the pointer to the BASEOBJECT */
851  pobj = pentry->einfo.pobj;
852 
853  /* Check if we already own the lock */
855  if (pobj->dwThreadId != dwThreadId)
856  {
857  /* Disable APCs and acquire the push lock */
860 
861  /* Set us as lock owner */
862  ASSERT(pobj->dwThreadId == 0);
863  pobj->dwThreadId = dwThreadId;
864  }
865 
866  /* Increase lock count */
867  pobj->cExclusiveLock++;
869  DBG_LOGEVENT(&pobj->slhLog, EVENT_LOCK, 0);
870 
871  /* Return the object */
872  return pobj;
873 }
FORCEINLINE VOID ExAcquirePushLockExclusive(PEX_PUSH_LOCK PushLock)
Definition: ex.h:1022
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:63
static PENTRY ENTRY_ReferenceEntryByHandle(HGDIOBJ hobj, FLONG fl)
Definition: gdiobj.c:478
#define DBG_LOGEVENT(pslh, type, val)
Definition: gdidebug.h:109
smooth NULL
Definition: ftsmooth.c:416
EX_PUSH_LOCK pushlock
Definition: gdiobj.h:47
void DPRINT(...)
Definition: polytest.cpp:61
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
unsigned long DWORD
Definition: ntddk_ex.h:95
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#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
Definition: ntgdihdl.h:230

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

◆ GDIOBJ_pvGetObjectAttr()

PVOID NTAPI GDIOBJ_pvGetObjectAttr ( POBJ  pobj)

Definition at line 1085 of file gdiobj.c.

1086 {
1088  return gpentHmgr[ulIndex].pUser;
1089 }
#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 688 of file gdiobj.c.

691 {
692  PENTRY pentry;
693  POBJ pobj;
694 
695  /* Check if the handle type matches */
697  if ((((ULONG_PTR)hobj >> 16) & 0x1f) != objt)
698  {
699  DPRINT("GDIOBJ: Wrong type. handle=%p, type=%x\n", hobj, objt);
700  return NULL;
701  }
702 
703  /* Reference the handle entry */
704  pentry = ENTRY_ReferenceEntryByHandle(hobj, 0);
705  if (!pentry)
706  {
707  DPRINT("GDIOBJ: Requested handle 0x%p is not valid.\n", hobj);
708  return NULL;
709  }
710 
711  /* Get the pointer to the BASEOBJECT */
712  pobj = pentry->einfo.pobj;
713 
714  /* Check if the object is exclusively locked */
715  if (pobj->cExclusiveLock != 0)
716  {
717  DPRINT1("GDIOBJ: Cannot reference object %p with exclusive lock.\n", hobj);
719  DBG_DUMP_EVENT_LIST(&pobj->slhLog);
720  return NULL;
721  }
722 
723  DBG_LOGEVENT(&pobj->slhLog, EVENT_REFERENCE, gpaulRefCount[pentry - gpentHmgr]);
724 
725  /* All is well, return the object */
726  return pobj;
727 }
struct _BASEOBJECT * pobj
Definition: ntgdihdl.h:234
VOID NTAPI GDIOBJ_vDereferenceObject(POBJ pobj)
Definition: gdiobj.c:628
USHORT cExclusiveLock
Definition: gdiobj.h:45
union _ENTRY::_EINFO einfo
uint32_t ULONG_PTR
Definition: typedefs.h:63
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
smooth NULL
Definition: ftsmooth.c:416
void DPRINT(...)
Definition: polytest.cpp:61
#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 DPRINT1
Definition: precomp.h:8
Definition: ntgdihdl.h:230

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

◆ GDIOBJ_ShareLockObj()

PGDIOBJ NTAPI GDIOBJ_ShareLockObj ( HGDIOBJ  hObj,
DWORD  ExpectedType 
)

Definition at line 1440 of file gdiobj.c.

1441 {
1442  if (ExpectedType == GDI_OBJECT_TYPE_DONTCARE)
1443  ExpectedType = GDI_HANDLE_GET_TYPE(hObj);
1444  return GDIOBJ_ReferenceObjectByHandle(hObj, (ExpectedType >> 16) & 0x1f);
1445 }
POBJ NTAPI GDIOBJ_ReferenceObjectByHandle(HGDIOBJ hobj, UCHAR objt)
Definition: gdiobj.c:688
#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 754 of file gdiobj.c.

757 {
758  PENTRY pentry;
759  POBJ pobj;
761 
762  /* Check if the handle type matches */
764  if ((((ULONG_PTR)hobj >> 16) & 0x1f) != objt)
765  {
766  DPRINT("Wrong object type: hobj=0x%p, objt=0x%x\n", hobj, objt);
767  return NULL;
768  }
769 
770  /* Make sure lock order is correct */
771  ASSERT_LOCK_ORDER(objt);
772 
773  /* Reference the handle entry */
774  pentry = ENTRY_ReferenceEntryByHandle(hobj, 0);
775  if (!pentry)
776  {
777  DPRINT("GDIOBJ: Requested handle 0x%p is not valid.\n", hobj);
778  return NULL;
779  }
780 
781  /* Get the pointer to the BASEOBJECT */
782  pobj = pentry->einfo.pobj;
783 
784  /* Check if we already own the lock */
786  if (pobj->dwThreadId != dwThreadId)
787  {
788  /* Disable APCs and try acquiring the push lock */
791  {
792  ULONG cRefs, ulIndex;
793  /* Already owned. Clean up and leave. */
795 
796  /* Calculate the index */
798 
799  /* Decrement reference count */
802  ASSERT(cRefs & REF_MASK_VALID);
803 
804  return NULL;
805  }
806 
807  /* Set us as lock owner */
808  ASSERT(pobj->dwThreadId == 0);
809  pobj->dwThreadId = dwThreadId;
810  }
811 
812  /* Increase lock count */
813  pobj->cExclusiveLock++;
815  DBG_LOGEVENT(&pobj->slhLog, EVENT_LOCK, 0);
816 
817  /* Return the object */
818  return pobj;
819 }
#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:63
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
smooth NULL
Definition: ftsmooth.c:416
EX_PUSH_LOCK pushlock
Definition: gdiobj.h:47
void DPRINT(...)
Definition: polytest.cpp:61
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
unsigned long DWORD
Definition: ntddk_ex.h:95
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#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
unsigned int ULONG
Definition: retypes.h:1
Definition: ntgdihdl.h:230
FORCEINLINE BOOLEAN ExTryAcquirePushLockExclusive(PEX_PUSH_LOCK PushLock)
Definition: misc.h:98

Referenced by DRIVEROBJ_TryLockObject().

◆ GDIOBJ_vCleanup()

static VOID NTAPI GDIOBJ_vCleanup ( PVOID  ObjectBody)
static

Definition at line 238 of file gdiobj.c.

239 {
240  /* Nothing to do */
241 }

◆ GDIOBJ_vDeleteObject()

VOID NTAPI GDIOBJ_vDeleteObject ( POBJ  pobj)

Definition at line 1108 of file gdiobj.c.

1109 {
1110  ULONG ulIndex;
1111 
1112  /* Set the object's delete flag */
1114  DBG_LOGEVENT(&pobj->slhLog, EVENT_DELETE, 0);
1115 
1116  /* Get the handle index */
1118  if (ulIndex)
1119  {
1120  /* Reset the handle valid bit */
1122 
1123  /* Check if the object is exclusively locked */
1124  if (pobj->cExclusiveLock != 0)
1125  {
1126  /* Reset lock owner and lock count */
1127  pobj->dwThreadId = 0;
1128  pobj->cExclusiveLock = 0;
1129 
1130  /* Release the pushlock and reenable APCs */
1134  }
1135  }
1136 
1137  /* Dereference the object (will take care of deletion) */
1139 }
#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:628
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:1238
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 628 of file gdiobj.c.

629 {
630  ULONG cRefs, ulIndex;
631 
632  /* Calculate the index */
634 
635  /* Check if the object has a handle */
636  if (ulIndex)
637  {
638  /* Decrement reference count */
639  if ((gpaulRefCount[ulIndex] & REF_MASK_COUNT) == 0)
640  {
641  DBG_DUMP_EVENT_LIST(&pobj->slhLog);
642  }
645  DBG_LOGEVENT(&pobj->slhLog, EVENT_DEREFERENCE, cRefs);
646 
647  /* Check if we reached 0 and handle bit is not set */
648  if ((cRefs & REF_MASK_INUSE) == 0)
649  {
650  /* Make sure it's ok to delete the object */
652 
653  /* Check if the handle was process owned */
654  if (gpentHmgr[ulIndex].ObjectOwner.ulObj != GDI_OBJ_HMGR_PUBLIC &&
656  {
657  /* Decrement the process handle count */
658  ASSERT(gpentHmgr[ulIndex].ObjectOwner.ulObj ==
661  }
662 
663  /* Push entry to the free list */
665 
666  /* Free the object */
667  GDIOBJ_vFreeObject(pobj);
668  }
669  }
670  else
671  {
672  /* Decrement the objects reference count */
673  ASSERT(pobj->ulShareCount > 0);
674  cRefs = InterlockedDecrement((LONG*)&pobj->ulShareCount);
675  DBG_LOGEVENT(&pobj->slhLog, EVENT_DEREFERENCE, cRefs);
676 
677  /* Check if we reached 0 */
678  if (cRefs == 0)
679  {
680  /* Free the object */
681  GDIOBJ_vFreeObject(pobj);
682  }
683  }
684 }
#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
ULONG ulObj
Definition: ntgdihdl.h:245
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#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:593

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 593 of file gdiobj.c.

594 {
595  UCHAR objt;
596 
597  DBG_CLEANUP_EVENT_LIST(&pobj->slhLog);
598 
599  /* Get the object type */
600  objt = ((ULONG_PTR)pobj->hHmgr >> 16) & 0x1f;
601 
602  /* Check if we have a delete procedure (for C++ based objects) */
603  if (apfnDelete[objt] != NULL)
604  {
605  /* Invoke the delete procedure */
606  apfnDelete[objt](pobj);
607  }
608  else
609  {
610  /* Call the cleanup procedure */
611  NT_ASSERT(apfnCleanup[objt]);
612  apfnCleanup[objt](pobj);
613 
614  /* Check if the object is allocated from a lookaside list */
615  if (pobj->BaseFlags & BASEFLAG_LOOKASIDE)
616  {
617  ExFreeToPagedLookasideList(&gpaLookasideList[objt], pobj);
618  }
619  else
620  {
621  ExFreePoolWithTag(pobj, GDIOBJ_POOL_TAG(objt));
622  }
623  }
624 }
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
smooth NULL
Definition: ftsmooth.c:416
static const GDIOBJDELETEPROC apfnDelete[]
Definition: gdiobj.c:197
unsigned char UCHAR
Definition: xmlstorage.h:181
#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 731 of file gdiobj.c.

732 {
733  ULONG cRefs;
734 
735  /* Check if the object has a handle */
736  if (GDI_HANDLE_GET_INDEX(pobj->hHmgr))
737  {
738  /* Increase the handle's reference count */
742  }
743  else
744  {
745  /* Increase the object's reference count */
746  cRefs = InterlockedIncrement((LONG*)&pobj->ulShareCount);
747  }
748 
749  DBG_LOGEVENT(&pobj->slhLog, EVENT_REFERENCE, cRefs);
750 }
#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
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
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 1093 of file gdiobj.c.

1094 {
1095  ULONG ulIndex;
1096 
1097  ASSERT(pobj->hHmgr);
1098 
1099  /* Get the handle index */
1101 
1102  /* Set pointer to the usermode attribute */
1103  gpentHmgr[ulIndex].pUser = pvObjAttr;
1104 }
#define GDI_HANDLE_GET_INDEX(h)
Definition: gdi.h:28
PVOID pUser
Definition: ntgdihdl.h:251
HGDIOBJ hHmgr
Definition: gdiobj.h:40
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
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  ulNewOwner 
)

Definition at line 962 of file gdiobj.c.

965 {
966  PENTRY pentry;
967  ULONG ulOldOwner;
968 
969  /* This is a ugly HACK, needed to fix IntGdiSetDCOwnerEx */
970  if (GDI_HANDLE_IS_STOCKOBJ(pobj->hHmgr))
971  {
972  DPRINT("Trying to set ownership of stock object %p to %lx\n", pobj->hHmgr, ulNewOwner);
973  return;
974  }
975 
976  /* Get the handle entry */
978  pentry = &gpentHmgr[GDI_HANDLE_GET_INDEX(pobj->hHmgr)];
979 
980  /* Check if the new owner is the same as the old one */
981  ulOldOwner = pentry->ObjectOwner.ulObj;
982  if (ulOldOwner == ulNewOwner)
983  {
984  /* Nothing to do */
985  return;
986  }
987 
988  /* Is the current process requested? */
989  if (ulNewOwner == GDI_OBJ_HMGR_POWNED)
990  {
991  /* Use process id */
992  ulNewOwner = HandleToUlong(PsGetCurrentProcessId());
993  }
994 
995  // HACK
996  if (ulNewOwner == GDI_OBJ_HMGR_NONE)
997  ulNewOwner = GDI_OBJ_HMGR_PUBLIC;
998 
999  /* Was the object process owned? */
1000  if ((ulOldOwner != GDI_OBJ_HMGR_PUBLIC) &&
1001  (ulOldOwner != GDI_OBJ_HMGR_NONE))
1002  {
1003  /* Decrement the previous owners handle count */
1004  DecrementGdiHandleCount(ulOldOwner);
1005  }
1006 
1007  /* Is the new owner a process? */
1008  if ((ulNewOwner != GDI_OBJ_HMGR_PUBLIC) &&
1009  (ulNewOwner != GDI_OBJ_HMGR_NONE))
1010  {
1011  /* Increment the new owners handle count */
1012  IncrementGdiHandleCount(ulNewOwner);
1013  }
1014  else
1015  {
1016  /* Make sure we don't leak user mode memory */
1017  NT_ASSERT(pentry->pUser == NULL);
1018  }
1019 
1020  /* Set new owner */
1021  pentry->ObjectOwner.ulObj = ulNewOwner;
1022  DBG_LOGEVENT(&pobj->slhLog, EVENT_SET_OWNER, 0);
1023 }
#define GDI_HANDLE_GET_INDEX(h)
Definition: gdi.h:28
PVOID pUser
Definition: ntgdihdl.h:251
#define HandleToUlong(h)
Definition: basetsd.h:79
HGDIOBJ hHmgr
Definition: gdiobj.h:40
#define DBG_LOGEVENT(pslh, type, val)
Definition: gdidebug.h:109
smooth NULL
Definition: ftsmooth.c:416
#define GDI_HANDLE_IS_STOCKOBJ(h)
Definition: gdi.h:37
void DPRINT(...)
Definition: polytest.cpp:61
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
FORCEINLINE VOID DecrementGdiHandleCount(ULONG ulProcessId)
Definition: gdiobj.c:365
FORCEINLINE 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 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 877 of file gdiobj.c.

878 {
879  ULONG cRefs, ulIndex;
880  ASSERT(pobj->cExclusiveLock > 0);
881 
882  /* Decrease lock count */
883  pobj->cExclusiveLock--;
885  DBG_LOGEVENT(&pobj->slhLog, EVENT_UNLOCK, 0);
886 
887  /* Check if this was the last lock */
888  if (pobj->cExclusiveLock == 0)
889  {
890  /* Reset lock owner */
891  pobj->dwThreadId = 0;
892 
893  /* Release the pushlock and reenable APCs */
896  }
897 
898  /* Calculate the index */
900 
901  /* Decrement reference count */
904  ASSERT(cRefs & REF_MASK_VALID);
905 }
#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:1238
PULONG gpaulRefCount
Definition: gdiobj.c:150
EX_PUSH_LOCK pushlock
Definition: gdiobj.h:47
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#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().

◆ GetBrushAttrPool()

PGDI_POOL GetBrushAttrPool ( VOID  )

HACK!

Definition at line 1609 of file gdiobj.c.

1610 {
1611  PPROCESSINFO ppi;
1612 
1614  NT_ASSERT(ppi != NULL);
1615 
1616  return ppi->pPoolBrushAttr;
1617 }
struct _GDI_POOL * pPoolBrushAttr
Definition: win32.h:283
smooth NULL
Definition: ftsmooth.c:416
PVOID NTAPI PsGetCurrentProcessWin32Process(VOID)
Definition: process.c:1183
#define NT_ASSERT
Definition: rtlfuncs.h:3312

Referenced by BRUSH::bAllocateBrushAttr(), and BRUSH::~BRUSH().

◆ GreDeleteObject()

BOOL NTAPI GreDeleteObject ( HGDIOBJ  hobj)

Definition at line 1155 of file gdiobj.c.

1156 {
1157  PENTRY pentry;
1158 
1159  /* Check for stock objects */
1160  if (GDI_HANDLE_IS_STOCKOBJ(hobj))
1161  {
1162  DPRINT1("GreDeleteObject: Cannot delete stock object %p.\n", hobj);
1163  return FALSE;
1164  }
1165 
1166  /* Reference the handle entry */
1167  pentry = ENTRY_ReferenceEntryByHandle(hobj, 0);
1168  if (!pentry)
1169  {
1170  DPRINT1("GreDeleteObject: Trying to delete invalid object %p\n", hobj);
1171  return FALSE;
1172  }
1173 
1174  /* Check for public owner */
1175  if (pentry->ObjectOwner.ulObj == GDI_OBJ_HMGR_PUBLIC)
1176  {
1177  DPRINT1("GreDeleteObject: Trying to delete global object %p\n", hobj);
1179  return FALSE;
1180  }
1181 
1182  /* Delete the object */
1183  GDIOBJ_vDeleteObject(pentry->einfo.pobj);
1184  return TRUE;
1185 }
#define TRUE
Definition: types.h:120
struct _BASEOBJECT * pobj
Definition: ntgdihdl.h:234
VOID NTAPI GDIOBJ_vDereferenceObject(POBJ pobj)
Definition: gdiobj.c:628
union _ENTRY::_EINFO einfo
static PENTRY ENTRY_ReferenceEntryByHandle(HGDIOBJ hobj, FLONG fl)
Definition: gdiobj.c:478
#define GDI_HANDLE_IS_STOCKOBJ(h)
Definition: gdi.h:37
VOID NTAPI GDIOBJ_vDeleteObject(POBJ pobj)
Definition: gdiobj.c:1108
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 1261 of file gdiobj.c.

1265 {
1266  PVOID pvObj;
1267  UCHAR objt;
1268  INT iResult = 0;
1269 
1270  /* Verify object type */
1271  objt = ((ULONG_PTR)hobj >> 16) & 0x1f;
1272  if (objt != GDIObjType_BRUSH_TYPE &&
1273  objt != GDIObjType_SURF_TYPE &&
1274  objt != GDIObjType_LFONT_TYPE &&
1275  objt != GDIObjType_PAL_TYPE)
1276  {
1277  DPRINT1("GreGetObject: Invalid object type\n");
1278  return 0;
1279  }
1280 
1281  pvObj = GDIOBJ_ReferenceObjectByHandle(hobj, objt);
1282  if (!pvObj)
1283  {
1284  DPRINT("GreGetObject: Could not lock object\n");
1285  return 0;
1286  }
1287 
1288  switch (GDI_HANDLE_GET_TYPE(hobj))
1289  {
1292  iResult = PEN_GetObject(pvObj, cbCount, pvBuffer);
1293  break;
1294 
1296  iResult = BRUSH_GetObject(pvObj, cbCount, pvBuffer);
1297  break;
1298 
1300  iResult = BITMAP_GetObject(pvObj, cbCount, pvBuffer);
1301  break;
1302 
1304  iResult = FontGetObject(pvObj, cbCount, pvBuffer);
1305  break;
1306 
1308  iResult = PALETTE_GetObject(pvObj, cbCount, pvBuffer);
1309  break;
1310 
1311  default:
1312  DPRINT1("GDI object type of 0x%p not implemented\n", hobj);
1313  break;
1314  }
1315 
1317  return iResult;
1318 }
POBJ NTAPI GDIOBJ_ReferenceObjectByHandle(HGDIOBJ hobj, UCHAR objt)
Definition: gdiobj.c:688
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:628
int32_t INT
Definition: typedefs.h:56
INT FASTCALL PALETTE_GetObject(PPALETTE ppal, INT cbCount, LPLOGBRUSH lpBuffer)
Definition: palette.c:247
void DPRINT(...)
Definition: polytest.cpp:61
#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

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

◆ GreGetObjectOwner()

ULONG NTAPI GreGetObjectOwner ( HGDIOBJ  hobj)

Definition at line 1189 of file gdiobj.c.

1190 {
1191  ULONG ulIndex, ulOwner;
1192 
1193  /* Get the handle index */
1194  ulIndex = GDI_HANDLE_GET_INDEX(hobj);
1195 
1196  /* Check if the handle is valid */
1197  if (ulIndex >= GDI_HANDLE_COUNT ||
1199  ((ULONG_PTR)hobj >> 16) != gpentHmgr[ulIndex].FullUnique)
1200  {
1201  DPRINT1("GreGetObjectOwner: invalid handle 0x%p.\n", hobj);
1202  return GDI_OBJ_HMGR_RESTRICTED;
1203  }
1204 
1205  /* Get the object owner */
1206  ulOwner = gpentHmgr[ulIndex].ObjectOwner.ulObj;
1207 
1208  if (ulOwner == HandleToUlong(PsGetCurrentProcessId()))
1209  return GDI_OBJ_HMGR_POWNED;
1210 
1211  if (ulOwner == GDI_OBJ_HMGR_PUBLIC)
1212  return GDI_OBJ_HMGR_PUBLIC;
1213 
1214  return GDI_OBJ_HMGR_RESTRICTED;
1215 }
#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:63
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 1143 of file gdiobj.c.

1144 {
1145  PENTRY pentry;
1146 
1147  pentry = ENTRY_ReferenceEntryByHandle(hobj, 0);
1148  if (!pentry) return FALSE;
1150  return TRUE;
1151 }
#define TRUE
Definition: types.h:120
struct _BASEOBJECT * pobj
Definition: ntgdihdl.h:234
VOID NTAPI GDIOBJ_vDereferenceObject(POBJ pobj)
Definition: gdiobj.c:628
union _ENTRY::_EINFO einfo
static PENTRY ENTRY_ReferenceEntryByHandle(HGDIOBJ hobj, FLONG fl)
Definition: gdiobj.c:478
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 1219 of file gdiobj.c.

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

Referenced by GreSetObjectOwner(), and NtUserConsoleControl().

◆ INCREASE_THREAD_LOCK_COUNT()

FORCEINLINE void INCREASE_THREAD_LOCK_COUNT ( _In_ HANDLE  hobj)

Definition at line 63 of file gdiobj.c.

65 {
68  if (pti)
69  {
70 #if DBG
71  pti->acExclusiveLockCount[((ULONG_PTR)hobj >> 16) & 0x1f]++;
72 #endif
73  pti->cExclusiveLocks++;
74  }
75 }
#define DBG_UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:325
PVOID NTAPI PsGetCurrentThreadWin32Thread(VOID)
Definition: thread.c:805
ULONG cExclusiveLocks
Definition: win32.h:152
#define ULONG_PTR
Definition: config.h:101

Referenced by GDIOBJ_hInsertObject(), GDIOBJ_LockObject(), and GDIOBJ_TryLockObject().

◆ IncrementCurrentProcessGdiHandleCount()

FORCEINLINE VOID IncrementCurrentProcessGdiHandleCount ( void  )

Definition at line 332 of file gdiobj.c.

333 {
335  if (ppi) InterlockedIncrement((LONG*)&ppi->GDIHandleCount);
336 }
long LONG
Definition: pedump.c:60
#define InterlockedIncrement
Definition: armddk.h:53
PVOID NTAPI PsGetCurrentProcessWin32Process(VOID)
Definition: process.c:1183

Referenced by GDIOBJ_hInsertObject().

◆ IncrementGdiHandleCount()

FORCEINLINE VOID IncrementGdiHandleCount ( ULONG  ulProcessId)

Definition at line 348 of file gdiobj.c.

349 {
350  PEPROCESS pep;
351  PPROCESSINFO ppi;
353 
354  Status = PsLookupProcessByProcessId(ULongToHandle(ulProcessId), &pep);
357 
358  ppi = PsGetProcessWin32Process(pep);
359  if (ppi) InterlockedIncrement((LONG*)&ppi->GDIHandleCount);
361 }
#define ULongToHandle(h)
Definition: basetsd.h:81
PVOID NTAPI PsGetProcessWin32Process(PEPROCESS Process)
Definition: process.c:1193
LONG NTSTATUS
Definition: precomp.h:26
VOID NTAPI ObDereferenceObject(IN PVOID Object)
Definition: obref.c:375
long LONG
Definition: pedump.c:60
#define __analysis_assume(expr)
Definition: sal.h:2893
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
NTSTATUS NTAPI PsLookupProcessByProcessId(IN HANDLE ProcessId, OUT PEPROCESS *Process)
Definition: process.c:919
Status
Definition: gdiplustypes.h:24
#define InterlockedIncrement
Definition: armddk.h:53
#define NT_ASSERT
Definition: rtlfuncs.h:3312

Referenced by GDIOBJ_vSetObjectOwner().

◆ InitGdiHandleTable()

INIT_FUNCTION 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
VOID NTAPI ObDereferenceObject(IN PVOID Object)
Definition: obref.c:375
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
smooth NULL
Definition: ftsmooth.c:416
PGDI_HANDLE_TABLE GdiHandleTable
Definition: gdiobj.c:1437
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:4975
Definition: brush.hpp:15
struct _GDI_HANDLE_TABLE GDI_HANDLE_TABLE
#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:78
struct LOOKASIDE_ALIGN _PAGED_LOOKASIDE_LIST PAGED_LOOKASIDE_LIST
#define GDI_HANDLE_COUNT
Definition: gdi.h:12
#define STATUS_NO_MEMORY
Definition: ntstatus.h:246
#define DPRINT1
Definition: precomp.h:8
unsigned int ULONG
Definition: retypes.h:1
NTSTATUS NTAPI MmMapViewInSessionSpace(IN PVOID Section, OUT PVOID *MappedBase, IN OUT PSIZE_T ViewSize)
Definition: section.c:2993
return STATUS_SUCCESS
Definition: btrfs.c:2966
static SERVICE_STATUS status
Definition: service.c:31
LONGLONG QuadPart
Definition: typedefs.h:112
#define PAGE_READWRITE
Definition: nt_native.h:1304
Definition: ps.c:97

Referenced by DriverEntry().

◆ InitLookasideList()

static VOID InitLookasideList ( UCHAR  objt,
ULONG  cjSize 
)
static

Definition at line 245 of file gdiobj.c.

246 {
248  NULL,
249  NULL,
250  0,
251  cjSize,
252  GDITAG_HMGR_LOOKASIDE_START + (objt << 24),
253  0);
254 }
VOID NTAPI ExInitializePagedLookasideList(IN PPAGED_LOOKASIDE_LIST Lookaside, IN PALLOCATE_FUNCTION Allocate OPTIONAL, IN PFREE_FUNCTION Free OPTIONAL, IN ULONG Flags, IN SIZE_T Size, IN ULONG Tag, IN USHORT Depth)
Definition: lookas.c:274
#define GDITAG_HMGR_LOOKASIDE_START
Definition: tags.h:130
static PPAGED_LOOKASIDE_LIST gpaLookasideList
Definition: gdiobj.c:153
smooth NULL
Definition: ftsmooth.c:416
_In_ ULONG cjSize
Definition: winddi.h:3634

Referenced by InitGdiHandleTable().

◆ InterlockedReadUlong()

FORCEINLINE ULONG InterlockedReadUlong ( _In_ _Interlocked_operand_ ULONG volatile Source)

Definition at line 55 of file gdiobj.c.

57 {
58  return *Source;
59 }
_In_ UINT _In_ UINT _In_ PNDIS_PACKET Source
Definition: ndis.h:3167

Referenced by ENTRY_pentPopFreeEntry(), and ENTRY_vPushFreeEntry().

◆ NtGdiCreateClientObj()

W32KAPI HANDLE APIENTRY NtGdiCreateClientObj ( IN ULONG  ulType)

Definition at line 1373 of file gdiobj.c.

1375 {
1376  POBJ pObject;
1377  HANDLE handle;
1378 
1379  /* Check if ulType is valid */
1383  {
1384  DPRINT1("NtGdiCreateClientObj: Invalid object type 0x%lx.\n", ulType);
1385  return NULL;
1386  }
1387 
1388  /* Allocate a new object */
1390  sizeof(CLIENTOBJ),
1392  if (!pObject)
1393  {
1394  DPRINT1("NtGdiCreateClientObj: Could not allocate a clientobj.\n");
1395  return NULL;
1396  }
1397 
1398  /* Set the real object type */
1400 
1401  /* Create a handle */
1403  if (!handle)
1404  {
1405  DPRINT1("NtGdiCreateClientObj: Could not create a handle.\n");
1406  GDIOBJ_vFreeObject(pObject);
1407  return NULL;
1408  }
1409 
1410  /* Unlock it */
1411  GDIOBJ_vUnlockObject(pObject);
1412 
1413  return handle;
1414 }
namespace GUID const ADDRINFOEXW ADDRINFOEXW struct timeval OVERLAPPED LPLOOKUPSERVICE_COMPLETION_ROUTINE HANDLE * handle
Definition: sock.c:82
HGDIOBJ hHmgr
Definition: gdiobj.h:40
smooth NULL
Definition: ftsmooth.c:416
#define UlongToHandle(ul)
Definition: basetsd.h:97
VOID NTAPI GDIOBJ_vUnlockObject(POBJ pobj)
Definition: gdiobj.c:877
#define GDI_OBJ_HMGR_POWNED
Definition: ntgdihdl.h:117
#define DPRINT1
Definition: precomp.h:8
_In_z_ PCWSTR _In_ ULONG ulType
Definition: ntuser.h:36
POBJ NTAPI GDIOBJ_AllocateObject(UCHAR objt, ULONG cjSize, FLONG fl)
Definition: gdiobj.c:559
VOID NTAPI GDIOBJ_vFreeObject(POBJ pobj)
Definition: gdiobj.c:593
HGDIOBJ NTAPI GDIOBJ_hInsertObject(POBJ pobj, ULONG ulOwner)
Definition: gdiobj.c:909

◆ NtGdiDeleteClientObj()

W32KAPI BOOL APIENTRY NtGdiDeleteClientObj ( IN HANDLE  hobj)

Definition at line 1419 of file gdiobj.c.

1421 {
1422  /* We first need to get the real type from the handle */
1424 
1425  /* Check if it's really a CLIENTOBJ */
1427  {
1428  /* FIXME: SetLastError? */
1429  return FALSE;
1430  }
1431 
1432  return GreDeleteObject(hobj);
1433 }
BOOL NTAPI GreDeleteObject(HGDIOBJ hobj)
Definition: gdiobj.c:1155
#define GDI_HANDLE_BASETYPE_MASK
Definition: gdi.h:18
#define GDI_HANDLE_GET_TYPE(h)
Definition: gdi.h:31
_In_z_ PCWSTR _In_ ULONG ulType
Definition: ntuser.h:36
unsigned int ULONG
Definition: retypes.h:1

◆ NtGdiExtGetObjectW()

W32KAPI INT APIENTRY NtGdiExtGetObjectW ( IN HANDLE  hobj,
IN INT  cjBufferSize,
OUT LPVOID  lpBuffer 
)

Definition at line 1323 of file gdiobj.c.

1327 {
1328  UINT iResult, cjMaxSize;
1329  union
1330  {
1331  BITMAP bitmap;
1332  DIBSECTION dibsection;
1333  LOGPEN logpen;
1334  LOGBRUSH logbrush;
1335  LOGFONTW logfontw;
1336  EXTLOGFONTW extlogfontw;
1337  ENUMLOGFONTEXDVW enumlogfontexdvw;
1338  } object;
1339 
1340  /* Normalize to the largest supported object size */
1341  cjMaxSize = min((UINT)cjBufferSize, sizeof(object));
1342 
1343  /* Now do the actual call */
1344  iResult = GreGetObject(hobj, cjMaxSize, lpBuffer ? &object : NULL);
1345 
1346  /* Check if we have a buffer and data */
1347  if ((lpBuffer != NULL) && (iResult != 0))
1348  {
1349  /* Enter SEH for buffer transfer */
1350  _SEH2_TRY
1351  {
1352  /* Probe the buffer and copy it */
1353  cjMaxSize = min(cjMaxSize, iResult);
1354  ProbeForWrite(lpBuffer, cjMaxSize, sizeof(WORD));
1355  RtlCopyMemory(lpBuffer, &object, cjMaxSize);
1356  }
1358  {
1359  /* Clear the return value.
1360  * Do *NOT* set last error here! */
1361  iResult = 0;
1362  }
1363  _SEH2_END;
1364  }
1365 
1366  /* Return the count */
1367  return iResult;
1368 }
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
VOID NTAPI ProbeForWrite(IN PVOID Address, IN SIZE_T Length, IN ULONG Alignment)
Definition: exintrin.c:143
_SEH2_TRY
Definition: create.c:4250
static TAGREF LPCWSTR LPDWORD LPVOID lpBuffer
Definition: db.cpp:173
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
smooth NULL
Definition: ftsmooth.c:416
unsigned short WORD
Definition: ntddk_ex.h:93
_SEH2_END
Definition: create.c:4424
Definition: bl.h:1331
#define min(a, b)
Definition: monoChain.cc:55
unsigned int UINT
Definition: ndis.h:50
static HBITMAP bitmap
Definition: clipboard.c:1344
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:6
void * object
Definition: jmemsys.h:48
INT NTAPI GreGetObject(IN HGDIOBJ hobj, IN INT cbCount, OUT PVOID pvBuffer)
Definition: gdiobj.c:1261

Referenced by GetFontObjectA(), and GetObjectW().

Variable Documentation

◆ apfnCleanup

const GDICLEANUPPROC apfnCleanup[]
static

Definition at line 159 of file gdiobj.c.

Referenced by GDIOBJ_vFreeObject().

◆ apfnDelete

const GDIOBJDELETEPROC apfnDelete[]
static

Definition at line 197 of file gdiobj.c.

Referenced by GDIOBJ_vFreeObject().

◆ GdiHandleTable

PGDI_HANDLE_TABLE GdiHandleTable = NULL

Definition at line 1437 of file gdiobj.c.

Referenced by InitGdiHandleTable().

◆ gpaLookasideList

PPAGED_LOOKASIDE_LIST gpaLookasideList
static

◆ gpaulRefCount

◆ gpentHmgr

◆ gpvGdiHdlTblSection

PVOID gpvGdiHdlTblSection = NULL
static

Definition at line 148 of file gdiobj.c.

Referenced by GDI_MapHandleTable(), and InitGdiHandleTable().

◆ gulFirstFree

volatile ULONG gulFirstFree

Definition at line 151 of file gdiobj.c.

Referenced by ENTRY_pentPopFreeEntry(), ENTRY_vPushFreeEntry(), and InitGdiHandleTable().

◆ gulFirstUnused