1 | /* $Id: GuestImpl.cpp 35907 2011-02-09 11:20:31Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VirtualBox COM class implementation: Guest
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2006-2011 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 | #include "GuestImpl.h"
|
---|
19 |
|
---|
20 | #include "Global.h"
|
---|
21 | #include "ConsoleImpl.h"
|
---|
22 | #include "ProgressImpl.h"
|
---|
23 | #include "VMMDev.h"
|
---|
24 |
|
---|
25 | #include "AutoCaller.h"
|
---|
26 | #include "Logging.h"
|
---|
27 |
|
---|
28 | #include <VBox/VMMDev.h>
|
---|
29 | #ifdef VBOX_WITH_GUEST_CONTROL
|
---|
30 | # include <VBox/com/array.h>
|
---|
31 | # include <VBox/com/ErrorInfo.h>
|
---|
32 | #endif
|
---|
33 | #include <iprt/cpp/utils.h>
|
---|
34 | #include <VBox/vmm/pgm.h>
|
---|
35 |
|
---|
36 | // defines
|
---|
37 | /////////////////////////////////////////////////////////////////////////////
|
---|
38 |
|
---|
39 | // constructor / destructor
|
---|
40 | /////////////////////////////////////////////////////////////////////////////
|
---|
41 |
|
---|
42 | DEFINE_EMPTY_CTOR_DTOR (Guest)
|
---|
43 |
|
---|
44 | HRESULT Guest::FinalConstruct()
|
---|
45 | {
|
---|
46 | return BaseFinalConstruct();
|
---|
47 | }
|
---|
48 |
|
---|
49 | void Guest::FinalRelease()
|
---|
50 | {
|
---|
51 | uninit ();
|
---|
52 | BaseFinalRelease();
|
---|
53 | }
|
---|
54 |
|
---|
55 | // public methods only for internal purposes
|
---|
56 | /////////////////////////////////////////////////////////////////////////////
|
---|
57 |
|
---|
58 | /**
|
---|
59 | * Initializes the guest object.
|
---|
60 | */
|
---|
61 | HRESULT Guest::init(Console *aParent)
|
---|
62 | {
|
---|
63 | LogFlowThisFunc(("aParent=%p\n", aParent));
|
---|
64 |
|
---|
65 | ComAssertRet(aParent, E_INVALIDARG);
|
---|
66 |
|
---|
67 | /* Enclose the state transition NotReady->InInit->Ready */
|
---|
68 | AutoInitSpan autoInitSpan(this);
|
---|
69 | AssertReturn(autoInitSpan.isOk(), E_FAIL);
|
---|
70 |
|
---|
71 | unconst(mParent) = aParent;
|
---|
72 |
|
---|
73 | /* Confirm a successful initialization when it's the case */
|
---|
74 | autoInitSpan.setSucceeded();
|
---|
75 |
|
---|
76 | ULONG aMemoryBalloonSize;
|
---|
77 | HRESULT ret = mParent->machine()->COMGETTER(MemoryBalloonSize)(&aMemoryBalloonSize);
|
---|
78 | if (ret == S_OK)
|
---|
79 | mMemoryBalloonSize = aMemoryBalloonSize;
|
---|
80 | else
|
---|
81 | mMemoryBalloonSize = 0; /* Default is no ballooning */
|
---|
82 |
|
---|
83 | BOOL fPageFusionEnabled;
|
---|
84 | ret = mParent->machine()->COMGETTER(PageFusionEnabled)(&fPageFusionEnabled);
|
---|
85 | if (ret == S_OK)
|
---|
86 | mfPageFusionEnabled = fPageFusionEnabled;
|
---|
87 | else
|
---|
88 | mfPageFusionEnabled = false; /* Default is no page fusion*/
|
---|
89 |
|
---|
90 | mStatUpdateInterval = 0; /* Default is not to report guest statistics at all */
|
---|
91 |
|
---|
92 | /* Clear statistics. */
|
---|
93 | for (unsigned i = 0 ; i < GUESTSTATTYPE_MAX; i++)
|
---|
94 | mCurrentGuestStat[i] = 0;
|
---|
95 |
|
---|
96 | #ifdef VBOX_WITH_GUEST_CONTROL
|
---|
97 | /* Init the context ID counter at 1000. */
|
---|
98 | mNextContextID = 1000;
|
---|
99 | #endif
|
---|
100 |
|
---|
101 | return S_OK;
|
---|
102 | }
|
---|
103 |
|
---|
104 | /**
|
---|
105 | * Uninitializes the instance and sets the ready flag to FALSE.
|
---|
106 | * Called either from FinalRelease() or by the parent when it gets destroyed.
|
---|
107 | */
|
---|
108 | void Guest::uninit()
|
---|
109 | {
|
---|
110 | LogFlowThisFunc(("\n"));
|
---|
111 |
|
---|
112 | #ifdef VBOX_WITH_GUEST_CONTROL
|
---|
113 | /* Scope write lock as much as possible. */
|
---|
114 | {
|
---|
115 | /*
|
---|
116 | * Cleanup must be done *before* AutoUninitSpan to cancel all
|
---|
117 | * all outstanding waits in API functions (which hold AutoCaller
|
---|
118 | * ref counts).
|
---|
119 | */
|
---|
120 | AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
121 |
|
---|
122 | /* Clean up callback data. */
|
---|
123 | CallbackMapIter it;
|
---|
124 | for (it = mCallbackMap.begin(); it != mCallbackMap.end(); it++)
|
---|
125 | destroyCtrlCallbackContext(it);
|
---|
126 |
|
---|
127 | /* Clear process map. */
|
---|
128 | mGuestProcessMap.clear();
|
---|
129 | }
|
---|
130 | #endif
|
---|
131 |
|
---|
132 | /* Enclose the state transition Ready->InUninit->NotReady */
|
---|
133 | AutoUninitSpan autoUninitSpan(this);
|
---|
134 | if (autoUninitSpan.uninitDone())
|
---|
135 | return;
|
---|
136 |
|
---|
137 | unconst(mParent) = NULL;
|
---|
138 | }
|
---|
139 |
|
---|
140 | // IGuest properties
|
---|
141 | /////////////////////////////////////////////////////////////////////////////
|
---|
142 |
|
---|
143 | STDMETHODIMP Guest::COMGETTER(OSTypeId) (BSTR *aOSTypeId)
|
---|
144 | {
|
---|
145 | CheckComArgOutPointerValid(aOSTypeId);
|
---|
146 |
|
---|
147 | AutoCaller autoCaller(this);
|
---|
148 | if (FAILED(autoCaller.rc())) return autoCaller.rc();
|
---|
149 |
|
---|
150 | AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
151 |
|
---|
152 | /* Redirect the call to IMachine if no additions are installed. */
|
---|
153 | if (mData.mAdditionsVersion.isEmpty())
|
---|
154 | return mParent->machine()->COMGETTER(OSTypeId)(aOSTypeId);
|
---|
155 |
|
---|
156 | mData.mOSTypeId.cloneTo(aOSTypeId);
|
---|
157 |
|
---|
158 | return S_OK;
|
---|
159 | }
|
---|
160 |
|
---|
161 | STDMETHODIMP Guest::COMGETTER(AdditionsRunLevel) (AdditionsRunLevelType_T *aRunLevel)
|
---|
162 | {
|
---|
163 | AutoCaller autoCaller(this);
|
---|
164 | if (FAILED(autoCaller.rc())) return autoCaller.rc();
|
---|
165 |
|
---|
166 | AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
167 |
|
---|
168 | *aRunLevel = mData.mAdditionsRunLevel;
|
---|
169 |
|
---|
170 | return S_OK;
|
---|
171 | }
|
---|
172 |
|
---|
173 | STDMETHODIMP Guest::COMGETTER(AdditionsVersion) (BSTR *aAdditionsVersion)
|
---|
174 | {
|
---|
175 | CheckComArgOutPointerValid(aAdditionsVersion);
|
---|
176 |
|
---|
177 | AutoCaller autoCaller(this);
|
---|
178 | if (FAILED(autoCaller.rc())) return autoCaller.rc();
|
---|
179 |
|
---|
180 | AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
181 |
|
---|
182 | HRESULT hr = S_OK;
|
---|
183 | if ( mData.mAdditionsVersion.isEmpty()
|
---|
184 | /* Only try alternative way if GA are active! */
|
---|
185 | && mData.mAdditionsRunLevel > AdditionsRunLevelType_None)
|
---|
186 | {
|
---|
187 | /*
|
---|
188 | * If we got back an empty string from GetAdditionsVersion() we either
|
---|
189 | * really don't have the Guest Additions version yet or the guest is running
|
---|
190 | * older Guest Additions (< 3.2.0) which don't provide VMMDevReq_ReportGuestInfo2,
|
---|
191 | * so get the version + revision from the (hopefully) provided guest properties
|
---|
192 | * instead.
|
---|
193 | */
|
---|
194 | Bstr addVersion;
|
---|
195 | LONG64 u64Timestamp;
|
---|
196 | Bstr flags;
|
---|
197 | hr = mParent->machine()->GetGuestProperty(Bstr("/VirtualBox/GuestAdd/Version").raw(),
|
---|
198 | addVersion.asOutParam(), &u64Timestamp, flags.asOutParam());
|
---|
199 | if (hr == S_OK)
|
---|
200 | {
|
---|
201 | Bstr addRevision;
|
---|
202 | hr = mParent->machine()->GetGuestProperty(Bstr("/VirtualBox/GuestAdd/Revision").raw(),
|
---|
203 | addRevision.asOutParam(), &u64Timestamp, flags.asOutParam());
|
---|
204 | if ( hr == S_OK
|
---|
205 | && !addVersion.isEmpty()
|
---|
206 | && !addRevision.isEmpty())
|
---|
207 | {
|
---|
208 | /* Some Guest Additions versions had interchanged version + revision values,
|
---|
209 | * so check if the version value at least has a dot to identify it and change
|
---|
210 | * both values to reflect the right content. */
|
---|
211 | if (!Utf8Str(addVersion).contains("."))
|
---|
212 | {
|
---|
213 | Bstr addTemp = addVersion;
|
---|
214 | addVersion = addRevision;
|
---|
215 | addRevision = addTemp;
|
---|
216 | }
|
---|
217 |
|
---|
218 | Bstr additionsVersion = BstrFmt("%ls r%ls",
|
---|
219 | addVersion.raw(), addRevision.raw());
|
---|
220 | additionsVersion.cloneTo(aAdditionsVersion);
|
---|
221 | }
|
---|
222 | /** @todo r=bird: else: Should not return failure! */
|
---|
223 | }
|
---|
224 | else
|
---|
225 | {
|
---|
226 | /* If getting the version + revision above fails or they simply aren't there
|
---|
227 | * because of *really* old Guest Additions we only can report the interface
|
---|
228 | * version to at least have something. */
|
---|
229 | mData.mInterfaceVersion.cloneTo(aAdditionsVersion);
|
---|
230 | /** @todo r=bird: hr is still indicating failure! */
|
---|
231 | }
|
---|
232 | }
|
---|
233 | else
|
---|
234 | mData.mAdditionsVersion.cloneTo(aAdditionsVersion);
|
---|
235 |
|
---|
236 | return hr;
|
---|
237 | }
|
---|
238 |
|
---|
239 | BOOL Guest::isPageFusionEnabled()
|
---|
240 | {
|
---|
241 | AutoCaller autoCaller(this);
|
---|
242 | if (FAILED(autoCaller.rc())) return false;
|
---|
243 |
|
---|
244 | AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
245 |
|
---|
246 | return mfPageFusionEnabled;
|
---|
247 | }
|
---|
248 |
|
---|
249 | STDMETHODIMP Guest::COMGETTER(MemoryBalloonSize) (ULONG *aMemoryBalloonSize)
|
---|
250 | {
|
---|
251 | CheckComArgOutPointerValid(aMemoryBalloonSize);
|
---|
252 |
|
---|
253 | AutoCaller autoCaller(this);
|
---|
254 | if (FAILED(autoCaller.rc())) return autoCaller.rc();
|
---|
255 |
|
---|
256 | AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
257 |
|
---|
258 | *aMemoryBalloonSize = mMemoryBalloonSize;
|
---|
259 |
|
---|
260 | return S_OK;
|
---|
261 | }
|
---|
262 |
|
---|
263 | STDMETHODIMP Guest::COMSETTER(MemoryBalloonSize) (ULONG aMemoryBalloonSize)
|
---|
264 | {
|
---|
265 | AutoCaller autoCaller(this);
|
---|
266 | if (FAILED(autoCaller.rc())) return autoCaller.rc();
|
---|
267 |
|
---|
268 | AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
269 |
|
---|
270 | /* We must be 100% sure that IMachine::COMSETTER(MemoryBalloonSize)
|
---|
271 | * does not call us back in any way! */
|
---|
272 | HRESULT ret = mParent->machine()->COMSETTER(MemoryBalloonSize)(aMemoryBalloonSize);
|
---|
273 | if (ret == S_OK)
|
---|
274 | {
|
---|
275 | mMemoryBalloonSize = aMemoryBalloonSize;
|
---|
276 | /* forward the information to the VMM device */
|
---|
277 | VMMDev *pVMMDev = mParent->getVMMDev();
|
---|
278 | /* MUST release all locks before calling VMM device as its critsect
|
---|
279 | * has higher lock order than anything in Main. */
|
---|
280 | alock.release();
|
---|
281 | if (pVMMDev)
|
---|
282 | {
|
---|
283 | PPDMIVMMDEVPORT pVMMDevPort = pVMMDev->getVMMDevPort();
|
---|
284 | if (pVMMDevPort)
|
---|
285 | pVMMDevPort->pfnSetMemoryBalloon(pVMMDevPort, aMemoryBalloonSize);
|
---|
286 | }
|
---|
287 | }
|
---|
288 |
|
---|
289 | return ret;
|
---|
290 | }
|
---|
291 |
|
---|
292 | STDMETHODIMP Guest::COMGETTER(StatisticsUpdateInterval)(ULONG *aUpdateInterval)
|
---|
293 | {
|
---|
294 | CheckComArgOutPointerValid(aUpdateInterval);
|
---|
295 |
|
---|
296 | AutoCaller autoCaller(this);
|
---|
297 | if (FAILED(autoCaller.rc())) return autoCaller.rc();
|
---|
298 |
|
---|
299 | AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
300 |
|
---|
301 | *aUpdateInterval = mStatUpdateInterval;
|
---|
302 | return S_OK;
|
---|
303 | }
|
---|
304 |
|
---|
305 | STDMETHODIMP Guest::COMSETTER(StatisticsUpdateInterval)(ULONG aUpdateInterval)
|
---|
306 | {
|
---|
307 | AutoCaller autoCaller(this);
|
---|
308 | if (FAILED(autoCaller.rc())) return autoCaller.rc();
|
---|
309 |
|
---|
310 | AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
311 |
|
---|
312 | mStatUpdateInterval = aUpdateInterval;
|
---|
313 | /* forward the information to the VMM device */
|
---|
314 | VMMDev *pVMMDev = mParent->getVMMDev();
|
---|
315 | /* MUST release all locks before calling VMM device as its critsect
|
---|
316 | * has higher lock order than anything in Main. */
|
---|
317 | alock.release();
|
---|
318 | if (pVMMDev)
|
---|
319 | {
|
---|
320 | PPDMIVMMDEVPORT pVMMDevPort = pVMMDev->getVMMDevPort();
|
---|
321 | if (pVMMDevPort)
|
---|
322 | pVMMDevPort->pfnSetStatisticsInterval(pVMMDevPort, aUpdateInterval);
|
---|
323 | }
|
---|
324 |
|
---|
325 | return S_OK;
|
---|
326 | }
|
---|
327 |
|
---|
328 | STDMETHODIMP Guest::InternalGetStatistics(ULONG *aCpuUser, ULONG *aCpuKernel, ULONG *aCpuIdle,
|
---|
329 | ULONG *aMemTotal, ULONG *aMemFree, ULONG *aMemBalloon, ULONG *aMemShared,
|
---|
330 | ULONG *aMemCache, ULONG *aPageTotal,
|
---|
331 | ULONG *aMemAllocTotal, ULONG *aMemFreeTotal, ULONG *aMemBalloonTotal, ULONG *aMemSharedTotal)
|
---|
332 | {
|
---|
333 | CheckComArgOutPointerValid(aCpuUser);
|
---|
334 | CheckComArgOutPointerValid(aCpuKernel);
|
---|
335 | CheckComArgOutPointerValid(aCpuIdle);
|
---|
336 | CheckComArgOutPointerValid(aMemTotal);
|
---|
337 | CheckComArgOutPointerValid(aMemFree);
|
---|
338 | CheckComArgOutPointerValid(aMemBalloon);
|
---|
339 | CheckComArgOutPointerValid(aMemShared);
|
---|
340 | CheckComArgOutPointerValid(aMemCache);
|
---|
341 | CheckComArgOutPointerValid(aPageTotal);
|
---|
342 | CheckComArgOutPointerValid(aMemAllocTotal);
|
---|
343 | CheckComArgOutPointerValid(aMemFreeTotal);
|
---|
344 | CheckComArgOutPointerValid(aMemBalloonTotal);
|
---|
345 | CheckComArgOutPointerValid(aMemSharedTotal);
|
---|
346 |
|
---|
347 | AutoCaller autoCaller(this);
|
---|
348 | if (FAILED(autoCaller.rc())) return autoCaller.rc();
|
---|
349 |
|
---|
350 | AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
351 |
|
---|
352 | *aCpuUser = mCurrentGuestStat[GUESTSTATTYPE_CPUUSER];
|
---|
353 | *aCpuKernel = mCurrentGuestStat[GUESTSTATTYPE_CPUKERNEL];
|
---|
354 | *aCpuIdle = mCurrentGuestStat[GUESTSTATTYPE_CPUIDLE];
|
---|
355 | *aMemTotal = mCurrentGuestStat[GUESTSTATTYPE_MEMTOTAL] * (_4K/_1K); /* page (4K) -> 1KB units */
|
---|
356 | *aMemFree = mCurrentGuestStat[GUESTSTATTYPE_MEMFREE] * (_4K/_1K); /* page (4K) -> 1KB units */
|
---|
357 | *aMemBalloon = mCurrentGuestStat[GUESTSTATTYPE_MEMBALLOON] * (_4K/_1K); /* page (4K) -> 1KB units */
|
---|
358 | *aMemCache = mCurrentGuestStat[GUESTSTATTYPE_MEMCACHE] * (_4K/_1K); /* page (4K) -> 1KB units */
|
---|
359 | *aPageTotal = mCurrentGuestStat[GUESTSTATTYPE_PAGETOTAL] * (_4K/_1K); /* page (4K) -> 1KB units */
|
---|
360 |
|
---|
361 | /* MUST release all locks before calling any PGM statistics queries,
|
---|
362 | * as they are executed by EMT and that might deadlock us by VMM device
|
---|
363 | * activity which waits for the Guest object lock. */
|
---|
364 | alock.release();
|
---|
365 | Console::SafeVMPtr pVM (mParent);
|
---|
366 | if (pVM.isOk())
|
---|
367 | {
|
---|
368 | uint64_t uFreeTotal, uAllocTotal, uBalloonedTotal, uSharedTotal;
|
---|
369 | *aMemFreeTotal = 0;
|
---|
370 | int rc = PGMR3QueryVMMMemoryStats(pVM.raw(), &uAllocTotal, &uFreeTotal, &uBalloonedTotal, &uSharedTotal);
|
---|
371 | AssertRC(rc);
|
---|
372 | if (rc == VINF_SUCCESS)
|
---|
373 | {
|
---|
374 | *aMemAllocTotal = (ULONG)(uAllocTotal / _1K); /* bytes -> KB */
|
---|
375 | *aMemFreeTotal = (ULONG)(uFreeTotal / _1K);
|
---|
376 | *aMemBalloonTotal = (ULONG)(uBalloonedTotal / _1K);
|
---|
377 | *aMemSharedTotal = (ULONG)(uSharedTotal / _1K);
|
---|
378 | }
|
---|
379 |
|
---|
380 | /* Query the missing per-VM memory statistics. */
|
---|
381 | *aMemShared = 0;
|
---|
382 | uint64_t uTotalMem, uPrivateMem, uSharedMem, uZeroMem;
|
---|
383 | rc = PGMR3QueryMemoryStats(pVM.raw(), &uTotalMem, &uPrivateMem, &uSharedMem, &uZeroMem);
|
---|
384 | if (rc == VINF_SUCCESS)
|
---|
385 | {
|
---|
386 | *aMemShared = (ULONG)(uSharedMem / _1K);
|
---|
387 | }
|
---|
388 | }
|
---|
389 | else
|
---|
390 | {
|
---|
391 | *aMemFreeTotal = 0;
|
---|
392 | *aMemShared = 0;
|
---|
393 | }
|
---|
394 |
|
---|
395 | return S_OK;
|
---|
396 | }
|
---|
397 |
|
---|
398 | HRESULT Guest::setStatistic(ULONG aCpuId, GUESTSTATTYPE enmType, ULONG aVal)
|
---|
399 | {
|
---|
400 | AutoCaller autoCaller(this);
|
---|
401 | if (FAILED(autoCaller.rc())) return autoCaller.rc();
|
---|
402 |
|
---|
403 | AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
404 |
|
---|
405 | if (enmType >= GUESTSTATTYPE_MAX)
|
---|
406 | return E_INVALIDARG;
|
---|
407 |
|
---|
408 | mCurrentGuestStat[enmType] = aVal;
|
---|
409 | return S_OK;
|
---|
410 | }
|
---|
411 |
|
---|
412 | /**
|
---|
413 | * Returns the status of a specified Guest Additions facility.
|
---|
414 | *
|
---|
415 | * @return aStatus Current status of specified facility.
|
---|
416 | * @param aType Facility to get the status from.
|
---|
417 | * @param aTimestamp Timestamp of last facility status update in ms (optional).
|
---|
418 | */
|
---|
419 | STDMETHODIMP Guest::GetFacilityStatus(AdditionsFacilityType_T aType, LONG64 *aTimestamp, AdditionsFacilityStatus_T *aStatus)
|
---|
420 | {
|
---|
421 | AutoCaller autoCaller(this);
|
---|
422 | if (FAILED(autoCaller.rc())) return autoCaller.rc();
|
---|
423 |
|
---|
424 | AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
425 |
|
---|
426 | CheckComArgNotNull(aStatus);
|
---|
427 | /* Not checking for aTimestamp is intentional; it's optional. */
|
---|
428 |
|
---|
429 | FacilityMapIter it = mData.mFacilityMap.find(aType);
|
---|
430 | if (it != mData.mFacilityMap.end())
|
---|
431 | {
|
---|
432 | *aStatus = it->second.curStatus;
|
---|
433 | if (aTimestamp)
|
---|
434 | *aTimestamp = RTTimeSpecGetMilli(&it->second.tsLastUpdated);
|
---|
435 | }
|
---|
436 | else
|
---|
437 | {
|
---|
438 | /*
|
---|
439 | * Do not fail here -- could be that the facility never has been brought up (yet) but
|
---|
440 | * the host wants to have its status anyway. So just tell we don't know at this point.
|
---|
441 | */
|
---|
442 | *aStatus = AdditionsFacilityStatus_Unknown;
|
---|
443 | if (aTimestamp)
|
---|
444 | *aTimestamp = RTTimeMilliTS();
|
---|
445 | }
|
---|
446 | return S_OK;
|
---|
447 | }
|
---|
448 |
|
---|
449 | STDMETHODIMP Guest::GetAdditionsStatus(AdditionsRunLevelType_T aLevel, BOOL *aActive)
|
---|
450 | {
|
---|
451 | AutoCaller autoCaller(this);
|
---|
452 | if (FAILED(autoCaller.rc())) return autoCaller.rc();
|
---|
453 |
|
---|
454 | AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
455 |
|
---|
456 | HRESULT rc = S_OK;
|
---|
457 | switch (aLevel)
|
---|
458 | {
|
---|
459 | case AdditionsRunLevelType_System:
|
---|
460 | *aActive = (mData.mAdditionsRunLevel > AdditionsRunLevelType_None);
|
---|
461 | break;
|
---|
462 |
|
---|
463 | case AdditionsRunLevelType_Userland:
|
---|
464 | *aActive = (mData.mAdditionsRunLevel >= AdditionsRunLevelType_Userland);
|
---|
465 | break;
|
---|
466 |
|
---|
467 | case AdditionsRunLevelType_Desktop:
|
---|
468 | *aActive = (mData.mAdditionsRunLevel >= AdditionsRunLevelType_Desktop);
|
---|
469 | break;
|
---|
470 |
|
---|
471 | default:
|
---|
472 | rc = setError(VBOX_E_NOT_SUPPORTED,
|
---|
473 | tr("Invalid status level defined: %u"), aLevel);
|
---|
474 | break;
|
---|
475 | }
|
---|
476 |
|
---|
477 | return rc;
|
---|
478 | }
|
---|
479 |
|
---|
480 | STDMETHODIMP Guest::SetCredentials(IN_BSTR aUserName, IN_BSTR aPassword,
|
---|
481 | IN_BSTR aDomain, BOOL aAllowInteractiveLogon)
|
---|
482 | {
|
---|
483 | AutoCaller autoCaller(this);
|
---|
484 | if (FAILED(autoCaller.rc())) return autoCaller.rc();
|
---|
485 |
|
---|
486 | /* forward the information to the VMM device */
|
---|
487 | VMMDev *pVMMDev = mParent->getVMMDev();
|
---|
488 | if (pVMMDev)
|
---|
489 | {
|
---|
490 | PPDMIVMMDEVPORT pVMMDevPort = pVMMDev->getVMMDevPort();
|
---|
491 | if (pVMMDevPort)
|
---|
492 | {
|
---|
493 | uint32_t u32Flags = VMMDEV_SETCREDENTIALS_GUESTLOGON;
|
---|
494 | if (!aAllowInteractiveLogon)
|
---|
495 | u32Flags = VMMDEV_SETCREDENTIALS_NOLOCALLOGON;
|
---|
496 |
|
---|
497 | pVMMDevPort->pfnSetCredentials(pVMMDevPort,
|
---|
498 | Utf8Str(aUserName).c_str(),
|
---|
499 | Utf8Str(aPassword).c_str(),
|
---|
500 | Utf8Str(aDomain).c_str(),
|
---|
501 | u32Flags);
|
---|
502 | return S_OK;
|
---|
503 | }
|
---|
504 | }
|
---|
505 |
|
---|
506 | return setError(VBOX_E_VM_ERROR,
|
---|
507 | tr("VMM device is not available (is the VM running?)"));
|
---|
508 | }
|
---|
509 |
|
---|
510 | // public methods only for internal purposes
|
---|
511 | /////////////////////////////////////////////////////////////////////////////
|
---|
512 |
|
---|
513 | /**
|
---|
514 | * Sets the general Guest Additions information like
|
---|
515 | * API (interface) version and OS type. Gets called by
|
---|
516 | * vmmdevUpdateGuestInfo.
|
---|
517 | *
|
---|
518 | * @param aInterfaceVersion
|
---|
519 | * @param aOsType
|
---|
520 | */
|
---|
521 | void Guest::setAdditionsInfo(Bstr aInterfaceVersion, VBOXOSTYPE aOsType)
|
---|
522 | {
|
---|
523 | AutoCaller autoCaller(this);
|
---|
524 | AssertComRCReturnVoid(autoCaller.rc());
|
---|
525 |
|
---|
526 | AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
527 |
|
---|
528 | /*
|
---|
529 | * Note: The Guest Additions API (interface) version is deprecated
|
---|
530 | * and will not be used anymore! We might need it to at least report
|
---|
531 | * something as version number if *really* ancient Guest Additions are
|
---|
532 | * installed (without the guest version + revision properties having set).
|
---|
533 | */
|
---|
534 | mData.mInterfaceVersion = aInterfaceVersion;
|
---|
535 |
|
---|
536 | /*
|
---|
537 | * Older Additions rely on the Additions API version whether they
|
---|
538 | * are assumed to be active or not. Since newer Additions do report
|
---|
539 | * the Additions version *before* calling this function (by calling
|
---|
540 | * VMMDevReportGuestInfo2, VMMDevReportGuestStatus, VMMDevReportGuestInfo,
|
---|
541 | * in that order) we can tell apart old and new Additions here. Old
|
---|
542 | * Additions never would set VMMDevReportGuestInfo2 (which set mData.mAdditionsVersion)
|
---|
543 | * so they just rely on the aInterfaceVersion string (which gets set by
|
---|
544 | * VMMDevReportGuestInfo).
|
---|
545 | *
|
---|
546 | * So only mark the Additions as being active (run level = system) when we
|
---|
547 | * don't have the Additions version set.
|
---|
548 | */
|
---|
549 | if (mData.mAdditionsVersion.isEmpty())
|
---|
550 | {
|
---|
551 | if (aInterfaceVersion.isEmpty())
|
---|
552 | mData.mAdditionsRunLevel = AdditionsRunLevelType_None;
|
---|
553 | else
|
---|
554 | mData.mAdditionsRunLevel = AdditionsRunLevelType_System;
|
---|
555 | }
|
---|
556 |
|
---|
557 | /*
|
---|
558 | * Older Additions didn't have this finer grained capability bit,
|
---|
559 | * so enable it by default. Newer Additions will not enable this here
|
---|
560 | * and use the setSupportedFeatures function instead.
|
---|
561 | */
|
---|
562 | updateFacility(VBoxGuestFacilityType_Graphics, facilityIsActive(VBoxGuestFacilityType_VBoxGuestDriver) ?
|
---|
563 | VBoxGuestFacilityStatus_Active : VBoxGuestFacilityStatus_Inactive);
|
---|
564 |
|
---|
565 | /*
|
---|
566 | * Note! There is a race going on between setting mAdditionsRunLevel and
|
---|
567 | * mSupportsGraphics here and disabling/enabling it later according to
|
---|
568 | * its real status when using new(er) Guest Additions.
|
---|
569 | */
|
---|
570 | mData.mOSTypeId = Global::OSTypeId (aOsType);
|
---|
571 | }
|
---|
572 |
|
---|
573 | /**
|
---|
574 | * Sets the Guest Additions version information details.
|
---|
575 | * Gets called by vmmdevUpdateGuestInfo2.
|
---|
576 | *
|
---|
577 | * @param aAdditionsVersion
|
---|
578 | * @param aVersionName
|
---|
579 | */
|
---|
580 | void Guest::setAdditionsInfo2(Bstr aAdditionsVersion, Bstr aVersionName, Bstr aRevision)
|
---|
581 | {
|
---|
582 | AutoCaller autoCaller(this);
|
---|
583 | AssertComRCReturnVoid(autoCaller.rc());
|
---|
584 |
|
---|
585 | AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
586 |
|
---|
587 | if (!aVersionName.isEmpty())
|
---|
588 | /*
|
---|
589 | * aVersionName could be "x.y.z_BETA1_FOOBAR", so append revision manually to
|
---|
590 | * become "x.y.z_BETA1_FOOBAR r12345".
|
---|
591 | */
|
---|
592 | mData.mAdditionsVersion = BstrFmt("%ls r%ls", aVersionName.raw(), aRevision.raw());
|
---|
593 | else /* aAdditionsVersion is in x.y.zr12345 format. */
|
---|
594 | mData.mAdditionsVersion = aAdditionsVersion;
|
---|
595 | }
|
---|
596 |
|
---|
597 | bool Guest::facilityIsActive(VBoxGuestFacilityType enmFacility)
|
---|
598 | {
|
---|
599 | return mData.mFacilityMap[(AdditionsFacilityType_T)enmFacility].curStatus == AdditionsFacilityStatus_Active;
|
---|
600 | }
|
---|
601 |
|
---|
602 | void Guest::updateFacility(VBoxGuestFacilityType enmFacility, VBoxGuestFacilityStatus enmStatus)
|
---|
603 | {
|
---|
604 | Assert(enmFacility < UINT32_MAX);
|
---|
605 | FacilityData *pData = &mData.mFacilityMap[(AdditionsFacilityType_T)enmFacility];
|
---|
606 | AssertPtr(pData);
|
---|
607 |
|
---|
608 | RTTimeNow(&pData->tsLastUpdated);
|
---|
609 | pData->curStatus = (AdditionsFacilityStatus_T)enmStatus;
|
---|
610 |
|
---|
611 | LogFlowFunc(("Setting guest facility %u = %u (%u)\n",
|
---|
612 | enmFacility, pData->curStatus, pData->tsLastUpdated));
|
---|
613 | }
|
---|
614 |
|
---|
615 | /**
|
---|
616 | * Sets the status of a certain Guest Additions facility.
|
---|
617 | * Gets called by vmmdevUpdateGuestStatus.
|
---|
618 | *
|
---|
619 | * @param enmFacility Facility to set the status for.
|
---|
620 | * @param enmStatus Actual status to set.
|
---|
621 | * @param aFlags
|
---|
622 | */
|
---|
623 | void Guest::setAdditionsStatus(VBoxGuestFacilityType enmFacility, VBoxGuestFacilityStatus enmStatus, ULONG aFlags)
|
---|
624 | {
|
---|
625 | AutoCaller autoCaller(this);
|
---|
626 | AssertComRCReturnVoid(autoCaller.rc());
|
---|
627 |
|
---|
628 | AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
629 |
|
---|
630 | /*
|
---|
631 | * Set overall additions run level.
|
---|
632 | */
|
---|
633 |
|
---|
634 | /* First check for disabled status. */
|
---|
635 | uint32_t uCurFacility = enmFacility + (enmStatus == VBoxGuestFacilityStatus_Active ? 0 : -1);
|
---|
636 | if ( enmFacility < VBoxGuestFacilityType_VBoxGuestDriver
|
---|
637 | || ( enmFacility == VBoxGuestFacilityType_All
|
---|
638 | && enmStatus == VBoxGuestFacilityStatus_Inactive)
|
---|
639 | )
|
---|
640 | {
|
---|
641 | mData.mAdditionsRunLevel = AdditionsRunLevelType_None;
|
---|
642 | }
|
---|
643 | else if (uCurFacility >= VBoxGuestFacilityType_VBoxTrayClient)
|
---|
644 | {
|
---|
645 | mData.mAdditionsRunLevel = AdditionsRunLevelType_Desktop;
|
---|
646 | }
|
---|
647 | else if (uCurFacility >= VBoxGuestFacilityType_VBoxService)
|
---|
648 | {
|
---|
649 | mData.mAdditionsRunLevel = AdditionsRunLevelType_Userland;
|
---|
650 | }
|
---|
651 | else if (uCurFacility >= VBoxGuestFacilityType_VBoxGuestDriver)
|
---|
652 | {
|
---|
653 | mData.mAdditionsRunLevel = AdditionsRunLevelType_System;
|
---|
654 | }
|
---|
655 | else /* Should never happen! */
|
---|
656 | AssertMsgFailed(("Invalid facility status/run level detected! uCurFacility=%ld\n", uCurFacility));
|
---|
657 |
|
---|
658 | /*
|
---|
659 | * Set a specific facility status.
|
---|
660 | */
|
---|
661 | if (enmFacility)
|
---|
662 | {
|
---|
663 | if (enmFacility == VBoxGuestFacilityType_All)
|
---|
664 | {
|
---|
665 | FacilityMapIter it = mData.mFacilityMap.begin();
|
---|
666 | while (it != mData.mFacilityMap.end())
|
---|
667 | {
|
---|
668 | updateFacility((VBoxGuestFacilityType)it->first, enmStatus);
|
---|
669 | it++;
|
---|
670 | }
|
---|
671 | }
|
---|
672 | else /* Update one facility only. */
|
---|
673 | updateFacility(enmFacility, enmStatus);
|
---|
674 | }
|
---|
675 | }
|
---|
676 |
|
---|
677 | /**
|
---|
678 | * Sets the supported features (and whether they are active or not).
|
---|
679 | *
|
---|
680 | * @param fCaps Guest capability bit mask (VMMDEV_GUEST_SUPPORTS_XXX).
|
---|
681 | */
|
---|
682 | void Guest::setSupportedFeatures(uint32_t aCaps)
|
---|
683 | {
|
---|
684 | AutoCaller autoCaller(this);
|
---|
685 | AssertComRCReturnVoid(autoCaller.rc());
|
---|
686 |
|
---|
687 | AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
688 |
|
---|
689 | updateFacility(VBoxGuestFacilityType_Seamless, aCaps & VMMDEV_GUEST_SUPPORTS_SEAMLESS ?
|
---|
690 | VBoxGuestFacilityStatus_Active : VBoxGuestFacilityStatus_Inactive);
|
---|
691 | /** @todo Add VMMDEV_GUEST_SUPPORTS_GUEST_HOST_WINDOW_MAPPING */
|
---|
692 | updateFacility(VBoxGuestFacilityType_Graphics, aCaps & VMMDEV_GUEST_SUPPORTS_GRAPHICS ?
|
---|
693 | VBoxGuestFacilityStatus_Active : VBoxGuestFacilityStatus_Inactive);
|
---|
694 | }
|
---|
695 | /* vi: set tabstop=4 shiftwidth=4 expandtab: */
|
---|