ReactOS  0.4.12-dev-919-gfc3b8d5
object.c File Reference
#include <win32k.h>
Include dependency graph for object.c:

Go to the source code of this file.

Functions

 DBG_DEFAULT_CHANNEL (UserObj)
 
 _Success_ (return!=NULL)
 
static void FreeThreadObject (_In_ PVOID Object)
 
static void FreeDeskThreadObject (_In_ PVOID Object)
 
static void FreeDeskProcObject (_In_ PVOID Object)
 
void FreeProcMarkObject (_In_ PVOID Object)
 
static void FreeSysObject (_In_ PVOID Object)
 
PUSER_HANDLE_ENTRY handle_to_entry (PUSER_HANDLE_TABLE ht, HANDLE handle)
 
static __inline HANDLE entry_to_handle (PUSER_HANDLE_TABLE ht, PUSER_HANDLE_ENTRY ptr)
 
static __inline PUSER_HANDLE_ENTRY alloc_user_entry (PUSER_HANDLE_TABLE ht)
 
VOID UserInitHandleTable (PUSER_HANDLE_TABLE ht, PVOID mem, ULONG bytes)
 
static __inline voidfree_user_entry (PUSER_HANDLE_TABLE ht, PUSER_HANDLE_ENTRY entry)
 
HANDLE UserAllocHandle (_Inout_ PUSER_HANDLE_TABLE ht, _In_ PVOID object, _In_ HANDLE_TYPE type, _In_ PVOID HandleOwner)
 
PVOID UserGetObjectNoErr (PUSER_HANDLE_TABLE ht, HANDLE handle, HANDLE_TYPE type)
 
PVOID UserGetObject (PUSER_HANDLE_TABLE ht, HANDLE handle, HANDLE_TYPE type)
 
HANDLE get_user_full_handle (PUSER_HANDLE_TABLE ht, HANDLE handle)
 
voidget_user_object_handle (PUSER_HANDLE_TABLE ht, HANDLE *handle, HANDLE_TYPE type)
 
BOOL FASTCALL UserCreateHandleTable (VOID)
 
PVOID FASTCALL UserCreateObject (PUSER_HANDLE_TABLE ht, PDESKTOP pDesktop, PTHREADINFO pti, HANDLE *h, HANDLE_TYPE type, ULONG size)
 
BOOL FASTCALL UserMarkObjectDestroy (PVOID Object)
 
BOOL FASTCALL UserDereferenceObject (PVOID Object)
 
BOOL FASTCALL UserFreeHandle (PUSER_HANDLE_TABLE ht, HANDLE handle)
 
BOOL FASTCALL UserObjectInDestroy (HANDLE h)
 
BOOL FASTCALL UserDeleteObject (HANDLE h, HANDLE_TYPE type)
 
VOID FASTCALL UserReferenceObject (PVOID obj)
 
PVOID FASTCALL UserReferenceObjectByHandle (HANDLE handle, HANDLE_TYPE type)
 
BOOLEAN UserDestroyObjectsForOwner (PUSER_HANDLE_TABLE Table, PVOID Owner)
 
BOOL APIENTRY NtUserValidateHandleSecure (HANDLE handle)
 

Variables

PUSER_HANDLE_TABLE gHandleTable = NULL
 
struct {
   PVOID(*   ObjectAlloc )(PDESKTOP, PTHREADINFO,
      SIZE_T, PVOID *)
 
   BOOLEAN(*   ObjectDestroy )(PVOID)
 
   void(*   ObjectFree )(PVOID)
 
ObjectCallbacks [TYPE_CTYPES]
 

Function Documentation

◆ _Success_()

_Success_ ( return!  = NULL)

Definition at line 16 of file object.c.

22 {
23  PTHROBJHEAD ObjHead;
24 
26 
27  ASSERT(Size > sizeof(*ObjHead));
28  ASSERT(pti != NULL);
29 
30  ObjHead = UserHeapAlloc(Size);
31  if (!ObjHead)
32  return NULL;
33 
34  RtlZeroMemory(ObjHead, Size);
35 
36  ObjHead->pti = pti;
38  *HandleOwner = pti;
39  /* It's a thread object, but it still count as one for the process */
40  pti->ppi->UserHandleCount++;
41 
42  return ObjHead;
43 }
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:323
static __inline PVOID UserHeapAlloc(SIZE_T Bytes)
Definition: usrheap.h:34
smooth NULL
Definition: ftsmooth.c:416
#define IntReferenceThreadInfo(pti)
Definition: win32.h:162
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
struct _THREADINFO * pti
Definition: ntuser.h:183
IN PVOID IN PVOID IN USHORT IN USHORT Size
Definition: pci.h:359
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261

◆ alloc_user_entry()

static __inline PUSER_HANDLE_ENTRY alloc_user_entry ( PUSER_HANDLE_TABLE  ht)
static

Definition at line 328 of file object.c.

329 {
331  TRACE("handles used %lu\n", gpsi->cHandleEntries);
332 
333  if (ht->freelist)
334  {
335  entry = ht->freelist;
336  ht->freelist = entry->ptr;
337 
338  gpsi->cHandleEntries++;
339  return entry;
340  }
341 
342  if (ht->nb_handles >= ht->allocated_handles) /* Need to grow the array */
343  {
344  ERR("Out of user handles! Used -> %lu, NM_Handle -> %d\n", gpsi->cHandleEntries, ht->nb_handles);
345 
346 #if DBG
348 #endif
349 
350  return NULL;
351 #if 0
352  PUSER_HANDLE_ENTRY new_handles;
353  /* Grow array by 50% (but at minimum 32 entries) */
354  int growth = max( 32, ht->allocated_handles / 2 );
355  int new_size = min( ht->allocated_handles + growth, (LAST_USER_HANDLE-FIRST_USER_HANDLE+1) >> 1 );
356  if (new_size <= ht->allocated_handles)
357  return NULL;
358  if (!(new_handles = UserHeapReAlloc( ht->handles, new_size * sizeof(*ht->handles) )))
359  return NULL;
360  ht->handles = new_handles;
361  ht->allocated_handles = new_size;
362 #endif
363  }
364 
365  entry = &ht->handles[ht->nb_handles++];
366 
367  entry->generation = 1;
368 
369  gpsi->cHandleEntries++;
370 
371  return entry;
372 }
ULONG_PTR cHandleEntries
Definition: ntuser.h:1005
#define max(a, b)
Definition: svc.c:63
uint8_t entry
Definition: isohybrid.c:63
#define FIRST_USER_HANDLE
Definition: ntuser.h:13
PSERVERINFO gpsi
Definition: main.c:27
#define LAST_USER_HANDLE
Definition: ntuser.h:14
smooth NULL
Definition: ftsmooth.c:416
Definition: ntuser.h:19
static __inline PVOID UserHeapReAlloc(PVOID lpMem, SIZE_T Bytes)
Definition: usrheap.h:50
#define TRACE(s)
Definition: solgame.cpp:4
#define ERR(fmt,...)
Definition: debug.h:109
static const struct newhuff ht[]
Definition: huffman.h:296
#define min(a, b)
Definition: monoChain.cc:55
void DbgUserDumpHandleTable()

Referenced by UserAllocHandle().

◆ DBG_DEFAULT_CHANNEL()

DBG_DEFAULT_CHANNEL ( UserObj  )

◆ entry_to_handle()

static __inline HANDLE entry_to_handle ( PUSER_HANDLE_TABLE  ht,
PUSER_HANDLE_ENTRY  ptr 
)
static

Definition at line 322 of file object.c.

323 {
324  int index = ptr - ht->handles;
325  return (HANDLE)((((INT_PTR)index << 1) + FIRST_USER_HANDLE) + (ptr->generation << 16));
326 }
#define FIRST_USER_HANDLE
Definition: ntuser.h:13
int32_t INT_PTR
Definition: typedefs.h:62
static PVOID ptr
Definition: dispmode.c:27
GLuint index
Definition: glext.h:6031
static const struct newhuff ht[]
Definition: huffman.h:296

Referenced by get_user_full_handle(), get_user_object_handle(), and UserAllocHandle().

◆ free_user_entry()

static __inline void* free_user_entry ( PUSER_HANDLE_TABLE  ht,
PUSER_HANDLE_ENTRY  entry 
)
static

Definition at line 384 of file object.c.

385 {
386  void *ret;
387 
388 #if DBG
389  {
390  PPROCESSINFO ppi;
391  switch (entry->type)
392  {
393  case TYPE_WINDOW:
394  case TYPE_HOOK:
395  case TYPE_WINEVENTHOOK:
396  ppi = ((PTHREADINFO)entry->pi)->ppi;
397  break;
398  case TYPE_MENU:
399  case TYPE_CURSOR:
400  case TYPE_CALLPROC:
401  case TYPE_ACCELTABLE:
402  ppi = entry->pi;
403  break;
404  default:
405  ppi = NULL;
406  }
407  if (ppi)
408  ppi->DbgHandleCount[entry->type]--;
409  }
410 #endif
411 
412  ret = entry->ptr;
413  entry->ptr = ht->freelist;
414  entry->type = 0;
415  entry->flags = 0;
416  entry->pi = NULL;
417  ht->freelist = entry;
418 
419  gpsi->cHandleEntries--;
420 
421  return ret;
422 }
ULONG_PTR cHandleEntries
Definition: ntuser.h:1005
uint8_t entry
Definition: isohybrid.c:63
PSERVERINFO gpsi
Definition: main.c:27
smooth NULL
Definition: ftsmooth.c:416
struct _THREADINFO * PTHREADINFO
Definition: ntwin32.h:6
int ret
static const struct newhuff ht[]
Definition: huffman.h:296

Referenced by UserDereferenceObject().

◆ FreeDeskProcObject()

static void FreeDeskProcObject ( _In_ PVOID  Object)
static

Definition at line 134 of file object.c.

136 {
138  PDESKTOP pDesk = ObjHead->rpdesk;
139  PPROCESSINFO ppi = (PPROCESSINFO)ObjHead->hTaskWow;
140 
141  ppi->UserHandleCount--;
143 
144  DesktopHeapFree(pDesk, Object);
145 }
struct _PROCESSINFO * PPROCESSINFO
Definition: ntwin32.h:5
struct _PROCDESKHEAD * PPROCDESKHEAD
static IUnknown Object
Definition: main.c:512
DWORD_PTR hTaskWow
Definition: ntuser.h:196
static __inline BOOL DesktopHeapFree(IN PDESKTOP Desktop, IN PVOID lpMem)
Definition: desktop.h:239
struct _DESKTOP * rpdesk
Definition: ntuser.h:197
#define IntDereferenceProcessInfo(ppi)
Definition: win32.h:182

◆ FreeDeskThreadObject()

static void FreeDeskThreadObject ( _In_ PVOID  Object)
static

Definition at line 89 of file object.c.

91 {
92  PTHRDESKHEAD ObjHead = (PTHRDESKHEAD)Object;
93  PDESKTOP pDesk = ObjHead->rpdesk;
94  PTHREADINFO pti = ObjHead->pti;
95 
96  DesktopHeapFree(pDesk, Object);
97 
98  pti->ppi->UserHandleCount--;
100 }
struct _DESKTOP * rpdesk
Definition: ntuser.h:189
PPROCESSINFO ppi
Definition: win32.h:87
struct _THRDESKHEAD * PTHRDESKHEAD
static IUnknown Object
Definition: main.c:512
static __inline BOOL DesktopHeapFree(IN PDESKTOP Desktop, IN PVOID lpMem)
Definition: desktop.h:239
#define IntDereferenceThreadInfo(pti)
Definition: win32.h:167

◆ FreeProcMarkObject()

void FreeProcMarkObject ( _In_ PVOID  Object)

Definition at line 175 of file object.c.

177 {
178  PPROCESSINFO ppi = ((PPROCMARKHEAD)Object)->ppi;
179 
181 
182  ppi->UserHandleCount--;
184 }
static __inline BOOL UserHeapFree(PVOID lpMem)
Definition: usrheap.h:42
static IUnknown Object
Definition: main.c:512
#define IntDereferenceProcessInfo(ppi)
Definition: win32.h:182
struct _PROCMARKHEAD * PPROCMARKHEAD

Referenced by FreeCurIconObject().

◆ FreeSysObject()

static void FreeSysObject ( _In_ PVOID  Object)
static

Definition at line 210 of file object.c.

212 {
214 }
static __inline BOOL UserHeapFree(PVOID lpMem)
Definition: usrheap.h:42
static IUnknown Object
Definition: main.c:512

◆ FreeThreadObject()

static void FreeThreadObject ( _In_ PVOID  Object)
static

Definition at line 45 of file object.c.

47 {
48  PTHROBJHEAD ObjHead = (PTHROBJHEAD)Object;
49  PTHREADINFO pti = ObjHead->pti;
50 
51  UserHeapFree(ObjHead);
52 
53  pti->ppi->UserHandleCount--;
55 }
static __inline BOOL UserHeapFree(PVOID lpMem)
Definition: usrheap.h:42
PPROCESSINFO ppi
Definition: win32.h:87
struct _THROBJHEAD * PTHROBJHEAD
static IUnknown Object
Definition: main.c:512
struct _THREADINFO * pti
Definition: ntuser.h:183
#define IntDereferenceThreadInfo(pti)
Definition: win32.h:167

◆ get_user_full_handle()

HANDLE get_user_full_handle ( PUSER_HANDLE_TABLE  ht,
HANDLE  handle 
)

Definition at line 478 of file object.c.

479 {
481 
482  if ((ULONG_PTR)handle >> 16)
483  return handle;
484  if (!(entry = handle_to_entry(ht, handle )))
485  return handle;
486  return entry_to_handle( ht, entry );
487 }
namespace GUID const ADDRINFOEXW ADDRINFOEXW struct timeval OVERLAPPED LPLOOKUPSERVICE_COMPLETION_ROUTINE HANDLE * handle
Definition: sock.c:82
PUSER_HANDLE_ENTRY handle_to_entry(PUSER_HANDLE_TABLE ht, HANDLE handle)
Definition: object.c:308
uint8_t entry
Definition: isohybrid.c:63
uint32_t ULONG_PTR
Definition: typedefs.h:63
Definition: ntuser.h:19
static __inline HANDLE entry_to_handle(PUSER_HANDLE_TABLE ht, PUSER_HANDLE_ENTRY ptr)
Definition: object.c:322
static const struct newhuff ht[]
Definition: huffman.h:296

◆ get_user_object_handle()

void* get_user_object_handle ( PUSER_HANDLE_TABLE  ht,
HANDLE handle,
HANDLE_TYPE  type 
)

Definition at line 491 of file object.c.

492 {
494 
495  if (!(entry = handle_to_entry(ht, *handle )) || entry->type != type)
496  return NULL;
498  return entry->ptr;
499 }
PUSER_HANDLE_ENTRY handle_to_entry(PUSER_HANDLE_TABLE ht, HANDLE handle)
Definition: object.c:308
uint8_t entry
Definition: isohybrid.c:63
GLuint GLuint GLsizei GLenum type
Definition: gl.h:1545
smooth NULL
Definition: ftsmooth.c:416
Definition: ntuser.h:19
static __inline HANDLE entry_to_handle(PUSER_HANDLE_TABLE ht, PUSER_HANDLE_ENTRY ptr)
Definition: object.c:322
static const struct newhuff ht[]
Definition: huffman.h:296

◆ handle_to_entry()

PUSER_HANDLE_ENTRY handle_to_entry ( PUSER_HANDLE_TABLE  ht,
HANDLE  handle 
)

Definition at line 308 of file object.c.

309 {
310  unsigned short generation;
311  int index = (LOWORD(handle) - FIRST_USER_HANDLE) >> 1;
312  if (index < 0 || index >= ht->nb_handles)
313  return NULL;
314  if (!ht->handles[index].type)
315  return NULL;
317  if (generation == ht->handles[index].generation || !generation || generation == 0xffff)
318  return &ht->handles[index];
319  return NULL;
320 }
#define FIRST_USER_HANDLE
Definition: ntuser.h:13
smooth NULL
Definition: ftsmooth.c:416
GLuint index
Definition: glext.h:6031
#define index(s, c)
Definition: various.h:29
_In_ UINT64 _In_ UINT64 _In_ UINT64 generation
Definition: btrfs.c:2644
static const struct newhuff ht[]
Definition: huffman.h:296
#define HIWORD(l)
Definition: typedefs.h:246
#define LOWORD(l)
Definition: pedump.c:82

Referenced by get_user_full_handle(), get_user_object_handle(), NtUserValidateHandleSecure(), UserDereferenceObject(), UserFreeHandle(), UserGetObject(), UserGetObjectNoErr(), UserMarkObjectDestroy(), and UserObjectInDestroy().

◆ NtUserValidateHandleSecure()

BOOL APIENTRY NtUserValidateHandleSecure ( HANDLE  handle)

Definition at line 758 of file object.c.

760 {
761  UINT uType;
762  PPROCESSINFO ppi;
764 
767 
769  {
771  RETURN( FALSE);
772  }
773  uType = entry->type;
774  switch (uType)
775  {
776  case TYPE_WINDOW:
777  case TYPE_INPUTCONTEXT:
778  ppi = ((PTHREADINFO)entry->pi)->ppi;
779  break;
780  case TYPE_MENU:
781  case TYPE_ACCELTABLE:
782  case TYPE_CURSOR:
783  case TYPE_HOOK:
784  case TYPE_CALLPROC:
785  case TYPE_SETWINDOWPOS:
786  ppi = entry->pi;
787  break;
788  default:
789  ppi = NULL;
790  break;
791  }
792 
793  if (!ppi) RETURN( FALSE);
794 
795  // Same process job returns TRUE.
796  if (gptiCurrent->ppi->pW32Job == ppi->pW32Job) RETURN( TRUE);
797 
798  RETURN( FALSE);
799 
800 CLEANUP:
801  UserLeave();
802  END_CLEANUP;
803 }
#define TRUE
Definition: types.h:120
#define CLEANUP
Definition: ntuser.h:5
PUSER_HANDLE_ENTRY handle_to_entry(PUSER_HANDLE_TABLE ht, HANDLE handle)
Definition: object.c:308
uint8_t entry
Definition: isohybrid.c:63
#define ERROR_INVALID_HANDLE
Definition: compat.h:88
PPROCESSINFO ppi
Definition: win32.h:87
unsigned int BOOL
Definition: ntddk_ex.h:94
smooth NULL
Definition: ftsmooth.c:416
PTHREADINFO gptiCurrent
Definition: ntuser.c:15
VOID FASTCALL UserEnterExclusive(VOID)
Definition: ntuser.c:247
Definition: ntuser.h:19
struct _THREADINFO * PTHREADINFO
Definition: ntwin32.h:6
#define DECLARE_RETURN(type)
Definition: ntuser.h:3
PVOID pW32Job
Definition: win32.h:266
VOID FASTCALL UserLeave(VOID)
Definition: ntuser.c:255
unsigned int UINT
Definition: ndis.h:50
PUSER_HANDLE_TABLE gHandleTable
Definition: object.c:13
ENGAPI VOID APIENTRY EngSetLastError(_In_ ULONG iError)
Definition: error.c:27
#define RETURN(rrr)
Definition: decompress.c:40
#define END_CLEANUP
Definition: ntuser.h:6

◆ UserAllocHandle()

HANDLE UserAllocHandle ( _Inout_ PUSER_HANDLE_TABLE  ht,
_In_ PVOID  object,
_In_ HANDLE_TYPE  type,
_In_ PVOID  HandleOwner 
)

Definition at line 425 of file object.c.

430 {
432  if (!entry)
433  return 0;
434  entry->ptr = object;
435  entry->type = type;
436  entry->flags = 0;
437  entry->pi = HandleOwner;
438  if (++entry->generation >= 0xffff)
439  entry->generation = 1;
440 
441  /* We have created a handle, which is a reference! */
442  UserReferenceObject(object);
443 
444  return entry_to_handle(ht, entry );
445 }
uint8_t entry
Definition: isohybrid.c:63
GLuint GLuint GLsizei GLenum type
Definition: gl.h:1545
static __inline PUSER_HANDLE_ENTRY alloc_user_entry(PUSER_HANDLE_TABLE ht)
Definition: object.c:328
Definition: ntuser.h:19
static __inline HANDLE entry_to_handle(PUSER_HANDLE_TABLE ht, PUSER_HANDLE_ENTRY ptr)
Definition: object.c:322
static const struct newhuff ht[]
Definition: huffman.h:296
void * object
Definition: jmemsys.h:48
VOID FASTCALL UserReferenceObject(PVOID obj)
Definition: object.c:697

Referenced by UserCreateObject().

◆ UserCreateHandleTable()

BOOL FASTCALL UserCreateHandleTable ( VOID  )

Definition at line 503 of file object.c.

504 {
505  PVOID mem;
506  INT HandleCount = 1024 * 4;
507 
508  // FIXME: Don't alloc all at once! Must be mapped into umode also...
509  mem = UserHeapAlloc(sizeof(USER_HANDLE_ENTRY) * HandleCount);
510  if (!mem)
511  {
512  ERR("Failed creating handle table\n");
513  return FALSE;
514  }
515 
517  if (gHandleTable == NULL)
518  {
519  UserHeapFree(mem);
520  ERR("Failed creating handle table\n");
521  return FALSE;
522  }
523 
524  // FIXME: Make auto growable
525  UserInitHandleTable(gHandleTable, mem, sizeof(USER_HANDLE_ENTRY) * HandleCount);
526 
527  return TRUE;
528 }
#define TRUE
Definition: types.h:120
static __inline BOOL UserHeapFree(PVOID lpMem)
Definition: usrheap.h:42
static __inline PVOID UserHeapAlloc(SIZE_T Bytes)
Definition: usrheap.h:34
int32_t INT
Definition: typedefs.h:56
smooth NULL
Definition: ftsmooth.c:416
Definition: ntuser.h:19
#define ERR(fmt,...)
Definition: debug.h:109
VOID UserInitHandleTable(PUSER_HANDLE_TABLE ht, PVOID mem, ULONG bytes)
Definition: object.c:374
Definition: mem.c:156
PUSER_HANDLE_TABLE gHandleTable
Definition: object.c:13

Referenced by InitUserImpl().

◆ UserCreateObject()

PVOID FASTCALL UserCreateObject ( PUSER_HANDLE_TABLE  ht,
PDESKTOP  pDesktop,
PTHREADINFO  pti,
HANDLE h,
HANDLE_TYPE  type,
ULONG  size 
)

Definition at line 535 of file object.c.

541 {
542  HANDLE hi;
543  PVOID Object;
544  PVOID ObjectOwner;
545 
546  /* Some sanity checks. Other checks will be made in the allocator */
548  ASSERT(type != TYPE_FREE);
549  ASSERT(ht != NULL);
550 
551  /* Allocate the object */
553  Object = ObjectCallbacks[type].ObjectAlloc(pDesktop, pti, size, &ObjectOwner);
554  if (!Object)
555  {
556  ERR("User object allocation failed. Out of memory!\n");
557  return NULL;
558  }
559 
560  hi = UserAllocHandle(ht, Object, type, ObjectOwner);
561  if (hi == NULL)
562  {
563  ERR("Out of user handles!\n");
564  ObjectCallbacks[type].ObjectFree(Object);
565  return NULL;
566  }
567 
568 #if DBG
569  if (pti)
570  pti->ppi->DbgHandleCount[type]++;
571 #endif
572 
573  /* Give this object its identity. */
574  ((PHEAD)Object)->h = hi;
575 
576  /* The caller will get a locked object.
577  * Note: with the reference from the handle, that makes two */
579 
580  if (h)
581  *h = hi;
582  return Object;
583 }
GLuint GLuint GLsizei GLenum type
Definition: gl.h:1545
GLfloat GLfloat GLfloat GLfloat h
Definition: glext.h:7723
PPROCESSINFO ppi
Definition: win32.h:87
smooth NULL
Definition: ftsmooth.c:416
GLsizeiptr size
Definition: glext.h:5919
static IUnknown Object
Definition: main.c:512
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
static const struct @4126 ObjectCallbacks[TYPE_CTYPES]
#define ERR(fmt,...)
Definition: debug.h:109
PVOID(* ObjectAlloc)(PDESKTOP, PTHREADINFO, SIZE_T, PVOID *)
Definition: object.c:218
static const struct newhuff ht[]
Definition: huffman.h:296
struct _HEAD * PHEAD
HANDLE UserAllocHandle(_Inout_ PUSER_HANDLE_TABLE ht, _In_ PVOID object, _In_ HANDLE_TYPE type, _In_ PVOID HandleOwner)
Definition: object.c:425
VOID FASTCALL UserReferenceObject(PVOID obj)
Definition: object.c:697

Referenced by CreateCallProc(), CreateTimer(), IntAddSynthesizedFormats(), IntCloneMenu(), IntCreateCurIconHandle(), IntCreateMenu(), IntCreateMonitorObject(), IntCreateWindow(), IntSynthesizeDib(), NtUserCallOneParam(), NtUserConvertMemHandle(), NtUserCreateAcceleratorTable(), NtUserSetWindowsHookEx(), NtUserSetWinEventHook(), UserLoadKbdFile(), and UserLoadKbdLayout().

◆ UserDeleteObject()

BOOL FASTCALL UserDeleteObject ( HANDLE  h,
HANDLE_TYPE  type 
)

Definition at line 683 of file object.c.

684 {
686 
687  if (!body) return FALSE;
688 
689  ASSERT( ((PHEAD)body)->cLockObj >= 1);
690  ASSERT( ((PHEAD)body)->cLockObj < 0x10000);
691 
692  return UserFreeHandle(gHandleTable, h);
693 }
GLuint GLuint GLsizei GLenum type
Definition: gl.h:1545
GLfloat GLfloat GLfloat GLfloat h
Definition: glext.h:7723
Definition: ntuser.h:174
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
PVOID UserGetObject(PUSER_HANDLE_TABLE ht, HANDLE handle, HANDLE_TYPE type)
Definition: object.c:462
static const void * body(MD5_CTX *ctx, const void *data, unsigned long size)
Definition: md5.c:100
BOOL FASTCALL UserFreeHandle(PUSER_HANDLE_TABLE ht, HANDLE handle)
Definition: object.c:652
PUSER_HANDLE_TABLE gHandleTable
Definition: object.c:13

Referenced by co_UserFreeWindow(), DestroyCallProc(), IntDestroyCurIconObject(), IntDestroyMenuObject(), IntDestroyMonitorObject(), IntEndDeferWindowPosEx(), IntFreeElementData(), IntFreeHook(), IntRemoveEvent(), NtUserCallOneParam(), NtUserConvertMemHandle(), NtUserCreateAcceleratorTable(), RemoveTimer(), UnloadKbdFile(), UserDestroyAccelTable(), UserLoadKbdFile(), UserLoadKbdLayout(), and UserUnloadKbl().

◆ UserDereferenceObject()

BOOL FASTCALL UserDereferenceObject ( PVOID  Object)

Definition at line 610 of file object.c.

611 {
612  PHEAD ObjHead = Object;
613 
614  ASSERT(ObjHead->cLockObj >= 1);
615  ASSERT(ObjHead->cLockObj < 0x10000);
616 
617  if (--ObjHead->cLockObj == 0)
618  {
621 
622  entry = handle_to_entry(gHandleTable, ObjHead->h);
623 
624  ASSERT(entry != NULL);
625  /* The entry should be marked as in deletion */
627 
628  type = entry->type;
629  ASSERT(type != TYPE_FREE);
631 
632  /* We can now get rid of everything */
634 
635 #if 0
636  /* Call the object destructor */
637  ASSERT(ObjectCallbacks[type].ObjectCleanup != NULL);
638  ObjectCallbacks[type].ObjectCleanup(Object);
639 #endif
640 
641  /* And free it */
643  ObjectCallbacks[type].ObjectFree(Object);
644 
645  return TRUE;
646  }
647  return FALSE;
648 }
#define TRUE
Definition: types.h:120
PUSER_HANDLE_ENTRY handle_to_entry(PUSER_HANDLE_TABLE ht, HANDLE handle)
Definition: object.c:308
static __inline void * free_user_entry(PUSER_HANDLE_TABLE ht, PUSER_HANDLE_ENTRY entry)
Definition: object.c:384
HANDLE h
Definition: ntuser.h:176
uint8_t entry
Definition: isohybrid.c:63
GLuint GLuint GLsizei GLenum type
Definition: gl.h:1545
void(* ObjectFree)(PVOID)
Definition: object.c:220
smooth NULL
Definition: ftsmooth.c:416
Definition: ntuser.h:174
Definition: ntuser.h:19
static IUnknown Object
Definition: main.c:512
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
DWORD cLockObj
Definition: ntuser.h:177
static const struct @4126 ObjectCallbacks[TYPE_CTYPES]
enum _HANDLE_TYPE HANDLE_TYPE
#define HANDLEENTRY_INDESTROY
Definition: ntuser.h:17
PUSER_HANDLE_TABLE gHandleTable
Definition: object.c:13

Referenced by _Success_(), co_UserActivateKbl(), co_UserCreateWindowEx(), co_UserFreeWindow(), co_UserSetParent(), co_WinPosSearchChildren(), CreateCallProc(), DefWndDoSizeMove(), DesktopWindowProc(), ExitThreadCallback(), FreeCurIconObject(), IntAddSynthesizedFormats(), IntCleanupCurIconCache(), IntCreateCurIconHandle(), IntCreateWindow(), IntDefWindowProc(), IntDestroyClass(), IntDestroyMonitorObject(), IntEndDeferWindowPosEx(), IntRemoveCursorFromList(), IntSetAconData(), IntSetOwner(), IntSynthesizeDib(), IntSystemSetCursor(), MENU_DrawBitmapItem(), MsqCleanupMessageQueue(), NtUserConvertMemHandle(), NtUserCreateAcceleratorTable(), NtUserDestroyCursor(), NtUserDrawIconEx(), NtUserGetCursorFrameInfo(), NtUserGetIconSize(), NtUserSetCursor(), NtUserSetWindowsHookEx(), NtUserSetWinEventHook(), NtUserUnhookWindowsHookEx(), RemoveTimer(), UserAttachThreadInput(), UserCreateMenu(), UserDerefObjectCo(), UserDrawCaption(), UserDrawSysMenuButton(), UserFreeHandle(), UserLoadKbdFile(), UserLoadKbdLayout(), UserSetClassLongPtr(), and UserSetCursorIconData().

◆ UserDestroyObjectsForOwner()

BOOLEAN UserDestroyObjectsForOwner ( PUSER_HANDLE_TABLE  Table,
PVOID  Owner 
)

Definition at line 720 of file object.c.

721 {
722  int i;
724  BOOLEAN Ret = TRUE;
725 
726  /* Sweep the whole handle table */
727  for (i = 0; i < Table->allocated_handles; i++)
728  {
729  Entry = &Table->handles[i];
730 
731  if (Entry->pi != Owner)
732  continue;
733 
734  /* Do not destroy if it's already been done */
735  if (Entry->flags & HANDLEENTRY_INDESTROY)
736  continue;
737 
738  /* Call destructor */
739  if (!ObjectCallbacks[Entry->type].ObjectDestroy(Entry->ptr))
740  {
741  ERR("Failed destructing object %p, type %u.\n", Entry->ptr, Entry->type);
742  /* Don't return immediately, we must continue destroying the other objects */
743  Ret = FALSE;
744  }
745  }
746 
747  return Ret;
748 }
ASMGENDATA Table[]
Definition: genincdata.c:61
#define TRUE
Definition: types.h:120
struct _Entry Entry
Definition: kefuncs.h:640
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
unsigned char BOOLEAN
Definition: ntuser.h:19
static const struct @4126 ObjectCallbacks[TYPE_CTYPES]
#define ERR(fmt,...)
Definition: debug.h:109
_Out_writes_bytes_to_opt_ AbsoluteSecurityDescriptorSize PSECURITY_DESCRIPTOR _Inout_ PULONG _Out_writes_bytes_to_opt_ DaclSize PACL _Inout_ PULONG _Out_writes_bytes_to_opt_ SaclSize PACL _Inout_ PULONG _Out_writes_bytes_to_opt_ OwnerSize PSID Owner
Definition: rtlfuncs.h:1557
#define HANDLEENTRY_INDESTROY
Definition: ntuser.h:17
base of all file and directory entries
Definition: entries.h:82

Referenced by ExitThreadCallback(), and UserProcessDestroy().

◆ UserFreeHandle()

BOOL FASTCALL UserFreeHandle ( PUSER_HANDLE_TABLE  ht,
HANDLE  handle 
)

Definition at line 652 of file object.c.

653 {
655 
656  if (!(entry = handle_to_entry( ht, handle )))
657  {
659  return FALSE;
660  }
661 
662  entry->flags = HANDLEENTRY_INDESTROY;
663 
664  return UserDereferenceObject(entry->ptr);
665 }
PUSER_HANDLE_ENTRY handle_to_entry(PUSER_HANDLE_TABLE ht, HANDLE handle)
Definition: object.c:308
uint8_t entry
Definition: isohybrid.c:63
BOOL FASTCALL UserDereferenceObject(PVOID Object)
Definition: object.c:610
#define STATUS_INVALID_HANDLE
Definition: ntstatus.h:231
Definition: ntuser.h:19
VOID FASTCALL SetLastNtError(NTSTATUS Status)
Definition: error.c:36
static const struct newhuff ht[]
Definition: huffman.h:296
#define HANDLEENTRY_INDESTROY
Definition: ntuser.h:17

Referenced by UserDeleteObject().

◆ UserGetObject()

PVOID UserGetObject ( PUSER_HANDLE_TABLE  ht,
HANDLE  handle,
HANDLE_TYPE  type 
)

Definition at line 462 of file object.c.

463 {
465 
466  ASSERT(ht);
467 
468  if (!(entry = handle_to_entry(ht, handle )) || entry->type != type)
469  {
471  return NULL;
472  }
473  return entry->ptr;
474 }
PUSER_HANDLE_ENTRY handle_to_entry(PUSER_HANDLE_TABLE ht, HANDLE handle)
Definition: object.c:308
uint8_t entry
Definition: isohybrid.c:63
#define ERROR_INVALID_HANDLE
Definition: compat.h:88
GLuint GLuint GLsizei GLenum type
Definition: gl.h:1545
smooth NULL
Definition: ftsmooth.c:416
Definition: ntuser.h:19
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
static const struct newhuff ht[]
Definition: huffman.h:296
ENGAPI VOID APIENTRY EngSetLastError(_In_ ULONG iError)
Definition: error.c:27

Referenced by co_HOOK_CallHooks(), IntDeferWindowPos(), IntEndDeferWindowPosEx(), IntGetHookObject(), IntSetClassWndProc(), IntSetWindowProc(), IntSynthesizeBitmap(), NtUserCreateLocalMemHandle(), NtUserUnhookWinEvent(), UserDeleteObject(), UserGetAccelObject(), UserGetCallProcInfo(), UserGetMenuObject(), UserGetMonitorObject(), UserGetWindowObject(), and UserReferenceObjectByHandle().

◆ UserGetObjectNoErr()

PVOID UserGetObjectNoErr ( PUSER_HANDLE_TABLE  ht,
HANDLE  handle,
HANDLE_TYPE  type 
)

Definition at line 448 of file object.c.

449 {
451 
452  ASSERT(ht);
453 
454  if (!(entry = handle_to_entry(ht, handle )) || entry->type != type)
455  {
456  return NULL;
457  }
458  return entry->ptr;
459 }
PUSER_HANDLE_ENTRY handle_to_entry(PUSER_HANDLE_TABLE ht, HANDLE handle)
Definition: object.c:308
uint8_t entry
Definition: isohybrid.c:63
GLuint GLuint GLsizei GLenum type
Definition: gl.h:1545
smooth NULL
Definition: ftsmooth.c:416
Definition: ntuser.h:19
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
static const struct newhuff ht[]
Definition: huffman.h:296

Referenced by NC_IconForWindow(), NtUserSetCursor(), and ValidateHwndNoErr().

◆ UserInitHandleTable()

VOID UserInitHandleTable ( PUSER_HANDLE_TABLE  ht,
PVOID  mem,
ULONG  bytes 
)

Definition at line 374 of file object.c.

375 {
376  ht->freelist = NULL;
377  ht->handles = mem;
378 
379  ht->nb_handles = 0;
380  ht->allocated_handles = bytes / sizeof(USER_HANDLE_ENTRY);
381 }
static unsigned char bytes[4]
Definition: adnsresfilter.c:74
smooth NULL
Definition: ftsmooth.c:416
struct _USER_HANDLE_ENTRY USER_HANDLE_ENTRY
static const struct newhuff ht[]
Definition: huffman.h:296
Definition: mem.c:156

Referenced by UserCreateHandleTable().

◆ UserMarkObjectDestroy()

BOOL FASTCALL UserMarkObjectDestroy ( PVOID  Object)

Definition at line 587 of file object.c.

588 {
590  PHEAD ObjHead = Object;
591 
592  entry = handle_to_entry(gHandleTable, ObjHead->h);
593 
594  ASSERT(entry != NULL);
595 
596  entry->flags |= HANDLEENTRY_DESTROY;
597 
598  if (ObjHead->cLockObj > 1)
599  {
600  entry->flags &= ~HANDLEENTRY_INDESTROY;
601  TRACE("Count %d\n",ObjHead->cLockObj);
602  return FALSE;
603  }
604 
605  return TRUE;
606 }
#define TRUE
Definition: types.h:120
PUSER_HANDLE_ENTRY handle_to_entry(PUSER_HANDLE_TABLE ht, HANDLE handle)
Definition: object.c:308
HANDLE h
Definition: ntuser.h:176
uint8_t entry
Definition: isohybrid.c:63
smooth NULL
Definition: ftsmooth.c:416
Definition: ntuser.h:174
Definition: ntuser.h:19
#define TRACE(s)
Definition: solgame.cpp:4
static IUnknown Object
Definition: main.c:512
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
DWORD cLockObj
Definition: ntuser.h:177
#define HANDLEENTRY_DESTROY
Definition: ntuser.h:16
#define HANDLEENTRY_INDESTROY
Definition: ntuser.h:17
PUSER_HANDLE_TABLE gHandleTable
Definition: object.c:13

Referenced by co_UserFreeWindow(), and IntDestroyMenuObject().

◆ UserObjectInDestroy()

BOOL FASTCALL UserObjectInDestroy ( HANDLE  h)

Definition at line 669 of file object.c.

670 {
672 
673  if (!(entry = handle_to_entry( gHandleTable, h )))
674  {
676  return TRUE;
677  }
678  return (entry->flags & HANDLEENTRY_INDESTROY);
679 }
#define TRUE
Definition: types.h:120
PUSER_HANDLE_ENTRY handle_to_entry(PUSER_HANDLE_TABLE ht, HANDLE handle)
Definition: object.c:308
uint8_t entry
Definition: isohybrid.c:63
#define STATUS_INVALID_HANDLE
Definition: ntstatus.h:231
GLfloat GLfloat GLfloat GLfloat h
Definition: glext.h:7723
Definition: ntuser.h:19
VOID FASTCALL SetLastNtError(NTSTATUS Status)
Definition: error.c:36
#define HANDLEENTRY_INDESTROY
Definition: ntuser.h:17
PUSER_HANDLE_TABLE gHandleTable
Definition: object.c:13

Referenced by co_CallHook(), IntDestroyClass(), IntSetMenuItemInfo(), NtUserSetCursor(), UserAttachThreadInput(), UserGetCurIconObject(), VerifyMenu(), and VerifyWnd().

◆ UserReferenceObject()

◆ UserReferenceObjectByHandle()

PVOID FASTCALL UserReferenceObjectByHandle ( HANDLE  handle,
HANDLE_TYPE  type 
)

Definition at line 707 of file object.c.

708 {
709  PVOID object;
710 
712  if (object)
713  {
714  UserReferenceObject(object);
715  }
716  return object;
717 }
GLuint GLuint GLsizei GLenum type
Definition: gl.h:1545
PVOID UserGetObject(PUSER_HANDLE_TABLE ht, HANDLE handle, HANDLE_TYPE type)
Definition: object.c:462
PUSER_HANDLE_TABLE gHandleTable
Definition: object.c:13
void * object
Definition: jmemsys.h:48
VOID FASTCALL UserReferenceObject(PVOID obj)
Definition: object.c:697

Referenced by UserGetCurIconObject().

Variable Documentation

◆ gHandleTable

◆ ObjectAlloc

PVOID(* ObjectAlloc) (PDESKTOP, PTHREADINFO, SIZE_T, PVOID *)

Definition at line 218 of file object.c.

Referenced by UserCreateObject().

◆ ObjectCallbacks

const { ... } ObjectCallbacks[TYPE_CTYPES]
Initial value:
=
{
{ NULL, NULL, NULL },
{ AllocDeskThreadObject, co_UserDestroyWindow, FreeDeskThreadObject },
{ AllocDeskProcObject, UserDestroyMenuObject, FreeDeskProcObject },
{ AllocProcMarkObject, IntDestroyCurIconObject, FreeCurIconObject },
{ AllocSysObject, NULL, FreeSysObject },
{ AllocDeskThreadObject, IntRemoveHook, FreeDeskThreadObject },
{ AllocSysObject, NULL,FreeSysObject },
{ AllocDeskProcObject, DestroyCallProc, FreeDeskProcObject },
{ AllocProcMarkObject, UserDestroyAccelTable, FreeProcMarkObject },
{ NULL, NULL, NULL },
{ NULL, NULL, NULL },
{ NULL, NULL, NULL },
{ AllocSysObject, NULL, FreeSysObject },
{ AllocSysObject, NULL,FreeSysObject },
{ AllocSysObject, NULL, FreeSysObject },
{ AllocThreadObject, IntRemoveEvent, FreeThreadObject },
{ AllocSysObject, NULL, FreeSysObject },
{ NULL, NULL, NULL },
{ NULL, NULL, NULL },
{ NULL, NULL, NULL },
{ NULL, NULL, NULL },
{ NULL, NULL, NULL },
}
BOOLEAN IntRemoveHook(PVOID Object)
Definition: hook.c:1037
BOOLEAN UserDestroyMenuObject(PVOID Object)
Definition: menu.c:315
BOOLEAN UserDestroyAccelTable(PVOID Object)
Definition: accelerator.c:328
BOOLEAN co_UserDestroyWindow(PVOID Object)
Definition: window.c:2629
BOOLEAN DestroyCallProc(_Inout_ PVOID Object)
Definition: callproc.c:22
smooth NULL
Definition: ftsmooth.c:416
void FreeProcMarkObject(_In_ PVOID Object)
Definition: object.c:175
static void FreeDeskProcObject(_In_ PVOID Object)
Definition: object.c:134
BOOLEAN IntRemoveEvent(PVOID Object)
Definition: event.c:127
static void FreeDeskThreadObject(_In_ PVOID Object)
Definition: object.c:89
static void FreeSysObject(_In_ PVOID Object)
Definition: object.c:210
VOID FreeCurIconObject(_In_ PVOID Object)
Definition: cursoricon.c:332
BOOLEAN IntDestroyCurIconObject(_In_ PVOID Object)
Definition: cursoricon.c:313
static void FreeThreadObject(_In_ PVOID Object)
Definition: object.c:45

Referenced by UserCreateObject(), UserDereferenceObject(), and UserDestroyObjectsForOwner().

◆ ObjectDestroy

BOOLEAN(* ObjectDestroy) (PVOID)

Definition at line 219 of file object.c.

◆ ObjectFree

void(* ObjectFree) (PVOID)

Definition at line 220 of file object.c.

Referenced by UserDereferenceObject().