VirtualBox

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

Last change on this file since 106901 was 106061, checked in by vboxsync, 3 months ago

Copyright year updates by scm.

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