VirtualBox

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

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

VMM,Main,HostServices: Use a function table for accessing the VBoxVMM.dll/so/dylib functionality, and load it dynamically when the Console object is initialized. Also converted a few drivers in Main to use device helpers to get config values and such. bugref:10074

  • 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 93444 2022-01-26 18:01:15Z 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 PLEDSET i_allocateDriverLeds(uint32_t cLeds, DeviceType_T enmType, DeviceType_T **ppSubTypes);
786 void i_attachStatusDriver(PCFGMNODE pCtlInst, DeviceType_T enmType,
787 uint32_t uFirst, uint32_t uLast,
788 DeviceType_T **ppaSubTypes,
789 Console::MediumAttachmentMap *pmapMediumAttachments,
790 const char *pcszDevice, unsigned uInstance);
791
792 int i_configNetwork(const char *pszDevice, unsigned uInstance, unsigned uLun, INetworkAdapter *aNetworkAdapter,
793 PCFGMNODE pCfg, PCFGMNODE pLunL0, PCFGMNODE pInst, bool fAttachDetach, bool fIgnoreConnectFailure,
794 PUVM pUVM, PCVMMR3VTABLE pVMM);
795 int i_configSerialPort(PCFGMNODE pInst, PortMode_T ePortMode, const char *pszPath, bool fServer);
796 static DECLCALLBACK(void) i_vmstateChangeCallback(PUVM pUVM, PCVMMR3VTABLE pVMM, VMSTATE enmState,
797 VMSTATE enmOldState, void *pvUser);
798 static DECLCALLBACK(int) i_unplugCpu(Console *pThis, PUVM pUVM, PCVMMR3VTABLE pVMM, VMCPUID idCpu);
799 static DECLCALLBACK(int) i_plugCpu(Console *pThis, PUVM pUVM, PCVMMR3VTABLE pVMM, VMCPUID idCpu);
800 HRESULT i_doMediumChange(IMediumAttachment *aMediumAttachment, bool fForce, PUVM pUVM, PCVMMR3VTABLE pVMM);
801 HRESULT i_doCPURemove(ULONG aCpu, PUVM pUVM, PCVMMR3VTABLE pVMM);
802 HRESULT i_doCPUAdd(ULONG aCpu, PUVM pUVM, PCVMMR3VTABLE pVMM);
803
804 HRESULT i_doNetworkAdapterChange(PUVM pUVM, PCVMMR3VTABLE pVMM, const char *pszDevice, unsigned uInstance,
805 unsigned uLun, INetworkAdapter *aNetworkAdapter);
806 static DECLCALLBACK(int) i_changeNetworkAttachment(Console *pThis, PUVM pUVM, PCVMMR3VTABLE pVMM, const char *pszDevice,
807 unsigned uInstance, unsigned uLun, INetworkAdapter *aNetworkAdapter);
808 static DECLCALLBACK(int) i_changeSerialPortAttachment(Console *pThis, PUVM pUVM, PCVMMR3VTABLE pVMM, ISerialPort *pSerialPort);
809
810 int i_changeClipboardMode(ClipboardMode_T aClipboardMode);
811 int i_changeClipboardFileTransferMode(bool aEnabled);
812 int i_changeDnDMode(DnDMode_T aDnDMode);
813
814#ifdef VBOX_WITH_USB
815 HRESULT i_attachUSBDevice(IUSBDevice *aHostDevice, ULONG aMaskedIfs, const Utf8Str &aCaptureFilename);
816 HRESULT i_detachUSBDevice(const ComObjPtr<OUSBDevice> &aHostDevice);
817
818 static DECLCALLBACK(int) i_usbAttachCallback(Console *that, PUVM pUVM, PCVMMR3VTABLE pVMM, IUSBDevice *aHostDevice,
819 PCRTUUID aUuid, const char *aBackend, const char *aAddress,
820 void *pvRemoteBackend, USBConnectionSpeed_T enmSpeed, ULONG aMaskedIfs,
821 const char *pszCaptureFilename);
822 static DECLCALLBACK(int) i_usbDetachCallback(Console *that, PUVM pUVM, PCVMMR3VTABLE pVMM, PCRTUUID aUuid);
823#endif
824
825 static DECLCALLBACK(int) i_attachStorageDevice(Console *pThis,
826 PUVM pUVM,
827 PCVMMR3VTABLE pVMM,
828 const char *pcszDevice,
829 unsigned uInstance,
830 StorageBus_T enmBus,
831 bool fUseHostIOCache,
832 IMediumAttachment *aMediumAtt,
833 bool fSilent);
834 static DECLCALLBACK(int) i_detachStorageDevice(Console *pThis,
835 PUVM pUVM,
836 PCVMMR3VTABLE pVMM,
837 const char *pcszDevice,
838 unsigned uInstance,
839 StorageBus_T enmBus,
840 IMediumAttachment *aMediumAtt,
841 bool fSilent);
842 HRESULT i_doStorageDeviceAttach(IMediumAttachment *aMediumAttachment, PUVM pUVM, PCVMMR3VTABLE pVMM, bool fSilent);
843 HRESULT i_doStorageDeviceDetach(IMediumAttachment *aMediumAttachment, PUVM pUVM, PCVMMR3VTABLE pVMM, bool fSilent);
844
845 static DECLCALLBACK(int) i_stateProgressCallback(PUVM pUVM, unsigned uPercent, void *pvUser);
846
847 static DECLCALLBACK(void) i_genericVMSetErrorCallback(PUVM pUVM, void *pvUser, int rc, RT_SRC_POS_DECL,
848 const char *pszErrorFmt, va_list va);
849
850 void i_atVMRuntimeErrorCallbackF(uint32_t fFatal, const char *pszErrorId, const char *pszFormat, ...);
851 static DECLCALLBACK(void) i_atVMRuntimeErrorCallback(PUVM pUVM, void *pvUser, uint32_t fFatal,
852 const char *pszErrorId, const char *pszFormat, va_list va);
853
854 HRESULT i_captureUSBDevices(PUVM pUVM);
855 void i_detachAllUSBDevices(bool aDone);
856
857
858 static DECLCALLBACK(int) i_vmm2User_SaveState(PCVMM2USERMETHODS pThis, PUVM pUVM);
859 static DECLCALLBACK(void) i_vmm2User_NotifyEmtInit(PCVMM2USERMETHODS pThis, PUVM pUVM, PUVMCPU pUVCpu);
860 static DECLCALLBACK(void) i_vmm2User_NotifyEmtTerm(PCVMM2USERMETHODS pThis, PUVM pUVM, PUVMCPU pUVCpu);
861 static DECLCALLBACK(void) i_vmm2User_NotifyPdmtInit(PCVMM2USERMETHODS pThis, PUVM pUVM);
862 static DECLCALLBACK(void) i_vmm2User_NotifyPdmtTerm(PCVMM2USERMETHODS pThis, PUVM pUVM);
863 static DECLCALLBACK(void) i_vmm2User_NotifyResetTurnedIntoPowerOff(PCVMM2USERMETHODS pThis, PUVM pUVM);
864 static DECLCALLBACK(void *) i_vmm2User_QueryGenericObject(PCVMM2USERMETHODS pThis, PUVM pUVM, PCRTUUID pUuid);
865
866 static DECLCALLBACK(void *) i_drvStatus_QueryInterface(PPDMIBASE pInterface, const char *pszIID);
867 static DECLCALLBACK(void) i_drvStatus_UnitChanged(PPDMILEDCONNECTORS pInterface, unsigned iLUN);
868 static DECLCALLBACK(int) i_drvStatus_MediumEjected(PPDMIMEDIANOTIFY pInterface, unsigned iLUN);
869 static DECLCALLBACK(void) i_drvStatus_Destruct(PPDMDRVINS pDrvIns);
870 static DECLCALLBACK(int) i_drvStatus_Construct(PPDMDRVINS pDrvIns, PCFGMNODE pCfg, uint32_t fFlags);
871
872 static DECLCALLBACK(int) i_pdmIfSecKey_KeyRetain(PPDMISECKEY pInterface, const char *pszId, const uint8_t **ppbKey,
873 size_t *pcbKey);
874 static DECLCALLBACK(int) i_pdmIfSecKey_KeyRelease(PPDMISECKEY pInterface, const char *pszId);
875 static DECLCALLBACK(int) i_pdmIfSecKey_PasswordRetain(PPDMISECKEY pInterface, const char *pszId, const char **ppszPassword);
876 static DECLCALLBACK(int) i_pdmIfSecKey_PasswordRelease(PPDMISECKEY pInterface, const char *pszId);
877
878 static DECLCALLBACK(int) i_pdmIfSecKeyHlp_KeyMissingNotify(PPDMISECKEYHLP pInterface);
879
880 int mcAudioRefs;
881 volatile uint32_t mcVRDPClients;
882 uint32_t mu32SingleRDPClientId; /* The id of a connected client in the single connection mode. */
883 volatile bool mcGuestCredentialsProvided;
884
885 static const char *sSSMConsoleUnit;
886
887 HRESULT i_loadDataFromSavedState();
888 int i_loadStateFileExecInternal(PSSMHANDLE pSSM, PCVMMR3VTABLE pVMM, uint32_t u32Version);
889
890 static DECLCALLBACK(int) i_saveStateFileExec(PSSMHANDLE pSSM, PCVMMR3VTABLE pVMM, void *pvUser);
891 static DECLCALLBACK(int) i_loadStateFileExec(PSSMHANDLE pSSM, PCVMMR3VTABLE pVMM, void *pvUser,
892 uint32_t uVersion, uint32_t uPass);
893
894#ifdef VBOX_WITH_GUEST_PROPS
895 HRESULT i_doEnumerateGuestProperties(const Utf8Str &aPatterns,
896 std::vector<Utf8Str> &aNames,
897 std::vector<Utf8Str> &aValues,
898 std::vector<LONG64> &aTimestamps,
899 std::vector<Utf8Str> &aFlags);
900
901 void i_guestPropertiesHandleVMReset(void);
902 bool i_guestPropertiesVRDPEnabled(void);
903 void i_guestPropertiesVRDPUpdateLogon(uint32_t u32ClientId, const char *pszUser, const char *pszDomain);
904 void i_guestPropertiesVRDPUpdateActiveClient(uint32_t u32ClientId);
905 void i_guestPropertiesVRDPUpdateClientAttach(uint32_t u32ClientId, bool fAttached);
906 void i_guestPropertiesVRDPUpdateNameChange(uint32_t u32ClientId, const char *pszName);
907 void i_guestPropertiesVRDPUpdateIPAddrChange(uint32_t u32ClientId, const char *pszIPAddr);
908 void i_guestPropertiesVRDPUpdateLocationChange(uint32_t u32ClientId, const char *pszLocation);
909 void i_guestPropertiesVRDPUpdateOtherInfoChange(uint32_t u32ClientId, const char *pszOtherInfo);
910 void i_guestPropertiesVRDPUpdateDisconnect(uint32_t u32ClientId);
911#endif
912
913 /** @name Disk encryption support
914 * @{ */
915 HRESULT i_consoleParseDiskEncryption(const char *psz, const char **ppszEnd);
916 HRESULT i_configureEncryptionForDisk(const Utf8Str &strId, unsigned *pcDisksConfigured);
917 HRESULT i_clearDiskEncryptionKeysOnAllAttachmentsWithKeyId(const Utf8Str &strId);
918 HRESULT i_initSecretKeyIfOnAllAttachments(void);
919 int i_consoleParseKeyValue(const char *psz, const char **ppszEnd,
920 char **ppszKey, char **ppszVal);
921 void i_removeSecretKeysOnSuspend();
922 /** @} */
923
924 /** @name Teleporter support
925 * @{ */
926 static DECLCALLBACK(int) i_teleporterSrcThreadWrapper(RTTHREAD hThreadSelf, void *pvUser);
927 HRESULT i_teleporterSrc(TeleporterStateSrc *pState);
928 HRESULT i_teleporterSrcReadACK(TeleporterStateSrc *pState, const char *pszWhich, const char *pszNAckMsg = NULL);
929 HRESULT i_teleporterSrcSubmitCommand(TeleporterStateSrc *pState, const char *pszCommand, bool fWaitForAck = true);
930 HRESULT i_teleporterTrg(PUVM pUVM, PCVMMR3VTABLE pVMM, IMachine *pMachine, Utf8Str *pErrorMsg,
931 bool fStartPaused, Progress *pProgress, bool *pfPowerOffOnFailure);
932 static DECLCALLBACK(int) i_teleporterTrgServeConnection(RTSOCKET Sock, void *pvUser);
933 /** @} */
934
935 bool mSavedStateDataLoaded : 1;
936
937 const ComPtr<IMachine> mMachine;
938 const ComPtr<IInternalMachineControl> mControl;
939
940 const ComPtr<IVRDEServer> mVRDEServer;
941
942 ConsoleVRDPServer * const mConsoleVRDPServer;
943 bool mfVRDEChangeInProcess;
944 bool mfVRDEChangePending;
945 const ComObjPtr<Guest> mGuest;
946 const ComObjPtr<Keyboard> mKeyboard;
947 const ComObjPtr<Mouse> mMouse;
948 const ComObjPtr<Display> mDisplay;
949 const ComObjPtr<MachineDebugger> mDebugger;
950 const ComObjPtr<VRDEServerInfo> mVRDEServerInfo;
951 /** This can safely be used without holding any locks.
952 * An AutoCaller suffices to prevent it being destroy while in use and
953 * internally there is a lock providing the necessary serialization. */
954 const ComObjPtr<EventSource> mEventSource;
955#ifdef VBOX_WITH_EXTPACK
956 const ComObjPtr<ExtPackManager> mptrExtPackManager;
957#endif
958 const ComObjPtr<EmulatedUSB> mEmulatedUSB;
959 const ComObjPtr<NvramStore> mptrNvramStore;
960
961 USBDeviceList mUSBDevices;
962 RemoteUSBDeviceList mRemoteUSBDevices;
963
964 SharedFolderDataMap m_mapGlobalSharedFolders;
965 SharedFolderDataMap m_mapMachineSharedFolders;
966 SharedFolderMap m_mapSharedFolders; // the console instances
967
968 /** VMM loader handle. */
969 RTLDRMOD mhModVMM;
970 /** The VMM vtable. */
971 PCVMMR3VTABLE mpVMM;
972 /** The user mode VM handle. */
973 PUVM mpUVM;
974 /** Holds the number of "readonly" mpUVM callers (users). */
975 uint32_t mVMCallers;
976 /** Semaphore posted when the number of mpUVM callers drops to zero. */
977 RTSEMEVENT mVMZeroCallersSem;
978 /** true when Console has entered the mpUVM destruction phase. */
979 bool mVMDestroying : 1;
980 /** true when power down is initiated by vmstateChangeCallback (EMT). */
981 bool mVMPoweredOff : 1;
982 /** true when vmstateChangeCallback shouldn't initiate a power down. */
983 bool mVMIsAlreadyPoweringOff : 1;
984 /** true if we already showed the snapshot folder size warning. */
985 bool mfSnapshotFolderSizeWarningShown : 1;
986 /** true if we already showed the snapshot folder ext4/xfs bug warning. */
987 bool mfSnapshotFolderExt4WarningShown : 1;
988 /** true if we already listed the disk type of the snapshot folder. */
989 bool mfSnapshotFolderDiskTypeShown : 1;
990 /** true if a USB controller is available (i.e. USB devices can be attached). */
991 bool mfVMHasUsbController : 1;
992 /** Shadow of the VBoxInternal2/TurnResetIntoPowerOff extra data setting.
993 * This is initialized by Console::i_configConstructorInner(). */
994 bool mfTurnResetIntoPowerOff : 1;
995 /** true if the VM power off was caused by reset. */
996 bool mfPowerOffCausedByReset : 1;
997
998 /** Pointer to the VMM -> User (that's us) callbacks. */
999 struct MYVMM2USERMETHODS : public VMM2USERMETHODS
1000 {
1001 Console *pConsole;
1002 /** The in-progress snapshot. */
1003 ISnapshot *pISnapshot;
1004 } *mpVmm2UserMethods;
1005
1006 /** The current network attachment type in the VM.
1007 * This doesn't have to match the network attachment type maintained in the
1008 * NetworkAdapter. This is needed to change the network attachment
1009 * dynamically.
1010 */
1011 typedef std::vector<NetworkAttachmentType_T> NetworkAttachmentTypeVector;
1012 NetworkAttachmentTypeVector meAttachmentType;
1013
1014 VMMDev * m_pVMMDev;
1015 AudioVRDE * const mAudioVRDE;
1016#ifdef VBOX_WITH_USB_CARDREADER
1017 UsbCardReader * const mUsbCardReader;
1018#endif
1019 BusAssignmentManager* mBusMgr;
1020
1021 /** @name LEDs and their management
1022 * @{ */
1023 /** Number of LED sets in use in maLedSets. */
1024 uint32_t mcLedSets;
1025 /** LED sets. */
1026 struct LEDSET
1027 {
1028 PPDMLED *papLeds;
1029 uint32_t cLeds;
1030 DeviceType_T enmType;
1031 DeviceType_T *paSubTypes; /**< Optionally, device types for each individual LED. Runs parallel to papLeds. */
1032 } maLedSets[32];
1033 /** @} */
1034
1035 MediumAttachmentMap mapMediumAttachments;
1036
1037 /** List of attached USB storage devices. */
1038 USBStorageDeviceList mUSBStorageDevices;
1039
1040 /** Store for secret keys. */
1041 SecretKeyStore * const m_pKeyStore;
1042 /** Number of disks configured for encryption. */
1043 unsigned m_cDisksEncrypted;
1044 /** Number of disks which have the key in the map. */
1045 unsigned m_cDisksPwProvided;
1046
1047 /** Current active port modes of the supported serial ports. */
1048 PortMode_T m_aeSerialPortMode[4];
1049
1050 /** Pointer to the key consumer -> provider (that's us) callbacks. */
1051 struct MYPDMISECKEY : public PDMISECKEY
1052 {
1053 Console *pConsole;
1054 } *mpIfSecKey;
1055
1056 /** Pointer to the key helpers -> provider (that's us) callbacks. */
1057 struct MYPDMISECKEYHLP : public PDMISECKEYHLP
1058 {
1059 Console *pConsole;
1060 } *mpIfSecKeyHlp;
1061
1062/* Note: FreeBSD needs this whether netflt is used or not. */
1063#if ((defined(RT_OS_LINUX) && !defined(VBOX_WITH_NETFLT)) || defined(RT_OS_FREEBSD))
1064 Utf8Str maTAPDeviceName[8];
1065 RTFILE maTapFD[8];
1066#endif
1067
1068 bool mVMStateChangeCallbackDisabled;
1069
1070 bool mfUseHostClipboard;
1071
1072 /** Local machine state value. */
1073 MachineState_T mMachineState;
1074
1075 /** Machine uuid string. */
1076 Bstr mstrUuid;
1077
1078#ifdef VBOX_WITH_DRAG_AND_DROP
1079 HGCMSVCEXTHANDLE m_hHgcmSvcExtDragAndDrop;
1080#endif
1081
1082 /** Pointer to the progress object of a live cancelable task.
1083 *
1084 * This is currently only used by Console::Teleport(), but is intended to later
1085 * be used by the live snapshot code path as well. Actions like
1086 * Console::PowerDown, which automatically cancels out the running snapshot /
1087 * teleportation operation, will cancel the teleportation / live snapshot
1088 * operation before starting. */
1089 ComPtr<IProgress> mptrCancelableProgress;
1090
1091 ComPtr<IEventListener> mVmListener;
1092
1093#ifdef VBOX_WITH_RECORDING
1094 struct Recording
1095 {
1096 Recording()
1097 : mpCtx(NULL)
1098# ifdef VBOX_WITH_AUDIO_RECORDING
1099 , mAudioRec(NULL)
1100# endif
1101 { }
1102
1103 /** The recording context. */
1104 RecordingContext *mpCtx;
1105# ifdef VBOX_WITH_AUDIO_RECORDING
1106 /** Pointer to capturing audio backend. */
1107 AudioVideoRec * const mAudioRec;
1108# endif
1109 } mRecording;
1110#endif /* VBOX_WITH_RECORDING */
1111
1112#ifdef VBOX_WITH_CLOUD_NET
1113 GatewayInfo mGateway;
1114#endif /* VBOX_WITH_CLOUD_NET */
1115
1116 friend class VMTask;
1117 friend class ConsoleVRDPServer;
1118};
1119
1120#endif /* !MAIN_INCLUDED_ConsoleImpl_h */
1121/* 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