/* $Id$ */
/** @file
* HGCMObjects - Host-Guest Communication Manager objects
*/
/*
* Copyright (C) 2006-2010 Oracle Corporation
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* General Public License (GPL) as published by the Free Software
* Foundation, in version 2 as it comes in the "COPYING" file of the
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
*/
#include "Logging.h"
#include "HGCMObjects.h"
/* There are internal handles, which are not saved,
* and client handles, which are saved.
* They use different range of values:
* 1..7FFFFFFF for clients,
* 0x80000001..0xFFFFFFFF for other handles.
*/
{
return RTCritSectEnter (&g_critsect);
}
{
}
int hgcmObjInit (void)
{
LogFlow(("MAIN::hgcmObjInit\n"));
g_u32InternalHandleCount = 0x80000000;
return rc;
}
void hgcmObjUninit (void)
{
if (RTCritSectIsInitialized (&g_critsect))
{
}
}
{
int handle = 0;
if (RT_SUCCESS(rc))
{
/* Generate a new handle value. */
for (;;)
{
if (u32HandleIn == 0)
{
{
/* Rollover. Something is wrong. */
break;
}
/* 0 and 0x80000000 are not valid handles. */
if ((Key & 0x7FFFFFFF) == 0)
{
/* Over the invalid value, reinitialize the source. */
0:
0x80000000;
continue;
}
}
else
{
Key = u32HandleIn;
}
/* Insert object to AVL tree. */
/* Could not insert a handle. */
if (!bRC)
{
if (u32HandleIn == 0)
{
/* Try another generated handle. */
continue;
}
else
{
/* Could not use the specified handle. */
break;
}
}
/* Initialize backlink. */
/* Reference the object for time while it resides in the tree. */
/* Store returned handle. */
break;
}
hgcmObjLeave ();
}
else
{
AssertReleaseMsgFailed (("MAIN::hgcmObjGenerateHandle: Failed to acquire object pool semaphore"));
}
return handle;
}
{
return hgcmObjMake (pObject, 0);
}
{
}
{
if (handle)
{
rc = hgcmObjEnter ();
if (RT_SUCCESS(rc))
{
if (pCore)
{
}
hgcmObjLeave ();
}
else
{
}
}
return;
}
{
if ((handle & 0x7FFFFFFF) == 0)
{
return pObject;
}
if (RT_SUCCESS(rc))
{
if ( pCore
{
}
hgcmObjLeave ();
}
else
{
}
return pObject;
}
{
pObject->Dereference ();
LogFlow(("MAIN::hgcmObjDereference: return\n"));
}
{
return g_u32ClientHandleCount;
}
{
if (RT_SUCCESS(rc))
{
hgcmObjLeave ();
}
}