VirtualBox

source: vbox/trunk/src/VBox/Main/include/ConsoleImpl.h@ 93901

Last change on this file since 93901 was 93858, checked in by vboxsync, 3 years ago

Main: Restored bwGroups[i]->COMGETTER(Name)(strName.asOutParam()); accidentally removed by r150070; Corrected bogus AssertLogRelMsgRCReturn; various cleanups. bugref:10053

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 49.9 KB
Line 
1/* $Id: ConsoleImpl.h 93858 2022-02-20 07:47:37Z vboxsync $ */
2/** @file
3 * VBox Console COM Class definition
4 */
5
6/*
7 * Copyright (C) 2005-2022 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#ifndef MAIN_INCLUDED_ConsoleImpl_h
19#define MAIN_INCLUDED_ConsoleImpl_h
20#ifndef RT_WITHOUT_PRAGMA_ONCE
21# pragma once
22#endif
23
24#include "VirtualBoxBase.h"
25#include "VBox/com/array.h"
26#include "EventImpl.h"
27#include "SecretKeyStore.h"
28#include "ConsoleWrap.h"
29#ifdef VBOX_WITH_RECORDING
30# include "Recording.h"
31#endif
32#ifdef VBOX_WITH_CLOUD_NET
33#include "CloudGateway.h"
34#endif /* VBOX_WITH_CLOUD_NET */
35
36class Guest;
37class Keyboard;
38class Mouse;
39class Display;
40class MachineDebugger;
41class TeleporterStateSrc;
42class OUSBDevice;
43class RemoteUSBDevice;
44class SharedFolder;
45class VRDEServerInfo;
46class EmulatedUSB;
47class AudioVRDE;
48#ifdef VBOX_WITH_AUDIO_RECORDING
49class AudioVideoRec;
50#endif
51#ifdef VBOX_WITH_USB_CARDREADER
52class UsbCardReader;
53#endif
54class ConsoleVRDPServer;
55class VMMDev;
56class Progress;
57class BusAssignmentManager;
58COM_STRUCT_OR_CLASS(IEventListener);
59#ifdef VBOX_WITH_EXTPACK
60class ExtPackManager;
61#endif
62class VMMDevMouseInterface;
63class DisplayMouseInterface;
64class VMPowerUpTask;
65class VMPowerDownTask;
66class NvramStore;
67
68#include <iprt/uuid.h>
69#include <iprt/memsafer.h>
70#include <VBox/RemoteDesktop/VRDE.h>
71#include <VBox/vmm/pdmdrv.h>
72#ifdef VBOX_WITH_GUEST_PROPS
73# include <VBox/HostServices/GuestPropertySvc.h> /* For the property notification callback */
74#endif
75
76#if defined(VBOX_WITH_GUEST_PROPS) || defined(VBOX_WITH_SHARED_CLIPBOARD) \
77 || defined(VBOX_WITH_DRAG_AND_DROP)
78# include "HGCM.h" /** @todo It should be possible to register a service
79 * extension using a VMMDev callback. */
80#endif
81
82struct VUSBIRHCONFIG;
83typedef struct VUSBIRHCONFIG *PVUSBIRHCONFIG;
84
85#include <list>
86#include <vector>
87
88// defines
89///////////////////////////////////////////////////////////////////////////////
90
91/**
92 * Checks the availability of the underlying VM device driver corresponding
93 * to the COM interface (IKeyboard, IMouse, IDisplay, etc.). When the driver is
94 * not available (NULL), sets error info and returns returns E_ACCESSDENIED.
95 * The translatable error message is defined in null context.
96 *
97 * Intended to used only within Console children (i.e. Keyboard, Mouse,
98 * Display, etc.).
99 *
100 * @param drv driver pointer to check (compare it with NULL)
101 */
102#define CHECK_CONSOLE_DRV(drv) \
103 do { \
104 if (!!(drv)) {} \
105 else return setError(E_ACCESSDENIED, Console::tr("The console is not powered up (%Rfn)"), __FUNCTION__); \
106 } while (0)
107
108// Console
109///////////////////////////////////////////////////////////////////////////////
110
111class ConsoleMouseInterface
112{
113public:
114 virtual ~ConsoleMouseInterface() { }
115 virtual VMMDevMouseInterface *i_getVMMDevMouseInterface(){return NULL;}
116 virtual DisplayMouseInterface *i_getDisplayMouseInterface(){return NULL;}
117 virtual void i_onMouseCapabilityChange(BOOL supportsAbsolute,
118 BOOL supportsRelative,
119 BOOL supportsMT,
120 BOOL needsHostCursor){NOREF(supportsAbsolute); NOREF(supportsRelative); NOREF(supportsMT); NOREF(needsHostCursor);}
121};
122
123/** IConsole implementation class */
124class ATL_NO_VTABLE Console :
125 public ConsoleWrap,
126 public ConsoleMouseInterface
127{
128
129public:
130
131 DECLARE_COMMON_CLASS_METHODS(Console)
132
133 HRESULT FinalConstruct();
134 void FinalRelease();
135
136 // public initializers/uninitializers for internal purposes only
137 HRESULT initWithMachine(IMachine *aMachine, IInternalMachineControl *aControl, LockType_T aLockType);
138 void uninit();
139
140
141 // public methods for internal purposes only
142
143 /*
144 * Note: the following methods do not increase refcount. intended to be
145 * called only by the VM execution thread.
146 */
147
148 PCVMMR3VTABLE i_getVMMVTable() const RT_NOEXCEPT { return mpVMM; }
149 Guest *i_getGuest() const { return mGuest; }
150 Keyboard *i_getKeyboard() const { return mKeyboard; }
151 Mouse *i_getMouse() const { return mMouse; }
152 Display *i_getDisplay() const { return mDisplay; }
153 MachineDebugger *i_getMachineDebugger() const { return mDebugger; }
154#ifdef VBOX_WITH_AUDIO_VRDE
155 AudioVRDE *i_getAudioVRDE() const { return mAudioVRDE; }
156#endif
157#ifdef VBOX_WITH_RECORDING
158 int i_recordingCreate(void);
159 void i_recordingDestroy(void);
160 int i_recordingEnable(BOOL fEnable, util::AutoWriteLock *pAutoLock);
161 int i_recordingGetSettings(settings::RecordingSettings &Settings);
162 int i_recordingStart(util::AutoWriteLock *pAutoLock = NULL);
163 int i_recordingStop(util::AutoWriteLock *pAutoLock = NULL);
164# ifdef VBOX_WITH_AUDIO_RECORDING
165 AudioVideoRec *i_recordingGetAudioDrv(void) const { return mRecording.mAudioRec; }
166# endif
167 RecordingContext *i_recordingGetContext(void) const { return mRecording.mpCtx; }
168# ifdef VBOX_WITH_AUDIO_RECORDING
169 HRESULT i_recordingSendAudio(const void *pvData, size_t cbData, uint64_t uDurationMs);
170# endif
171#endif
172
173 const ComPtr<IMachine> &i_machine() const { return mMachine; }
174 const Bstr &i_getId() const { return mstrUuid; }
175
176 bool i_useHostClipboard() { return mfUseHostClipboard; }
177
178 /** Method is called only from ConsoleVRDPServer */
179 IVRDEServer *i_getVRDEServer() const { return mVRDEServer; }
180
181 ConsoleVRDPServer *i_consoleVRDPServer() const { return mConsoleVRDPServer; }
182
183 HRESULT i_updateMachineState(MachineState_T aMachineState);
184 HRESULT i_getNominalState(MachineState_T &aNominalState);
185 Utf8Str i_getAudioAdapterDeviceName(IAudioAdapter *aAudioAdapter);
186
187 // events from IInternalSessionControl
188 HRESULT i_onNetworkAdapterChange(INetworkAdapter *aNetworkAdapter, BOOL changeAdapter);
189 HRESULT i_onAudioAdapterChange(IAudioAdapter *aAudioAdapter);
190 HRESULT i_onSerialPortChange(ISerialPort *aSerialPort);
191 HRESULT i_onParallelPortChange(IParallelPort *aParallelPort);
192 HRESULT i_onStorageControllerChange(const com::Guid& aMachineId, const com::Utf8Str& aControllerName);
193 HRESULT i_onMediumChange(IMediumAttachment *aMediumAttachment, BOOL aForce);
194 HRESULT i_onCPUChange(ULONG aCPU, BOOL aRemove);
195 HRESULT i_onCPUExecutionCapChange(ULONG aExecutionCap);
196 HRESULT i_onClipboardModeChange(ClipboardMode_T aClipboardMode);
197 HRESULT i_onClipboardFileTransferModeChange(bool aEnabled);
198 HRESULT i_onDnDModeChange(DnDMode_T aDnDMode);
199 HRESULT i_onVRDEServerChange(BOOL aRestart);
200 HRESULT i_onRecordingChange(BOOL fEnable);
201 HRESULT i_onUSBControllerChange();
202 HRESULT i_onSharedFolderChange(BOOL aGlobal);
203 HRESULT i_onUSBDeviceAttach(IUSBDevice *aDevice, IVirtualBoxErrorInfo *aError, ULONG aMaskedIfs,
204 const Utf8Str &aCaptureFilename);
205 HRESULT i_onUSBDeviceDetach(IN_BSTR aId, IVirtualBoxErrorInfo *aError);
206 HRESULT i_onBandwidthGroupChange(IBandwidthGroup *aBandwidthGroup);
207 HRESULT i_onStorageDeviceChange(IMediumAttachment *aMediumAttachment, BOOL aRemove, BOOL aSilent);
208 HRESULT i_onExtraDataChange(const Bstr &aMachineId, const Bstr &aKey, const Bstr &aVal);
209
210 HRESULT i_getGuestProperty(const Utf8Str &aName, Utf8Str *aValue, LONG64 *aTimestamp, Utf8Str *aFlags);
211 HRESULT i_setGuestProperty(const Utf8Str &aName, const Utf8Str &aValue, const Utf8Str &aFlags);
212 HRESULT i_deleteGuestProperty(const Utf8Str &aName);
213 HRESULT i_enumerateGuestProperties(const Utf8Str &aPatterns,
214 std::vector<Utf8Str> &aNames,
215 std::vector<Utf8Str> &aValues,
216 std::vector<LONG64> &aTimestamps,
217 std::vector<Utf8Str> &aFlags);
218 HRESULT i_onlineMergeMedium(IMediumAttachment *aMediumAttachment,
219 ULONG aSourceIdx, ULONG aTargetIdx,
220 IProgress *aProgress);
221 HRESULT i_reconfigureMediumAttachments(const std::vector<ComPtr<IMediumAttachment> > &aAttachments);
222 HRESULT i_onVMProcessPriorityChange(VMProcPriority_T priority);
223 int i_hgcmLoadService(const char *pszServiceLibrary, const char *pszServiceName);
224 VMMDev *i_getVMMDev() { return m_pVMMDev; }
225
226#ifdef VBOX_WITH_EXTPACK
227 ExtPackManager *i_getExtPackManager();
228#endif
229 EventSource *i_getEventSource() { return mEventSource; }
230#ifdef VBOX_WITH_USB_CARDREADER
231 UsbCardReader *i_getUsbCardReader() { return mUsbCardReader; }
232#endif
233
234 int i_VRDPClientLogon(uint32_t u32ClientId, const char *pszUser, const char *pszPassword, const char *pszDomain);
235 void i_VRDPClientStatusChange(uint32_t u32ClientId, const char *pszStatus);
236 void i_VRDPClientConnect(uint32_t u32ClientId);
237 void i_VRDPClientDisconnect(uint32_t u32ClientId, uint32_t fu32Intercepted);
238 void i_VRDPInterceptAudio(uint32_t u32ClientId);
239 void i_VRDPInterceptUSB(uint32_t u32ClientId, void **ppvIntercept);
240 void i_VRDPInterceptClipboard(uint32_t u32ClientId);
241
242 void i_processRemoteUSBDevices(uint32_t u32ClientId, VRDEUSBDEVICEDESC *pDevList, uint32_t cbDevList, bool fDescExt);
243 void i_reportVmStatistics(ULONG aValidStats, ULONG aCpuUser,
244 ULONG aCpuKernel, ULONG aCpuIdle,
245 ULONG aMemTotal, ULONG aMemFree,
246 ULONG aMemBalloon, ULONG aMemShared,
247 ULONG aMemCache, ULONG aPageTotal,
248 ULONG aAllocVMM, ULONG aFreeVMM,
249 ULONG aBalloonedVMM, ULONG aSharedVMM,
250 ULONG aVmNetRx, ULONG aVmNetTx)
251 {
252 mControl->ReportVmStatistics(aValidStats, aCpuUser, aCpuKernel, aCpuIdle,
253 aMemTotal, aMemFree, aMemBalloon, aMemShared,
254 aMemCache, aPageTotal, aAllocVMM, aFreeVMM,
255 aBalloonedVMM, aSharedVMM, aVmNetRx, aVmNetTx);
256 }
257 void i_enableVMMStatistics(BOOL aEnable);
258
259 HRESULT i_pause(Reason_T aReason);
260 HRESULT i_resume(Reason_T aReason, AutoWriteLock &alock);
261 HRESULT i_saveState(Reason_T aReason, const ComPtr<IProgress> &aProgress,
262 const ComPtr<ISnapshot> &aSnapshot,
263 const Utf8Str &aStateFilePath, bool fPauseVM, bool &fLeftPaused);
264 HRESULT i_cancelSaveState();
265
266 // callback callers (partly; for some events console callbacks are notified
267 // directly from IInternalSessionControl event handlers declared above)
268 void i_onMousePointerShapeChange(bool fVisible, bool fAlpha,
269 uint32_t xHot, uint32_t yHot,
270 uint32_t width, uint32_t height,
271 const uint8_t *pu8Shape,
272 uint32_t cbShape);
273 void i_onMouseCapabilityChange(BOOL supportsAbsolute, BOOL supportsRelative,
274 BOOL supportsMT, BOOL needsHostCursor);
275 void i_onStateChange(MachineState_T aMachineState);
276 void i_onAdditionsStateChange();
277 void i_onAdditionsOutdated();
278 void i_onKeyboardLedsChange(bool fNumLock, bool fCapsLock, bool fScrollLock);
279 void i_onUSBDeviceStateChange(IUSBDevice *aDevice, bool aAttached,
280 IVirtualBoxErrorInfo *aError);
281 void i_onRuntimeError(BOOL aFatal, IN_BSTR aErrorID, IN_BSTR aMessage);
282 HRESULT i_onShowWindow(BOOL aCheck, BOOL *aCanShow, LONG64 *aWinId);
283 void i_onVRDEServerInfoChange();
284 HRESULT i_sendACPIMonitorHotPlugEvent();
285
286 static const PDMDRVREG DrvStatusReg;
287
288 static HRESULT i_setErrorStatic(HRESULT aResultCode, const char *pcsz, ...);
289 static HRESULT i_setErrorStaticBoth(HRESULT aResultCode, int vrc, const char *pcsz, ...);
290 HRESULT i_setInvalidMachineStateError();
291
292 static const char *i_storageControllerTypeToStr(StorageControllerType_T enmCtrlType);
293 static HRESULT i_storageBusPortDeviceToLun(StorageBus_T enmBus, LONG port, LONG device, unsigned &uLun);
294 // Called from event listener
295 HRESULT i_onNATRedirectRuleChanged(ULONG ulInstance, BOOL aNatRuleRemove,
296 NATProtocol_T aProto, IN_BSTR aHostIp, LONG aHostPort, IN_BSTR aGuestIp, LONG aGuestPort);
297 HRESULT i_onNATDnsChanged();
298
299 // Mouse interface
300 VMMDevMouseInterface *i_getVMMDevMouseInterface();
301 DisplayMouseInterface *i_getDisplayMouseInterface();
302
303 EmulatedUSB *i_getEmulatedUSB(void) { return mEmulatedUSB; }
304
305 /**
306 * Sets the disk encryption keys.
307 *
308 * @returns COM status code.
309 * @param strCfg The config for the disks.
310 *
311 * @note One line in the config string contains all required data for one disk.
312 * The format for one disk is some sort of comma separated value using
313 * key=value pairs.
314 * There are two keys defined at the moment:
315 * - uuid: The uuid of the base image the key is for (with or without)
316 * the curly braces.
317 * - dek: The data encryption key in base64 encoding
318 */
319 HRESULT i_setDiskEncryptionKeys(const Utf8Str &strCfg);
320
321
322#ifdef VBOX_WITH_GUEST_PROPS
323 // VMMDev needs:
324 HRESULT i_pullGuestProperties(ComSafeArrayOut(BSTR, names), ComSafeArrayOut(BSTR, values),
325 ComSafeArrayOut(LONG64, timestamps), ComSafeArrayOut(BSTR, flags));
326 static DECLCALLBACK(int) i_doGuestPropNotification(void *pvExtension, uint32_t, void *pvParms, uint32_t cbParms);
327#endif
328
329private:
330
331 // wrapped IConsole properties
332 HRESULT getMachine(ComPtr<IMachine> &aMachine);
333 HRESULT getState(MachineState_T *aState);
334 HRESULT getGuest(ComPtr<IGuest> &aGuest);
335 HRESULT getKeyboard(ComPtr<IKeyboard> &aKeyboard);
336 HRESULT getMouse(ComPtr<IMouse> &aMouse);
337 HRESULT getDisplay(ComPtr<IDisplay> &aDisplay);
338 HRESULT getDebugger(ComPtr<IMachineDebugger> &aDebugger);
339 HRESULT getUSBDevices(std::vector<ComPtr<IUSBDevice> > &aUSBDevices);
340 HRESULT getRemoteUSBDevices(std::vector<ComPtr<IHostUSBDevice> > &aRemoteUSBDevices);
341 HRESULT getSharedFolders(std::vector<ComPtr<ISharedFolder> > &aSharedFolders);
342 HRESULT getVRDEServerInfo(ComPtr<IVRDEServerInfo> &aVRDEServerInfo);
343 HRESULT getEventSource(ComPtr<IEventSource> &aEventSource);
344 HRESULT getAttachedPCIDevices(std::vector<ComPtr<IPCIDeviceAttachment> > &aAttachedPCIDevices);
345 HRESULT getUseHostClipboard(BOOL *aUseHostClipboard);
346 HRESULT setUseHostClipboard(BOOL aUseHostClipboard);
347 HRESULT getEmulatedUSB(ComPtr<IEmulatedUSB> &aEmulatedUSB);
348
349 // wrapped IConsole methods
350 HRESULT powerUp(ComPtr<IProgress> &aProgress);
351 HRESULT powerUpPaused(ComPtr<IProgress> &aProgress);
352 HRESULT powerDown(ComPtr<IProgress> &aProgress);
353 HRESULT reset();
354 HRESULT pause();
355 HRESULT resume();
356 HRESULT powerButton();
357 HRESULT sleepButton();
358 HRESULT getPowerButtonHandled(BOOL *aHandled);
359 HRESULT getGuestEnteredACPIMode(BOOL *aEntered);
360 HRESULT getDeviceActivity(const std::vector<DeviceType_T> &aType,
361 std::vector<DeviceActivity_T> &aActivity);
362 HRESULT attachUSBDevice(const com::Guid &aId, const com::Utf8Str &aCaptureFilename);
363 HRESULT detachUSBDevice(const com::Guid &aId,
364 ComPtr<IUSBDevice> &aDevice);
365 HRESULT findUSBDeviceByAddress(const com::Utf8Str &aName,
366 ComPtr<IUSBDevice> &aDevice);
367 HRESULT findUSBDeviceById(const com::Guid &aId,
368 ComPtr<IUSBDevice> &aDevice);
369 HRESULT createSharedFolder(const com::Utf8Str &aName,
370 const com::Utf8Str &aHostPath,
371 BOOL aWritable,
372 BOOL aAutomount,
373 const com::Utf8Str &aAutoMountPoint);
374 HRESULT removeSharedFolder(const com::Utf8Str &aName);
375 HRESULT teleport(const com::Utf8Str &aHostname,
376 ULONG aTcpport,
377 const com::Utf8Str &aPassword,
378 ULONG aMaxDowntime,
379 ComPtr<IProgress> &aProgress);
380 HRESULT addDiskEncryptionPassword(const com::Utf8Str &aId, const com::Utf8Str &aPassword,
381 BOOL aClearOnSuspend);
382 HRESULT addDiskEncryptionPasswords(const std::vector<com::Utf8Str> &aIds, const std::vector<com::Utf8Str> &aPasswords,
383 BOOL aClearOnSuspend);
384 HRESULT removeDiskEncryptionPassword(const com::Utf8Str &aId);
385 HRESULT clearAllDiskEncryptionPasswords();
386
387 void notifyNatDnsChange(PUVM pUVM, PCVMMR3VTABLE pVMM, const char *pszDevice, ULONG ulInstanceMax);
388 Utf8Str VRDPServerErrorToMsg(int vrc);
389
390 /**
391 * Base template for AutoVMCaller and SafeVMPtr. Template arguments
392 * have the same meaning as arguments of Console::addVMCaller().
393 */
394 template <bool taQuiet = false, bool taAllowNullVM = false>
395 class AutoVMCallerBase
396 {
397 public:
398 AutoVMCallerBase(Console *aThat) : mThat(aThat), mRC(E_FAIL)
399 {
400 Assert(aThat);
401 mRC = aThat->i_addVMCaller(taQuiet, taAllowNullVM);
402 }
403 ~AutoVMCallerBase()
404 {
405 doRelease();
406 }
407 /** Decreases the number of callers before the instance is destroyed. */
408 void releaseCaller()
409 {
410 Assert(SUCCEEDED(mRC));
411 doRelease();
412 }
413 /** Restores the number of callers after by #release(). #rc() must be
414 * rechecked to ensure the operation succeeded. */
415 void addYY()
416 {
417 AssertReturnVoid(!SUCCEEDED(mRC));
418 mRC = mThat->i_addVMCaller(taQuiet, taAllowNullVM);
419 }
420 /** Returns the result of Console::addVMCaller() */
421 HRESULT rc() const { return mRC; }
422 /** Shortcut to SUCCEEDED(rc()) */
423 bool isOk() const { return SUCCEEDED(mRC); }
424 protected:
425 Console *mThat;
426 void doRelease()
427 {
428 if (SUCCEEDED(mRC))
429 {
430 mThat->i_releaseVMCaller();
431 mRC = E_FAIL;
432 }
433 }
434 private:
435 HRESULT mRC; /* Whether the caller was added. */
436 DECLARE_CLS_COPY_CTOR_ASSIGN_NOOP(AutoVMCallerBase);
437 };
438
439#if 0
440 /**
441 * Helper class that protects sections of code using the mpUVM pointer by
442 * automatically calling addVMCaller() on construction and
443 * releaseVMCaller() on destruction. Intended for Console methods dealing
444 * with mpUVM. The usage pattern is:
445 * <code>
446 * AutoVMCaller autoVMCaller(this);
447 * if (FAILED(autoVMCaller.rc())) return autoVMCaller.rc();
448 * ...
449 * VMR3ReqCall (mpUVM, ...
450 * </code>
451 *
452 * @note Temporarily locks the argument for writing.
453 *
454 * @sa SafeVMPtr, SafeVMPtrQuiet
455 * @note Obsolete, use SafeVMPtr
456 */
457 typedef AutoVMCallerBase<false, false> AutoVMCaller;
458#endif
459
460 /**
461 * Same as AutoVMCaller but doesn't set extended error info on failure.
462 *
463 * @note Temporarily locks the argument for writing.
464 * @note Obsolete, use SafeVMPtrQuiet
465 */
466 typedef AutoVMCallerBase<true, false> AutoVMCallerQuiet;
467
468 /**
469 * Same as AutoVMCaller but allows a null VM pointer (to trigger an error
470 * instead of assertion).
471 *
472 * @note Temporarily locks the argument for writing.
473 * @note Obsolete, use SafeVMPtr
474 */
475 typedef AutoVMCallerBase<false, true> AutoVMCallerWeak;
476
477 /**
478 * Same as AutoVMCaller but doesn't set extended error info on failure
479 * and allows a null VM pointer (to trigger an error instead of
480 * assertion).
481 *
482 * @note Temporarily locks the argument for writing.
483 * @note Obsolete, use SafeVMPtrQuiet
484 */
485 typedef AutoVMCallerBase<true, true> AutoVMCallerQuietWeak;
486
487 /**
488 * Base template for SafeVMPtr and SafeVMPtrQuiet.
489 */
490 template<bool taQuiet = false>
491 class SafeVMPtrBase : public AutoVMCallerBase<taQuiet, true>
492 {
493 typedef AutoVMCallerBase<taQuiet, true> Base;
494 public:
495 SafeVMPtrBase(Console *aThat) : Base(aThat), mRC(E_FAIL), mpUVM(NULL), mpVMM(NULL)
496 {
497 if (Base::isOk())
498 mRC = aThat->i_safeVMPtrRetainer(&mpUVM, &mpVMM, taQuiet);
499 }
500 ~SafeVMPtrBase()
501 {
502 doRelease();
503 }
504 /** Direct PUVM access. */
505 PUVM rawUVM() const { return mpUVM; }
506 /** Direct PCVMMR3VTABLE access. */
507 PCVMMR3VTABLE vtable() const { return mpVMM; }
508 /** Release the handles. */
509 void release()
510 {
511 Assert(SUCCEEDED(mRC));
512 doRelease();
513 }
514
515 /** The combined result of Console::addVMCaller() and Console::safeVMPtrRetainer */
516 HRESULT rc() const { return Base::isOk()? mRC: Base::rc(); }
517 /** Shortcut to SUCCEEDED(rc()) */
518 bool isOk() const { return SUCCEEDED(mRC) && Base::isOk(); }
519
520 private:
521 void doRelease()
522 {
523 if (SUCCEEDED(mRC))
524 {
525 Base::mThat->i_safeVMPtrReleaser(&mpUVM);
526 mRC = E_FAIL;
527 }
528 Base::doRelease();
529 }
530 HRESULT mRC; /* Whether the VM ptr was retained. */
531 PUVM mpUVM;
532 PCVMMR3VTABLE mpVMM;
533 DECLARE_CLS_COPY_CTOR_ASSIGN_NOOP(SafeVMPtrBase);
534 };
535
536public:
537
538 /*
539 * Helper class that safely manages the Console::mpUVM pointer
540 * by calling addVMCaller() on construction and releaseVMCaller() on
541 * destruction. Intended for Console children. The usage pattern is:
542 * <code>
543 * Console::SafeVMPtr ptrVM(mParent);
544 * if (!ptrVM.isOk())
545 * return ptrVM.rc();
546 * ...
547 * VMR3ReqCall(ptrVM.rawUVM(), ...
548 * ...
549 * printf("%p\n", ptrVM.rawUVM());
550 * </code>
551 *
552 * @note Temporarily locks the argument for writing.
553 *
554 * @sa SafeVMPtrQuiet, AutoVMCaller
555 */
556 typedef SafeVMPtrBase<false> SafeVMPtr;
557
558 /**
559 * A deviation of SafeVMPtr that doesn't set the error info on failure.
560 * Intended for pieces of code that don't need to return the VM access
561 * failure to the caller. The usage pattern is:
562 * <code>
563 * Console::SafeVMPtrQuiet pVM(mParent);
564 * if (pVM.rc())
565 * VMR3ReqCall(pVM, ...
566 * return S_OK;
567 * </code>
568 *
569 * @note Temporarily locks the argument for writing.
570 *
571 * @sa SafeVMPtr, AutoVMCaller
572 */
573 typedef SafeVMPtrBase<true> SafeVMPtrQuiet;
574
575 class SharedFolderData
576 {
577 public:
578 SharedFolderData()
579 { }
580
581 SharedFolderData(const Utf8Str &aHostPath,
582 bool aWritable,
583 bool aAutoMount,
584 const Utf8Str &aAutoMountPoint)
585 : m_strHostPath(aHostPath)
586 , m_fWritable(aWritable)
587 , m_fAutoMount(aAutoMount)
588 , m_strAutoMountPoint(aAutoMountPoint)
589 { }
590
591 /** Copy constructor. */
592 SharedFolderData(const SharedFolderData& aThat)
593 : m_strHostPath(aThat.m_strHostPath)
594 , m_fWritable(aThat.m_fWritable)
595 , m_fAutoMount(aThat.m_fAutoMount)
596 , m_strAutoMountPoint(aThat.m_strAutoMountPoint)
597 { }
598
599 /** Copy assignment operator. */
600 SharedFolderData &operator=(SharedFolderData const &a_rThat) RT_NOEXCEPT
601 {
602 m_strHostPath = a_rThat.m_strHostPath;
603 m_fWritable = a_rThat.m_fWritable;
604 m_fAutoMount = a_rThat.m_fAutoMount;
605 m_strAutoMountPoint = a_rThat.m_strAutoMountPoint;
606
607 return *this;
608 }
609
610 Utf8Str m_strHostPath;
611 bool m_fWritable;
612 bool m_fAutoMount;
613 Utf8Str m_strAutoMountPoint;
614 };
615
616 /**
617 * Class for managing emulated USB MSDs.
618 */
619 class USBStorageDevice
620 {
621 public:
622 USBStorageDevice()
623 { }
624 /** The UUID associated with the USB device. */
625 RTUUID mUuid;
626 /** Port of the storage device. */
627 LONG iPort;
628 };
629
630 typedef std::map<Utf8Str, ComObjPtr<SharedFolder> > SharedFolderMap;
631 typedef std::map<Utf8Str, SharedFolderData> SharedFolderDataMap;
632 typedef std::map<Utf8Str, ComPtr<IMediumAttachment> > MediumAttachmentMap;
633 typedef std::list <USBStorageDevice> USBStorageDeviceList;
634
635 static void i_powerUpThreadTask(VMPowerUpTask *pTask);
636 static void i_powerDownThreadTask(VMPowerDownTask *pTask);
637
638private:
639
640 typedef std::list <ComObjPtr<OUSBDevice> > USBDeviceList;
641 typedef std::list <ComObjPtr<RemoteUSBDevice> > RemoteUSBDeviceList;
642
643 HRESULT i_loadVMM(void) RT_NOEXCEPT;
644 HRESULT i_addVMCaller(bool aQuiet = false, bool aAllowNullVM = false);
645 void i_releaseVMCaller();
646 HRESULT i_safeVMPtrRetainer(PUVM *a_ppUVM, PCVMMR3VTABLE *a_ppVMM, bool aQuiet) RT_NOEXCEPT;
647 void i_safeVMPtrReleaser(PUVM *a_ppUVM);
648
649 HRESULT i_consoleInitReleaseLog(const ComPtr<IMachine> aMachine);
650
651 HRESULT i_powerUp(IProgress **aProgress, bool aPaused);
652 HRESULT i_powerDown(IProgress *aProgress = NULL);
653
654/* Note: FreeBSD needs this whether netflt is used or not. */
655#if ((defined(RT_OS_LINUX) && !defined(VBOX_WITH_NETFLT)) || defined(RT_OS_FREEBSD))
656 HRESULT i_attachToTapInterface(INetworkAdapter *networkAdapter);
657 HRESULT i_detachFromTapInterface(INetworkAdapter *networkAdapter);
658#endif
659 HRESULT i_powerDownHostInterfaces();
660
661 HRESULT i_setMachineState(MachineState_T aMachineState, bool aUpdateServer = true);
662 HRESULT i_setMachineStateLocally(MachineState_T aMachineState)
663 {
664 return i_setMachineState(aMachineState, false /* aUpdateServer */);
665 }
666
667 HRESULT i_findSharedFolder(const Utf8Str &strName,
668 ComObjPtr<SharedFolder> &aSharedFolder,
669 bool aSetError = false);
670
671 HRESULT i_fetchSharedFolders(BOOL aGlobal);
672 bool i_findOtherSharedFolder(const Utf8Str &straName,
673 SharedFolderDataMap::const_iterator &aIt);
674
675 HRESULT i_createSharedFolder(const Utf8Str &strName, const SharedFolderData &aData);
676 HRESULT i_removeSharedFolder(const Utf8Str &strName);
677
678 HRESULT i_suspendBeforeConfigChange(PUVM pUVM, PCVMMR3VTABLE pVMM, AutoWriteLock *pAlock, bool *pfResume);
679 void i_resumeAfterConfigChange(PUVM pUVM, PCVMMR3VTABLE pVMM);
680
681 static DECLCALLBACK(int) i_configConstructor(PUVM pUVM, PVM pVM, PCVMMR3VTABLE pVMM, void *pvConsole);
682 void InsertConfigString(PCFGMNODE pNode, const char *pcszName, const char *pcszValue);
683 void InsertConfigString(PCFGMNODE pNode, const char *pcszName, const Utf8Str &rStrValue);
684 void InsertConfigString(PCFGMNODE pNode, const char *pcszName, const Bstr &rBstrValue);
685 void InsertConfigPassword(PCFGMNODE pNode, const char *pcszName, const Utf8Str &rStrValue);
686 void InsertConfigBytes(PCFGMNODE pNode, const char *pcszName, const void *pvBytes, size_t cbBytes);
687 void InsertConfigInteger(PCFGMNODE pNode, const char *pcszName, uint64_t u64Integer);
688 void InsertConfigNode(PCFGMNODE pNode, const char *pcszName, PCFGMNODE *ppChild);
689 void InsertConfigNodeF(PCFGMNODE pNode, PCFGMNODE *ppChild, const char *pszNameFormat, ...);
690 void RemoveConfigValue(PCFGMNODE pNode, const char *pcszName);
691 int SetBiosDiskInfo(ComPtr<IMachine> pMachine, PCFGMNODE pCfg, PCFGMNODE pBiosCfg,
692 Bstr controllerName, const char * const s_apszBiosConfig[4]);
693 void i_configAudioDriver(IVirtualBox *pVirtualBox, IMachine *pMachine, PCFGMNODE pLUN, const char *pszDriverName,
694 bool fAudioEnabledIn, bool fAudioEnabledOut);
695 int i_configConstructorInner(PUVM pUVM, PVM pVM, PCVMMR3VTABLE pVMM, AutoWriteLock *pAlock);
696 int i_configCfgmOverlay(PCFGMNODE pRoot, IVirtualBox *pVirtualBox, IMachine *pMachine);
697 int i_configDumpAPISettingsTweaks(IVirtualBox *pVirtualBox, IMachine *pMachine);
698
699 int i_configGraphicsController(PCFGMNODE pDevices,
700 const GraphicsControllerType_T graphicsController,
701 BusAssignmentManager *pBusMgr,
702 const ComPtr<IMachine> &ptrMachine,
703 const ComPtr<IGraphicsAdapter> &ptrGraphicsAdapter,
704 const ComPtr<IBIOSSettings> &ptrBiosSettings,
705 bool fHMEnabled);
706 int i_checkMediumLocation(IMedium *pMedium, bool *pfUseHostIOCache);
707 int i_unmountMediumFromGuest(PUVM pUVM, PCVMMR3VTABLE pVMM, StorageBus_T enmBus, DeviceType_T enmDevType,
708 const char *pcszDevice, unsigned uInstance, unsigned uLUN,
709 bool fForceUnmount) RT_NOEXCEPT;
710 int i_removeMediumDriverFromVm(PCFGMNODE pCtlInst,
711 const char *pcszDevice,
712 unsigned uInstance,
713 unsigned uLUN,
714 StorageBus_T enmBus,
715 bool fAttachDetach,
716 bool fHotplug,
717 bool fForceUnmount,
718 PUVM pUVM,
719 PCVMMR3VTABLE pVMM,
720 DeviceType_T enmDevType,
721 PCFGMNODE *ppLunL0);
722 int i_configMediumAttachment(const char *pcszDevice,
723 unsigned uInstance,
724 StorageBus_T enmBus,
725 bool fUseHostIOCache,
726 bool fBuiltinIoCache,
727 bool fInsertDiskIntegrityDrv,
728 bool fSetupMerge,
729 unsigned uMergeSource,
730 unsigned uMergeTarget,
731 IMediumAttachment *pMediumAtt,
732 MachineState_T aMachineState,
733 HRESULT *phrc,
734 bool fAttachDetach,
735 bool fForceUnmount,
736 bool fHotplug,
737 PUVM pUVM,
738 PCVMMR3VTABLE pVMM,
739 DeviceType_T *paLedDevType,
740 PCFGMNODE *ppLunL0);
741 int i_configMedium(PCFGMNODE pLunL0,
742 bool fPassthrough,
743 DeviceType_T enmType,
744 bool fUseHostIOCache,
745 bool fBuiltinIoCache,
746 bool fInsertDiskIntegrityDrv,
747 bool fSetupMerge,
748 unsigned uMergeSource,
749 unsigned uMergeTarget,
750 const char *pcszBwGroup,
751 bool fDiscard,
752 bool fNonRotational,
753 ComPtr<IMedium> ptrMedium,
754 MachineState_T aMachineState,
755 HRESULT *phrc);
756 int i_configMediumProperties(PCFGMNODE pCur, IMedium *pMedium, bool *pfHostIP, bool *pfEncrypted);
757 static DECLCALLBACK(int) i_reconfigureMediumAttachment(Console *pThis,
758 PUVM pUVM,
759 PCVMMR3VTABLE pVMM,
760 const char *pcszDevice,
761 unsigned uInstance,
762 StorageBus_T enmBus,
763 bool fUseHostIOCache,
764 bool fBuiltinIoCache,
765 bool fInsertDiskIntegrityDrv,
766 bool fSetupMerge,
767 unsigned uMergeSource,
768 unsigned uMergeTarget,
769 IMediumAttachment *aMediumAtt,
770 MachineState_T aMachineState,
771 HRESULT *phrc);
772 static DECLCALLBACK(int) i_changeRemovableMedium(Console *pThis,
773 PUVM pUVM,
774 PCVMMR3VTABLE pVMM,
775 const char *pcszDevice,
776 unsigned uInstance,
777 StorageBus_T enmBus,
778 bool fUseHostIOCache,
779 IMediumAttachment *aMediumAtt,
780 bool fForce);
781
782 HRESULT i_attachRawPCIDevices(PUVM pUVM, BusAssignmentManager *BusMgr, PCFGMNODE pDevices);
783 struct LEDSET;
784 typedef struct LEDSET *PLEDSET;
785 PPDMLED *i_getLedSet(uint32_t iLedSet);
786 uint32_t i_allocateDriverLeds(uint32_t cLeds, DeviceType_T enmType, DeviceType_T **ppSubTypes);
787 void i_attachStatusDriver(PCFGMNODE pCtlInst, DeviceType_T enmType,
788 uint32_t uFirst, uint32_t uLast,
789 DeviceType_T **ppaSubTypes,
790 Console::MediumAttachmentMap *pmapMediumAttachments,
791 const char *pcszDevice, unsigned uInstance);
792
793 int i_configNetwork(const char *pszDevice, unsigned uInstance, unsigned uLun, INetworkAdapter *aNetworkAdapter,
794 PCFGMNODE pCfg, PCFGMNODE pLunL0, PCFGMNODE pInst, bool fAttachDetach, bool fIgnoreConnectFailure,
795 PUVM pUVM, PCVMMR3VTABLE pVMM);
796 int i_configSerialPort(PCFGMNODE pInst, PortMode_T ePortMode, const char *pszPath, bool fServer);
797 static DECLCALLBACK(void) i_vmstateChangeCallback(PUVM pUVM, PCVMMR3VTABLE pVMM, VMSTATE enmState,
798 VMSTATE enmOldState, void *pvUser);
799 static DECLCALLBACK(int) i_unplugCpu(Console *pThis, PUVM pUVM, PCVMMR3VTABLE pVMM, VMCPUID idCpu);
800 static DECLCALLBACK(int) i_plugCpu(Console *pThis, PUVM pUVM, PCVMMR3VTABLE pVMM, VMCPUID idCpu);
801 HRESULT i_doMediumChange(IMediumAttachment *aMediumAttachment, bool fForce, PUVM pUVM, PCVMMR3VTABLE pVMM);
802 HRESULT i_doCPURemove(ULONG aCpu, PUVM pUVM, PCVMMR3VTABLE pVMM);
803 HRESULT i_doCPUAdd(ULONG aCpu, PUVM pUVM, PCVMMR3VTABLE pVMM);
804
805 HRESULT i_doNetworkAdapterChange(PUVM pUVM, PCVMMR3VTABLE pVMM, const char *pszDevice, unsigned uInstance,
806 unsigned uLun, INetworkAdapter *aNetworkAdapter);
807 static DECLCALLBACK(int) i_changeNetworkAttachment(Console *pThis, PUVM pUVM, PCVMMR3VTABLE pVMM, const char *pszDevice,
808 unsigned uInstance, unsigned uLun, INetworkAdapter *aNetworkAdapter);
809 static DECLCALLBACK(int) i_changeSerialPortAttachment(Console *pThis, PUVM pUVM, PCVMMR3VTABLE pVMM, ISerialPort *pSerialPort);
810
811 int i_changeClipboardMode(ClipboardMode_T aClipboardMode);
812 int i_changeClipboardFileTransferMode(bool aEnabled);
813 int i_changeDnDMode(DnDMode_T aDnDMode);
814
815#ifdef VBOX_WITH_USB
816 HRESULT i_attachUSBDevice(IUSBDevice *aHostDevice, ULONG aMaskedIfs, const Utf8Str &aCaptureFilename);
817 HRESULT i_detachUSBDevice(const ComObjPtr<OUSBDevice> &aHostDevice);
818
819 static DECLCALLBACK(int) i_usbAttachCallback(Console *that, PUVM pUVM, PCVMMR3VTABLE pVMM, IUSBDevice *aHostDevice,
820 PCRTUUID aUuid, const char *aBackend, const char *aAddress,
821 void *pvRemoteBackend, USBConnectionSpeed_T enmSpeed, ULONG aMaskedIfs,
822 const char *pszCaptureFilename);
823 static DECLCALLBACK(int) i_usbDetachCallback(Console *that, PUVM pUVM, PCVMMR3VTABLE pVMM, PCRTUUID aUuid);
824#endif
825
826 static DECLCALLBACK(int) i_attachStorageDevice(Console *pThis,
827 PUVM pUVM,
828 PCVMMR3VTABLE pVMM,
829 const char *pcszDevice,
830 unsigned uInstance,
831 StorageBus_T enmBus,
832 bool fUseHostIOCache,
833 IMediumAttachment *aMediumAtt,
834 bool fSilent);
835 static DECLCALLBACK(int) i_detachStorageDevice(Console *pThis,
836 PUVM pUVM,
837 PCVMMR3VTABLE pVMM,
838 const char *pcszDevice,
839 unsigned uInstance,
840 StorageBus_T enmBus,
841 IMediumAttachment *aMediumAtt,
842 bool fSilent);
843 HRESULT i_doStorageDeviceAttach(IMediumAttachment *aMediumAttachment, PUVM pUVM, PCVMMR3VTABLE pVMM, bool fSilent);
844 HRESULT i_doStorageDeviceDetach(IMediumAttachment *aMediumAttachment, PUVM pUVM, PCVMMR3VTABLE pVMM, bool fSilent);
845
846 static DECLCALLBACK(int) i_stateProgressCallback(PUVM pUVM, unsigned uPercent, void *pvUser);
847
848 static DECLCALLBACK(void) i_genericVMSetErrorCallback(PUVM pUVM, void *pvUser, int rc, RT_SRC_POS_DECL,
849 const char *pszErrorFmt, va_list va);
850
851 void i_atVMRuntimeErrorCallbackF(uint32_t fFatal, const char *pszErrorId, const char *pszFormat, ...);
852 static DECLCALLBACK(void) i_atVMRuntimeErrorCallback(PUVM pUVM, void *pvUser, uint32_t fFatal,
853 const char *pszErrorId, const char *pszFormat, va_list va);
854
855 HRESULT i_captureUSBDevices(PUVM pUVM);
856 void i_detachAllUSBDevices(bool aDone);
857
858
859 static DECLCALLBACK(int) i_vmm2User_SaveState(PCVMM2USERMETHODS pThis, PUVM pUVM);
860 static DECLCALLBACK(void) i_vmm2User_NotifyEmtInit(PCVMM2USERMETHODS pThis, PUVM pUVM, PUVMCPU pUVCpu);
861 static DECLCALLBACK(void) i_vmm2User_NotifyEmtTerm(PCVMM2USERMETHODS pThis, PUVM pUVM, PUVMCPU pUVCpu);
862 static DECLCALLBACK(void) i_vmm2User_NotifyPdmtInit(PCVMM2USERMETHODS pThis, PUVM pUVM);
863 static DECLCALLBACK(void) i_vmm2User_NotifyPdmtTerm(PCVMM2USERMETHODS pThis, PUVM pUVM);
864 static DECLCALLBACK(void) i_vmm2User_NotifyResetTurnedIntoPowerOff(PCVMM2USERMETHODS pThis, PUVM pUVM);
865 static DECLCALLBACK(void *) i_vmm2User_QueryGenericObject(PCVMM2USERMETHODS pThis, PUVM pUVM, PCRTUUID pUuid);
866
867 static DECLCALLBACK(void *) i_drvStatus_QueryInterface(PPDMIBASE pInterface, const char *pszIID);
868 static DECLCALLBACK(void) i_drvStatus_UnitChanged(PPDMILEDCONNECTORS pInterface, unsigned iLUN);
869 static DECLCALLBACK(int) i_drvStatus_MediumEjected(PPDMIMEDIANOTIFY pInterface, unsigned iLUN);
870 static DECLCALLBACK(void) i_drvStatus_Destruct(PPDMDRVINS pDrvIns);
871 static DECLCALLBACK(int) i_drvStatus_Construct(PPDMDRVINS pDrvIns, PCFGMNODE pCfg, uint32_t fFlags);
872
873 static DECLCALLBACK(int) i_pdmIfSecKey_KeyRetain(PPDMISECKEY pInterface, const char *pszId, const uint8_t **ppbKey,
874 size_t *pcbKey);
875 static DECLCALLBACK(int) i_pdmIfSecKey_KeyRelease(PPDMISECKEY pInterface, const char *pszId);
876 static DECLCALLBACK(int) i_pdmIfSecKey_PasswordRetain(PPDMISECKEY pInterface, const char *pszId, const char **ppszPassword);
877 static DECLCALLBACK(int) i_pdmIfSecKey_PasswordRelease(PPDMISECKEY pInterface, const char *pszId);
878
879 static DECLCALLBACK(int) i_pdmIfSecKeyHlp_KeyMissingNotify(PPDMISECKEYHLP pInterface);
880
881 int mcAudioRefs;
882 volatile uint32_t mcVRDPClients;
883 uint32_t mu32SingleRDPClientId; /* The id of a connected client in the single connection mode. */
884 volatile bool mcGuestCredentialsProvided;
885
886 static const char *sSSMConsoleUnit;
887
888 HRESULT i_loadDataFromSavedState();
889 int i_loadStateFileExecInternal(PSSMHANDLE pSSM, PCVMMR3VTABLE pVMM, uint32_t u32Version);
890
891 static DECLCALLBACK(int) i_saveStateFileExec(PSSMHANDLE pSSM, PCVMMR3VTABLE pVMM, void *pvUser);
892 static DECLCALLBACK(int) i_loadStateFileExec(PSSMHANDLE pSSM, PCVMMR3VTABLE pVMM, void *pvUser,
893 uint32_t uVersion, uint32_t uPass);
894
895#ifdef VBOX_WITH_GUEST_PROPS
896 HRESULT i_doEnumerateGuestProperties(const Utf8Str &aPatterns,
897 std::vector<Utf8Str> &aNames,
898 std::vector<Utf8Str> &aValues,
899 std::vector<LONG64> &aTimestamps,
900 std::vector<Utf8Str> &aFlags);
901
902 void i_guestPropertiesHandleVMReset(void);
903 bool i_guestPropertiesVRDPEnabled(void);
904 void i_guestPropertiesVRDPUpdateLogon(uint32_t u32ClientId, const char *pszUser, const char *pszDomain);
905 void i_guestPropertiesVRDPUpdateActiveClient(uint32_t u32ClientId);
906 void i_guestPropertiesVRDPUpdateClientAttach(uint32_t u32ClientId, bool fAttached);
907 void i_guestPropertiesVRDPUpdateNameChange(uint32_t u32ClientId, const char *pszName);
908 void i_guestPropertiesVRDPUpdateIPAddrChange(uint32_t u32ClientId, const char *pszIPAddr);
909 void i_guestPropertiesVRDPUpdateLocationChange(uint32_t u32ClientId, const char *pszLocation);
910 void i_guestPropertiesVRDPUpdateOtherInfoChange(uint32_t u32ClientId, const char *pszOtherInfo);
911 void i_guestPropertiesVRDPUpdateDisconnect(uint32_t u32ClientId);
912#endif
913
914 /** @name Disk encryption support
915 * @{ */
916 HRESULT i_consoleParseDiskEncryption(const char *psz, const char **ppszEnd);
917 HRESULT i_configureEncryptionForDisk(const Utf8Str &strId, unsigned *pcDisksConfigured);
918 HRESULT i_clearDiskEncryptionKeysOnAllAttachmentsWithKeyId(const Utf8Str &strId);
919 HRESULT i_initSecretKeyIfOnAllAttachments(void);
920 int i_consoleParseKeyValue(const char *psz, const char **ppszEnd,
921 char **ppszKey, char **ppszVal);
922 void i_removeSecretKeysOnSuspend();
923 /** @} */
924
925 /** @name Teleporter support
926 * @{ */
927 static DECLCALLBACK(int) i_teleporterSrcThreadWrapper(RTTHREAD hThreadSelf, void *pvUser);
928 HRESULT i_teleporterSrc(TeleporterStateSrc *pState);
929 HRESULT i_teleporterSrcReadACK(TeleporterStateSrc *pState, const char *pszWhich, const char *pszNAckMsg = NULL);
930 HRESULT i_teleporterSrcSubmitCommand(TeleporterStateSrc *pState, const char *pszCommand, bool fWaitForAck = true);
931 HRESULT i_teleporterTrg(PUVM pUVM, PCVMMR3VTABLE pVMM, IMachine *pMachine, Utf8Str *pErrorMsg,
932 bool fStartPaused, Progress *pProgress, bool *pfPowerOffOnFailure);
933 static DECLCALLBACK(int) i_teleporterTrgServeConnection(RTSOCKET Sock, void *pvUser);
934 /** @} */
935
936 bool mSavedStateDataLoaded : 1;
937
938 const ComPtr<IMachine> mMachine;
939 const ComPtr<IInternalMachineControl> mControl;
940
941 const ComPtr<IVRDEServer> mVRDEServer;
942
943 ConsoleVRDPServer * const mConsoleVRDPServer;
944 bool mfVRDEChangeInProcess;
945 bool mfVRDEChangePending;
946 const ComObjPtr<Guest> mGuest;
947 const ComObjPtr<Keyboard> mKeyboard;
948 const ComObjPtr<Mouse> mMouse;
949 const ComObjPtr<Display> mDisplay;
950 const ComObjPtr<MachineDebugger> mDebugger;
951 const ComObjPtr<VRDEServerInfo> mVRDEServerInfo;
952 /** This can safely be used without holding any locks.
953 * An AutoCaller suffices to prevent it being destroy while in use and
954 * internally there is a lock providing the necessary serialization. */
955 const ComObjPtr<EventSource> mEventSource;
956#ifdef VBOX_WITH_EXTPACK
957 const ComObjPtr<ExtPackManager> mptrExtPackManager;
958#endif
959 const ComObjPtr<EmulatedUSB> mEmulatedUSB;
960 const ComObjPtr<NvramStore> mptrNvramStore;
961
962 USBDeviceList mUSBDevices;
963 RemoteUSBDeviceList mRemoteUSBDevices;
964
965 SharedFolderDataMap m_mapGlobalSharedFolders;
966 SharedFolderDataMap m_mapMachineSharedFolders;
967 SharedFolderMap m_mapSharedFolders; // the console instances
968
969 /** VMM loader handle. */
970 RTLDRMOD mhModVMM;
971 /** The VMM vtable. */
972 PCVMMR3VTABLE mpVMM;
973 /** The user mode VM handle. */
974 PUVM mpUVM;
975 /** Holds the number of "readonly" mpUVM callers (users). */
976 uint32_t mVMCallers;
977 /** Semaphore posted when the number of mpUVM callers drops to zero. */
978 RTSEMEVENT mVMZeroCallersSem;
979 /** true when Console has entered the mpUVM destruction phase. */
980 bool mVMDestroying : 1;
981 /** true when power down is initiated by vmstateChangeCallback (EMT). */
982 bool mVMPoweredOff : 1;
983 /** true when vmstateChangeCallback shouldn't initiate a power down. */
984 bool mVMIsAlreadyPoweringOff : 1;
985 /** true if we already showed the snapshot folder size warning. */
986 bool mfSnapshotFolderSizeWarningShown : 1;
987 /** true if we already showed the snapshot folder ext4/xfs bug warning. */
988 bool mfSnapshotFolderExt4WarningShown : 1;
989 /** true if we already listed the disk type of the snapshot folder. */
990 bool mfSnapshotFolderDiskTypeShown : 1;
991 /** true if a USB controller is available (i.e. USB devices can be attached). */
992 bool mfVMHasUsbController : 1;
993 /** Shadow of the VBoxInternal2/TurnResetIntoPowerOff extra data setting.
994 * This is initialized by Console::i_configConstructorInner(). */
995 bool mfTurnResetIntoPowerOff : 1;
996 /** true if the VM power off was caused by reset. */
997 bool mfPowerOffCausedByReset : 1;
998
999 /** Pointer to the VMM -> User (that's us) callbacks. */
1000 struct MYVMM2USERMETHODS : public VMM2USERMETHODS
1001 {
1002 Console *pConsole;
1003 /** The in-progress snapshot. */
1004 ISnapshot *pISnapshot;
1005 } *mpVmm2UserMethods;
1006
1007 /** The current network attachment type in the VM.
1008 * This doesn't have to match the network attachment type maintained in the
1009 * NetworkAdapter. This is needed to change the network attachment
1010 * dynamically.
1011 */
1012 typedef std::vector<NetworkAttachmentType_T> NetworkAttachmentTypeVector;
1013 NetworkAttachmentTypeVector meAttachmentType;
1014
1015 VMMDev * m_pVMMDev;
1016 AudioVRDE * const mAudioVRDE;
1017#ifdef VBOX_WITH_USB_CARDREADER
1018 UsbCardReader * const mUsbCardReader;
1019#endif
1020 BusAssignmentManager* mBusMgr;
1021
1022 /** @name LEDs and their management
1023 * @{ */
1024 /** Number of LED sets in use in maLedSets. */
1025 uint32_t mcLedSets;
1026 /** LED sets. */
1027 struct LEDSET
1028 {
1029 PPDMLED *papLeds;
1030 uint32_t cLeds;
1031 DeviceType_T enmType;
1032 DeviceType_T *paSubTypes; /**< Optionally, device types for each individual LED. Runs parallel to papLeds. */
1033 } maLedSets[32];
1034 /** @} */
1035
1036 MediumAttachmentMap mapMediumAttachments;
1037
1038 /** List of attached USB storage devices. */
1039 USBStorageDeviceList mUSBStorageDevices;
1040
1041 /** Store for secret keys. */
1042 SecretKeyStore * const m_pKeyStore;
1043 /** Number of disks configured for encryption. */
1044 unsigned m_cDisksEncrypted;
1045 /** Number of disks which have the key in the map. */
1046 unsigned m_cDisksPwProvided;
1047
1048 /** Current active port modes of the supported serial ports. */
1049 PortMode_T m_aeSerialPortMode[4];
1050
1051 /** Pointer to the key consumer -> provider (that's us) callbacks. */
1052 struct MYPDMISECKEY : public PDMISECKEY
1053 {
1054 Console *pConsole;
1055 } *mpIfSecKey;
1056
1057 /** Pointer to the key helpers -> provider (that's us) callbacks. */
1058 struct MYPDMISECKEYHLP : public PDMISECKEYHLP
1059 {
1060 Console *pConsole;
1061 } *mpIfSecKeyHlp;
1062
1063/* Note: FreeBSD needs this whether netflt is used or not. */
1064#if ((defined(RT_OS_LINUX) && !defined(VBOX_WITH_NETFLT)) || defined(RT_OS_FREEBSD))
1065 Utf8Str maTAPDeviceName[8];
1066 RTFILE maTapFD[8];
1067#endif
1068
1069 bool mVMStateChangeCallbackDisabled;
1070
1071 bool mfUseHostClipboard;
1072
1073 /** Local machine state value. */
1074 MachineState_T mMachineState;
1075
1076 /** Machine uuid string. */
1077 Bstr mstrUuid;
1078
1079#ifdef VBOX_WITH_DRAG_AND_DROP
1080 HGCMSVCEXTHANDLE m_hHgcmSvcExtDragAndDrop;
1081#endif
1082
1083 /** Pointer to the progress object of a live cancelable task.
1084 *
1085 * This is currently only used by Console::Teleport(), but is intended to later
1086 * be used by the live snapshot code path as well. Actions like
1087 * Console::PowerDown, which automatically cancels out the running snapshot /
1088 * teleportation operation, will cancel the teleportation / live snapshot
1089 * operation before starting. */
1090 ComPtr<IProgress> mptrCancelableProgress;
1091
1092 ComPtr<IEventListener> mVmListener;
1093
1094#ifdef VBOX_WITH_RECORDING
1095 struct Recording
1096 {
1097 Recording()
1098 : mpCtx(NULL)
1099# ifdef VBOX_WITH_AUDIO_RECORDING
1100 , mAudioRec(NULL)
1101# endif
1102 { }
1103
1104 /** The recording context. */
1105 RecordingContext *mpCtx;
1106# ifdef VBOX_WITH_AUDIO_RECORDING
1107 /** Pointer to capturing audio backend. */
1108 AudioVideoRec * const mAudioRec;
1109# endif
1110 } mRecording;
1111#endif /* VBOX_WITH_RECORDING */
1112
1113#ifdef VBOX_WITH_CLOUD_NET
1114 GatewayInfo mGateway;
1115#endif /* VBOX_WITH_CLOUD_NET */
1116
1117 friend class VMTask;
1118 friend class ConsoleVRDPServer;
1119};
1120
1121#endif /* !MAIN_INCLUDED_ConsoleImpl_h */
1122/* vi: set tabstop=4 shiftwidth=4 expandtab: */
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