ConsoleImpl2.cpp revision 323bf6a10a0b2a254da0d1d04a570a061f77330d
fd9abdda70912b99b24e3bf1a38f26fde908a74cnd * VBox Console COM Class implementation
fd9abdda70912b99b24e3bf1a38f26fde908a74cnd * @remark We've split out the code that the 64-bit VC++ v8 compiler finds
f3ec420152ca921e4c1ce77782f51b53f659018dnd * problematic to optimize so we can disable optimizations and later,
f3ec420152ca921e4c1ce77782f51b53f659018dnd * perhaps, find a real solution for it (like rewriting the code and
f3ec420152ca921e4c1ce77782f51b53f659018dnd * to stop resemble a tonne of spaghetti).
f3ec420152ca921e4c1ce77782f51b53f659018dnd * Copyright (C) 2006-2010 Oracle Corporation
2e545ce2450a9953665f701bb05350f0d3f26275nd * This file is part of VirtualBox Open Source Edition (OSE), as
d29d9ab4614ff992b0e8de6e2b88d52b6f1f153erbowen * available from http://www.virtualbox.org. This file is free software;
d29d9ab4614ff992b0e8de6e2b88d52b6f1f153erbowen * you can redistribute it and/or modify it under the terms of the GNU
f3ec420152ca921e4c1ce77782f51b53f659018dnd * General Public License (GPL) as published by the Free Software
f3ec420152ca921e4c1ce77782f51b53f659018dnd * Foundation, in version 2 as it comes in the "COPYING" file of the
af33a4994ae2ff15bc67d19ff1a7feb906745bf8rbowen * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
3f08db06526d6901aa08c110b5bc7dde6bc39905nd * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
f3ec420152ca921e4c1ce77782f51b53f659018dnd/*******************************************************************************
3f08db06526d6901aa08c110b5bc7dde6bc39905nd* Header Files *
f3ec420152ca921e4c1ce77782f51b53f659018dnd*******************************************************************************/
f3ec420152ca921e4c1ce77782f51b53f659018dnd// for some reason Windows burns in sdk\...\winsock.h if this isn't included first
f3ec420152ca921e4c1ce77782f51b53f659018dnd// generated header
d03cac4d8ba79a23cfda410d35b614b0d805ba4cnilgun#if 0 /* enable to play with lots of memory. */
f3ec420152ca921e4c1ce77782f51b53f659018dnd#include <VBox/vmm/pdmapi.h> /* For PDMR3DriverAttach/PDMR3DriverDetach */
d03cac4d8ba79a23cfda410d35b614b0d805ba4cnilgun# include "HGCM.h" /** @todo it should be possible to register a service
d03cac4d8ba79a23cfda410d35b614b0d805ba4cnilgun * extension using a VMMDev callback. */
f3ec420152ca921e4c1ce77782f51b53f659018dnd#endif /* VBOX_WITH_GUEST_PROPS */
f3ec420152ca921e4c1ce77782f51b53f659018dnd# if defined(RT_OS_SOLARIS)
f3ec420152ca921e4c1ce77782f51b53f659018dnd#endif /* VBOX_WITH_NETFLT */
94cfb5d816f18c39adb74a03b6502ab73e35a73bnilgun * Method as described in Amit Singh's article:
d03cac4d8ba79a23cfda410d35b614b0d805ba4cnilgun typedef struct
f3ec420152ca921e4c1ce77782f51b53f659018dnd io_service_t service = IOServiceGetMatchingService(kIOMasterPortDefault,
d03cac4d8ba79a23cfda410d35b614b0d805ba4cnilgun kern_return_t kr = IOServiceOpen(service, mach_task_self(), 0, &port);
d03cac4d8ba79a23cfda410d35b614b0d805ba4cnilgun AppleSMCBuffer inputStruct = { 0, {0}, 32, {0}, 5, };
f3ec420152ca921e4c1ce77782f51b53f659018dnd for (int i = 0; i < 2; i++)
f3ec420152ca921e4c1ce77782f51b53f659018dnd inputStruct.key = (uint32_t)((i == 0) ? 'OSK0' : 'OSK1');
f3ec420152ca921e4c1ce77782f51b53f659018dnd (const void *)&inputStruct,
f3ec420152ca921e4c1ce77782f51b53f659018dnd for (int j = 0; j < 32; j++)
f3ec420152ca921e4c1ce77782f51b53f659018dnd#endif /* RT_OS_DARWIN */
f3ec420152ca921e4c1ce77782f51b53f659018dnd/* Darwin compile kludge */
f3ec420152ca921e4c1ce77782f51b53f659018dnd/* Comment out the following line to remove VMWare compatibility hack. */
f3ec420152ca921e4c1ce77782f51b53f659018dnd * Translate IDE StorageControllerType_T to string representation.
f3ec420152ca921e4c1ce77782f51b53f659018dndconst char* controllerString(StorageControllerType_T enmType)
f3ec420152ca921e4c1ce77782f51b53f659018dnd return "PIIX3";
f3ec420152ca921e4c1ce77782f51b53f659018dnd return "PIIX4";
f3ec420152ca921e4c1ce77782f51b53f659018dnd return "ICH6";
f3ec420152ca921e4c1ce77782f51b53f659018dnd return "Unknown";
f3ec420152ca921e4c1ce77782f51b53f659018dnd * Simple class for storing network boot information.
f3ec420152ca921e4c1ce77782f51b53f659018dnd ULONG lval = mBootPrio - 1; /* 0 will wrap around and get the lowest priority. */
f3ec420152ca921e4c1ce77782f51b53f659018dnd return lval < rval; /* Zero compares as highest number (lowest prio). */
f3ec420152ca921e4c1ce77782f51b53f659018dndstatic int findEfiRom(IVirtualBox* vbox, FirmwareType_T aFirmwareType, Utf8Str *pEfiRomFile)
f3ec420152ca921e4c1ce77782f51b53f659018dnd HRESULT hrc = vbox->CheckFirmwarePresent(aFirmwareType, empty.raw(),
f3ec420152ca921e4c1ce77782f51b53f659018dnd AssertComRCReturn(hrc, Global::vboxStatusCodeFromCOM(hrc));
f3ec420152ca921e4c1ce77782f51b53f659018dndstatic int getSmcDeviceKey(IMachine *pMachine, BSTR *aKey, bool *pfGetKeyFromRealSMC)
f3ec420152ca921e4c1ce77782f51b53f659018dnd * The extra data takes precedence (if non-zero).
f3ec420152ca921e4c1ce77782f51b53f659018dnd HRESULT hrc = pMachine->GetExtraData(Bstr("VBoxInternal2/SmcDeviceKey").raw(),
f3ec420152ca921e4c1ce77782f51b53f659018dnd * Query it here and now.
f3ec420152ca921e4c1ce77782f51b53f659018dnd LogRel(("Warning: DarwinSmcKey failed with rc=%Rrc!\n", rc));
f3ec420152ca921e4c1ce77782f51b53f659018dnd * Is it apple hardware in bootcamp?
f3ec420152ca921e4c1ce77782f51b53f659018dnd /** @todo implement + test RTSYSDMISTR_MANUFACTURER on all hosts.
f3ec420152ca921e4c1ce77782f51b53f659018dnd * Currently falling back on the product name. */
f3ec420152ca921e4c1ce77782f51b53f659018dnd RTSystemQueryDmiString(RTSYSDMISTR_MANUFACTURER, szManufacturer, sizeof(szManufacturer));
d03cac4d8ba79a23cfda410d35b614b0d805ba4cnilgun RTSystemQueryDmiString(RTSYSDMISTR_PRODUCT_NAME, szProdName, sizeof(szProdName));
f3ec420152ca921e4c1ce77782f51b53f659018dnd && RT_C_IS_DIGIT(szProdName[strlen(szProdName) - 1]) /* version number */
727872d18412fc021f03969b8641810d8896820bhumbedooh * VC++ 8 / amd64 has some serious trouble with the next functions.
0d0ba3a410038e179b695446bb149cce6264e0abnd * As a temporary measure, we'll drop global optimizations.
0d0ba3a410038e179b695446bb149cce6264e0abnd const char *pcszName)
7fec19672a491661b2fe4b29f685bc7f4efa64d4nd : RTCError(Utf8StrFmt("%s failed: rc=%Rrc, pcszName=%s", pcszFunction, vrc, pcszName)),
f3ec420152ca921e4c1ce77782f51b53f659018dnd AssertMsgFailed(("%s\n", what())); // in strict mode, hit a breakpoint here
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;
int iBridgesMissed = 0;
iBase++;
return hrc;
return hrc;
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);
atts[j],
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;
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
switch (mode)
case ClipboardMode_Disabled:
#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,
unsigned uLUN;
if (pLunL0)
if (fAttachDetach)
return rc;
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,
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)
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 "
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 defined(VBOX_WITH_VDE)
switch (eAttachmentType)
#if defined(VBOX_WITH_VDE)
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])
return VINF_SUCCESS;
return VERR_NOT_SUPPORTED;
#ifdef VBOX_WITH_GUEST_CONTROL
return rc;
return VERR_NOT_SUPPORTED;