VirtualBox

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

最後變更 在這個檔案從99965是 99913,由 vboxsync 提交於 23 月 前

Main/src-client/ConsoleImpl: Add some _very_ basic config code to run an ARMv8 based guest inside the main VirtualBox frontend, can be activated by a CFGM key, bugref:10384

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

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