VirtualBox

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

Last change on this file since 88163 was 87391, checked in by vboxsync, 4 years ago

Allocate PDMLED console LED structs in a sensible manner for each virtual HW driver; not prearranged slices of an poorly sized global pool. bugref:9892

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