VirtualBox

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

Last change on this file since 107188 was 106960, checked in by vboxsync, 3 months ago

Main: Unify the TPM instantiation as much as possible between x86 and armv8 platforms, bugref:10732

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

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