VirtualBox

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

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

libs/libssh,Main,FE/VBoxManage,Devices/Network/DrvCloudTunnel|ai: Add support for proxies, bugref:9469

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