VirtualBox

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

Last change on this file since 107500 was 107498, checked in by vboxsync, 2 months ago

src/VBox/Main/include/ConsoleImpl: Fixed warning found by Parfait (uninitialized attributes), sorted initializers, renaming. jiraref:VBP-1424

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 59.6 KB
Line 
1/* $Id: ConsoleImpl.h 107498 2025-01-08 12:48:08Z 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, PCFGMNODE pUsbDevices, std::list<BootNic> &llBootNics);
880#if defined(VBOX_WITH_TPM)
881 int i_configTpm(ComPtr<ITrustedPlatformModule> pTpm, TpmType_T enmTpmType, PCFGMNODE pDevices,
882 RTGCPHYS GCPhysTpmMmio, uint32_t uIrq, RTGCPHYS GCPhysTpmPpi, bool fCrb = false);
883#endif
884
885 static DECLCALLBACK(void) i_vmstateChangeCallback(PUVM pUVM, PCVMMR3VTABLE pVMM, VMSTATE enmState,
886 VMSTATE enmOldState, void *pvUser);
887 static DECLCALLBACK(int) i_unplugCpu(Console *pThis, PUVM pUVM, PCVMMR3VTABLE pVMM, VMCPUID idCpu);
888 static DECLCALLBACK(int) i_plugCpu(Console *pThis, PUVM pUVM, PCVMMR3VTABLE pVMM, VMCPUID idCpu);
889 HRESULT i_doMediumChange(IMediumAttachment *aMediumAttachment, bool fForce, PUVM pUVM, PCVMMR3VTABLE pVMM);
890 HRESULT i_doCPURemove(ULONG aCpu, PUVM pUVM, PCVMMR3VTABLE pVMM);
891 HRESULT i_doCPUAdd(ULONG aCpu, PUVM pUVM, PCVMMR3VTABLE pVMM);
892
893 HRESULT i_doNetworkAdapterChange(PUVM pUVM, PCVMMR3VTABLE pVMM, const char *pszDevice, unsigned uInstance,
894 unsigned uLun, INetworkAdapter *aNetworkAdapter);
895 static DECLCALLBACK(int) i_changeNetworkAttachment(Console *pThis, PUVM pUVM, PCVMMR3VTABLE pVMM, const char *pszDevice,
896 unsigned uInstance, unsigned uLun, INetworkAdapter *aNetworkAdapter);
897 static DECLCALLBACK(int) i_changeSerialPortAttachment(Console *pThis, PUVM pUVM, PCVMMR3VTABLE pVMM, ISerialPort *pSerialPort);
898
899 int i_changeClipboardMode(ClipboardMode_T aClipboardMode);
900 int i_changeClipboardFileTransferMode(bool aEnabled);
901 int i_changeDnDMode(DnDMode_T aDnDMode);
902
903#ifdef VBOX_WITH_USB
904 HRESULT i_attachUSBDevice(IUSBDevice *aHostDevice, ULONG aMaskedIfs, const Utf8Str &aCaptureFilename);
905 HRESULT i_detachUSBDevice(const ComObjPtr<OUSBDevice> &aHostDevice);
906
907 static DECLCALLBACK(int) i_usbAttachCallback(Console *that, PUVM pUVM, PCVMMR3VTABLE pVMM, IUSBDevice *aHostDevice,
908 PCRTUUID aUuid, const char *aBackend, const char *aAddress, PCFGMNODE pRemoteCfg,
909 USBConnectionSpeed_T *penmSpeed, ULONG *pfMaskedIfs,
910 const char *pszCaptureFilename);
911 static DECLCALLBACK(int) i_usbDetachCallback(Console *that, PUVM pUVM, PCVMMR3VTABLE pVMM, PCRTUUID aUuid);
912 static DECLCALLBACK(PREMOTEUSBCALLBACK) i_usbQueryRemoteUsbBackend(void *pvUser, PCRTUUID pUuid, uint32_t idClient);
913
914 /** Interface for the VRDP USB proxy backend to query for a device remote callback table. */
915 REMOTEUSBIF mRemoteUsbIf;
916#endif
917
918 static DECLCALLBACK(int) i_attachStorageDevice(Console *pThis,
919 PUVM pUVM,
920 PCVMMR3VTABLE pVMM,
921 const char *pcszDevice,
922 unsigned uInstance,
923 StorageBus_T enmBus,
924 bool fUseHostIOCache,
925 IMediumAttachment *aMediumAtt,
926 bool fSilent);
927 static DECLCALLBACK(int) i_detachStorageDevice(Console *pThis,
928 PUVM pUVM,
929 PCVMMR3VTABLE pVMM,
930 const char *pcszDevice,
931 unsigned uInstance,
932 StorageBus_T enmBus,
933 IMediumAttachment *aMediumAtt,
934 bool fSilent);
935 HRESULT i_doStorageDeviceAttach(IMediumAttachment *aMediumAttachment, PUVM pUVM, PCVMMR3VTABLE pVMM, bool fSilent);
936 HRESULT i_doStorageDeviceDetach(IMediumAttachment *aMediumAttachment, PUVM pUVM, PCVMMR3VTABLE pVMM, bool fSilent);
937
938 static DECLCALLBACK(int) i_stateProgressCallback(PUVM pUVM, unsigned uPercent, void *pvUser);
939
940 static DECLCALLBACK(void) i_genericVMSetErrorCallback(PUVM pUVM, void *pvUser, int vrc, RT_SRC_POS_DECL,
941 const char *pszErrorFmt, va_list va);
942
943 void i_atVMRuntimeErrorCallbackF(uint32_t fFatal, const char *pszErrorId, const char *pszFormat, ...);
944 static DECLCALLBACK(void) i_atVMRuntimeErrorCallback(PUVM pUVM, void *pvUser, uint32_t fFatal,
945 const char *pszErrorId, const char *pszFormat, va_list va);
946
947 HRESULT i_captureUSBDevices(PUVM pUVM);
948 void i_detachAllUSBDevices(bool aDone);
949
950
951 static DECLCALLBACK(int) i_vmm2User_SaveState(PCVMM2USERMETHODS pThis, PUVM pUVM);
952 static DECLCALLBACK(void) i_vmm2User_NotifyEmtInit(PCVMM2USERMETHODS pThis, PUVM pUVM, PUVMCPU pUVCpu);
953 static DECLCALLBACK(void) i_vmm2User_NotifyEmtTerm(PCVMM2USERMETHODS pThis, PUVM pUVM, PUVMCPU pUVCpu);
954 static DECLCALLBACK(void) i_vmm2User_NotifyPdmtInit(PCVMM2USERMETHODS pThis, PUVM pUVM);
955 static DECLCALLBACK(void) i_vmm2User_NotifyPdmtTerm(PCVMM2USERMETHODS pThis, PUVM pUVM);
956 static DECLCALLBACK(void) i_vmm2User_NotifyResetTurnedIntoPowerOff(PCVMM2USERMETHODS pThis, PUVM pUVM);
957 static DECLCALLBACK(void *) i_vmm2User_QueryGenericObject(PCVMM2USERMETHODS pThis, PUVM pUVM, PCRTUUID pUuid);
958
959 static DECLCALLBACK(void *) i_drvStatus_QueryInterface(PPDMIBASE pInterface, const char *pszIID);
960 static DECLCALLBACK(void) i_drvStatus_UnitChanged(PPDMILEDCONNECTORS pInterface, unsigned iLUN);
961 static DECLCALLBACK(int) i_drvStatus_MediumEjected(PPDMIMEDIANOTIFY pInterface, unsigned iLUN);
962 static DECLCALLBACK(void) i_drvStatus_Destruct(PPDMDRVINS pDrvIns);
963 static DECLCALLBACK(int) i_drvStatus_Construct(PPDMDRVINS pDrvIns, PCFGMNODE pCfg, uint32_t fFlags);
964
965 static DECLCALLBACK(int) i_pdmIfSecKey_KeyRetain(PPDMISECKEY pInterface, const char *pszId, const uint8_t **ppbKey,
966 size_t *pcbKey);
967 static DECLCALLBACK(int) i_pdmIfSecKey_KeyRelease(PPDMISECKEY pInterface, const char *pszId);
968 static DECLCALLBACK(int) i_pdmIfSecKey_PasswordRetain(PPDMISECKEY pInterface, const char *pszId, const char **ppszPassword);
969 static DECLCALLBACK(int) i_pdmIfSecKey_PasswordRelease(PPDMISECKEY pInterface, const char *pszId);
970
971 static DECLCALLBACK(int) i_pdmIfSecKeyHlp_KeyMissingNotify(PPDMISECKEYHLP pInterface);
972
973 volatile uint32_t mcVRDPClients;
974 uint32_t mu32SingleRDPClientId; /* The id of a connected client in the single connection mode. */
975 volatile bool mfGuestCredentialsProvided;
976
977 static const char *sSSMConsoleUnit;
978
979 HRESULT i_loadDataFromSavedState();
980 int i_loadStateFileExecInternal(PSSMHANDLE pSSM, PCVMMR3VTABLE pVMM, uint32_t u32Version);
981
982 static DECLCALLBACK(int) i_saveStateFileExec(PSSMHANDLE pSSM, PCVMMR3VTABLE pVMM, void *pvUser);
983 static DECLCALLBACK(int) i_loadStateFileExec(PSSMHANDLE pSSM, PCVMMR3VTABLE pVMM, void *pvUser,
984 uint32_t uVersion, uint32_t uPass);
985
986#ifdef VBOX_WITH_GUEST_PROPS
987 HRESULT i_doEnumerateGuestProperties(const Utf8Str &aPatterns,
988 std::vector<Utf8Str> &aNames,
989 std::vector<Utf8Str> &aValues,
990 std::vector<LONG64> &aTimestamps,
991 std::vector<Utf8Str> &aFlags);
992
993 void i_guestPropertiesHandleVMReset(void);
994 bool i_guestPropertiesVRDPEnabled(void);
995 void i_guestPropertiesVRDPUpdateLogon(uint32_t u32ClientId, const char *pszUser, const char *pszDomain);
996 void i_guestPropertiesVRDPUpdateActiveClient(uint32_t u32ClientId);
997 void i_guestPropertiesVRDPUpdateClientAttach(uint32_t u32ClientId, bool fAttached);
998 void i_guestPropertiesVRDPUpdateNameChange(uint32_t u32ClientId, const char *pszName);
999 void i_guestPropertiesVRDPUpdateIPAddrChange(uint32_t u32ClientId, const char *pszIPAddr);
1000 void i_guestPropertiesVRDPUpdateLocationChange(uint32_t u32ClientId, const char *pszLocation);
1001 void i_guestPropertiesVRDPUpdateOtherInfoChange(uint32_t u32ClientId, const char *pszOtherInfo);
1002 void i_guestPropertiesVRDPUpdateDisconnect(uint32_t u32ClientId);
1003#endif
1004
1005 /** @name Disk encryption support
1006 * @{ */
1007 HRESULT i_consoleParseDiskEncryption(const char *psz, const char **ppszEnd);
1008 HRESULT i_configureEncryptionForDisk(const Utf8Str &strId, unsigned *pcDisksConfigured);
1009 HRESULT i_clearDiskEncryptionKeysOnAllAttachmentsWithKeyId(const Utf8Str &strId);
1010 HRESULT i_initSecretKeyIfOnAllAttachments(void);
1011 int i_consoleParseKeyValue(const char *psz, const char **ppszEnd,
1012 char **ppszKey, char **ppszVal);
1013 void i_removeSecretKeysOnSuspend();
1014 /** @} */
1015
1016 /** @name Teleporter support
1017 * @{ */
1018 static DECLCALLBACK(int) i_teleporterSrcThreadWrapper(RTTHREAD hThreadSelf, void *pvUser);
1019 HRESULT i_teleporterSrc(TeleporterStateSrc *pState);
1020 HRESULT i_teleporterSrcReadACK(TeleporterStateSrc *pState, const char *pszWhich, const char *pszNAckMsg = NULL);
1021 HRESULT i_teleporterSrcSubmitCommand(TeleporterStateSrc *pState, const char *pszCommand, bool fWaitForAck = true);
1022 HRESULT i_teleporterTrg(PUVM pUVM, PCVMMR3VTABLE pVMM, IMachine *pMachine, Utf8Str *pErrorMsg,
1023 bool fStartPaused, Progress *pProgress, bool *pfPowerOffOnFailure);
1024 static DECLCALLBACK(int) i_teleporterTrgServeConnection(RTSOCKET Sock, void *pvUser);
1025 /** @} */
1026
1027#ifdef VBOX_WITH_FULL_VM_ENCRYPTION
1028 /** @name Encrypted log interface
1029 * @{ */
1030 static DECLCALLBACK(int) i_logEncryptedDirCtxOpen(PCRTLOGOUTPUTIF pIf, void *pvUser, const char *pszFilename, void **pvDirCtx);
1031 static DECLCALLBACK(int) i_logEncryptedDirCtxClose(PCRTLOGOUTPUTIF pIf, void *pvUser, void *pvDirCtx);
1032 static DECLCALLBACK(int) i_logEncryptedDelete(PCRTLOGOUTPUTIF pIf, void *pvUser, void *pvDirCtx, const char *pszFilename);
1033 static DECLCALLBACK(int) i_logEncryptedRename(PCRTLOGOUTPUTIF pIf, void *pvUser, void *pvDirCtx,
1034 const char *pszFilenameOld, const char *pszFilenameNew, uint32_t fFlags);
1035 static DECLCALLBACK(int) i_logEncryptedOpen(PCRTLOGOUTPUTIF pIf, void *pvUser, void *pvDirCtx, const char *pszFilename, uint32_t fFlags);
1036 static DECLCALLBACK(int) i_logEncryptedClose(PCRTLOGOUTPUTIF pIf, void *pvUser);
1037 static DECLCALLBACK(int) i_logEncryptedQuerySize(PCRTLOGOUTPUTIF pIf, void *pvUser, uint64_t *pcbSize);
1038 static DECLCALLBACK(int) i_logEncryptedWrite(PCRTLOGOUTPUTIF pIf, void *pvUser, const void *pvBuf,
1039 size_t cbWrite, size_t *pcbWritten);
1040 static DECLCALLBACK(int) i_logEncryptedFlush(PCRTLOGOUTPUTIF pIf, void *pvUser);
1041 /** The logging output interface for encrypted logs. */
1042 static RTLOGOUTPUTIF const s_ConsoleEncryptedLogOutputIf;
1043 /** @} */
1044#endif
1045
1046 bool mSavedStateDataLoaded : 1;
1047
1048 const ComPtr<IMachine> mMachine;
1049 const ComPtr<IInternalMachineControl> mControl;
1050
1051 const ComPtr<IVRDEServer> mVRDEServer;
1052
1053 ConsoleVRDPServer * const mConsoleVRDPServer;
1054 bool mfVRDEChangeInProcess;
1055 bool mfVRDEChangePending;
1056 const ComObjPtr<Guest> mGuest;
1057 const ComObjPtr<Keyboard> mKeyboard;
1058 const ComObjPtr<Mouse> mMouse;
1059 const ComObjPtr<Display> mDisplay;
1060 const ComObjPtr<MachineDebugger> mDebugger;
1061 const ComObjPtr<VRDEServerInfo> mVRDEServerInfo;
1062 /** This can safely be used without holding any locks.
1063 * An AutoCaller suffices to prevent it being destroy while in use and
1064 * internally there is a lock providing the necessary serialization. */
1065 const ComObjPtr<EventSource> mEventSource;
1066#ifdef VBOX_WITH_EXTPACK
1067 const ComObjPtr<ExtPackManager> mptrExtPackManager;
1068#endif
1069 const ComObjPtr<EmulatedUSB> mEmulatedUSB;
1070 const ComObjPtr<NvramStore> mptrNvramStore;
1071#ifdef VBOX_WITH_VIRT_ARMV8
1072 const ComObjPtr<ResourceStore> mptrResourceStore;
1073#endif
1074
1075 USBDeviceList mUSBDevices;
1076 RemoteUSBDeviceList mRemoteUSBDevices;
1077
1078 SharedFolderDataMap m_mapGlobalSharedFolders;
1079 SharedFolderDataMap m_mapMachineSharedFolders;
1080 SharedFolderMap m_mapSharedFolders; // the console instances
1081
1082 /** VMM loader handle. */
1083 RTLDRMOD mhModVMM;
1084 /** The VMM vtable. */
1085 PCVMMR3VTABLE mpVMM;
1086 /** The user mode VM handle. */
1087 PUVM mpUVM;
1088 /** Holds the number of "readonly" mpUVM callers (users). */
1089 uint32_t mVMCallers;
1090 /** Semaphore posted when the number of mpUVM callers drops to zero. */
1091 RTSEMEVENT mVMZeroCallersSem;
1092 /** true when Console has entered the mpUVM destruction phase. */
1093 bool mVMDestroying : 1;
1094 /** true when power down is initiated by vmstateChangeCallback (EMT). */
1095 bool mVMPoweredOff : 1;
1096 /** true when vmstateChangeCallback shouldn't initiate a power down. */
1097 bool mVMIsAlreadyPoweringOff : 1;
1098 /** true if we already showed the snapshot folder size warning. */
1099 bool mfSnapshotFolderSizeWarningShown : 1;
1100 /** true if we already showed the snapshot folder ext4/xfs bug warning. */
1101 bool mfSnapshotFolderExt4WarningShown : 1;
1102 /** true if we already listed the disk type of the snapshot folder. */
1103 bool mfSnapshotFolderDiskTypeShown : 1;
1104 /** true if a USB controller is available (i.e. USB devices can be attached). */
1105 bool mfVMHasUsbController : 1;
1106 /** Shadow of the VBoxInternal2/TurnResetIntoPowerOff extra data setting.
1107 * This is initialized by Console::i_configConstructorInner(). */
1108 bool mfTurnResetIntoPowerOff : 1;
1109 /** true if the VM power off was caused by reset. */
1110 bool mfPowerOffCausedByReset : 1;
1111
1112 /** Pointer to the VMM -> User (that's us) callbacks. */
1113 struct MYVMM2USERMETHODS : public VMM2USERMETHODS
1114 {
1115 Console *pConsole;
1116 /** The in-progress snapshot. */
1117 ISnapshot *pISnapshot;
1118 } *mpVmm2UserMethods;
1119
1120 /** The current network attachment type in the VM.
1121 * This doesn't have to match the network attachment type maintained in the
1122 * NetworkAdapter. This is needed to change the network attachment
1123 * dynamically.
1124 */
1125 typedef std::vector<NetworkAttachmentType_T> NetworkAttachmentTypeVector;
1126 NetworkAttachmentTypeVector meAttachmentType;
1127
1128 VMMDev * m_pVMMDev;
1129 AudioVRDE * const mAudioVRDE;
1130#ifdef VBOX_WITH_USB_CARDREADER
1131 UsbCardReader * const mUsbCardReader;
1132#endif
1133 BusAssignmentManager* mBusMgr;
1134
1135 /** @name LEDs and their management
1136 * @{ */
1137 /** Read/write lock separating LED allocations and per-type data construction
1138 * (write) from queries (read). */
1139 RWLockHandle mLedLock;
1140 /** LED configuration generation. This is increased whenever a new set is
1141 * allocated or a sub-device type changes. */
1142 uint32_t muLedGen;
1143 /** The LED configuration generation which maLedTypes was constructed for. */
1144 uint32_t muLedTypeGen;
1145 /** Number of LED sets in use in maLedSets. */
1146 uint32_t mcLedSets;
1147 /** LED sets. */
1148 struct LEDSET
1149 {
1150 /** Bitmask of possible DeviceType_T values (e.g. RT_BIT_32(DeviceType_Network)). */
1151 uint32_t fTypes;
1152 /** Number of LEDs. */
1153 uint32_t cLeds;
1154 /** Array of PDMLED pointers. The pointers in the array can be changed at any
1155 * time by Console::i_drvStatus_UnitChanged(). */
1156 PPDMLED volatile *papLeds;
1157 /** Optionally, device types for each individual LED. Runs parallel to papLeds. */
1158 DeviceType_T *paSubTypes;
1159 } maLedSets[32];
1160 /** LEDs data organized by DeviceType_T.
1161 * This is reconstructed by Console::i_refreshLedTypeArrays() when
1162 * Console::getDeviceActivity is called and mLedTypeGen doesn't match
1163 * muLedGen. */
1164 struct
1165 {
1166 /** Number of possibly valid entries in pappLeds. */
1167 uint32_t cLeds;
1168 /** Number of allocated entries. */
1169 uint32_t cAllocated;
1170 /** Array of pointer to LEDSET::papLed entries.
1171 * The indirection is due to Console::i_drvStatus_UnitChanged() only knowing
1172 * about the LEDSET::papLeds. */
1173 PPDMLED volatile **pappLeds;
1174 } maLedTypes[DeviceType_End];
1175 /** @} */
1176
1177 MediumAttachmentMap mapMediumAttachments;
1178
1179 /** List of attached USB storage devices. */
1180 USBStorageDeviceList mUSBStorageDevices;
1181
1182 /** Store for secret keys. */
1183 SecretKeyStore * const m_pKeyStore;
1184 /** Number of disks configured for encryption. */
1185 unsigned m_cDisksEncrypted;
1186 /** Number of disks which have the key in the map. */
1187 unsigned m_cDisksPwProvided;
1188
1189 /** Current active port modes of the supported serial ports. */
1190 PortMode_T m_aeSerialPortMode[4];
1191
1192 /** Pointer to the key consumer -> provider (that's us) callbacks. */
1193 struct MYPDMISECKEY : public PDMISECKEY
1194 {
1195 Console *pConsole;
1196 } *mpIfSecKey;
1197
1198 /** Pointer to the key helpers -> provider (that's us) callbacks. */
1199 struct MYPDMISECKEYHLP : public PDMISECKEYHLP
1200 {
1201 Console *pConsole;
1202 } *mpIfSecKeyHlp;
1203
1204/* Note: FreeBSD needs this whether netflt is used or not. */
1205#if ((defined(RT_OS_LINUX) && !defined(VBOX_WITH_NETFLT)) || defined(RT_OS_FREEBSD))
1206 Utf8Str maTAPDeviceName[8];
1207 RTFILE maTapFD[8];
1208#endif
1209
1210 bool mVMStateChangeCallbackDisabled;
1211
1212 bool mfUseHostClipboard;
1213
1214 /** Local machine state value. */
1215 MachineState_T mMachineState;
1216
1217 /** Machine uuid string. */
1218 Bstr mstrUuid;
1219
1220 /** @name Members related to the cryptographic support interface.
1221 * @{ */
1222 /** The loaded module handle if loaded. */
1223 RTLDRMOD mhLdrModCrypto;
1224 /** Reference counter tracking how many users of the cryptographic support
1225 * are there currently. */
1226 volatile uint32_t mcRefsCrypto;
1227 /** Pointer to the cryptographic support interface. */
1228 PCVBOXCRYPTOIF mpCryptoIf;
1229 /** @} */
1230
1231#ifdef VBOX_WITH_FULL_VM_ENCRYPTION
1232 /** Flag whether the log is encrypted. */
1233 bool m_fEncryptedLog;
1234 /** The file handle of the encrypted log. */
1235 RTVFSFILE m_hVfsFileLog;
1236 /** The log file key ID. */
1237 Utf8Str m_strLogKeyId;
1238 /** The log file key store. */
1239 Utf8Str m_strLogKeyStore;
1240#endif
1241
1242#ifdef VBOX_WITH_SHARED_CLIPBOARD
1243 /* Service extension for the Shared Clipboard HGCM service. */
1244 HGCMSVCEXTHANDLE m_hHgcmSvcExtShCl;
1245#endif
1246
1247#ifdef VBOX_WITH_DRAG_AND_DROP
1248 /* Service extension for the Drag'n Drop HGCM service. */
1249 HGCMSVCEXTHANDLE m_hHgcmSvcExtDragAndDrop;
1250#endif
1251 /** Pointer to the progress object of a live cancelable task.
1252 *
1253 * This is currently only used by Console::Teleport(), but is intended to later
1254 * be used by the live snapshot code path as well. Actions like
1255 * Console::PowerDown, which automatically cancels out the running snapshot /
1256 * teleportation operation, will cancel the teleportation / live snapshot
1257 * operation before starting. */
1258 ComPtr<IProgress> mptrCancelableProgress;
1259
1260 ComPtr<IEventListener> mVmListener;
1261
1262#ifdef VBOX_WITH_RECORDING
1263 /** Structure for keeping recording-related stuff. */
1264 struct Recording
1265 {
1266 Recording()
1267# ifdef VBOX_WITH_AUDIO_RECORDING
1268 : mAudioRec(NULL)
1269# endif
1270 { }
1271
1272 /** The recording progress object to use. */
1273 ComObjPtr<IProgress> mProgress;
1274 /** The recording context. */
1275 RecordingContext mCtx;
1276# ifdef VBOX_WITH_AUDIO_RECORDING
1277 /** Pointer to capturing audio backend. */
1278 AudioVideoRec * const mAudioRec;
1279# endif
1280 } mRecording;
1281#endif /* VBOX_WITH_RECORDING */
1282
1283#ifdef VBOX_WITH_CLOUD_NET
1284 GatewayInfo mGateway;
1285#endif /* VBOX_WITH_CLOUD_NET */
1286
1287 friend class VMTask;
1288 friend class ConsoleVRDPServer;
1289};
1290
1291
1292class ConfigError : public RTCError
1293{
1294public:
1295
1296 ConfigError(const char *pcszFunction,
1297 int vrc,
1298 const char *pcszName)
1299 : RTCError(Utf8StrFmt(Console::tr("%s failed: vrc=%Rrc, pcszName=%s"), pcszFunction, vrc, pcszName)),
1300 m_vrc(vrc)
1301 {
1302 AssertMsgFailed(("%s\n", what())); // in strict mode, hit a breakpoint here
1303 }
1304
1305 int m_vrc;
1306};
1307
1308DECL_HIDDEN_THROW(Utf8Str *) GetExtraDataBoth(IVirtualBox *pVirtualBox, IMachine *pMachine, const char *pszName, Utf8Str *pStrValue);
1309
1310#ifndef VBOX_WITH_EFI_IN_DD2
1311DECLHIDDEN(int) findEfiRom(IVirtualBox* vbox, PlatformArchitecture_T aPlatformArchitecture, FirmwareType_T aFirmwareType, Utf8Str *pEfiRomFile);
1312#endif
1313
1314#endif /* !MAIN_INCLUDED_ConsoleImpl_h */
1315/* vi: set tabstop=4 shiftwidth=4 expandtab: */
Note: See TracBrowser for help on using the repository browser.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette