VirtualBox

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

最後變更 在這個檔案從95665是 95645,由 vboxsync 提交於 3 年 前

Recording/Main: Simplified and got rid of some destruction races by not dynamically (re-)allocating the recording context. Added docs, a bit of renaming. bugref:9286

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