VirtualBox

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

Last change on this file since 96457 was 96407, checked in by vboxsync, 2 years ago

scm copyright and license note update

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