VirtualBox

source: vbox/trunk/src/VBox/Main/src-client/GuestImpl.cpp@ 79050

Last change on this file since 79050 was 79050, checked in by vboxsync, 5 years ago

Main/GuestImpl: Added OnGuestAdditionsStatusChanged event so the validation kit can more efficiently wait on GAs to come online. bugref:9151

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

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette