VirtualBox

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

Last change on this file since 41549 was 41528, checked in by vboxsync, 13 years ago

Main/HostUSBDevice(all platforms)+USBProxyService: redo USB locking, fixes major regression, added lots of assertions to catch locking flaws early, whitespace cleanup
Main/Machine: small USB locking fix to be consistent with the remaining code
Main/Host+glue/AutoLock: replace USB list lock by host lock, small numbering cleanup
Main/Console: redo USB locking, do less in USB callbacks/EMT (addresses long standing todo items), eliminate unsafe iterator parameters

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 36.2 KB
Line 
1/* $Id: ConsoleImpl.h 41528 2012-05-31 16:48:33Z vboxsync $ */
2/** @file
3 * VBox Console COM Class definition
4 */
5
6/*
7 * Copyright (C) 2005-2012 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.215389.xyz. 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 ____H_CONSOLEIMPL
19#define ____H_CONSOLEIMPL
20
21#include "VirtualBoxBase.h"
22#include "VBox/com/array.h"
23#include "EventImpl.h"
24
25class Guest;
26class Keyboard;
27class Mouse;
28class Display;
29class MachineDebugger;
30class TeleporterStateSrc;
31class OUSBDevice;
32class RemoteUSBDevice;
33class SharedFolder;
34class VRDEServerInfo;
35class AudioSniffer;
36#ifdef VBOX_WITH_USB_VIDEO
37class UsbWebcamInterface;
38#endif
39#ifdef VBOX_WITH_USB_CARDREADER
40class UsbCardReader;
41#endif
42class ConsoleVRDPServer;
43class VMMDev;
44class Progress;
45class BusAssignmentManager;
46COM_STRUCT_OR_CLASS(IEventListener);
47#ifdef VBOX_WITH_EXTPACK
48class ExtPackManager;
49#endif
50
51#include <VBox/RemoteDesktop/VRDE.h>
52#include <VBox/vmm/pdmdrv.h>
53#ifdef VBOX_WITH_GUEST_PROPS
54# include <VBox/HostServices/GuestPropertySvc.h> /* For the property notification callback */
55#endif
56
57#ifdef RT_OS_WINDOWS
58# include "../src-server/win/VBoxComEvents.h"
59#endif
60
61struct VUSBIRHCONFIG;
62typedef struct VUSBIRHCONFIG *PVUSBIRHCONFIG;
63
64#include <list>
65#include <vector>
66
67// defines
68///////////////////////////////////////////////////////////////////////////////
69
70/**
71 * Checks the availability of the underlying VM device driver corresponding
72 * to the COM interface (IKeyboard, IMouse, IDisplay, etc.). When the driver is
73 * not available (NULL), sets error info and returns returns E_ACCESSDENIED.
74 * The translatable error message is defined in null context.
75 *
76 * Intended to used only within Console children (i.e. Keyboard, Mouse,
77 * Display, etc.).
78 *
79 * @param drv driver pointer to check (compare it with NULL)
80 */
81#define CHECK_CONSOLE_DRV(drv) \
82 do { \
83 if (!(drv)) \
84 return setError(E_ACCESSDENIED, tr("The console is not powered up")); \
85 } while (0)
86
87// Console
88///////////////////////////////////////////////////////////////////////////////
89
90/** IConsole implementation class */
91class ATL_NO_VTABLE Console :
92 public VirtualBoxBase,
93 VBOX_SCRIPTABLE_IMPL(IConsole)
94{
95 Q_OBJECT
96
97public:
98
99 VIRTUALBOXBASE_ADD_ERRORINFO_SUPPORT(Console, IConsole)
100
101 DECLARE_NOT_AGGREGATABLE(Console)
102
103 DECLARE_PROTECT_FINAL_CONSTRUCT()
104
105 BEGIN_COM_MAP(Console)
106 VBOX_DEFAULT_INTERFACE_ENTRIES(IConsole)
107 END_COM_MAP()
108
109 Console();
110 ~Console();
111
112 HRESULT FinalConstruct();
113 void FinalRelease();
114
115 // public initializers/uninitializers for internal purposes only
116 HRESULT init(IMachine *aMachine, IInternalMachineControl *aControl);
117 void uninit();
118
119 // IConsole properties
120 STDMETHOD(COMGETTER(Machine))(IMachine **aMachine);
121 STDMETHOD(COMGETTER(State))(MachineState_T *aMachineState);
122 STDMETHOD(COMGETTER(Guest))(IGuest **aGuest);
123 STDMETHOD(COMGETTER(Keyboard))(IKeyboard **aKeyboard);
124 STDMETHOD(COMGETTER(Mouse))(IMouse **aMouse);
125 STDMETHOD(COMGETTER(Display))(IDisplay **aDisplay);
126 STDMETHOD(COMGETTER(Debugger))(IMachineDebugger **aDebugger);
127 STDMETHOD(COMGETTER(USBDevices))(ComSafeArrayOut(IUSBDevice *, aUSBDevices));
128 STDMETHOD(COMGETTER(RemoteUSBDevices))(ComSafeArrayOut(IHostUSBDevice *, aRemoteUSBDevices));
129 STDMETHOD(COMGETTER(VRDEServerInfo))(IVRDEServerInfo **aVRDEServerInfo);
130 STDMETHOD(COMGETTER(SharedFolders))(ComSafeArrayOut(ISharedFolder *, aSharedFolders));
131 STDMETHOD(COMGETTER(EventSource)) (IEventSource ** aEventSource);
132 STDMETHOD(COMGETTER(AttachedPciDevices))(ComSafeArrayOut(IPciDeviceAttachment *, aAttachments));
133 STDMETHOD(COMGETTER(UseHostClipboard))(BOOL *aUseHostClipboard);
134 STDMETHOD(COMSETTER(UseHostClipboard))(BOOL aUseHostClipboard);
135
136 // IConsole methods
137 STDMETHOD(PowerUp)(IProgress **aProgress);
138 STDMETHOD(PowerUpPaused)(IProgress **aProgress);
139 STDMETHOD(PowerDown)(IProgress **aProgress);
140 STDMETHOD(Reset)();
141 STDMETHOD(Pause)();
142 STDMETHOD(Resume)();
143 STDMETHOD(PowerButton)();
144 STDMETHOD(SleepButton)();
145 STDMETHOD(GetPowerButtonHandled)(BOOL *aHandled);
146 STDMETHOD(GetGuestEnteredACPIMode)(BOOL *aEntered);
147 STDMETHOD(SaveState)(IProgress **aProgress);
148 STDMETHOD(AdoptSavedState)(IN_BSTR aSavedStateFile);
149 STDMETHOD(DiscardSavedState)(BOOL aRemoveFile);
150 STDMETHOD(GetDeviceActivity)(DeviceType_T aDeviceType,
151 DeviceActivity_T *aDeviceActivity);
152 STDMETHOD(AttachUSBDevice)(IN_BSTR aId);
153 STDMETHOD(DetachUSBDevice)(IN_BSTR aId, IUSBDevice **aDevice);
154 STDMETHOD(FindUSBDeviceByAddress)(IN_BSTR aAddress, IUSBDevice **aDevice);
155 STDMETHOD(FindUSBDeviceById)(IN_BSTR aId, IUSBDevice **aDevice);
156 STDMETHOD(CreateSharedFolder)(IN_BSTR aName, IN_BSTR aHostPath, BOOL aWritable, BOOL aAutoMount);
157 STDMETHOD(RemoveSharedFolder)(IN_BSTR aName);
158 STDMETHOD(TakeSnapshot)(IN_BSTR aName, IN_BSTR aDescription,
159 IProgress **aProgress);
160 STDMETHOD(DeleteSnapshot)(IN_BSTR aId, IProgress **aProgress);
161 STDMETHOD(DeleteSnapshotAndAllChildren)(IN_BSTR aId, IProgress **aProgress);
162 STDMETHOD(DeleteSnapshotRange)(IN_BSTR aStartId, IN_BSTR aEndId, IProgress **aProgress);
163 STDMETHOD(RestoreSnapshot)(ISnapshot *aSnapshot, IProgress **aProgress);
164 STDMETHOD(Teleport)(IN_BSTR aHostname, ULONG aPort, IN_BSTR aPassword, ULONG aMaxDowntime, IProgress **aProgress);
165
166 // public methods for internal purposes only
167
168 /*
169 * Note: the following methods do not increase refcount. intended to be
170 * called only by the VM execution thread.
171 */
172
173 Guest *getGuest() const { return mGuest; }
174 Keyboard *getKeyboard() const { return mKeyboard; }
175 Mouse *getMouse() const { return mMouse; }
176 Display *getDisplay() const { return mDisplay; }
177 MachineDebugger *getMachineDebugger() const { return mDebugger; }
178 AudioSniffer *getAudioSniffer() const { return mAudioSniffer; }
179
180 const ComPtr<IMachine> &machine() const { return mMachine; }
181
182 bool useHostClipboard() { return mfUseHostClipboard; }
183
184 /** Method is called only from ConsoleVRDPServer */
185 IVRDEServer *getVRDEServer() const { return mVRDEServer; }
186
187 ConsoleVRDPServer *consoleVRDPServer() const { return mConsoleVRDPServer; }
188
189 HRESULT updateMachineState(MachineState_T aMachineState);
190
191 // events from IInternalSessionControl
192 HRESULT onNetworkAdapterChange(INetworkAdapter *aNetworkAdapter, BOOL changeAdapter);
193 HRESULT onSerialPortChange(ISerialPort *aSerialPort);
194 HRESULT onParallelPortChange(IParallelPort *aParallelPort);
195 HRESULT onStorageControllerChange();
196 HRESULT onMediumChange(IMediumAttachment *aMediumAttachment, BOOL aForce);
197 HRESULT onCPUChange(ULONG aCPU, BOOL aRemove);
198 HRESULT onCPUExecutionCapChange(ULONG aExecutionCap);
199 HRESULT onVRDEServerChange(BOOL aRestart);
200 HRESULT onUSBControllerChange();
201 HRESULT onSharedFolderChange(BOOL aGlobal);
202 HRESULT onUSBDeviceAttach(IUSBDevice *aDevice, IVirtualBoxErrorInfo *aError, ULONG aMaskedIfs);
203 HRESULT onUSBDeviceDetach(IN_BSTR aId, IVirtualBoxErrorInfo *aError);
204 HRESULT onBandwidthGroupChange(IBandwidthGroup *aBandwidthGroup);
205 HRESULT onStorageDeviceChange(IMediumAttachment *aMediumAttachment, BOOL aRemove);
206 HRESULT getGuestProperty(IN_BSTR aKey, BSTR *aValue, LONG64 *aTimestamp, BSTR *aFlags);
207 HRESULT setGuestProperty(IN_BSTR aKey, IN_BSTR aValue, IN_BSTR aFlags);
208 HRESULT enumerateGuestProperties(IN_BSTR aPatterns,
209 ComSafeArrayOut(BSTR, aNames),
210 ComSafeArrayOut(BSTR, aValues),
211 ComSafeArrayOut(LONG64, aTimestamps),
212 ComSafeArrayOut(BSTR, aFlags));
213 HRESULT onlineMergeMedium(IMediumAttachment *aMediumAttachment,
214 ULONG aSourceIdx, ULONG aTargetIdx,
215 IMedium *aSource, IMedium *aTarget,
216 BOOL aMergeForward, IMedium *aParentForTarget,
217 ComSafeArrayIn(IMedium *, aChildrenToReparent),
218 IProgress *aProgress);
219 VMMDev *getVMMDev() { return m_pVMMDev; }
220 AudioSniffer *getAudioSniffer() { return mAudioSniffer; }
221#ifdef VBOX_WITH_EXTPACK
222 ExtPackManager *getExtPackManager();
223#endif
224 EventSource *getEventSource() { return mEventSource; }
225#ifdef VBOX_WITH_USB_CARDREADER
226 UsbCardReader *getUsbCardReader() { return mUsbCardReader; }
227#endif
228
229 int VRDPClientLogon(uint32_t u32ClientId, const char *pszUser, const char *pszPassword, const char *pszDomain);
230 void VRDPClientStatusChange(uint32_t u32ClientId, const char *pszStatus);
231 void VRDPClientConnect(uint32_t u32ClientId);
232 void VRDPClientDisconnect(uint32_t u32ClientId, uint32_t fu32Intercepted);
233 void VRDPInterceptAudio(uint32_t u32ClientId);
234 void VRDPInterceptUSB(uint32_t u32ClientId, void **ppvIntercept);
235 void VRDPInterceptClipboard(uint32_t u32ClientId);
236
237 void processRemoteUSBDevices(uint32_t u32ClientId, VRDEUSBDEVICEDESC *pDevList, uint32_t cbDevList, bool fDescExt);
238 void reportGuestStatistics(ULONG aValidStats, ULONG aCpuUser,
239 ULONG aCpuKernel, ULONG aCpuIdle,
240 ULONG aMemTotal, ULONG aMemFree,
241 ULONG aMemBalloon, ULONG aMemShared,
242 ULONG aMemCache, ULONG aPageTotal,
243 ULONG aAllocVMM, ULONG aFreeVMM,
244 ULONG aBalloonedVMM, ULONG aSharedVMM)
245 {
246 mControl->ReportGuestStatistics(aValidStats, aCpuUser, aCpuKernel, aCpuIdle,
247 aMemTotal, aMemFree, aMemBalloon, aMemShared,
248 aMemCache, aPageTotal, aAllocVMM, aFreeVMM,
249 aBalloonedVMM, aSharedVMM);
250 }
251 void enableVMMStatistics(BOOL aEnable);
252
253 // callback callers (partly; for some events console callbacks are notified
254 // directly from IInternalSessionControl event handlers declared above)
255 void onMousePointerShapeChange(bool fVisible, bool fAlpha,
256 uint32_t xHot, uint32_t yHot,
257 uint32_t width, uint32_t height,
258 ComSafeArrayIn(uint8_t, aShape));
259 void onMouseCapabilityChange(BOOL supportsAbsolute, BOOL supportsRelative, BOOL needsHostCursor);
260 void onStateChange(MachineState_T aMachineState);
261 void onAdditionsStateChange();
262 void onAdditionsOutdated();
263 void onKeyboardLedsChange(bool fNumLock, bool fCapsLock, bool fScrollLock);
264 void onUSBDeviceStateChange(IUSBDevice *aDevice, bool aAttached,
265 IVirtualBoxErrorInfo *aError);
266 void onRuntimeError(BOOL aFatal, IN_BSTR aErrorID, IN_BSTR aMessage);
267 HRESULT onShowWindow(BOOL aCheck, BOOL *aCanShow, LONG64 *aWinId);
268 void onVRDEServerInfoChange();
269
270 static const PDMDRVREG DrvStatusReg;
271
272 static HRESULT setErrorStatic(HRESULT aResultCode, const char *pcsz, ...);
273 HRESULT setInvalidMachineStateError();
274
275 static const char *convertControllerTypeToDev(StorageControllerType_T enmCtrlType);
276 static HRESULT convertBusPortDeviceToLun(StorageBus_T enmBus, LONG port, LONG device, unsigned &uLun);
277 // Called from event listener
278 HRESULT onNATRedirectRuleChange(ULONG ulInstance, BOOL aNatRuleRemove,
279 NATProtocol_T aProto, IN_BSTR aHostIp, LONG aHostPort, IN_BSTR aGuestIp, LONG aGuestPort);
280
281private:
282
283 /**
284 * Base template for AutoVMCaller and SaveVMPtr. Template arguments
285 * have the same meaning as arguments of Console::addVMCaller().
286 */
287 template <bool taQuiet = false, bool taAllowNullVM = false>
288 class AutoVMCallerBase
289 {
290 public:
291 AutoVMCallerBase(Console *aThat) : mThat(aThat), mRC(S_OK)
292 {
293 Assert(aThat);
294 mRC = aThat->addVMCaller(taQuiet, taAllowNullVM);
295 }
296 ~AutoVMCallerBase()
297 {
298 if (SUCCEEDED(mRC))
299 mThat->releaseVMCaller();
300 }
301 /** Decreases the number of callers before the instance is destroyed. */
302 void releaseCaller()
303 {
304 AssertReturnVoid(SUCCEEDED(mRC));
305 mThat->releaseVMCaller();
306 mRC = E_FAIL;
307 }
308 /** Restores the number of callers after by #release(). #rc() must be
309 * rechecked to ensure the operation succeeded. */
310 void addYY()
311 {
312 AssertReturnVoid(!SUCCEEDED(mRC));
313 mRC = mThat->addVMCaller(taQuiet, taAllowNullVM);
314 }
315 /** Returns the result of Console::addVMCaller() */
316 HRESULT rc() const { return mRC; }
317 /** Shortcut to SUCCEEDED(rc()) */
318 bool isOk() const { return SUCCEEDED(mRC); }
319 protected:
320 Console *mThat;
321 HRESULT mRC;
322 private:
323 DECLARE_CLS_COPY_CTOR_ASSIGN_NOOP(AutoVMCallerBase)
324 };
325
326#if 0
327 /**
328 * Helper class that protects sections of code using the mpVM pointer by
329 * automatically calling addVMCaller() on construction and
330 * releaseVMCaller() on destruction. Intended for Console methods dealing
331 * with mpVM. The usage pattern is:
332 * <code>
333 * AutoVMCaller autoVMCaller(this);
334 * if (FAILED(autoVMCaller.rc())) return autoVMCaller.rc();
335 * ...
336 * VMR3ReqCall (mpVM, ...
337 * </code>
338 *
339 * @note Temporarily locks the argument for writing.
340 *
341 * @sa SafeVMPtr, SafeVMPtrQuiet
342 * @obsolete Use SafeVMPtr
343 */
344 typedef AutoVMCallerBase<false, false> AutoVMCaller;
345#endif
346
347 /**
348 * Same as AutoVMCaller but doesn't set extended error info on failure.
349 *
350 * @note Temporarily locks the argument for writing.
351 * @obsolete Use SafeVMPtrQuiet
352 */
353 typedef AutoVMCallerBase<true, false> AutoVMCallerQuiet;
354
355 /**
356 * Same as AutoVMCaller but allows a null VM pointer (to trigger an error
357 * instead of assertion).
358 *
359 * @note Temporarily locks the argument for writing.
360 * @obsolete Use SafeVMPtr
361 */
362 typedef AutoVMCallerBase<false, true> AutoVMCallerWeak;
363
364 /**
365 * Same as AutoVMCaller but doesn't set extended error info on failure
366 * and allows a null VM pointer (to trigger an error instead of
367 * assertion).
368 *
369 * @note Temporarily locks the argument for writing.
370 * @obsolete Use SafeVMPtrQuiet
371 */
372 typedef AutoVMCallerBase<true, true> AutoVMCallerQuietWeak;
373
374 /**
375 * Base template for SaveVMPtr and SaveVMPtrQuiet.
376 */
377 template<bool taQuiet = false>
378 class SafeVMPtrBase : public AutoVMCallerBase<taQuiet, true>
379 {
380 typedef AutoVMCallerBase<taQuiet, true> Base;
381 public:
382 SafeVMPtrBase(Console *aThat) : Base(aThat), mpVM(NULL), mpUVM(NULL)
383 {
384 if (SUCCEEDED(Base::mRC))
385 Base::mRC = aThat->safeVMPtrRetainer(&mpVM, &mpUVM, taQuiet);
386 }
387 ~SafeVMPtrBase()
388 {
389 if (SUCCEEDED(Base::mRC))
390 release();
391 }
392 /** Smart SaveVMPtr to PVM cast operator */
393 operator PVM() const { return mpVM; }
394 /** Direct PVM access for printf()-like functions */
395 PVM raw() const { return mpVM; }
396 /** Direct PUVM access for printf()-like functions */
397 PUVM rawUVM() const { return mpUVM; }
398 /** Release the handles. */
399 void release()
400 {
401 AssertReturnVoid(SUCCEEDED(Base::mRC));
402 Base::mThat->safeVMPtrReleaser(&mpVM, &mpUVM);
403 Base::releaseCaller();
404 }
405
406 private:
407 PVM mpVM;
408 PUVM mpUVM;
409 DECLARE_CLS_COPY_CTOR_ASSIGN_NOOP(SafeVMPtrBase)
410 };
411
412public:
413
414 /**
415 * Helper class that safely manages the Console::mpVM pointer
416 * by calling addVMCaller() on construction and releaseVMCaller() on
417 * destruction. Intended for Console children. The usage pattern is:
418 * <code>
419 * Console::SaveVMPtr pVM(mParent);
420 * if (FAILED(pVM.rc())) return pVM.rc();
421 * ...
422 * VMR3ReqCall(pVM, ...
423 * ...
424 * printf("%p\n", pVM.raw());
425 * </code>
426 *
427 * @note Temporarily locks the argument for writing.
428 *
429 * @sa SafeVMPtrQuiet, AutoVMCaller
430 */
431 typedef SafeVMPtrBase<false> SafeVMPtr;
432
433 /**
434 * A deviation of SaveVMPtr that doesn't set the error info on failure.
435 * Intended for pieces of code that don't need to return the VM access
436 * failure to the caller. The usage pattern is:
437 * <code>
438 * Console::SaveVMPtrQuiet pVM(mParent);
439 * if (pVM.rc())
440 * VMR3ReqCall(pVM, ...
441 * return S_OK;
442 * </code>
443 *
444 * @note Temporarily locks the argument for writing.
445 *
446 * @sa SafeVMPtr, AutoVMCaller
447 */
448 typedef SafeVMPtrBase<true> SafeVMPtrQuiet;
449
450 class SharedFolderData
451 {
452 public:
453 SharedFolderData()
454 { }
455
456 SharedFolderData(const Utf8Str &aHostPath,
457 bool aWritable,
458 bool aAutoMount)
459 : m_strHostPath(aHostPath),
460 m_fWritable(aWritable),
461 m_fAutoMount(aAutoMount)
462 { }
463
464 // copy constructor
465 SharedFolderData(const SharedFolderData& aThat)
466 : m_strHostPath(aThat.m_strHostPath),
467 m_fWritable(aThat.m_fWritable),
468 m_fAutoMount(aThat.m_fAutoMount)
469 { }
470
471 Utf8Str m_strHostPath;
472 bool m_fWritable;
473 bool m_fAutoMount;
474 };
475
476 typedef std::map<Utf8Str, ComObjPtr<SharedFolder> > SharedFolderMap;
477 typedef std::map<Utf8Str, SharedFolderData> SharedFolderDataMap;
478 typedef std::map<Utf8Str, ComPtr<IMediumAttachment> > MediumAttachmentMap;
479
480private:
481
482 typedef std::list <ComObjPtr<OUSBDevice> > USBDeviceList;
483 typedef std::list <ComObjPtr<RemoteUSBDevice> > RemoteUSBDeviceList;
484
485 HRESULT addVMCaller(bool aQuiet = false, bool aAllowNullVM = false);
486 void releaseVMCaller();
487 HRESULT safeVMPtrRetainer(PVM *a_ppVM, PUVM *a_ppUVM, bool aQuiet);
488 void safeVMPtrReleaser(PVM *a_ppVM, PUVM *a_ppUVM);
489
490 HRESULT consoleInitReleaseLog(const ComPtr<IMachine> aMachine);
491
492 HRESULT powerUp(IProgress **aProgress, bool aPaused);
493 HRESULT powerDown(IProgress *aProgress = NULL);
494
495/* Note: FreeBSD needs this whether netflt is used or not. */
496#if ((defined(RT_OS_LINUX) && !defined(VBOX_WITH_NETFLT)) || defined(RT_OS_FREEBSD))
497 HRESULT attachToTapInterface(INetworkAdapter *networkAdapter);
498 HRESULT detachFromTapInterface(INetworkAdapter *networkAdapter);
499#endif
500 HRESULT powerDownHostInterfaces();
501
502 HRESULT setMachineState(MachineState_T aMachineState, bool aUpdateServer = true);
503 HRESULT setMachineStateLocally(MachineState_T aMachineState)
504 {
505 return setMachineState(aMachineState, false /* aUpdateServer */);
506 }
507
508 HRESULT findSharedFolder(const Utf8Str &strName,
509 ComObjPtr<SharedFolder> &aSharedFolder,
510 bool aSetError = false);
511
512 HRESULT fetchSharedFolders(BOOL aGlobal);
513 bool findOtherSharedFolder(const Utf8Str &straName,
514 SharedFolderDataMap::const_iterator &aIt);
515
516 HRESULT createSharedFolder(const Utf8Str &strName, const SharedFolderData &aData);
517 HRESULT removeSharedFolder(const Utf8Str &strName);
518
519 static DECLCALLBACK(int) configConstructor(PVM pVM, void *pvConsole);
520 int configConstructorInner(PVM pVM, AutoWriteLock *pAlock);
521 int configCfgmOverlay(PVM pVM, IVirtualBox *pVirtualBox, IMachine *pMachine);
522
523 int configMediumAttachment(PCFGMNODE pCtlInst,
524 const char *pcszDevice,
525 unsigned uInstance,
526 StorageBus_T enmBus,
527 bool fUseHostIOCache,
528 bool fBuiltinIoCache,
529 bool fSetupMerge,
530 unsigned uMergeSource,
531 unsigned uMergeTarget,
532 IMediumAttachment *pMediumAtt,
533 MachineState_T aMachineState,
534 HRESULT *phrc,
535 bool fAttachDetach,
536 bool fForceUnmount,
537 bool fHotplug,
538 PVM pVM,
539 DeviceType_T *paLedDevType);
540 int configMedium(PCFGMNODE pLunL0,
541 bool fPassthrough,
542 DeviceType_T enmType,
543 bool fUseHostIOCache,
544 bool fBuiltinIoCache,
545 bool fSetupMerge,
546 unsigned uMergeSource,
547 unsigned uMergeTarget,
548 const char *pcszBwGroup,
549 bool fDiscard,
550 IMedium *pMedium,
551 MachineState_T aMachineState,
552 HRESULT *phrc);
553 static DECLCALLBACK(int) reconfigureMediumAttachment(Console *pConsole,
554 PVM pVM,
555 const char *pcszDevice,
556 unsigned uInstance,
557 StorageBus_T enmBus,
558 bool fUseHostIOCache,
559 bool fBuiltinIoCache,
560 bool fSetupMerge,
561 unsigned uMergeSource,
562 unsigned uMergeTarget,
563 IMediumAttachment *aMediumAtt,
564 MachineState_T aMachineState,
565 HRESULT *phrc);
566 static DECLCALLBACK(int) changeRemovableMedium(Console *pThis,
567 PVM pVM,
568 const char *pcszDevice,
569 unsigned uInstance,
570 StorageBus_T enmBus,
571 bool fUseHostIOCache,
572 IMediumAttachment *aMediumAtt,
573 bool fForce);
574
575 HRESULT attachRawPciDevices(PVM pVM, BusAssignmentManager *BusMgr, PCFGMNODE pDevices);
576 void attachStatusDriver(PCFGMNODE pCtlInst, PPDMLED *papLeds,
577 uint64_t uFirst, uint64_t uLast,
578 Console::MediumAttachmentMap *pmapMediumAttachments,
579 const char *pcszDevice, unsigned uInstance);
580
581 int configNetwork(const char *pszDevice, unsigned uInstance, unsigned uLun,
582 INetworkAdapter *aNetworkAdapter, PCFGMNODE pCfg,
583 PCFGMNODE pLunL0, PCFGMNODE pInst,
584 bool fAttachDetach, bool fIgnoreConnectFailure);
585
586 static DECLCALLBACK(int) configGuestProperties(void *pvConsole, PVM pVM);
587 static DECLCALLBACK(int) configGuestControl(void *pvConsole);
588 static DECLCALLBACK(void) vmstateChangeCallback(PVM aVM, VMSTATE aState,
589 VMSTATE aOldState, void *aUser);
590 static DECLCALLBACK(int) unplugCpu(Console *pThis, PVM pVM, unsigned uCpu);
591 static DECLCALLBACK(int) plugCpu(Console *pThis, PVM pVM, unsigned uCpu);
592 HRESULT doMediumChange(IMediumAttachment *aMediumAttachment, bool fForce, PVM pVM);
593 HRESULT doCPURemove(ULONG aCpu, PVM pVM);
594 HRESULT doCPUAdd(ULONG aCpu, PVM pVM);
595
596 HRESULT doNetworkAdapterChange(PVM pVM, const char *pszDevice, unsigned uInstance,
597 unsigned uLun, INetworkAdapter *aNetworkAdapter);
598 static DECLCALLBACK(int) changeNetworkAttachment(Console *pThis, PVM pVM, const char *pszDevice,
599 unsigned uInstance, unsigned uLun,
600 INetworkAdapter *aNetworkAdapter);
601
602#ifdef VBOX_WITH_USB
603 HRESULT attachUSBDevice(IUSBDevice *aHostDevice, ULONG aMaskedIfs);
604 HRESULT detachUSBDevice(const ComObjPtr<OUSBDevice> &aHostDevice);
605
606 static DECLCALLBACK(int) usbAttachCallback(Console *that, PVM pVM, IUSBDevice *aHostDevice, PCRTUUID aUuid,
607 bool aRemote, const char *aAddress, void *pvRemoteBackend, USHORT aPortVersion, ULONG aMaskedIfs);
608 static DECLCALLBACK(int) usbDetachCallback(Console *that, PVM pVM, PCRTUUID aUuid);
609#endif
610
611 static DECLCALLBACK(int) attachStorageDevice(Console *pThis,
612 PVM pVM,
613 const char *pcszDevice,
614 unsigned uInstance,
615 StorageBus_T enmBus,
616 bool fUseHostIOCache,
617 IMediumAttachment *aMediumAtt);
618 static DECLCALLBACK(int) detachStorageDevice(Console *pThis,
619 PVM pVM,
620 const char *pcszDevice,
621 unsigned uInstance,
622 StorageBus_T enmBus,
623 IMediumAttachment *aMediumAtt);
624 HRESULT doStorageDeviceAttach(IMediumAttachment *aMediumAttachment, PVM pVM);
625 HRESULT doStorageDeviceDetach(IMediumAttachment *aMediumAttachment, PVM pVM);
626
627 static DECLCALLBACK(int) fntTakeSnapshotWorker(RTTHREAD Thread, void *pvUser);
628
629 static DECLCALLBACK(int) stateProgressCallback(PVM pVM, unsigned uPercent, void *pvUser);
630
631 static DECLCALLBACK(void) genericVMSetErrorCallback(PVM pVM, void *pvUser, int rc, RT_SRC_POS_DECL,
632 const char *pszErrorFmt, va_list va);
633
634 static void setVMRuntimeErrorCallbackF(PVM pVM, void *pvUser, uint32_t fFatal,
635 const char *pszErrorId, const char *pszFormat, ...);
636 static DECLCALLBACK(void) setVMRuntimeErrorCallback(PVM pVM, void *pvUser, uint32_t fFatal,
637 const char *pszErrorId, const char *pszFormat, va_list va);
638
639 HRESULT captureUSBDevices(PVM pVM);
640 void detachAllUSBDevices(bool aDone);
641
642 static DECLCALLBACK(int) powerUpThread(RTTHREAD Thread, void *pvUser);
643 static DECLCALLBACK(int) saveStateThread(RTTHREAD Thread, void *pvUser);
644 static DECLCALLBACK(int) powerDownThread(RTTHREAD Thread, void *pvUser);
645
646 static DECLCALLBACK(int) vmm2User_SaveState(PCVMM2USERMETHODS pThis, PUVM pUVM);
647 static DECLCALLBACK(void) vmm2User_NotifyEmtInit(PCVMM2USERMETHODS pThis, PUVM pUVM, PUVMCPU pUVCpu);
648 static DECLCALLBACK(void) vmm2User_NotifyEmtTerm(PCVMM2USERMETHODS pThis, PUVM pUVM, PUVMCPU pUVCpu);
649 static DECLCALLBACK(void) vmm2User_NotifyPdmtInit(PCVMM2USERMETHODS pThis, PUVM pUVM);
650 static DECLCALLBACK(void) vmm2User_NotifyPdmtTerm(PCVMM2USERMETHODS pThis, PUVM pUVM);
651
652 static DECLCALLBACK(void *) drvStatus_QueryInterface(PPDMIBASE pInterface, const char *pszIID);
653 static DECLCALLBACK(void) drvStatus_UnitChanged(PPDMILEDCONNECTORS pInterface, unsigned iLUN);
654 static DECLCALLBACK(int) drvStatus_MediumEjected(PPDMIMEDIANOTIFY pInterface, unsigned iLUN);
655 static DECLCALLBACK(void) drvStatus_Destruct(PPDMDRVINS pDrvIns);
656 static DECLCALLBACK(int) drvStatus_Construct(PPDMDRVINS pDrvIns, PCFGMNODE pCfg, uint32_t fFlags);
657
658 int mcAudioRefs;
659 volatile uint32_t mcVRDPClients;
660 uint32_t mu32SingleRDPClientId; /* The id of a connected client in the single connection mode. */
661 volatile bool mcGuestCredentialsProvided;
662
663 static const char *sSSMConsoleUnit;
664 static uint32_t sSSMConsoleVer;
665
666 HRESULT loadDataFromSavedState();
667 int loadStateFileExecInternal(PSSMHANDLE pSSM, uint32_t u32Version);
668
669 static DECLCALLBACK(void) saveStateFileExec(PSSMHANDLE pSSM, void *pvUser);
670 static DECLCALLBACK(int) loadStateFileExec(PSSMHANDLE pSSM, void *pvUser, uint32_t uVersion, uint32_t uPass);
671
672#ifdef VBOX_WITH_GUEST_PROPS
673 static DECLCALLBACK(int) doGuestPropNotification(void *pvExtension, uint32_t, void *pvParms, uint32_t cbParms);
674 HRESULT doEnumerateGuestProperties(CBSTR aPatterns,
675 ComSafeArrayOut(BSTR, aNames),
676 ComSafeArrayOut(BSTR, aValues),
677 ComSafeArrayOut(LONG64, aTimestamps),
678 ComSafeArrayOut(BSTR, aFlags));
679
680 void guestPropertiesHandleVMReset(void);
681 bool guestPropertiesVRDPEnabled(void);
682 void guestPropertiesVRDPUpdateLogon(uint32_t u32ClientId, const char *pszUser, const char *pszDomain);
683 void guestPropertiesVRDPUpdateActiveClient(uint32_t u32ClientId);
684 void guestPropertiesVRDPUpdateClientAttach(uint32_t u32ClientId, bool fAttached);
685 void guestPropertiesVRDPUpdateNameChange(uint32_t u32ClientId, const char *pszName);
686 void guestPropertiesVRDPUpdateDisconnect(uint32_t u32ClientId);
687#endif
688
689 /** @name Teleporter support
690 * @{ */
691 static DECLCALLBACK(int) teleporterSrcThreadWrapper(RTTHREAD hThread, void *pvUser);
692 HRESULT teleporterSrc(TeleporterStateSrc *pState);
693 HRESULT teleporterSrcReadACK(TeleporterStateSrc *pState, const char *pszWhich, const char *pszNAckMsg = NULL);
694 HRESULT teleporterSrcSubmitCommand(TeleporterStateSrc *pState, const char *pszCommand, bool fWaitForAck = true);
695 HRESULT teleporterTrg(PUVM pUVM, IMachine *pMachine, Utf8Str *pErrorMsg, bool fStartPaused,
696 Progress *pProgress, bool *pfPowerOffOnFailure);
697 static DECLCALLBACK(int) teleporterTrgServeConnection(RTSOCKET Sock, void *pvUser);
698 /** @} */
699
700 bool mSavedStateDataLoaded : 1;
701
702 const ComPtr<IMachine> mMachine;
703 const ComPtr<IInternalMachineControl> mControl;
704
705 const ComPtr<IVRDEServer> mVRDEServer;
706
707 ConsoleVRDPServer * const mConsoleVRDPServer;
708
709 const ComObjPtr<Guest> mGuest;
710 const ComObjPtr<Keyboard> mKeyboard;
711 const ComObjPtr<Mouse> mMouse;
712 const ComObjPtr<Display> mDisplay;
713 const ComObjPtr<MachineDebugger> mDebugger;
714 const ComObjPtr<VRDEServerInfo> mVRDEServerInfo;
715 /** This can safely be used without holding any locks.
716 * An AutoCaller suffices to prevent it being destroy while in use and
717 * internally there is a lock providing the necessary serialization. */
718 const ComObjPtr<EventSource> mEventSource;
719#ifdef VBOX_WITH_EXTPACK
720 const ComObjPtr<ExtPackManager> mptrExtPackManager;
721#endif
722
723 USBDeviceList mUSBDevices;
724 RemoteUSBDeviceList mRemoteUSBDevices;
725
726 SharedFolderDataMap m_mapGlobalSharedFolders;
727 SharedFolderDataMap m_mapMachineSharedFolders;
728 SharedFolderMap m_mapSharedFolders; // the console instances
729
730 /** The user mode VM handle. */
731 PUVM mpUVM;
732 /** Holds the number of "readonly" mpVM callers (users) */
733 uint32_t mVMCallers;
734 /** Semaphore posted when the number of mpVM callers drops to zero */
735 RTSEMEVENT mVMZeroCallersSem;
736 /** true when Console has entered the mpVM destruction phase */
737 bool mVMDestroying : 1;
738 /** true when power down is initiated by vmstateChangeCallback (EMT) */
739 bool mVMPoweredOff : 1;
740 /** true when vmstateChangeCallback shouldn't initiate a power down. */
741 bool mVMIsAlreadyPoweringOff : 1;
742 /** true if we already showed the snapshot folder size warning. */
743 bool mfSnapshotFolderSizeWarningShown : 1;
744 /** true if we already showed the snapshot folder ext4/xfs bug warning. */
745 bool mfSnapshotFolderExt4WarningShown : 1;
746 /** true if we already listed the disk type of the snapshot folder. */
747 bool mfSnapshotFolderDiskTypeShown : 1;
748
749 /** Pointer to the VMM -> User (that's us) callbacks. */
750 struct MYVMM2USERMETHODS : public VMM2USERMETHODS
751 {
752 Console *pConsole;
753 } *mpVmm2UserMethods;
754
755 /** The current network attachment type in the VM.
756 * This doesn't have to match the network attachment type maintained in the
757 * NetworkAdapter. This is needed to change the network attachment
758 * dynamically.
759 */
760 typedef std::vector<NetworkAttachmentType_T> NetworkAttachmentTypeVector;
761 NetworkAttachmentTypeVector meAttachmentType;
762
763 VMMDev * m_pVMMDev;
764 AudioSniffer * const mAudioSniffer;
765#ifdef VBOX_WITH_USB_VIDEO
766 UsbWebcamInterface * const mUsbWebcamInterface;
767#endif
768#ifdef VBOX_WITH_USB_CARDREADER
769 UsbCardReader * const mUsbCardReader;
770#endif
771 BusAssignmentManager* mBusMgr;
772
773 enum
774 {
775 iLedFloppy = 0,
776 cLedFloppy = 2,
777 iLedIde = iLedFloppy + cLedFloppy,
778 cLedIde = 4,
779 iLedSata = iLedIde + cLedIde,
780 cLedSata = 30,
781 iLedScsi = iLedSata + cLedSata,
782 cLedScsi = 16,
783 iLedSas = iLedScsi + cLedScsi,
784 cLedSas = 8,
785 cLedStorage = cLedFloppy + cLedIde + cLedSata + cLedScsi + cLedSas
786 };
787 DeviceType_T maStorageDevType[cLedStorage];
788 PPDMLED mapStorageLeds[cLedStorage];
789 PPDMLED mapNetworkLeds[36]; /**< @todo adapt this to the maximum network card count */
790 PPDMLED mapSharedFolderLed;
791 PPDMLED mapUSBLed[2];
792
793 MediumAttachmentMap mapMediumAttachments;
794
795/* Note: FreeBSD needs this whether netflt is used or not. */
796#if ((defined(RT_OS_LINUX) && !defined(VBOX_WITH_NETFLT)) || defined(RT_OS_FREEBSD))
797 Utf8Str maTAPDeviceName[8];
798 RTFILE maTapFD[8];
799#endif
800
801 bool mVMStateChangeCallbackDisabled;
802
803 bool mfUseHostClipboard;
804
805 /** Local machine state value. */
806 MachineState_T mMachineState;
807
808 /** Pointer to the progress object of a live cancelable task.
809 *
810 * This is currently only used by Console::Teleport(), but is intended to later
811 * be used by the live snapshot code path as well. Actions like
812 * Console::PowerDown, which automatically cancels out the running snapshot /
813 * teleportation operation, will cancel the teleportation / live snapshot
814 * operation before starting. */
815 ComObjPtr<Progress> mptrCancelableProgress;
816
817 /* The purpose of caching of some events is probably in order to
818 automatically fire them at new event listeners. However, there is no
819 (longer?) any code making use of this... */
820#ifdef CONSOLE_WITH_EVENT_CACHE
821 struct
822 {
823 /** OnMousePointerShapeChange() cache */
824 struct
825 {
826 bool valid;
827 bool visible;
828 bool alpha;
829 uint32_t xHot;
830 uint32_t yHot;
831 uint32_t width;
832 uint32_t height;
833 com::SafeArray<BYTE> shape;
834 } mpsc;
835
836 /** OnMouseCapabilityChange() cache */
837 struct
838 {
839 bool valid;
840 BOOL supportsAbsolute;
841 BOOL supportsRelative;
842 BOOL needsHostCursor;
843 } mcc;
844
845 /** OnKeyboardLedsChange() cache */
846 struct
847 {
848 bool valid;
849 bool numLock;
850 bool capsLock;
851 bool scrollLock;
852 } klc;
853
854 void clear()
855 {
856 RT_ZERO(mcc);
857 RT_ZERO(klc);
858
859 /* We cannot RT_ZERO mpsc because of shape's vtable. */
860 mpsc.shape.setNull();
861 mpsc.valid = mpsc.visible = mpsc.alpha = false;
862 mpsc.xHot = mpsc.yHot = mpsc.width = mpsc.height = 0;
863 }
864 } mCallbackData;
865#endif
866 ComPtr<IEventListener> mVmListener;
867
868 friend struct VMTask;
869};
870
871#endif // !____H_CONSOLEIMPL
872/* vi: set tabstop=4 shiftwidth=4 expandtab: */
Note: See TracBrowser for help on using the repository browser.

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