GuestImpl.cpp revision ba94b5e24d2365d9aebd9b98ec5854e4da161567
/* $Id$ */
/** @file
* VirtualBox COM class implementation: Guest features.
*/
/*
* Copyright (C) 2006-2014 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 "GuestImpl.h"
#include "GuestSessionImpl.h"
#include "Global.h"
#include "ConsoleImpl.h"
#include "ProgressImpl.h"
#ifdef VBOX_WITH_DRAG_AND_DROP
# include "GuestDnDPrivate.h"
#endif
#include "VMMDev.h"
#include "AutoCaller.h"
#include "Logging.h"
#include "Performance.h"
#include "VBoxEvents.h"
// defines
/////////////////////////////////////////////////////////////////////////////
// constructor / destructor
/////////////////////////////////////////////////////////////////////////////
{
return BaseFinalConstruct();
}
void Guest::FinalRelease()
{
uninit();
}
// public methods only for internal purposes
/////////////////////////////////////////////////////////////////////////////
/**
* Initializes the guest object.
*/
{
/* Enclose the state transition NotReady->InInit->Ready */
AutoInitSpan autoInitSpan(this);
/* Confirm a successful initialization when it's the case */
else
mMemoryBalloonSize = 0; /* Default is no ballooning */
else
mfPageFusionEnabled = false; /* Default is no page fusion*/
mStatUpdateInterval = 0; /* Default is not to report guest statistics at all */
mCollectVMMStats = false;
/* Clear statistics. */
mNetStatRx = mNetStatTx = 0;
for (unsigned i = 0 ; i < GUESTSTATTYPE_MAX; i++)
mCurrentGuestStat[i] = 0;
&Guest::i_staticUpdateStats, this);
#ifdef VBOX_WITH_GUEST_CONTROL
#else
#endif
#ifdef VBOX_WITH_DRAG_AND_DROP
try
{
{
}
}
{
hr = E_OUTOFMEMORY;
}
#endif
return hr;
}
/**
* Uninitializes the instance and sets the ready flag to FALSE.
* Called either from FinalRelease() or by the parent when it gets destroyed.
*/
{
LogFlowThisFunc(("\n"));
/* Enclose the state transition Ready->InUninit->NotReady */
AutoUninitSpan autoUninitSpan(this);
if (autoUninitSpan.uninitDone())
return;
/* Destroy stat update timer */
mStatTimer = NULL;
mMagic = 0;
#ifdef VBOX_WITH_GUEST_CONTROL
LogFlowThisFunc(("Closing sessions (%RU64 total)\n",
{
# ifdef DEBUG
# endif
itSessions++;
}
#endif
#ifdef VBOX_WITH_DRAG_AND_DROP
#endif
#ifdef VBOX_WITH_GUEST_CONTROL
#endif
}
/* static */
{
}
/* static */
int Guest::i_staticEnumStatsCallback(const char *pszName, STAMTYPE enmType, void *pvSample, STAMUNIT enmUnit,
{
AssertLogRelMsgReturn(enmType == STAMTYPE_COUNTER, ("Unexpected sample type %d ('%s')\n", enmType, pszName), VINF_SUCCESS);
AssertLogRelMsgReturn(enmUnit == STAMUNIT_BYTES, ("Unexpected sample unit %d ('%s')\n", enmUnit, pszName), VINF_SUCCESS);
/* Get the base name w/ slash. */
/* Receive or transmit? */
bool fRx;
fRx = true;
fRx = false;
else
#if 0 /* not used for anything, so don't bother parsing it. */
do
--pszLastSlash;
pszLastSlash++;
#endif
/* Add the bytes to our counters. */
#if 0
#else
#endif
if (fRx)
else
return VINF_SUCCESS;
}
{
uint64_t cbFreeTotal = 0;
uint64_t cbAllocTotal = 0;
uint64_t cbBalloonedTotal = 0;
uint64_t cbSharedTotal = 0;
uint64_t cbSharedMem = 0;
ULONG uNetStatRx = 0;
ULONG uNetStatTx = 0;
/* Check if we have anything to report */
if (validStats)
{
}
/*
* Calling SessionMachine may take time as the object resides in VBoxSVC
* process. This is why we took a snapshot of currently collected stats
* and released the lock.
*/
{
int rc;
/*
* There is no point in collecting VM shared memory if other memory
* statistics are not available yet. Or is there?
*/
if (validStats)
{
/* Query the missing per-VM memory statistics. */
rc = PGMR3QueryMemoryStats(ptrVM.rawUVM(), &cbTotalMemIgn, &cbPrivateMemIgn, &cbSharedMem, &cbZeroMemIgn);
if (rc == VINF_SUCCESS)
}
if (mCollectVMMStats)
{
rc = PGMR3QueryGlobalMemoryStats(ptrVM.rawUVM(), &cbAllocTotal, &cbFreeTotal, &cbBalloonedTotal, &cbSharedTotal);
if (rc == VINF_SUCCESS)
}
mNetStatRx = mNetStatTx = 0;
if (cNsPassed >= 1000)
{
uNetStatRx = (ULONG)((mNetStatRx - uRxPrev) * 1000000 / (cNsPassed / 1000)); /* in bytes per second */
uNetStatTx = (ULONG)((mNetStatTx - uTxPrev) * 1000000 / (cNsPassed / 1000)); /* in bytes per second */
LogFlowThisFunc(("Net Rx=%llu Tx=%llu Ts=%llu Delta=%llu\n", mNetStatRx, mNetStatTx, uTsNow, cNsPassed));
}
else
{
/* Can happen on resume or if we're using a non-monotonic clock
source for the timer and the time is adjusted. */
}
}
/* Convert the units for RAM usage stats: page (4K) -> 1KB units */
}
// IGuest properties
/////////////////////////////////////////////////////////////////////////////
{
else
{
/* Redirect the call to IMachine if no additions are installed. */
}
return hrc;
}
{
return S_OK;
}
{
/*
* Return the ReportGuestInfo2 version info if available.
*/
else
{
/*
* If we're running older guest additions (< 3.2.0) try get it from
* the guest properties. Detected switched around Version and
* Revision in early 3.1.x releases (see r57115).
*/
hrc = ptrMachine->GetGuestPropertyValue(Bstr("/VirtualBox/GuestAdd/Version").raw(), bstr.asOutParam());
{
hrc = ptrMachine->GetGuestPropertyValue(Bstr("/VirtualBox/GuestAdd/Revision").raw(), bstr.asOutParam());
}
else
{
/* Returning 1.4 is better than nothing. */
}
}
return hrc;
}
{
/*
* Return the ReportGuestInfo2 version info if available.
*/
else
{
/*
* If we're running older guest additions (< 3.2.0) try get it from
* the guest properties. Detected switched around Version and
* Revision in early 3.1.x releases (see r57115).
*/
hrc = ptrMachine->GetGuestPropertyValue(Bstr("/VirtualBox/GuestAdd/Revision").raw(), bstr.asOutParam());
{
{
hrc = ptrMachine->GetGuestPropertyValue(Bstr("/VirtualBox/GuestAdd/Version").raw(), bstr.asOutParam());
{
}
}
if (vrc == VINF_SUCCESS)
else
}
{
/* Return 0 if we don't know. */
*aAdditionsRevision = 0;
}
}
return hrc;
}
{
#ifndef VBOX_WITH_DRAG_AND_DROP
#else
/* No need to lock - lifetime constant. */
return hr;
#endif /* VBOX_WITH_DRAG_AND_DROP */
}
{
#ifndef VBOX_WITH_DRAG_AND_DROP
#else
/* No need to lock - lifetime constant. */
return hr;
#endif /* VBOX_WITH_DRAG_AND_DROP */
}
{
#ifndef VBOX_WITH_GUEST_CONTROL
#else
/* No need to lock - lifetime constant. */
return S_OK;
#endif /* VBOX_WITH_GUEST_CONTROL */
}
{
size_t i = 0;
return S_OK;
}
{
size_t i = 0;
for (GuestSessions::iterator it = mData.mGuestSessions.begin(); it != mData.mGuestSessions.end(); ++it, ++i)
return S_OK;
}
{
return mfPageFusionEnabled;
}
{
return S_OK;
}
{
/* We must be 100% sure that IMachine::COMSETTER(MemoryBalloonSize)
* does not call us back in any way! */
{
/* forward the information to the VMM device */
/* MUST release all locks before calling VMM device as its critsect
* has higher lock order than anything in Main. */
if (pVMMDev)
{
if (pVMMDevPort)
}
}
return ret;
}
{
return S_OK;
}
{
if (mStatUpdateInterval)
if (aStatisticsUpdateInterval == 0)
else
else
if (aStatisticsUpdateInterval != 0)
{
RTTimerLRStart(mStatTimer, 0);
}
/* forward the information to the VMM device */
/* MUST release all locks before calling VMM device as its critsect
* has higher lock order than anything in Main. */
if (pVMMDev)
{
if (pVMMDevPort)
}
return S_OK;
}
{
*aMemBalloon = mCurrentGuestStat[GUESTSTATTYPE_MEMBALLOON] * (_4K/_1K); /* page (4K) -> 1KB units */
/* Play safe or smth? */
*aMemAllocTotal = 0;
*aMemFreeTotal = 0;
*aMemBalloonTotal = 0;
*aMemSharedTotal = 0;
*aMemShared = 0;
/* MUST release all locks before calling any PGM statistics queries,
* as they are executed by EMT and that might deadlock us by VMM device
* activity which waits for the Guest object lock. */
return E_FAIL;
int rc = PGMR3QueryGlobalMemoryStats(ptrVM.rawUVM(), &cbAllocTotal, &cbFreeTotal, &cbBalloonedTotal, &cbSharedTotal);
/* Query the missing per-VM memory statistics. */
rc = PGMR3QueryMemoryStats(ptrVM.rawUVM(), &cbTotalMemIgn, &cbPrivateMemIgn, &cbSharedMem, &cbZeroMemIgn);
return S_OK;
}
{
static ULONG indexToPerfMask[] =
{
};
AutoCaller autoCaller(this);
if (enmType >= GUESTSTATTYPE_MAX)
return E_INVALIDARG;
return S_OK;
}
/**
* Returns the status of a specified Guest Additions facility.
*
* @return aStatus Current status of specified facility.
* @param aType Facility to get the status from.
* @param aTimestamp Timestamp of last facility status update in ms (optional).
*/
HRESULT Guest::getFacilityStatus(AdditionsFacilityType_T aFacility, LONG64 *aTimestamp, AdditionsFacilityStatus_T *aStatus)
{
/* Not checking for aTimestamp is intentional; it's optional. */
{
if (aTimestamp)
}
else
{
/*
* Do not fail here -- could be that the facility never has been brought up (yet) but
* the host wants to have its status anyway. So just tell we don't know at this point.
*/
if (aTimestamp)
*aTimestamp = RTTimeMilliTS();
}
return S_OK;
}
{
switch (aLevel)
{
break;
break;
break;
default:
break;
}
return rc;
}
{
/* Check for magic domain names which are used to pass encryption keys to the disk. */
{
/** @todo */
return E_NOTIMPL;
}
else
{
/* forward the information to the VMM device */
if (pVMMDev)
{
if (pVMMDevPort)
{
if (!aAllowInteractiveLogon)
u32Flags);
return S_OK;
}
}
}
return setError(VBOX_E_VM_ERROR,
tr("VMM device is not available (is the VM running?)"));
}
// public methods only for internal purposes
/////////////////////////////////////////////////////////////////////////////
/**
* Sets the general Guest Additions information like
* API (interface) version and OS type. Gets called by
* vmmdevUpdateGuestInfo.
*
* @param aInterfaceVersion
* @param aOsType
*/
{
AutoCaller autoCaller(this);
/*
* Note: The Guest Additions API (interface) version is deprecated
* and will not be used anymore! We might need it to at least report
* something as version number if *really* ancient Guest Additions are
* installed (without the guest version + revision properties having set).
*/
/*
* Older Additions rely on the Additions API version whether they
* are assumed to be active or not. Since newer Additions do report
* the Additions version *before* calling this function (by calling
* VMMDevReportGuestInfo2, VMMDevReportGuestStatus, VMMDevReportGuestInfo,
* in that order) we can tell apart old and new Additions here. Old
* Additions never would set VMMDevReportGuestInfo2 (which set mData.mAdditionsVersion)
* so they just rely on the aInterfaceVersion string (which gets set by
* VMMDevReportGuestInfo).
*
* So only mark the Additions as being active (run level = system) when we
* don't have the Additions version set.
*/
{
if (aInterfaceVersion.isEmpty())
else
{
/*
* To keep it compatible with the old Guest Additions behavior we need to set the
* "graphics" (feature) facility to active as soon as we got the Guest Additions
* interface version.
*/
i_facilityUpdate(VBoxGuestFacilityType_Graphics, VBoxGuestFacilityStatus_Active, 0 /*fFlags*/, &TimeSpecTS);
}
}
/*
* Older Additions didn't have this finer grained capability bit,
* so enable it by default. Newer Additions will not enable this here
* and use the setSupportedFeatures function instead.
*/
/** @todo r=bird: I don't get the above comment nor the code below...
* One talks about capability bits, the one always does something to a facility.
* Then there is the comment below it all, which is placed like it addresses the
* mOSTypeId, but talks about something which doesn't remotely like mOSTypeId...
*
* Andy, could you please try clarify and make the comments shorter and more
* coherent! Also, explain why this is important and what depends on it.
*
* PS. There is the VMMDEV_GUEST_SUPPORTS_GRAPHICS capability* report... It
* should come in pretty quickly after this update, normally.
*/
0 /*fFlags*/, &TimeSpecTS); /** @todo the timestamp isn't gonna be right here on saved state restore. */
/*
* Note! There is a race going on between setting mAdditionsRunLevel and
* its real status when using new(er) Guest Additions.
*/
}
/**
* Sets the Guest Additions version information details.
*
* Gets called by vmmdevUpdateGuestInfo2 and vmmdevUpdateGuestInfo (to clear the
* state).
*
* @param a_uFullVersion VBoxGuestInfo2::additionsMajor,
* VBoxGuestInfo2::additionsMinor and
* VBoxGuestInfo2::additionsBuild combined into
* one value by VBOX_FULL_VERSION_MAKE.
*
* When this is 0, it's vmmdevUpdateGuestInfo
* calling to reset the state.
*
* string if neiter of those are present.
* @param a_uRevision See VBoxGuestInfo2::additionsRevision.
* @param a_fFeatures See VBoxGuestInfo2::additionsFeatures.
*/
void Guest::i_setAdditionsInfo2(uint32_t a_uFullVersion, const char *a_pszName, uint32_t a_uRevision, uint32_t a_fFeatures)
{
if (a_uFullVersion)
{
}
else
{
mData.mAdditionsRevision = 0;
mData.mAdditionsFeatures = 0;
}
}
{
{
}
return false;
}
void Guest::i_facilityUpdate(VBoxGuestFacilityType a_enmFacility, VBoxGuestFacilityStatus a_enmStatus,
{
{
}
else
{
{
/* The easy way out for now. We could automatically destroy
inactive facilities like VMMDev does if we like... */
}
HRESULT hrc = ptrFac->init(this, (AdditionsFacilityType_T)a_enmFacility, (AdditionsFacilityStatus_T)a_enmStatus,
}
}
/**
* Issued by the guest when a guest user changed its state.
*
* @return IPRT status code.
* @param aUser Guest user name.
* @param aDomain Domain of guest user account. Optional.
* @param enmState New state to indicate.
* @param puDetails Pointer to state details. Optional.
* @param cbDetails Size (in bytes) of state details. Pass 0 if not used.
*/
{
LogFlowThisFunc(("\n"));
AutoCaller autoCaller(this);
}
/**
* Sets the status of a certain Guest Additions facility.
*
* Gets called by vmmdevUpdateGuestStatus, which just passes the report along.
*
* @param a_pInterface Pointer to this interface.
* @param a_enmFacility The facility.
* @param a_enmStatus The status.
* @param a_fFlags Flags assoicated with the update. Currently
* reserved and should be ignored.
* @param a_pTimeSpecTS Pointer to the timestamp of this report.
* @sa PDMIVMMDEVCONNECTOR::pfnUpdateGuestStatus, vmmdevUpdateGuestStatus
* @thread The emulation thread.
*/
void Guest::i_setAdditionsStatus(VBoxGuestFacilityType a_enmFacility, VBoxGuestFacilityStatus a_enmStatus,
{
AutoCaller autoCaller(this);
/*
* Set a specific facility status.
*/
else /* Update one facility only. */
/*
* Recalc the runlevel.
*/
else
}
/**
* Sets the supported features (and whether they are active or not).
*
* @param fCaps Guest capability bit mask (VMMDEV_GUEST_SUPPORTS_XXX).
*/
{
AutoCaller autoCaller(this);
/** @todo A nit: The timestamp is wrong on saved state restore. Would be better
* to move the graphics and seamless capability -> facility translation to
* VMMDev so this could be saved. */
aCaps & VMMDEV_GUEST_SUPPORTS_SEAMLESS ? VBoxGuestFacilityStatus_Active : VBoxGuestFacilityStatus_Inactive,
0 /*fFlags*/, &TimeSpecTS);
/** @todo Add VMMDEV_GUEST_SUPPORTS_GUEST_HOST_WINDOW_MAPPING */
aCaps & VMMDEV_GUEST_SUPPORTS_GRAPHICS ? VBoxGuestFacilityStatus_Active : VBoxGuestFacilityStatus_Inactive,
0 /*fFlags*/, &TimeSpecTS);
}