ConsoleImpl2.cpp revision 0220076bc8def0ee99c7c43471290b2224756225
/** $Id$ */
/** @file
* VBox Console COM Class implementation
*
* @remark We've split out the code that the 64-bit VC++ v8 compiler
* finds problematic to optimize so we can disable optimizations
* and later, perhaps, find a real solution for it.
*/
/*
* Copyright (C) 2006-2007 innotek GmbH
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* General Public License (GPL) as published by the Free Software
* Foundation, in version 2 as it comes in the "COPYING" file of the
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
*/
/*******************************************************************************
* Header Files *
*******************************************************************************/
#include "ConsoleImpl.h"
#include "DisplayImpl.h"
#include "VMMDev.h"
// generated header
#include "SchemaDefs.h"
#include "Logging.h"
/*
* VC++ 8 / amd64 has some serious trouble with this function.
* As a temporary measure, we'll drop global optimizations.
*/
#if defined(_MSC_VER) && defined(RT_ARCH_AMD64)
#endif
/**
* Construct the VM configuration tree (CFGM).
*
* This is a callback for VMR3Create() call. It is called from CFGMR3Init()
* is done here.
*
* @param pVM VM handle.
* @param pvConsole Pointer to the VMPowerUpTask object.
* @return VBox status code.
*
* @note Locks the Console object for writing.
*/
{
/* Note: hardcoded assumption about number of slots; see rom bios */
bool afPciDeviceNo[15] = {false};
#if !defined (VBOX_WITH_XPCOM)
{
/* initialize COM */
}
#endif
/* lock the console because we widely use internal fields and methods */
int rc;
#define STR_FREE() do { if (str) { SysFreeString(str); str = NULL; } if (psz) { RTStrFree(psz); psz = NULL; } } while (0)
#define RC_CHECK() do { if (VBOX_FAILURE(rc)) { AssertMsgFailed(("rc=%Vrc\n", rc)); STR_FREE(); return rc; } } while (0)
#define H() do { if (FAILED(hrc)) { AssertMsgFailed(("hrc=%#x\n", hrc)); STR_FREE(); return VERR_GENERAL_FAILURE; } } while (0)
/*
* Get necessary objects and frequently used parameters.
*/
/*
* Get root node first.
* This is the only node in the tree.
*/
/*
* Set the root level values.
*/
STR_CONV();
STR_FREE();
/** @todo Config: RawR0, PATMEnabled and CASMEnabled needs attention later. */
/* hardware virtualization extensions */
if (hwVirtExEnabled == TSBool_Default)
{
/* check the default value */
}
else
#ifndef RT_OS_DARWIN /** @todo Implement HWVirtExt on darwin. See #1865. */
if (fHWVirtExEnabled)
{
}
#endif
/* Physical Address Extension (PAE) */
BOOL fEnablePAE = false;
/*
* Virtual IDE controller type.
*/
switch (controllerType)
{
case IDEControllerType_PIIX3:
break;
case IDEControllerType_PIIX4:
break;
default:
return VERR_INVALID_PARAMETER;
}
/*
* PDM config.
* Load drivers in VBoxC.[so|dll]
*/
#ifdef VBOX_WITH_XPCOM
// VBoxC is located in the components subdirectory
char szPathVBoxC[RTPATH_MAX];
#else
#endif
/*
* Devices
*/
/*
* PC Arch.
*/
/*
* PC Bios.
*/
{
AssertMsgFailed (("Too many boot devices %d\n",
return VERR_INVALID_PARAMETER;
}
{
char szParamName[] = "BootDeviceX";
const char *pszBootDevice;
switch (bootDevice)
{
case DeviceType_Null:
pszBootDevice = "NONE";
break;
case DeviceType_HardDisk:
pszBootDevice = "IDE";
break;
case DeviceType_DVD:
pszBootDevice = "DVD";
break;
case DeviceType_Floppy:
pszBootDevice = "FLOPPY";
break;
case DeviceType_Network:
pszBootDevice = "LAN";
break;
default:
return VERR_INVALID_PARAMETER;
}
}
/*
* The time offset
*/
/*
* ACPI
*/
if (fACPI)
{
afPciDeviceNo[7] = true;
}
/*
* DMA
*/
/*
* PCI bus.
*/
/*
* PS/2 keyboard & mouse.
*/
/*
* i82078 Floppy drive controller
*/
if (fFloppyEnabled)
{
/* Attach the status driver */
if (floppyImage)
{
STR_CONV();
STR_FREE();
}
else
{
if (hostFloppyDrive)
{
STR_CONV();
STR_FREE();
}
else
{
}
}
}
/*
* i8254 Programmable Interval Timer And Dummy Speaker
*/
#ifdef DEBUG
#endif
/*
* i8259 Programmable Interrupt Controller.
*/
/*
* Advanced Programmable Interrupt Controller.
*/
if (fIOAPIC)
{
/*
* I/O Advanced Programmable Interrupt Controller.
*/
}
/*
* RTC MC146818.
*/
/*
* VGA.
*/
afPciDeviceNo[2] = true;
/*
* BIOS logo
*/
/*
* Boot menu
*/
int value;
switch (bootMenuMode)
{
value = 0;
break;
value = 1;
break;
default:
value = 2;
}
/* Custom VESA mode list */
unsigned cModes = 0;
{
char szExtraDataKey[sizeof("CustomVideoModeXX")];
break;
STR_CONV();
STR_FREE();
cModes++;
}
/* VESA height reduction */
if (pFramebuffer)
{
}
else
{
/* If framebuffer is not available, there is no height reduction. */
ulHeightReduction = 0;
}
/* Attach the display. */
/*
* IDE (update this when the main interface changes)
*/
afPciDeviceNo[1] = true;
/* Attach the status driver */
/*
* SATA controller
*/
if (sataController)
{
if (enabled)
{
afPciDeviceNo[13] = true;
/* Needed configuration values for the bios. */
for (uint32_t i = 0; i < 4; i++)
{
static const char *s_apszConfig[4] =
{ "PrimaryMaster", "PrimarySlave", "SecondaryMaster", "SecondarySlave" };
static const char *s_apszBiosConfig[4] =
{ "SataPrimaryMasterLUN", "SataPrimarySlaveLUN", "SataSecondaryMasterLUN", "SataSecondarySlaveLUN" };
}
/* Attach the status driver */
}
}
/* Attach the harddisks */
&& fMore)
{
int iLUN;
switch (enmBus)
{
case StorageBus_IDE:
{
{
return VERR_GENERAL_FAILURE;
}
{
return VERR_GENERAL_FAILURE;
}
}
break;
case StorageBus_SATA:
break;
default:
return VERR_GENERAL_FAILURE;
}
/* Can be NULL if SATA controller is not enabled and current hard disk is attached to SATA controller. */
if (pHardDiskCtl)
{
char szLUN[16];
{
STR_CONV();
STR_FREE();
/* Create an inversed tree of parents. */
{
if (!curHardDisk)
break;
STR_CONV();
STR_FREE();
/* next */
}
}
else if (hddType == HardDiskStorageType_ISCSIHardDisk)
{
/* Set up the iSCSI initiator driver configuration. */
STR_CONV();
STR_FREE();
// @todo currently there is no Initiator name config.
STR_CONV();
if (port != 0)
{
char *pszTN;
}
else
{
}
STR_FREE();
if (str)
{
STR_CONV();
STR_FREE();
}
if (str)
{
STR_CONV();
STR_FREE();
}
// @todo currently there is no target username config.
//rc = CFGMR3InsertString(pCfg, "TargetUsername", ""); RC_CHECK();
// @todo currently there is no target password config.
//rc = CFGMR3InsertString(pCfg, "TargetSecret", ""); RC_CHECK();
/* The iSCSI initiator needs an attached iSCSI transport driver. */
/* Currently the transport driver has no config options. */
}
else if (hddType == HardDiskStorageType_VMDKImage)
{
#if 1 /* Enable new VD container code (and new VMDK), as the bugs are fixed. */
#else
#endif
STR_CONV();
STR_FREE();
}
else if (hddType == HardDiskStorageType_CustomHardDisk)
{
STR_CONV();
STR_FREE();
STR_CONV();
STR_FREE();
}
else if (hddType == HardDiskStorageType_VHDImage)
{
STR_CONV();
STR_FREE();
}
else
AssertFailed();
}
}
H();
if (dvdDrive)
{
// ASSUME: DVD drive is always attached to LUN#2 (i.e. secondary IDE master)
if (hostDvdDrive)
{
STR_CONV();
STR_FREE();
}
else
{
if (dvdImage)
{
STR_CONV();
STR_FREE();
}
}
}
/*
* Network adapters
*/
#ifdef VBOX_WITH_E1000
#endif
{
if (!fEnabled)
continue;
/*
* The virtual hardware type. Create appropriate device first.
*/
switch (adapterType)
{
break;
#ifdef VBOX_WITH_E1000
break;
#endif
default:
AssertMsgFailed(("Invalid network adapter type '%d' for slot '%d'",
return VERR_GENERAL_FAILURE;
}
/* the first network card gets the PCI ID 3, the next 3 gets 8..10. */
afPciDeviceNo[iPciDeviceNo] = true;
/*
* The virtual hardware type. PCNet supports two types.
*/
switch (adapterType)
{
break;
break;
}
/*
* Get the MAC address and convert it to binary representation
*/
for (uint32_t i = 0; i < 6; i++)
{
if (c1 > 9)
c1 -= 7;
if (c2 > 9)
c2 -= 7;
}
/*
* Check if the cable is supposed to be unplugged
*/
/*
* Line speed to report from custom drivers
*/
/*
* Attach the status driver.
*/
rc = CFGMR3InsertInteger(pCfg, "papLeds", (uintptr_t)&pConsole->mapNetworkLeds[ulInstance]); RC_CHECK();
/*
* Enable the packet sniffer if requested.
*/
if (fSniffer)
{
/* insert the sniffer filter driver. */
if (str) /* check convention for indicating default file. */
{
STR_CONV();
STR_FREE();
}
}
switch (networkAttachment)
{
break;
{
if (fSniffer)
{
}
else
{
}
/* (Port forwarding goes here.) */
/* Configure TFTP prefix and boot filename. */
STR_CONV();
{
char *pszTFTPPrefix = NULL;
}
STR_FREE();
STR_CONV();
char *pszBootFile = NULL;
STR_FREE();
break;
}
{
/*
* Perform the attachment if required (don't return on error!)
*/
{
{
if (fSniffer)
{
}
else
{
}
# if defined(RT_OS_SOLARIS)
if (!tapDeviceName.isEmpty())
/* TAP setup application/script */
if (!tapSetupApp.isEmpty())
/* TAP terminate application/script */
if (!tapTerminateApp.isEmpty())
/* "FileHandle" must NOT be inserted here, it is done in DrvTAP.cpp */
# ifdef VBOX_WITH_CROSSBOW
/* Crossbow: needs the MAC address for setting up TAP. */
# endif
# else
# endif
}
#elif defined(RT_OS_WINDOWS)
if (fSniffer)
{
}
else
{
}
{
}
else
{
char szDriverGUID[256] = {0};
/* add curly brackets */
szDriverGUID[0] = '{';
}
#else
# error "Port me"
#endif
}
else
{
switch (hrc)
{
#ifdef RT_OS_LINUX
case VERR_ACCESS_DENIED:
"change the group of that node and make yourself a member of that group. Make "
"sure that these changes are permanent, especially if you are "
"using udev"));
#endif /* RT_OS_LINUX */
default:
AssertMsgFailed(("Could not attach to host interface! Bad!\n"));
"Failed to initialize Host Interface Networking"));
}
}
break;
}
{
STR_CONV();
{
if (fSniffer)
{
}
else
{
}
}
STR_FREE();
break;
}
default:
AssertMsgFailed(("should not get here!\n"));
break;
}
}
/*
* Serial (UART) Ports
*/
{
if (serialPort)
if (!fEnabled)
continue;
if (HostMode != PortMode_Disconnected)
{
if (HostMode == PortMode_HostPipe)
{
}
else if (HostMode == PortMode_HostDevice)
{
}
}
}
/*
* Parallel (LPT) Ports
*/
{
if (parallelPort)
if (!fEnabled)
continue;
}
/*
* VMM Device
*/
afPciDeviceNo[4] = true;
/* the VMM device's Main driver */
/*
* Attach the status driver.
*/
/*
* Audio Sniffer Device
*/
/* the Audio Sniffer device's Main driver */
/*
* AC'97 ICH / SoundBlaster16 audio
*/
if (audioAdapter)
if (enabled)
{
switch (audioController)
{
case AudioControllerType_AC97:
{
/* default: ICH AC97 */
afPciDeviceNo[5] = true;
break;
}
case AudioControllerType_SB16:
{
/* legacy SoundBlaster16 */
break;
}
}
/* the Audio driver */
switch (audioDriver)
{
case AudioDriverType_Null:
{
break;
}
#ifdef RT_OS_WINDOWS
#ifdef VBOX_WITH_WINMM
case AudioDriverType_WinMM:
{
break;
}
#endif
{
break;
}
#endif /* RT_OS_WINDOWS */
#ifdef RT_OS_SOLARIS
case AudioDriverType_SolAudio:
{
break;
}
#endif
#ifdef RT_OS_LINUX
case AudioDriverType_OSS:
{
break;
}
# ifdef VBOX_WITH_ALSA
case AudioDriverType_ALSA:
{
break;
}
# endif
# ifdef VBOX_WITH_PULSE
case AudioDriverType_Pulse:
{
break;
}
# endif
#endif /* RT_OS_LINUX */
#ifdef RT_OS_DARWIN
{
break;
}
#endif
}
STR_CONV();
STR_FREE();
}
/*
* The USB Controller.
*/
if (USBCtlPtr)
{
if (fEnabled)
{
afPciDeviceNo[6] = true;
/*
* Attach the status driver.
*/
#ifdef VBOX_WITH_EHCI
if (fEnabled)
{
afPciDeviceNo[11] = true;
/*
* Attach the status driver.
*/
}
else
#endif
{
/*
* Enable the 2.0 -> 1.1 device morphing of proxied devies to keep windows quiet.
*/
// The following breaks stuff, but it makes MSDs work in vista. (I include it here so
// that it's documented somewhere.) Users needing it can use:
// VBoxManage setextradata "myvm" "VBoxInternal/USB/USBProxy/GlobalConfig/Force11PacketSize" 1
//rc = CFGMR3InsertInteger(pCfg, "Force11PacketSize", true); RC_CHECK();
}
}
}
/*
* Clipboard
*/
{
if (mode != ClipboardMode_Disabled)
{
/* Load the service */
if (VBOX_FAILURE (rc))
{
/* That is not a fatal failure. */
rc = VINF_SUCCESS;
}
else
{
/* Setup the service. */
switch (mode)
{
default:
case ClipboardMode_Disabled:
{
LogRel(("VBoxSharedClipboard mode: Off\n"));
break;
}
{
LogRel(("VBoxSharedClipboard mode: Guest to Host\n"));
break;
}
{
LogRel(("VBoxSharedClipboard mode: Host to Guest\n"));
break;
}
{
LogRel(("VBoxSharedClipboard mode: Bidirectional\n"));
break;
}
}
pConsole->mVMMDev->hgcmHostCall ("VBoxSharedClipboard", VBOX_SHARED_CLIPBOARD_HOST_FN_SET_MODE, 1, &parm);
Log(("Set VBoxSharedClipboard mode\n"));
}
}
}
/*
* CFGM overlay handling.
*
* Here we check the extra data entries for CFGM values
* and create the nodes and insert the values on the fly. Existing
* values will be removed and reinserted. If a value is a valid number,
* it will be inserted as a number, otherwise as a string.
*
* We first perform a run on global extra data, then on the machine
* extra data to support global settings with local overrides.
*
*/
bool fGlobalExtraData = true;
for (;;)
{
/* get the next key */
if (fGlobalExtraData)
else
/* stop if for some reason there's nothing more to request */
{
/* if we're out of global keys, continue with machine, otherwise we're done */
if (fGlobalExtraData)
{
fGlobalExtraData = false;
continue;
}
break;
}
/* we only care about keys starting with "VBoxInternal/" */
continue;
if (pszCFGMValueName)
{
/* terminate the node and advance to the value */
*pszCFGMValueName = '\0';
/* does the node already exist? */
if (pNode)
{
/* the value might already exist, remove it to be safe */
}
else
{
/* create the node */
continue;
}
}
else
{
/* the value might already exist, remove it to be safe */
}
/* now let's have a look at the value */
/* empty value means remove value which we've already done */
if (pszCFGMValue && *pszCFGMValue)
{
/* if it's a valid number, we'll insert it as such, otherwise string */
)
{
}
else
{
}
}
}
#undef H
/* Register VM state change handler */
if (VBOX_SUCCESS (rc))
/* Register VM runtime error handler */
if (VBOX_SUCCESS (rc))
/* Save the VM pointer in the machine object */
return rc;
}