2003-05-18 17:16:18 +00:00
|
|
|
/*
|
2005-09-07 20:59:26 +00:00
|
|
|
* Server-side USER handles
|
2003-05-18 17:16:18 +00:00
|
|
|
*
|
2005-09-07 20:59:26 +00:00
|
|
|
* Copyright (C) 2001 Alexandre Julliard
|
2003-05-18 17:16:18 +00:00
|
|
|
*
|
2005-09-07 20:59:26 +00:00
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
2003-05-18 17:16:18 +00:00
|
|
|
*
|
2005-09-07 20:59:26 +00:00
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
2001-06-12 17:51:51 +00:00
|
|
|
*
|
2005-09-07 20:59:26 +00:00
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
2009-10-27 10:34:16 +00:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
2001-06-12 17:51:51 +00:00
|
|
|
*/
|
2005-09-07 20:59:26 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
2002-01-27 01:11:24 +00:00
|
|
|
/* INCLUDES ******************************************************************/
|
|
|
|
|
2010-04-26 13:58:46 +00:00
|
|
|
#include <win32k.h>
|
2001-06-12 17:51:51 +00:00
|
|
|
|
|
|
|
#define NDEBUG
|
|
|
|
#include <debug.h>
|
|
|
|
|
2009-07-25 00:41:22 +00:00
|
|
|
//int usedHandles=0;
|
2006-04-05 08:05:55 +00:00
|
|
|
PUSER_HANDLE_TABLE gHandleTable = NULL;
|
2001-06-12 17:51:51 +00:00
|
|
|
|
|
|
|
|
2005-09-07 20:59:26 +00:00
|
|
|
PUSER_HANDLE_ENTRY handle_to_entry(PUSER_HANDLE_TABLE ht, HANDLE handle )
|
2001-06-12 17:51:51 +00:00
|
|
|
{
|
2005-09-07 21:25:42 +00:00
|
|
|
unsigned short generation;
|
|
|
|
int index = (((unsigned int)handle & 0xffff) - FIRST_USER_HANDLE) >> 1;
|
|
|
|
if (index < 0 || index >= ht->nb_handles)
|
|
|
|
return NULL;
|
|
|
|
if (!ht->handles[index].type)
|
|
|
|
return NULL;
|
|
|
|
generation = (unsigned int)handle >> 16;
|
|
|
|
if (generation == ht->handles[index].generation || !generation || generation == 0xffff)
|
|
|
|
return &ht->handles[index];
|
|
|
|
return NULL;
|
2005-09-07 20:59:26 +00:00
|
|
|
}
|
2005-05-08 02:11:54 +00:00
|
|
|
|
2005-11-28 23:35:35 +00:00
|
|
|
__inline static HANDLE entry_to_handle(PUSER_HANDLE_TABLE ht, PUSER_HANDLE_ENTRY ptr )
|
2005-09-07 20:59:26 +00:00
|
|
|
{
|
2005-09-07 21:25:42 +00:00
|
|
|
int index = ptr - ht->handles;
|
|
|
|
return (HANDLE)(((index << 1) + FIRST_USER_HANDLE) + (ptr->generation << 16));
|
2001-06-12 17:51:51 +00:00
|
|
|
}
|
|
|
|
|
2005-11-28 23:35:35 +00:00
|
|
|
__inline static PUSER_HANDLE_ENTRY alloc_user_entry(PUSER_HANDLE_TABLE ht)
|
2001-06-12 17:51:51 +00:00
|
|
|
{
|
2005-09-07 21:25:42 +00:00
|
|
|
PUSER_HANDLE_ENTRY entry;
|
|
|
|
|
2009-07-25 00:41:22 +00:00
|
|
|
DPRINT("handles used %i\n",gpsi->cHandleEntries);
|
2005-09-11 14:48:32 +00:00
|
|
|
|
2005-09-07 21:25:42 +00:00
|
|
|
if (ht->freelist)
|
|
|
|
{
|
|
|
|
entry = ht->freelist;
|
|
|
|
ht->freelist = entry->ptr;
|
|
|
|
|
2009-07-25 00:41:22 +00:00
|
|
|
gpsi->cHandleEntries++;
|
2005-09-07 21:25:42 +00:00
|
|
|
return entry;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ht->nb_handles >= ht->allocated_handles) /* need to grow the array */
|
|
|
|
{
|
2007-12-20 02:36:38 +00:00
|
|
|
/**/
|
2008-02-13 00:46:23 +00:00
|
|
|
int i, iFree = 0, iWindow = 0, iMenu = 0, iCursorIcon = 0,
|
2009-01-14 02:02:26 +00:00
|
|
|
iHook = 0, iCallProc = 0, iAccel = 0, iMonitor = 0, iTimer = 0;
|
2007-12-20 02:36:38 +00:00
|
|
|
/**/
|
2009-07-25 00:41:22 +00:00
|
|
|
DPRINT1("Out of user handles! Used -> %i, NM_Handle -> %d\n", gpsi->cHandleEntries, ht->nb_handles);
|
2007-12-20 02:36:38 +00:00
|
|
|
//#if 0
|
|
|
|
for(i = 0; i < ht->nb_handles; i++)
|
|
|
|
{
|
|
|
|
switch (ht->handles[i].type)
|
|
|
|
{
|
|
|
|
case otFree: // Should be zero.
|
|
|
|
iFree++;
|
|
|
|
break;
|
|
|
|
case otWindow:
|
|
|
|
iWindow++;
|
|
|
|
break;
|
|
|
|
case otMenu:
|
|
|
|
iMenu++;
|
|
|
|
break;
|
|
|
|
case otCursorIcon:
|
|
|
|
iCursorIcon++;
|
|
|
|
break;
|
|
|
|
case otHook:
|
|
|
|
iHook++;
|
|
|
|
break;
|
|
|
|
case otCallProc:
|
|
|
|
iCallProc++;
|
|
|
|
break;
|
|
|
|
case otAccel:
|
|
|
|
iAccel++;
|
|
|
|
break;
|
|
|
|
case otMonitor:
|
|
|
|
iMonitor++;
|
|
|
|
break;
|
2009-01-14 02:02:26 +00:00
|
|
|
case otTimer:
|
2009-01-14 07:09:25 +00:00
|
|
|
iTimer++;
|
2009-01-14 02:02:26 +00:00
|
|
|
break;
|
2007-12-20 02:36:38 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2009-01-14 02:02:26 +00:00
|
|
|
DPRINT1("Handle Count by Type:\n Free = %d Window = %d Menu = %d CursorIcon = %d Hook = %d\n CallProc = %d Accel = %d Monitor = %d Timer = %d\n",
|
|
|
|
iFree, iWindow, iMenu, iCursorIcon, iHook, iCallProc, iAccel, iMonitor, iTimer );
|
2008-02-13 00:46:23 +00:00
|
|
|
//#endif
|
2005-09-07 21:25:42 +00:00
|
|
|
return NULL;
|
2005-09-07 20:59:26 +00:00
|
|
|
#if 0
|
2006-04-05 08:05:55 +00:00
|
|
|
PUSER_HANDLE_ENTRY new_handles;
|
2005-09-07 21:25:42 +00:00
|
|
|
/* grow array by 50% (but at minimum 32 entries) */
|
2006-04-05 08:05:55 +00:00
|
|
|
int growth = max( 32, ht->allocated_handles / 2 );
|
|
|
|
int new_size = min( ht->allocated_handles + growth, (LAST_USER_HANDLE-FIRST_USER_HANDLE+1) >> 1 );
|
|
|
|
if (new_size <= ht->allocated_handles)
|
2005-09-07 21:25:42 +00:00
|
|
|
return NULL;
|
2006-04-05 08:05:55 +00:00
|
|
|
if (!(new_handles = UserHeapReAlloc( ht->handles, new_size * sizeof(*ht->handles) )))
|
2005-09-07 21:25:42 +00:00
|
|
|
return NULL;
|
2006-04-05 08:05:55 +00:00
|
|
|
ht->handles = new_handles;
|
|
|
|
ht->allocated_handles = new_size;
|
2005-09-07 21:25:42 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
entry = &ht->handles[ht->nb_handles++];
|
|
|
|
|
|
|
|
entry->generation = 1;
|
|
|
|
|
2009-07-25 00:41:22 +00:00
|
|
|
gpsi->cHandleEntries++;
|
2005-09-07 21:25:42 +00:00
|
|
|
|
|
|
|
return entry;
|
2001-06-12 17:51:51 +00:00
|
|
|
}
|
|
|
|
|
2005-09-07 20:59:26 +00:00
|
|
|
VOID UserInitHandleTable(PUSER_HANDLE_TABLE ht, PVOID mem, ULONG bytes)
|
2001-06-12 17:51:51 +00:00
|
|
|
{
|
2005-09-07 20:59:26 +00:00
|
|
|
ht->freelist = NULL;
|
|
|
|
ht->handles = mem;
|
2005-09-07 21:25:42 +00:00
|
|
|
|
|
|
|
ht->nb_handles = 0;
|
2005-09-07 20:59:26 +00:00
|
|
|
ht->allocated_handles = bytes / sizeof(USER_HANDLE_ENTRY);
|
2001-06-12 17:51:51 +00:00
|
|
|
}
|
|
|
|
|
2005-11-28 23:35:35 +00:00
|
|
|
__inline static void *free_user_entry(PUSER_HANDLE_TABLE ht, PUSER_HANDLE_ENTRY entry)
|
2001-06-12 17:51:51 +00:00
|
|
|
{
|
2005-09-07 21:25:42 +00:00
|
|
|
void *ret;
|
|
|
|
ret = entry->ptr;
|
|
|
|
entry->ptr = ht->freelist;
|
|
|
|
entry->type = 0;
|
2010-01-14 13:33:04 +00:00
|
|
|
entry->flags = 0;
|
2007-11-15 05:42:44 +00:00
|
|
|
entry->pi = NULL;
|
2005-09-07 21:25:42 +00:00
|
|
|
ht->freelist = entry;
|
|
|
|
|
2009-07-25 00:41:22 +00:00
|
|
|
gpsi->cHandleEntries--;
|
2005-09-07 21:25:42 +00:00
|
|
|
|
|
|
|
return ret;
|
2001-06-12 17:51:51 +00:00
|
|
|
}
|
|
|
|
|
2007-11-15 05:42:44 +00:00
|
|
|
static __inline PVOID
|
|
|
|
UserHandleOwnerByType(USER_OBJECT_TYPE type)
|
|
|
|
{
|
|
|
|
PVOID pi;
|
|
|
|
|
|
|
|
switch (type)
|
|
|
|
{
|
|
|
|
case otWindow:
|
2010-01-15 13:47:25 +00:00
|
|
|
case otInputContext:
|
2007-11-15 05:42:44 +00:00
|
|
|
pi = GetW32ThreadInfo();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case otMenu:
|
|
|
|
case otCursorIcon:
|
|
|
|
case otHook:
|
|
|
|
case otCallProc:
|
|
|
|
case otAccel:
|
|
|
|
pi = GetW32ProcessInfo();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case otMonitor:
|
|
|
|
pi = NULL; /* System */
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
pi = NULL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return pi;
|
|
|
|
}
|
|
|
|
|
2005-09-07 20:59:26 +00:00
|
|
|
/* allocate a user handle for a given object */
|
|
|
|
HANDLE UserAllocHandle(PUSER_HANDLE_TABLE ht, PVOID object, USER_OBJECT_TYPE type )
|
2001-06-12 17:51:51 +00:00
|
|
|
{
|
2005-09-07 21:25:42 +00:00
|
|
|
PUSER_HANDLE_ENTRY entry = alloc_user_entry(ht);
|
|
|
|
if (!entry)
|
|
|
|
return 0;
|
|
|
|
entry->ptr = object;
|
|
|
|
entry->type = type;
|
2010-01-14 13:33:04 +00:00
|
|
|
entry->flags = 0;
|
2007-11-15 05:42:44 +00:00
|
|
|
entry->pi = UserHandleOwnerByType(type);
|
2005-09-07 21:25:42 +00:00
|
|
|
if (++entry->generation >= 0xffff)
|
|
|
|
entry->generation = 1;
|
2008-02-13 00:46:23 +00:00
|
|
|
|
|
|
|
/* We have created a handle, which is a reference! */
|
|
|
|
UserReferenceObject(object);
|
|
|
|
|
2005-09-07 21:25:42 +00:00
|
|
|
return entry_to_handle(ht, entry );
|
2001-06-12 17:51:51 +00:00
|
|
|
}
|
|
|
|
|
2005-09-07 20:59:26 +00:00
|
|
|
/* return a pointer to a user object from its handle */
|
|
|
|
PVOID UserGetObject(PUSER_HANDLE_TABLE ht, HANDLE handle, USER_OBJECT_TYPE type )
|
2001-06-12 17:51:51 +00:00
|
|
|
{
|
2005-09-07 21:25:42 +00:00
|
|
|
PUSER_HANDLE_ENTRY entry;
|
2005-05-08 02:11:54 +00:00
|
|
|
|
2005-09-07 21:25:42 +00:00
|
|
|
ASSERT(ht);
|
2001-06-12 17:51:51 +00:00
|
|
|
|
2005-09-07 21:25:42 +00:00
|
|
|
if (!(entry = handle_to_entry(ht, handle )) || entry->type != type)
|
|
|
|
{
|
|
|
|
SetLastWin32Error(ERROR_INVALID_HANDLE);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
return entry->ptr;
|
2001-06-12 17:51:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-09-07 20:59:26 +00:00
|
|
|
/* get the full handle (32bit) for a possibly truncated (16bit) handle */
|
|
|
|
HANDLE get_user_full_handle(PUSER_HANDLE_TABLE ht, HANDLE handle )
|
2001-06-12 17:51:51 +00:00
|
|
|
{
|
2005-09-07 21:25:42 +00:00
|
|
|
PUSER_HANDLE_ENTRY entry;
|
2001-06-12 17:51:51 +00:00
|
|
|
|
2005-09-07 21:25:42 +00:00
|
|
|
if ((unsigned int)handle >> 16)
|
|
|
|
return handle;
|
|
|
|
if (!(entry = handle_to_entry(ht, handle )))
|
|
|
|
return handle;
|
|
|
|
return entry_to_handle( ht, entry );
|
2001-06-12 17:51:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-09-07 20:59:26 +00:00
|
|
|
/* same as get_user_object plus set the handle to the full 32-bit value */
|
|
|
|
void *get_user_object_handle(PUSER_HANDLE_TABLE ht, HANDLE* handle, USER_OBJECT_TYPE type )
|
2001-06-12 17:51:51 +00:00
|
|
|
{
|
2005-09-07 21:25:42 +00:00
|
|
|
PUSER_HANDLE_ENTRY entry;
|
2005-05-08 02:11:54 +00:00
|
|
|
|
2005-09-07 21:25:42 +00:00
|
|
|
if (!(entry = handle_to_entry(ht, *handle )) || entry->type != type)
|
|
|
|
return NULL;
|
|
|
|
*handle = entry_to_handle( ht, entry );
|
|
|
|
return entry->ptr;
|
2001-06-12 17:51:51 +00:00
|
|
|
}
|
|
|
|
|
2005-09-07 20:59:26 +00:00
|
|
|
/* return the next user handle after 'handle' that is of a given type */
|
|
|
|
PVOID UserGetNextHandle(PUSER_HANDLE_TABLE ht, HANDLE* handle, USER_OBJECT_TYPE type )
|
2001-06-12 17:51:51 +00:00
|
|
|
{
|
2005-09-07 21:25:42 +00:00
|
|
|
PUSER_HANDLE_ENTRY entry;
|
|
|
|
|
|
|
|
if (!*handle)
|
|
|
|
entry = ht->handles;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
int index = (((unsigned int)*handle & 0xffff) - FIRST_USER_HANDLE) >> 1;
|
|
|
|
if (index < 0 || index >= ht->nb_handles)
|
|
|
|
return NULL;
|
|
|
|
entry = ht->handles + index + 1; /* start from the next one */
|
|
|
|
}
|
|
|
|
while (entry < ht->handles + ht->nb_handles)
|
|
|
|
{
|
|
|
|
if (!type || entry->type == type)
|
|
|
|
{
|
|
|
|
*handle = entry_to_handle(ht, entry );
|
|
|
|
return entry->ptr;
|
|
|
|
}
|
|
|
|
entry++;
|
|
|
|
}
|
|
|
|
return NULL;
|
2005-09-07 20:59:26 +00:00
|
|
|
}
|
2005-05-08 02:11:54 +00:00
|
|
|
|
2009-08-24 20:09:58 +00:00
|
|
|
BOOL FASTCALL UserCreateHandleTable(VOID)
|
2001-06-12 17:51:51 +00:00
|
|
|
{
|
2005-09-07 21:25:42 +00:00
|
|
|
|
2005-09-07 20:59:26 +00:00
|
|
|
PVOID mem;
|
|
|
|
|
|
|
|
//FIXME: dont alloc all at once! must be mapped into umode also...
|
2006-04-05 08:05:55 +00:00
|
|
|
//mem = ExAllocatePool(PagedPool, sizeof(USER_HANDLE_ENTRY) * 1024*2);
|
|
|
|
mem = UserHeapAlloc(sizeof(USER_HANDLE_ENTRY) * 1024*2);
|
2005-09-07 20:59:26 +00:00
|
|
|
if (!mem)
|
|
|
|
{
|
|
|
|
DPRINT1("Failed creating handle table\n");
|
|
|
|
return FALSE;
|
|
|
|
}
|
2005-09-07 21:25:42 +00:00
|
|
|
|
2006-04-05 08:05:55 +00:00
|
|
|
gHandleTable = UserHeapAlloc(sizeof(USER_HANDLE_TABLE));
|
|
|
|
if (gHandleTable == NULL)
|
|
|
|
{
|
|
|
|
UserHeapFree(mem);
|
|
|
|
DPRINT1("Failed creating handle table\n");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2005-09-07 20:59:26 +00:00
|
|
|
//FIXME: make auto growable
|
2006-04-05 08:05:55 +00:00
|
|
|
UserInitHandleTable(gHandleTable, mem, sizeof(USER_HANDLE_ENTRY) * 1024*2);
|
2005-09-07 21:25:42 +00:00
|
|
|
|
2005-09-07 20:59:26 +00:00
|
|
|
return TRUE;
|
2001-06-12 17:51:51 +00:00
|
|
|
}
|
2010-01-14 13:33:04 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// New
|
|
|
|
//
|
|
|
|
PVOID
|
|
|
|
FASTCALL
|
2010-01-15 13:47:25 +00:00
|
|
|
UserCreateObject( PUSER_HANDLE_TABLE ht,
|
|
|
|
PDESKTOP pDesktop,
|
|
|
|
HANDLE* h,
|
|
|
|
USER_OBJECT_TYPE type,
|
|
|
|
ULONG size)
|
2010-01-14 13:33:04 +00:00
|
|
|
{
|
|
|
|
HANDLE hi;
|
|
|
|
PVOID Object;
|
|
|
|
PTHREADINFO pti;
|
|
|
|
PPROCESSINFO ppi;
|
|
|
|
BOOL dt;
|
2010-01-15 13:47:25 +00:00
|
|
|
PDESKTOP rpdesk = pDesktop;
|
2010-01-14 13:33:04 +00:00
|
|
|
|
|
|
|
pti = GetW32ThreadInfo();
|
|
|
|
ppi = pti->ppi;
|
2010-01-15 13:47:25 +00:00
|
|
|
if (!pDesktop) rpdesk = pti->rpdesk;
|
2010-01-14 13:33:04 +00:00
|
|
|
|
|
|
|
switch (type)
|
|
|
|
{
|
2010-01-15 13:47:25 +00:00
|
|
|
// case otWindow:
|
|
|
|
// case otMenu:
|
|
|
|
// case otHook:
|
|
|
|
// case otCallProc:
|
|
|
|
case otInputContext:
|
|
|
|
Object = DesktopHeapAlloc(rpdesk, size);
|
2010-01-14 13:33:04 +00:00
|
|
|
dt = TRUE;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
Object = UserHeapAlloc(size);
|
|
|
|
dt = FALSE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!Object)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
|
|
hi = UserAllocHandle(ht, Object, type );
|
|
|
|
if (!hi)
|
|
|
|
{
|
|
|
|
if (dt)
|
2010-01-15 13:47:25 +00:00
|
|
|
DesktopHeapFree(rpdesk, Object);
|
2010-01-14 13:33:04 +00:00
|
|
|
else
|
|
|
|
UserHeapFree(Object);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
RtlZeroMemory(Object, size);
|
|
|
|
|
|
|
|
switch (type)
|
|
|
|
{
|
|
|
|
case otWindow:
|
|
|
|
case otHook:
|
2010-01-15 13:47:25 +00:00
|
|
|
case otInputContext:
|
|
|
|
((PTHRDESKHEAD)Object)->rpdesk = rpdesk;
|
2010-01-14 13:33:04 +00:00
|
|
|
((PTHRDESKHEAD)Object)->pSelf = Object;
|
|
|
|
case otEvent:
|
|
|
|
((PTHROBJHEAD)Object)->pti = pti;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case otMenu:
|
|
|
|
case otCallProc:
|
2010-01-15 13:47:25 +00:00
|
|
|
((PPROCDESKHEAD)Object)->rpdesk = rpdesk;
|
2010-01-14 13:33:04 +00:00
|
|
|
((PPROCDESKHEAD)Object)->pSelf = Object;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case otCursorIcon:
|
|
|
|
((PPROCMARKHEAD)Object)->ppi = ppi;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
/* Now set default headers. */
|
|
|
|
((PHEAD)Object)->h = hi;
|
|
|
|
((PHEAD)Object)->cLockObj = 2; // we need this, because we create 2 refs: handle and pointer!
|
|
|
|
|
|
|
|
if (h)
|
|
|
|
*h = hi;
|
|
|
|
return Object;
|
|
|
|
}
|
|
|
|
|
2010-01-15 13:47:25 +00:00
|
|
|
|
2010-01-14 13:33:04 +00:00
|
|
|
BOOL
|
|
|
|
FASTCALL
|
2010-01-16 05:56:22 +00:00
|
|
|
UserDereferenceObject(PVOID object)
|
2010-01-14 13:33:04 +00:00
|
|
|
{
|
|
|
|
PUSER_HANDLE_ENTRY entry;
|
|
|
|
USER_OBJECT_TYPE type;
|
|
|
|
|
2010-01-16 05:56:22 +00:00
|
|
|
ASSERT(((PHEAD)object)->cLockObj >= 1);
|
|
|
|
|
|
|
|
if ((INT)--((PHEAD)object)->cLockObj <= 0)
|
2010-01-14 13:33:04 +00:00
|
|
|
{
|
2010-01-16 05:56:22 +00:00
|
|
|
entry = handle_to_entry(gHandleTable, ((PHEAD)object)->h );
|
2010-01-14 13:33:04 +00:00
|
|
|
|
2010-01-16 05:56:22 +00:00
|
|
|
DPRINT("warning! Dereference to zero! Obj -> 0x%x\n", object);
|
|
|
|
|
|
|
|
((PHEAD)object)->cLockObj = 0;
|
|
|
|
|
|
|
|
if (!(entry->flags & HANDLEENTRY_INDESTROY))
|
|
|
|
return TRUE;
|
2010-01-14 13:33:04 +00:00
|
|
|
|
|
|
|
type = entry->type;
|
2010-01-16 05:56:22 +00:00
|
|
|
free_user_entry(gHandleTable, entry );
|
2010-01-14 13:33:04 +00:00
|
|
|
|
2010-01-15 13:47:25 +00:00
|
|
|
switch (type)
|
2010-01-14 13:33:04 +00:00
|
|
|
{
|
2010-01-15 13:47:25 +00:00
|
|
|
// case otWindow:
|
|
|
|
// case otMenu:
|
|
|
|
// case otHook:
|
|
|
|
// case otCallProc:
|
|
|
|
case otInputContext:
|
|
|
|
return DesktopHeapFree(((PTHRDESKHEAD)object)->rpdesk, object);
|
|
|
|
|
|
|
|
default:
|
|
|
|
return UserHeapFree(object);
|
2010-01-14 13:33:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2010-01-16 05:56:22 +00:00
|
|
|
BOOL
|
|
|
|
FASTCALL
|
|
|
|
UserFreeHandle(PUSER_HANDLE_TABLE ht, HANDLE handle )
|
|
|
|
{
|
|
|
|
PUSER_HANDLE_ENTRY entry;
|
|
|
|
|
|
|
|
if (!(entry = handle_to_entry( ht, handle )))
|
|
|
|
{
|
|
|
|
SetLastNtError( STATUS_INVALID_HANDLE );
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
entry->flags = HANDLEENTRY_INDESTROY;
|
|
|
|
|
|
|
|
return UserDereferenceObject(entry->ptr);
|
|
|
|
}
|
|
|
|
|
2010-01-14 13:33:04 +00:00
|
|
|
BOOL
|
|
|
|
FASTCALL
|
2010-01-15 13:47:25 +00:00
|
|
|
UserDeleteObject(HANDLE h, USER_OBJECT_TYPE type )
|
2010-01-14 13:33:04 +00:00
|
|
|
{
|
|
|
|
PVOID body = UserGetObject(gHandleTable, h, type);
|
|
|
|
|
|
|
|
if (!body) return FALSE;
|
|
|
|
|
|
|
|
ASSERT( ((PHEAD)body)->cLockObj >= 1);
|
|
|
|
|
2010-01-15 13:47:25 +00:00
|
|
|
return UserFreeHandle(gHandleTable, h);
|
2010-01-14 13:33:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
VOID
|
|
|
|
FASTCALL
|
2010-01-15 13:47:25 +00:00
|
|
|
UserReferenceObject(PVOID obj)
|
2010-01-14 13:33:04 +00:00
|
|
|
{
|
|
|
|
ASSERT(((PHEAD)obj)->cLockObj >= 0);
|
|
|
|
|
|
|
|
((PHEAD)obj)->cLockObj++;
|
|
|
|
}
|
|
|
|
|
|
|
|
PVOID
|
|
|
|
FASTCALL
|
2010-01-15 13:47:25 +00:00
|
|
|
UserReferenceObjectByHandle(HANDLE handle, USER_OBJECT_TYPE type)
|
2010-01-14 13:33:04 +00:00
|
|
|
{
|
|
|
|
PVOID object;
|
|
|
|
|
|
|
|
object = UserGetObject(gHandleTable, handle, type);
|
|
|
|
if (object)
|
|
|
|
{
|
2010-01-15 13:47:25 +00:00
|
|
|
UserReferenceObject(object);
|
2010-01-14 13:33:04 +00:00
|
|
|
}
|
|
|
|
return object;
|
|
|
|
}
|