[9360] | 1 | /* $Id: GuestImpl.cpp 99739 2023-05-11 01:01:08Z vboxsync $ */
|
---|
[1] | 2 | /** @file
|
---|
[51476] | 3 | * VirtualBox COM class implementation: Guest features.
|
---|
[1] | 4 | */
|
---|
| 5 |
|
---|
| 6 | /*
|
---|
[98103] | 7 | * Copyright (C) 2006-2023 Oracle and/or its affiliates.
|
---|
[1] | 8 | *
|
---|
[96407] | 9 | * This file is part of VirtualBox base platform packages, as
|
---|
| 10 | * available from https://www.virtualbox.org.
|
---|
| 11 | *
|
---|
| 12 | * This program is free software; you can redistribute it and/or
|
---|
| 13 | * modify it under the terms of the GNU General Public License
|
---|
| 14 | * as published by the Free Software Foundation, in version 3 of the
|
---|
| 15 | * License.
|
---|
| 16 | *
|
---|
| 17 | * This program is distributed in the hope that it will be useful, but
|
---|
| 18 | * WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
| 20 | * General Public License for more details.
|
---|
| 21 | *
|
---|
| 22 | * You should have received a copy of the GNU General Public License
|
---|
| 23 | * along with this program; if not, see <https://www.gnu.org/licenses>.
|
---|
| 24 | *
|
---|
| 25 | * SPDX-License-Identifier: GPL-3.0-only
|
---|
[1] | 26 | */
|
---|
| 27 |
|
---|
[67914] | 28 | #define LOG_GROUP LOG_GROUP_MAIN_GUEST
|
---|
| 29 | #include "LoggingNew.h"
|
---|
| 30 |
|
---|
[1] | 31 | #include "GuestImpl.h"
|
---|
[55644] | 32 | #ifdef VBOX_WITH_GUEST_CONTROL
|
---|
| 33 | # include "GuestSessionImpl.h"
|
---|
| 34 | #endif
|
---|
[9360] | 35 | #include "Global.h"
|
---|
[1] | 36 | #include "ConsoleImpl.h"
|
---|
[28132] | 37 | #include "ProgressImpl.h"
|
---|
[39450] | 38 | #ifdef VBOX_WITH_DRAG_AND_DROP
|
---|
[51476] | 39 | # include "GuestDnDPrivate.h"
|
---|
[39450] | 40 | #endif
|
---|
[1] | 41 | #include "VMMDev.h"
|
---|
| 42 |
|
---|
[25860] | 43 | #include "AutoCaller.h"
|
---|
[40084] | 44 | #include "Performance.h"
|
---|
[47294] | 45 | #include "VBoxEvents.h"
|
---|
[1] | 46 |
|
---|
[21219] | 47 | #include <VBox/VMMDev.h>
|
---|
[25346] | 48 | #include <iprt/cpp/utils.h>
|
---|
[43908] | 49 | #include <iprt/ctype.h>
|
---|
| 50 | #include <iprt/stream.h>
|
---|
[40084] | 51 | #include <iprt/timer.h>
|
---|
[35346] | 52 | #include <VBox/vmm/pgm.h>
|
---|
[93444] | 53 | #include <VBox/vmm/vmmr3vtable.h>
|
---|
[39882] | 54 | #include <VBox/version.h>
|
---|
[1] | 55 |
|
---|
| 56 | // defines
|
---|
| 57 | /////////////////////////////////////////////////////////////////////////////
|
---|
| 58 |
|
---|
| 59 | // constructor / destructor
|
---|
| 60 | /////////////////////////////////////////////////////////////////////////////
|
---|
| 61 |
|
---|
[42817] | 62 | DEFINE_EMPTY_CTOR_DTOR(Guest)
|
---|
[2567] | 63 |
|
---|
[1] | 64 | HRESULT Guest::FinalConstruct()
|
---|
| 65 | {
|
---|
[35638] | 66 | return BaseFinalConstruct();
|
---|
[1] | 67 | }
|
---|
| 68 |
|
---|
| 69 | void Guest::FinalRelease()
|
---|
| 70 | {
|
---|
[42817] | 71 | uninit();
|
---|
[35638] | 72 | BaseFinalRelease();
|
---|
[1] | 73 | }
|
---|
| 74 |
|
---|
| 75 | // public methods only for internal purposes
|
---|
| 76 | /////////////////////////////////////////////////////////////////////////////
|
---|
| 77 |
|
---|
| 78 | /**
|
---|
| 79 | * Initializes the guest object.
|
---|
| 80 | */
|
---|
[33492] | 81 | HRESULT Guest::init(Console *aParent)
|
---|
[1] | 82 | {
|
---|
[21878] | 83 | LogFlowThisFunc(("aParent=%p\n", aParent));
|
---|
[1] | 84 |
|
---|
[26235] | 85 | ComAssertRet(aParent, E_INVALIDARG);
|
---|
[1] | 86 |
|
---|
[2567] | 87 | /* Enclose the state transition NotReady->InInit->Ready */
|
---|
[21878] | 88 | AutoInitSpan autoInitSpan(this);
|
---|
| 89 | AssertReturn(autoInitSpan.isOk(), E_FAIL);
|
---|
[1] | 90 |
|
---|
[21878] | 91 | unconst(mParent) = aParent;
|
---|
[1] | 92 |
|
---|
[79294] | 93 | ULONG aMemoryBalloonSize = 0;
|
---|
[51612] | 94 | HRESULT hr = mParent->i_machine()->COMGETTER(MemoryBalloonSize)(&aMemoryBalloonSize);
|
---|
[79294] | 95 | if (SUCCEEDED(hr))
|
---|
[4529] | 96 | mMemoryBalloonSize = aMemoryBalloonSize;
|
---|
| 97 | else
|
---|
[45415] | 98 | mMemoryBalloonSize = 0; /* Default is no ballooning */
|
---|
[4321] | 99 |
|
---|
[79294] | 100 | BOOL fPageFusionEnabled = FALSE;
|
---|
[51612] | 101 | hr = mParent->i_machine()->COMGETTER(PageFusionEnabled)(&fPageFusionEnabled);
|
---|
[79294] | 102 | if (SUCCEEDED(hr))
|
---|
[29589] | 103 | mfPageFusionEnabled = fPageFusionEnabled;
|
---|
| 104 | else
|
---|
[45415] | 105 | mfPageFusionEnabled = false; /* Default is no page fusion*/
|
---|
[29589] | 106 |
|
---|
[45415] | 107 | mStatUpdateInterval = 0; /* Default is not to report guest statistics at all */
|
---|
[40084] | 108 | mCollectVMMStats = false;
|
---|
[27896] | 109 |
|
---|
| 110 | /* Clear statistics. */
|
---|
[43908] | 111 | mNetStatRx = mNetStatTx = 0;
|
---|
| 112 | mNetStatLastTs = RTTimeNanoTS();
|
---|
[27896] | 113 | for (unsigned i = 0 ; i < GUESTSTATTYPE_MAX; i++)
|
---|
| 114 | mCurrentGuestStat[i] = 0;
|
---|
[43908] | 115 | mVmValidStats = pm::VMSTATMASK_NONE;
|
---|
[56470] | 116 | RT_ZERO(mCurrentGuestCpuUserStat);
|
---|
| 117 | RT_ZERO(mCurrentGuestCpuKernelStat);
|
---|
| 118 | RT_ZERO(mCurrentGuestCpuIdleStat);
|
---|
[27896] | 119 |
|
---|
[40084] | 120 | mMagic = GUEST_MAGIC;
|
---|
[80670] | 121 | mStatTimer = NIL_RTTIMERLR;
|
---|
[40084] | 122 |
|
---|
[47469] | 123 | hr = unconst(mEventSource).createObject();
|
---|
| 124 | if (SUCCEEDED(hr))
|
---|
[50544] | 125 | hr = mEventSource->init();
|
---|
[45415] | 126 |
|
---|
[56470] | 127 | mCpus = 1;
|
---|
| 128 |
|
---|
[51476] | 129 | #ifdef VBOX_WITH_DRAG_AND_DROP
|
---|
[79294] | 130 | if (SUCCEEDED(hr))
|
---|
[42867] | 131 | {
|
---|
[79294] | 132 | try
|
---|
[51476] | 133 | {
|
---|
[79294] | 134 | GuestDnD::createInstance(this /* pGuest */);
|
---|
| 135 | hr = unconst(mDnDSource).createObject();
|
---|
[51476] | 136 | if (SUCCEEDED(hr))
|
---|
[79294] | 137 | hr = mDnDSource->init(this /* pGuest */);
|
---|
| 138 | if (SUCCEEDED(hr))
|
---|
| 139 | {
|
---|
| 140 | hr = unconst(mDnDTarget).createObject();
|
---|
| 141 | if (SUCCEEDED(hr))
|
---|
| 142 | hr = mDnDTarget->init(this /* pGuest */);
|
---|
| 143 | }
|
---|
| 144 |
|
---|
| 145 | LogFlowFunc(("Drag and drop initializied with hr=%Rhrc\n", hr));
|
---|
[51476] | 146 | }
|
---|
[79294] | 147 | catch (std::bad_alloc &)
|
---|
| 148 | {
|
---|
| 149 | hr = E_OUTOFMEMORY;
|
---|
| 150 | }
|
---|
[42867] | 151 | }
|
---|
[51476] | 152 | #endif
|
---|
[39450] | 153 |
|
---|
[79294] | 154 | /* Confirm a successful initialization when it's the case: */
|
---|
| 155 | if (SUCCEEDED(hr))
|
---|
| 156 | autoInitSpan.setSucceeded();
|
---|
| 157 | else
|
---|
| 158 | autoInitSpan.setFailed();
|
---|
| 159 |
|
---|
[51476] | 160 | LogFlowFunc(("hr=%Rhrc\n", hr));
|
---|
[45415] | 161 | return hr;
|
---|
[1] | 162 | }
|
---|
| 163 |
|
---|
| 164 | /**
|
---|
[30758] | 165 | * Uninitializes the instance and sets the ready flag to FALSE.
|
---|
| 166 | * Called either from FinalRelease() or by the parent when it gets destroyed.
|
---|
[1] | 167 | */
|
---|
| 168 | void Guest::uninit()
|
---|
| 169 | {
|
---|
[21878] | 170 | LogFlowThisFunc(("\n"));
|
---|
[1] | 171 |
|
---|
[40020] | 172 | /* Enclose the state transition Ready->InUninit->NotReady */
|
---|
| 173 | AutoUninitSpan autoUninitSpan(this);
|
---|
| 174 | if (autoUninitSpan.uninitDone())
|
---|
| 175 | return;
|
---|
| 176 |
|
---|
[40084] | 177 | /* Destroy stat update timer */
|
---|
[42817] | 178 | int vrc = RTTimerLRDestroy(mStatTimer);
|
---|
| 179 | AssertMsgRC(vrc, ("Failed to create guest statistics update timer(%Rra)\n", vrc));
|
---|
[80670] | 180 | mStatTimer = NIL_RTTIMERLR;
|
---|
[40084] | 181 | mMagic = 0;
|
---|
| 182 |
|
---|
[42867] | 183 | #ifdef VBOX_WITH_GUEST_CONTROL
|
---|
[42897] | 184 | LogFlowThisFunc(("Closing sessions (%RU64 total)\n",
|
---|
| 185 | mData.mGuestSessions.size()));
|
---|
[42867] | 186 | GuestSessions::iterator itSessions = mData.mGuestSessions.begin();
|
---|
| 187 | while (itSessions != mData.mGuestSessions.end())
|
---|
| 188 | {
|
---|
[51476] | 189 | # ifdef DEBUG
|
---|
[78234] | 190 | /** @todo r=bird: hit a use-after-free situation here while debugging the
|
---|
| 191 | * 0xcccccccc status code issue in copyto. My bet is that this happens
|
---|
| 192 | * because of an uninit race, where GuestSession::close(), or someone, does
|
---|
| 193 | * not ensure that the parent object (Guest) is okay to use (in the AutoCaller
|
---|
| 194 | * sense), only their own object. */
|
---|
[42897] | 195 | ULONG cRefs = itSessions->second->AddRef();
|
---|
[49389] | 196 | LogFlowThisFunc(("sessionID=%RU32, cRefs=%RU32\n", itSessions->first, cRefs > 1 ? cRefs - 1 : 0));
|
---|
[42897] | 197 | itSessions->second->Release();
|
---|
[51476] | 198 | # endif
|
---|
[42897] | 199 | itSessions->second->uninit();
|
---|
[56030] | 200 | ++itSessions;
|
---|
[42867] | 201 | }
|
---|
| 202 | mData.mGuestSessions.clear();
|
---|
| 203 | #endif
|
---|
| 204 |
|
---|
[39450] | 205 | #ifdef VBOX_WITH_DRAG_AND_DROP
|
---|
[51476] | 206 | GuestDnD::destroyInstance();
|
---|
| 207 | unconst(mDnDSource).setNull();
|
---|
| 208 | unconst(mDnDTarget).setNull();
|
---|
[39450] | 209 | #endif
|
---|
| 210 |
|
---|
[45415] | 211 | unconst(mEventSource).setNull();
|
---|
[27607] | 212 | unconst(mParent) = NULL;
|
---|
[42897] | 213 |
|
---|
| 214 | LogFlowFuncLeave();
|
---|
[1] | 215 | }
|
---|
| 216 |
|
---|
[40084] | 217 | /* static */
|
---|
[52082] | 218 | DECLCALLBACK(void) Guest::i_staticUpdateStats(RTTIMERLR hTimerLR, void *pvUser, uint64_t iTick)
|
---|
[40084] | 219 | {
|
---|
[42817] | 220 | AssertReturnVoid(pvUser != NULL);
|
---|
| 221 | Guest *guest = static_cast<Guest *>(pvUser);
|
---|
[40084] | 222 | Assert(guest->mMagic == GUEST_MAGIC);
|
---|
| 223 | if (guest->mMagic == GUEST_MAGIC)
|
---|
[52082] | 224 | guest->i_updateStats(iTick);
|
---|
[40084] | 225 |
|
---|
[42817] | 226 | NOREF(hTimerLR);
|
---|
[40084] | 227 | }
|
---|
| 228 |
|
---|
[43908] | 229 | /* static */
|
---|
[57425] | 230 | DECLCALLBACK(int) Guest::i_staticEnumStatsCallback(const char *pszName, STAMTYPE enmType, void *pvSample,
|
---|
[93468] | 231 | STAMUNIT enmUnit, const char *pszUnit, STAMVISIBILITY enmVisiblity,
|
---|
[57425] | 232 | const char *pszDesc, void *pvUser)
|
---|
[43908] | 233 | {
|
---|
[93468] | 234 | RT_NOREF(enmVisiblity, pszDesc, pszUnit);
|
---|
[46456] | 235 | AssertLogRelMsgReturn(enmType == STAMTYPE_COUNTER, ("Unexpected sample type %d ('%s')\n", enmType, pszName), VINF_SUCCESS);
|
---|
| 236 | AssertLogRelMsgReturn(enmUnit == STAMUNIT_BYTES, ("Unexpected sample unit %d ('%s')\n", enmUnit, pszName), VINF_SUCCESS);
|
---|
[43908] | 237 |
|
---|
[46456] | 238 | /* Get the base name w/ slash. */
|
---|
| 239 | const char *pszLastSlash = strrchr(pszName, '/');
|
---|
| 240 | AssertLogRelMsgReturn(pszLastSlash, ("Unexpected sample '%s'\n", pszName), VINF_SUCCESS);
|
---|
| 241 |
|
---|
| 242 | /* Receive or transmit? */
|
---|
| 243 | bool fRx;
|
---|
| 244 | if (!strcmp(pszLastSlash, "/BytesReceived"))
|
---|
| 245 | fRx = true;
|
---|
| 246 | else if (!strcmp(pszLastSlash, "/BytesTransmitted"))
|
---|
| 247 | fRx = false;
|
---|
[43908] | 248 | else
|
---|
[46456] | 249 | AssertLogRelMsgFailedReturn(("Unexpected sample '%s'\n", pszName), VINF_SUCCESS);
|
---|
[43908] | 250 |
|
---|
[46456] | 251 | #if 0 /* not used for anything, so don't bother parsing it. */
|
---|
| 252 | /* Find start of instance number. ASSUMES '/Public/Net/Name<Instance digits>/Bytes...' */
|
---|
| 253 | do
|
---|
| 254 | --pszLastSlash;
|
---|
| 255 | while (pszLastSlash > pszName && RT_C_IS_DIGIT(*pszLastSlash));
|
---|
| 256 | pszLastSlash++;
|
---|
| 257 |
|
---|
| 258 | uint8_t uInstance;
|
---|
[94954] | 259 | int vrc = RTStrToUInt8Ex(pszLastSlash, NULL, 10, &uInstance);
|
---|
| 260 | AssertLogRelMsgReturn(RT_SUCCESS(vrc) && vrc != VWRN_NUMBER_TOO_BIG && vrc != VWRN_NEGATIVE_UNSIGNED,
|
---|
| 261 | ("%Rrc '%s'\n", vrc, pszName), VINF_SUCCESS)
|
---|
[46456] | 262 | #endif
|
---|
| 263 |
|
---|
| 264 | /* Add the bytes to our counters. */
|
---|
| 265 | PSTAMCOUNTER pCnt = (PSTAMCOUNTER)pvSample;
|
---|
| 266 | Guest *pGuest = (Guest *)pvUser;
|
---|
| 267 | uint64_t cb = pCnt->c;
|
---|
| 268 | #if 0
|
---|
| 269 | LogFlowFunc(("%s i=%u d=%s %llu bytes\n", pszName, uInstance, fRx ? "RX" : "TX", cb));
|
---|
| 270 | #else
|
---|
| 271 | LogFlowFunc(("%s d=%s %llu bytes\n", pszName, fRx ? "RX" : "TX", cb));
|
---|
| 272 | #endif
|
---|
| 273 | if (fRx)
|
---|
| 274 | pGuest->mNetStatRx += cb;
|
---|
| 275 | else
|
---|
| 276 | pGuest->mNetStatTx += cb;
|
---|
| 277 |
|
---|
[43908] | 278 | return VINF_SUCCESS;
|
---|
| 279 | }
|
---|
| 280 |
|
---|
[52082] | 281 | void Guest::i_updateStats(uint64_t iTick)
|
---|
[40084] | 282 | {
|
---|
[63244] | 283 | RT_NOREF(iTick);
|
---|
| 284 |
|
---|
[44347] | 285 | uint64_t cbFreeTotal = 0;
|
---|
| 286 | uint64_t cbAllocTotal = 0;
|
---|
| 287 | uint64_t cbBalloonedTotal = 0;
|
---|
| 288 | uint64_t cbSharedTotal = 0;
|
---|
| 289 | uint64_t cbSharedMem = 0;
|
---|
| 290 | ULONG uNetStatRx = 0;
|
---|
| 291 | ULONG uNetStatTx = 0;
|
---|
| 292 | ULONG aGuestStats[GUESTSTATTYPE_MAX];
|
---|
| 293 | RT_ZERO(aGuestStats);
|
---|
[40084] | 294 |
|
---|
| 295 | AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
| 296 |
|
---|
[43908] | 297 | ULONG validStats = mVmValidStats;
|
---|
[40084] | 298 | /* Check if we have anything to report */
|
---|
| 299 | if (validStats)
|
---|
| 300 | {
|
---|
[43908] | 301 | mVmValidStats = pm::VMSTATMASK_NONE;
|
---|
[40084] | 302 | memcpy(aGuestStats, mCurrentGuestStat, sizeof(aGuestStats));
|
---|
| 303 | }
|
---|
| 304 | alock.release();
|
---|
[44347] | 305 |
|
---|
[40084] | 306 | /*
|
---|
| 307 | * Calling SessionMachine may take time as the object resides in VBoxSVC
|
---|
| 308 | * process. This is why we took a snapshot of currently collected stats
|
---|
| 309 | * and released the lock.
|
---|
| 310 | */
|
---|
[45674] | 311 | Console::SafeVMPtrQuiet ptrVM(mParent);
|
---|
[44347] | 312 | if (ptrVM.isOk())
|
---|
[40084] | 313 | {
|
---|
[94954] | 314 | int vrc;
|
---|
[40084] | 315 |
|
---|
| 316 | /*
|
---|
| 317 | * There is no point in collecting VM shared memory if other memory
|
---|
[44903] | 318 | * statistics are not available yet. Or is there?
|
---|
[40084] | 319 | */
|
---|
| 320 | if (validStats)
|
---|
| 321 | {
|
---|
| 322 | /* Query the missing per-VM memory statistics. */
|
---|
[44347] | 323 | uint64_t cbTotalMemIgn, cbPrivateMemIgn, cbZeroMemIgn;
|
---|
[94954] | 324 | vrc = ptrVM.vtable()->pfnPGMR3QueryMemoryStats(ptrVM.rawUVM(), &cbTotalMemIgn, &cbPrivateMemIgn,
|
---|
| 325 | &cbSharedMem, &cbZeroMemIgn);
|
---|
| 326 | if (vrc == VINF_SUCCESS)
|
---|
[43908] | 327 | validStats |= pm::VMSTATMASK_GUEST_MEMSHARED;
|
---|
[40084] | 328 | }
|
---|
| 329 |
|
---|
| 330 | if (mCollectVMMStats)
|
---|
| 331 | {
|
---|
[94954] | 332 | vrc = ptrVM.vtable()->pfnPGMR3QueryGlobalMemoryStats(ptrVM.rawUVM(), &cbAllocTotal, &cbFreeTotal,
|
---|
| 333 | &cbBalloonedTotal, &cbSharedTotal);
|
---|
| 334 | AssertRC(vrc);
|
---|
| 335 | if (vrc == VINF_SUCCESS)
|
---|
[44903] | 336 | validStats |= pm::VMSTATMASK_VMM_ALLOC | pm::VMSTATMASK_VMM_FREE
|
---|
| 337 | | pm::VMSTATMASK_VMM_BALOON | pm::VMSTATMASK_VMM_SHARED;
|
---|
[40084] | 338 | }
|
---|
| 339 |
|
---|
[43908] | 340 | uint64_t uRxPrev = mNetStatRx;
|
---|
| 341 | uint64_t uTxPrev = mNetStatTx;
|
---|
| 342 | mNetStatRx = mNetStatTx = 0;
|
---|
[94954] | 343 | vrc = ptrVM.vtable()->pfnSTAMR3Enum(ptrVM.rawUVM(), "/Public/Net/*/Bytes*", i_staticEnumStatsCallback, this);
|
---|
| 344 | AssertRC(vrc);
|
---|
[44903] | 345 |
|
---|
[43908] | 346 | uint64_t uTsNow = RTTimeNanoTS();
|
---|
[44903] | 347 | uint64_t cNsPassed = uTsNow - mNetStatLastTs;
|
---|
| 348 | if (cNsPassed >= 1000)
|
---|
| 349 | {
|
---|
| 350 | mNetStatLastTs = uTsNow;
|
---|
| 351 |
|
---|
| 352 | uNetStatRx = (ULONG)((mNetStatRx - uRxPrev) * 1000000 / (cNsPassed / 1000)); /* in bytes per second */
|
---|
| 353 | uNetStatTx = (ULONG)((mNetStatTx - uTxPrev) * 1000000 / (cNsPassed / 1000)); /* in bytes per second */
|
---|
| 354 | validStats |= pm::VMSTATMASK_NET_RX | pm::VMSTATMASK_NET_TX;
|
---|
| 355 | LogFlowThisFunc(("Net Rx=%llu Tx=%llu Ts=%llu Delta=%llu\n", mNetStatRx, mNetStatTx, uTsNow, cNsPassed));
|
---|
| 356 | }
|
---|
| 357 | else
|
---|
| 358 | {
|
---|
| 359 | /* Can happen on resume or if we're using a non-monotonic clock
|
---|
| 360 | source for the timer and the time is adjusted. */
|
---|
| 361 | mNetStatRx = uRxPrev;
|
---|
| 362 | mNetStatTx = uTxPrev;
|
---|
| 363 | LogThisFunc(("Net Ts=%llu cNsPassed=%llu - too small interval\n", uTsNow, cNsPassed));
|
---|
| 364 | }
|
---|
[40084] | 365 | }
|
---|
| 366 |
|
---|
[51612] | 367 | mParent->i_reportVmStatistics(validStats,
|
---|
| 368 | aGuestStats[GUESTSTATTYPE_CPUUSER],
|
---|
| 369 | aGuestStats[GUESTSTATTYPE_CPUKERNEL],
|
---|
| 370 | aGuestStats[GUESTSTATTYPE_CPUIDLE],
|
---|
| 371 | /* Convert the units for RAM usage stats: page (4K) -> 1KB units */
|
---|
| 372 | mCurrentGuestStat[GUESTSTATTYPE_MEMTOTAL] * (_4K/_1K),
|
---|
| 373 | mCurrentGuestStat[GUESTSTATTYPE_MEMFREE] * (_4K/_1K),
|
---|
| 374 | mCurrentGuestStat[GUESTSTATTYPE_MEMBALLOON] * (_4K/_1K),
|
---|
| 375 | (ULONG)(cbSharedMem / _1K), /* bytes -> KB */
|
---|
| 376 | mCurrentGuestStat[GUESTSTATTYPE_MEMCACHE] * (_4K/_1K),
|
---|
| 377 | mCurrentGuestStat[GUESTSTATTYPE_PAGETOTAL] * (_4K/_1K),
|
---|
| 378 | (ULONG)(cbAllocTotal / _1K), /* bytes -> KB */
|
---|
| 379 | (ULONG)(cbFreeTotal / _1K),
|
---|
| 380 | (ULONG)(cbBalloonedTotal / _1K),
|
---|
| 381 | (ULONG)(cbSharedTotal / _1K),
|
---|
| 382 | uNetStatRx,
|
---|
| 383 | uNetStatTx);
|
---|
[40084] | 384 | }
|
---|
| 385 |
|
---|
[1] | 386 | // IGuest properties
|
---|
| 387 | /////////////////////////////////////////////////////////////////////////////
|
---|
| 388 |
|
---|
[52082] | 389 | HRESULT Guest::getOSTypeId(com::Utf8Str &aOSTypeId)
|
---|
[1] | 390 | {
|
---|
[52082] | 391 | HRESULT hrc = S_OK;
|
---|
| 392 | AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
| 393 | if (!mData.mInterfaceVersion.isEmpty())
|
---|
| 394 | aOSTypeId = mData.mOSTypeId;
|
---|
| 395 | else
|
---|
[39882] | 396 | {
|
---|
[52082] | 397 | /* Redirect the call to IMachine if no additions are installed. */
|
---|
| 398 | ComPtr<IMachine> ptrMachine(mParent->i_machine());
|
---|
| 399 | alock.release();
|
---|
[77436] | 400 | Bstr bstr;
|
---|
| 401 | hrc = ptrMachine->COMGETTER(OSTypeId)(bstr.asOutParam());
|
---|
[52082] | 402 | aOSTypeId = bstr;
|
---|
[39882] | 403 | }
|
---|
| 404 | return hrc;
|
---|
[1] | 405 | }
|
---|
| 406 |
|
---|
[52082] | 407 | HRESULT Guest::getAdditionsRunLevel(AdditionsRunLevelType_T *aAdditionsRunLevel)
|
---|
[1] | 408 | {
|
---|
[25310] | 409 | AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
[2567] | 410 |
|
---|
[52082] | 411 | *aAdditionsRunLevel = mData.mAdditionsRunLevel;
|
---|
[2567] | 412 |
|
---|
[1] | 413 | return S_OK;
|
---|
| 414 | }
|
---|
| 415 |
|
---|
[52082] | 416 | HRESULT Guest::getAdditionsVersion(com::Utf8Str &aAdditionsVersion)
|
---|
[1] | 417 | {
|
---|
[52082] | 418 | AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
| 419 | HRESULT hrc = S_OK;
|
---|
[1] | 420 |
|
---|
[52082] | 421 | /*
|
---|
| 422 | * Return the ReportGuestInfo2 version info if available.
|
---|
| 423 | */
|
---|
| 424 | if ( !mData.mAdditionsVersionNew.isEmpty()
|
---|
| 425 | || mData.mAdditionsRunLevel <= AdditionsRunLevelType_None)
|
---|
| 426 | aAdditionsVersion = mData.mAdditionsVersionNew;
|
---|
| 427 | else
|
---|
[39882] | 428 | {
|
---|
[31436] | 429 | /*
|
---|
[84564] | 430 | * If we're running older Guest Additions (< 3.2.0) try get it from
|
---|
[52082] | 431 | * the guest properties. Detected switched around Version and
|
---|
| 432 | * Revision in early 3.1.x releases (see r57115).
|
---|
[31436] | 433 | */
|
---|
[52082] | 434 | ComPtr<IMachine> ptrMachine = mParent->i_machine();
|
---|
| 435 | alock.release(); /* No need to hold this during the IPC fun. */
|
---|
| 436 |
|
---|
| 437 | Bstr bstr;
|
---|
| 438 | hrc = ptrMachine->GetGuestPropertyValue(Bstr("/VirtualBox/GuestAdd/Version").raw(), bstr.asOutParam());
|
---|
| 439 | if ( SUCCEEDED(hrc)
|
---|
| 440 | && !bstr.isEmpty())
|
---|
| 441 | {
|
---|
| 442 | Utf8Str str(bstr);
|
---|
| 443 | if (str.count('.') == 0)
|
---|
| 444 | hrc = ptrMachine->GetGuestPropertyValue(Bstr("/VirtualBox/GuestAdd/Revision").raw(), bstr.asOutParam());
|
---|
| 445 | str = bstr;
|
---|
| 446 | if (str.count('.') != 2)
|
---|
| 447 | hrc = E_FAIL;
|
---|
| 448 | }
|
---|
| 449 |
|
---|
| 450 | if (SUCCEEDED(hrc))
|
---|
| 451 | aAdditionsVersion = bstr;
|
---|
[39882] | 452 | else
|
---|
[31436] | 453 | {
|
---|
[52082] | 454 | /* Returning 1.4 is better than nothing. */
|
---|
| 455 | alock.acquire();
|
---|
| 456 | aAdditionsVersion = mData.mInterfaceVersion;
|
---|
| 457 | hrc = S_OK;
|
---|
[31436] | 458 | }
|
---|
[39882] | 459 | }
|
---|
| 460 | return hrc;
|
---|
| 461 | }
|
---|
| 462 |
|
---|
[52082] | 463 | HRESULT Guest::getAdditionsRevision(ULONG *aAdditionsRevision)
|
---|
[39882] | 464 | {
|
---|
[52082] | 465 | HRESULT hrc = S_OK;
|
---|
| 466 | AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
[39882] | 467 |
|
---|
[52082] | 468 | /*
|
---|
| 469 | * Return the ReportGuestInfo2 version info if available.
|
---|
| 470 | */
|
---|
| 471 | if ( !mData.mAdditionsVersionNew.isEmpty()
|
---|
| 472 | || mData.mAdditionsRunLevel <= AdditionsRunLevelType_None)
|
---|
| 473 | *aAdditionsRevision = mData.mAdditionsRevision;
|
---|
| 474 | else
|
---|
[39882] | 475 | {
|
---|
| 476 | /*
|
---|
[84564] | 477 | * If we're running older Guest Additions (< 3.2.0) try get it from
|
---|
[52082] | 478 | * the guest properties. Detected switched around Version and
|
---|
| 479 | * Revision in early 3.1.x releases (see r57115).
|
---|
[39882] | 480 | */
|
---|
[52082] | 481 | ComPtr<IMachine> ptrMachine = mParent->i_machine();
|
---|
| 482 | alock.release(); /* No need to hold this during the IPC fun. */
|
---|
| 483 |
|
---|
| 484 | Bstr bstr;
|
---|
| 485 | hrc = ptrMachine->GetGuestPropertyValue(Bstr("/VirtualBox/GuestAdd/Revision").raw(), bstr.asOutParam());
|
---|
| 486 | if (SUCCEEDED(hrc))
|
---|
[31436] | 487 | {
|
---|
[52082] | 488 | Utf8Str str(bstr);
|
---|
| 489 | uint32_t uRevision;
|
---|
| 490 | int vrc = RTStrToUInt32Full(str.c_str(), 0, &uRevision);
|
---|
| 491 | if (vrc != VINF_SUCCESS && str.count('.') == 2)
|
---|
[39882] | 492 | {
|
---|
[52082] | 493 | hrc = ptrMachine->GetGuestPropertyValue(Bstr("/VirtualBox/GuestAdd/Version").raw(), bstr.asOutParam());
|
---|
| 494 | if (SUCCEEDED(hrc))
|
---|
[39898] | 495 | {
|
---|
[52082] | 496 | str = bstr;
|
---|
| 497 | vrc = RTStrToUInt32Full(str.c_str(), 0, &uRevision);
|
---|
[39898] | 498 | }
|
---|
[39882] | 499 | }
|
---|
[52082] | 500 | if (vrc == VINF_SUCCESS)
|
---|
| 501 | *aAdditionsRevision = uRevision;
|
---|
| 502 | else
|
---|
| 503 | hrc = VBOX_E_IPRT_ERROR;
|
---|
[31436] | 504 | }
|
---|
[52082] | 505 | if (FAILED(hrc))
|
---|
| 506 | {
|
---|
| 507 | /* Return 0 if we don't know. */
|
---|
| 508 | *aAdditionsRevision = 0;
|
---|
| 509 | hrc = S_OK;
|
---|
| 510 | }
|
---|
[31436] | 511 | }
|
---|
[39882] | 512 | return hrc;
|
---|
[1] | 513 | }
|
---|
| 514 |
|
---|
[52082] | 515 | HRESULT Guest::getDnDSource(ComPtr<IGuestDnDSource> &aDnDSource)
|
---|
[51476] | 516 | {
|
---|
| 517 | #ifndef VBOX_WITH_DRAG_AND_DROP
|
---|
[63418] | 518 | RT_NOREF(aDnDSource);
|
---|
[51476] | 519 | ReturnComNotImplemented();
|
---|
| 520 | #else
|
---|
| 521 | LogFlowThisFuncEnter();
|
---|
| 522 |
|
---|
| 523 | /* No need to lock - lifetime constant. */
|
---|
[52082] | 524 | HRESULT hr = mDnDSource.queryInterfaceTo(aDnDSource.asOutParam());
|
---|
[51476] | 525 |
|
---|
| 526 | LogFlowFuncLeaveRC(hr);
|
---|
| 527 | return hr;
|
---|
| 528 | #endif /* VBOX_WITH_DRAG_AND_DROP */
|
---|
| 529 | }
|
---|
| 530 |
|
---|
[52082] | 531 | HRESULT Guest::getDnDTarget(ComPtr<IGuestDnDTarget> &aDnDTarget)
|
---|
[51476] | 532 | {
|
---|
| 533 | #ifndef VBOX_WITH_DRAG_AND_DROP
|
---|
[63418] | 534 | RT_NOREF(aDnDTarget);
|
---|
[51476] | 535 | ReturnComNotImplemented();
|
---|
| 536 | #else
|
---|
| 537 | LogFlowThisFuncEnter();
|
---|
| 538 |
|
---|
| 539 | /* No need to lock - lifetime constant. */
|
---|
[52082] | 540 | HRESULT hr = mDnDTarget.queryInterfaceTo(aDnDTarget.asOutParam());
|
---|
[51476] | 541 |
|
---|
| 542 | LogFlowFuncLeaveRC(hr);
|
---|
| 543 | return hr;
|
---|
| 544 | #endif /* VBOX_WITH_DRAG_AND_DROP */
|
---|
| 545 | }
|
---|
| 546 |
|
---|
[52082] | 547 | HRESULT Guest::getEventSource(ComPtr<IEventSource> &aEventSource)
|
---|
[45426] | 548 | {
|
---|
| 549 | LogFlowThisFuncEnter();
|
---|
| 550 |
|
---|
[51476] | 551 | /* No need to lock - lifetime constant. */
|
---|
[52082] | 552 | mEventSource.queryInterfaceTo(aEventSource.asOutParam());
|
---|
[45426] | 553 |
|
---|
| 554 | LogFlowFuncLeaveRC(S_OK);
|
---|
| 555 | return S_OK;
|
---|
| 556 | }
|
---|
| 557 |
|
---|
[52082] | 558 | HRESULT Guest::getFacilities(std::vector<ComPtr<IAdditionsFacility> > &aFacilities)
|
---|
[35967] | 559 | {
|
---|
| 560 | AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
| 561 |
|
---|
[52082] | 562 | aFacilities.resize(mData.mFacilityMap.size());
|
---|
| 563 | size_t i = 0;
|
---|
| 564 | for (FacilityMapIter it = mData.mFacilityMap.begin(); it != mData.mFacilityMap.end(); ++it, ++i)
|
---|
| 565 | it->second.queryInterfaceTo(aFacilities[i].asOutParam());
|
---|
[35967] | 566 |
|
---|
| 567 | return S_OK;
|
---|
| 568 | }
|
---|
| 569 |
|
---|
[52082] | 570 | HRESULT Guest::getSessions(std::vector<ComPtr<IGuestSession> > &aSessions)
|
---|
[42084] | 571 | {
|
---|
[55644] | 572 | #ifdef VBOX_WITH_GUEST_CONTROL
|
---|
[42084] | 573 | AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
| 574 |
|
---|
[52082] | 575 | aSessions.resize(mData.mGuestSessions.size());
|
---|
| 576 | size_t i = 0;
|
---|
| 577 | for (GuestSessions::iterator it = mData.mGuestSessions.begin(); it != mData.mGuestSessions.end(); ++it, ++i)
|
---|
| 578 | it->second.queryInterfaceTo(aSessions[i].asOutParam());
|
---|
[42084] | 579 |
|
---|
| 580 | return S_OK;
|
---|
[55644] | 581 | #else
|
---|
| 582 | ReturnComNotImplemented();
|
---|
| 583 | #endif
|
---|
[42084] | 584 | }
|
---|
| 585 |
|
---|
[52082] | 586 | BOOL Guest::i_isPageFusionEnabled()
|
---|
[29589] | 587 | {
|
---|
| 588 | AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
| 589 |
|
---|
[31692] | 590 | return mfPageFusionEnabled;
|
---|
[29589] | 591 | }
|
---|
| 592 |
|
---|
[52082] | 593 | HRESULT Guest::getMemoryBalloonSize(ULONG *aMemoryBalloonSize)
|
---|
[4314] | 594 | {
|
---|
[25310] | 595 | AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
[4314] | 596 |
|
---|
| 597 | *aMemoryBalloonSize = mMemoryBalloonSize;
|
---|
| 598 |
|
---|
| 599 | return S_OK;
|
---|
| 600 | }
|
---|
| 601 |
|
---|
[52082] | 602 | HRESULT Guest::setMemoryBalloonSize(ULONG aMemoryBalloonSize)
|
---|
[4314] | 603 | {
|
---|
[25310] | 604 | AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
[4318] | 605 |
|
---|
[28529] | 606 | /* We must be 100% sure that IMachine::COMSETTER(MemoryBalloonSize)
|
---|
| 607 | * does not call us back in any way! */
|
---|
[51612] | 608 | HRESULT ret = mParent->i_machine()->COMSETTER(MemoryBalloonSize)(aMemoryBalloonSize);
|
---|
[4513] | 609 | if (ret == S_OK)
|
---|
| 610 | {
|
---|
| 611 | mMemoryBalloonSize = aMemoryBalloonSize;
|
---|
[32851] | 612 | /* forward the information to the VMM device */
|
---|
[51612] | 613 | VMMDev *pVMMDev = mParent->i_getVMMDev();
|
---|
[32827] | 614 | /* MUST release all locks before calling VMM device as its critsect
|
---|
| 615 | * has higher lock order than anything in Main. */
|
---|
| 616 | alock.release();
|
---|
[29997] | 617 | if (pVMMDev)
|
---|
| 618 | {
|
---|
| 619 | PPDMIVMMDEVPORT pVMMDevPort = pVMMDev->getVMMDevPort();
|
---|
[30002] | 620 | if (pVMMDevPort)
|
---|
| 621 | pVMMDevPort->pfnSetMemoryBalloon(pVMMDevPort, aMemoryBalloonSize);
|
---|
[29997] | 622 | }
|
---|
[4513] | 623 | }
|
---|
[4318] | 624 |
|
---|
[4513] | 625 | return ret;
|
---|
[4314] | 626 | }
|
---|
| 627 |
|
---|
[52082] | 628 | HRESULT Guest::getStatisticsUpdateInterval(ULONG *aStatisticsUpdateInterval)
|
---|
[26295] | 629 | {
|
---|
| 630 | AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
| 631 |
|
---|
[52082] | 632 | *aStatisticsUpdateInterval = mStatUpdateInterval;
|
---|
[26295] | 633 | return S_OK;
|
---|
| 634 | }
|
---|
| 635 |
|
---|
[52082] | 636 | HRESULT Guest::setStatisticsUpdateInterval(ULONG aStatisticsUpdateInterval)
|
---|
[26295] | 637 | {
|
---|
| 638 | AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
| 639 |
|
---|
[80670] | 640 | /* Update the timer, creating it the first time we're called with a non-zero value. */
|
---|
| 641 | int vrc;
|
---|
| 642 | HRESULT hrc = S_OK;
|
---|
| 643 | if (aStatisticsUpdateInterval > 0)
|
---|
[80654] | 644 | {
|
---|
[80670] | 645 | if (mStatTimer == NIL_RTTIMERLR)
|
---|
| 646 | {
|
---|
| 647 | vrc = RTTimerLRCreate(&mStatTimer, aStatisticsUpdateInterval * RT_MS_1SEC, &Guest::i_staticUpdateStats, this);
|
---|
[91503] | 648 | AssertRCStmt(vrc, hrc = setErrorVrc(vrc, tr("Failed to create guest statistics update timer (%Rrc)"), vrc));
|
---|
[80670] | 649 | }
|
---|
| 650 | else if (aStatisticsUpdateInterval != mStatUpdateInterval)
|
---|
| 651 | {
|
---|
| 652 | vrc = RTTimerLRChangeInterval(mStatTimer, aStatisticsUpdateInterval * RT_NS_1SEC_64);
|
---|
[91503] | 653 | AssertRCStmt(vrc, hrc = setErrorVrc(vrc, tr("Failed to change guest statistics update timer interval from %u to %u failed (%Rrc)"),
|
---|
[80670] | 654 | mStatUpdateInterval, aStatisticsUpdateInterval, vrc));
|
---|
| 655 | if (mStatUpdateInterval == 0)
|
---|
| 656 | {
|
---|
| 657 | vrc = RTTimerLRStart(mStatTimer, 0);
|
---|
[91503] | 658 | AssertRCStmt(vrc, hrc = setErrorVrc(vrc, tr("Failed to start the guest statistics update timer (%Rrc)"), vrc));
|
---|
[80670] | 659 | }
|
---|
| 660 | }
|
---|
[80654] | 661 | }
|
---|
[80670] | 662 | /* Setting interval to zero - stop the update timer if needed: */
|
---|
| 663 | else if (mStatUpdateInterval > 0 && mStatTimer != NIL_RTTIMERLR)
|
---|
[80654] | 664 | {
|
---|
[80670] | 665 | vrc = RTTimerLRStop(mStatTimer);
|
---|
[91503] | 666 | AssertRCStmt(vrc, hrc = setErrorVrc(vrc, tr("Failed to stop the guest statistics update timer (%Rrc)"), vrc));
|
---|
[80654] | 667 | }
|
---|
[80670] | 668 |
|
---|
| 669 | /* Update the interval now that the timer is in sync. */
|
---|
[52082] | 670 | mStatUpdateInterval = aStatisticsUpdateInterval;
|
---|
[80654] | 671 |
|
---|
| 672 | /* Forward the information to the VMM device.
|
---|
| 673 | MUST release all locks before calling VMM device as its critsect
|
---|
| 674 | has higher lock order than anything in Main. */
|
---|
[51612] | 675 | VMMDev *pVMMDev = mParent->i_getVMMDev();
|
---|
[32827] | 676 | alock.release();
|
---|
[29997] | 677 | if (pVMMDev)
|
---|
| 678 | {
|
---|
| 679 | PPDMIVMMDEVPORT pVMMDevPort = pVMMDev->getVMMDevPort();
|
---|
[30002] | 680 | if (pVMMDevPort)
|
---|
[52082] | 681 | pVMMDevPort->pfnSetStatisticsInterval(pVMMDevPort, aStatisticsUpdateInterval);
|
---|
[29997] | 682 | }
|
---|
[26295] | 683 |
|
---|
[80670] | 684 | return hrc;
|
---|
[26295] | 685 | }
|
---|
| 686 |
|
---|
[52082] | 687 |
|
---|
| 688 | HRESULT Guest::internalGetStatistics(ULONG *aCpuUser, ULONG *aCpuKernel, ULONG *aCpuIdle,
|
---|
| 689 | ULONG *aMemTotal, ULONG *aMemFree, ULONG *aMemBalloon,
|
---|
| 690 | ULONG *aMemShared, ULONG *aMemCache, ULONG *aPageTotal,
|
---|
| 691 | ULONG *aMemAllocTotal, ULONG *aMemFreeTotal,
|
---|
| 692 | ULONG *aMemBalloonTotal, ULONG *aMemSharedTotal)
|
---|
[27885] | 693 | {
|
---|
[27896] | 694 | AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
| 695 |
|
---|
[29225] | 696 | *aCpuUser = mCurrentGuestStat[GUESTSTATTYPE_CPUUSER];
|
---|
| 697 | *aCpuKernel = mCurrentGuestStat[GUESTSTATTYPE_CPUKERNEL];
|
---|
| 698 | *aCpuIdle = mCurrentGuestStat[GUESTSTATTYPE_CPUIDLE];
|
---|
[80670] | 699 | *aMemTotal = mCurrentGuestStat[GUESTSTATTYPE_MEMTOTAL] * (_4K/_1K); /* page (4K) -> 1KB units */
|
---|
| 700 | *aMemFree = mCurrentGuestStat[GUESTSTATTYPE_MEMFREE] * (_4K/_1K); /* page (4K) -> 1KB units */
|
---|
[28481] | 701 | *aMemBalloon = mCurrentGuestStat[GUESTSTATTYPE_MEMBALLOON] * (_4K/_1K); /* page (4K) -> 1KB units */
|
---|
[80670] | 702 | *aMemCache = mCurrentGuestStat[GUESTSTATTYPE_MEMCACHE] * (_4K/_1K); /* page (4K) -> 1KB units */
|
---|
| 703 | *aPageTotal = mCurrentGuestStat[GUESTSTATTYPE_PAGETOTAL] * (_4K/_1K); /* page (4K) -> 1KB units */
|
---|
[27896] | 704 |
|
---|
[44347] | 705 | /* Play safe or smth? */
|
---|
| 706 | *aMemAllocTotal = 0;
|
---|
| 707 | *aMemFreeTotal = 0;
|
---|
| 708 | *aMemBalloonTotal = 0;
|
---|
| 709 | *aMemSharedTotal = 0;
|
---|
| 710 | *aMemShared = 0;
|
---|
| 711 |
|
---|
[32827] | 712 | /* MUST release all locks before calling any PGM statistics queries,
|
---|
| 713 | * as they are executed by EMT and that might deadlock us by VMM device
|
---|
| 714 | * activity which waits for the Guest object lock. */
|
---|
| 715 | alock.release();
|
---|
[44347] | 716 | Console::SafeVMPtr ptrVM(mParent);
|
---|
| 717 | if (!ptrVM.isOk())
|
---|
[36128] | 718 | return E_FAIL;
|
---|
[28004] | 719 |
|
---|
[44347] | 720 | uint64_t cbFreeTotal, cbAllocTotal, cbBalloonedTotal, cbSharedTotal;
|
---|
[94954] | 721 | int vrc = ptrVM.vtable()->pfnPGMR3QueryGlobalMemoryStats(ptrVM.rawUVM(), &cbAllocTotal, &cbFreeTotal,
|
---|
| 722 | &cbBalloonedTotal, &cbSharedTotal);
|
---|
| 723 | AssertRCReturn(vrc, E_FAIL);
|
---|
[44347] | 724 |
|
---|
| 725 | *aMemAllocTotal = (ULONG)(cbAllocTotal / _1K); /* bytes -> KB */
|
---|
| 726 | *aMemFreeTotal = (ULONG)(cbFreeTotal / _1K);
|
---|
| 727 | *aMemBalloonTotal = (ULONG)(cbBalloonedTotal / _1K);
|
---|
| 728 | *aMemSharedTotal = (ULONG)(cbSharedTotal / _1K);
|
---|
| 729 |
|
---|
| 730 | /* Query the missing per-VM memory statistics. */
|
---|
| 731 | uint64_t cbTotalMemIgn, cbPrivateMemIgn, cbSharedMem, cbZeroMemIgn;
|
---|
[94954] | 732 | vrc = ptrVM.vtable()->pfnPGMR3QueryMemoryStats(ptrVM.rawUVM(), &cbTotalMemIgn, &cbPrivateMemIgn, &cbSharedMem, &cbZeroMemIgn);
|
---|
| 733 | AssertRCReturn(vrc, E_FAIL);
|
---|
[44347] | 734 | *aMemShared = (ULONG)(cbSharedMem / _1K);
|
---|
| 735 |
|
---|
[27885] | 736 | return S_OK;
|
---|
| 737 | }
|
---|
| 738 |
|
---|
[52082] | 739 | HRESULT Guest::i_setStatistic(ULONG aCpuId, GUESTSTATTYPE enmType, ULONG aVal)
|
---|
[27896] | 740 | {
|
---|
[40084] | 741 | static ULONG indexToPerfMask[] =
|
---|
| 742 | {
|
---|
[43908] | 743 | pm::VMSTATMASK_GUEST_CPUUSER,
|
---|
| 744 | pm::VMSTATMASK_GUEST_CPUKERNEL,
|
---|
| 745 | pm::VMSTATMASK_GUEST_CPUIDLE,
|
---|
| 746 | pm::VMSTATMASK_GUEST_MEMTOTAL,
|
---|
| 747 | pm::VMSTATMASK_GUEST_MEMFREE,
|
---|
| 748 | pm::VMSTATMASK_GUEST_MEMBALLOON,
|
---|
| 749 | pm::VMSTATMASK_GUEST_MEMCACHE,
|
---|
| 750 | pm::VMSTATMASK_GUEST_PAGETOTAL,
|
---|
| 751 | pm::VMSTATMASK_NONE
|
---|
[40084] | 752 | };
|
---|
[27896] | 753 | AutoCaller autoCaller(this);
|
---|
[98262] | 754 | if (FAILED(autoCaller.hrc())) return autoCaller.hrc();
|
---|
[27885] | 755 |
|
---|
[27896] | 756 | AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
| 757 |
|
---|
[27930] | 758 | if (enmType >= GUESTSTATTYPE_MAX)
|
---|
[27896] | 759 | return E_INVALIDARG;
|
---|
| 760 |
|
---|
[56470] | 761 | if (aCpuId < VMM_MAX_CPU_COUNT)
|
---|
| 762 | {
|
---|
| 763 | ULONG *paCpuStats;
|
---|
| 764 | switch (enmType)
|
---|
| 765 | {
|
---|
| 766 | case GUESTSTATTYPE_CPUUSER: paCpuStats = mCurrentGuestCpuUserStat; break;
|
---|
| 767 | case GUESTSTATTYPE_CPUKERNEL: paCpuStats = mCurrentGuestCpuKernelStat; break;
|
---|
| 768 | case GUESTSTATTYPE_CPUIDLE: paCpuStats = mCurrentGuestCpuIdleStat; break;
|
---|
| 769 | default: paCpuStats = NULL; break;
|
---|
| 770 | }
|
---|
| 771 | if (paCpuStats)
|
---|
| 772 | {
|
---|
| 773 | paCpuStats[aCpuId] = aVal;
|
---|
| 774 | aVal = 0;
|
---|
| 775 | for (uint32_t i = 0; i < mCpus && i < VMM_MAX_CPU_COUNT; i++)
|
---|
| 776 | aVal += paCpuStats[i];
|
---|
| 777 | aVal /= mCpus;
|
---|
| 778 | }
|
---|
| 779 | }
|
---|
| 780 |
|
---|
[27896] | 781 | mCurrentGuestStat[enmType] = aVal;
|
---|
[43908] | 782 | mVmValidStats |= indexToPerfMask[enmType];
|
---|
[27896] | 783 | return S_OK;
|
---|
| 784 | }
|
---|
| 785 |
|
---|
[35887] | 786 | /**
|
---|
| 787 | * Returns the status of a specified Guest Additions facility.
|
---|
| 788 | *
|
---|
[65120] | 789 | * @return COM status code
|
---|
| 790 | * @param aFacility Facility to get the status from.
|
---|
[35887] | 791 | * @param aTimestamp Timestamp of last facility status update in ms (optional).
|
---|
[65120] | 792 | * @param aStatus Current status of the specified facility.
|
---|
[35887] | 793 | */
|
---|
[52082] | 794 | HRESULT Guest::getFacilityStatus(AdditionsFacilityType_T aFacility, LONG64 *aTimestamp, AdditionsFacilityStatus_T *aStatus)
|
---|
[35887] | 795 | {
|
---|
| 796 | AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
| 797 |
|
---|
| 798 | /* Not checking for aTimestamp is intentional; it's optional. */
|
---|
[52082] | 799 | FacilityMapIterConst it = mData.mFacilityMap.find(aFacility);
|
---|
[35887] | 800 | if (it != mData.mFacilityMap.end())
|
---|
| 801 | {
|
---|
[35967] | 802 | AdditionsFacility *pFacility = it->second;
|
---|
| 803 | ComAssert(pFacility);
|
---|
[50370] | 804 | *aStatus = pFacility->i_getStatus();
|
---|
[35887] | 805 | if (aTimestamp)
|
---|
[50370] | 806 | *aTimestamp = pFacility->i_getLastUpdated();
|
---|
[35887] | 807 | }
|
---|
| 808 | else
|
---|
| 809 | {
|
---|
| 810 | /*
|
---|
| 811 | * Do not fail here -- could be that the facility never has been brought up (yet) but
|
---|
| 812 | * the host wants to have its status anyway. So just tell we don't know at this point.
|
---|
| 813 | */
|
---|
| 814 | *aStatus = AdditionsFacilityStatus_Unknown;
|
---|
| 815 | if (aTimestamp)
|
---|
| 816 | *aTimestamp = RTTimeMilliTS();
|
---|
| 817 | }
|
---|
| 818 | return S_OK;
|
---|
| 819 | }
|
---|
| 820 |
|
---|
[52082] | 821 | HRESULT Guest::getAdditionsStatus(AdditionsRunLevelType_T aLevel, BOOL *aActive)
|
---|
[32020] | 822 | {
|
---|
| 823 | AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
| 824 |
|
---|
[94954] | 825 | HRESULT hrc = S_OK;
|
---|
[32020] | 826 | switch (aLevel)
|
---|
| 827 | {
|
---|
[32086] | 828 | case AdditionsRunLevelType_System:
|
---|
| 829 | *aActive = (mData.mAdditionsRunLevel > AdditionsRunLevelType_None);
|
---|
[32020] | 830 | break;
|
---|
| 831 |
|
---|
[32086] | 832 | case AdditionsRunLevelType_Userland:
|
---|
| 833 | *aActive = (mData.mAdditionsRunLevel >= AdditionsRunLevelType_Userland);
|
---|
[32020] | 834 | break;
|
---|
| 835 |
|
---|
[32086] | 836 | case AdditionsRunLevelType_Desktop:
|
---|
| 837 | *aActive = (mData.mAdditionsRunLevel >= AdditionsRunLevelType_Desktop);
|
---|
[32020] | 838 | break;
|
---|
| 839 |
|
---|
| 840 | default:
|
---|
[94954] | 841 | hrc = setError(VBOX_E_NOT_SUPPORTED,
|
---|
| 842 | tr("Invalid status level defined: %u"), aLevel);
|
---|
[32020] | 843 | break;
|
---|
| 844 | }
|
---|
| 845 |
|
---|
[94954] | 846 | return hrc;
|
---|
[32020] | 847 | }
|
---|
[94954] | 848 |
|
---|
[52082] | 849 | HRESULT Guest::setCredentials(const com::Utf8Str &aUserName, const com::Utf8Str &aPassword,
|
---|
| 850 | const com::Utf8Str &aDomain, BOOL aAllowInteractiveLogon)
|
---|
[1] | 851 | {
|
---|
[51342] | 852 | /* Check for magic domain names which are used to pass encryption keys to the disk. */
|
---|
| 853 | if (Utf8Str(aDomain) == "@@disk")
|
---|
[52082] | 854 | return mParent->i_setDiskEncryptionKeys(aPassword);
|
---|
[73003] | 855 | if (Utf8Str(aDomain) == "@@mem")
|
---|
[1] | 856 | {
|
---|
[51342] | 857 | /** @todo */
|
---|
[51476] | 858 | return E_NOTIMPL;
|
---|
[51342] | 859 | }
|
---|
[73003] | 860 |
|
---|
| 861 | /* forward the information to the VMM device */
|
---|
| 862 | VMMDev *pVMMDev = mParent->i_getVMMDev();
|
---|
| 863 | if (pVMMDev)
|
---|
[51342] | 864 | {
|
---|
[73003] | 865 | PPDMIVMMDEVPORT pVMMDevPort = pVMMDev->getVMMDevPort();
|
---|
| 866 | if (pVMMDevPort)
|
---|
[30002] | 867 | {
|
---|
[73003] | 868 | uint32_t u32Flags = VMMDEV_SETCREDENTIALS_GUESTLOGON;
|
---|
| 869 | if (!aAllowInteractiveLogon)
|
---|
| 870 | u32Flags = VMMDEV_SETCREDENTIALS_NOLOCALLOGON;
|
---|
[51476] | 871 |
|
---|
[73003] | 872 | pVMMDevPort->pfnSetCredentials(pVMMDevPort,
|
---|
| 873 | aUserName.c_str(),
|
---|
| 874 | aPassword.c_str(),
|
---|
| 875 | aDomain.c_str(),
|
---|
| 876 | u32Flags);
|
---|
| 877 | return S_OK;
|
---|
[30002] | 878 | }
|
---|
[1] | 879 | }
|
---|
[2567] | 880 |
|
---|
[73003] | 881 | return setError(VBOX_E_VM_ERROR, tr("VMM device is not available (is the VM running?)"));
|
---|
[1] | 882 | }
|
---|
| 883 |
|
---|
| 884 | // public methods only for internal purposes
|
---|
| 885 | /////////////////////////////////////////////////////////////////////////////
|
---|
| 886 |
|
---|
[30758] | 887 | /**
|
---|
| 888 | * Sets the general Guest Additions information like
|
---|
[31364] | 889 | * API (interface) version and OS type. Gets called by
|
---|
| 890 | * vmmdevUpdateGuestInfo.
|
---|
[30758] | 891 | *
|
---|
[31241] | 892 | * @param aInterfaceVersion
|
---|
[30758] | 893 | * @param aOsType
|
---|
| 894 | */
|
---|
[67793] | 895 | void Guest::i_setAdditionsInfo(const com::Utf8Str &aInterfaceVersion, VBOXOSTYPE aOsType)
|
---|
[1] | 896 | {
|
---|
[39890] | 897 | RTTIMESPEC TimeSpecTS;
|
---|
| 898 | RTTimeNow(&TimeSpecTS);
|
---|
| 899 |
|
---|
[21878] | 900 | AutoCaller autoCaller(this);
|
---|
[98262] | 901 | AssertComRCReturnVoid(autoCaller.hrc());
|
---|
[2567] | 902 |
|
---|
[25310] | 903 | AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
[2567] | 904 |
|
---|
[30758] | 905 | /*
|
---|
[31241] | 906 | * Note: The Guest Additions API (interface) version is deprecated
|
---|
[31436] | 907 | * and will not be used anymore! We might need it to at least report
|
---|
| 908 | * something as version number if *really* ancient Guest Additions are
|
---|
| 909 | * installed (without the guest version + revision properties having set).
|
---|
[30758] | 910 | */
|
---|
[31436] | 911 | mData.mInterfaceVersion = aInterfaceVersion;
|
---|
[31241] | 912 |
|
---|
[30758] | 913 | /*
|
---|
| 914 | * Older Additions rely on the Additions API version whether they
|
---|
[31364] | 915 | * are assumed to be active or not. Since newer Additions do report
|
---|
| 916 | * the Additions version *before* calling this function (by calling
|
---|
| 917 | * VMMDevReportGuestInfo2, VMMDevReportGuestStatus, VMMDevReportGuestInfo,
|
---|
| 918 | * in that order) we can tell apart old and new Additions here. Old
|
---|
| 919 | * Additions never would set VMMDevReportGuestInfo2 (which set mData.mAdditionsVersion)
|
---|
| 920 | * so they just rely on the aInterfaceVersion string (which gets set by
|
---|
| 921 | * VMMDevReportGuestInfo).
|
---|
| 922 | *
|
---|
[32020] | 923 | * So only mark the Additions as being active (run level = system) when we
|
---|
| 924 | * don't have the Additions version set.
|
---|
[30758] | 925 | */
|
---|
[39882] | 926 | if (mData.mAdditionsVersionNew.isEmpty())
|
---|
[32020] | 927 | {
|
---|
[32138] | 928 | if (aInterfaceVersion.isEmpty())
|
---|
| 929 | mData.mAdditionsRunLevel = AdditionsRunLevelType_None;
|
---|
| 930 | else
|
---|
[35977] | 931 | {
|
---|
[32138] | 932 | mData.mAdditionsRunLevel = AdditionsRunLevelType_System;
|
---|
[35977] | 933 |
|
---|
| 934 | /*
|
---|
| 935 | * To keep it compatible with the old Guest Additions behavior we need to set the
|
---|
| 936 | * "graphics" (feature) facility to active as soon as we got the Guest Additions
|
---|
| 937 | * interface version.
|
---|
| 938 | */
|
---|
[79050] | 939 | i_facilityUpdate(VBoxGuestFacilityType_Graphics, VBoxGuestFacilityStatus_Active, 0 /*fFlags*/, &TimeSpecTS);
|
---|
[35977] | 940 | }
|
---|
[32020] | 941 | }
|
---|
| 942 |
|
---|
[30758] | 943 | /*
|
---|
| 944 | * Older Additions didn't have this finer grained capability bit,
|
---|
[35907] | 945 | * so enable it by default. Newer Additions will not enable this here
|
---|
[31436] | 946 | * and use the setSupportedFeatures function instead.
|
---|
[30758] | 947 | */
|
---|
[39890] | 948 | /** @todo r=bird: I don't get the above comment nor the code below...
|
---|
| 949 | * One talks about capability bits, the one always does something to a facility.
|
---|
| 950 | * Then there is the comment below it all, which is placed like it addresses the
|
---|
| 951 | * mOSTypeId, but talks about something which doesn't remotely like mOSTypeId...
|
---|
| 952 | *
|
---|
| 953 | * Andy, could you please try clarify and make the comments shorter and more
|
---|
| 954 | * coherent! Also, explain why this is important and what depends on it.
|
---|
| 955 | *
|
---|
| 956 | * PS. There is the VMMDEV_GUEST_SUPPORTS_GRAPHICS capability* report... It
|
---|
| 957 | * should come in pretty quickly after this update, normally.
|
---|
| 958 | */
|
---|
[52082] | 959 | i_facilityUpdate(VBoxGuestFacilityType_Graphics,
|
---|
| 960 | i_facilityIsActive(VBoxGuestFacilityType_VBoxGuestDriver)
|
---|
| 961 | ? VBoxGuestFacilityStatus_Active : VBoxGuestFacilityStatus_Inactive,
|
---|
| 962 | 0 /*fFlags*/, &TimeSpecTS); /** @todo the timestamp isn't gonna be right here on saved state restore. */
|
---|
[9360] | 963 |
|
---|
[30758] | 964 | /*
|
---|
[32020] | 965 | * Note! There is a race going on between setting mAdditionsRunLevel and
|
---|
[30758] | 966 | * mSupportsGraphics here and disabling/enabling it later according to
|
---|
| 967 | * its real status when using new(er) Guest Additions.
|
---|
| 968 | */
|
---|
[55613] | 969 | mData.mOSType = aOsType;
|
---|
[39248] | 970 | mData.mOSTypeId = Global::OSTypeId(aOsType);
|
---|
[79050] | 971 |
|
---|
| 972 | /*
|
---|
| 973 | * Always fire an event here.
|
---|
| 974 | */
|
---|
| 975 | AdditionsRunLevelType_T const enmRunLevel = mData.mAdditionsRunLevel;
|
---|
| 976 | alock.release();
|
---|
[85300] | 977 | ::FireGuestAdditionsStatusChangedEvent(mEventSource, AdditionsFacilityType_None, AdditionsFacilityStatus_Active,
|
---|
| 978 | enmRunLevel, RTTimeSpecGetMilli(&TimeSpecTS));
|
---|
[1] | 979 | }
|
---|
[3582] | 980 |
|
---|
[30758] | 981 | /**
|
---|
[31241] | 982 | * Sets the Guest Additions version information details.
|
---|
| 983 | *
|
---|
[39882] | 984 | * Gets called by vmmdevUpdateGuestInfo2 and vmmdevUpdateGuestInfo (to clear the
|
---|
| 985 | * state).
|
---|
| 986 | *
|
---|
| 987 | * @param a_uFullVersion VBoxGuestInfo2::additionsMajor,
|
---|
| 988 | * VBoxGuestInfo2::additionsMinor and
|
---|
| 989 | * VBoxGuestInfo2::additionsBuild combined into
|
---|
| 990 | * one value by VBOX_FULL_VERSION_MAKE.
|
---|
| 991 | *
|
---|
| 992 | * When this is 0, it's vmmdevUpdateGuestInfo
|
---|
| 993 | * calling to reset the state.
|
---|
| 994 | *
|
---|
| 995 | * @param a_pszName Build type tag and/or publisher tag, empty
|
---|
| 996 | * string if neiter of those are present.
|
---|
| 997 | * @param a_uRevision See VBoxGuestInfo2::additionsRevision.
|
---|
| 998 | * @param a_fFeatures See VBoxGuestInfo2::additionsFeatures.
|
---|
[31241] | 999 | */
|
---|
[52082] | 1000 | void Guest::i_setAdditionsInfo2(uint32_t a_uFullVersion, const char *a_pszName, uint32_t a_uRevision, uint32_t a_fFeatures)
|
---|
[31241] | 1001 | {
|
---|
| 1002 | AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
| 1003 |
|
---|
[39882] | 1004 | if (a_uFullVersion)
|
---|
| 1005 | {
|
---|
[52085] | 1006 | mData.mAdditionsVersionNew = Utf8StrFmt(*a_pszName ? "%u.%u.%u_%s" : "%u.%u.%u",
|
---|
| 1007 | VBOX_FULL_VERSION_GET_MAJOR(a_uFullVersion),
|
---|
| 1008 | VBOX_FULL_VERSION_GET_MINOR(a_uFullVersion),
|
---|
| 1009 | VBOX_FULL_VERSION_GET_BUILD(a_uFullVersion),
|
---|
| 1010 | a_pszName);
|
---|
[39882] | 1011 | mData.mAdditionsVersionFull = a_uFullVersion;
|
---|
| 1012 | mData.mAdditionsRevision = a_uRevision;
|
---|
| 1013 | mData.mAdditionsFeatures = a_fFeatures;
|
---|
| 1014 | }
|
---|
| 1015 | else
|
---|
| 1016 | {
|
---|
| 1017 | Assert(!a_fFeatures && !a_uRevision && !*a_pszName);
|
---|
| 1018 | mData.mAdditionsVersionNew.setNull();
|
---|
| 1019 | mData.mAdditionsVersionFull = 0;
|
---|
| 1020 | mData.mAdditionsRevision = 0;
|
---|
| 1021 | mData.mAdditionsFeatures = 0;
|
---|
| 1022 | }
|
---|
[31241] | 1023 | }
|
---|
| 1024 |
|
---|
[52082] | 1025 | bool Guest::i_facilityIsActive(VBoxGuestFacilityType enmFacility)
|
---|
[35907] | 1026 | {
|
---|
[35970] | 1027 | Assert(enmFacility < INT32_MAX);
|
---|
[35967] | 1028 | FacilityMapIterConst it = mData.mFacilityMap.find((AdditionsFacilityType_T)enmFacility);
|
---|
| 1029 | if (it != mData.mFacilityMap.end())
|
---|
| 1030 | {
|
---|
| 1031 | AdditionsFacility *pFac = it->second;
|
---|
[50370] | 1032 | return (pFac->i_getStatus() == AdditionsFacilityStatus_Active);
|
---|
[35967] | 1033 | }
|
---|
| 1034 | return false;
|
---|
[35907] | 1035 | }
|
---|
| 1036 |
|
---|
[79050] | 1037 | bool Guest::i_facilityUpdate(VBoxGuestFacilityType a_enmFacility, VBoxGuestFacilityStatus a_enmStatus,
|
---|
[52082] | 1038 | uint32_t a_fFlags, PCRTTIMESPEC a_pTimeSpecTS)
|
---|
[35907] | 1039 | {
|
---|
[79050] | 1040 | AssertReturn( a_enmFacility < VBoxGuestFacilityType_All
|
---|
| 1041 | && a_enmFacility > VBoxGuestFacilityType_Unknown, false);
|
---|
[35907] | 1042 |
|
---|
[79050] | 1043 | bool fChanged;
|
---|
[39890] | 1044 | FacilityMapIter it = mData.mFacilityMap.find((AdditionsFacilityType_T)a_enmFacility);
|
---|
[35967] | 1045 | if (it != mData.mFacilityMap.end())
|
---|
| 1046 | {
|
---|
| 1047 | AdditionsFacility *pFac = it->second;
|
---|
[79050] | 1048 | fChanged = pFac->i_update((AdditionsFacilityStatus_T)a_enmStatus, a_fFlags, a_pTimeSpecTS);
|
---|
[35967] | 1049 | }
|
---|
| 1050 | else
|
---|
| 1051 | {
|
---|
[39890] | 1052 | if (mData.mFacilityMap.size() > 64)
|
---|
| 1053 | {
|
---|
| 1054 | /* The easy way out for now. We could automatically destroy
|
---|
| 1055 | inactive facilities like VMMDev does if we like... */
|
---|
[79050] | 1056 | AssertFailedReturn(false);
|
---|
[39890] | 1057 | }
|
---|
| 1058 |
|
---|
| 1059 | ComObjPtr<AdditionsFacility> ptrFac;
|
---|
[79053] | 1060 | HRESULT hrc = ptrFac.createObject();
|
---|
| 1061 | AssertComRCReturn(hrc, false);
|
---|
| 1062 | Assert(ptrFac);
|
---|
[39890] | 1063 |
|
---|
[79053] | 1064 | hrc = ptrFac->init(this, (AdditionsFacilityType_T)a_enmFacility, (AdditionsFacilityStatus_T)a_enmStatus,
|
---|
| 1065 | a_fFlags, a_pTimeSpecTS);
|
---|
[79050] | 1066 | AssertComRCReturn(hrc, false);
|
---|
[79053] | 1067 | try
|
---|
| 1068 | {
|
---|
| 1069 | mData.mFacilityMap.insert(std::make_pair((AdditionsFacilityType_T)a_enmFacility, ptrFac));
|
---|
| 1070 | fChanged = true;
|
---|
| 1071 | }
|
---|
| 1072 | catch (std::bad_alloc &)
|
---|
| 1073 | {
|
---|
| 1074 | fChanged = false;
|
---|
| 1075 | }
|
---|
[35967] | 1076 | }
|
---|
[79050] | 1077 | return fChanged;
|
---|
[35907] | 1078 | }
|
---|
| 1079 |
|
---|
[31241] | 1080 | /**
|
---|
[47294] | 1081 | * Issued by the guest when a guest user changed its state.
|
---|
| 1082 | *
|
---|
| 1083 | * @param aUser Guest user name.
|
---|
| 1084 | * @param aDomain Domain of guest user account. Optional.
|
---|
| 1085 | * @param enmState New state to indicate.
|
---|
[55644] | 1086 | * @param pbDetails Pointer to state details. Optional.
|
---|
[47294] | 1087 | * @param cbDetails Size (in bytes) of state details. Pass 0 if not used.
|
---|
| 1088 | */
|
---|
[85309] | 1089 | void Guest::i_onUserStateChanged(const Utf8Str &aUser, const Utf8Str &aDomain, VBoxGuestUserState enmState,
|
---|
| 1090 | const uint8_t *pbDetails, uint32_t cbDetails)
|
---|
[47294] | 1091 | {
|
---|
[63244] | 1092 | RT_NOREF(pbDetails, cbDetails);
|
---|
[47294] | 1093 | LogFlowThisFunc(("\n"));
|
---|
| 1094 |
|
---|
| 1095 | AutoCaller autoCaller(this);
|
---|
[98262] | 1096 | AssertComRCReturnVoid(autoCaller.hrc());
|
---|
[47294] | 1097 |
|
---|
[85309] | 1098 | Utf8Str strDetails; /** @todo Implement state details here. */
|
---|
[47294] | 1099 |
|
---|
[85309] | 1100 | ::FireGuestUserStateChangedEvent(mEventSource, aUser, aDomain, (GuestUserState_T)enmState, strDetails);
|
---|
[47294] | 1101 | LogFlowFuncLeave();
|
---|
| 1102 | }
|
---|
| 1103 |
|
---|
| 1104 | /**
|
---|
[30758] | 1105 | * Sets the status of a certain Guest Additions facility.
|
---|
| 1106 | *
|
---|
[39890] | 1107 | * Gets called by vmmdevUpdateGuestStatus, which just passes the report along.
|
---|
| 1108 | *
|
---|
| 1109 | * @param a_enmFacility The facility.
|
---|
| 1110 | * @param a_enmStatus The status.
|
---|
| 1111 | * @param a_fFlags Flags assoicated with the update. Currently
|
---|
| 1112 | * reserved and should be ignored.
|
---|
| 1113 | * @param a_pTimeSpecTS Pointer to the timestamp of this report.
|
---|
| 1114 | * @sa PDMIVMMDEVCONNECTOR::pfnUpdateGuestStatus, vmmdevUpdateGuestStatus
|
---|
| 1115 | * @thread The emulation thread.
|
---|
[30758] | 1116 | */
|
---|
[52082] | 1117 | void Guest::i_setAdditionsStatus(VBoxGuestFacilityType a_enmFacility, VBoxGuestFacilityStatus a_enmStatus,
|
---|
| 1118 | uint32_t a_fFlags, PCRTTIMESPEC a_pTimeSpecTS)
|
---|
[3582] | 1119 | {
|
---|
[39890] | 1120 | Assert( a_enmFacility > VBoxGuestFacilityType_Unknown
|
---|
| 1121 | && a_enmFacility <= VBoxGuestFacilityType_All); /* Paranoia, VMMDev checks for this. */
|
---|
| 1122 |
|
---|
[21878] | 1123 | AutoCaller autoCaller(this);
|
---|
[98262] | 1124 | AssertComRCReturnVoid(autoCaller.hrc());
|
---|
[3582] | 1125 |
|
---|
[25310] | 1126 | AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
[3582] | 1127 |
|
---|
[35887] | 1128 | /*
|
---|
[39890] | 1129 | * Set a specific facility status.
|
---|
[35887] | 1130 | */
|
---|
[79050] | 1131 | bool fFireEvent = false;
|
---|
[39890] | 1132 | if (a_enmFacility == VBoxGuestFacilityType_All)
|
---|
| 1133 | for (FacilityMapIter it = mData.mFacilityMap.begin(); it != mData.mFacilityMap.end(); ++it)
|
---|
[79050] | 1134 | fFireEvent |= i_facilityUpdate((VBoxGuestFacilityType)it->first, a_enmStatus, a_fFlags, a_pTimeSpecTS);
|
---|
[39890] | 1135 | else /* Update one facility only. */
|
---|
[79050] | 1136 | fFireEvent = i_facilityUpdate(a_enmFacility, a_enmStatus, a_fFlags, a_pTimeSpecTS);
|
---|
[32020] | 1137 |
|
---|
[39890] | 1138 | /*
|
---|
| 1139 | * Recalc the runlevel.
|
---|
| 1140 | */
|
---|
[79050] | 1141 | AdditionsRunLevelType_T const enmOldRunLevel = mData.mAdditionsRunLevel;
|
---|
[52082] | 1142 | if (i_facilityIsActive(VBoxGuestFacilityType_VBoxTrayClient))
|
---|
[32086] | 1143 | mData.mAdditionsRunLevel = AdditionsRunLevelType_Desktop;
|
---|
[52082] | 1144 | else if (i_facilityIsActive(VBoxGuestFacilityType_VBoxService))
|
---|
[32086] | 1145 | mData.mAdditionsRunLevel = AdditionsRunLevelType_Userland;
|
---|
[52082] | 1146 | else if (i_facilityIsActive(VBoxGuestFacilityType_VBoxGuestDriver))
|
---|
[32086] | 1147 | mData.mAdditionsRunLevel = AdditionsRunLevelType_System;
|
---|
[39890] | 1148 | else
|
---|
| 1149 | mData.mAdditionsRunLevel = AdditionsRunLevelType_None;
|
---|
[79050] | 1150 |
|
---|
| 1151 | /*
|
---|
| 1152 | * Fire event if something actually changed.
|
---|
| 1153 | */
|
---|
| 1154 | AdditionsRunLevelType_T const enmNewRunLevel = mData.mAdditionsRunLevel;
|
---|
| 1155 | if (fFireEvent || enmNewRunLevel != enmOldRunLevel)
|
---|
| 1156 | {
|
---|
| 1157 | alock.release();
|
---|
[85300] | 1158 | ::FireGuestAdditionsStatusChangedEvent(mEventSource, (AdditionsFacilityType_T)a_enmFacility,
|
---|
| 1159 | (AdditionsFacilityStatus_T)a_enmStatus, enmNewRunLevel,
|
---|
| 1160 | RTTimeSpecGetMilli(a_pTimeSpecTS));
|
---|
[79050] | 1161 | }
|
---|
[3582] | 1162 | }
|
---|
[7409] | 1163 |
|
---|
[30758] | 1164 | /**
|
---|
| 1165 | * Sets the supported features (and whether they are active or not).
|
---|
| 1166 | *
|
---|
[65120] | 1167 | * @param aCaps Guest capability bit mask (VMMDEV_GUEST_SUPPORTS_XXX).
|
---|
[30758] | 1168 | */
|
---|
[52082] | 1169 | void Guest::i_setSupportedFeatures(uint32_t aCaps)
|
---|
[7409] | 1170 | {
|
---|
[21878] | 1171 | AutoCaller autoCaller(this);
|
---|
[98262] | 1172 | AssertComRCReturnVoid(autoCaller.hrc());
|
---|
[7409] | 1173 |
|
---|
[25310] | 1174 | AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
[7409] | 1175 |
|
---|
[39890] | 1176 | /** @todo A nit: The timestamp is wrong on saved state restore. Would be better
|
---|
| 1177 | * to move the graphics and seamless capability -> facility translation to
|
---|
| 1178 | * VMMDev so this could be saved. */
|
---|
| 1179 | RTTIMESPEC TimeSpecTS;
|
---|
| 1180 | RTTimeNow(&TimeSpecTS);
|
---|
| 1181 |
|
---|
[79055] | 1182 | bool fFireEvent = i_facilityUpdate(VBoxGuestFacilityType_Seamless,
|
---|
| 1183 | aCaps & VMMDEV_GUEST_SUPPORTS_SEAMLESS
|
---|
| 1184 | ? VBoxGuestFacilityStatus_Active : VBoxGuestFacilityStatus_Inactive,
|
---|
| 1185 | 0 /*fFlags*/, &TimeSpecTS);
|
---|
[30758] | 1186 | /** @todo Add VMMDEV_GUEST_SUPPORTS_GUEST_HOST_WINDOW_MAPPING */
|
---|
[79055] | 1187 |
|
---|
| 1188 | /*
|
---|
| 1189 | * Fire event if the state actually changed.
|
---|
| 1190 | */
|
---|
| 1191 | if (fFireEvent)
|
---|
| 1192 | {
|
---|
| 1193 | AdditionsRunLevelType_T const enmRunLevel = mData.mAdditionsRunLevel;
|
---|
| 1194 | alock.release();
|
---|
[85300] | 1195 | ::FireGuestAdditionsStatusChangedEvent(mEventSource, AdditionsFacilityType_Seamless,
|
---|
| 1196 | aCaps & VMMDEV_GUEST_SUPPORTS_SEAMLESS
|
---|
| 1197 | ? AdditionsFacilityStatus_Active : AdditionsFacilityStatus_Inactive,
|
---|
| 1198 | enmRunLevel, RTTimeSpecGetMilli(&TimeSpecTS));
|
---|
[79055] | 1199 | }
|
---|
[7409] | 1200 | }
|
---|