VirtualBox

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

Last change on this file since 100606 was 100606, checked in by vboxsync, 17 months ago

Shared Clipboard/Main + FE/Qt: Added clipboard error propagation from the host service via a newly added ClipboardErrorEvent. For that we now have a generic (private) Shared Clipboard handling class within Main, which does the HGCM service callback dispatching. The VRDP console object, which was in charge for this before, now is daisy-chained to this new class as a service extension. FE/QT in turn then shows the error(s) via the notification center. bugref:9437

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