VirtualBox

source: vbox/trunk/src/VBox/Main/GuestImpl.cpp@ 29542

Last change on this file since 29542 was 29516, checked in by vboxsync, 15 years ago

Guest Control: Remove unused Std* arguments.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 45.0 KB
Line 
1/* $Id: GuestImpl.cpp 29516 2010-05-17 09:55:17Z vboxsync $ */
2
3/** @file
4 *
5 * VirtualBox COM class implementation
6 */
7
8/*
9 * Copyright (C) 2006-2008 Oracle Corporation
10 *
11 * This file is part of VirtualBox Open Source Edition (OSE), as
12 * available from http://www.215389.xyz. This file is free software;
13 * you can redistribute it and/or modify it under the terms of the GNU
14 * General Public License (GPL) as published by the Free Software
15 * Foundation, in version 2 as it comes in the "COPYING" file of the
16 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
17 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
18 */
19
20#include "GuestImpl.h"
21
22#include "Global.h"
23#include "ConsoleImpl.h"
24#include "ProgressImpl.h"
25#include "VMMDev.h"
26
27#include "AutoCaller.h"
28#include "Logging.h"
29
30#include <VBox/VMMDev.h>
31#ifdef VBOX_WITH_GUEST_CONTROL
32# include <VBox/com/array.h>
33#endif
34#include <iprt/cpp/utils.h>
35#include <iprt/getopt.h>
36#include <VBox/pgm.h>
37
38// defines
39/////////////////////////////////////////////////////////////////////////////
40
41// constructor / destructor
42/////////////////////////////////////////////////////////////////////////////
43
44DEFINE_EMPTY_CTOR_DTOR (Guest)
45
46HRESULT Guest::FinalConstruct()
47{
48 return S_OK;
49}
50
51void Guest::FinalRelease()
52{
53 uninit ();
54}
55
56// public methods only for internal purposes
57/////////////////////////////////////////////////////////////////////////////
58
59/**
60 * Initializes the guest object.
61 */
62HRESULT Guest::init (Console *aParent)
63{
64 LogFlowThisFunc(("aParent=%p\n", aParent));
65
66 ComAssertRet(aParent, E_INVALIDARG);
67
68 /* Enclose the state transition NotReady->InInit->Ready */
69 AutoInitSpan autoInitSpan(this);
70 AssertReturn(autoInitSpan.isOk(), E_FAIL);
71
72 unconst(mParent) = aParent;
73
74 /* mData.mAdditionsActive is FALSE */
75
76 /* Confirm a successful initialization when it's the case */
77 autoInitSpan.setSucceeded();
78
79 ULONG aMemoryBalloonSize;
80 HRESULT ret = mParent->machine()->COMGETTER(MemoryBalloonSize)(&aMemoryBalloonSize);
81 if (ret == S_OK)
82 mMemoryBalloonSize = aMemoryBalloonSize;
83 else
84 mMemoryBalloonSize = 0; /* Default is no ballooning */
85
86 mStatUpdateInterval = 0; /* Default is not to report guest statistics at all */
87
88 /* Clear statistics. */
89 for (unsigned i = 0 ; i < GUESTSTATTYPE_MAX; i++)
90 mCurrentGuestStat[i] = 0;
91
92#ifdef VBOX_WITH_GUEST_CONTROL
93 /* Init the context ID counter at 1000. */
94 mNextContextID = 1000;
95#endif
96
97 return S_OK;
98}
99
100/**
101 * Uninitializes the instance and sets the ready flag to FALSE.
102 * Called either from FinalRelease() or by the parent when it gets destroyed.
103 */
104void Guest::uninit()
105{
106 LogFlowThisFunc(("\n"));
107
108#ifdef VBOX_WITH_GUEST_CONTROL
109 /*
110 * Cleanup must be done *before* AutoUninitSpan to cancel all
111 * all outstanding waits in API functions (which hold AutoCaller
112 * ref counts).
113 */
114 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
115
116 /* Clean up callback data. */
117 CallbackListIter it;
118 for (it = mCallbackList.begin(); it != mCallbackList.end(); it++)
119 destroyCtrlCallbackContext(it);
120
121 /* Clear process list. */
122 mGuestProcessList.clear();
123#endif
124
125 /* Enclose the state transition Ready->InUninit->NotReady */
126 AutoUninitSpan autoUninitSpan(this);
127 if (autoUninitSpan.uninitDone())
128 return;
129
130 unconst(mParent) = NULL;
131}
132
133// IGuest properties
134/////////////////////////////////////////////////////////////////////////////
135
136STDMETHODIMP Guest::COMGETTER(OSTypeId) (BSTR *aOSTypeId)
137{
138 CheckComArgOutPointerValid(aOSTypeId);
139
140 AutoCaller autoCaller(this);
141 if (FAILED(autoCaller.rc())) return autoCaller.rc();
142
143 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
144
145 // redirect the call to IMachine if no additions are installed
146 if (mData.mAdditionsVersion.isEmpty())
147 return mParent->machine()->COMGETTER(OSTypeId)(aOSTypeId);
148
149 mData.mOSTypeId.cloneTo(aOSTypeId);
150
151 return S_OK;
152}
153
154STDMETHODIMP Guest::COMGETTER(AdditionsActive) (BOOL *aAdditionsActive)
155{
156 CheckComArgOutPointerValid(aAdditionsActive);
157
158 AutoCaller autoCaller(this);
159 if (FAILED(autoCaller.rc())) return autoCaller.rc();
160
161 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
162
163 *aAdditionsActive = mData.mAdditionsActive;
164
165 return S_OK;
166}
167
168STDMETHODIMP Guest::COMGETTER(AdditionsVersion) (BSTR *aAdditionsVersion)
169{
170 CheckComArgOutPointerValid(aAdditionsVersion);
171
172 AutoCaller autoCaller(this);
173 if (FAILED(autoCaller.rc())) return autoCaller.rc();
174
175 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
176
177 mData.mAdditionsVersion.cloneTo(aAdditionsVersion);
178
179 return S_OK;
180}
181
182STDMETHODIMP Guest::COMGETTER(SupportsSeamless) (BOOL *aSupportsSeamless)
183{
184 CheckComArgOutPointerValid(aSupportsSeamless);
185
186 AutoCaller autoCaller(this);
187 if (FAILED(autoCaller.rc())) return autoCaller.rc();
188
189 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
190
191 *aSupportsSeamless = mData.mSupportsSeamless;
192
193 return S_OK;
194}
195
196STDMETHODIMP Guest::COMGETTER(SupportsGraphics) (BOOL *aSupportsGraphics)
197{
198 CheckComArgOutPointerValid(aSupportsGraphics);
199
200 AutoCaller autoCaller(this);
201 if (FAILED(autoCaller.rc())) return autoCaller.rc();
202
203 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
204
205 *aSupportsGraphics = mData.mSupportsGraphics;
206
207 return S_OK;
208}
209
210STDMETHODIMP Guest::COMGETTER(MemoryBalloonSize) (ULONG *aMemoryBalloonSize)
211{
212 CheckComArgOutPointerValid(aMemoryBalloonSize);
213
214 AutoCaller autoCaller(this);
215 if (FAILED(autoCaller.rc())) return autoCaller.rc();
216
217 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
218
219 *aMemoryBalloonSize = mMemoryBalloonSize;
220
221 return S_OK;
222}
223
224STDMETHODIMP Guest::COMSETTER(MemoryBalloonSize) (ULONG aMemoryBalloonSize)
225{
226 AutoCaller autoCaller(this);
227 if (FAILED(autoCaller.rc())) return autoCaller.rc();
228
229 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
230
231 /* We must be 100% sure that IMachine::COMSETTER(MemoryBalloonSize)
232 * does not call us back in any way! */
233 HRESULT ret = mParent->machine()->COMSETTER(MemoryBalloonSize)(aMemoryBalloonSize);
234 if (ret == S_OK)
235 {
236 mMemoryBalloonSize = aMemoryBalloonSize;
237 /* forward the information to the VMM device */
238 VMMDev *vmmDev = mParent->getVMMDev();
239 if (vmmDev)
240 vmmDev->getVMMDevPort()->pfnSetMemoryBalloon(vmmDev->getVMMDevPort(), aMemoryBalloonSize);
241 }
242
243 return ret;
244}
245
246STDMETHODIMP Guest::COMGETTER(StatisticsUpdateInterval)(ULONG *aUpdateInterval)
247{
248 CheckComArgOutPointerValid(aUpdateInterval);
249
250 AutoCaller autoCaller(this);
251 if (FAILED(autoCaller.rc())) return autoCaller.rc();
252
253 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
254
255 *aUpdateInterval = mStatUpdateInterval;
256 return S_OK;
257}
258
259STDMETHODIMP Guest::COMSETTER(StatisticsUpdateInterval)(ULONG aUpdateInterval)
260{
261 AutoCaller autoCaller(this);
262 if (FAILED(autoCaller.rc())) return autoCaller.rc();
263
264 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
265
266 mStatUpdateInterval = aUpdateInterval;
267 /* forward the information to the VMM device */
268 VMMDev *vmmDev = mParent->getVMMDev();
269 if (vmmDev)
270 vmmDev->getVMMDevPort()->pfnSetStatisticsInterval(vmmDev->getVMMDevPort(), aUpdateInterval);
271
272 return S_OK;
273}
274
275STDMETHODIMP Guest::InternalGetStatistics(ULONG *aCpuUser, ULONG *aCpuKernel, ULONG *aCpuIdle,
276 ULONG *aMemTotal, ULONG *aMemFree, ULONG *aMemBalloon, ULONG *aMemShared,
277 ULONG *aMemCache, ULONG *aPageTotal,
278 ULONG *aMemAllocTotal, ULONG *aMemFreeTotal, ULONG *aMemBalloonTotal, ULONG *aMemSharedTotal)
279{
280 CheckComArgOutPointerValid(aCpuUser);
281 CheckComArgOutPointerValid(aCpuKernel);
282 CheckComArgOutPointerValid(aCpuIdle);
283 CheckComArgOutPointerValid(aMemTotal);
284 CheckComArgOutPointerValid(aMemFree);
285 CheckComArgOutPointerValid(aMemBalloon);
286 CheckComArgOutPointerValid(aMemShared);
287 CheckComArgOutPointerValid(aMemCache);
288 CheckComArgOutPointerValid(aPageTotal);
289 CheckComArgOutPointerValid(aMemAllocTotal);
290 CheckComArgOutPointerValid(aMemFreeTotal);
291 CheckComArgOutPointerValid(aMemBalloonTotal);
292 CheckComArgOutPointerValid(aMemSharedTotal);
293
294 AutoCaller autoCaller(this);
295 if (FAILED(autoCaller.rc())) return autoCaller.rc();
296
297 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
298
299 *aCpuUser = mCurrentGuestStat[GUESTSTATTYPE_CPUUSER];
300 *aCpuKernel = mCurrentGuestStat[GUESTSTATTYPE_CPUKERNEL];
301 *aCpuIdle = mCurrentGuestStat[GUESTSTATTYPE_CPUIDLE];
302 *aMemTotal = mCurrentGuestStat[GUESTSTATTYPE_MEMTOTAL] * (_4K/_1K); /* page (4K) -> 1KB units */
303 *aMemFree = mCurrentGuestStat[GUESTSTATTYPE_MEMFREE] * (_4K/_1K); /* page (4K) -> 1KB units */
304 *aMemBalloon = mCurrentGuestStat[GUESTSTATTYPE_MEMBALLOON] * (_4K/_1K); /* page (4K) -> 1KB units */
305 *aMemCache = mCurrentGuestStat[GUESTSTATTYPE_MEMCACHE] * (_4K/_1K); /* page (4K) -> 1KB units */
306 *aPageTotal = mCurrentGuestStat[GUESTSTATTYPE_PAGETOTAL] * (_4K/_1K); /* page (4K) -> 1KB units */
307 *aMemShared = 0; /** todo */
308
309 Console::SafeVMPtr pVM (mParent);
310 if (pVM.isOk())
311 {
312 uint64_t uFreeTotal, uAllocTotal, uBalloonedTotal;
313 *aMemFreeTotal = 0;
314 int rc = PGMR3QueryVMMMemoryStats(pVM.raw(), &uAllocTotal, &uFreeTotal, &uBalloonedTotal);
315 AssertRC(rc);
316 if (rc == VINF_SUCCESS)
317 {
318 *aMemAllocTotal = (ULONG)(uAllocTotal / _1K); /* bytes -> KB */
319 *aMemFreeTotal = (ULONG)(uFreeTotal / _1K);
320 *aMemBalloonTotal = (ULONG)(uBalloonedTotal / _1K);
321 *aMemSharedTotal = 0; /** todo */
322 }
323 }
324 else
325 *aMemFreeTotal = 0;
326
327 return S_OK;
328}
329
330HRESULT Guest::SetStatistic(ULONG aCpuId, GUESTSTATTYPE enmType, ULONG aVal)
331{
332 AutoCaller autoCaller(this);
333 if (FAILED(autoCaller.rc())) return autoCaller.rc();
334
335 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
336
337 if (enmType >= GUESTSTATTYPE_MAX)
338 return E_INVALIDARG;
339
340 mCurrentGuestStat[enmType] = aVal;
341 return S_OK;
342}
343
344STDMETHODIMP Guest::SetCredentials(IN_BSTR aUserName, IN_BSTR aPassword,
345 IN_BSTR aDomain, BOOL aAllowInteractiveLogon)
346{
347 AutoCaller autoCaller(this);
348 if (FAILED(autoCaller.rc())) return autoCaller.rc();
349
350 /* forward the information to the VMM device */
351 VMMDev *vmmDev = mParent->getVMMDev();
352 if (vmmDev)
353 {
354 uint32_t u32Flags = VMMDEV_SETCREDENTIALS_GUESTLOGON;
355 if (!aAllowInteractiveLogon)
356 u32Flags = VMMDEV_SETCREDENTIALS_NOLOCALLOGON;
357
358 vmmDev->getVMMDevPort()->pfnSetCredentials(vmmDev->getVMMDevPort(),
359 Utf8Str(aUserName).raw(), Utf8Str(aPassword).raw(),
360 Utf8Str(aDomain).raw(), u32Flags);
361 return S_OK;
362 }
363
364 return setError(VBOX_E_VM_ERROR,
365 tr("VMM device is not available (is the VM running?)"));
366}
367
368#ifdef VBOX_WITH_GUEST_CONTROL
369/**
370 * Appends environment variables to the environment block. Each var=value pair is separated
371 * by NULL (\0) sequence. The whole block will be stored in one blob and disassembled on the
372 * guest side later to fit into the HGCM param structure.
373 *
374 * @returns VBox status code.
375 *
376 * @todo
377 *
378 */
379int Guest::prepareExecuteEnv(const char *pszEnv, void **ppvList, uint32_t *pcbList, uint32_t *pcEnv)
380{
381 int rc = VINF_SUCCESS;
382 uint32_t cbLen = strlen(pszEnv);
383 if (*ppvList)
384 {
385 uint32_t cbNewLen = *pcbList + cbLen + 1; /* Include zero termination. */
386 char *pvTmp = (char*)RTMemRealloc(*ppvList, cbNewLen);
387 if (NULL == pvTmp)
388 {
389 rc = VERR_NO_MEMORY;
390 }
391 else
392 {
393 memcpy(pvTmp + *pcbList, pszEnv, cbLen);
394 pvTmp[cbNewLen - 1] = '\0'; /* Add zero termination. */
395 *ppvList = (void**)pvTmp;
396 }
397 }
398 else
399 {
400 char *pcTmp;
401 if (RTStrAPrintf(&pcTmp, "%s", pszEnv) > 0)
402 {
403 *ppvList = (void**)pcTmp;
404 /* Reset counters. */
405 *pcEnv = 0;
406 *pcbList = 0;
407 }
408 }
409 if (RT_SUCCESS(rc))
410 {
411 *pcbList += cbLen + 1; /* Include zero termination. */
412 *pcEnv += 1; /* Increase env pairs count. */
413 }
414 return rc;
415}
416
417/**
418 * Static callback function for receiving updates on guest control commands
419 * from the guest. Acts as a dispatcher for the actual class instance.
420 *
421 * @returns VBox status code.
422 *
423 * @todo
424 *
425 */
426DECLCALLBACK(int) Guest::doGuestCtrlNotification(void *pvExtension,
427 uint32_t u32Function,
428 void *pvParms,
429 uint32_t cbParms)
430{
431 using namespace guestControl;
432
433 /*
434 * No locking, as this is purely a notification which does not make any
435 * changes to the object state.
436 */
437 LogFlowFunc(("pvExtension = %p, u32Function = %d, pvParms = %p, cbParms = %d\n",
438 pvExtension, u32Function, pvParms, cbParms));
439 ComObjPtr<Guest> pGuest = reinterpret_cast<Guest *>(pvExtension);
440
441 int rc = VINF_SUCCESS;
442 if (u32Function == GUEST_EXEC_SEND_STATUS)
443 {
444 LogFlowFunc(("GUEST_EXEC_SEND_STATUS\n"));
445
446 PHOSTEXECCALLBACKDATA pCBData = reinterpret_cast<PHOSTEXECCALLBACKDATA>(pvParms);
447 AssertPtr(pCBData);
448 AssertReturn(sizeof(HOSTEXECCALLBACKDATA) == cbParms, VERR_INVALID_PARAMETER);
449 AssertReturn(HOSTEXECCALLBACKDATAMAGIC == pCBData->hdr.u32Magic, VERR_INVALID_PARAMETER);
450
451 rc = pGuest->notifyCtrlExec(u32Function, pCBData);
452 }
453 else if (u32Function == GUEST_EXEC_SEND_OUTPUT)
454 {
455 LogFlowFunc(("GUEST_EXEC_SEND_OUTPUT\n"));
456
457 PHOSTEXECOUTCALLBACKDATA pCBData = reinterpret_cast<PHOSTEXECOUTCALLBACKDATA>(pvParms);
458 AssertPtr(pCBData);
459 AssertReturn(sizeof(HOSTEXECOUTCALLBACKDATA) == cbParms, VERR_INVALID_PARAMETER);
460 AssertReturn(HOSTEXECOUTCALLBACKDATAMAGIC == pCBData->hdr.u32Magic, VERR_INVALID_PARAMETER);
461
462 rc = pGuest->notifyCtrlExecOut(u32Function, pCBData);
463 }
464 else
465 rc = VERR_NOT_SUPPORTED;
466 return rc;
467}
468
469/* Function for handling the execution start/termination notification. */
470int Guest::notifyCtrlExec(uint32_t u32Function,
471 PHOSTEXECCALLBACKDATA pData)
472{
473 LogFlowFuncEnter();
474 int rc = VINF_SUCCESS;
475
476 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
477
478 AssertPtr(pData);
479 CallbackListIter it = getCtrlCallbackContextByID(pData->hdr.u32ContextID);
480
481 /* Callback can be called several times. */
482 if (it != mCallbackList.end())
483 {
484 PHOSTEXECCALLBACKDATA pCBData = (HOSTEXECCALLBACKDATA*)it->pvData;
485 AssertPtr(pCBData);
486
487 pCBData->u32PID = pData->u32PID;
488 pCBData->u32Status = pData->u32Status;
489 pCBData->u32Flags = pData->u32Flags;
490 /** @todo Copy void* buffer contents! */
491
492 /* Was progress canceled before? */
493 BOOL fCancelled;
494 it->pProgress->COMGETTER(Canceled)(&fCancelled);
495
496 /* Do progress handling. */
497 Utf8Str errMsg;
498 HRESULT rc2 = S_OK;
499 switch (pData->u32Status)
500 {
501 case PROC_STS_STARTED:
502 break;
503
504 case PROC_STS_TEN: /* Terminated normally. */
505 if ( !it->pProgress->getCompleted()
506 && !fCancelled)
507 {
508 it->pProgress->notifyComplete(S_OK);
509 }
510 break;
511
512 case PROC_STS_TEA: /* Terminated abnormally. */
513 errMsg = Utf8StrFmt(Guest::tr("Process terminated abnormally with status '%u'"),
514 pCBData->u32Flags);
515 break;
516
517 case PROC_STS_TES: /* Terminated through signal. */
518 errMsg = Utf8StrFmt(Guest::tr("Process terminated via signal with status '%u'"),
519 pCBData->u32Flags);
520 break;
521
522 case PROC_STS_TOK:
523 errMsg = Utf8StrFmt(Guest::tr("Process timed out and was killed"));
524 break;
525
526 case PROC_STS_TOA:
527 errMsg = Utf8StrFmt(Guest::tr("Process timed out and could not be killed"));
528 break;
529
530 case PROC_STS_DWN:
531 errMsg = Utf8StrFmt(Guest::tr("Process exited because system is shutting down"));
532 break;
533
534 default:
535 break;
536 }
537
538 /* Handle process list. */
539 /** @todo What happens on/deal with PID reuse? */
540 /** @todo How to deal with multiple updates at once? */
541 GuestProcessIter it_proc = getProcessByPID(pCBData->u32PID);
542 if (it_proc == mGuestProcessList.end())
543 {
544 /* Not found, add to list. */
545 GuestProcess p;
546 p.mPID = pCBData->u32PID;
547 p.mStatus = pCBData->u32Status;
548 p.mExitCode = pCBData->u32Flags; /* Contains exit code. */
549 p.mFlags = 0;
550
551 mGuestProcessList.push_back(p);
552 }
553 else /* Update list. */
554 {
555 it_proc->mStatus = pCBData->u32Status;
556 it_proc->mExitCode = pCBData->u32Flags; /* Contains exit code. */
557 it_proc->mFlags = 0;
558 }
559
560 if ( !it->pProgress.isNull()
561 && errMsg.length())
562 {
563 if ( !it->pProgress->getCompleted()
564 && !fCancelled)
565 {
566 it->pProgress->notifyComplete(E_FAIL /** @todo Find a better rc! */, COM_IIDOF(IGuest),
567 (CBSTR)Guest::getComponentName(), errMsg.c_str());
568 LogFlowFunc(("Callback (context ID=%u, status=%u) progress marked as completed\n",
569 pData->hdr.u32ContextID, pData->u32Status));
570 }
571 else
572 LogFlowFunc(("Callback (context ID=%u, status=%u) progress already marked as completed\n",
573 pData->hdr.u32ContextID, pData->u32Status));
574 }
575 ASMAtomicWriteBool(&it->bCalled, true);
576 }
577 else
578 LogFlowFunc(("Unexpected callback (magic=%u, context ID=%u) arrived\n", pData->hdr.u32Magic, pData->hdr.u32ContextID));
579 LogFlowFuncLeave();
580 return rc;
581}
582
583/* Function for handling the execution output notification. */
584int Guest::notifyCtrlExecOut(uint32_t u32Function,
585 PHOSTEXECOUTCALLBACKDATA pData)
586{
587 LogFlowFuncEnter();
588 int rc = VINF_SUCCESS;
589
590 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
591
592 AssertPtr(pData);
593 CallbackListIter it = getCtrlCallbackContextByID(pData->hdr.u32ContextID);
594 if (it != mCallbackList.end())
595 {
596 Assert(!it->bCalled);
597 PHOSTEXECOUTCALLBACKDATA pCBData = (HOSTEXECOUTCALLBACKDATA*)it->pvData;
598 AssertPtr(pCBData);
599
600 pCBData->u32PID = pData->u32PID;
601 pCBData->u32HandleId = pData->u32HandleId;
602 pCBData->u32Flags = pData->u32Flags;
603
604 /* Make sure we really got something! */
605 if ( pData->cbData
606 && pData->pvData)
607 {
608 /* Allocate data buffer and copy it */
609 pCBData->pvData = RTMemAlloc(pData->cbData);
610 pCBData->cbData = pData->cbData;
611
612 AssertReturn(pCBData->pvData, VERR_NO_MEMORY);
613 memcpy(pCBData->pvData, pData->pvData, pData->cbData);
614 }
615 else
616 {
617 pCBData->pvData = NULL;
618 pCBData->cbData = 0;
619 }
620 ASMAtomicWriteBool(&it->bCalled, true);
621 }
622 else
623 LogFlowFunc(("Unexpected callback (magic=%u, context ID=%u) arrived\n", pData->hdr.u32Magic, pData->hdr.u32ContextID));
624 LogFlowFuncLeave();
625 return rc;
626}
627
628Guest::CallbackListIter Guest::getCtrlCallbackContextByID(uint32_t u32ContextID)
629{
630 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
631
632 /** @todo Maybe use a map instead of list for fast context lookup. */
633 CallbackListIter it;
634 for (it = mCallbackList.begin(); it != mCallbackList.end(); it++)
635 {
636 if (it->mContextID == u32ContextID)
637 return (it);
638 }
639 return it;
640}
641
642Guest::GuestProcessIter Guest::getProcessByPID(uint32_t u32PID)
643{
644 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
645
646 /** @todo Maybe use a map instead of list for fast context lookup. */
647 GuestProcessIter it;
648 for (it = mGuestProcessList.begin(); it != mGuestProcessList.end(); it++)
649 {
650 if (it->mPID == u32PID)
651 return (it);
652 }
653 return it;
654}
655
656/* No locking here; */
657void Guest::destroyCtrlCallbackContext(Guest::CallbackListIter it)
658{
659 LogFlowFuncEnter();
660 if (it->pvData)
661 {
662 RTMemFree(it->pvData);
663 it->pvData = NULL;
664 it->cbData = 0;
665
666 /* Notify outstanding waits for progress ... */
667 if (!it->pProgress.isNull())
668 {
669 /* Only cancel if not canceled before! */
670 BOOL fCancelled;
671 if (SUCCEEDED(it->pProgress->COMGETTER(Canceled)(&fCancelled)) && !fCancelled)
672 it->pProgress->Cancel();
673 /*
674 * Do *not NULL pProgress here, because waiting function like executeProcess()
675 * will still rely on this object for checking whether they have to give up!
676 */
677 }
678 }
679 LogFlowFuncLeave();
680}
681
682/* Adds a callback with a user provided data block and an optional progress object
683 * to the callback list. A callback is identified by a unique context ID which is used
684 * to identify a callback from the guest side. */
685uint32_t Guest::addCtrlCallbackContext(eVBoxGuestCtrlCallbackType enmType, void *pvData, uint32_t cbData, Progress *pProgress)
686{
687 LogFlowFuncEnter();
688 uint32_t uNewContext = ASMAtomicIncU32(&mNextContextID);
689 if (uNewContext == UINT32_MAX)
690 ASMAtomicUoWriteU32(&mNextContextID, 1000);
691
692 /** @todo Put this stuff into a constructor! */
693 CallbackContext context;
694 context.mContextID = uNewContext;
695 context.mType = enmType;
696 context.bCalled = false;
697 context.pvData = pvData;
698 context.cbData = cbData;
699 context.pProgress = pProgress;
700
701 uint32_t nCallbacks;
702 {
703 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
704 mCallbackList.push_back(context);
705 nCallbacks = mCallbackList.size();
706 }
707
708#if 0
709 if (nCallbacks > 256) /* Don't let the container size get too big! */
710 {
711 Guest::CallbackListIter it = mCallbackList.begin();
712 destroyCtrlCallbackContext(it);
713 {
714 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
715 mCallbackList.erase(it);
716 }
717 }
718#endif
719
720 LogFlowFuncLeave();
721 return uNewContext;
722}
723#endif /* VBOX_WITH_GUEST_CONTROL */
724
725STDMETHODIMP Guest::ExecuteProcess(IN_BSTR aCommand, ULONG aFlags,
726 ComSafeArrayIn(IN_BSTR, aArguments), ComSafeArrayIn(IN_BSTR, aEnvironment),
727 IN_BSTR aUserName, IN_BSTR aPassword,
728 ULONG aTimeoutMS, ULONG *aPID, IProgress **aProgress)
729{
730#ifndef VBOX_WITH_GUEST_CONTROL
731 ReturnComNotImplemented();
732#else /* VBOX_WITH_GUEST_CONTROL */
733 using namespace guestControl;
734
735 CheckComArgStrNotEmptyOrNull(aCommand);
736 CheckComArgOutPointerValid(aPID);
737 CheckComArgOutPointerValid(aProgress);
738
739 AutoCaller autoCaller(this);
740 if (FAILED(autoCaller.rc())) return autoCaller.rc();
741
742 if (aFlags != 0) /* Flags are not supported at the moment. */
743 return E_INVALIDARG;
744
745 HRESULT rc = S_OK;
746
747 try
748 {
749 /*
750 * Create progress object.
751 */
752 ComObjPtr <Progress> progress;
753 rc = progress.createObject();
754 if (SUCCEEDED(rc))
755 {
756 rc = progress->init(static_cast<IGuest*>(this),
757 BstrFmt(tr("Executing process")),
758 TRUE);
759 }
760 if (FAILED(rc)) return rc;
761
762 /*
763 * Prepare process execution.
764 */
765 int vrc = VINF_SUCCESS;
766 Utf8Str Utf8Command(aCommand);
767
768 /* Adjust timeout */
769 if (aTimeoutMS == 0)
770 aTimeoutMS = UINT32_MAX;
771
772 /* Prepare arguments. */
773 char **papszArgv = NULL;
774 uint32_t uNumArgs = 0;
775 if (aArguments > 0)
776 {
777 com::SafeArray<IN_BSTR> args(ComSafeArrayInArg(aArguments));
778 uNumArgs = args.size();
779 papszArgv = (char**)RTMemAlloc(sizeof(char*) * (uNumArgs + 1));
780 AssertReturn(papszArgv, E_OUTOFMEMORY);
781 for (unsigned i = 0; RT_SUCCESS(vrc) && i < uNumArgs; i++)
782 {
783 int cbLen = RTStrAPrintf(&papszArgv[i], "%s", Utf8Str(args[i]).raw());
784 if (cbLen < 0)
785 vrc = VERR_NO_MEMORY;
786
787 }
788 papszArgv[uNumArgs] = NULL;
789 }
790
791 Utf8Str Utf8UserName(aUserName);
792 Utf8Str Utf8Password(aPassword);
793 if (RT_SUCCESS(vrc))
794 {
795 uint32_t uContextID = 0;
796
797 char *pszArgs = NULL;
798 if (uNumArgs > 0)
799 vrc = RTGetOptArgvToString(&pszArgs, papszArgv, 0);
800 if (RT_SUCCESS(vrc))
801 {
802 uint32_t cbArgs = pszArgs ? strlen(pszArgs) + 1 : 0; /* Include terminating zero. */
803
804 /* Prepare environment. */
805 void *pvEnv = NULL;
806 uint32_t uNumEnv = 0;
807 uint32_t cbEnv = 0;
808 if (aEnvironment > 0)
809 {
810 com::SafeArray<IN_BSTR> env(ComSafeArrayInArg(aEnvironment));
811
812 for (unsigned i = 0; i < env.size(); i++)
813 {
814 vrc = prepareExecuteEnv(Utf8Str(env[i]).raw(), &pvEnv, &cbEnv, &uNumEnv);
815 if (RT_FAILURE(vrc))
816 break;
817 }
818 }
819
820 if (RT_SUCCESS(vrc))
821 {
822 PHOSTEXECCALLBACKDATA pData = (HOSTEXECCALLBACKDATA*)RTMemAlloc(sizeof(HOSTEXECCALLBACKDATA));
823 AssertReturn(pData, VBOX_E_IPRT_ERROR);
824 uContextID = addCtrlCallbackContext(VBOXGUESTCTRLCALLBACKTYPE_EXEC_START,
825 pData, sizeof(HOSTEXECCALLBACKDATA), progress);
826 Assert(uContextID > 0);
827
828 VBOXHGCMSVCPARM paParms[15];
829 int i = 0;
830 paParms[i++].setUInt32(uContextID);
831 paParms[i++].setPointer((void*)Utf8Command.raw(), (uint32_t)strlen(Utf8Command.raw()) + 1);
832 paParms[i++].setUInt32(aFlags);
833 paParms[i++].setUInt32(uNumArgs);
834 paParms[i++].setPointer((void*)pszArgs, cbArgs);
835 paParms[i++].setUInt32(uNumEnv);
836 paParms[i++].setUInt32(cbEnv);
837 paParms[i++].setPointer((void*)pvEnv, cbEnv);
838 paParms[i++].setPointer((void*)Utf8UserName.raw(), (uint32_t)strlen(Utf8UserName.raw()) + 1);
839 paParms[i++].setPointer((void*)Utf8Password.raw(), (uint32_t)strlen(Utf8Password.raw()) + 1);
840 paParms[i++].setUInt32(aTimeoutMS);
841
842 VMMDev *vmmDev;
843 {
844 /* Make sure mParent is valid, so set the read lock while using.
845 * Do not keep this lock while doing the actual call, because in the meanwhile
846 * another thread could request a write lock which would be a bad idea ... */
847 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
848
849 /* Forward the information to the VMM device. */
850 AssertPtr(mParent);
851 vmmDev = mParent->getVMMDev();
852 }
853
854 if (vmmDev)
855 {
856 LogFlowFunc(("hgcmHostCall numParms=%d\n", i));
857 vrc = vmmDev->hgcmHostCall("VBoxGuestControlSvc", HOST_EXEC_CMD,
858 i, paParms);
859 }
860 else
861 vrc = VERR_INVALID_VM_HANDLE;
862 RTMemFree(pvEnv);
863 }
864 RTStrFree(pszArgs);
865 }
866 if (RT_SUCCESS(vrc))
867 {
868 LogFlowFunc(("Waiting for HGCM callback (timeout=%ldms) ...\n", aTimeoutMS));
869
870 /*
871 * Wait for the HGCM low level callback until the process
872 * has been started (or something went wrong). This is necessary to
873 * get the PID.
874 */
875 CallbackListIter it = getCtrlCallbackContextByID(uContextID);
876 BOOL fCanceled = FALSE;
877 if (it != mCallbackList.end())
878 {
879 uint64_t u64Started = RTTimeMilliTS();
880 while (!it->bCalled)
881 {
882 /* Check for timeout. */
883 unsigned cMsWait;
884 if (aTimeoutMS == RT_INDEFINITE_WAIT)
885 cMsWait = 10;
886 else
887 {
888 uint64_t cMsElapsed = RTTimeMilliTS() - u64Started;
889 if (cMsElapsed >= aTimeoutMS)
890 break; /* Timed out. */
891 cMsWait = RT_MIN(10, aTimeoutMS - (uint32_t)cMsElapsed);
892 }
893
894 /* Check for manual stop. */
895 if (!it->pProgress.isNull())
896 {
897 rc = it->pProgress->COMGETTER(Canceled)(&fCanceled);
898 if (FAILED(rc)) throw rc;
899 if (fCanceled)
900 break; /* Client wants to abort. */
901 }
902 RTThreadSleep(cMsWait);
903 }
904 }
905
906 /* Was the whole thing canceled? */
907 if (!fCanceled)
908 {
909 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
910
911 PHOSTEXECCALLBACKDATA pData = (HOSTEXECCALLBACKDATA*)it->pvData;
912 Assert(it->cbData == sizeof(HOSTEXECCALLBACKDATA));
913 AssertPtr(pData);
914
915 if (it->bCalled)
916 {
917 /* Did we get some status? */
918 switch (pData->u32Status)
919 {
920 case PROC_STS_STARTED:
921 /* Process is (still) running; get PID. */
922 *aPID = pData->u32PID;
923 break;
924
925 /* In any other case the process either already
926 * terminated or something else went wrong, so no PID ... */
927 case PROC_STS_TEN: /* Terminated normally. */
928 case PROC_STS_TEA: /* Terminated abnormally. */
929 case PROC_STS_TES: /* Terminated through signal. */
930 case PROC_STS_TOK:
931 case PROC_STS_TOA:
932 case PROC_STS_DWN:
933 /*
934 * Process (already) ended, but we want to get the
935 * PID anyway to retrieve the output in a later call.
936 */
937 *aPID = pData->u32PID;
938 break;
939
940 case PROC_STS_ERROR:
941 vrc = pData->u32Flags; /* u32Flags member contains IPRT error code. */
942 break;
943
944 default:
945 vrc = VERR_INVALID_PARAMETER; /* Unknown status, should never happen! */
946 break;
947 }
948 }
949 else /* If callback not called within time ... well, that's a timeout! */
950 vrc = VERR_TIMEOUT;
951
952 /*
953 * Do *not* remove the callback yet - we might wait with the IProgress object on something
954 * else (like end of process) ...
955 */
956 if (RT_FAILURE(vrc))
957 {
958 if (vrc == VERR_FILE_NOT_FOUND) /* This is the most likely error. */
959 {
960 rc = setError(VBOX_E_IPRT_ERROR,
961 tr("The file '%s' was not found on guest"), Utf8Command.raw());
962 }
963 else if (vrc == VERR_BAD_EXE_FORMAT)
964 {
965 rc = setError(VBOX_E_IPRT_ERROR,
966 tr("The file '%s' is not an executable format on guest"), Utf8Command.raw());
967 }
968 else if (vrc == VERR_LOGON_FAILURE)
969 {
970 rc = setError(VBOX_E_IPRT_ERROR,
971 tr("The specified user '%s' was not able to logon on guest"), Utf8UserName.raw());
972 }
973 else if (vrc == VERR_TIMEOUT)
974 {
975 rc = setError(VBOX_E_IPRT_ERROR,
976 tr("The guest did not respond within time (%ums)"), aTimeoutMS);
977 }
978 else if (vrc == VERR_INVALID_PARAMETER)
979 {
980 rc = setError(VBOX_E_IPRT_ERROR,
981 tr("The guest reported an unknown process status (%u)"), pData->u32Status);
982 }
983 else
984 {
985 rc = setError(E_UNEXPECTED,
986 tr("The service call failed with error %Rrc"), vrc);
987 }
988 }
989 else /* Execution went fine. */
990 {
991 /* Return the progress to the caller. */
992 progress.queryInterfaceTo(aProgress);
993 }
994 }
995 else /* Operation was canceled. */
996 {
997 rc = setError(VBOX_E_IPRT_ERROR,
998 tr("The operation was canceled."));
999 }
1000 }
1001 else /* HGCM related error codes .*/
1002 {
1003 if (vrc == VERR_INVALID_VM_HANDLE)
1004 {
1005 rc = setError(VBOX_E_VM_ERROR,
1006 tr("VMM device is not available (is the VM running?)"));
1007 }
1008 else if (vrc == VERR_TIMEOUT)
1009 {
1010 rc = setError(VBOX_E_VM_ERROR,
1011 tr("The guest execution service is not ready"));
1012 }
1013 else /* HGCM call went wrong. */
1014 {
1015 rc = setError(E_UNEXPECTED,
1016 tr("The HGCM call failed with error %Rrc"), vrc);
1017 }
1018 }
1019
1020 for (unsigned i = 0; i < uNumArgs; i++)
1021 RTMemFree(papszArgv[i]);
1022 RTMemFree(papszArgv);
1023 }
1024 }
1025 catch (std::bad_alloc &)
1026 {
1027 rc = E_OUTOFMEMORY;
1028 }
1029 return rc;
1030#endif /* VBOX_WITH_GUEST_CONTROL */
1031}
1032
1033STDMETHODIMP Guest::GetProcessOutput(ULONG aPID, ULONG aFlags, ULONG aTimeoutMS, ULONG64 aSize, ComSafeArrayOut(BYTE, aData))
1034{
1035#ifndef VBOX_WITH_GUEST_CONTROL
1036 ReturnComNotImplemented();
1037#else /* VBOX_WITH_GUEST_CONTROL */
1038 using namespace guestControl;
1039
1040 CheckComArgExpr(aPID, aPID > 0);
1041
1042 if (aFlags != 0) /* Flags are not supported at the moment. */
1043 return E_INVALIDARG;
1044
1045 AutoCaller autoCaller(this);
1046 if (FAILED(autoCaller.rc())) return autoCaller.rc();
1047
1048 HRESULT rc = S_OK;
1049
1050 try
1051 {
1052 /*
1053 * Create progress object.
1054 * Note that we need at least a local progress object here in order
1055 * to get notified when someone cancels the operation.
1056 */
1057 ComObjPtr <Progress> progress;
1058 rc = progress.createObject();
1059 if (SUCCEEDED(rc))
1060 {
1061 rc = progress->init(static_cast<IGuest*>(this),
1062 BstrFmt(tr("Getting output of process")),
1063 TRUE);
1064 }
1065 if (FAILED(rc)) return rc;
1066
1067 /* Adjust timeout */
1068 if (aTimeoutMS == 0)
1069 aTimeoutMS = UINT32_MAX;
1070
1071 /* Search for existing PID. */
1072 PHOSTEXECOUTCALLBACKDATA pData = (HOSTEXECOUTCALLBACKDATA*)RTMemAlloc(sizeof(HOSTEXECOUTCALLBACKDATA));
1073 AssertReturn(pData, VBOX_E_IPRT_ERROR);
1074 uint32_t uContextID = addCtrlCallbackContext(VBOXGUESTCTRLCALLBACKTYPE_EXEC_OUTPUT,
1075 pData, sizeof(HOSTEXECOUTCALLBACKDATA), progress);
1076 Assert(uContextID > 0);
1077
1078 size_t cbData = (size_t)RT_MIN(aSize, _64K);
1079 com::SafeArray<BYTE> outputData(cbData);
1080
1081 VBOXHGCMSVCPARM paParms[5];
1082 int i = 0;
1083 paParms[i++].setUInt32(uContextID);
1084 paParms[i++].setUInt32(aPID);
1085 paParms[i++].setUInt32(aFlags); /** @todo Should represent stdout and/or stderr. */
1086
1087 int vrc = VINF_SUCCESS;
1088
1089 {
1090 VMMDev *vmmDev;
1091 {
1092 /* Make sure mParent is valid, so set the read lock while using.
1093 * Do not keep this lock while doing the actual call, because in the meanwhile
1094 * another thread could request a write lock which would be a bad idea ... */
1095 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
1096
1097 /* Forward the information to the VMM device. */
1098 AssertPtr(mParent);
1099 vmmDev = mParent->getVMMDev();
1100 }
1101
1102 if (vmmDev)
1103 {
1104 LogFlowFunc(("hgcmHostCall numParms=%d\n", i));
1105 vrc = vmmDev->hgcmHostCall("VBoxGuestControlSvc", HOST_EXEC_GET_OUTPUT,
1106 i, paParms);
1107 }
1108 }
1109
1110 if (RT_SUCCESS(vrc))
1111 {
1112 LogFlowFunc(("Waiting for HGCM callback (timeout=%ldms) ...\n", aTimeoutMS));
1113
1114 /*
1115 * Wait for the HGCM low level callback until the process
1116 * has been started (or something went wrong). This is necessary to
1117 * get the PID.
1118 */
1119 CallbackListIter it = getCtrlCallbackContextByID(uContextID);
1120 BOOL fCanceled = FALSE;
1121 if (it != mCallbackList.end())
1122 {
1123 uint64_t u64Started = RTTimeMilliTS();
1124 while (!it->bCalled)
1125 {
1126 /* Check for timeout. */
1127 unsigned cMsWait;
1128 if (aTimeoutMS == RT_INDEFINITE_WAIT)
1129 cMsWait = 10;
1130 else
1131 {
1132 uint64_t cMsElapsed = RTTimeMilliTS() - u64Started;
1133 if (cMsElapsed >= aTimeoutMS)
1134 break; /* Timed out. */
1135 cMsWait = RT_MIN(10, aTimeoutMS - (uint32_t)cMsElapsed);
1136 }
1137
1138 /* Check for manual stop. */
1139 if (!it->pProgress.isNull())
1140 {
1141 rc = it->pProgress->COMGETTER(Canceled)(&fCanceled);
1142 if (FAILED(rc)) throw rc;
1143 if (fCanceled)
1144 break; /* Client wants to abort. */
1145 }
1146 RTThreadSleep(cMsWait);
1147 }
1148
1149 /* Was the whole thing canceled? */
1150 if (!fCanceled)
1151 {
1152 if (it->bCalled)
1153 {
1154 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
1155
1156 /* Did we get some output? */
1157 pData = (HOSTEXECOUTCALLBACKDATA*)it->pvData;
1158 Assert(it->cbData == sizeof(HOSTEXECOUTCALLBACKDATA));
1159 AssertPtr(pData);
1160
1161 if (pData->cbData)
1162 {
1163 /* Do we need to resize the array? */
1164 if (pData->cbData > cbData)
1165 outputData.resize(pData->cbData);
1166
1167 /* Fill output in supplied out buffer. */
1168 memcpy(outputData.raw(), pData->pvData, pData->cbData);
1169 outputData.resize(pData->cbData); /* Shrink to fit actual buffer size. */
1170 }
1171 else
1172 vrc = VERR_NO_DATA; /* This is not an error we want to report to COM. */
1173 }
1174 else /* If callback not called within time ... well, that's a timeout! */
1175 vrc = VERR_TIMEOUT;
1176 }
1177 else /* Operation was canceled. */
1178 vrc = VERR_CANCELLED;
1179
1180 if (RT_FAILURE(vrc))
1181 {
1182 if (vrc == VERR_NO_DATA)
1183 {
1184 /* This is not an error we want to report to COM. */
1185 }
1186 else if (vrc == VERR_TIMEOUT)
1187 {
1188 rc = setError(VBOX_E_IPRT_ERROR,
1189 tr("The guest did not output within time (%ums)"), aTimeoutMS);
1190 }
1191 else if (vrc == VERR_CANCELLED)
1192 {
1193 rc = setError(VBOX_E_IPRT_ERROR,
1194 tr("The operation was canceled."));
1195 }
1196 else
1197 {
1198 rc = setError(E_UNEXPECTED,
1199 tr("The service call failed with error %Rrc"), vrc);
1200 }
1201 }
1202
1203 {
1204 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
1205 destroyCtrlCallbackContext(it);
1206 }
1207 }
1208 else /* PID lookup failed. */
1209 rc = setError(VBOX_E_IPRT_ERROR,
1210 tr("Process (PID %u) not found!"), aPID);
1211 }
1212 else /* HGCM operation failed. */
1213 rc = setError(E_UNEXPECTED,
1214 tr("The HGCM call failed with error %Rrc"), vrc);
1215
1216 /* Cleanup. */
1217 progress->uninit();
1218 progress.setNull();
1219
1220 /* If something failed (or there simply was no data, indicated by VERR_NO_DATA,
1221 * we return an empty array so that the frontend knows when to give up. */
1222 if (RT_FAILURE(vrc) || FAILED(rc))
1223 outputData.resize(0);
1224 outputData.detachTo(ComSafeArrayOutArg(aData));
1225 }
1226 catch (std::bad_alloc &)
1227 {
1228 rc = E_OUTOFMEMORY;
1229 }
1230 return rc;
1231#endif
1232}
1233
1234STDMETHODIMP Guest::GetProcessStatus(ULONG aPID, ULONG *aExitCode, ULONG *aFlags, ULONG *aStatus)
1235{
1236#ifndef VBOX_WITH_GUEST_CONTROL
1237 ReturnComNotImplemented();
1238#else /* VBOX_WITH_GUEST_CONTROL */
1239 using namespace guestControl;
1240
1241 AutoCaller autoCaller(this);
1242 if (FAILED(autoCaller.rc())) return autoCaller.rc();
1243
1244 HRESULT rc = S_OK;
1245
1246 try
1247 {
1248 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
1249
1250 GuestProcessIterConst it;
1251 for (it = mGuestProcessList.begin(); it != mGuestProcessList.end(); it++)
1252 {
1253 if (it->mPID == aPID)
1254 break;
1255 }
1256
1257 if (it != mGuestProcessList.end())
1258 {
1259 *aExitCode = it->mExitCode;
1260 *aFlags = it->mFlags;
1261 *aStatus = it->mStatus;
1262 }
1263 else
1264 rc = setError(VBOX_E_IPRT_ERROR,
1265 tr("Process (PID %u) not found!"), aPID);
1266 }
1267 catch (std::bad_alloc &)
1268 {
1269 rc = E_OUTOFMEMORY;
1270 }
1271 return rc;
1272#endif
1273}
1274
1275// public methods only for internal purposes
1276/////////////////////////////////////////////////////////////////////////////
1277
1278void Guest::setAdditionsVersion(Bstr aVersion, VBOXOSTYPE aOsType)
1279{
1280 AutoCaller autoCaller(this);
1281 AssertComRCReturnVoid (autoCaller.rc());
1282
1283 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
1284
1285 mData.mAdditionsVersion = aVersion;
1286 mData.mAdditionsActive = !aVersion.isEmpty();
1287 /* Older Additions didn't have this finer grained capability bit,
1288 * so enable it by default. Newer Additions will disable it immediately
1289 * if relevant. */
1290 mData.mSupportsGraphics = mData.mAdditionsActive;
1291
1292 mData.mOSTypeId = Global::OSTypeId (aOsType);
1293}
1294
1295void Guest::setSupportsSeamless (BOOL aSupportsSeamless)
1296{
1297 AutoCaller autoCaller(this);
1298 AssertComRCReturnVoid (autoCaller.rc());
1299
1300 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
1301
1302 mData.mSupportsSeamless = aSupportsSeamless;
1303}
1304
1305void Guest::setSupportsGraphics (BOOL aSupportsGraphics)
1306{
1307 AutoCaller autoCaller(this);
1308 AssertComRCReturnVoid (autoCaller.rc());
1309
1310 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
1311
1312 mData.mSupportsGraphics = aSupportsGraphics;
1313}
1314/* vi: set tabstop=4 shiftwidth=4 expandtab: */
Note: See TracBrowser for help on using the repository browser.

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