VirtualBox

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

Last change on this file since 105352 was 105352, checked in by vboxsync, 7 months ago

VMM/VMR3Req,iprt/cdefs.h: Adjustments of VMR3ReqCallUV family to fit darwin/arm64 restrictions. bugref:10725

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 59.2 KB
Line 
1/* $Id: ConsoleImpl.h 105352 2024-07-16 11:21:19Z 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(ComPtr<IProgress> &pProgress);
201 void i_recordingDestroy(void);
202 int i_recordingEnable(BOOL fEnable, util::AutoWriteLock *pAutoLock, ComPtr<IProgress> &pProgress);
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# ifdef VBOX_WITH_AUDIO_RECORDING
208 AudioVideoRec *i_recordingGetAudioDrv(void) const { return mRecording.mAudioRec; }
209# endif
210 RecordingContext *i_recordingGetContext(void) { return &mRecording.mCtx; }
211# ifdef VBOX_WITH_AUDIO_RECORDING
212 HRESULT i_recordingSendAudio(const void *pvData, size_t cbData, uint64_t uDurationMs);
213# endif
214#endif
215
216 const ComPtr<IMachine> &i_machine() const { return mMachine; }
217 const Bstr &i_getId() const { return mstrUuid; }
218
219 bool i_useHostClipboard() { return mfUseHostClipboard; }
220
221 /** Method is called only from ConsoleVRDPServer */
222 IVRDEServer *i_getVRDEServer() const { return mVRDEServer; }
223
224 ConsoleVRDPServer *i_consoleVRDPServer() const { return mConsoleVRDPServer; }
225
226 HRESULT i_updateMachineState(MachineState_T aMachineState);
227 HRESULT i_getNominalState(MachineState_T &aNominalState);
228 Utf8Str i_getAudioAdapterDeviceName(IAudioAdapter *aAudioAdapter);
229
230 // events from IInternalSessionControl
231 HRESULT i_onNetworkAdapterChange(INetworkAdapter *aNetworkAdapter, BOOL changeAdapter);
232 HRESULT i_onAudioAdapterChange(IAudioAdapter *aAudioAdapter);
233 HRESULT i_onHostAudioDeviceChange(IHostAudioDevice *aDevice, BOOL aNew, AudioDeviceState_T aState,
234 IVirtualBoxErrorInfo *aErrInfo);
235 HRESULT i_onSerialPortChange(ISerialPort *aSerialPort);
236 HRESULT i_onParallelPortChange(IParallelPort *aParallelPort);
237 HRESULT i_onStorageControllerChange(const com::Guid& aMachineId, const com::Utf8Str& aControllerName);
238 HRESULT i_onMediumChange(IMediumAttachment *aMediumAttachment, BOOL aForce);
239 HRESULT i_onCPUChange(ULONG aCPU, BOOL aRemove);
240 HRESULT i_onCPUExecutionCapChange(ULONG aExecutionCap);
241 HRESULT i_onClipboardError(const Utf8Str &aId, const Utf8Str &aErrMsg, LONG aRc);
242 HRESULT i_onClipboardModeChange(ClipboardMode_T aClipboardMode);
243 HRESULT i_onClipboardFileTransferModeChange(bool aEnabled);
244 HRESULT i_onDnDModeChange(DnDMode_T aDnDMode);
245 HRESULT i_onVRDEServerChange(BOOL aRestart);
246 HRESULT i_onRecordingStateChange(BOOL aEnable, ComPtr<IProgress> &aProgress);
247 HRESULT i_onRecordingScreenStateChange(BOOL aEnable, ULONG aScreen);
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 /** i_reconfigureMediumAttachment has too many problematic arguments for
815 * passing directly to VMR3ReqCallUV, so we pack them up. @bugref{10725} */
816 struct ReconfigureMediumAttachmentArgs
817 {
818 const char *pcszDevice; /**< The name of the controller type. */
819 unsigned uInstance; /**< The instance of the controller. */
820 StorageBus_T enmBus; /**< The storage bus type of the controller. */
821 bool fUseHostIOCache; /**< Use the host I/O cache (disable async I/O). */
822 bool fBuiltinIOCache; /**< Use the builtin I/O cache. */
823 bool fInsertDiskIntegrityDrv; /**< Flag whether to insert the disk integrity driver into the chain for additionalk debugging aids. */
824 bool fSetupMerge; /**< Whether to set up a medium merge */
825 unsigned uMergeSource; /**< Merge source image index */
826 unsigned uMergeTarget; /**< Merge target image index */
827 IMediumAttachment *aMediumAtt; /**< The medium attachment. */
828 MachineState_T aMachineState; /**< The current machine state. */
829 };
830 static DECLCALLBACK(int) i_reconfigureMediumAttachment(Console *pThis,
831 PUVM pUVM,
832 PCVMMR3VTABLE pVMM,
833 ReconfigureMediumAttachmentArgs const *pArgs,
834 HRESULT *phrc);
835 static DECLCALLBACK(int) i_changeRemovableMedium(Console *pThis,
836 PUVM pUVM,
837 PCVMMR3VTABLE pVMM,
838 const char *pcszDevice,
839 unsigned uInstance,
840 StorageBus_T enmBus,
841 bool fUseHostIOCache,
842 IMediumAttachment *aMediumAtt,
843 bool fForce);
844
845 HRESULT i_attachRawPCIDevices(PUVM pUVM, BusAssignmentManager *BusMgr, PCFGMNODE pDevices);
846 struct LEDSET;
847 typedef struct LEDSET *PLEDSET;
848 PPDMLED volatile *i_getLedSet(uint32_t iLedSet);
849 void i_setLedType(DeviceType_T *penmSubTypeEntry, DeviceType_T enmNewType);
850 HRESULT i_refreshLedTypeArrays(AutoReadLock *pReadLock);
851 uint32_t i_allocateDriverLeds(uint32_t cLeds, uint32_t fTypes, DeviceType_T **ppSubTypes);
852 void i_attachStatusDriver(PCFGMNODE pCtlInst, DeviceType_T enmType, uint32_t cLeds = 1);
853 void i_attachStatusDriver(PCFGMNODE pCtlInst, uint32_t fTypes, uint32_t cLeds, DeviceType_T **ppaSubTypes,
854 Console::MediumAttachmentMap *pmapMediumAttachments,
855 const char *pcszDevice, unsigned uInstance);
856
857 int i_configNetwork(const char *pszDevice, unsigned uInstance, unsigned uLun, INetworkAdapter *aNetworkAdapter,
858 PCFGMNODE pCfg, PCFGMNODE pLunL0, PCFGMNODE pInst, bool fAttachDetach, bool fIgnoreConnectFailure,
859 PUVM pUVM, PCVMMR3VTABLE pVMM);
860 int i_configProxy(ComPtr<IVirtualBox> virtualBox, PCFGMNODE pCfg, const char *pcszPrefix, const com::Utf8Str &strIpAddr);
861
862 int i_configSerialPort(PCFGMNODE pInst, PortMode_T ePortMode, const char *pszPath, bool fServer);
863
864 int i_configAudioCtrl(ComPtr<IVirtualBox> pVBox, ComPtr<IMachine> pMachine, BusAssignmentManager *pBusMgr, PCFGMNODE pDevices,
865 bool fOsXGuest, bool *pfAudioEnabled);
866 int i_configVmmDev(ComPtr<IMachine> pMachine, BusAssignmentManager *pBusMgr, PCFGMNODE pDevices, bool fMmioReq = false);
867 int i_configPdm(ComPtr<IMachine> pMachine, PCVMMR3VTABLE pVMM, PUVM pUVM, PCFGMNODE pRoot);
868 int i_configUsb(ComPtr<IMachine> pMachine, BusAssignmentManager *pBusMgr, PCFGMNODE pRoot, PCFGMNODE pDevices,
869 KeyboardHIDType_T enmKbdHid, PointingHIDType_T enmPointingHid, PCFGMNODE *ppUsbDevices);
870 int i_configGuestDbg(ComPtr<IVirtualBox> pVBox, ComPtr<IMachine> pMachine, PCFGMNODE pRoot);
871 int i_configStorageCtrls(ComPtr<IMachine> pMachine, BusAssignmentManager *pBusMgr, PCVMMR3VTABLE pVMM, PUVM pUVM,
872 PCFGMNODE pDevices, PCFGMNODE pUsbDevices, PCFGMNODE pBiosCfg, bool *pfFdcEnabled);
873 int i_configNetworkCtrls(ComPtr<IMachine> pMachine, ComPtr<IPlatformProperties> pPlatformProperties,
874 ChipsetType_T enmChipset, BusAssignmentManager *pBusMgr, PCVMMR3VTABLE pVMM, PUVM pUVM,
875 PCFGMNODE pDevices, std::list<BootNic> &llBootNics);
876
877 static DECLCALLBACK(void) i_vmstateChangeCallback(PUVM pUVM, PCVMMR3VTABLE pVMM, VMSTATE enmState,
878 VMSTATE enmOldState, void *pvUser);
879 static DECLCALLBACK(int) i_unplugCpu(Console *pThis, PUVM pUVM, PCVMMR3VTABLE pVMM, VMCPUID idCpu);
880 static DECLCALLBACK(int) i_plugCpu(Console *pThis, PUVM pUVM, PCVMMR3VTABLE pVMM, VMCPUID idCpu);
881 HRESULT i_doMediumChange(IMediumAttachment *aMediumAttachment, bool fForce, PUVM pUVM, PCVMMR3VTABLE pVMM);
882 HRESULT i_doCPURemove(ULONG aCpu, PUVM pUVM, PCVMMR3VTABLE pVMM);
883 HRESULT i_doCPUAdd(ULONG aCpu, PUVM pUVM, PCVMMR3VTABLE pVMM);
884
885 HRESULT i_doNetworkAdapterChange(PUVM pUVM, PCVMMR3VTABLE pVMM, const char *pszDevice, unsigned uInstance,
886 unsigned uLun, INetworkAdapter *aNetworkAdapter);
887 static DECLCALLBACK(int) i_changeNetworkAttachment(Console *pThis, PUVM pUVM, PCVMMR3VTABLE pVMM, const char *pszDevice,
888 unsigned uInstance, unsigned uLun, INetworkAdapter *aNetworkAdapter);
889 static DECLCALLBACK(int) i_changeSerialPortAttachment(Console *pThis, PUVM pUVM, PCVMMR3VTABLE pVMM, ISerialPort *pSerialPort);
890
891 int i_changeClipboardMode(ClipboardMode_T aClipboardMode);
892 int i_changeClipboardFileTransferMode(bool aEnabled);
893 int i_changeDnDMode(DnDMode_T aDnDMode);
894
895#ifdef VBOX_WITH_USB
896 HRESULT i_attachUSBDevice(IUSBDevice *aHostDevice, ULONG aMaskedIfs, const Utf8Str &aCaptureFilename);
897 HRESULT i_detachUSBDevice(const ComObjPtr<OUSBDevice> &aHostDevice);
898
899 static DECLCALLBACK(int) i_usbAttachCallback(Console *that, PUVM pUVM, PCVMMR3VTABLE pVMM, IUSBDevice *aHostDevice,
900 PCRTUUID aUuid, const char *aBackend, const char *aAddress, PCFGMNODE pRemoteCfg,
901 USBConnectionSpeed_T *penmSpeed, ULONG *pfMaskedIfs,
902 const char *pszCaptureFilename);
903 static DECLCALLBACK(int) i_usbDetachCallback(Console *that, PUVM pUVM, PCVMMR3VTABLE pVMM, PCRTUUID aUuid);
904 static DECLCALLBACK(PREMOTEUSBCALLBACK) i_usbQueryRemoteUsbBackend(void *pvUser, PCRTUUID pUuid, uint32_t idClient);
905
906 /** Interface for the VRDP USB proxy backend to query for a device remote callback table. */
907 REMOTEUSBIF mRemoteUsbIf;
908#endif
909
910 static DECLCALLBACK(int) i_attachStorageDevice(Console *pThis,
911 PUVM pUVM,
912 PCVMMR3VTABLE pVMM,
913 const char *pcszDevice,
914 unsigned uInstance,
915 StorageBus_T enmBus,
916 bool fUseHostIOCache,
917 IMediumAttachment *aMediumAtt,
918 bool fSilent);
919 static DECLCALLBACK(int) i_detachStorageDevice(Console *pThis,
920 PUVM pUVM,
921 PCVMMR3VTABLE pVMM,
922 const char *pcszDevice,
923 unsigned uInstance,
924 StorageBus_T enmBus,
925 IMediumAttachment *aMediumAtt,
926 bool fSilent);
927 HRESULT i_doStorageDeviceAttach(IMediumAttachment *aMediumAttachment, PUVM pUVM, PCVMMR3VTABLE pVMM, bool fSilent);
928 HRESULT i_doStorageDeviceDetach(IMediumAttachment *aMediumAttachment, PUVM pUVM, PCVMMR3VTABLE pVMM, bool fSilent);
929
930 static DECLCALLBACK(int) i_stateProgressCallback(PUVM pUVM, unsigned uPercent, void *pvUser);
931
932 static DECLCALLBACK(void) i_genericVMSetErrorCallback(PUVM pUVM, void *pvUser, int vrc, RT_SRC_POS_DECL,
933 const char *pszErrorFmt, va_list va);
934
935 void i_atVMRuntimeErrorCallbackF(uint32_t fFatal, const char *pszErrorId, const char *pszFormat, ...);
936 static DECLCALLBACK(void) i_atVMRuntimeErrorCallback(PUVM pUVM, void *pvUser, uint32_t fFatal,
937 const char *pszErrorId, const char *pszFormat, va_list va);
938
939 HRESULT i_captureUSBDevices(PUVM pUVM);
940 void i_detachAllUSBDevices(bool aDone);
941
942
943 static DECLCALLBACK(int) i_vmm2User_SaveState(PCVMM2USERMETHODS pThis, PUVM pUVM);
944 static DECLCALLBACK(void) i_vmm2User_NotifyEmtInit(PCVMM2USERMETHODS pThis, PUVM pUVM, PUVMCPU pUVCpu);
945 static DECLCALLBACK(void) i_vmm2User_NotifyEmtTerm(PCVMM2USERMETHODS pThis, PUVM pUVM, PUVMCPU pUVCpu);
946 static DECLCALLBACK(void) i_vmm2User_NotifyPdmtInit(PCVMM2USERMETHODS pThis, PUVM pUVM);
947 static DECLCALLBACK(void) i_vmm2User_NotifyPdmtTerm(PCVMM2USERMETHODS pThis, PUVM pUVM);
948 static DECLCALLBACK(void) i_vmm2User_NotifyResetTurnedIntoPowerOff(PCVMM2USERMETHODS pThis, PUVM pUVM);
949 static DECLCALLBACK(void *) i_vmm2User_QueryGenericObject(PCVMM2USERMETHODS pThis, PUVM pUVM, PCRTUUID pUuid);
950
951 static DECLCALLBACK(void *) i_drvStatus_QueryInterface(PPDMIBASE pInterface, const char *pszIID);
952 static DECLCALLBACK(void) i_drvStatus_UnitChanged(PPDMILEDCONNECTORS pInterface, unsigned iLUN);
953 static DECLCALLBACK(int) i_drvStatus_MediumEjected(PPDMIMEDIANOTIFY pInterface, unsigned iLUN);
954 static DECLCALLBACK(void) i_drvStatus_Destruct(PPDMDRVINS pDrvIns);
955 static DECLCALLBACK(int) i_drvStatus_Construct(PPDMDRVINS pDrvIns, PCFGMNODE pCfg, uint32_t fFlags);
956
957 static DECLCALLBACK(int) i_pdmIfSecKey_KeyRetain(PPDMISECKEY pInterface, const char *pszId, const uint8_t **ppbKey,
958 size_t *pcbKey);
959 static DECLCALLBACK(int) i_pdmIfSecKey_KeyRelease(PPDMISECKEY pInterface, const char *pszId);
960 static DECLCALLBACK(int) i_pdmIfSecKey_PasswordRetain(PPDMISECKEY pInterface, const char *pszId, const char **ppszPassword);
961 static DECLCALLBACK(int) i_pdmIfSecKey_PasswordRelease(PPDMISECKEY pInterface, const char *pszId);
962
963 static DECLCALLBACK(int) i_pdmIfSecKeyHlp_KeyMissingNotify(PPDMISECKEYHLP pInterface);
964
965 int mcAudioRefs;
966 volatile uint32_t mcVRDPClients;
967 uint32_t mu32SingleRDPClientId; /* The id of a connected client in the single connection mode. */
968 volatile bool mcGuestCredentialsProvided;
969
970 static const char *sSSMConsoleUnit;
971
972 HRESULT i_loadDataFromSavedState();
973 int i_loadStateFileExecInternal(PSSMHANDLE pSSM, PCVMMR3VTABLE pVMM, uint32_t u32Version);
974
975 static DECLCALLBACK(int) i_saveStateFileExec(PSSMHANDLE pSSM, PCVMMR3VTABLE pVMM, void *pvUser);
976 static DECLCALLBACK(int) i_loadStateFileExec(PSSMHANDLE pSSM, PCVMMR3VTABLE pVMM, void *pvUser,
977 uint32_t uVersion, uint32_t uPass);
978
979#ifdef VBOX_WITH_GUEST_PROPS
980 HRESULT i_doEnumerateGuestProperties(const Utf8Str &aPatterns,
981 std::vector<Utf8Str> &aNames,
982 std::vector<Utf8Str> &aValues,
983 std::vector<LONG64> &aTimestamps,
984 std::vector<Utf8Str> &aFlags);
985
986 void i_guestPropertiesHandleVMReset(void);
987 bool i_guestPropertiesVRDPEnabled(void);
988 void i_guestPropertiesVRDPUpdateLogon(uint32_t u32ClientId, const char *pszUser, const char *pszDomain);
989 void i_guestPropertiesVRDPUpdateActiveClient(uint32_t u32ClientId);
990 void i_guestPropertiesVRDPUpdateClientAttach(uint32_t u32ClientId, bool fAttached);
991 void i_guestPropertiesVRDPUpdateNameChange(uint32_t u32ClientId, const char *pszName);
992 void i_guestPropertiesVRDPUpdateIPAddrChange(uint32_t u32ClientId, const char *pszIPAddr);
993 void i_guestPropertiesVRDPUpdateLocationChange(uint32_t u32ClientId, const char *pszLocation);
994 void i_guestPropertiesVRDPUpdateOtherInfoChange(uint32_t u32ClientId, const char *pszOtherInfo);
995 void i_guestPropertiesVRDPUpdateDisconnect(uint32_t u32ClientId);
996#endif
997
998 /** @name Disk encryption support
999 * @{ */
1000 HRESULT i_consoleParseDiskEncryption(const char *psz, const char **ppszEnd);
1001 HRESULT i_configureEncryptionForDisk(const Utf8Str &strId, unsigned *pcDisksConfigured);
1002 HRESULT i_clearDiskEncryptionKeysOnAllAttachmentsWithKeyId(const Utf8Str &strId);
1003 HRESULT i_initSecretKeyIfOnAllAttachments(void);
1004 int i_consoleParseKeyValue(const char *psz, const char **ppszEnd,
1005 char **ppszKey, char **ppszVal);
1006 void i_removeSecretKeysOnSuspend();
1007 /** @} */
1008
1009 /** @name Teleporter support
1010 * @{ */
1011 static DECLCALLBACK(int) i_teleporterSrcThreadWrapper(RTTHREAD hThreadSelf, void *pvUser);
1012 HRESULT i_teleporterSrc(TeleporterStateSrc *pState);
1013 HRESULT i_teleporterSrcReadACK(TeleporterStateSrc *pState, const char *pszWhich, const char *pszNAckMsg = NULL);
1014 HRESULT i_teleporterSrcSubmitCommand(TeleporterStateSrc *pState, const char *pszCommand, bool fWaitForAck = true);
1015 HRESULT i_teleporterTrg(PUVM pUVM, PCVMMR3VTABLE pVMM, IMachine *pMachine, Utf8Str *pErrorMsg,
1016 bool fStartPaused, Progress *pProgress, bool *pfPowerOffOnFailure);
1017 static DECLCALLBACK(int) i_teleporterTrgServeConnection(RTSOCKET Sock, void *pvUser);
1018 /** @} */
1019
1020#ifdef VBOX_WITH_FULL_VM_ENCRYPTION
1021 /** @name Encrypted log interface
1022 * @{ */
1023 static DECLCALLBACK(int) i_logEncryptedDirCtxOpen(PCRTLOGOUTPUTIF pIf, void *pvUser, const char *pszFilename, void **pvDirCtx);
1024 static DECLCALLBACK(int) i_logEncryptedDirCtxClose(PCRTLOGOUTPUTIF pIf, void *pvUser, void *pvDirCtx);
1025 static DECLCALLBACK(int) i_logEncryptedDelete(PCRTLOGOUTPUTIF pIf, void *pvUser, void *pvDirCtx, const char *pszFilename);
1026 static DECLCALLBACK(int) i_logEncryptedRename(PCRTLOGOUTPUTIF pIf, void *pvUser, void *pvDirCtx,
1027 const char *pszFilenameOld, const char *pszFilenameNew, uint32_t fFlags);
1028 static DECLCALLBACK(int) i_logEncryptedOpen(PCRTLOGOUTPUTIF pIf, void *pvUser, void *pvDirCtx, const char *pszFilename, uint32_t fFlags);
1029 static DECLCALLBACK(int) i_logEncryptedClose(PCRTLOGOUTPUTIF pIf, void *pvUser);
1030 static DECLCALLBACK(int) i_logEncryptedQuerySize(PCRTLOGOUTPUTIF pIf, void *pvUser, uint64_t *pcbSize);
1031 static DECLCALLBACK(int) i_logEncryptedWrite(PCRTLOGOUTPUTIF pIf, void *pvUser, const void *pvBuf,
1032 size_t cbWrite, size_t *pcbWritten);
1033 static DECLCALLBACK(int) i_logEncryptedFlush(PCRTLOGOUTPUTIF pIf, void *pvUser);
1034 /** The logging output interface for encrypted logs. */
1035 static RTLOGOUTPUTIF const s_ConsoleEncryptedLogOutputIf;
1036 /** @} */
1037#endif
1038
1039 bool mSavedStateDataLoaded : 1;
1040
1041 const ComPtr<IMachine> mMachine;
1042 const ComPtr<IInternalMachineControl> mControl;
1043
1044 const ComPtr<IVRDEServer> mVRDEServer;
1045
1046 ConsoleVRDPServer * const mConsoleVRDPServer;
1047 bool mfVRDEChangeInProcess;
1048 bool mfVRDEChangePending;
1049 const ComObjPtr<Guest> mGuest;
1050 const ComObjPtr<Keyboard> mKeyboard;
1051 const ComObjPtr<Mouse> mMouse;
1052 const ComObjPtr<Display> mDisplay;
1053 const ComObjPtr<MachineDebugger> mDebugger;
1054 const ComObjPtr<VRDEServerInfo> mVRDEServerInfo;
1055 /** This can safely be used without holding any locks.
1056 * An AutoCaller suffices to prevent it being destroy while in use and
1057 * internally there is a lock providing the necessary serialization. */
1058 const ComObjPtr<EventSource> mEventSource;
1059#ifdef VBOX_WITH_EXTPACK
1060 const ComObjPtr<ExtPackManager> mptrExtPackManager;
1061#endif
1062 const ComObjPtr<EmulatedUSB> mEmulatedUSB;
1063 const ComObjPtr<NvramStore> mptrNvramStore;
1064#ifdef VBOX_WITH_VIRT_ARMV8
1065 const ComObjPtr<ResourceStore> mptrResourceStore;
1066#endif
1067
1068 USBDeviceList mUSBDevices;
1069 RemoteUSBDeviceList mRemoteUSBDevices;
1070
1071 SharedFolderDataMap m_mapGlobalSharedFolders;
1072 SharedFolderDataMap m_mapMachineSharedFolders;
1073 SharedFolderMap m_mapSharedFolders; // the console instances
1074
1075 /** VMM loader handle. */
1076 RTLDRMOD mhModVMM;
1077 /** The VMM vtable. */
1078 PCVMMR3VTABLE mpVMM;
1079 /** The user mode VM handle. */
1080 PUVM mpUVM;
1081 /** Holds the number of "readonly" mpUVM callers (users). */
1082 uint32_t mVMCallers;
1083 /** Semaphore posted when the number of mpUVM callers drops to zero. */
1084 RTSEMEVENT mVMZeroCallersSem;
1085 /** true when Console has entered the mpUVM destruction phase. */
1086 bool mVMDestroying : 1;
1087 /** true when power down is initiated by vmstateChangeCallback (EMT). */
1088 bool mVMPoweredOff : 1;
1089 /** true when vmstateChangeCallback shouldn't initiate a power down. */
1090 bool mVMIsAlreadyPoweringOff : 1;
1091 /** true if we already showed the snapshot folder size warning. */
1092 bool mfSnapshotFolderSizeWarningShown : 1;
1093 /** true if we already showed the snapshot folder ext4/xfs bug warning. */
1094 bool mfSnapshotFolderExt4WarningShown : 1;
1095 /** true if we already listed the disk type of the snapshot folder. */
1096 bool mfSnapshotFolderDiskTypeShown : 1;
1097 /** true if a USB controller is available (i.e. USB devices can be attached). */
1098 bool mfVMHasUsbController : 1;
1099 /** Shadow of the VBoxInternal2/TurnResetIntoPowerOff extra data setting.
1100 * This is initialized by Console::i_configConstructorInner(). */
1101 bool mfTurnResetIntoPowerOff : 1;
1102 /** true if the VM power off was caused by reset. */
1103 bool mfPowerOffCausedByReset : 1;
1104
1105 /** Pointer to the VMM -> User (that's us) callbacks. */
1106 struct MYVMM2USERMETHODS : public VMM2USERMETHODS
1107 {
1108 Console *pConsole;
1109 /** The in-progress snapshot. */
1110 ISnapshot *pISnapshot;
1111 } *mpVmm2UserMethods;
1112
1113 /** The current network attachment type in the VM.
1114 * This doesn't have to match the network attachment type maintained in the
1115 * NetworkAdapter. This is needed to change the network attachment
1116 * dynamically.
1117 */
1118 typedef std::vector<NetworkAttachmentType_T> NetworkAttachmentTypeVector;
1119 NetworkAttachmentTypeVector meAttachmentType;
1120
1121 VMMDev * m_pVMMDev;
1122 AudioVRDE * const mAudioVRDE;
1123#ifdef VBOX_WITH_USB_CARDREADER
1124 UsbCardReader * const mUsbCardReader;
1125#endif
1126 BusAssignmentManager* mBusMgr;
1127
1128 /** @name LEDs and their management
1129 * @{ */
1130 /** Read/write lock separating LED allocations and per-type data construction
1131 * (write) from queries (read). */
1132 RWLockHandle mLedLock;
1133 /** LED configuration generation. This is increased whenever a new set is
1134 * allocated or a sub-device type changes. */
1135 uint32_t muLedGen;
1136 /** The LED configuration generation which maLedTypes was constructed for. */
1137 uint32_t muLedTypeGen;
1138 /** Number of LED sets in use in maLedSets. */
1139 uint32_t mcLedSets;
1140 /** LED sets. */
1141 struct LEDSET
1142 {
1143 /** Bitmask of possible DeviceType_T values (e.g. RT_BIT_32(DeviceType_Network)). */
1144 uint32_t fTypes;
1145 /** Number of LEDs. */
1146 uint32_t cLeds;
1147 /** Array of PDMLED pointers. The pointers in the array can be changed at any
1148 * time by Console::i_drvStatus_UnitChanged(). */
1149 PPDMLED volatile *papLeds;
1150 /** Optionally, device types for each individual LED. Runs parallel to papLeds. */
1151 DeviceType_T *paSubTypes;
1152 } maLedSets[32];
1153 /** LEDs data organized by DeviceType_T.
1154 * This is reconstructed by Console::i_refreshLedTypeArrays() when
1155 * Console::getDeviceActivity is called and mLedTypeGen doesn't match
1156 * muLedGen. */
1157 struct
1158 {
1159 /** Number of possibly valid entries in pappLeds. */
1160 uint32_t cLeds;
1161 /** Number of allocated entries. */
1162 uint32_t cAllocated;
1163 /** Array of pointer to LEDSET::papLed entries.
1164 * The indirection is due to Console::i_drvStatus_UnitChanged() only knowing
1165 * about the LEDSET::papLeds. */
1166 PPDMLED volatile **pappLeds;
1167 } maLedTypes[DeviceType_End];
1168 /** @} */
1169
1170 MediumAttachmentMap mapMediumAttachments;
1171
1172 /** List of attached USB storage devices. */
1173 USBStorageDeviceList mUSBStorageDevices;
1174
1175 /** Store for secret keys. */
1176 SecretKeyStore * const m_pKeyStore;
1177 /** Number of disks configured for encryption. */
1178 unsigned m_cDisksEncrypted;
1179 /** Number of disks which have the key in the map. */
1180 unsigned m_cDisksPwProvided;
1181
1182 /** Current active port modes of the supported serial ports. */
1183 PortMode_T m_aeSerialPortMode[4];
1184
1185 /** Pointer to the key consumer -> provider (that's us) callbacks. */
1186 struct MYPDMISECKEY : public PDMISECKEY
1187 {
1188 Console *pConsole;
1189 } *mpIfSecKey;
1190
1191 /** Pointer to the key helpers -> provider (that's us) callbacks. */
1192 struct MYPDMISECKEYHLP : public PDMISECKEYHLP
1193 {
1194 Console *pConsole;
1195 } *mpIfSecKeyHlp;
1196
1197/* Note: FreeBSD needs this whether netflt is used or not. */
1198#if ((defined(RT_OS_LINUX) && !defined(VBOX_WITH_NETFLT)) || defined(RT_OS_FREEBSD))
1199 Utf8Str maTAPDeviceName[8];
1200 RTFILE maTapFD[8];
1201#endif
1202
1203 bool mVMStateChangeCallbackDisabled;
1204
1205 bool mfUseHostClipboard;
1206
1207 /** Local machine state value. */
1208 MachineState_T mMachineState;
1209
1210 /** Machine uuid string. */
1211 Bstr mstrUuid;
1212
1213 /** @name Members related to the cryptographic support interface.
1214 * @{ */
1215 /** The loaded module handle if loaded. */
1216 RTLDRMOD mhLdrModCrypto;
1217 /** Reference counter tracking how many users of the cryptographic support
1218 * are there currently. */
1219 volatile uint32_t mcRefsCrypto;
1220 /** Pointer to the cryptographic support interface. */
1221 PCVBOXCRYPTOIF mpCryptoIf;
1222 /** @} */
1223
1224#ifdef VBOX_WITH_FULL_VM_ENCRYPTION
1225 /** Flag whether the log is encrypted. */
1226 bool m_fEncryptedLog;
1227 /** The file handle of the encrypted log. */
1228 RTVFSFILE m_hVfsFileLog;
1229 /** The log file key ID. */
1230 Utf8Str m_strLogKeyId;
1231 /** The log file key store. */
1232 Utf8Str m_strLogKeyStore;
1233#endif
1234
1235#ifdef VBOX_WITH_SHARED_CLIPBOARD
1236 /* Service extension for the Shared Clipboard HGCM service. */
1237 HGCMSVCEXTHANDLE m_hHgcmSvcExtShCl;
1238#endif
1239
1240#ifdef VBOX_WITH_DRAG_AND_DROP
1241 /* Service extension for the Drag'n Drop HGCM service. */
1242 HGCMSVCEXTHANDLE m_hHgcmSvcExtDragAndDrop;
1243#endif
1244 /** Pointer to the progress object of a live cancelable task.
1245 *
1246 * This is currently only used by Console::Teleport(), but is intended to later
1247 * be used by the live snapshot code path as well. Actions like
1248 * Console::PowerDown, which automatically cancels out the running snapshot /
1249 * teleportation operation, will cancel the teleportation / live snapshot
1250 * operation before starting. */
1251 ComPtr<IProgress> mptrCancelableProgress;
1252
1253 ComPtr<IEventListener> mVmListener;
1254
1255#ifdef VBOX_WITH_RECORDING
1256 /** Structure for keeping recording-related stuff. */
1257 struct Recording
1258 {
1259 Recording()
1260# ifdef VBOX_WITH_AUDIO_RECORDING
1261 : mAudioRec(NULL)
1262# endif
1263 { }
1264
1265 /** The recording progress object to use. */
1266 ComObjPtr<IProgress> mProgress;
1267 /** The recording context. */
1268 RecordingContext mCtx;
1269# ifdef VBOX_WITH_AUDIO_RECORDING
1270 /** Pointer to capturing audio backend. */
1271 AudioVideoRec * const mAudioRec;
1272# endif
1273 } mRecording;
1274#endif /* VBOX_WITH_RECORDING */
1275
1276#ifdef VBOX_WITH_CLOUD_NET
1277 GatewayInfo mGateway;
1278#endif /* VBOX_WITH_CLOUD_NET */
1279
1280 friend class VMTask;
1281 friend class ConsoleVRDPServer;
1282};
1283
1284
1285class ConfigError : public RTCError
1286{
1287public:
1288
1289 ConfigError(const char *pcszFunction,
1290 int vrc,
1291 const char *pcszName)
1292 : RTCError(Utf8StrFmt(Console::tr("%s failed: vrc=%Rrc, pcszName=%s"), pcszFunction, vrc, pcszName)),
1293 m_vrc(vrc)
1294 {
1295 AssertMsgFailed(("%s\n", what())); // in strict mode, hit a breakpoint here
1296 }
1297
1298 int m_vrc;
1299};
1300
1301DECL_HIDDEN_THROW(Utf8Str *) GetExtraDataBoth(IVirtualBox *pVirtualBox, IMachine *pMachine, const char *pszName, Utf8Str *pStrValue);
1302
1303#ifndef VBOX_WITH_EFI_IN_DD2
1304DECLHIDDEN(int) findEfiRom(IVirtualBox* vbox, PlatformArchitecture_T aPlatformArchitecture, FirmwareType_T aFirmwareType, Utf8Str *pEfiRomFile);
1305#endif
1306
1307#endif /* !MAIN_INCLUDED_ConsoleImpl_h */
1308/* 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