ConsoleImpl2.cpp revision c5b29236aa344200f7a9c46c838c0c9eed9352a2
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync * VBox Console COM Class implementation
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync * @remark We've split out the code that the 64-bit VC++ v8 compiler finds
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync * problematic to optimize so we can disable optimizations and later,
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync * perhaps, find a real solution for it (like rewriting the code and
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync * to stop resemble a tonne of spaghetti).
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync * Copyright (C) 2006-2011 Oracle Corporation
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync * available from http://www.virtualbox.org. This file is free software;
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync * you can redistribute it and/or modify it under the terms of the GNU
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync * General Public License (GPL) as published by the Free Software
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync/*******************************************************************************
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync* Header Files *
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync*******************************************************************************/
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync// for some reason Windows burns in sdk\...\winsock.h if this isn't included first
#ifdef VBOX_WITH_PCI_PASSTHROUGH
# include "PciRawDevImpl.h"
#include "SchemaDefs.h"
#include "AutoCaller.h"
#include "Logging.h"
#ifdef VBOX_WITH_CROGL
#ifdef VBOX_WITH_GUEST_PROPS
# include <vector>
#ifdef VBOX_WITH_NETFLT
# if defined(RT_OS_SOLARIS)
# include <zone.h>
# include <unistd.h>
# include <unistd.h>
# if defined(RT_OS_WINDOWS)
# include <Ntddndis.h>
# include <devguid.h>
# include <HostNetworkInterfaceImpl.h>
# include <netif.h>
# include <stdlib.h>
#include "DHCPServerRunner.h"
#include "BusAssignmentManager.h"
#ifdef VBOX_WITH_EXTPACK
# include "ExtPackManagerImpl.h"
#if defined(RT_OS_DARWIN)
# include "IOKit/IOKitLib.h"
if (!service)
return VERR_NOT_FOUND;
(const void *)&inputStruct,
sizeof(inputStruct),
(void *)&outputStruct,
return VINF_SUCCESS;
#define VMWARE_NET_IN_SLOT_11
switch (enmType)
struct BootNic
if (!fPresent)
return VERR_FILE_NOT_FOUND;
return VINF_SUCCESS;
*pfGetKeyFromRealSMC = false;
aKey);
&& *aKey
&& **aKey)
return VINF_SUCCESS;
#ifdef RT_OS_DARWIN
return rc;
*pfGetKeyFromRealSMC = true;
*pfGetKeyFromRealSMC = true;
return rc;
int vrc,
const char *pcszName)
int m_vrc;
const char *pcszName,
const char *pcszValue)
const char *pcszName,
const char *pcszName,
const char *pcszName,
const void *pvBytes,
cbBytes);
const char *pcszName,
const char *pcszName,
const char *pcszName)
#ifdef VBOX_WITH_PCI_PASSTHROUGH
return hrc;
# ifdef VBOX_WITH_EXTPACK
int iBridgesMissed = 0;
iBase++;
return hrc;
return hrc;
int vrc;
return vrc;
int rc;
#ifdef VBOX_WITH_RAW_MODE
if (fOsXGuest)
#ifdef VBOX_WITH_RAW_MODE
# ifdef RT_OS_DARWIN
if (!fHwVirtExtForced)
if (fHWVirtExEnabled)
&fSupportsLongMode); H();
/** @todo Not exactly pretty to check strings; VBOXOSTYPE would be better, but that requires quite a bit of API change in Main. */
if ( !fIsGuest64Bit
&& fIOAPIC
#ifdef VBOX_WITH_XPCOM
switch (chipsetType)
Assert(false);
case ChipsetType_PIIX3:
case ChipsetType_ICH9:
#ifdef VBOX_WITH_PCI_PASSTHROUGH
if (fHpetEnabled)
if (fSmcEnabled)
bool fGetKeyFromRealSMC;
if (fLpcEnabled)
#ifdef DEBUG
if (fIOAPIC)
#ifdef VBOX_WITH_2X_4GB_ADDR_SPACE
int iShowBootMenu;
switch (eBootMenuMode)
unsigned cModes = 0;
++cModes;
if (pFramebuffer)
ulHeightReduction = 0;
#ifdef VBOX_WITH_EFI
if (!fEfiEnabled)
return VERR_INVALID_PARAMETER;
const char *pszBootDevice;
switch (bootDevice)
case DeviceType_Null:
case DeviceType_HardDisk:
case DeviceType_DVD:
case DeviceType_Floppy:
case DeviceType_Network:
hrc = pMachine->GetExtraData(Bstr("VBoxInternal2/EfiDeviceProps").raw(), deviceProps.asOutParam()); H();
hrc = pMachine->GetExtraData(Bstr("VBoxInternal2/EfiUgaHorizontalResolution").raw(), bstr.asOutParam()); H();
hrc = pMachine->GetExtraData(Bstr("VBoxInternal2/EfiUgaVerticalResolution").raw(), bstr.asOutParam()); H();
if (fOsXGuest)
bool fFdcEnabled = false;
if (!pDev)
switch (enmCtrlType)
if (pBiosCfg)
{ "SataPrimaryMasterLUN", "SataPrimarySlaveLUN", "SataSecondaryMasterLUN", "SataSecondarySlaveLUN" };
if (pBiosCfg)
fFdcEnabled = true;
AssertMsgFailedReturn(("invalid storage controller type: %d\n", enmCtrlType), VERR_GENERAL_FAILURE);
pVM,
return rc;
#ifdef VMWARE_NET_IN_SLOT_11
bool fSwapSlots3and11 = false;
#ifdef VBOX_WITH_E1000
#ifdef VBOX_WITH_VIRTIO
if (!fEnabled)
switch (adapterType)
#ifdef VBOX_WITH_E1000
#ifdef VBOX_WITH_VIRTIO
int iPciDeviceNo;
switch (ulInstance)
#ifdef VMWARE_NET_IN_SLOT_11
fSwapSlots3and11 = true;
#ifdef VBOX_WITH_2X_4GB_ADDR_SPACE /* not safe here yet. */ /** @todo Make PCNet ring-0 safe on 32-bit mac kernels! */
switch (adapterType)
pCfg,
return rc;
unsigned uBootIdx = 0;
if (serialPort)
if (!fEnabled)
if (parallelPort)
if (!fEnabled)
if (audioAdapter)
if (fAudioEnabled)
switch (audioController)
case AudioControllerType_AC97:
case AudioControllerType_SB16:
case AudioControllerType_HDA:
switch (audioDriver)
case AudioDriverType_Null:
#ifdef RT_OS_WINDOWS
#ifdef VBOX_WITH_WINMM
case AudioDriverType_WinMM:
#ifdef RT_OS_SOLARIS
case AudioDriverType_SolAudio:
#ifdef RT_OS_LINUX
# ifdef VBOX_WITH_ALSA
case AudioDriverType_ALSA:
# ifdef VBOX_WITH_PULSE
case AudioDriverType_Pulse:
case AudioDriverType_OSS:
#ifdef RT_OS_FREEBSD
# ifdef VBOX_WITH_PULSE
case AudioDriverType_Pulse:
#ifdef RT_OS_DARWIN
if (USBCtlPtr)
if (fOhciEnabled)
#ifdef VBOX_WITH_EHCI
if (fEhciEnabled)
# ifdef VBOX_WITH_EXTPACK
# ifdef VBOX_WITH_EXTPACK
#ifdef VBOX_WITH_USB
// VBoxManage setextradata "myvm" "VBoxInternal/USB/USBProxy/GlobalConfig/Force11PacketSize" 1
#ifdef VBOX_WITH_USB_VIDEO
# ifdef VBOX_WITH_USB_VIDEO_TEST
#ifdef VBOX_WITH_USB_CARDREADER
# ifdef VBOX_WITH_USB_CARDREADER_TEST
switch (mode)
case ClipboardMode_Disabled:
#ifdef VBOX_WITH_DRAG_AND_DROP
getGuest());
#ifdef VBOX_WITH_CROGL
if (fEnabled)
rc = pVMMDev->hgcmHostCall("VBoxSharedCrOpenGL", SHCRGL_HOST_FN_SET_CONSOLE, SHCRGL_CPARMS_SET_CONSOLE, &parm);
rc = pVMMDev->hgcmHostCall("VBoxSharedCrOpenGL", SHCRGL_HOST_FN_SET_VM, SHCRGL_CPARMS_SET_VM, &parm);
#ifdef VBOX_WITH_GUEST_PROPS
#ifdef VBOX_WITH_GUEST_CONTROL
if (fACPI)
fShowCpu = true;
if (fCpuHotPlug)
if (fCpuAttached)
catch (ConfigError &x)
return x.m_vrc;
#ifdef VBOX_WITH_EXTPACK
#undef H
return rc;
* Applies the CFGM overlay as specified by /VBoxInternal/XXX extra data
if (pszCFGMValueName)
if (pNode)
AssertLogRelMsgRCBreak(rc, ("failed to insert CFGM value '%s' to key '%s'\n", strCFGMValueUtf8.c_str(), pszExtraDataKey));
catch (ConfigError &x)
return x.m_vrc;
return rc;
void Console::setVMRuntimeErrorCallbackF(PVM pVM, void *pvConsole, uint32_t fFlags, const char *pszErrorId, const char *pszFormat, ...)
const char *pcszDevice,
unsigned uInstance,
bool fUseHostIOCache,
bool fBuiltinIoCache,
bool fSetupMerge,
unsigned uMergeSource,
unsigned uMergeTarget,
bool fAttachDetach,
bool fForceUnmount,
bool fHotplug,
unsigned uLUN;
if (pLunL0)
if (fAttachDetach)
return rc;
rc = PDMR3DeviceDetach(pVM, pcszDevice, uInstance, uLUN, fHotplug ? 0 : PDM_TACH_FLAGS_NOT_HOT_PLUG);
if (pCfg)
if (!pDrive)
if (!pDrive)
mfSnapshotFolderDiskTypeShown = true;
#ifdef RT_OS_WINDOWS
const char *pszUnit;
&& maxSize > 0
const char *pszUnitSiz;
const char *pszUnitMax;
const char *pszUnit;
#ifdef RT_OS_WINDOWS
mfSnapshotFolderSizeWarningShown = true;
#ifdef RT_OS_LINUX
&& !fUseHostIOCache
fUseHostIOCache = true;
fUseHostIOCache = true;
mfSnapshotFolderExt4WarningShown = true;
!!fPassthrough,
phrc);
return rc;
if (fAttachDetach)
if (paLedDevType)
catch (ConfigError &x)
return x.m_vrc;
#undef H
return VINF_SUCCESS;;
bool fPassthrough,
bool fUseHostIOCache,
bool fBuiltinIoCache,
bool fSetupMerge,
unsigned uMergeSource,
unsigned uMergeTarget,
const char *pcszBwGroup,
bool fDiscard,
AssertMsgReturnStmt(SUCCEEDED(hrc), ("hrc=%Rhrc\n", hrc), if (phrc) *phrc = hrc, Global::vboxStatusCodeFromCOM(hrc))
if (pMedium)
if (fHostDrive)
switch (enmType)
case DeviceType_DVD:
case DeviceType_Floppy:
case DeviceType_HardDisk:
if ( pMedium
"The image file '%ls' is inaccessible and is being ignored. Please select a different image file for the virtual %s drive.",
if (pMedium)
unsigned uImage = 0;
while (pTmp)
uImage++;
uImage--;
if (!fUseHostIOCache)
if ( fBuiltinIoCache
if (fSetupMerge)
switch (enmType)
case DeviceType_DVD:
case DeviceType_Floppy:
case DeviceType_HardDisk:
if (pcszBwGroup)
if (fDiscard)
bool fHostIP = true;
fHostIP = false;
uImage--;
if (!pMedium)
if (fSetupMerge)
fHostIP = false;
if (!fHostIP)
#undef H
catch (ConfigError &x)
return x.m_vrc;
return VINF_SUCCESS;
unsigned uInstance,
unsigned uLun,
bool fAttachDetach,
bool fIgnoreConnectFailure)
const char *pszPromiscuousGuestPolicy;
switch (enmPromiscModePolicy)
case NetworkAdapterPromiscModePolicy_AllowNetwork: pszPromiscuousGuestPolicy = "allow-network"; break;
if (pLunAD)
switch (eAttachmentType)
if (fSniffer)
InsertConfigString(pCfg, "TFTPPrefix", Utf8StrFmt("%ls%c%s", bstr.raw(), RTPATH_DELIMITER, "TFTP"));
if (mtu)
if (sockRcv)
if (sockSnd)
if (tcpRcv)
if (tcpSnd)
bool fValid = true;
switch (proto)
case NATProtocol_UDP:
case NATProtocol_TCP:
fValid = false;
if (!fValid)
if (port)
if (port)
switch (hrc)
case VERR_ACCESS_DENIED:
if (fSniffer)
if (fSniffer)
# if defined(RT_OS_DARWIN)
if (pszColon)
if (pszSpace)
if (pszColon)
AssertLogRelMsgFailed(("NetworkAttachmentType_Bridged: FindByName failed, rc=%Rhrc (0x%x)", hrc, hrc));
hrc = VBoxNetCfgWinGetComponentByGuid(pNc, &GUID_DEVCLASS_NET, (GUID*)hostIFGuid.raw(), pAdaptorComponent.asOutParam());
wchar_t * pswzBindName;
AssertLogRelMsgFailed(("NetworkAttachmentType_Bridged: WideCharToMultiByte failed, hr=%Rhrc (0x%x) err=%u\n", hrc, hrc, err));
AssertFailed();
AssertLogRelMsgFailed(("NetworkAttachmentType_Bridged: VBoxNetCfgWinGetComponentByGuid failed, hrc (0x%x)", hrc));
/* we're not releasing the INetCfg stuff here since we use it later to figure out whether it is wireless */
# if defined(RT_OS_FREEBSD)
switch (hrc)
case VERR_ACCESS_DENIED:
"permissions of that node, and that the net.link.tap.user_open "
"a member of that group. Make sure that these changes are permanent."), pszBridgedIfName, pszBridgedIfName);
if (iSock >= 0)
# if defined(RT_OS_DARWIN)
/** @todo Come up with a better deal here. Problem is that IHostNetworkInterface is completely useless here. */
if (iSock >= 0)
if (fSharedMacOnWire)
if (iSock >= 0)
if (fSharedMacOnWire)
NULL,
NULL);
bool fSharedMacOnWire = false;
&Oid,
sizeof(Oid),
&PhMedium,
sizeof(PhMedium),
&cbResult,
NULL))
fSharedMacOnWire = true;
Assert(winEr == ERROR_INVALID_PARAMETER || winEr == ERROR_NOT_SUPPORTED || winEr == ERROR_BAD_COMMAND);
if (fSharedMacOnWire)
AssertLogRelMsgFailed(("Console::configNetwork: CreateFile failed, err (0x%x), ignoring\n", winEr));
# if defined(RT_OS_SOLARIS)
if (fSniffer)
if (fSniffer)
#if defined(RT_OS_WINDOWS)
# ifndef VBOX_WITH_NETFLT
hrc = VBoxNetCfgWinGetComponentByGuid(pNc, &GUID_DEVCLASS_NET, (GUID*)hostIFGuid.raw(), pAdaptorComponent.asOutParam());
LogRel(("NetworkAttachmentType_HostOnly: VBoxNetCfgWinGetComponentByGuid failed, hrc=%Rhrc (0x%x)\n", hrc, hrc));
wchar_t * pswzBindName;
AssertLogRelMsgFailed(("NetworkAttachmentType_HostOnly: WideCharToMultiByte failed, hr=%Rhrc (0x%x) err=%u\n", hrc, hrc, err));
AssertFailed();
AssertLogRelMsgFailed(("NetworkAttachmentType_HostOnly: VBoxNetCfgWinGetComponentByGuid failed, hrc=%Rhrc (0x%x)\n", hrc, hrc));
InsertConfigInteger(pCfg, "IgnoreConnectFailure", (uint64_t)fIgnoreConnectFailure); /** @todo why is this windows only?? */
/* Grab the IP number from the 'vboxnetX' instance number (see netif.h) */
if (fSniffer)
switch (eAttachmentType)
if (fAttachDetach)
if (fEnabled)
catch (ConfigError &x)
return x.m_vrc;
#undef H
return VINF_SUCCESS;
#ifdef VBOX_WITH_GUEST_PROPS
void *names,
void *values,
void *timestamps,
void *flags)
&parms[0]);
const char *pszName,
const char *pszValue,
const char *pszFlags)
&parms[0]);
&paParm);
return rc;
#ifdef VBOX_WITH_GUEST_PROPS
if (valuesOut[i])
if (flagsOut[i])
(void *)papszNames,
(void *)papszValues,
(void *)pai64Timestamps,
(void *)papszFlags);
for (unsigned i = 0; i < cProps; ++i)
if (valuesOut[i])
if (flagsOut[i])
* information/branding and/or pre-release tags. */
return VINF_SUCCESS;
return VERR_NOT_SUPPORTED;
#ifdef VBOX_WITH_GUEST_CONTROL
return rc;
return VERR_NOT_SUPPORTED;