VirtualBox

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

Last change on this file since 105163 was 105095, checked in by vboxsync, 10 months ago

Video Recording/Main: More optimizations for recording older guests which have a slightly different screen update logic. bugref:10650

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