VirtualBox

source: vbox/trunk/src/VBox/Main/src-client/ConsoleImpl2.cpp@ 40767

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

also enumerate guest properties during guru meditation

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 202.1 KB
Line 
1/* $Id: ConsoleImpl2.cpp 40767 2012-04-05 09:47:33Z vboxsync $ */
2/** @file
3 * VBox Console COM Class implementation - VM Configuration Bits.
4 *
5 * @remark We've split out the code that the 64-bit VC++ v8 compiler finds
6 * problematic to optimize so we can disable optimizations and later,
7 * perhaps, find a real solution for it (like rewriting the code and
8 * to stop resemble a tonne of spaghetti).
9 */
10
11/*
12 * Copyright (C) 2006-2012 Oracle Corporation
13 *
14 * This file is part of VirtualBox Open Source Edition (OSE), as
15 * available from http://www.215389.xyz. This file is free software;
16 * you can redistribute it and/or modify it under the terms of the GNU
17 * General Public License (GPL) as published by the Free Software
18 * Foundation, in version 2 as it comes in the "COPYING" file of the
19 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
20 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
21 */
22
23/*******************************************************************************
24* Header Files *
25*******************************************************************************/
26// for some reason Windows burns in sdk\...\winsock.h if this isn't included first
27#include "VBox/com/ptr.h"
28
29#include "ConsoleImpl.h"
30#include "DisplayImpl.h"
31#ifdef VBOX_WITH_GUEST_CONTROL
32# include "GuestImpl.h"
33#endif
34#ifdef VBOX_WITH_DRAG_AND_DROP
35# include "GuestDnDImpl.h"
36#endif
37#include "VMMDev.h"
38#include "Global.h"
39#ifdef VBOX_WITH_PCI_PASSTHROUGH
40# include "PciRawDevImpl.h"
41#endif
42
43// generated header
44#include "SchemaDefs.h"
45
46#include "AutoCaller.h"
47#include "Logging.h"
48
49#include <iprt/buildconfig.h>
50#include <iprt/ctype.h>
51#include <iprt/dir.h>
52#include <iprt/file.h>
53#include <iprt/param.h>
54#include <iprt/path.h>
55#include <iprt/string.h>
56#include <iprt/system.h>
57#include <iprt/cpp/exception.h>
58#if 0 /* enable to play with lots of memory. */
59# include <iprt/env.h>
60#endif
61#include <iprt/stream.h>
62
63#include <VBox/vmm/vmapi.h>
64#include <VBox/err.h>
65#include <VBox/param.h>
66#include <VBox/vmm/pdmapi.h> /* For PDMR3DriverAttach/PDMR3DriverDetach */
67#include <VBox/version.h>
68#include <VBox/HostServices/VBoxClipboardSvc.h>
69#ifdef VBOX_WITH_CROGL
70# include <VBox/HostServices/VBoxCrOpenGLSvc.h>
71#endif
72#ifdef VBOX_WITH_GUEST_PROPS
73# include <VBox/HostServices/GuestPropertySvc.h>
74# include <VBox/com/defs.h>
75# include <VBox/com/array.h>
76# include "HGCM.h" /** @todo it should be possible to register a service
77 * extension using a VMMDev callback. */
78# include <vector>
79#endif /* VBOX_WITH_GUEST_PROPS */
80#include <VBox/intnet.h>
81
82#include <VBox/com/com.h>
83#include <VBox/com/string.h>
84#include <VBox/com/array.h>
85
86#ifdef VBOX_WITH_NETFLT
87# if defined(RT_OS_SOLARIS)
88# include <zone.h>
89# elif defined(RT_OS_LINUX)
90# include <unistd.h>
91# include <sys/ioctl.h>
92# include <sys/socket.h>
93# include <linux/types.h>
94# include <linux/if.h>
95# include <linux/wireless.h>
96# elif defined(RT_OS_FREEBSD)
97# include <unistd.h>
98# include <sys/types.h>
99# include <sys/ioctl.h>
100# include <sys/socket.h>
101# include <net/if.h>
102# include <net80211/ieee80211_ioctl.h>
103# endif
104# if defined(RT_OS_WINDOWS)
105# include <VBox/VBoxNetCfg-win.h>
106# include <Ntddndis.h>
107# include <devguid.h>
108# else
109# include <HostNetworkInterfaceImpl.h>
110# include <netif.h>
111# include <stdlib.h>
112# endif
113#endif /* VBOX_WITH_NETFLT */
114
115#include "DHCPServerRunner.h"
116#include "BusAssignmentManager.h"
117#ifdef VBOX_WITH_EXTPACK
118# include "ExtPackManagerImpl.h"
119#endif
120
121#if defined(RT_OS_DARWIN)
122
123# include "IOKit/IOKitLib.h"
124
125static int DarwinSmcKey(char *pabKey, uint32_t cbKey)
126{
127 /*
128 * Method as described in Amit Singh's article:
129 * http://osxbook.com/book/bonus/chapter7/tpmdrmmyth/
130 */
131 typedef struct
132 {
133 uint32_t key;
134 uint8_t pad0[22];
135 uint32_t datasize;
136 uint8_t pad1[10];
137 uint8_t cmd;
138 uint32_t pad2;
139 uint8_t data[32];
140 } AppleSMCBuffer;
141
142 AssertReturn(cbKey >= 65, VERR_INTERNAL_ERROR);
143
144 io_service_t service = IOServiceGetMatchingService(kIOMasterPortDefault,
145 IOServiceMatching("AppleSMC"));
146 if (!service)
147 return VERR_NOT_FOUND;
148
149 io_connect_t port = (io_connect_t)0;
150 kern_return_t kr = IOServiceOpen(service, mach_task_self(), 0, &port);
151 IOObjectRelease(service);
152
153 if (kr != kIOReturnSuccess)
154 return RTErrConvertFromDarwin(kr);
155
156 AppleSMCBuffer inputStruct = { 0, {0}, 32, {0}, 5, };
157 AppleSMCBuffer outputStruct;
158 size_t cbOutputStruct = sizeof(outputStruct);
159
160 for (int i = 0; i < 2; i++)
161 {
162 inputStruct.key = (uint32_t)((i == 0) ? 'OSK0' : 'OSK1');
163 kr = IOConnectCallStructMethod((mach_port_t)port,
164 (uint32_t)2,
165 (const void *)&inputStruct,
166 sizeof(inputStruct),
167 (void *)&outputStruct,
168 &cbOutputStruct);
169 if (kr != kIOReturnSuccess)
170 {
171 IOServiceClose(port);
172 return RTErrConvertFromDarwin(kr);
173 }
174
175 for (int j = 0; j < 32; j++)
176 pabKey[j + i*32] = outputStruct.data[j];
177 }
178
179 IOServiceClose(port);
180
181 pabKey[64] = 0;
182
183 return VINF_SUCCESS;
184}
185
186#endif /* RT_OS_DARWIN */
187
188/* Darwin compile kludge */
189#undef PVM
190
191/* Comment out the following line to remove VMWare compatibility hack. */
192#define VMWARE_NET_IN_SLOT_11
193
194/**
195 * Translate IDE StorageControllerType_T to string representation.
196 */
197const char* controllerString(StorageControllerType_T enmType)
198{
199 switch (enmType)
200 {
201 case StorageControllerType_PIIX3:
202 return "PIIX3";
203 case StorageControllerType_PIIX4:
204 return "PIIX4";
205 case StorageControllerType_ICH6:
206 return "ICH6";
207 default:
208 return "Unknown";
209 }
210}
211
212/**
213 * Simple class for storing network boot information.
214 */
215struct BootNic
216{
217 ULONG mInstance;
218 PciBusAddress mPciAddress;
219
220 ULONG mBootPrio;
221 bool operator < (const BootNic &rhs) const
222 {
223 ULONG lval = mBootPrio - 1; /* 0 will wrap around and get the lowest priority. */
224 ULONG rval = rhs.mBootPrio - 1;
225 return lval < rval; /* Zero compares as highest number (lowest prio). */
226 }
227};
228
229static int findEfiRom(IVirtualBox* vbox, FirmwareType_T aFirmwareType, Utf8Str *pEfiRomFile)
230{
231 Bstr aFilePath, empty;
232 BOOL fPresent = FALSE;
233 HRESULT hrc = vbox->CheckFirmwarePresent(aFirmwareType, empty.raw(),
234 empty.asOutParam(), aFilePath.asOutParam(), &fPresent);
235 AssertComRCReturn(hrc, Global::vboxStatusCodeFromCOM(hrc));
236
237 if (!fPresent)
238 {
239 LogRel(("Failed to find an EFI ROM file.\n"));
240 return VERR_FILE_NOT_FOUND;
241 }
242
243 *pEfiRomFile = Utf8Str(aFilePath);
244
245 return VINF_SUCCESS;
246}
247
248static int getSmcDeviceKey(IMachine *pMachine, BSTR *aKey, bool *pfGetKeyFromRealSMC)
249{
250 *pfGetKeyFromRealSMC = false;
251
252 /*
253 * The extra data takes precedence (if non-zero).
254 */
255 HRESULT hrc = pMachine->GetExtraData(Bstr("VBoxInternal2/SmcDeviceKey").raw(),
256 aKey);
257 if (FAILED(hrc))
258 return Global::vboxStatusCodeFromCOM(hrc);
259 if ( SUCCEEDED(hrc)
260 && *aKey
261 && **aKey)
262 return VINF_SUCCESS;
263
264#ifdef RT_OS_DARWIN
265 /*
266 * Query it here and now.
267 */
268 char abKeyBuf[65];
269 int rc = DarwinSmcKey(abKeyBuf, sizeof(abKeyBuf));
270 if (SUCCEEDED(rc))
271 {
272 Bstr(abKeyBuf).detachTo(aKey);
273 return rc;
274 }
275 LogRel(("Warning: DarwinSmcKey failed with rc=%Rrc!\n", rc));
276
277#else
278 /*
279 * Is it apple hardware in bootcamp?
280 */
281 /** @todo implement + test RTSYSDMISTR_MANUFACTURER on all hosts.
282 * Currently falling back on the product name. */
283 char szManufacturer[256];
284 szManufacturer[0] = '\0';
285 RTSystemQueryDmiString(RTSYSDMISTR_MANUFACTURER, szManufacturer, sizeof(szManufacturer));
286 if (szManufacturer[0] != '\0')
287 {
288 if ( !strcmp(szManufacturer, "Apple Computer, Inc.")
289 || !strcmp(szManufacturer, "Apple Inc.")
290 )
291 *pfGetKeyFromRealSMC = true;
292 }
293 else
294 {
295 char szProdName[256];
296 szProdName[0] = '\0';
297 RTSystemQueryDmiString(RTSYSDMISTR_PRODUCT_NAME, szProdName, sizeof(szProdName));
298 if ( ( !strncmp(szProdName, "Mac", 3)
299 || !strncmp(szProdName, "iMac", 4)
300 || !strncmp(szProdName, "iMac", 4)
301 || !strncmp(szProdName, "Xserve", 6)
302 )
303 && !strchr(szProdName, ' ') /* no spaces */
304 && RT_C_IS_DIGIT(szProdName[strlen(szProdName) - 1]) /* version number */
305 )
306 *pfGetKeyFromRealSMC = true;
307 }
308
309 int rc = VINF_SUCCESS;
310#endif
311
312 return rc;
313}
314
315
316/*
317 * VC++ 8 / amd64 has some serious trouble with the next functions.
318 * As a temporary measure, we'll drop global optimizations.
319 */
320#if defined(_MSC_VER) && defined(RT_ARCH_AMD64)
321# pragma optimize("g", off)
322#endif
323
324static const char *const g_apszIDEDrives[4] =
325 { "PrimaryMaster", "PrimarySlave", "SecondaryMaster", "SecondarySlave" };
326
327class ConfigError : public RTCError
328{
329public:
330
331 ConfigError(const char *pcszFunction,
332 int vrc,
333 const char *pcszName)
334 : RTCError(Utf8StrFmt("%s failed: rc=%Rrc, pcszName=%s", pcszFunction, vrc, pcszName)),
335 m_vrc(vrc)
336 {
337 AssertMsgFailed(("%s\n", what())); // in strict mode, hit a breakpoint here
338 }
339
340 int m_vrc;
341};
342
343
344/**
345 * Helper that calls CFGMR3InsertString and throws an RTCError if that
346 * fails (C-string variant).
347 * @param pParent See CFGMR3InsertStringN.
348 * @param pcszNodeName See CFGMR3InsertStringN.
349 * @param pcszValue The string value.
350 */
351static void InsertConfigString(PCFGMNODE pNode,
352 const char *pcszName,
353 const char *pcszValue)
354{
355 int vrc = CFGMR3InsertString(pNode,
356 pcszName,
357 pcszValue);
358 if (RT_FAILURE(vrc))
359 throw ConfigError("CFGMR3InsertString", vrc, pcszName);
360}
361
362/**
363 * Helper that calls CFGMR3InsertString and throws an RTCError if that
364 * fails (Utf8Str variant).
365 * @param pParent See CFGMR3InsertStringN.
366 * @param pcszNodeName See CFGMR3InsertStringN.
367 * @param rStrValue The string value.
368 */
369static void InsertConfigString(PCFGMNODE pNode,
370 const char *pcszName,
371 const Utf8Str &rStrValue)
372{
373 int vrc = CFGMR3InsertStringN(pNode,
374 pcszName,
375 rStrValue.c_str(),
376 rStrValue.length());
377 if (RT_FAILURE(vrc))
378 throw ConfigError("CFGMR3InsertStringLengthKnown", vrc, pcszName);
379}
380
381/**
382 * Helper that calls CFGMR3InsertString and throws an RTCError if that
383 * fails (Bstr variant).
384 *
385 * @param pParent See CFGMR3InsertStringN.
386 * @param pcszNodeName See CFGMR3InsertStringN.
387 * @param rBstrValue The string value.
388 */
389static void InsertConfigString(PCFGMNODE pNode,
390 const char *pcszName,
391 const Bstr &rBstrValue)
392{
393 InsertConfigString(pNode, pcszName, Utf8Str(rBstrValue));
394}
395
396/**
397 * Helper that calls CFGMR3InsertBytes and throws an RTCError if that fails.
398 *
399 * @param pNode See CFGMR3InsertBytes.
400 * @param pcszName See CFGMR3InsertBytes.
401 * @param pvBytes See CFGMR3InsertBytes.
402 * @param cbBytes See CFGMR3InsertBytes.
403 */
404static void InsertConfigBytes(PCFGMNODE pNode,
405 const char *pcszName,
406 const void *pvBytes,
407 size_t cbBytes)
408{
409 int vrc = CFGMR3InsertBytes(pNode,
410 pcszName,
411 pvBytes,
412 cbBytes);
413 if (RT_FAILURE(vrc))
414 throw ConfigError("CFGMR3InsertBytes", vrc, pcszName);
415}
416
417/**
418 * Helper that calls CFGMR3InsertInteger and throws an RTCError if that
419 * fails.
420 *
421 * @param pNode See CFGMR3InsertInteger.
422 * @param pcszName See CFGMR3InsertInteger.
423 * @param u64Integer See CFGMR3InsertInteger.
424 */
425static void InsertConfigInteger(PCFGMNODE pNode,
426 const char *pcszName,
427 uint64_t u64Integer)
428{
429 int vrc = CFGMR3InsertInteger(pNode,
430 pcszName,
431 u64Integer);
432 if (RT_FAILURE(vrc))
433 throw ConfigError("CFGMR3InsertInteger", vrc, pcszName);
434}
435
436/**
437 * Helper that calls CFGMR3InsertNode and throws an RTCError if that fails.
438 *
439 * @param pNode See CFGMR3InsertNode.
440 * @param pcszName See CFGMR3InsertNode.
441 * @param ppChild See CFGMR3InsertNode.
442 */
443static void InsertConfigNode(PCFGMNODE pNode,
444 const char *pcszName,
445 PCFGMNODE *ppChild)
446{
447 int vrc = CFGMR3InsertNode(pNode, pcszName, ppChild);
448 if (RT_FAILURE(vrc))
449 throw ConfigError("CFGMR3InsertNode", vrc, pcszName);
450}
451
452/**
453 * Helper that calls CFGMR3RemoveValue and throws an RTCError if that fails.
454 *
455 * @param pNode See CFGMR3RemoveValue.
456 * @param pcszName See CFGMR3RemoveValue.
457 */
458static void RemoveConfigValue(PCFGMNODE pNode,
459 const char *pcszName)
460{
461 int vrc = CFGMR3RemoveValue(pNode, pcszName);
462 if (RT_FAILURE(vrc))
463 throw ConfigError("CFGMR3RemoveValue", vrc, pcszName);
464}
465
466#ifdef VBOX_WITH_PCI_PASSTHROUGH
467HRESULT Console::attachRawPciDevices(PVM pVM,
468 BusAssignmentManager *BusMgr,
469 PCFGMNODE pDevices)
470{
471 HRESULT hrc = S_OK;
472 PCFGMNODE pInst, pCfg, pLunL0, pLunL1;
473
474 SafeIfaceArray<IPciDeviceAttachment> assignments;
475 ComPtr<IMachine> aMachine = machine();
476
477 hrc = aMachine->COMGETTER(PciDeviceAssignments)(ComSafeArrayAsOutParam(assignments));
478 if ( hrc != S_OK
479 || assignments.size() < 1)
480 return hrc;
481
482 /*
483 * PCI passthrough is only available if the proper ExtPack is installed.
484 *
485 * Note. Configuring PCI passthrough here and providing messages about
486 * the missing extpack isn't exactly clean, but it is a necessary evil
487 * to patch over legacy compatability issues introduced by the new
488 * distribution model.
489 */
490# ifdef VBOX_WITH_EXTPACK
491 static const char *s_pszPciRawExtPackName = "Oracle VM VirtualBox Extension Pack";
492 if (!mptrExtPackManager->isExtPackUsable(s_pszPciRawExtPackName))
493 {
494 /* Always fatal! */
495 return VMSetError(pVM, VERR_NOT_FOUND, RT_SRC_POS,
496 N_("Implementation of the PCI passthrough framework not found!\n"
497 "The VM cannot be started. To fix this problem, either "
498 "install the '%s' or disable PCI passthrough via VBoxManage"),
499 s_pszPciRawExtPackName);
500 }
501# endif
502
503 PCFGMNODE pBridges = CFGMR3GetChild(pDevices, "ich9pcibridge");
504 Assert(pBridges);
505
506 /* Find required bridges, and add missing ones */
507 for (size_t iDev = 0; iDev < assignments.size(); iDev++)
508 {
509 ComPtr<IPciDeviceAttachment> assignment = assignments[iDev];
510 LONG guest = 0;
511 PciBusAddress GuestPciAddress;
512
513 assignment->COMGETTER(GuestAddress)(&guest);
514 GuestPciAddress.fromLong(guest);
515 Assert(GuestPciAddress.valid());
516
517 if (GuestPciAddress.miBus > 0)
518 {
519 int iBridgesMissed = 0;
520 int iBase = GuestPciAddress.miBus - 1;
521
522 while (!BusMgr->hasPciDevice("ich9pcibridge", iBase) && iBase > 0)
523 {
524 iBridgesMissed++; iBase--;
525 }
526 iBase++;
527
528 for (int iBridge = 0; iBridge < iBridgesMissed; iBridge++)
529 {
530 InsertConfigNode(pBridges, Utf8StrFmt("%d", iBase + iBridge).c_str(), &pInst);
531 InsertConfigInteger(pInst, "Trusted", 1);
532 hrc = BusMgr->assignPciDevice("ich9pcibridge", pInst);
533 }
534 }
535 }
536
537 /* Now actually add devices */
538 PCFGMNODE pPciDevs = NULL;
539
540 if (assignments.size() > 0)
541 {
542 InsertConfigNode(pDevices, "pciraw", &pPciDevs);
543
544 PCFGMNODE pRoot = CFGMR3GetParent(pDevices); Assert(pRoot);
545
546 /* Tell PGM to tell GPciRaw about guest mappings. */
547 CFGMR3InsertNode(pRoot, "PGM", NULL);
548 InsertConfigInteger(CFGMR3GetChild(pRoot, "PGM"), "PciPassThrough", 1);
549
550 /*
551 * Currently, using IOMMU needed for PCI passthrough
552 * requires RAM preallocation.
553 */
554 /** @todo: check if we can lift this requirement */
555 CFGMR3RemoveValue(pRoot, "RamPreAlloc");
556 InsertConfigInteger(pRoot, "RamPreAlloc", 1);
557 }
558
559 for (size_t iDev = 0; iDev < assignments.size(); iDev++)
560 {
561 PciBusAddress HostPciAddress, GuestPciAddress;
562 ComPtr<IPciDeviceAttachment> assignment = assignments[iDev];
563 LONG host, guest;
564 Bstr aDevName;
565
566 assignment->COMGETTER(HostAddress)(&host);
567 assignment->COMGETTER(GuestAddress)(&guest);
568 assignment->COMGETTER(Name)(aDevName.asOutParam());
569
570 InsertConfigNode(pPciDevs, Utf8StrFmt("%d", iDev).c_str(), &pInst);
571 InsertConfigInteger(pInst, "Trusted", 1);
572
573 HostPciAddress.fromLong(host);
574 Assert(HostPciAddress.valid());
575 InsertConfigNode(pInst, "Config", &pCfg);
576 InsertConfigString(pCfg, "DeviceName", aDevName);
577
578 InsertConfigInteger(pCfg, "DetachHostDriver", 1);
579 InsertConfigInteger(pCfg, "HostPCIBusNo", HostPciAddress.miBus);
580 InsertConfigInteger(pCfg, "HostPCIDeviceNo", HostPciAddress.miDevice);
581 InsertConfigInteger(pCfg, "HostPCIFunctionNo", HostPciAddress.miFn);
582
583 GuestPciAddress.fromLong(guest);
584 Assert(GuestPciAddress.valid());
585 hrc = BusMgr->assignHostPciDevice("pciraw", pInst, HostPciAddress, GuestPciAddress, true);
586 if (hrc != S_OK)
587 return hrc;
588
589 InsertConfigInteger(pCfg, "GuestPCIBusNo", GuestPciAddress.miBus);
590 InsertConfigInteger(pCfg, "GuestPCIDeviceNo", GuestPciAddress.miDevice);
591 InsertConfigInteger(pCfg, "GuestPCIFunctionNo", GuestPciAddress.miFn);
592
593 /* the driver */
594 InsertConfigNode(pInst, "LUN#0", &pLunL0);
595 InsertConfigString(pLunL0, "Driver", "pciraw");
596 InsertConfigNode(pLunL0, "AttachedDriver", &pLunL1);
597
598 /* the Main driver */
599 InsertConfigString(pLunL1, "Driver", "MainPciRaw");
600 InsertConfigNode(pLunL1, "Config", &pCfg);
601 PciRawDev* pMainDev = new PciRawDev(this);
602 InsertConfigInteger(pCfg, "Object", (uintptr_t)pMainDev);
603 }
604
605 return hrc;
606}
607#endif
608
609
610void Console::attachStatusDriver(PCFGMNODE pCtlInst, PPDMLED *papLeds,
611 uint64_t uFirst, uint64_t uLast,
612 Console::MediumAttachmentMap *pmapMediumAttachments,
613 const char *pcszDevice, unsigned uInstance)
614{
615 PCFGMNODE pLunL0, pCfg;
616 InsertConfigNode(pCtlInst, "LUN#999", &pLunL0);
617 InsertConfigString(pLunL0, "Driver", "MainStatus");
618 InsertConfigNode(pLunL0, "Config", &pCfg);
619 InsertConfigInteger(pCfg, "papLeds", (uintptr_t)papLeds);
620 if (pmapMediumAttachments)
621 {
622 InsertConfigInteger(pCfg, "pmapMediumAttachments", (uintptr_t)pmapMediumAttachments);
623 InsertConfigInteger(pCfg, "pConsole", (uintptr_t)this);
624 AssertPtr(pcszDevice);
625 Utf8Str deviceInstance = Utf8StrFmt("%s/%u", pcszDevice, uInstance);
626 InsertConfigString(pCfg, "DeviceInstance", deviceInstance.c_str());
627 }
628 InsertConfigInteger(pCfg, "First", uFirst);
629 InsertConfigInteger(pCfg, "Last", uLast);
630}
631
632
633/**
634 * Construct the VM configuration tree (CFGM).
635 *
636 * This is a callback for VMR3Create() call. It is called from CFGMR3Init()
637 * in the emulation thread (EMT). Any per thread COM/XPCOM initialization
638 * is done here.
639 *
640 * @param pVM VM handle.
641 * @param pvConsole Pointer to the VMPowerUpTask object.
642 * @return VBox status code.
643 *
644 * @note Locks the Console object for writing.
645 */
646DECLCALLBACK(int) Console::configConstructor(PVM pVM, void *pvConsole)
647{
648 LogFlowFuncEnter();
649
650 AssertReturn(pvConsole, VERR_GENERAL_FAILURE);
651 ComObjPtr<Console> pConsole = static_cast<Console *>(pvConsole);
652
653 AutoCaller autoCaller(pConsole);
654 AssertComRCReturn(autoCaller.rc(), VERR_ACCESS_DENIED);
655
656 /* lock the console because we widely use internal fields and methods */
657 AutoWriteLock alock(pConsole COMMA_LOCKVAL_SRC_POS);
658
659 /*
660 * Set the VM handle and do the rest of the job in an worker method so we
661 * can easily reset the VM handle on failure.
662 */
663 PUVM pUVM = pConsole->mpUVM = VMR3GetUVM(pVM);
664 VMR3RetainUVM(pUVM);
665 int vrc;
666 try
667 {
668 vrc = pConsole->configConstructorInner(pVM, &alock);
669 }
670 catch (...)
671 {
672 vrc = VERR_UNEXPECTED_EXCEPTION;
673 }
674 if (RT_FAILURE(vrc))
675 {
676 pConsole->mpUVM = NULL;
677 VMR3ReleaseUVM(pUVM);
678 }
679
680 return vrc;
681}
682
683
684/**
685 * Worker for configConstructor.
686 *
687 * @return VBox status code.
688 * @param pVM The VM handle.
689 * @param pAlock The automatic lock instance. This is for when we have
690 * to leave it in order to avoid deadlocks (ext packs and
691 * more).
692 */
693int Console::configConstructorInner(PVM pVM, AutoWriteLock *pAlock)
694{
695 VMMDev *pVMMDev = m_pVMMDev;
696 Assert(pVMMDev);
697
698 ComPtr<IMachine> pMachine = machine();
699
700 int rc;
701 HRESULT hrc;
702 Bstr bstr;
703
704#define H() AssertMsgReturn(!FAILED(hrc), ("hrc=%Rhrc\n", hrc), VERR_GENERAL_FAILURE)
705
706 /*
707 * Get necessary objects and frequently used parameters.
708 */
709 ComPtr<IVirtualBox> virtualBox;
710 hrc = pMachine->COMGETTER(Parent)(virtualBox.asOutParam()); H();
711
712 ComPtr<IHost> host;
713 hrc = virtualBox->COMGETTER(Host)(host.asOutParam()); H();
714
715 ComPtr<ISystemProperties> systemProperties;
716 hrc = virtualBox->COMGETTER(SystemProperties)(systemProperties.asOutParam()); H();
717
718 ComPtr<IBIOSSettings> biosSettings;
719 hrc = pMachine->COMGETTER(BIOSSettings)(biosSettings.asOutParam()); H();
720
721 hrc = pMachine->COMGETTER(HardwareUUID)(bstr.asOutParam()); H();
722 RTUUID HardwareUuid;
723 rc = RTUuidFromUtf16(&HardwareUuid, bstr.raw());
724 AssertRCReturn(rc, rc);
725
726 ULONG cRamMBs;
727 hrc = pMachine->COMGETTER(MemorySize)(&cRamMBs); H();
728#if 0 /* enable to play with lots of memory. */
729 if (RTEnvExist("VBOX_RAM_SIZE"))
730 cRamMBs = RTStrToUInt64(RTEnvGet("VBOX_RAM_SIZE"));
731#endif
732 uint64_t const cbRam = cRamMBs * (uint64_t)_1M;
733 uint32_t cbRamHole = MM_RAM_HOLE_SIZE_DEFAULT;
734 uint64_t uMcfgBase = 0;
735 uint32_t cbMcfgLength = 0;
736
737 ChipsetType_T chipsetType;
738 hrc = pMachine->COMGETTER(ChipsetType)(&chipsetType); H();
739 if (chipsetType == ChipsetType_ICH9)
740 {
741 /* We'd better have 0x10000000 region, to cover 256 buses
742 but this put too much load on hypervisor heap */
743 cbMcfgLength = 0x4000000; //0x10000000;
744 cbRamHole += cbMcfgLength;
745 uMcfgBase = _4G - cbRamHole;
746 }
747
748 BusAssignmentManager* BusMgr = mBusMgr = BusAssignmentManager::createInstance(chipsetType);
749
750 ULONG cCpus = 1;
751 hrc = pMachine->COMGETTER(CPUCount)(&cCpus); H();
752
753 ULONG ulCpuExecutionCap = 100;
754 hrc = pMachine->COMGETTER(CPUExecutionCap)(&ulCpuExecutionCap); H();
755
756 Bstr osTypeId;
757 hrc = pMachine->COMGETTER(OSTypeId)(osTypeId.asOutParam()); H();
758
759 BOOL fIOAPIC;
760 hrc = biosSettings->COMGETTER(IOAPICEnabled)(&fIOAPIC); H();
761
762 ComPtr<IGuestOSType> guestOSType;
763 hrc = virtualBox->GetGuestOSType(osTypeId.raw(), guestOSType.asOutParam()); H();
764
765 Bstr guestTypeFamilyId;
766 hrc = guestOSType->COMGETTER(FamilyId)(guestTypeFamilyId.asOutParam()); H();
767 BOOL fOsXGuest = guestTypeFamilyId == Bstr("MacOS");
768
769 ULONG maxNetworkAdapters;
770 hrc = systemProperties->GetMaxNetworkAdapters(chipsetType, &maxNetworkAdapters); H();
771 /*
772 * Get root node first.
773 * This is the only node in the tree.
774 */
775 PCFGMNODE pRoot = CFGMR3GetRoot(pVM);
776 Assert(pRoot);
777
778 // InsertConfigString throws
779 try
780 {
781
782 /*
783 * Set the root (and VMM) level values.
784 */
785 hrc = pMachine->COMGETTER(Name)(bstr.asOutParam()); H();
786 InsertConfigString(pRoot, "Name", bstr);
787 InsertConfigBytes(pRoot, "UUID", &HardwareUuid, sizeof(HardwareUuid));
788 InsertConfigInteger(pRoot, "RamSize", cbRam);
789 InsertConfigInteger(pRoot, "RamHoleSize", cbRamHole);
790 InsertConfigInteger(pRoot, "NumCPUs", cCpus);
791 InsertConfigInteger(pRoot, "CpuExecutionCap", ulCpuExecutionCap);
792 InsertConfigInteger(pRoot, "TimerMillies", 10);
793#ifdef VBOX_WITH_RAW_MODE
794 InsertConfigInteger(pRoot, "RawR3Enabled", 1); /* boolean */
795 InsertConfigInteger(pRoot, "RawR0Enabled", 1); /* boolean */
796 /** @todo Config: RawR0, PATMEnabled and CSAMEnabled needs attention later. */
797 InsertConfigInteger(pRoot, "PATMEnabled", 1); /* boolean */
798 InsertConfigInteger(pRoot, "CSAMEnabled", 1); /* boolean */
799#endif
800 /* Not necessary, but to make sure these two settings end up in the release log. */
801 BOOL fPageFusion = FALSE;
802 hrc = pMachine->COMGETTER(PageFusionEnabled)(&fPageFusion); H();
803 InsertConfigInteger(pRoot, "PageFusion", fPageFusion); /* boolean */
804 ULONG ulBalloonSize = 0;
805 hrc = pMachine->COMGETTER(MemoryBalloonSize)(&ulBalloonSize); H();
806 InsertConfigInteger(pRoot, "MemBalloonSize", ulBalloonSize);
807
808 /*
809 * CPUM values.
810 */
811 PCFGMNODE pCPUM;
812 InsertConfigNode(pRoot, "CPUM", &pCPUM);
813
814 /* cpuid leaf overrides. */
815 static uint32_t const s_auCpuIdRanges[] =
816 {
817 UINT32_C(0x00000000), UINT32_C(0x0000000a),
818 UINT32_C(0x80000000), UINT32_C(0x8000000a)
819 };
820 for (unsigned i = 0; i < RT_ELEMENTS(s_auCpuIdRanges); i += 2)
821 for (uint32_t uLeaf = s_auCpuIdRanges[i]; uLeaf < s_auCpuIdRanges[i + 1]; uLeaf++)
822 {
823 ULONG ulEax, ulEbx, ulEcx, ulEdx;
824 hrc = pMachine->GetCPUIDLeaf(uLeaf, &ulEax, &ulEbx, &ulEcx, &ulEdx);
825 if (SUCCEEDED(hrc))
826 {
827 PCFGMNODE pLeaf;
828 InsertConfigNode(pCPUM, Utf8StrFmt("HostCPUID/%RX32", uLeaf).c_str(), &pLeaf);
829
830 InsertConfigInteger(pLeaf, "eax", ulEax);
831 InsertConfigInteger(pLeaf, "ebx", ulEbx);
832 InsertConfigInteger(pLeaf, "ecx", ulEcx);
833 InsertConfigInteger(pLeaf, "edx", ulEdx);
834 }
835 else if (hrc != E_INVALIDARG) H();
836 }
837
838 /* We must limit CPUID count for Windows NT 4, as otherwise it stops
839 with error 0x3e (MULTIPROCESSOR_CONFIGURATION_NOT_SUPPORTED). */
840 if (osTypeId == "WindowsNT4")
841 {
842 LogRel(("Limiting CPUID leaf count for NT4 guests\n"));
843 InsertConfigInteger(pCPUM, "NT4LeafLimit", true);
844 }
845
846 /* Expose extended MWAIT features to Mac OS X guests. */
847 if (fOsXGuest)
848 {
849 LogRel(("Using MWAIT extensions\n"));
850 InsertConfigInteger(pCPUM, "MWaitExtensions", true);
851 }
852
853 /*
854 * Hardware virtualization extensions.
855 */
856 BOOL fHWVirtExEnabled;
857 BOOL fHwVirtExtForced = false;
858#ifdef VBOX_WITH_RAW_MODE
859 hrc = pMachine->GetHWVirtExProperty(HWVirtExPropertyType_Enabled, &fHWVirtExEnabled); H();
860 if (cCpus > 1) /** @todo SMP: This isn't nice, but things won't work on mac otherwise. */
861 fHWVirtExEnabled = TRUE;
862# ifdef RT_OS_DARWIN
863 fHwVirtExtForced = fHWVirtExEnabled;
864# else
865 /* - With more than 4GB PGM will use different RAMRANGE sizes for raw
866 mode and hv mode to optimize lookup times.
867 - With more than one virtual CPU, raw-mode isn't a fallback option. */
868 fHwVirtExtForced = fHWVirtExEnabled
869 && ( cbRam + cbRamHole > _4G
870 || cCpus > 1);
871# endif
872#else /* !VBOX_WITH_RAW_MODE */
873 fHWVirtExEnabled = fHwVirtExtForced = true;
874#endif /* !VBOX_WITH_RAW_MODE */
875 /* only honor the property value if there was no other reason to enable it */
876 if (!fHwVirtExtForced)
877 {
878 hrc = pMachine->GetHWVirtExProperty(HWVirtExPropertyType_Force, &fHwVirtExtForced); H();
879 }
880 InsertConfigInteger(pRoot, "HwVirtExtForced", fHwVirtExtForced);
881
882
883 /*
884 * MM values.
885 */
886 PCFGMNODE pMM;
887 InsertConfigNode(pRoot, "MM", &pMM);
888 InsertConfigInteger(pMM, "CanUseLargerHeap", chipsetType == ChipsetType_ICH9);
889
890 /*
891 * Hardware virtualization settings.
892 */
893 BOOL fIsGuest64Bit = false;
894 PCFGMNODE pHWVirtExt;
895 InsertConfigNode(pRoot, "HWVirtExt", &pHWVirtExt);
896 if (fHWVirtExEnabled)
897 {
898 InsertConfigInteger(pHWVirtExt, "Enabled", 1);
899
900 /* Indicate whether 64-bit guests are supported or not. */
901 /** @todo This is currently only forced off on 32-bit hosts only because it
902 * makes a lof of difference there (REM and Solaris performance).
903 */
904 BOOL fSupportsLongMode = false;
905 hrc = host->GetProcessorFeature(ProcessorFeature_LongMode,
906 &fSupportsLongMode); H();
907 hrc = guestOSType->COMGETTER(Is64Bit)(&fIsGuest64Bit); H();
908
909 if (fSupportsLongMode && fIsGuest64Bit)
910 {
911 InsertConfigInteger(pHWVirtExt, "64bitEnabled", 1);
912#if ARCH_BITS == 32 /* The recompiler must use VBoxREM64 (32-bit host only). */
913 PCFGMNODE pREM;
914 InsertConfigNode(pRoot, "REM", &pREM);
915 InsertConfigInteger(pREM, "64bitEnabled", 1);
916#endif
917 }
918#if ARCH_BITS == 32 /* 32-bit guests only. */
919 else
920 {
921 InsertConfigInteger(pHWVirtExt, "64bitEnabled", 0);
922 }
923#endif
924
925 /** @todo Not exactly pretty to check strings; VBOXOSTYPE would be better, but that requires quite a bit of API change in Main. */
926 if ( !fIsGuest64Bit
927 && fIOAPIC
928 && ( osTypeId == "WindowsNT4"
929 || osTypeId == "Windows2000"
930 || osTypeId == "WindowsXP"
931 || osTypeId == "Windows2003"))
932 {
933 /* Only allow TPR patching for NT, Win2k, XP and Windows Server 2003. (32 bits mode)
934 * We may want to consider adding more guest OSes (Solaris) later on.
935 */
936 InsertConfigInteger(pHWVirtExt, "TPRPatchingEnabled", 1);
937 }
938 }
939
940 /* HWVirtEx exclusive mode */
941 BOOL fHWVirtExExclusive = true;
942 hrc = pMachine->GetHWVirtExProperty(HWVirtExPropertyType_Exclusive, &fHWVirtExExclusive); H();
943 InsertConfigInteger(pHWVirtExt, "Exclusive", fHWVirtExExclusive);
944
945 /* Nested paging (VT-x/AMD-V) */
946 BOOL fEnableNestedPaging = false;
947 hrc = pMachine->GetHWVirtExProperty(HWVirtExPropertyType_NestedPaging, &fEnableNestedPaging); H();
948 InsertConfigInteger(pHWVirtExt, "EnableNestedPaging", fEnableNestedPaging);
949
950 /* Large pages; requires nested paging */
951 BOOL fEnableLargePages = false;
952 hrc = pMachine->GetHWVirtExProperty(HWVirtExPropertyType_LargePages, &fEnableLargePages); H();
953 InsertConfigInteger(pHWVirtExt, "EnableLargePages", fEnableLargePages);
954
955 /* VPID (VT-x) */
956 BOOL fEnableVPID = false;
957 hrc = pMachine->GetHWVirtExProperty(HWVirtExPropertyType_VPID, &fEnableVPID); H();
958 InsertConfigInteger(pHWVirtExt, "EnableVPID", fEnableVPID);
959
960 /* Physical Address Extension (PAE) */
961 BOOL fEnablePAE = false;
962 hrc = pMachine->GetCPUProperty(CPUPropertyType_PAE, &fEnablePAE); H();
963 InsertConfigInteger(pRoot, "EnablePAE", fEnablePAE);
964
965 /* Synthetic CPU */
966 BOOL fSyntheticCpu = false;
967 hrc = pMachine->GetCPUProperty(CPUPropertyType_Synthetic, &fSyntheticCpu); H();
968 InsertConfigInteger(pCPUM, "SyntheticCpu", fSyntheticCpu);
969
970 BOOL fPXEDebug;
971 hrc = biosSettings->COMGETTER(PXEDebugEnabled)(&fPXEDebug); H();
972
973 /*
974 * PDM config.
975 * Load drivers in VBoxC.[so|dll]
976 */
977 PCFGMNODE pPDM;
978 PCFGMNODE pNode;
979 PCFGMNODE pMod;
980 InsertConfigNode(pRoot, "PDM", &pPDM);
981 InsertConfigNode(pPDM, "Devices", &pNode);
982 InsertConfigNode(pPDM, "Drivers", &pNode);
983 InsertConfigNode(pNode, "VBoxC", &pMod);
984#ifdef VBOX_WITH_XPCOM
985 // VBoxC is located in the components subdirectory
986 char szPathVBoxC[RTPATH_MAX];
987 rc = RTPathAppPrivateArch(szPathVBoxC, RTPATH_MAX - sizeof("/components/VBoxC")); AssertRC(rc);
988 strcat(szPathVBoxC, "/components/VBoxC");
989 InsertConfigString(pMod, "Path", szPathVBoxC);
990#else
991 InsertConfigString(pMod, "Path", "VBoxC");
992#endif
993
994
995 /*
996 * Block cache settings.
997 */
998 PCFGMNODE pPDMBlkCache;
999 InsertConfigNode(pPDM, "BlkCache", &pPDMBlkCache);
1000
1001 /* I/O cache size */
1002 ULONG ioCacheSize = 5;
1003 hrc = pMachine->COMGETTER(IoCacheSize)(&ioCacheSize); H();
1004 InsertConfigInteger(pPDMBlkCache, "CacheSize", ioCacheSize * _1M);
1005
1006 /*
1007 * Bandwidth groups.
1008 */
1009 PCFGMNODE pAc;
1010 PCFGMNODE pAcFile;
1011 PCFGMNODE pAcFileBwGroups;
1012 ComPtr<IBandwidthControl> bwCtrl;
1013 com::SafeIfaceArray<IBandwidthGroup> bwGroups;
1014
1015 hrc = pMachine->COMGETTER(BandwidthControl)(bwCtrl.asOutParam()); H();
1016
1017 hrc = bwCtrl->GetAllBandwidthGroups(ComSafeArrayAsOutParam(bwGroups)); H();
1018
1019 InsertConfigNode(pPDM, "AsyncCompletion", &pAc);
1020 InsertConfigNode(pAc, "File", &pAcFile);
1021 InsertConfigNode(pAcFile, "BwGroups", &pAcFileBwGroups);
1022#ifdef VBOX_WITH_NETSHAPER
1023 PCFGMNODE pNetworkShaper;
1024 PCFGMNODE pNetworkBwGroups;
1025
1026 InsertConfigNode(pPDM, "NetworkShaper", &pNetworkShaper);
1027 InsertConfigNode(pNetworkShaper, "BwGroups", &pNetworkBwGroups);
1028#endif /* VBOX_WITH_NETSHAPER */
1029
1030 for (size_t i = 0; i < bwGroups.size(); i++)
1031 {
1032 Bstr strName;
1033 ULONG cMaxMbPerSec;
1034 BandwidthGroupType_T enmType;
1035
1036 hrc = bwGroups[i]->COMGETTER(Name)(strName.asOutParam()); H();
1037 hrc = bwGroups[i]->COMGETTER(Type)(&enmType); H();
1038 hrc = bwGroups[i]->COMGETTER(MaxMbPerSec)(&cMaxMbPerSec); H();
1039
1040 if (enmType == BandwidthGroupType_Disk)
1041 {
1042 PCFGMNODE pBwGroup;
1043 InsertConfigNode(pAcFileBwGroups, Utf8Str(strName).c_str(), &pBwGroup);
1044 InsertConfigInteger(pBwGroup, "Max", cMaxMbPerSec * _1M);
1045 InsertConfigInteger(pBwGroup, "Start", cMaxMbPerSec * _1M);
1046 InsertConfigInteger(pBwGroup, "Step", 0);
1047 }
1048#ifdef VBOX_WITH_NETSHAPER
1049 else if (enmType == BandwidthGroupType_Network)
1050 {
1051 /* Network bandwidth groups. */
1052 PCFGMNODE pBwGroup;
1053 InsertConfigNode(pNetworkBwGroups, Utf8Str(strName).c_str(), &pBwGroup);
1054 InsertConfigInteger(pBwGroup, "Max", cMaxMbPerSec * 1000); // @todo: _1M);
1055 }
1056#endif /* VBOX_WITH_NETSHAPER */
1057 }
1058
1059 /*
1060 * Devices
1061 */
1062 PCFGMNODE pDevices = NULL; /* /Devices */
1063 PCFGMNODE pDev = NULL; /* /Devices/Dev/ */
1064 PCFGMNODE pInst = NULL; /* /Devices/Dev/0/ */
1065 PCFGMNODE pCfg = NULL; /* /Devices/Dev/.../Config/ */
1066 PCFGMNODE pLunL0 = NULL; /* /Devices/Dev/0/LUN#0/ */
1067 PCFGMNODE pLunL1 = NULL; /* /Devices/Dev/0/LUN#0/AttachedDriver/ */
1068 PCFGMNODE pLunL2 = NULL; /* /Devices/Dev/0/LUN#0/AttachedDriver/Config/ */
1069 PCFGMNODE pBiosCfg = NULL; /* /Devices/pcbios/0/Config/ */
1070 PCFGMNODE pNetBootCfg = NULL; /* /Devices/pcbios/0/Config/NetBoot/ */
1071
1072 InsertConfigNode(pRoot, "Devices", &pDevices);
1073
1074 /*
1075 * PC Arch.
1076 */
1077 InsertConfigNode(pDevices, "pcarch", &pDev);
1078 InsertConfigNode(pDev, "0", &pInst);
1079 InsertConfigInteger(pInst, "Trusted", 1); /* boolean */
1080 InsertConfigNode(pInst, "Config", &pCfg);
1081
1082 /*
1083 * The time offset
1084 */
1085 LONG64 timeOffset;
1086 hrc = biosSettings->COMGETTER(TimeOffset)(&timeOffset); H();
1087 PCFGMNODE pTMNode;
1088 InsertConfigNode(pRoot, "TM", &pTMNode);
1089 InsertConfigInteger(pTMNode, "UTCOffset", timeOffset * 1000000);
1090
1091 /*
1092 * DMA
1093 */
1094 InsertConfigNode(pDevices, "8237A", &pDev);
1095 InsertConfigNode(pDev, "0", &pInst);
1096 InsertConfigInteger(pInst, "Trusted", 1); /* boolean */
1097
1098 /*
1099 * PCI buses.
1100 */
1101 uint32_t uIocPciAddress, uHbcPciAddress;
1102 switch (chipsetType)
1103 {
1104 default:
1105 Assert(false);
1106 case ChipsetType_PIIX3:
1107 InsertConfigNode(pDevices, "pci", &pDev);
1108 uHbcPciAddress = (0x0 << 16) | 0;
1109 uIocPciAddress = (0x1 << 16) | 0; // ISA controller
1110 break;
1111 case ChipsetType_ICH9:
1112 InsertConfigNode(pDevices, "ich9pci", &pDev);
1113 uHbcPciAddress = (0x1e << 16) | 0;
1114 uIocPciAddress = (0x1f << 16) | 0; // LPC controller
1115 break;
1116 }
1117 InsertConfigNode(pDev, "0", &pInst);
1118 InsertConfigInteger(pInst, "Trusted", 1); /* boolean */
1119 InsertConfigNode(pInst, "Config", &pCfg);
1120 InsertConfigInteger(pCfg, "IOAPIC", fIOAPIC);
1121 if (chipsetType == ChipsetType_ICH9)
1122 {
1123 /* Provide MCFG info */
1124 InsertConfigInteger(pCfg, "McfgBase", uMcfgBase);
1125 InsertConfigInteger(pCfg, "McfgLength", cbMcfgLength);
1126
1127
1128 /* And register 2 bridges */
1129 InsertConfigNode(pDevices, "ich9pcibridge", &pDev);
1130 InsertConfigNode(pDev, "0", &pInst);
1131 InsertConfigInteger(pInst, "Trusted", 1); /* boolean */
1132 hrc = BusMgr->assignPciDevice("ich9pcibridge", pInst); H();
1133
1134 InsertConfigNode(pDev, "1", &pInst);
1135 InsertConfigInteger(pInst, "Trusted", 1); /* boolean */
1136 hrc = BusMgr->assignPciDevice("ich9pcibridge", pInst); H();
1137
1138#ifdef VBOX_WITH_PCI_PASSTHROUGH
1139 /* Add PCI passthrough devices */
1140 hrc = attachRawPciDevices(pVM, BusMgr, pDevices); H();
1141#endif
1142 }
1143
1144 /*
1145 * Enable the following devices: HPET, SMC and LPC on MacOS X guests or on ICH9 chipset
1146 */
1147
1148 /*
1149 * High Precision Event Timer (HPET)
1150 */
1151 BOOL fHpetEnabled;
1152 /* Other guests may wish to use HPET too, but MacOS X not functional without it */
1153 hrc = pMachine->COMGETTER(HpetEnabled)(&fHpetEnabled); H();
1154 /* so always enable HPET in extended profile */
1155 fHpetEnabled |= fOsXGuest;
1156 /* HPET is always present on ICH9 */
1157 fHpetEnabled |= (chipsetType == ChipsetType_ICH9);
1158 if (fHpetEnabled)
1159 {
1160 InsertConfigNode(pDevices, "hpet", &pDev);
1161 InsertConfigNode(pDev, "0", &pInst);
1162 InsertConfigInteger(pInst, "Trusted", 1); /* boolean */
1163 InsertConfigNode(pInst, "Config", &pCfg);
1164 InsertConfigInteger(pCfg, "ICH9", (chipsetType == ChipsetType_ICH9) ? 1 : 0); /* boolean */
1165 }
1166
1167 /*
1168 * System Management Controller (SMC)
1169 */
1170 BOOL fSmcEnabled;
1171 fSmcEnabled = fOsXGuest;
1172 if (fSmcEnabled)
1173 {
1174 InsertConfigNode(pDevices, "smc", &pDev);
1175 InsertConfigNode(pDev, "0", &pInst);
1176 InsertConfigInteger(pInst, "Trusted", 1); /* boolean */
1177 InsertConfigNode(pInst, "Config", &pCfg);
1178
1179 bool fGetKeyFromRealSMC;
1180 Bstr bstrKey;
1181 rc = getSmcDeviceKey(pMachine, bstrKey.asOutParam(), &fGetKeyFromRealSMC);
1182 AssertRCReturn(rc, rc);
1183
1184 InsertConfigString(pCfg, "DeviceKey", bstrKey);
1185 InsertConfigInteger(pCfg, "GetKeyFromRealSMC", fGetKeyFromRealSMC);
1186 }
1187
1188 /*
1189 * Low Pin Count (LPC) bus
1190 */
1191 BOOL fLpcEnabled;
1192 /** @todo: implement appropriate getter */
1193 fLpcEnabled = fOsXGuest || (chipsetType == ChipsetType_ICH9);
1194 if (fLpcEnabled)
1195 {
1196 InsertConfigNode(pDevices, "lpc", &pDev);
1197 InsertConfigNode(pDev, "0", &pInst);
1198 hrc = BusMgr->assignPciDevice("lpc", pInst); H();
1199 InsertConfigInteger(pInst, "Trusted", 1); /* boolean */
1200 }
1201
1202 BOOL fShowRtc;
1203 fShowRtc = fOsXGuest || (chipsetType == ChipsetType_ICH9);
1204
1205 /*
1206 * PS/2 keyboard & mouse.
1207 */
1208 InsertConfigNode(pDevices, "pckbd", &pDev);
1209 InsertConfigNode(pDev, "0", &pInst);
1210 InsertConfigInteger(pInst, "Trusted", 1); /* boolean */
1211 InsertConfigNode(pInst, "Config", &pCfg);
1212
1213 InsertConfigNode(pInst, "LUN#0", &pLunL0);
1214 InsertConfigString(pLunL0, "Driver", "KeyboardQueue");
1215 InsertConfigNode(pLunL0, "Config", &pCfg);
1216 InsertConfigInteger(pCfg, "QueueSize", 64);
1217
1218 InsertConfigNode(pLunL0, "AttachedDriver", &pLunL1);
1219 InsertConfigString(pLunL1, "Driver", "MainKeyboard");
1220 InsertConfigNode(pLunL1, "Config", &pCfg);
1221 Keyboard *pKeyboard = mKeyboard;
1222 InsertConfigInteger(pCfg, "Object", (uintptr_t)pKeyboard);
1223
1224 InsertConfigNode(pInst, "LUN#1", &pLunL0);
1225 InsertConfigString(pLunL0, "Driver", "MouseQueue");
1226 InsertConfigNode(pLunL0, "Config", &pCfg);
1227 InsertConfigInteger(pCfg, "QueueSize", 128);
1228
1229 InsertConfigNode(pLunL0, "AttachedDriver", &pLunL1);
1230 InsertConfigString(pLunL1, "Driver", "MainMouse");
1231 InsertConfigNode(pLunL1, "Config", &pCfg);
1232 Mouse *pMouse = mMouse;
1233 InsertConfigInteger(pCfg, "Object", (uintptr_t)pMouse);
1234
1235 /*
1236 * i8254 Programmable Interval Timer And Dummy Speaker
1237 */
1238 InsertConfigNode(pDevices, "i8254", &pDev);
1239 InsertConfigNode(pDev, "0", &pInst);
1240 InsertConfigNode(pInst, "Config", &pCfg);
1241#ifdef DEBUG
1242 InsertConfigInteger(pInst, "Trusted", 1); /* boolean */
1243#endif
1244
1245 /*
1246 * i8259 Programmable Interrupt Controller.
1247 */
1248 InsertConfigNode(pDevices, "i8259", &pDev);
1249 InsertConfigNode(pDev, "0", &pInst);
1250 InsertConfigInteger(pInst, "Trusted", 1); /* boolean */
1251 InsertConfigNode(pInst, "Config", &pCfg);
1252
1253 /*
1254 * Advanced Programmable Interrupt Controller.
1255 * SMP: Each CPU has a LAPIC, but we have a single device representing all LAPICs states,
1256 * thus only single insert
1257 */
1258 InsertConfigNode(pDevices, "apic", &pDev);
1259 InsertConfigNode(pDev, "0", &pInst);
1260 InsertConfigInteger(pInst, "Trusted", 1); /* boolean */
1261 InsertConfigNode(pInst, "Config", &pCfg);
1262 InsertConfigInteger(pCfg, "IOAPIC", fIOAPIC);
1263 InsertConfigInteger(pCfg, "NumCPUs", cCpus);
1264
1265 if (fIOAPIC)
1266 {
1267 /*
1268 * I/O Advanced Programmable Interrupt Controller.
1269 */
1270 InsertConfigNode(pDevices, "ioapic", &pDev);
1271 InsertConfigNode(pDev, "0", &pInst);
1272 InsertConfigInteger(pInst, "Trusted", 1); /* boolean */
1273 InsertConfigNode(pInst, "Config", &pCfg);
1274 InsertConfigInteger(pCfg, "NumCPUs", cCpus);
1275 }
1276
1277 /*
1278 * RTC MC146818.
1279 */
1280 InsertConfigNode(pDevices, "mc146818", &pDev);
1281 InsertConfigNode(pDev, "0", &pInst);
1282 InsertConfigNode(pInst, "Config", &pCfg);
1283 BOOL fRTCUseUTC;
1284 hrc = pMachine->COMGETTER(RTCUseUTC)(&fRTCUseUTC); H();
1285 InsertConfigInteger(pCfg, "UseUTC", fRTCUseUTC ? 1 : 0);
1286
1287 /*
1288 * VGA.
1289 */
1290 InsertConfigNode(pDevices, "vga", &pDev);
1291 InsertConfigNode(pDev, "0", &pInst);
1292 InsertConfigInteger(pInst, "Trusted", 1); /* boolean */
1293
1294 hrc = BusMgr->assignPciDevice("vga", pInst); H();
1295 InsertConfigNode(pInst, "Config", &pCfg);
1296 ULONG cVRamMBs;
1297 hrc = pMachine->COMGETTER(VRAMSize)(&cVRamMBs); H();
1298 InsertConfigInteger(pCfg, "VRamSize", cVRamMBs * _1M);
1299 ULONG cMonitorCount;
1300 hrc = pMachine->COMGETTER(MonitorCount)(&cMonitorCount); H();
1301 InsertConfigInteger(pCfg, "MonitorCount", cMonitorCount);
1302#ifdef VBOX_WITH_2X_4GB_ADDR_SPACE
1303 InsertConfigInteger(pCfg, "R0Enabled", fHWVirtExEnabled);
1304#endif
1305
1306 /*
1307 * BIOS logo
1308 */
1309 BOOL fFadeIn;
1310 hrc = biosSettings->COMGETTER(LogoFadeIn)(&fFadeIn); H();
1311 InsertConfigInteger(pCfg, "FadeIn", fFadeIn ? 1 : 0);
1312 BOOL fFadeOut;
1313 hrc = biosSettings->COMGETTER(LogoFadeOut)(&fFadeOut); H();
1314 InsertConfigInteger(pCfg, "FadeOut", fFadeOut ? 1: 0);
1315 ULONG logoDisplayTime;
1316 hrc = biosSettings->COMGETTER(LogoDisplayTime)(&logoDisplayTime); H();
1317 InsertConfigInteger(pCfg, "LogoTime", logoDisplayTime);
1318 Bstr logoImagePath;
1319 hrc = biosSettings->COMGETTER(LogoImagePath)(logoImagePath.asOutParam()); H();
1320 InsertConfigString(pCfg, "LogoFile", Utf8Str(!logoImagePath.isEmpty() ? logoImagePath : "") );
1321
1322 /*
1323 * Boot menu
1324 */
1325 BIOSBootMenuMode_T eBootMenuMode;
1326 int iShowBootMenu;
1327 biosSettings->COMGETTER(BootMenuMode)(&eBootMenuMode);
1328 switch (eBootMenuMode)
1329 {
1330 case BIOSBootMenuMode_Disabled: iShowBootMenu = 0; break;
1331 case BIOSBootMenuMode_MenuOnly: iShowBootMenu = 1; break;
1332 default: iShowBootMenu = 2; break;
1333 }
1334 InsertConfigInteger(pCfg, "ShowBootMenu", iShowBootMenu);
1335
1336 /* Custom VESA mode list */
1337 unsigned cModes = 0;
1338 for (unsigned iMode = 1; iMode <= 16; ++iMode)
1339 {
1340 char szExtraDataKey[sizeof("CustomVideoModeXX")];
1341 RTStrPrintf(szExtraDataKey, sizeof(szExtraDataKey), "CustomVideoMode%u", iMode);
1342 hrc = pMachine->GetExtraData(Bstr(szExtraDataKey).raw(), bstr.asOutParam()); H();
1343 if (bstr.isEmpty())
1344 break;
1345 InsertConfigString(pCfg, szExtraDataKey, bstr);
1346 ++cModes;
1347 }
1348 InsertConfigInteger(pCfg, "CustomVideoModes", cModes);
1349
1350 /* VESA height reduction */
1351 ULONG ulHeightReduction;
1352 IFramebuffer *pFramebuffer = getDisplay()->getFramebuffer();
1353 if (pFramebuffer)
1354 {
1355 hrc = pFramebuffer->COMGETTER(HeightReduction)(&ulHeightReduction); H();
1356 }
1357 else
1358 {
1359 /* If framebuffer is not available, there is no height reduction. */
1360 ulHeightReduction = 0;
1361 }
1362 InsertConfigInteger(pCfg, "HeightReduction", ulHeightReduction);
1363
1364 /* Attach the display. */
1365 InsertConfigNode(pInst, "LUN#0", &pLunL0);
1366 InsertConfigString(pLunL0, "Driver", "MainDisplay");
1367 InsertConfigNode(pLunL0, "Config", &pCfg);
1368 Display *pDisplay = mDisplay;
1369 InsertConfigInteger(pCfg, "Object", (uintptr_t)pDisplay);
1370
1371
1372 /*
1373 * Firmware.
1374 */
1375 FirmwareType_T eFwType = FirmwareType_BIOS;
1376 hrc = pMachine->COMGETTER(FirmwareType)(&eFwType); H();
1377
1378#ifdef VBOX_WITH_EFI
1379 BOOL fEfiEnabled = (eFwType >= FirmwareType_EFI) && (eFwType <= FirmwareType_EFIDUAL);
1380#else
1381 BOOL fEfiEnabled = false;
1382#endif
1383 if (!fEfiEnabled)
1384 {
1385 /*
1386 * PC Bios.
1387 */
1388 InsertConfigNode(pDevices, "pcbios", &pDev);
1389 InsertConfigNode(pDev, "0", &pInst);
1390 InsertConfigInteger(pInst, "Trusted", 1); /* boolean */
1391 InsertConfigNode(pInst, "Config", &pBiosCfg);
1392 InsertConfigInteger(pBiosCfg, "RamSize", cbRam);
1393 InsertConfigInteger(pBiosCfg, "RamHoleSize", cbRamHole);
1394 InsertConfigInteger(pBiosCfg, "NumCPUs", cCpus);
1395 InsertConfigString(pBiosCfg, "HardDiskDevice", "piix3ide");
1396 InsertConfigString(pBiosCfg, "FloppyDevice", "i82078");
1397 InsertConfigInteger(pBiosCfg, "IOAPIC", fIOAPIC);
1398 InsertConfigInteger(pBiosCfg, "PXEDebug", fPXEDebug);
1399 InsertConfigBytes(pBiosCfg, "UUID", &HardwareUuid,sizeof(HardwareUuid));
1400 InsertConfigNode(pBiosCfg, "NetBoot", &pNetBootCfg);
1401 InsertConfigInteger(pBiosCfg, "McfgBase", uMcfgBase);
1402 InsertConfigInteger(pBiosCfg, "McfgLength", cbMcfgLength);
1403
1404 DeviceType_T bootDevice;
1405 if (SchemaDefs::MaxBootPosition > 9)
1406 {
1407 AssertMsgFailed(("Too many boot devices %d\n",
1408 SchemaDefs::MaxBootPosition));
1409 return VERR_INVALID_PARAMETER;
1410 }
1411
1412 for (ULONG pos = 1; pos <= SchemaDefs::MaxBootPosition; ++pos)
1413 {
1414 hrc = pMachine->GetBootOrder(pos, &bootDevice); H();
1415
1416 char szParamName[] = "BootDeviceX";
1417 szParamName[sizeof(szParamName) - 2] = ((char (pos - 1)) + '0');
1418
1419 const char *pszBootDevice;
1420 switch (bootDevice)
1421 {
1422 case DeviceType_Null:
1423 pszBootDevice = "NONE";
1424 break;
1425 case DeviceType_HardDisk:
1426 pszBootDevice = "IDE";
1427 break;
1428 case DeviceType_DVD:
1429 pszBootDevice = "DVD";
1430 break;
1431 case DeviceType_Floppy:
1432 pszBootDevice = "FLOPPY";
1433 break;
1434 case DeviceType_Network:
1435 pszBootDevice = "LAN";
1436 break;
1437 default:
1438 AssertMsgFailed(("Invalid bootDevice=%d\n", bootDevice));
1439 return VMSetError(pVM, VERR_INVALID_PARAMETER, RT_SRC_POS,
1440 N_("Invalid boot device '%d'"), bootDevice);
1441 }
1442 InsertConfigString(pBiosCfg, szParamName, pszBootDevice);
1443 }
1444 }
1445 else
1446 {
1447 /* Autodetect firmware type, basing on guest type */
1448 if (eFwType == FirmwareType_EFI)
1449 {
1450 eFwType = fIsGuest64Bit
1451 ? (FirmwareType_T)FirmwareType_EFI64
1452 : (FirmwareType_T)FirmwareType_EFI32;
1453 }
1454 bool const f64BitEntry = eFwType == FirmwareType_EFI64;
1455
1456 Utf8Str efiRomFile;
1457 rc = findEfiRom(virtualBox, eFwType, &efiRomFile);
1458 AssertRCReturn(rc, rc);
1459
1460 /* Get boot args */
1461 Bstr bootArgs;
1462 hrc = pMachine->GetExtraData(Bstr("VBoxInternal2/EfiBootArgs").raw(), bootArgs.asOutParam()); H();
1463
1464 /* Get device props */
1465 Bstr deviceProps;
1466 hrc = pMachine->GetExtraData(Bstr("VBoxInternal2/EfiDeviceProps").raw(), deviceProps.asOutParam()); H();
1467
1468 /* Get GOP mode settings */
1469 uint32_t u32GopMode = UINT32_MAX;
1470 hrc = pMachine->GetExtraData(Bstr("VBoxInternal2/EfiGopMode").raw(), bstr.asOutParam()); H();
1471 if (!bstr.isEmpty())
1472 u32GopMode = Utf8Str(bstr).toUInt32();
1473
1474 /* UGA mode settings */
1475 uint32_t u32UgaHorisontal = 0;
1476 hrc = pMachine->GetExtraData(Bstr("VBoxInternal2/EfiUgaHorizontalResolution").raw(), bstr.asOutParam()); H();
1477 if (!bstr.isEmpty())
1478 u32UgaHorisontal = Utf8Str(bstr).toUInt32();
1479
1480 uint32_t u32UgaVertical = 0;
1481 hrc = pMachine->GetExtraData(Bstr("VBoxInternal2/EfiUgaVerticalResolution").raw(), bstr.asOutParam()); H();
1482 if (!bstr.isEmpty())
1483 u32UgaVertical = Utf8Str(bstr).toUInt32();
1484
1485 /*
1486 * EFI subtree.
1487 */
1488 InsertConfigNode(pDevices, "efi", &pDev);
1489 InsertConfigNode(pDev, "0", &pInst);
1490 InsertConfigInteger(pInst, "Trusted", 1); /* boolean */
1491 InsertConfigNode(pInst, "Config", &pCfg);
1492 InsertConfigInteger(pCfg, "RamSize", cbRam);
1493 InsertConfigInteger(pCfg, "RamHoleSize", cbRamHole);
1494 InsertConfigInteger(pCfg, "NumCPUs", cCpus);
1495 InsertConfigString(pCfg, "EfiRom", efiRomFile);
1496 InsertConfigString(pCfg, "BootArgs", bootArgs);
1497 InsertConfigString(pCfg, "DeviceProps", deviceProps);
1498 InsertConfigInteger(pCfg, "IOAPIC", fIOAPIC);
1499 InsertConfigBytes(pCfg, "UUID", &HardwareUuid,sizeof(HardwareUuid));
1500 InsertConfigInteger(pCfg, "64BitEntry", f64BitEntry); /* boolean */
1501 InsertConfigInteger(pCfg, "GopMode", u32GopMode);
1502 InsertConfigInteger(pCfg, "UgaHorizontalResolution", u32UgaHorisontal);
1503 InsertConfigInteger(pCfg, "UgaVerticalResolution", u32UgaVertical);
1504
1505 /* For OS X guests we'll force passing host's DMI info to the guest */
1506 if (fOsXGuest)
1507 {
1508 InsertConfigInteger(pCfg, "DmiUseHostInfo", 1);
1509 InsertConfigInteger(pCfg, "DmiExposeMemoryTable", 1);
1510 }
1511 }
1512
1513 /*
1514 * Storage controllers.
1515 */
1516 com::SafeIfaceArray<IStorageController> ctrls;
1517 PCFGMNODE aCtrlNodes[StorageControllerType_LsiLogicSas + 1] = {};
1518 hrc = pMachine->COMGETTER(StorageControllers)(ComSafeArrayAsOutParam(ctrls)); H();
1519
1520 bool fFdcEnabled = false;
1521 for (size_t i = 0; i < ctrls.size(); ++i)
1522 {
1523 DeviceType_T *paLedDevType = NULL;
1524
1525 StorageControllerType_T enmCtrlType;
1526 rc = ctrls[i]->COMGETTER(ControllerType)(&enmCtrlType); H();
1527 AssertRelease((unsigned)enmCtrlType < RT_ELEMENTS(aCtrlNodes));
1528
1529 StorageBus_T enmBus;
1530 rc = ctrls[i]->COMGETTER(Bus)(&enmBus); H();
1531
1532 Bstr controllerName;
1533 rc = ctrls[i]->COMGETTER(Name)(controllerName.asOutParam()); H();
1534
1535 ULONG ulInstance = 999;
1536 rc = ctrls[i]->COMGETTER(Instance)(&ulInstance); H();
1537
1538 BOOL fUseHostIOCache;
1539 rc = ctrls[i]->COMGETTER(UseHostIOCache)(&fUseHostIOCache); H();
1540
1541 BOOL fBootable;
1542 rc = ctrls[i]->COMGETTER(Bootable)(&fBootable); H();
1543
1544 /* /Devices/<ctrldev>/ */
1545 const char *pszCtrlDev = convertControllerTypeToDev(enmCtrlType);
1546 pDev = aCtrlNodes[enmCtrlType];
1547 if (!pDev)
1548 {
1549 InsertConfigNode(pDevices, pszCtrlDev, &pDev);
1550 aCtrlNodes[enmCtrlType] = pDev; /* IDE variants are handled in the switch */
1551 }
1552
1553 /* /Devices/<ctrldev>/<instance>/ */
1554 PCFGMNODE pCtlInst = NULL;
1555 InsertConfigNode(pDev, Utf8StrFmt("%u", ulInstance).c_str(), &pCtlInst);
1556
1557 /* Device config: /Devices/<ctrldev>/<instance>/<values> & /ditto/Config/<values> */
1558 InsertConfigInteger(pCtlInst, "Trusted", 1);
1559 InsertConfigNode(pCtlInst, "Config", &pCfg);
1560
1561 switch (enmCtrlType)
1562 {
1563 case StorageControllerType_LsiLogic:
1564 {
1565 hrc = BusMgr->assignPciDevice("lsilogic", pCtlInst); H();
1566
1567 InsertConfigInteger(pCfg, "Bootable", fBootable);
1568
1569 /* Attach the status driver */
1570 Assert(cLedScsi >= 16);
1571 attachStatusDriver(pCtlInst, &mapStorageLeds[iLedScsi], 0, 15,
1572 &mapMediumAttachments, pszCtrlDev, ulInstance);
1573 paLedDevType = &maStorageDevType[iLedScsi];
1574 break;
1575 }
1576
1577 case StorageControllerType_BusLogic:
1578 {
1579 hrc = BusMgr->assignPciDevice("buslogic", pCtlInst); H();
1580
1581 InsertConfigInteger(pCfg, "Bootable", fBootable);
1582
1583 /* Attach the status driver */
1584 Assert(cLedScsi >= 16);
1585 attachStatusDriver(pCtlInst, &mapStorageLeds[iLedScsi], 0, 15,
1586 &mapMediumAttachments, pszCtrlDev, ulInstance);
1587 paLedDevType = &maStorageDevType[iLedScsi];
1588 break;
1589 }
1590
1591 case StorageControllerType_IntelAhci:
1592 {
1593 hrc = BusMgr->assignPciDevice("ahci", pCtlInst); H();
1594
1595 ULONG cPorts = 0;
1596 hrc = ctrls[i]->COMGETTER(PortCount)(&cPorts); H();
1597 InsertConfigInteger(pCfg, "PortCount", cPorts);
1598 InsertConfigInteger(pCfg, "Bootable", fBootable);
1599
1600 /* Needed configuration values for the bios, only first controller. */
1601 if (!BusMgr->hasPciDevice("ahci", 1))
1602 {
1603 if (pBiosCfg)
1604 {
1605 InsertConfigString(pBiosCfg, "SataHardDiskDevice", "ahci");
1606 }
1607
1608 for (uint32_t j = 0; j < 4; ++j)
1609 {
1610 static const char * const s_apszBiosConfig[4] =
1611 { "SataPrimaryMasterLUN", "SataPrimarySlaveLUN", "SataSecondaryMasterLUN", "SataSecondarySlaveLUN" };
1612
1613 LONG lPortNumber = -1;
1614 hrc = ctrls[i]->GetIDEEmulationPort(j, &lPortNumber); H();
1615 InsertConfigInteger(pCfg, g_apszIDEDrives[j], lPortNumber);
1616 if (pBiosCfg)
1617 InsertConfigInteger(pBiosCfg, s_apszBiosConfig[j], lPortNumber);
1618 }
1619 }
1620
1621 /* Attach the status driver */
1622 AssertRelease(cPorts <= cLedSata);
1623 attachStatusDriver(pCtlInst, &mapStorageLeds[iLedSata], 0, cPorts - 1,
1624 &mapMediumAttachments, pszCtrlDev, ulInstance);
1625 paLedDevType = &maStorageDevType[iLedSata];
1626 break;
1627 }
1628
1629 case StorageControllerType_PIIX3:
1630 case StorageControllerType_PIIX4:
1631 case StorageControllerType_ICH6:
1632 {
1633 /*
1634 * IDE (update this when the main interface changes)
1635 */
1636 hrc = BusMgr->assignPciDevice("piix3ide", pCtlInst); H();
1637 InsertConfigString(pCfg, "Type", controllerString(enmCtrlType));
1638 /* Attach the status driver */
1639 Assert(cLedIde >= 4);
1640 attachStatusDriver(pCtlInst, &mapStorageLeds[iLedIde], 0, 3,
1641 &mapMediumAttachments, pszCtrlDev, ulInstance);
1642 paLedDevType = &maStorageDevType[iLedIde];
1643
1644 /* IDE flavors */
1645 aCtrlNodes[StorageControllerType_PIIX3] = pDev;
1646 aCtrlNodes[StorageControllerType_PIIX4] = pDev;
1647 aCtrlNodes[StorageControllerType_ICH6] = pDev;
1648 break;
1649 }
1650
1651 case StorageControllerType_I82078:
1652 {
1653 /*
1654 * i82078 Floppy drive controller
1655 */
1656 fFdcEnabled = true;
1657 InsertConfigInteger(pCfg, "IRQ", 6);
1658 InsertConfigInteger(pCfg, "DMA", 2);
1659 InsertConfigInteger(pCfg, "MemMapped", 0 );
1660 InsertConfigInteger(pCfg, "IOBase", 0x3f0);
1661
1662 /* Attach the status driver */
1663 Assert(cLedFloppy >= 2);
1664 attachStatusDriver(pCtlInst, &mapStorageLeds[iLedFloppy], 0, 1,
1665 &mapMediumAttachments, pszCtrlDev, ulInstance);
1666 paLedDevType = &maStorageDevType[iLedFloppy];
1667 break;
1668 }
1669
1670 case StorageControllerType_LsiLogicSas:
1671 {
1672 hrc = BusMgr->assignPciDevice("lsilogicsas", pCtlInst); H();
1673
1674 InsertConfigString(pCfg, "ControllerType", "SAS1068");
1675 InsertConfigInteger(pCfg, "Bootable", fBootable);
1676
1677 /* Attach the status driver */
1678 Assert(cLedSas >= 8);
1679 attachStatusDriver(pCtlInst, &mapStorageLeds[iLedSas], 0, 7,
1680 &mapMediumAttachments, pszCtrlDev, ulInstance);
1681 paLedDevType = &maStorageDevType[iLedSas];
1682 break;
1683 }
1684
1685 default:
1686 AssertMsgFailedReturn(("invalid storage controller type: %d\n", enmCtrlType), VERR_GENERAL_FAILURE);
1687 }
1688
1689 /* Attach the media to the storage controllers. */
1690 com::SafeIfaceArray<IMediumAttachment> atts;
1691 hrc = pMachine->GetMediumAttachmentsOfController(controllerName.raw(),
1692 ComSafeArrayAsOutParam(atts)); H();
1693
1694 /* Builtin I/O cache - per device setting. */
1695 BOOL fBuiltinIoCache = true;
1696 hrc = pMachine->COMGETTER(IoCacheEnabled)(&fBuiltinIoCache); H();
1697
1698
1699 for (size_t j = 0; j < atts.size(); ++j)
1700 {
1701 IMediumAttachment *pMediumAtt = atts[j];
1702 rc = configMediumAttachment(pCtlInst,
1703 pszCtrlDev,
1704 ulInstance,
1705 enmBus,
1706 !!fUseHostIOCache,
1707 !!fBuiltinIoCache,
1708 false /* fSetupMerge */,
1709 0 /* uMergeSource */,
1710 0 /* uMergeTarget */,
1711 pMediumAtt,
1712 mMachineState,
1713 NULL /* phrc */,
1714 false /* fAttachDetach */,
1715 false /* fForceUnmount */,
1716 false /* fHotplug */,
1717 pVM,
1718 paLedDevType);
1719 if (RT_FAILURE(rc))
1720 return rc;
1721 }
1722 H();
1723 }
1724 H();
1725
1726 /*
1727 * Network adapters
1728 */
1729#ifdef VMWARE_NET_IN_SLOT_11
1730 bool fSwapSlots3and11 = false;
1731#endif
1732 PCFGMNODE pDevPCNet = NULL; /* PCNet-type devices */
1733 InsertConfigNode(pDevices, "pcnet", &pDevPCNet);
1734#ifdef VBOX_WITH_E1000
1735 PCFGMNODE pDevE1000 = NULL; /* E1000-type devices */
1736 InsertConfigNode(pDevices, "e1000", &pDevE1000);
1737#endif
1738#ifdef VBOX_WITH_VIRTIO
1739 PCFGMNODE pDevVirtioNet = NULL; /* Virtio network devices */
1740 InsertConfigNode(pDevices, "virtio-net", &pDevVirtioNet);
1741#endif /* VBOX_WITH_VIRTIO */
1742 std::list<BootNic> llBootNics;
1743 for (ULONG ulInstance = 0; ulInstance < maxNetworkAdapters; ++ulInstance)
1744 {
1745 ComPtr<INetworkAdapter> networkAdapter;
1746 hrc = pMachine->GetNetworkAdapter(ulInstance, networkAdapter.asOutParam()); H();
1747 BOOL fEnabledNetAdapter = FALSE;
1748 hrc = networkAdapter->COMGETTER(Enabled)(&fEnabledNetAdapter); H();
1749 if (!fEnabledNetAdapter)
1750 continue;
1751
1752 /*
1753 * The virtual hardware type. Create appropriate device first.
1754 */
1755 const char *pszAdapterName = "pcnet";
1756 NetworkAdapterType_T adapterType;
1757 hrc = networkAdapter->COMGETTER(AdapterType)(&adapterType); H();
1758 switch (adapterType)
1759 {
1760 case NetworkAdapterType_Am79C970A:
1761 case NetworkAdapterType_Am79C973:
1762 pDev = pDevPCNet;
1763 break;
1764#ifdef VBOX_WITH_E1000
1765 case NetworkAdapterType_I82540EM:
1766 case NetworkAdapterType_I82543GC:
1767 case NetworkAdapterType_I82545EM:
1768 pDev = pDevE1000;
1769 pszAdapterName = "e1000";
1770 break;
1771#endif
1772#ifdef VBOX_WITH_VIRTIO
1773 case NetworkAdapterType_Virtio:
1774 pDev = pDevVirtioNet;
1775 pszAdapterName = "virtio-net";
1776 break;
1777#endif /* VBOX_WITH_VIRTIO */
1778 default:
1779 AssertMsgFailed(("Invalid network adapter type '%d' for slot '%d'",
1780 adapterType, ulInstance));
1781 return VMSetError(pVM, VERR_INVALID_PARAMETER, RT_SRC_POS,
1782 N_("Invalid network adapter type '%d' for slot '%d'"),
1783 adapterType, ulInstance);
1784 }
1785
1786 InsertConfigNode(pDev, Utf8StrFmt("%u", ulInstance).c_str(), &pInst);
1787 InsertConfigInteger(pInst, "Trusted", 1); /* boolean */
1788 /* the first network card gets the PCI ID 3, the next 3 gets 8..10,
1789 * next 4 get 16..19. */
1790 int iPciDeviceNo;
1791 switch (ulInstance)
1792 {
1793 case 0:
1794 iPciDeviceNo = 3;
1795 break;
1796 case 1: case 2: case 3:
1797 iPciDeviceNo = ulInstance - 1 + 8;
1798 break;
1799 case 4: case 5: case 6: case 7:
1800 iPciDeviceNo = ulInstance - 4 + 16;
1801 break;
1802 default:
1803 /* auto assignment */
1804 iPciDeviceNo = -1;
1805 break;
1806 }
1807#ifdef VMWARE_NET_IN_SLOT_11
1808 /*
1809 * Dirty hack for PCI slot compatibility with VMWare,
1810 * it assigns slot 11 to the first network controller.
1811 */
1812 if (iPciDeviceNo == 3 && adapterType == NetworkAdapterType_I82545EM)
1813 {
1814 iPciDeviceNo = 0x11;
1815 fSwapSlots3and11 = true;
1816 }
1817 else if (iPciDeviceNo == 0x11 && fSwapSlots3and11)
1818 iPciDeviceNo = 3;
1819#endif
1820 PciBusAddress PciAddr = PciBusAddress(0, iPciDeviceNo, 0);
1821 hrc = BusMgr->assignPciDevice(pszAdapterName, pInst, PciAddr); H();
1822
1823 InsertConfigNode(pInst, "Config", &pCfg);
1824#ifdef VBOX_WITH_2X_4GB_ADDR_SPACE /* not safe here yet. */ /** @todo Make PCNet ring-0 safe on 32-bit mac kernels! */
1825 if (pDev == pDevPCNet)
1826 {
1827 InsertConfigInteger(pCfg, "R0Enabled", false);
1828 }
1829#endif
1830 /*
1831 * Collect information needed for network booting and add it to the list.
1832 */
1833 BootNic nic;
1834
1835 nic.mInstance = ulInstance;
1836 /* Could be updated by reference, if auto assigned */
1837 nic.mPciAddress = PciAddr;
1838
1839 hrc = networkAdapter->COMGETTER(BootPriority)(&nic.mBootPrio); H();
1840
1841 llBootNics.push_back(nic);
1842
1843 /*
1844 * The virtual hardware type. PCNet supports two types.
1845 */
1846 switch (adapterType)
1847 {
1848 case NetworkAdapterType_Am79C970A:
1849 InsertConfigInteger(pCfg, "Am79C973", 0);
1850 break;
1851 case NetworkAdapterType_Am79C973:
1852 InsertConfigInteger(pCfg, "Am79C973", 1);
1853 break;
1854 case NetworkAdapterType_I82540EM:
1855 InsertConfigInteger(pCfg, "AdapterType", 0);
1856 break;
1857 case NetworkAdapterType_I82543GC:
1858 InsertConfigInteger(pCfg, "AdapterType", 1);
1859 break;
1860 case NetworkAdapterType_I82545EM:
1861 InsertConfigInteger(pCfg, "AdapterType", 2);
1862 break;
1863 }
1864
1865 /*
1866 * Get the MAC address and convert it to binary representation
1867 */
1868 Bstr macAddr;
1869 hrc = networkAdapter->COMGETTER(MACAddress)(macAddr.asOutParam()); H();
1870 Assert(!macAddr.isEmpty());
1871 Utf8Str macAddrUtf8 = macAddr;
1872 char *macStr = (char*)macAddrUtf8.c_str();
1873 Assert(strlen(macStr) == 12);
1874 RTMAC Mac;
1875 memset(&Mac, 0, sizeof(Mac));
1876 char *pMac = (char*)&Mac;
1877 for (uint32_t i = 0; i < 6; ++i)
1878 {
1879 char c1 = *macStr++ - '0';
1880 if (c1 > 9)
1881 c1 -= 7;
1882 char c2 = *macStr++ - '0';
1883 if (c2 > 9)
1884 c2 -= 7;
1885 *pMac++ = ((c1 & 0x0f) << 4) | (c2 & 0x0f);
1886 }
1887 InsertConfigBytes(pCfg, "MAC", &Mac, sizeof(Mac));
1888
1889 /*
1890 * Check if the cable is supposed to be unplugged
1891 */
1892 BOOL fCableConnected;
1893 hrc = networkAdapter->COMGETTER(CableConnected)(&fCableConnected); H();
1894 InsertConfigInteger(pCfg, "CableConnected", fCableConnected ? 1 : 0);
1895
1896 /*
1897 * Line speed to report from custom drivers
1898 */
1899 ULONG ulLineSpeed;
1900 hrc = networkAdapter->COMGETTER(LineSpeed)(&ulLineSpeed); H();
1901 InsertConfigInteger(pCfg, "LineSpeed", ulLineSpeed);
1902
1903 /*
1904 * Attach the status driver.
1905 */
1906 attachStatusDriver(pInst, &mapNetworkLeds[ulInstance], 0, 0, NULL, NULL, 0);
1907
1908 /*
1909 * Configure the network card now
1910 */
1911 bool fIgnoreConnectFailure = mMachineState == MachineState_Restoring;
1912 rc = configNetwork(pszAdapterName,
1913 ulInstance,
1914 0,
1915 networkAdapter,
1916 pCfg,
1917 pLunL0,
1918 pInst,
1919 false /*fAttachDetach*/,
1920 fIgnoreConnectFailure);
1921 if (RT_FAILURE(rc))
1922 return rc;
1923 }
1924
1925 /*
1926 * Build network boot information and transfer it to the BIOS.
1927 */
1928 if (pNetBootCfg && !llBootNics.empty()) /* NetBoot node doesn't exist for EFI! */
1929 {
1930 llBootNics.sort(); /* Sort the list by boot priority. */
1931
1932 char achBootIdx[] = "0";
1933 unsigned uBootIdx = 0;
1934
1935 for (std::list<BootNic>::iterator it = llBootNics.begin(); it != llBootNics.end(); ++it)
1936 {
1937 /* A NIC with priority 0 is only used if it's first in the list. */
1938 if (it->mBootPrio == 0 && uBootIdx != 0)
1939 break;
1940
1941 PCFGMNODE pNetBtDevCfg;
1942 achBootIdx[0] = '0' + uBootIdx++; /* Boot device order. */
1943 InsertConfigNode(pNetBootCfg, achBootIdx, &pNetBtDevCfg);
1944 InsertConfigInteger(pNetBtDevCfg, "NIC", it->mInstance);
1945 InsertConfigInteger(pNetBtDevCfg, "PCIBusNo", it->mPciAddress.miBus);
1946 InsertConfigInteger(pNetBtDevCfg, "PCIDeviceNo", it->mPciAddress.miDevice);
1947 InsertConfigInteger(pNetBtDevCfg, "PCIFunctionNo", it->mPciAddress.miFn);
1948 }
1949 }
1950
1951 /*
1952 * Serial (UART) Ports
1953 */
1954 /* serial enabled mask to be passed to dev ACPI */
1955 uint16_t auSerialIoPortBase[SchemaDefs::SerialPortCount] = {0};
1956 uint8_t auSerialIrq[SchemaDefs::SerialPortCount] = {0};
1957 InsertConfigNode(pDevices, "serial", &pDev);
1958 for (ULONG ulInstance = 0; ulInstance < SchemaDefs::SerialPortCount; ++ulInstance)
1959 {
1960 ComPtr<ISerialPort> serialPort;
1961 hrc = pMachine->GetSerialPort(ulInstance, serialPort.asOutParam()); H();
1962 BOOL fEnabledSerPort = FALSE;
1963 if (serialPort)
1964 hrc = serialPort->COMGETTER(Enabled)(&fEnabledSerPort); H();
1965 if (!fEnabledSerPort)
1966 continue;
1967
1968 InsertConfigNode(pDev, Utf8StrFmt("%u", ulInstance).c_str(), &pInst);
1969 InsertConfigNode(pInst, "Config", &pCfg);
1970
1971 ULONG ulIRQ;
1972 hrc = serialPort->COMGETTER(IRQ)(&ulIRQ); H();
1973 InsertConfigInteger(pCfg, "IRQ", ulIRQ);
1974 auSerialIrq[ulInstance] = (uint8_t)ulIRQ;
1975
1976 ULONG ulIOBase;
1977 hrc = serialPort->COMGETTER(IOBase)(&ulIOBase); H();
1978 InsertConfigInteger(pCfg, "IOBase", ulIOBase);
1979 auSerialIoPortBase[ulInstance] = (uint16_t)ulIOBase;
1980
1981 BOOL fServer;
1982 hrc = serialPort->COMGETTER(Server)(&fServer); H();
1983 hrc = serialPort->COMGETTER(Path)(bstr.asOutParam()); H();
1984 PortMode_T eHostMode;
1985 hrc = serialPort->COMGETTER(HostMode)(&eHostMode); H();
1986 if (eHostMode != PortMode_Disconnected)
1987 {
1988 InsertConfigNode(pInst, "LUN#0", &pLunL0);
1989 if (eHostMode == PortMode_HostPipe)
1990 {
1991 InsertConfigString(pLunL0, "Driver", "Char");
1992 InsertConfigNode(pLunL0, "AttachedDriver", &pLunL1);
1993 InsertConfigString(pLunL1, "Driver", "NamedPipe");
1994 InsertConfigNode(pLunL1, "Config", &pLunL2);
1995 InsertConfigString(pLunL2, "Location", bstr);
1996 InsertConfigInteger(pLunL2, "IsServer", fServer);
1997 }
1998 else if (eHostMode == PortMode_HostDevice)
1999 {
2000 InsertConfigString(pLunL0, "Driver", "Host Serial");
2001 InsertConfigNode(pLunL0, "Config", &pLunL1);
2002 InsertConfigString(pLunL1, "DevicePath", bstr);
2003 }
2004 else if (eHostMode == PortMode_RawFile)
2005 {
2006 InsertConfigString(pLunL0, "Driver", "Char");
2007 InsertConfigNode(pLunL0, "AttachedDriver", &pLunL1);
2008 InsertConfigString(pLunL1, "Driver", "RawFile");
2009 InsertConfigNode(pLunL1, "Config", &pLunL2);
2010 InsertConfigString(pLunL2, "Location", bstr);
2011 }
2012 }
2013 }
2014
2015 /*
2016 * Parallel (LPT) Ports
2017 */
2018 InsertConfigNode(pDevices, "parallel", &pDev);
2019 for (ULONG ulInstance = 0; ulInstance < SchemaDefs::ParallelPortCount; ++ulInstance)
2020 {
2021 ComPtr<IParallelPort> parallelPort;
2022 hrc = pMachine->GetParallelPort(ulInstance, parallelPort.asOutParam()); H();
2023 BOOL fEnabledParPort = FALSE;
2024 if (parallelPort)
2025 {
2026 hrc = parallelPort->COMGETTER(Enabled)(&fEnabledParPort); H();
2027 }
2028 if (!fEnabledParPort)
2029 continue;
2030
2031 InsertConfigNode(pDev, Utf8StrFmt("%u", ulInstance).c_str(), &pInst);
2032 InsertConfigNode(pInst, "Config", &pCfg);
2033
2034 ULONG ulIRQ;
2035 hrc = parallelPort->COMGETTER(IRQ)(&ulIRQ); H();
2036 InsertConfigInteger(pCfg, "IRQ", ulIRQ);
2037 ULONG ulIOBase;
2038 hrc = parallelPort->COMGETTER(IOBase)(&ulIOBase); H();
2039 InsertConfigInteger(pCfg, "IOBase", ulIOBase);
2040 InsertConfigNode(pInst, "LUN#0", &pLunL0);
2041 InsertConfigString(pLunL0, "Driver", "HostParallel");
2042 InsertConfigNode(pLunL0, "Config", &pLunL1);
2043 hrc = parallelPort->COMGETTER(Path)(bstr.asOutParam()); H();
2044 InsertConfigString(pLunL1, "DevicePath", bstr);
2045 }
2046
2047 /*
2048 * VMM Device
2049 */
2050 InsertConfigNode(pDevices, "VMMDev", &pDev);
2051 InsertConfigNode(pDev, "0", &pInst);
2052 InsertConfigNode(pInst, "Config", &pCfg);
2053 InsertConfigInteger(pInst, "Trusted", 1); /* boolean */
2054 hrc = BusMgr->assignPciDevice("VMMDev", pInst); H();
2055
2056 Bstr hwVersion;
2057 hrc = pMachine->COMGETTER(HardwareVersion)(hwVersion.asOutParam()); H();
2058 InsertConfigInteger(pCfg, "RamSize", cbRam);
2059 if (hwVersion.compare(Bstr("1").raw()) == 0) /* <= 2.0.x */
2060 InsertConfigInteger(pCfg, "HeapEnabled", 0);
2061 Bstr snapshotFolder;
2062 hrc = pMachine->COMGETTER(SnapshotFolder)(snapshotFolder.asOutParam()); H();
2063 InsertConfigString(pCfg, "GuestCoreDumpDir", snapshotFolder);
2064
2065 /* the VMM device's Main driver */
2066 InsertConfigNode(pInst, "LUN#0", &pLunL0);
2067 InsertConfigString(pLunL0, "Driver", "HGCM");
2068 InsertConfigNode(pLunL0, "Config", &pCfg);
2069 InsertConfigInteger(pCfg, "Object", (uintptr_t)pVMMDev);
2070
2071 /*
2072 * Attach the status driver.
2073 */
2074 attachStatusDriver(pInst, &mapSharedFolderLed, 0, 0, NULL, NULL, 0);
2075
2076 /*
2077 * Audio Sniffer Device
2078 */
2079 InsertConfigNode(pDevices, "AudioSniffer", &pDev);
2080 InsertConfigNode(pDev, "0", &pInst);
2081 InsertConfigNode(pInst, "Config", &pCfg);
2082
2083 /* the Audio Sniffer device's Main driver */
2084 InsertConfigNode(pInst, "LUN#0", &pLunL0);
2085 InsertConfigString(pLunL0, "Driver", "MainAudioSniffer");
2086 InsertConfigNode(pLunL0, "Config", &pCfg);
2087 AudioSniffer *pAudioSniffer = mAudioSniffer;
2088 InsertConfigInteger(pCfg, "Object", (uintptr_t)pAudioSniffer);
2089
2090 /*
2091 * AC'97 ICH / SoundBlaster16 audio / Intel HD Audio
2092 */
2093 BOOL fAudioEnabled = FALSE;
2094 ComPtr<IAudioAdapter> audioAdapter;
2095 hrc = pMachine->COMGETTER(AudioAdapter)(audioAdapter.asOutParam()); H();
2096 if (audioAdapter)
2097 hrc = audioAdapter->COMGETTER(Enabled)(&fAudioEnabled); H();
2098
2099 if (fAudioEnabled)
2100 {
2101 AudioControllerType_T audioController;
2102 hrc = audioAdapter->COMGETTER(AudioController)(&audioController); H();
2103 switch (audioController)
2104 {
2105 case AudioControllerType_AC97:
2106 {
2107 /* default: ICH AC97 */
2108 InsertConfigNode(pDevices, "ichac97", &pDev);
2109 InsertConfigNode(pDev, "0", &pInst);
2110 InsertConfigInteger(pInst, "Trusted", 1); /* boolean */
2111 hrc = BusMgr->assignPciDevice("ichac97", pInst); H();
2112 InsertConfigNode(pInst, "Config", &pCfg);
2113 break;
2114 }
2115 case AudioControllerType_SB16:
2116 {
2117 /* legacy SoundBlaster16 */
2118 InsertConfigNode(pDevices, "sb16", &pDev);
2119 InsertConfigNode(pDev, "0", &pInst);
2120 InsertConfigInteger(pInst, "Trusted", 1); /* boolean */
2121 InsertConfigNode(pInst, "Config", &pCfg);
2122 InsertConfigInteger(pCfg, "IRQ", 5);
2123 InsertConfigInteger(pCfg, "DMA", 1);
2124 InsertConfigInteger(pCfg, "DMA16", 5);
2125 InsertConfigInteger(pCfg, "Port", 0x220);
2126 InsertConfigInteger(pCfg, "Version", 0x0405);
2127 break;
2128 }
2129 case AudioControllerType_HDA:
2130 {
2131 /* Intel HD Audio */
2132 InsertConfigNode(pDevices, "hda", &pDev);
2133 InsertConfigNode(pDev, "0", &pInst);
2134 InsertConfigInteger(pInst, "Trusted", 1); /* boolean */
2135 hrc = BusMgr->assignPciDevice("hda", pInst); H();
2136 InsertConfigNode(pInst, "Config", &pCfg);
2137 }
2138 }
2139
2140 /* the Audio driver */
2141 InsertConfigNode(pInst, "LUN#0", &pLunL0);
2142 InsertConfigString(pLunL0, "Driver", "AUDIO");
2143 InsertConfigNode(pLunL0, "Config", &pCfg);
2144
2145 AudioDriverType_T audioDriver;
2146 hrc = audioAdapter->COMGETTER(AudioDriver)(&audioDriver); H();
2147 switch (audioDriver)
2148 {
2149 case AudioDriverType_Null:
2150 {
2151 InsertConfigString(pCfg, "AudioDriver", "null");
2152 break;
2153 }
2154#ifdef RT_OS_WINDOWS
2155#ifdef VBOX_WITH_WINMM
2156 case AudioDriverType_WinMM:
2157 {
2158 InsertConfigString(pCfg, "AudioDriver", "winmm");
2159 break;
2160 }
2161#endif
2162 case AudioDriverType_DirectSound:
2163 {
2164 InsertConfigString(pCfg, "AudioDriver", "dsound");
2165 break;
2166 }
2167#endif /* RT_OS_WINDOWS */
2168#ifdef RT_OS_SOLARIS
2169 case AudioDriverType_SolAudio:
2170 {
2171 InsertConfigString(pCfg, "AudioDriver", "solaudio");
2172 break;
2173 }
2174#endif
2175#ifdef RT_OS_LINUX
2176# ifdef VBOX_WITH_ALSA
2177 case AudioDriverType_ALSA:
2178 {
2179 InsertConfigString(pCfg, "AudioDriver", "alsa");
2180 break;
2181 }
2182# endif
2183# ifdef VBOX_WITH_PULSE
2184 case AudioDriverType_Pulse:
2185 {
2186 InsertConfigString(pCfg, "AudioDriver", "pulse");
2187 break;
2188 }
2189# endif
2190#endif /* RT_OS_LINUX */
2191#if defined(RT_OS_LINUX) || defined(RT_OS_FREEBSD) || defined(VBOX_WITH_SOLARIS_OSS)
2192 case AudioDriverType_OSS:
2193 {
2194 InsertConfigString(pCfg, "AudioDriver", "oss");
2195 break;
2196 }
2197#endif
2198#ifdef RT_OS_FREEBSD
2199# ifdef VBOX_WITH_PULSE
2200 case AudioDriverType_Pulse:
2201 {
2202 InsertConfigString(pCfg, "AudioDriver", "pulse");
2203 break;
2204 }
2205# endif
2206#endif
2207#ifdef RT_OS_DARWIN
2208 case AudioDriverType_CoreAudio:
2209 {
2210 InsertConfigString(pCfg, "AudioDriver", "coreaudio");
2211 break;
2212 }
2213#endif
2214 }
2215 hrc = pMachine->COMGETTER(Name)(bstr.asOutParam()); H();
2216 InsertConfigString(pCfg, "StreamName", bstr);
2217 }
2218
2219 /*
2220 * The USB Controller.
2221 */
2222 ComPtr<IUSBController> USBCtlPtr;
2223 hrc = pMachine->COMGETTER(USBController)(USBCtlPtr.asOutParam());
2224 if (USBCtlPtr)
2225 {
2226 BOOL fOhciEnabled;
2227 hrc = USBCtlPtr->COMGETTER(Enabled)(&fOhciEnabled); H();
2228 if (fOhciEnabled)
2229 {
2230 InsertConfigNode(pDevices, "usb-ohci", &pDev);
2231 InsertConfigNode(pDev, "0", &pInst);
2232 InsertConfigNode(pInst, "Config", &pCfg);
2233 InsertConfigInteger(pInst, "Trusted", 1); /* boolean */
2234 hrc = BusMgr->assignPciDevice("usb-ohci", pInst); H();
2235 InsertConfigNode(pInst, "LUN#0", &pLunL0);
2236 InsertConfigString(pLunL0, "Driver", "VUSBRootHub");
2237 InsertConfigNode(pLunL0, "Config", &pCfg);
2238
2239 /*
2240 * Attach the status driver.
2241 */
2242 attachStatusDriver(pInst, &mapUSBLed[0], 0, 0, NULL, NULL, 0);
2243
2244#ifdef VBOX_WITH_EHCI
2245 BOOL fEhciEnabled;
2246 hrc = USBCtlPtr->COMGETTER(EnabledEhci)(&fEhciEnabled); H();
2247 if (fEhciEnabled)
2248 {
2249 /*
2250 * USB 2.0 is only available if the proper ExtPack is installed.
2251 *
2252 * Note. Configuring EHCI here and providing messages about
2253 * the missing extpack isn't exactly clean, but it is a
2254 * necessary evil to patch over legacy compatability issues
2255 * introduced by the new distribution model.
2256 */
2257 static const char *s_pszUsbExtPackName = "Oracle VM VirtualBox Extension Pack";
2258# ifdef VBOX_WITH_EXTPACK
2259 if (mptrExtPackManager->isExtPackUsable(s_pszUsbExtPackName))
2260# endif
2261 {
2262 InsertConfigNode(pDevices, "usb-ehci", &pDev);
2263 InsertConfigNode(pDev, "0", &pInst);
2264 InsertConfigNode(pInst, "Config", &pCfg);
2265 InsertConfigInteger(pInst, "Trusted", 1); /* boolean */
2266 hrc = BusMgr->assignPciDevice("usb-ehci", pInst); H();
2267
2268 InsertConfigNode(pInst, "LUN#0", &pLunL0);
2269 InsertConfigString(pLunL0, "Driver", "VUSBRootHub");
2270 InsertConfigNode(pLunL0, "Config", &pCfg);
2271
2272 /*
2273 * Attach the status driver.
2274 */
2275 attachStatusDriver(pInst, &mapUSBLed[1], 0, 0, NULL, NULL, 0);
2276 }
2277# ifdef VBOX_WITH_EXTPACK
2278 else
2279 {
2280 /* Always fatal! Up to VBox 4.0.4 we allowed to start the VM anyway
2281 * but this induced problems when the user saved + restored the VM! */
2282 return VMSetError(pVM, VERR_NOT_FOUND, RT_SRC_POS,
2283 N_("Implementation of the USB 2.0 controller not found!\n"
2284 "Because the USB 2.0 controller state is part of the saved "
2285 "VM state, the VM cannot be started. To fix "
2286 "this problem, either install the '%s' or disable USB 2.0 "
2287 "support in the VM settings"),
2288 s_pszUsbExtPackName);
2289 }
2290# endif
2291 }
2292#endif
2293
2294 /*
2295 * Virtual USB Devices.
2296 */
2297 PCFGMNODE pUsbDevices = NULL;
2298 InsertConfigNode(pRoot, "USB", &pUsbDevices);
2299
2300#ifdef VBOX_WITH_USB
2301 {
2302 /*
2303 * Global USB options, currently unused as we'll apply the 2.0 -> 1.1 morphing
2304 * on a per device level now.
2305 */
2306 InsertConfigNode(pUsbDevices, "USBProxy", &pCfg);
2307 InsertConfigNode(pCfg, "GlobalConfig", &pCfg);
2308 // This globally enables the 2.0 -> 1.1 device morphing of proxied devices to keep windows quiet.
2309 //InsertConfigInteger(pCfg, "Force11Device", true);
2310 // The following breaks stuff, but it makes MSDs work in vista. (I include it here so
2311 // that it's documented somewhere.) Users needing it can use:
2312 // VBoxManage setextradata "myvm" "VBoxInternal/USB/USBProxy/GlobalConfig/Force11PacketSize" 1
2313 //InsertConfigInteger(pCfg, "Force11PacketSize", true);
2314 }
2315#endif
2316
2317#ifdef VBOX_WITH_USB_VIDEO
2318
2319 InsertConfigNode(pUsbDevices, "Webcam", &pDev);
2320 InsertConfigNode(pDev, "0", &pInst);
2321 InsertConfigNode(pInst, "Config", &pCfg);
2322# if 0 /* Experiments with attaching */
2323 InsertConfigInteger(pCfg, "USBVER", RT_BIT(2));
2324# endif
2325 InsertConfigNode(pInst, "LUN#0", &pLunL0);
2326# ifdef VBOX_WITH_USB_VIDEO_TEST
2327 InsertConfigString(pLunL0, "Driver", "WebcamFileFeeder");
2328 InsertConfigNode(pLunL0, "Config", &pCfg);
2329 InsertConfigString(pCfg, "DirToFeed", "out");
2330# else
2331 InsertConfigString(pLunL0, "Driver", "UsbWebcamInterface");
2332 InsertConfigNode(pLunL0, "Config", &pCfg);
2333 InsertConfigInteger(pCfg, "Object", mUsbWebcamInterface);
2334# endif
2335#endif
2336#ifdef VBOX_WITH_USB_CARDREADER
2337 InsertConfigNode(pUsbDevices, "CardReader", &pDev);
2338 InsertConfigNode(pDev, "0", &pInst);
2339 InsertConfigNode(pInst, "Config", &pCfg);
2340 InsertConfigNode(pInst, "LUN#0", &pLunL0);
2341# ifdef VBOX_WITH_USB_CARDREADER_TEST
2342 InsertConfigString(pLunL0, "Driver", "DrvDirectCardReader");
2343 InsertConfigNode(pLunL0, "Config", &pCfg);
2344# endif
2345#endif
2346# if 0 /* Virtual MSD*/
2347
2348 InsertConfigNode(pUsbDevices, "Msd", &pDev);
2349 InsertConfigNode(pDev, "0", &pInst);
2350 InsertConfigNode(pInst, "Config", &pCfg);
2351 InsertConfigNode(pInst, "LUN#0", &pLunL0);
2352
2353 InsertConfigString(pLunL0, "Driver", "SCSI");
2354 InsertConfigNode(pLunL0, "Config", &pCfg);
2355
2356 InsertConfigNode(pLunL0, "AttachedDriver", &pLunL1);
2357 InsertConfigString(pLunL1, "Driver", "Block");
2358 InsertConfigNode(pLunL1, "Config", &pCfg);
2359 InsertConfigString(pCfg, "Type", "HardDisk");
2360 InsertConfigInteger(pCfg, "Mountable", 0);
2361
2362 InsertConfigNode(pLunL1, "AttachedDriver", &pLunL2);
2363 InsertConfigString(pLunL2, "Driver", "VD");
2364 InsertConfigNode(pLunL2, "Config", &pCfg);
2365 InsertConfigString(pCfg, "Path", "/Volumes/DataHFS/bird/VDIs/linux.vdi");
2366 InsertConfigString(pCfg, "Format", "VDI");
2367# endif
2368
2369 /* Virtual USB Mouse/Tablet */
2370 PointingHidType_T aPointingHid;
2371 hrc = pMachine->COMGETTER(PointingHidType)(&aPointingHid); H();
2372 if (aPointingHid == PointingHidType_USBMouse || aPointingHid == PointingHidType_USBTablet)
2373 {
2374 InsertConfigNode(pUsbDevices, "HidMouse", &pDev);
2375 InsertConfigNode(pDev, "0", &pInst);
2376 InsertConfigNode(pInst, "Config", &pCfg);
2377
2378 if (aPointingHid == PointingHidType_USBTablet)
2379 {
2380 InsertConfigInteger(pCfg, "Absolute", 1);
2381 }
2382 else
2383 {
2384 InsertConfigInteger(pCfg, "Absolute", 0);
2385 }
2386 InsertConfigNode(pInst, "LUN#0", &pLunL0);
2387 InsertConfigString(pLunL0, "Driver", "MouseQueue");
2388 InsertConfigNode(pLunL0, "Config", &pCfg);
2389 InsertConfigInteger(pCfg, "QueueSize", 128);
2390
2391 InsertConfigNode(pLunL0, "AttachedDriver", &pLunL1);
2392 InsertConfigString(pLunL1, "Driver", "MainMouse");
2393 InsertConfigNode(pLunL1, "Config", &pCfg);
2394 pMouse = mMouse;
2395 InsertConfigInteger(pCfg, "Object", (uintptr_t)pMouse);
2396 }
2397
2398 /* Virtual USB Keyboard */
2399 KeyboardHidType_T aKbdHid;
2400 hrc = pMachine->COMGETTER(KeyboardHidType)(&aKbdHid); H();
2401 if (aKbdHid == KeyboardHidType_USBKeyboard)
2402 {
2403 InsertConfigNode(pUsbDevices, "HidKeyboard", &pDev);
2404 InsertConfigNode(pDev, "0", &pInst);
2405 InsertConfigNode(pInst, "Config", &pCfg);
2406
2407 InsertConfigNode(pInst, "LUN#0", &pLunL0);
2408 InsertConfigString(pLunL0, "Driver", "KeyboardQueue");
2409 InsertConfigNode(pLunL0, "Config", &pCfg);
2410 InsertConfigInteger(pCfg, "QueueSize", 64);
2411
2412 InsertConfigNode(pLunL0, "AttachedDriver", &pLunL1);
2413 InsertConfigString(pLunL1, "Driver", "MainKeyboard");
2414 InsertConfigNode(pLunL1, "Config", &pCfg);
2415 pKeyboard = mKeyboard;
2416 InsertConfigInteger(pCfg, "Object", (uintptr_t)pKeyboard);
2417 }
2418 }
2419 }
2420
2421 /*
2422 * Clipboard
2423 */
2424 {
2425 ClipboardMode_T mode = ClipboardMode_Disabled;
2426 hrc = pMachine->COMGETTER(ClipboardMode)(&mode); H();
2427
2428 if (mode != ClipboardMode_Disabled)
2429 {
2430 /* Load the service */
2431 rc = pVMMDev->hgcmLoadService("VBoxSharedClipboard", "VBoxSharedClipboard");
2432
2433 if (RT_FAILURE(rc))
2434 {
2435 LogRel(("VBoxSharedClipboard is not available. rc = %Rrc\n", rc));
2436 /* That is not a fatal failure. */
2437 rc = VINF_SUCCESS;
2438 }
2439 else
2440 {
2441 /* Setup the service. */
2442 VBOXHGCMSVCPARM parm;
2443
2444 parm.type = VBOX_HGCM_SVC_PARM_32BIT;
2445
2446 switch (mode)
2447 {
2448 default:
2449 case ClipboardMode_Disabled:
2450 {
2451 LogRel(("VBoxSharedClipboard mode: Off\n"));
2452 parm.u.uint32 = VBOX_SHARED_CLIPBOARD_MODE_OFF;
2453 break;
2454 }
2455 case ClipboardMode_GuestToHost:
2456 {
2457 LogRel(("VBoxSharedClipboard mode: Guest to Host\n"));
2458 parm.u.uint32 = VBOX_SHARED_CLIPBOARD_MODE_GUEST_TO_HOST;
2459 break;
2460 }
2461 case ClipboardMode_HostToGuest:
2462 {
2463 LogRel(("VBoxSharedClipboard mode: Host to Guest\n"));
2464 parm.u.uint32 = VBOX_SHARED_CLIPBOARD_MODE_HOST_TO_GUEST;
2465 break;
2466 }
2467 case ClipboardMode_Bidirectional:
2468 {
2469 LogRel(("VBoxSharedClipboard mode: Bidirectional\n"));
2470 parm.u.uint32 = VBOX_SHARED_CLIPBOARD_MODE_BIDIRECTIONAL;
2471 break;
2472 }
2473 }
2474
2475 pVMMDev->hgcmHostCall("VBoxSharedClipboard", VBOX_SHARED_CLIPBOARD_HOST_FN_SET_MODE, 1, &parm);
2476
2477 parm.setUInt32(!useHostClipboard());
2478
2479 pVMMDev->hgcmHostCall("VBoxSharedClipboard", VBOX_SHARED_CLIPBOARD_HOST_FN_SET_HEADLESS, 1, &parm);
2480
2481 Log(("Set VBoxSharedClipboard mode\n"));
2482 }
2483 }
2484 }
2485
2486#ifdef VBOX_WITH_DRAG_AND_DROP
2487 /*
2488 * Drag & Drop
2489 */
2490 {
2491 /* Load the service */
2492 rc = pVMMDev->hgcmLoadService("VBoxDragAndDropSvc", "VBoxDragAndDropSvc");
2493
2494 if (RT_FAILURE(rc))
2495 {
2496 LogRel(("VBoxDragAndDropService is not available. rc = %Rrc\n", rc));
2497 /* That is not a fatal failure. */
2498 rc = VINF_SUCCESS;
2499 }
2500 else
2501 {
2502 HGCMSVCEXTHANDLE hDummy;
2503 rc = HGCMHostRegisterServiceExtension(&hDummy, "VBoxDragAndDropSvc",
2504 &GuestDnD::notifyGuestDragAndDropEvent,
2505 getGuest());
2506 if (RT_FAILURE(rc))
2507 Log(("Cannot register VBoxDragAndDropSvc extension!\n"));
2508 else
2509 Log(("VBoxDragAndDropSvc loaded\n"));
2510 }
2511 }
2512#endif /* VBOX_WITH_DRAG_AND_DROP */
2513
2514#ifdef VBOX_WITH_CROGL
2515 /*
2516 * crOpenGL
2517 */
2518 {
2519 BOOL fEnabled3D = false;
2520 hrc = pMachine->COMGETTER(Accelerate3DEnabled)(&fEnabled3D); H();
2521
2522 if (fEnabled3D)
2523 {
2524 BOOL fSupports3D = false;
2525 hrc = host->COMGETTER(Acceleration3DAvailable)(&fSupports3D); H();
2526 if (!fSupports3D)
2527 return VMSetError(pVM, VERR_NOT_AVAILABLE, RT_SRC_POS,
2528 N_("This VM was configured to use 3D acceleration. However, the "
2529 "3D support of the host is not working properly and the "
2530 "VM cannot be started. To fix this problem, either "
2531 "fix the host 3D support (update the host graphics driver?) "
2532 "or disable 3D acceleration in the VM settings"));
2533
2534 /* Load the service */
2535 rc = pVMMDev->hgcmLoadService("VBoxSharedCrOpenGL", "VBoxSharedCrOpenGL");
2536 if (RT_FAILURE(rc))
2537 {
2538 LogRel(("Failed to load Shared OpenGL service %Rrc\n", rc));
2539 /* That is not a fatal failure. */
2540 rc = VINF_SUCCESS;
2541 }
2542 else
2543 {
2544 LogRel(("Shared crOpenGL service loaded.\n"));
2545
2546 /* Setup the service. */
2547 VBOXHGCMSVCPARM parm;
2548 parm.type = VBOX_HGCM_SVC_PARM_PTR;
2549
2550 parm.u.pointer.addr = (IConsole *)(Console *)this;
2551 parm.u.pointer.size = sizeof(IConsole *);
2552
2553 rc = pVMMDev->hgcmHostCall("VBoxSharedCrOpenGL", SHCRGL_HOST_FN_SET_CONSOLE, SHCRGL_CPARMS_SET_CONSOLE, &parm);
2554 if (!RT_SUCCESS(rc))
2555 AssertMsgFailed(("SHCRGL_HOST_FN_SET_CONSOLE failed with %Rrc\n", rc));
2556
2557 parm.u.pointer.addr = pVM;
2558 parm.u.pointer.size = sizeof(pVM);
2559 rc = pVMMDev->hgcmHostCall("VBoxSharedCrOpenGL", SHCRGL_HOST_FN_SET_VM, SHCRGL_CPARMS_SET_VM, &parm);
2560 if (!RT_SUCCESS(rc))
2561 AssertMsgFailed(("SHCRGL_HOST_FN_SET_VM failed with %Rrc\n", rc));
2562 }
2563
2564 }
2565 }
2566#endif
2567
2568#ifdef VBOX_WITH_GUEST_PROPS
2569 /*
2570 * Guest property service
2571 */
2572
2573 rc = configGuestProperties(this, pVM);
2574#endif /* VBOX_WITH_GUEST_PROPS defined */
2575
2576#ifdef VBOX_WITH_GUEST_CONTROL
2577 /*
2578 * Guest control service
2579 */
2580
2581 rc = configGuestControl(this);
2582#endif /* VBOX_WITH_GUEST_CONTROL defined */
2583
2584 /*
2585 * ACPI
2586 */
2587 BOOL fACPI;
2588 hrc = biosSettings->COMGETTER(ACPIEnabled)(&fACPI); H();
2589 if (fACPI)
2590 {
2591 BOOL fCpuHotPlug = false;
2592 BOOL fShowCpu = fOsXGuest;
2593 /* Always show the CPU leafs when we have multiple VCPUs or when the IO-APIC is enabled.
2594 * The Windows SMP kernel needs a CPU leaf or else its idle loop will burn cpu cycles; the
2595 * intelppm driver refuses to register an idle state handler.
2596 */
2597 if ((cCpus > 1) || fIOAPIC)
2598 fShowCpu = true;
2599
2600 hrc = pMachine->COMGETTER(CPUHotPlugEnabled)(&fCpuHotPlug); H();
2601
2602 InsertConfigNode(pDevices, "acpi", &pDev);
2603 InsertConfigNode(pDev, "0", &pInst);
2604 InsertConfigInteger(pInst, "Trusted", 1); /* boolean */
2605 InsertConfigNode(pInst, "Config", &pCfg);
2606 hrc = BusMgr->assignPciDevice("acpi", pInst); H();
2607
2608 InsertConfigInteger(pCfg, "RamSize", cbRam);
2609 InsertConfigInteger(pCfg, "RamHoleSize", cbRamHole);
2610 InsertConfigInteger(pCfg, "NumCPUs", cCpus);
2611
2612 InsertConfigInteger(pCfg, "IOAPIC", fIOAPIC);
2613 InsertConfigInteger(pCfg, "FdcEnabled", fFdcEnabled);
2614 InsertConfigInteger(pCfg, "HpetEnabled", fHpetEnabled);
2615 InsertConfigInteger(pCfg, "SmcEnabled", fSmcEnabled);
2616 InsertConfigInteger(pCfg, "ShowRtc", fShowRtc);
2617 if (fOsXGuest && !llBootNics.empty())
2618 {
2619 BootNic aNic = llBootNics.front();
2620 uint32_t u32NicPciAddr = (aNic.mPciAddress.miDevice << 16) | aNic.mPciAddress.miFn;
2621 InsertConfigInteger(pCfg, "NicPciAddress", u32NicPciAddr);
2622 }
2623 if (fOsXGuest && fAudioEnabled)
2624 {
2625 PciBusAddress Address;
2626 if (BusMgr->findPciAddress("hda", 0, Address))
2627 {
2628 uint32_t u32AudioPciAddr = (Address.miDevice << 16) | Address.miFn;
2629 InsertConfigInteger(pCfg, "AudioPciAddress", u32AudioPciAddr);
2630 }
2631 }
2632 InsertConfigInteger(pCfg, "IocPciAddress", uIocPciAddress);
2633 if (chipsetType == ChipsetType_ICH9)
2634 {
2635 InsertConfigInteger(pCfg, "McfgBase", uMcfgBase);
2636 InsertConfigInteger(pCfg, "McfgLength", cbMcfgLength);
2637 }
2638 InsertConfigInteger(pCfg, "HostBusPciAddress", uHbcPciAddress);
2639 InsertConfigInteger(pCfg, "ShowCpu", fShowCpu);
2640 InsertConfigInteger(pCfg, "CpuHotPlug", fCpuHotPlug);
2641
2642 InsertConfigInteger(pCfg, "Serial0IoPortBase", auSerialIoPortBase[0]);
2643 InsertConfigInteger(pCfg, "Serial0Irq", auSerialIrq[0]);
2644
2645 InsertConfigInteger(pCfg, "Serial1IoPortBase", auSerialIoPortBase[1]);
2646 InsertConfigInteger(pCfg, "Serial1Irq", auSerialIrq[1]);
2647
2648 InsertConfigNode(pInst, "LUN#0", &pLunL0);
2649 InsertConfigString(pLunL0, "Driver", "ACPIHost");
2650 InsertConfigNode(pLunL0, "Config", &pCfg);
2651
2652 /* Attach the dummy CPU drivers */
2653 for (ULONG iCpuCurr = 1; iCpuCurr < cCpus; iCpuCurr++)
2654 {
2655 BOOL fCpuAttached = true;
2656
2657 if (fCpuHotPlug)
2658 {
2659 hrc = pMachine->GetCPUStatus(iCpuCurr, &fCpuAttached); H();
2660 }
2661
2662 if (fCpuAttached)
2663 {
2664 InsertConfigNode(pInst, Utf8StrFmt("LUN#%u", iCpuCurr).c_str(), &pLunL0);
2665 InsertConfigString(pLunL0, "Driver", "ACPICpu");
2666 InsertConfigNode(pLunL0, "Config", &pCfg);
2667 }
2668 }
2669 }
2670
2671 /*
2672 * Configure DBGF (Debug(ger) Facility).
2673 */
2674 {
2675 PCFGMNODE pDbgf;
2676 InsertConfigNode(pRoot, "DBGF", &pDbgf);
2677
2678 /* Paths to search for debug info and such things. */
2679 hrc = pMachine->COMGETTER(SettingsFilePath)(bstr.asOutParam()); H();
2680 Utf8Str strSettingsPath(bstr);
2681 bstr.setNull();
2682 strSettingsPath.stripFilename();
2683
2684 char szHomeDir[RTPATH_MAX];
2685 rc = RTPathUserHome(szHomeDir, sizeof(szHomeDir));
2686 if (RT_FAILURE(rc))
2687 szHomeDir[0] = '\0';
2688
2689 Utf8Str strPath;
2690 strPath.append(strSettingsPath).append("/debug/;");
2691 strPath.append(strSettingsPath).append("/;");
2692 strPath.append(szHomeDir).append("/");
2693
2694 InsertConfigString(pDbgf, "Path", strPath.c_str());
2695
2696 /* Tracing configuration. */
2697 BOOL fTracingEnabled;
2698 hrc = pMachine->COMGETTER(TracingEnabled)(&fTracingEnabled); H();
2699 if (fTracingEnabled)
2700 InsertConfigInteger(pDbgf, "TracingEnabled", 1);
2701
2702 hrc = pMachine->COMGETTER(TracingConfig)(bstr.asOutParam()); H();
2703 if (fTracingEnabled)
2704 InsertConfigString(pDbgf, "TracingConfig", bstr);
2705
2706 BOOL fAllowTracingToAccessVM;
2707 hrc = pMachine->COMGETTER(AllowTracingToAccessVM)(&fAllowTracingToAccessVM); H();
2708 if (fAllowTracingToAccessVM)
2709 InsertConfigInteger(pPDM, "AllowTracingToAccessVM", 1);
2710 }
2711 }
2712 catch (ConfigError &x)
2713 {
2714 // InsertConfig threw something:
2715 return x.m_vrc;
2716 }
2717
2718#ifdef VBOX_WITH_EXTPACK
2719 /*
2720 * Call the extension pack hooks if everything went well thus far.
2721 */
2722 if (RT_SUCCESS(rc))
2723 {
2724 pAlock->release();
2725 rc = mptrExtPackManager->callAllVmConfigureVmmHooks(this, pVM);
2726 pAlock->acquire();
2727 }
2728#endif
2729
2730 /*
2731 * Apply the CFGM overlay.
2732 */
2733 if (RT_SUCCESS(rc))
2734 rc = configCfgmOverlay(pVM, virtualBox, pMachine);
2735
2736#undef H
2737
2738 pAlock->release(); /* Avoid triggering the lock order inversion check. */
2739
2740 /*
2741 * Register VM state change handler.
2742 */
2743 int rc2 = VMR3AtStateRegister(pVM, Console::vmstateChangeCallback, this);
2744 AssertRC(rc2);
2745 if (RT_SUCCESS(rc))
2746 rc = rc2;
2747
2748 /*
2749 * Register VM runtime error handler.
2750 */
2751 rc2 = VMR3AtRuntimeErrorRegister(pVM, Console::setVMRuntimeErrorCallback, this);
2752 AssertRC(rc2);
2753 if (RT_SUCCESS(rc))
2754 rc = rc2;
2755
2756 pAlock->acquire();
2757
2758 LogFlowFunc(("vrc = %Rrc\n", rc));
2759 LogFlowFuncLeave();
2760
2761 return rc;
2762}
2763
2764/**
2765 * Applies the CFGM overlay as specified by /VBoxInternal/XXX extra data
2766 * values.
2767 *
2768 * @returns VBox status code.
2769 * @param pVM The VM handle.
2770 * @param pVirtualBox Pointer to the IVirtualBox interface.
2771 * @param pMachine Pointer to the IMachine interface.
2772 */
2773/* static */
2774int Console::configCfgmOverlay(PVM pVM, IVirtualBox *pVirtualBox, IMachine *pMachine)
2775{
2776 /*
2777 * CFGM overlay handling.
2778 *
2779 * Here we check the extra data entries for CFGM values
2780 * and create the nodes and insert the values on the fly. Existing
2781 * values will be removed and reinserted. CFGM is typed, so by default
2782 * we will guess whether it's a string or an integer (byte arrays are
2783 * not currently supported). It's possible to override this autodetection
2784 * by adding "string:", "integer:" or "bytes:" (future).
2785 *
2786 * We first perform a run on global extra data, then on the machine
2787 * extra data to support global settings with local overrides.
2788 */
2789 PCFGMNODE pRoot = CFGMR3GetRoot(pVM);
2790 int rc = VINF_SUCCESS;
2791 try
2792 {
2793 /** @todo add support for removing nodes and byte blobs. */
2794 /*
2795 * Get the next key
2796 */
2797 SafeArray<BSTR> aGlobalExtraDataKeys;
2798 SafeArray<BSTR> aMachineExtraDataKeys;
2799 HRESULT hrc = pVirtualBox->GetExtraDataKeys(ComSafeArrayAsOutParam(aGlobalExtraDataKeys));
2800 AssertMsg(SUCCEEDED(hrc), ("VirtualBox::GetExtraDataKeys failed with %Rhrc\n", hrc));
2801
2802 // remember the no. of global values so we can call the correct method below
2803 size_t cGlobalValues = aGlobalExtraDataKeys.size();
2804
2805 hrc = pMachine->GetExtraDataKeys(ComSafeArrayAsOutParam(aMachineExtraDataKeys));
2806 AssertMsg(SUCCEEDED(hrc), ("VirtualBox::GetExtraDataKeys failed with %Rhrc\n", hrc));
2807
2808 // build a combined list from global keys...
2809 std::list<Utf8Str> llExtraDataKeys;
2810
2811 for (size_t i = 0; i < aGlobalExtraDataKeys.size(); ++i)
2812 llExtraDataKeys.push_back(Utf8Str(aGlobalExtraDataKeys[i]));
2813 // ... and machine keys
2814 for (size_t i = 0; i < aMachineExtraDataKeys.size(); ++i)
2815 llExtraDataKeys.push_back(Utf8Str(aMachineExtraDataKeys[i]));
2816
2817 size_t i2 = 0;
2818 for (std::list<Utf8Str>::const_iterator it = llExtraDataKeys.begin();
2819 it != llExtraDataKeys.end();
2820 ++it, ++i2)
2821 {
2822 const Utf8Str &strKey = *it;
2823
2824 /*
2825 * We only care about keys starting with "VBoxInternal/" (skip "G:" or "M:")
2826 */
2827 if (!strKey.startsWith("VBoxInternal/"))
2828 continue;
2829
2830 const char *pszExtraDataKey = strKey.c_str() + sizeof("VBoxInternal/") - 1;
2831
2832 // get the value
2833 Bstr bstrExtraDataValue;
2834 if (i2 < cGlobalValues)
2835 // this is still one of the global values:
2836 hrc = pVirtualBox->GetExtraData(Bstr(strKey).raw(),
2837 bstrExtraDataValue.asOutParam());
2838 else
2839 hrc = pMachine->GetExtraData(Bstr(strKey).raw(),
2840 bstrExtraDataValue.asOutParam());
2841 if (FAILED(hrc))
2842 LogRel(("Warning: Cannot get extra data key %s, rc = %Rrc\n", strKey.c_str(), hrc));
2843
2844 /*
2845 * The key will be in the format "Node1/Node2/Value" or simply "Value".
2846 * Split the two and get the node, delete the value and create the node
2847 * if necessary.
2848 */
2849 PCFGMNODE pNode;
2850 const char *pszCFGMValueName = strrchr(pszExtraDataKey, '/');
2851 if (pszCFGMValueName)
2852 {
2853 /* terminate the node and advance to the value (Utf8Str might not
2854 offically like this but wtf) */
2855 *(char*)pszCFGMValueName = '\0';
2856 ++pszCFGMValueName;
2857
2858 /* does the node already exist? */
2859 pNode = CFGMR3GetChild(pRoot, pszExtraDataKey);
2860 if (pNode)
2861 CFGMR3RemoveValue(pNode, pszCFGMValueName);
2862 else
2863 {
2864 /* create the node */
2865 rc = CFGMR3InsertNode(pRoot, pszExtraDataKey, &pNode);
2866 if (RT_FAILURE(rc))
2867 {
2868 AssertLogRelMsgRC(rc, ("failed to insert node '%s'\n", pszExtraDataKey));
2869 continue;
2870 }
2871 Assert(pNode);
2872 }
2873 }
2874 else
2875 {
2876 /* root value (no node path). */
2877 pNode = pRoot;
2878 pszCFGMValueName = pszExtraDataKey;
2879 pszExtraDataKey--;
2880 CFGMR3RemoveValue(pNode, pszCFGMValueName);
2881 }
2882
2883 /*
2884 * Now let's have a look at the value.
2885 * Empty strings means that we should remove the value, which we've
2886 * already done above.
2887 */
2888 Utf8Str strCFGMValueUtf8(bstrExtraDataValue);
2889 if (!strCFGMValueUtf8.isEmpty())
2890 {
2891 uint64_t u64Value;
2892
2893 /* check for type prefix first. */
2894 if (!strncmp(strCFGMValueUtf8.c_str(), "string:", sizeof("string:") - 1))
2895 InsertConfigString(pNode, pszCFGMValueName, strCFGMValueUtf8.c_str() + sizeof("string:") - 1);
2896 else if (!strncmp(strCFGMValueUtf8.c_str(), "integer:", sizeof("integer:") - 1))
2897 {
2898 rc = RTStrToUInt64Full(strCFGMValueUtf8.c_str() + sizeof("integer:") - 1, 0, &u64Value);
2899 if (RT_SUCCESS(rc))
2900 rc = CFGMR3InsertInteger(pNode, pszCFGMValueName, u64Value);
2901 }
2902 else if (!strncmp(strCFGMValueUtf8.c_str(), "bytes:", sizeof("bytes:") - 1))
2903 rc = VERR_NOT_IMPLEMENTED;
2904 /* auto detect type. */
2905 else if (RT_SUCCESS(RTStrToUInt64Full(strCFGMValueUtf8.c_str(), 0, &u64Value)))
2906 rc = CFGMR3InsertInteger(pNode, pszCFGMValueName, u64Value);
2907 else
2908 InsertConfigString(pNode, pszCFGMValueName, strCFGMValueUtf8);
2909 AssertLogRelMsgRCBreak(rc, ("failed to insert CFGM value '%s' to key '%s'\n", strCFGMValueUtf8.c_str(), pszExtraDataKey));
2910 }
2911 }
2912 }
2913 catch (ConfigError &x)
2914 {
2915 // InsertConfig threw something:
2916 return x.m_vrc;
2917 }
2918 return rc;
2919}
2920
2921/**
2922 * Ellipsis to va_list wrapper for calling setVMRuntimeErrorCallback.
2923 */
2924/*static*/
2925void Console::setVMRuntimeErrorCallbackF(PVM pVM, void *pvConsole, uint32_t fFlags, const char *pszErrorId, const char *pszFormat, ...)
2926{
2927 va_list va;
2928 va_start(va, pszFormat);
2929 setVMRuntimeErrorCallback(pVM, pvConsole, fFlags, pszErrorId, pszFormat, va);
2930 va_end(va);
2931}
2932
2933/* XXX introduce RT format specifier */
2934static uint64_t formatDiskSize(uint64_t u64Size, const char **pszUnit)
2935{
2936 if (u64Size > INT64_C(5000)*_1G)
2937 {
2938 *pszUnit = "TB";
2939 return u64Size / _1T;
2940 }
2941 else if (u64Size > INT64_C(5000)*_1M)
2942 {
2943 *pszUnit = "GB";
2944 return u64Size / _1G;
2945 }
2946 else
2947 {
2948 *pszUnit = "MB";
2949 return u64Size / _1M;
2950 }
2951}
2952
2953int Console::configMediumAttachment(PCFGMNODE pCtlInst,
2954 const char *pcszDevice,
2955 unsigned uInstance,
2956 StorageBus_T enmBus,
2957 bool fUseHostIOCache,
2958 bool fBuiltinIoCache,
2959 bool fSetupMerge,
2960 unsigned uMergeSource,
2961 unsigned uMergeTarget,
2962 IMediumAttachment *pMediumAtt,
2963 MachineState_T aMachineState,
2964 HRESULT *phrc,
2965 bool fAttachDetach,
2966 bool fForceUnmount,
2967 bool fHotplug,
2968 PVM pVM,
2969 DeviceType_T *paLedDevType)
2970{
2971 // InsertConfig* throws
2972 try
2973 {
2974 int rc = VINF_SUCCESS;
2975 HRESULT hrc;
2976 Bstr bstr;
2977
2978// #define RC_CHECK() AssertMsgReturn(RT_SUCCESS(rc), ("rc=%Rrc\n", rc), rc)
2979#define H() AssertMsgReturn(!FAILED(hrc), ("hrc=%Rhrc\n", hrc), VERR_GENERAL_FAILURE)
2980
2981 LONG lDev;
2982 hrc = pMediumAtt->COMGETTER(Device)(&lDev); H();
2983 LONG lPort;
2984 hrc = pMediumAtt->COMGETTER(Port)(&lPort); H();
2985 DeviceType_T lType;
2986 hrc = pMediumAtt->COMGETTER(Type)(&lType); H();
2987 BOOL fNonRotational;
2988 hrc = pMediumAtt->COMGETTER(NonRotational)(&fNonRotational); H();
2989 BOOL fDiscard;
2990 hrc = pMediumAtt->COMGETTER(Discard)(&fDiscard); H();
2991
2992 unsigned uLUN;
2993 PCFGMNODE pLunL0 = NULL;
2994 hrc = Console::convertBusPortDeviceToLun(enmBus, lPort, lDev, uLUN); H();
2995
2996 /* First check if the LUN already exists. */
2997 pLunL0 = CFGMR3GetChildF(pCtlInst, "LUN#%u", uLUN);
2998 if (pLunL0)
2999 {
3000 if (fAttachDetach)
3001 {
3002 if (lType != DeviceType_HardDisk)
3003 {
3004 /* Unmount existing media only for floppy and DVD drives. */
3005 PPDMIBASE pBase;
3006 rc = PDMR3QueryLun(pVM, pcszDevice, uInstance, uLUN, &pBase);
3007 if (RT_FAILURE(rc))
3008 {
3009 if (rc == VERR_PDM_LUN_NOT_FOUND || rc == VERR_PDM_NO_DRIVER_ATTACHED_TO_LUN)
3010 rc = VINF_SUCCESS;
3011 AssertRC(rc);
3012 }
3013 else
3014 {
3015 PPDMIMOUNT pIMount = PDMIBASE_QUERY_INTERFACE(pBase, PDMIMOUNT);
3016 AssertReturn(pIMount, VERR_INVALID_POINTER);
3017
3018 /* Unmount the media (but do not eject the medium!) */
3019 rc = pIMount->pfnUnmount(pIMount, fForceUnmount, false /*=fEject*/);
3020 if (rc == VERR_PDM_MEDIA_NOT_MOUNTED)
3021 rc = VINF_SUCCESS;
3022 /* for example if the medium is locked */
3023 else if (RT_FAILURE(rc))
3024 return rc;
3025 }
3026 }
3027
3028 rc = PDMR3DeviceDetach(pVM, pcszDevice, uInstance, uLUN, fHotplug ? 0 : PDM_TACH_FLAGS_NOT_HOT_PLUG);
3029 if (rc == VERR_PDM_NO_DRIVER_ATTACHED_TO_LUN)
3030 rc = VINF_SUCCESS;
3031 AssertRCReturn(rc, rc);
3032
3033 CFGMR3RemoveNode(pLunL0);
3034 }
3035 else
3036 AssertFailedReturn(VERR_INTERNAL_ERROR);
3037 }
3038
3039 InsertConfigNode(pCtlInst, Utf8StrFmt("LUN#%u", uLUN).c_str(), &pLunL0);
3040
3041 PCFGMNODE pCfg = CFGMR3GetChild(pCtlInst, "Config");
3042 if (pCfg)
3043 {
3044 if (!strcmp(pcszDevice, "piix3ide"))
3045 {
3046 PCFGMNODE pDrive = CFGMR3GetChild(pCfg, g_apszIDEDrives[uLUN]);
3047 if (!pDrive)
3048 InsertConfigNode(pCfg, g_apszIDEDrives[uLUN], &pDrive);
3049 /* Don't use the RemoveConfigValue wrapper above, as we don't
3050 * know if the leaf is present or not. */
3051 CFGMR3RemoveValue(pDrive, "NonRotationalMedium");
3052 InsertConfigInteger(pDrive, "NonRotationalMedium", !!fNonRotational);
3053 }
3054 else if (!strcmp(pcszDevice, "ahci"))
3055 {
3056 Utf8Str strPort = Utf8StrFmt("Port%u", uLUN);
3057 PCFGMNODE pDrive = CFGMR3GetChild(pCfg, strPort.c_str());
3058 if (!pDrive)
3059 InsertConfigNode(pCfg, strPort.c_str(), &pDrive);
3060 /* Don't use the RemoveConfigValue wrapper above, as we don't
3061 * know if the leaf is present or not. */
3062 CFGMR3RemoveValue(pDrive, "NonRotationalMedium");
3063 InsertConfigInteger(pDrive, "NonRotationalMedium", !!fNonRotational);
3064 }
3065 }
3066
3067 Utf8Str devicePath = Utf8StrFmt("%s/%u/LUN#%u", pcszDevice, uInstance, uLUN);
3068 mapMediumAttachments[devicePath] = pMediumAtt;
3069
3070 /* SCSI has a another driver between device and block. */
3071 if (enmBus == StorageBus_SCSI || enmBus == StorageBus_SAS)
3072 {
3073 InsertConfigString(pLunL0, "Driver", "SCSI");
3074 PCFGMNODE pL1Cfg = NULL;
3075 InsertConfigNode(pLunL0, "Config", &pL1Cfg);
3076 InsertConfigInteger(pL1Cfg, "NonRotationalMedium", !!fNonRotational);
3077
3078 InsertConfigNode(pLunL0, "AttachedDriver", &pLunL0);
3079 }
3080
3081 ComPtr<IMedium> pMedium;
3082 hrc = pMediumAtt->COMGETTER(Medium)(pMedium.asOutParam()); H();
3083
3084 /*
3085 * 1. Only check this for hard disk images.
3086 * 2. Only check during VM creation and not later, especially not during
3087 * taking an online snapshot!
3088 */
3089 if ( lType == DeviceType_HardDisk
3090 && ( aMachineState == MachineState_Starting
3091 || aMachineState == MachineState_Restoring))
3092 {
3093 /*
3094 * Some sanity checks.
3095 */
3096 ComPtr<IMediumFormat> pMediumFormat;
3097 hrc = pMedium->COMGETTER(MediumFormat)(pMediumFormat.asOutParam()); H();
3098 ULONG uCaps;
3099 hrc = pMediumFormat->COMGETTER(Capabilities)(&uCaps); H();
3100 if (uCaps & MediumFormatCapabilities_File)
3101 {
3102 Bstr strFile;
3103 hrc = pMedium->COMGETTER(Location)(strFile.asOutParam()); H();
3104 Utf8Str utfFile = Utf8Str(strFile);
3105 Bstr strSnap;
3106 ComPtr<IMachine> pMachine = machine();
3107 hrc = pMachine->COMGETTER(SnapshotFolder)(strSnap.asOutParam()); H();
3108 Utf8Str utfSnap = Utf8Str(strSnap);
3109 RTFSTYPE enmFsTypeFile = RTFSTYPE_UNKNOWN;
3110 RTFSTYPE enmFsTypeSnap = RTFSTYPE_UNKNOWN;
3111 int rc2 = RTFsQueryType(utfFile.c_str(), &enmFsTypeFile);
3112 AssertMsgRCReturn(rc2, ("Querying the file type of '%s' failed!\n", utfFile.c_str()), rc2);
3113 /* Ignore the error code. On error, the file system type is still 'unknown' so
3114 * none of the following paths are taken. This can happen for new VMs which
3115 * still don't have a snapshot folder. */
3116 (void)RTFsQueryType(utfSnap.c_str(), &enmFsTypeSnap);
3117 if (!mfSnapshotFolderDiskTypeShown)
3118 {
3119 LogRel(("File system of '%s' (snapshots) is %s\n", utfSnap.c_str(), RTFsTypeName(enmFsTypeSnap)));
3120 mfSnapshotFolderDiskTypeShown = true;
3121 }
3122 LogRel(("File system of '%s' is %s\n", utfFile.c_str(), RTFsTypeName(enmFsTypeFile)));
3123 LONG64 i64Size;
3124 hrc = pMedium->COMGETTER(LogicalSize)(&i64Size); H();
3125#ifdef RT_OS_WINDOWS
3126 if ( enmFsTypeFile == RTFSTYPE_FAT
3127 && i64Size >= _4G)
3128 {
3129 const char *pszUnit;
3130 uint64_t u64Print = formatDiskSize((uint64_t)i64Size, &pszUnit);
3131 setVMRuntimeErrorCallbackF(pVM, this, 0,
3132 "FatPartitionDetected",
3133 N_("The medium '%ls' has a logical size of %RU64%s "
3134 "but the file system the medium is located on seems "
3135 "to be FAT(32) which cannot handle files bigger than 4GB.\n"
3136 "We strongly recommend to put all your virtual disk images and "
3137 "the snapshot folder onto an NTFS partition"),
3138 strFile.raw(), u64Print, pszUnit);
3139 }
3140#else /* !RT_OS_WINDOWS */
3141 if ( enmFsTypeFile == RTFSTYPE_FAT
3142 || enmFsTypeFile == RTFSTYPE_EXT
3143 || enmFsTypeFile == RTFSTYPE_EXT2
3144 || enmFsTypeFile == RTFSTYPE_EXT3
3145 || enmFsTypeFile == RTFSTYPE_EXT4)
3146 {
3147 RTFILE file;
3148 rc = RTFileOpen(&file, utfFile.c_str(), RTFILE_O_READ | RTFILE_O_OPEN | RTFILE_O_DENY_NONE);
3149 if (RT_SUCCESS(rc))
3150 {
3151 RTFOFF maxSize;
3152 /* Careful: This function will work only on selected local file systems! */
3153 rc = RTFileGetMaxSizeEx(file, &maxSize);
3154 RTFileClose(file);
3155 if ( RT_SUCCESS(rc)
3156 && maxSize > 0
3157 && i64Size > (LONG64)maxSize)
3158 {
3159 const char *pszUnitSiz;
3160 const char *pszUnitMax;
3161 uint64_t u64PrintSiz = formatDiskSize((LONG64)i64Size, &pszUnitSiz);
3162 uint64_t u64PrintMax = formatDiskSize(maxSize, &pszUnitMax);
3163 setVMRuntimeErrorCallbackF(pVM, this, 0,
3164 "FatPartitionDetected", /* <= not exact but ... */
3165 N_("The medium '%ls' has a logical size of %RU64%s "
3166 "but the file system the medium is located on can "
3167 "only handle files up to %RU64%s in theory.\n"
3168 "We strongly recommend to put all your virtual disk "
3169 "images and the snapshot folder onto a proper "
3170 "file system (e.g. ext3) with a sufficient size"),
3171 strFile.raw(), u64PrintSiz, pszUnitSiz, u64PrintMax, pszUnitMax);
3172 }
3173 }
3174 }
3175#endif /* !RT_OS_WINDOWS */
3176
3177 /*
3178 * Snapshot folder:
3179 * Here we test only for a FAT partition as we had to create a dummy file otherwise
3180 */
3181 if ( enmFsTypeSnap == RTFSTYPE_FAT
3182 && i64Size >= _4G
3183 && !mfSnapshotFolderSizeWarningShown)
3184 {
3185 const char *pszUnit;
3186 uint64_t u64Print = formatDiskSize(i64Size, &pszUnit);
3187 setVMRuntimeErrorCallbackF(pVM, this, 0,
3188 "FatPartitionDetected",
3189#ifdef RT_OS_WINDOWS
3190 N_("The snapshot folder of this VM '%ls' seems to be located on "
3191 "a FAT(32) file system. The logical size of the medium '%ls' "
3192 "(%RU64%s) is bigger than the maximum file size this file "
3193 "system can handle (4GB).\n"
3194 "We strongly recommend to put all your virtual disk images and "
3195 "the snapshot folder onto an NTFS partition"),
3196#else
3197 N_("The snapshot folder of this VM '%ls' seems to be located on "
3198 "a FAT(32) file system. The logical size of the medium '%ls' "
3199 "(%RU64%s) is bigger than the maximum file size this file "
3200 "system can handle (4GB).\n"
3201 "We strongly recommend to put all your virtual disk images and "
3202 "the snapshot folder onto a proper file system (e.g. ext3)"),
3203#endif
3204 strSnap.raw(), strFile.raw(), u64Print, pszUnit);
3205 /* Show this particular warning only once */
3206 mfSnapshotFolderSizeWarningShown = true;
3207 }
3208
3209#ifdef RT_OS_LINUX
3210 /*
3211 * Ext4 bug: Check if the host I/O cache is disabled and the disk image is located
3212 * on an ext4 partition. Later we have to check the Linux kernel version!
3213 * This bug apparently applies to the XFS file system as well.
3214 * Linux 2.6.36 is known to be fixed (tested with 2.6.36-rc4).
3215 */
3216
3217 char szOsRelease[128];
3218 rc = RTSystemQueryOSInfo(RTSYSOSINFO_RELEASE, szOsRelease, sizeof(szOsRelease));
3219 bool fKernelHasODirectBug = RT_FAILURE(rc)
3220 || (RTStrVersionCompare(szOsRelease, "2.6.36-rc4") < 0);
3221
3222 if ( (uCaps & MediumFormatCapabilities_Asynchronous)
3223 && !fUseHostIOCache
3224 && fKernelHasODirectBug)
3225 {
3226 if ( enmFsTypeFile == RTFSTYPE_EXT4
3227 || enmFsTypeFile == RTFSTYPE_XFS)
3228 {
3229 setVMRuntimeErrorCallbackF(pVM, this, 0,
3230 "Ext4PartitionDetected",
3231 N_("The host I/O cache for at least one controller is disabled "
3232 "and the medium '%ls' for this VM "
3233 "is located on an %s partition. There is a known Linux "
3234 "kernel bug which can lead to the corruption of the virtual "
3235 "disk image under these conditions.\n"
3236 "Either enable the host I/O cache permanently in the VM "
3237 "settings or put the disk image and the snapshot folder "
3238 "onto a different file system.\n"
3239 "The host I/O cache will now be enabled for this medium"),
3240 strFile.raw(), enmFsTypeFile == RTFSTYPE_EXT4 ? "ext4" : "xfs");
3241 fUseHostIOCache = true;
3242 }
3243 else if ( ( enmFsTypeSnap == RTFSTYPE_EXT4
3244 || enmFsTypeSnap == RTFSTYPE_XFS)
3245 && !mfSnapshotFolderExt4WarningShown)
3246 {
3247 setVMRuntimeErrorCallbackF(pVM, this, 0,
3248 "Ext4PartitionDetected",
3249 N_("The host I/O cache for at least one controller is disabled "
3250 "and the snapshot folder for this VM "
3251 "is located on an %s partition. There is a known Linux "
3252 "kernel bug which can lead to the corruption of the virtual "
3253 "disk image under these conditions.\n"
3254 "Either enable the host I/O cache permanently in the VM "
3255 "settings or put the disk image and the snapshot folder "
3256 "onto a different file system.\n"
3257 "The host I/O cache will now be enabled for this medium"),
3258 enmFsTypeSnap == RTFSTYPE_EXT4 ? "ext4" : "xfs");
3259 fUseHostIOCache = true;
3260 mfSnapshotFolderExt4WarningShown = true;
3261 }
3262 }
3263#endif
3264 }
3265 }
3266
3267 BOOL fPassthrough;
3268 hrc = pMediumAtt->COMGETTER(Passthrough)(&fPassthrough); H();
3269
3270 ComObjPtr<IBandwidthGroup> pBwGroup;
3271 Bstr strBwGroup;
3272 hrc = pMediumAtt->COMGETTER(BandwidthGroup)(pBwGroup.asOutParam()); H();
3273
3274 if (!pBwGroup.isNull())
3275 {
3276 hrc = pBwGroup->COMGETTER(Name)(strBwGroup.asOutParam()); H();
3277 }
3278
3279 rc = configMedium(pLunL0,
3280 !!fPassthrough,
3281 lType,
3282 fUseHostIOCache,
3283 fBuiltinIoCache,
3284 fSetupMerge,
3285 uMergeSource,
3286 uMergeTarget,
3287 strBwGroup.isEmpty() ? NULL : Utf8Str(strBwGroup).c_str(),
3288 !!fDiscard,
3289 pMedium,
3290 aMachineState,
3291 phrc);
3292 if (RT_FAILURE(rc))
3293 return rc;
3294
3295 if (fAttachDetach)
3296 {
3297 /* Attach the new driver. */
3298 rc = PDMR3DeviceAttach(pVM, pcszDevice, uInstance, uLUN,
3299 fHotplug ? 0 : PDM_TACH_FLAGS_NOT_HOT_PLUG, NULL /*ppBase*/);
3300 AssertRCReturn(rc, rc);
3301
3302 /* There is no need to handle removable medium mounting, as we
3303 * unconditionally replace everthing including the block driver level.
3304 * This means the new medium will be picked up automatically. */
3305 }
3306
3307 if (paLedDevType)
3308 paLedDevType[uLUN] = lType;
3309 }
3310 catch (ConfigError &x)
3311 {
3312 // InsertConfig threw something:
3313 return x.m_vrc;
3314 }
3315
3316#undef H
3317
3318 return VINF_SUCCESS;;
3319}
3320
3321int Console::configMedium(PCFGMNODE pLunL0,
3322 bool fPassthrough,
3323 DeviceType_T enmType,
3324 bool fUseHostIOCache,
3325 bool fBuiltinIoCache,
3326 bool fSetupMerge,
3327 unsigned uMergeSource,
3328 unsigned uMergeTarget,
3329 const char *pcszBwGroup,
3330 bool fDiscard,
3331 IMedium *pMedium,
3332 MachineState_T aMachineState,
3333 HRESULT *phrc)
3334{
3335 // InsertConfig* throws
3336 try
3337 {
3338 int rc = VINF_SUCCESS;
3339 HRESULT hrc;
3340 Bstr bstr;
3341 PCFGMNODE pLunL1 = NULL;
3342 PCFGMNODE pCfg = NULL;
3343
3344#define H() \
3345 AssertMsgReturnStmt(SUCCEEDED(hrc), ("hrc=%Rhrc\n", hrc), if (phrc) *phrc = hrc, Global::vboxStatusCodeFromCOM(hrc))
3346
3347
3348 BOOL fHostDrive = FALSE;
3349 MediumType_T mediumType = MediumType_Normal;
3350 if (pMedium)
3351 {
3352 hrc = pMedium->COMGETTER(HostDrive)(&fHostDrive); H();
3353 hrc = pMedium->COMGETTER(Type)(&mediumType); H();
3354 }
3355
3356 if (fHostDrive)
3357 {
3358 Assert(pMedium);
3359 if (enmType == DeviceType_DVD)
3360 {
3361 InsertConfigString(pLunL0, "Driver", "HostDVD");
3362 InsertConfigNode(pLunL0, "Config", &pCfg);
3363
3364 hrc = pMedium->COMGETTER(Location)(bstr.asOutParam()); H();
3365 InsertConfigString(pCfg, "Path", bstr);
3366
3367 InsertConfigInteger(pCfg, "Passthrough", fPassthrough);
3368 }
3369 else if (enmType == DeviceType_Floppy)
3370 {
3371 InsertConfigString(pLunL0, "Driver", "HostFloppy");
3372 InsertConfigNode(pLunL0, "Config", &pCfg);
3373
3374 hrc = pMedium->COMGETTER(Location)(bstr.asOutParam()); H();
3375 InsertConfigString(pCfg, "Path", bstr);
3376 }
3377 }
3378 else
3379 {
3380 InsertConfigString(pLunL0, "Driver", "Block");
3381 InsertConfigNode(pLunL0, "Config", &pCfg);
3382 switch (enmType)
3383 {
3384 case DeviceType_DVD:
3385 InsertConfigString(pCfg, "Type", "DVD");
3386 InsertConfigInteger(pCfg, "Mountable", 1);
3387 break;
3388 case DeviceType_Floppy:
3389 InsertConfigString(pCfg, "Type", "Floppy 1.44");
3390 InsertConfigInteger(pCfg, "Mountable", 1);
3391 break;
3392 case DeviceType_HardDisk:
3393 default:
3394 InsertConfigString(pCfg, "Type", "HardDisk");
3395 InsertConfigInteger(pCfg, "Mountable", 0);
3396 }
3397
3398 if ( pMedium
3399 && ( enmType == DeviceType_DVD
3400 || enmType == DeviceType_Floppy)
3401 )
3402 {
3403 // if this medium represents an ISO image and this image is inaccessible,
3404 // the ignore it instead of causing a failure; this can happen when we
3405 // restore a VM state and the ISO has disappeared, e.g. because the Guest
3406 // Additions were mounted and the user upgraded VirtualBox. Previously
3407 // we failed on startup, but that's not good because the only way out then
3408 // would be to discard the VM state...
3409 MediumState_T mediumState;
3410 hrc = pMedium->RefreshState(&mediumState); H();
3411 if (mediumState == MediumState_Inaccessible)
3412 {
3413 Bstr loc;
3414 hrc = pMedium->COMGETTER(Location)(loc.asOutParam()); H();
3415 setVMRuntimeErrorCallbackF(VMR3GetVM(mpUVM),
3416 this,
3417 0,
3418 "DvdOrFloppyImageInaccessible",
3419 "The image file '%ls' is inaccessible and is being ignored. Please select a different image file for the virtual %s drive.",
3420 loc.raw(),
3421 enmType == DeviceType_DVD ? "DVD" : "floppy");
3422 pMedium = NULL;
3423 }
3424 }
3425
3426 if (pMedium)
3427 {
3428 /* Start with length of parent chain, as the list is reversed */
3429 unsigned uImage = 0;
3430 IMedium *pTmp = pMedium;
3431 while (pTmp)
3432 {
3433 uImage++;
3434 hrc = pTmp->COMGETTER(Parent)(&pTmp); H();
3435 }
3436 /* Index of last image */
3437 uImage--;
3438
3439#if 0 /* Enable for I/O debugging */
3440 InsertConfigNode(pLunL0, "AttachedDriver", &pLunL0);
3441 InsertConfigString(pLunL0, "Driver", "DiskIntegrity");
3442 InsertConfigNode(pLunL0, "Config", &pCfg);
3443 InsertConfigInteger(pCfg, "CheckConsistency", 0);
3444 InsertConfigInteger(pCfg, "CheckDoubleCompletions", 1);
3445#endif
3446
3447 InsertConfigNode(pLunL0, "AttachedDriver", &pLunL1);
3448 InsertConfigString(pLunL1, "Driver", "VD");
3449 InsertConfigNode(pLunL1, "Config", &pCfg);
3450
3451 hrc = pMedium->COMGETTER(Location)(bstr.asOutParam()); H();
3452 InsertConfigString(pCfg, "Path", bstr);
3453
3454 hrc = pMedium->COMGETTER(Format)(bstr.asOutParam()); H();
3455 InsertConfigString(pCfg, "Format", bstr);
3456
3457 if (mediumType == MediumType_Readonly)
3458 InsertConfigInteger(pCfg, "ReadOnly", 1);
3459 else if (enmType == DeviceType_Floppy)
3460 InsertConfigInteger(pCfg, "MaybeReadOnly", 1);
3461
3462 /* Start without exclusive write access to the images. */
3463 /** @todo Live Migration: I don't quite like this, we risk screwing up when
3464 * we're resuming the VM if some 3rd dude have any of the VDIs open
3465 * with write sharing denied. However, if the two VMs are sharing a
3466 * image it really is necessary....
3467 *
3468 * So, on the "lock-media" command, the target teleporter should also
3469 * make DrvVD undo TempReadOnly. It gets interesting if we fail after
3470 * that. Grumble. */
3471 if ( enmType == DeviceType_HardDisk
3472 && ( aMachineState == MachineState_TeleportingIn
3473 || aMachineState == MachineState_FaultTolerantSyncing))
3474 InsertConfigInteger(pCfg, "TempReadOnly", 1);
3475
3476 /* Flag for opening the medium for sharing between VMs. This
3477 * is done at the moment only for the first (and only) medium
3478 * in the chain, as shared media can have no diffs. */
3479 if (mediumType == MediumType_Shareable)
3480 InsertConfigInteger(pCfg, "Shareable", 1);
3481
3482 if (!fUseHostIOCache)
3483 {
3484 InsertConfigInteger(pCfg, "UseNewIo", 1);
3485 /*
3486 * Activate the builtin I/O cache for harddisks only.
3487 * It caches writes only which doesn't make sense for DVD drives
3488 * and just increases the overhead.
3489 */
3490 if ( fBuiltinIoCache
3491 && (enmType == DeviceType_HardDisk))
3492 InsertConfigInteger(pCfg, "BlockCache", 1);
3493 }
3494
3495 if (fSetupMerge)
3496 {
3497 InsertConfigInteger(pCfg, "SetupMerge", 1);
3498 if (uImage == uMergeSource)
3499 InsertConfigInteger(pCfg, "MergeSource", 1);
3500 else if (uImage == uMergeTarget)
3501 InsertConfigInteger(pCfg, "MergeTarget", 1);
3502 }
3503
3504 switch (enmType)
3505 {
3506 case DeviceType_DVD:
3507 InsertConfigString(pCfg, "Type", "DVD");
3508 break;
3509 case DeviceType_Floppy:
3510 InsertConfigString(pCfg, "Type", "Floppy");
3511 break;
3512 case DeviceType_HardDisk:
3513 default:
3514 InsertConfigString(pCfg, "Type", "HardDisk");
3515 }
3516
3517 if (pcszBwGroup)
3518 InsertConfigString(pCfg, "BwGroup", pcszBwGroup);
3519
3520 if (fDiscard)
3521 InsertConfigInteger(pCfg, "Discard", 1);
3522
3523 /* Pass all custom parameters. */
3524 bool fHostIP = true;
3525 SafeArray<BSTR> names;
3526 SafeArray<BSTR> values;
3527 hrc = pMedium->GetProperties(Bstr().raw(),
3528 ComSafeArrayAsOutParam(names),
3529 ComSafeArrayAsOutParam(values)); H();
3530
3531 if (names.size() != 0)
3532 {
3533 PCFGMNODE pVDC;
3534 InsertConfigNode(pCfg, "VDConfig", &pVDC);
3535 for (size_t ii = 0; ii < names.size(); ++ii)
3536 {
3537 if (values[ii] && *values[ii])
3538 {
3539 Utf8Str name = names[ii];
3540 Utf8Str value = values[ii];
3541 InsertConfigString(pVDC, name.c_str(), value);
3542 if ( name.compare("HostIPStack") == 0
3543 && value.compare("0") == 0)
3544 fHostIP = false;
3545 }
3546 }
3547 }
3548
3549 /* Create an inverted list of parents. */
3550 uImage--;
3551 IMedium *pParentMedium = pMedium;
3552 for (PCFGMNODE pParent = pCfg;; uImage--)
3553 {
3554 hrc = pParentMedium->COMGETTER(Parent)(&pMedium); H();
3555 if (!pMedium)
3556 break;
3557
3558 PCFGMNODE pCur;
3559 InsertConfigNode(pParent, "Parent", &pCur);
3560 hrc = pMedium->COMGETTER(Location)(bstr.asOutParam()); H();
3561 InsertConfigString(pCur, "Path", bstr);
3562
3563 hrc = pMedium->COMGETTER(Format)(bstr.asOutParam()); H();
3564 InsertConfigString(pCur, "Format", bstr);
3565
3566 if (fSetupMerge)
3567 {
3568 if (uImage == uMergeSource)
3569 InsertConfigInteger(pCur, "MergeSource", 1);
3570 else if (uImage == uMergeTarget)
3571 InsertConfigInteger(pCur, "MergeTarget", 1);
3572 }
3573
3574 /* Pass all custom parameters. */
3575 SafeArray<BSTR> aNames;
3576 SafeArray<BSTR> aValues;
3577 hrc = pMedium->GetProperties(NULL,
3578 ComSafeArrayAsOutParam(aNames),
3579 ComSafeArrayAsOutParam(aValues)); H();
3580
3581 if (aNames.size() != 0)
3582 {
3583 PCFGMNODE pVDC;
3584 InsertConfigNode(pCur, "VDConfig", &pVDC);
3585 for (size_t ii = 0; ii < aNames.size(); ++ii)
3586 {
3587 if (aValues[ii] && *aValues[ii])
3588 {
3589 Utf8Str name = aNames[ii];
3590 Utf8Str value = aValues[ii];
3591 InsertConfigString(pVDC, name.c_str(), value);
3592 if ( name.compare("HostIPStack") == 0
3593 && value.compare("0") == 0)
3594 fHostIP = false;
3595 }
3596 }
3597 }
3598
3599 /* next */
3600 pParent = pCur;
3601 pParentMedium = pMedium;
3602 }
3603
3604 /* Custom code: put marker to not use host IP stack to driver
3605 * configuration node. Simplifies life of DrvVD a bit. */
3606 if (!fHostIP)
3607 InsertConfigInteger(pCfg, "HostIPStack", 0);
3608 }
3609 }
3610#undef H
3611 }
3612 catch (ConfigError &x)
3613 {
3614 // InsertConfig threw something:
3615 return x.m_vrc;
3616 }
3617
3618 return VINF_SUCCESS;
3619}
3620
3621/**
3622 * Construct the Network configuration tree
3623 *
3624 * @returns VBox status code.
3625 *
3626 * @param pszDevice The PDM device name.
3627 * @param uInstance The PDM device instance.
3628 * @param uLun The PDM LUN number of the drive.
3629 * @param aNetworkAdapter The network adapter whose attachment needs to be changed
3630 * @param pCfg Configuration node for the device
3631 * @param pLunL0 To store the pointer to the LUN#0.
3632 * @param pInst The instance CFGM node
3633 * @param fAttachDetach To determine if the network attachment should
3634 * be attached/detached after/before
3635 * configuration.
3636 * @param fIgnoreConnectFailure
3637 * True if connection failures should be ignored
3638 * (makes only sense for bridged/host-only networks).
3639 *
3640 * @note Locks this object for writing.
3641 * @thread EMT
3642 */
3643int Console::configNetwork(const char *pszDevice,
3644 unsigned uInstance,
3645 unsigned uLun,
3646 INetworkAdapter *aNetworkAdapter,
3647 PCFGMNODE pCfg,
3648 PCFGMNODE pLunL0,
3649 PCFGMNODE pInst,
3650 bool fAttachDetach,
3651 bool fIgnoreConnectFailure)
3652{
3653 AutoCaller autoCaller(this);
3654 AssertComRCReturn(autoCaller.rc(), VERR_ACCESS_DENIED);
3655
3656 // InsertConfig* throws
3657 try
3658 {
3659 int rc = VINF_SUCCESS;
3660 HRESULT hrc;
3661 Bstr bstr;
3662
3663#define H() AssertMsgReturn(!FAILED(hrc), ("hrc=%Rhrc\n", hrc), VERR_GENERAL_FAILURE)
3664
3665 /*
3666 * Locking the object before doing VMR3* calls is quite safe here, since
3667 * we're on EMT. Write lock is necessary because we indirectly modify the
3668 * meAttachmentType member.
3669 */
3670 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
3671
3672 PVM pVM = VMR3GetVM(mpUVM); /* We're on an EMT, so this is safe. */
3673
3674 ComPtr<IMachine> pMachine = machine();
3675
3676 ComPtr<IVirtualBox> virtualBox;
3677 hrc = pMachine->COMGETTER(Parent)(virtualBox.asOutParam()); H();
3678
3679 ComPtr<IHost> host;
3680 hrc = virtualBox->COMGETTER(Host)(host.asOutParam()); H();
3681
3682 BOOL fSniffer;
3683 hrc = aNetworkAdapter->COMGETTER(TraceEnabled)(&fSniffer); H();
3684
3685 NetworkAdapterPromiscModePolicy_T enmPromiscModePolicy;
3686 hrc = aNetworkAdapter->COMGETTER(PromiscModePolicy)(&enmPromiscModePolicy); H();
3687 const char *pszPromiscuousGuestPolicy;
3688 switch (enmPromiscModePolicy)
3689 {
3690 case NetworkAdapterPromiscModePolicy_Deny: pszPromiscuousGuestPolicy = "deny"; break;
3691 case NetworkAdapterPromiscModePolicy_AllowNetwork: pszPromiscuousGuestPolicy = "allow-network"; break;
3692 case NetworkAdapterPromiscModePolicy_AllowAll: pszPromiscuousGuestPolicy = "allow-all"; break;
3693 default: AssertFailedReturn(VERR_INTERNAL_ERROR_4);
3694 }
3695
3696 if (fAttachDetach)
3697 {
3698 rc = PDMR3DeviceDetach(pVM, pszDevice, uInstance, uLun, 0 /*fFlags*/);
3699 if (rc == VINF_PDM_NO_DRIVER_ATTACHED_TO_LUN)
3700 rc = VINF_SUCCESS;
3701 AssertLogRelRCReturn(rc, rc);
3702
3703 /* nuke anything which might have been left behind. */
3704 CFGMR3RemoveNode(CFGMR3GetChildF(pInst, "LUN#%u", uLun));
3705 }
3706
3707#ifdef VBOX_WITH_NETSHAPER
3708 ComObjPtr<IBandwidthGroup> pBwGroup;
3709 Bstr strBwGroup;
3710 hrc = aNetworkAdapter->COMGETTER(BandwidthGroup)(pBwGroup.asOutParam()); H();
3711
3712 if (!pBwGroup.isNull())
3713 {
3714 hrc = pBwGroup->COMGETTER(Name)(strBwGroup.asOutParam()); H();
3715 }
3716#endif /* VBOX_WITH_NETSHAPER */
3717
3718 Utf8Str strNetDriver;
3719
3720
3721 InsertConfigNode(pInst, "LUN#0", &pLunL0);
3722
3723#ifdef VBOX_WITH_NETSHAPER
3724 if (!strBwGroup.isEmpty())
3725 {
3726 InsertConfigString(pLunL0, "Driver", "NetShaper");
3727 InsertConfigNode(pLunL0, "Config", &pCfg);
3728 InsertConfigString(pCfg, "BwGroup", strBwGroup);
3729 InsertConfigNode(pLunL0, "AttachedDriver", &pLunL0);
3730 }
3731#endif /* VBOX_WITH_NETSHAPER */
3732
3733 if (fSniffer)
3734 {
3735 InsertConfigString(pLunL0, "Driver", "NetSniffer");
3736 InsertConfigNode(pLunL0, "Config", &pCfg);
3737 hrc = aNetworkAdapter->COMGETTER(TraceFile)(bstr.asOutParam()); H();
3738 if (!bstr.isEmpty()) /* check convention for indicating default file. */
3739 InsertConfigString(pCfg, "File", bstr);
3740 InsertConfigNode(pLunL0, "AttachedDriver", &pLunL0);
3741 }
3742
3743
3744 Bstr networkName, trunkName, trunkType;
3745 NetworkAttachmentType_T eAttachmentType;
3746 hrc = aNetworkAdapter->COMGETTER(AttachmentType)(&eAttachmentType); H();
3747 switch (eAttachmentType)
3748 {
3749 case NetworkAttachmentType_Null:
3750 break;
3751
3752 case NetworkAttachmentType_NAT:
3753 {
3754 ComPtr<INATEngine> natDriver;
3755 hrc = aNetworkAdapter->COMGETTER(NatDriver)(natDriver.asOutParam()); H();
3756 InsertConfigString(pLunL0, "Driver", "NAT");
3757 InsertConfigNode(pLunL0, "Config", &pCfg);
3758
3759 /* Configure TFTP prefix and boot filename. */
3760 hrc = virtualBox->COMGETTER(HomeFolder)(bstr.asOutParam()); H();
3761 if (!bstr.isEmpty())
3762 InsertConfigString(pCfg, "TFTPPrefix", Utf8StrFmt("%ls%c%s", bstr.raw(), RTPATH_DELIMITER, "TFTP"));
3763 hrc = pMachine->COMGETTER(Name)(bstr.asOutParam()); H();
3764 InsertConfigString(pCfg, "BootFile", Utf8StrFmt("%ls.pxe", bstr.raw()));
3765
3766 hrc = natDriver->COMGETTER(Network)(bstr.asOutParam()); H();
3767 if (!bstr.isEmpty())
3768 InsertConfigString(pCfg, "Network", bstr);
3769 else
3770 {
3771 ULONG uSlot;
3772 hrc = aNetworkAdapter->COMGETTER(Slot)(&uSlot); H();
3773 InsertConfigString(pCfg, "Network", Utf8StrFmt("10.0.%d.0/24", uSlot+2));
3774 }
3775 hrc = natDriver->COMGETTER(HostIP)(bstr.asOutParam()); H();
3776 if (!bstr.isEmpty())
3777 InsertConfigString(pCfg, "BindIP", bstr);
3778 ULONG mtu = 0;
3779 ULONG sockSnd = 0;
3780 ULONG sockRcv = 0;
3781 ULONG tcpSnd = 0;
3782 ULONG tcpRcv = 0;
3783 hrc = natDriver->GetNetworkSettings(&mtu, &sockSnd, &sockRcv, &tcpSnd, &tcpRcv); H();
3784 if (mtu)
3785 InsertConfigInteger(pCfg, "SlirpMTU", mtu);
3786 if (sockRcv)
3787 InsertConfigInteger(pCfg, "SockRcv", sockRcv);
3788 if (sockSnd)
3789 InsertConfigInteger(pCfg, "SockSnd", sockSnd);
3790 if (tcpRcv)
3791 InsertConfigInteger(pCfg, "TcpRcv", tcpRcv);
3792 if (tcpSnd)
3793 InsertConfigInteger(pCfg, "TcpSnd", tcpSnd);
3794 hrc = natDriver->COMGETTER(TftpPrefix)(bstr.asOutParam()); H();
3795 if (!bstr.isEmpty())
3796 {
3797 RemoveConfigValue(pCfg, "TFTPPrefix");
3798 InsertConfigString(pCfg, "TFTPPrefix", bstr);
3799 }
3800 hrc = natDriver->COMGETTER(TftpBootFile)(bstr.asOutParam()); H();
3801 if (!bstr.isEmpty())
3802 {
3803 RemoveConfigValue(pCfg, "BootFile");
3804 InsertConfigString(pCfg, "BootFile", bstr);
3805 }
3806 hrc = natDriver->COMGETTER(TftpNextServer)(bstr.asOutParam()); H();
3807 if (!bstr.isEmpty())
3808 InsertConfigString(pCfg, "NextServer", bstr);
3809 BOOL fDnsFlag;
3810 hrc = natDriver->COMGETTER(DnsPassDomain)(&fDnsFlag); H();
3811 InsertConfigInteger(pCfg, "PassDomain", fDnsFlag);
3812 hrc = natDriver->COMGETTER(DnsProxy)(&fDnsFlag); H();
3813 InsertConfigInteger(pCfg, "DNSProxy", fDnsFlag);
3814 hrc = natDriver->COMGETTER(DnsUseHostResolver)(&fDnsFlag); H();
3815 InsertConfigInteger(pCfg, "UseHostResolver", fDnsFlag);
3816
3817 ULONG aliasMode;
3818 hrc = natDriver->COMGETTER(AliasMode)(&aliasMode); H();
3819 InsertConfigInteger(pCfg, "AliasMode", aliasMode);
3820
3821 /* port-forwarding */
3822 SafeArray<BSTR> pfs;
3823 hrc = natDriver->COMGETTER(Redirects)(ComSafeArrayAsOutParam(pfs)); H();
3824 PCFGMNODE pPF = NULL; /* /Devices/Dev/.../Config/PF#0/ */
3825 for (unsigned int i = 0; i < pfs.size(); ++i)
3826 {
3827 uint16_t port = 0;
3828 BSTR r = pfs[i];
3829 Utf8Str utf = Utf8Str(r);
3830 Utf8Str strName;
3831 Utf8Str strProto;
3832 Utf8Str strHostPort;
3833 Utf8Str strHostIP;
3834 Utf8Str strGuestPort;
3835 Utf8Str strGuestIP;
3836 size_t pos, ppos;
3837 pos = ppos = 0;
3838#define ITERATE_TO_NEXT_TERM(res, str, pos, ppos) \
3839 do { \
3840 pos = str.find(",", ppos); \
3841 if (pos == Utf8Str::npos) \
3842 { \
3843 Log(( #res " extracting from %s is failed\n", str.c_str())); \
3844 continue; \
3845 } \
3846 res = str.substr(ppos, pos - ppos); \
3847 Log2((#res " %s pos:%d, ppos:%d\n", res.c_str(), pos, ppos)); \
3848 ppos = pos + 1; \
3849 } while (0)
3850 ITERATE_TO_NEXT_TERM(strName, utf, pos, ppos);
3851 ITERATE_TO_NEXT_TERM(strProto, utf, pos, ppos);
3852 ITERATE_TO_NEXT_TERM(strHostIP, utf, pos, ppos);
3853 ITERATE_TO_NEXT_TERM(strHostPort, utf, pos, ppos);
3854 ITERATE_TO_NEXT_TERM(strGuestIP, utf, pos, ppos);
3855 strGuestPort = utf.substr(ppos, utf.length() - ppos);
3856#undef ITERATE_TO_NEXT_TERM
3857
3858 uint32_t proto = strProto.toUInt32();
3859 bool fValid = true;
3860 switch (proto)
3861 {
3862 case NATProtocol_UDP:
3863 strProto = "UDP";
3864 break;
3865 case NATProtocol_TCP:
3866 strProto = "TCP";
3867 break;
3868 default:
3869 fValid = false;
3870 }
3871 /* continue with next rule if no valid proto was passed */
3872 if (!fValid)
3873 continue;
3874
3875 InsertConfigNode(pCfg, strName.c_str(), &pPF);
3876 InsertConfigString(pPF, "Protocol", strProto);
3877
3878 if (!strHostIP.isEmpty())
3879 InsertConfigString(pPF, "BindIP", strHostIP);
3880
3881 if (!strGuestIP.isEmpty())
3882 InsertConfigString(pPF, "GuestIP", strGuestIP);
3883
3884 port = RTStrToUInt16(strHostPort.c_str());
3885 if (port)
3886 InsertConfigInteger(pPF, "HostPort", port);
3887
3888 port = RTStrToUInt16(strGuestPort.c_str());
3889 if (port)
3890 InsertConfigInteger(pPF, "GuestPort", port);
3891 }
3892 break;
3893 }
3894
3895 case NetworkAttachmentType_Bridged:
3896 {
3897#if (defined(RT_OS_LINUX) || defined(RT_OS_FREEBSD)) && !defined(VBOX_WITH_NETFLT)
3898 hrc = attachToTapInterface(aNetworkAdapter);
3899 if (FAILED(hrc))
3900 {
3901 switch (hrc)
3902 {
3903 case VERR_ACCESS_DENIED:
3904 return VMSetError(pVM, VERR_HOSTIF_INIT_FAILED, RT_SRC_POS, N_(
3905 "Failed to open '/dev/net/tun' for read/write access. Please check the "
3906 "permissions of that node. Either run 'chmod 0666 /dev/net/tun' or "
3907 "change the group of that node and make yourself a member of that group. Make "
3908 "sure that these changes are permanent, especially if you are "
3909 "using udev"));
3910 default:
3911 AssertMsgFailed(("Could not attach to host interface! Bad!\n"));
3912 return VMSetError(pVM, VERR_HOSTIF_INIT_FAILED, RT_SRC_POS, N_(
3913 "Failed to initialize Host Interface Networking"));
3914 }
3915 }
3916
3917 Assert((int)maTapFD[uInstance] >= 0);
3918 if ((int)maTapFD[uInstance] >= 0)
3919 {
3920 InsertConfigString(pLunL0, "Driver", "HostInterface");
3921 InsertConfigNode(pLunL0, "Config", &pCfg);
3922 InsertConfigInteger(pCfg, "FileHandle", maTapFD[uInstance]);
3923 }
3924
3925#elif defined(VBOX_WITH_NETFLT)
3926 /*
3927 * This is the new VBoxNetFlt+IntNet stuff.
3928 */
3929 Bstr BridgedIfName;
3930 hrc = aNetworkAdapter->COMGETTER(BridgedInterface)(BridgedIfName.asOutParam());
3931 if (FAILED(hrc))
3932 {
3933 LogRel(("NetworkAttachmentType_Bridged: COMGETTER(BridgedInterface) failed, hrc (0x%x)", hrc));
3934 H();
3935 }
3936
3937 Utf8Str BridgedIfNameUtf8(BridgedIfName);
3938 const char *pszBridgedIfName = BridgedIfNameUtf8.c_str();
3939
3940# if defined(RT_OS_DARWIN)
3941 /* The name is on the form 'ifX: long name', chop it off at the colon. */
3942 char szTrunk[8];
3943 RTStrCopy(szTrunk, sizeof(szTrunk), pszBridgedIfName);
3944 char *pszColon = (char *)memchr(szTrunk, ':', sizeof(szTrunk));
3945// Quick fix for #5633
3946// if (!pszColon)
3947// {
3948// /*
3949// * Dynamic changing of attachment causes an attempt to configure
3950// * network with invalid host adapter (as it is must be changed before
3951// * the attachment), calling Detach here will cause a deadlock.
3952// * See #4750.
3953// * hrc = aNetworkAdapter->Detach(); H();
3954// */
3955// return VMSetError(pVM, VERR_INTERNAL_ERROR, RT_SRC_POS,
3956// N_("Malformed host interface networking name '%ls'"),
3957// BridgedIfName.raw());
3958// }
3959 if (pszColon)
3960 *pszColon = '\0';
3961 const char *pszTrunk = szTrunk;
3962
3963# elif defined(RT_OS_SOLARIS)
3964 /* The name is on the form format 'ifX[:1] - long name, chop it off at space. */
3965 char szTrunk[256];
3966 strlcpy(szTrunk, pszBridgedIfName, sizeof(szTrunk));
3967 char *pszSpace = (char *)memchr(szTrunk, ' ', sizeof(szTrunk));
3968
3969 /*
3970 * Currently don't bother about malformed names here for the sake of people using
3971 * VBoxManage and setting only the NIC name from there. If there is a space we
3972 * chop it off and proceed, otherwise just use whatever we've got.
3973 */
3974 if (pszSpace)
3975 *pszSpace = '\0';
3976
3977 /* Chop it off at the colon (zone naming eg: e1000g:1 we need only the e1000g) */
3978 char *pszColon = (char *)memchr(szTrunk, ':', sizeof(szTrunk));
3979 if (pszColon)
3980 *pszColon = '\0';
3981
3982 const char *pszTrunk = szTrunk;
3983
3984# elif defined(RT_OS_WINDOWS)
3985 ComPtr<IHostNetworkInterface> hostInterface;
3986 hrc = host->FindHostNetworkInterfaceByName(BridgedIfName.raw(),
3987 hostInterface.asOutParam());
3988 if (!SUCCEEDED(hrc))
3989 {
3990 AssertLogRelMsgFailed(("NetworkAttachmentType_Bridged: FindByName failed, rc=%Rhrc (0x%x)", hrc, hrc));
3991 return VMSetError(pVM, VERR_INTERNAL_ERROR, RT_SRC_POS,
3992 N_("Nonexistent host networking interface, name '%ls'"),
3993 BridgedIfName.raw());
3994 }
3995
3996 HostNetworkInterfaceType_T eIfType;
3997 hrc = hostInterface->COMGETTER(InterfaceType)(&eIfType);
3998 if (FAILED(hrc))
3999 {
4000 LogRel(("NetworkAttachmentType_Bridged: COMGETTER(InterfaceType) failed, hrc (0x%x)", hrc));
4001 H();
4002 }
4003
4004 if (eIfType != HostNetworkInterfaceType_Bridged)
4005 {
4006 return VMSetError(pVM, VERR_INTERNAL_ERROR, RT_SRC_POS,
4007 N_("Interface ('%ls') is not a Bridged Adapter interface"),
4008 BridgedIfName.raw());
4009 }
4010
4011 hrc = hostInterface->COMGETTER(Id)(bstr.asOutParam());
4012 if (FAILED(hrc))
4013 {
4014 LogRel(("NetworkAttachmentType_Bridged: COMGETTER(Id) failed, hrc (0x%x)", hrc));
4015 H();
4016 }
4017 Guid hostIFGuid(bstr);
4018
4019 INetCfg *pNc;
4020 ComPtr<INetCfgComponent> pAdaptorComponent;
4021 LPWSTR pszApp;
4022
4023 hrc = VBoxNetCfgWinQueryINetCfg(&pNc, FALSE, L"VirtualBox", 10, &pszApp);
4024 Assert(hrc == S_OK);
4025 if (hrc != S_OK)
4026 {
4027 LogRel(("NetworkAttachmentType_Bridged: Failed to get NetCfg, hrc=%Rhrc (0x%x)\n", hrc, hrc));
4028 H();
4029 }
4030
4031 /* get the adapter's INetCfgComponent*/
4032 hrc = VBoxNetCfgWinGetComponentByGuid(pNc, &GUID_DEVCLASS_NET, (GUID*)hostIFGuid.raw(), pAdaptorComponent.asOutParam());
4033 if (hrc != S_OK)
4034 {
4035 VBoxNetCfgWinReleaseINetCfg(pNc, FALSE /*fHasWriteLock*/);
4036 LogRel(("NetworkAttachmentType_Bridged: VBoxNetCfgWinGetComponentByGuid failed, hrc (0x%x)", hrc));
4037 H();
4038 }
4039#define VBOX_WIN_BINDNAME_PREFIX "\\DEVICE\\"
4040 char szTrunkName[INTNET_MAX_TRUNK_NAME];
4041 char *pszTrunkName = szTrunkName;
4042 wchar_t * pswzBindName;
4043 hrc = pAdaptorComponent->GetBindName(&pswzBindName);
4044 Assert(hrc == S_OK);
4045 if (hrc == S_OK)
4046 {
4047 int cwBindName = (int)wcslen(pswzBindName) + 1;
4048 int cbFullBindNamePrefix = sizeof(VBOX_WIN_BINDNAME_PREFIX);
4049 if (sizeof(szTrunkName) > cbFullBindNamePrefix + cwBindName)
4050 {
4051 strcpy(szTrunkName, VBOX_WIN_BINDNAME_PREFIX);
4052 pszTrunkName += cbFullBindNamePrefix-1;
4053 if (!WideCharToMultiByte(CP_ACP, 0, pswzBindName, cwBindName, pszTrunkName,
4054 sizeof(szTrunkName) - cbFullBindNamePrefix + 1, NULL, NULL))
4055 {
4056 DWORD err = GetLastError();
4057 hrc = HRESULT_FROM_WIN32(err);
4058 AssertMsgFailed(("%hrc=%Rhrc %#x\n", hrc, hrc));
4059 AssertLogRelMsgFailed(("NetworkAttachmentType_Bridged: WideCharToMultiByte failed, hr=%Rhrc (0x%x) err=%u\n", hrc, hrc, err));
4060 }
4061 }
4062 else
4063 {
4064 AssertLogRelMsgFailed(("NetworkAttachmentType_Bridged: insufficient szTrunkName buffer space\n"));
4065 /** @todo set appropriate error code */
4066 hrc = E_FAIL;
4067 }
4068
4069 if (hrc != S_OK)
4070 {
4071 AssertFailed();
4072 CoTaskMemFree(pswzBindName);
4073 VBoxNetCfgWinReleaseINetCfg(pNc, FALSE /*fHasWriteLock*/);
4074 H();
4075 }
4076
4077 /* we're not freeing the bind name since we'll use it later for detecting wireless*/
4078 }
4079 else
4080 {
4081 VBoxNetCfgWinReleaseINetCfg(pNc, FALSE /*fHasWriteLock*/);
4082 AssertLogRelMsgFailed(("NetworkAttachmentType_Bridged: VBoxNetCfgWinGetComponentByGuid failed, hrc (0x%x)", hrc));
4083 H();
4084 }
4085
4086 const char *pszTrunk = szTrunkName;
4087 /* we're not releasing the INetCfg stuff here since we use it later to figure out whether it is wireless */
4088
4089# elif defined(RT_OS_LINUX) || defined(RT_OS_FREEBSD)
4090# if defined(RT_OS_FREEBSD)
4091 /*
4092 * If we bridge to a tap interface open it the `old' direct way.
4093 * This works and performs better than bridging a physical
4094 * interface via the current FreeBSD vboxnetflt implementation.
4095 */
4096 if (!strncmp(pszBridgedIfName, "tap", sizeof "tap" - 1)) {
4097 hrc = attachToTapInterface(aNetworkAdapter);
4098 if (FAILED(hrc))
4099 {
4100 switch (hrc)
4101 {
4102 case VERR_ACCESS_DENIED:
4103 return VMSetError(pVM, VERR_HOSTIF_INIT_FAILED, RT_SRC_POS, N_(
4104 "Failed to open '/dev/%s' for read/write access. Please check the "
4105 "permissions of that node, and that the net.link.tap.user_open "
4106 "sysctl is set. Either run 'chmod 0666 /dev/%s' or "
4107 "change the group of that node to vboxusers and make yourself "
4108 "a member of that group. Make sure that these changes are permanent."), pszBridgedIfName, pszBridgedIfName);
4109 default:
4110 AssertMsgFailed(("Could not attach to tap interface! Bad!\n"));
4111 return VMSetError(pVM, VERR_HOSTIF_INIT_FAILED, RT_SRC_POS, N_(
4112 "Failed to initialize Host Interface Networking"));
4113 }
4114 }
4115
4116 Assert((int)maTapFD[uInstance] >= 0);
4117 if ((int)maTapFD[uInstance] >= 0)
4118 {
4119 InsertConfigString(pLunL0, "Driver", "HostInterface");
4120 InsertConfigNode(pLunL0, "Config", &pCfg);
4121 InsertConfigInteger(pCfg, "FileHandle", maTapFD[uInstance]);
4122 }
4123 break;
4124 }
4125# endif
4126 /** @todo Check for malformed names. */
4127 const char *pszTrunk = pszBridgedIfName;
4128
4129 /* Issue a warning if the interface is down */
4130 {
4131 int iSock = socket(AF_INET, SOCK_DGRAM, 0);
4132 if (iSock >= 0)
4133 {
4134 struct ifreq Req;
4135 RT_ZERO(Req);
4136 strncpy(Req.ifr_name, pszBridgedIfName, sizeof(Req.ifr_name) - 1);
4137 if (ioctl(iSock, SIOCGIFFLAGS, &Req) >= 0)
4138 if ((Req.ifr_flags & IFF_UP) == 0)
4139 setVMRuntimeErrorCallbackF(pVM, this, 0, "BridgedInterfaceDown",
4140 "Bridged interface %s is down. Guest will not be able to use this interface",
4141 pszBridgedIfName);
4142
4143 close(iSock);
4144 }
4145 }
4146
4147# else
4148# error "PORTME (VBOX_WITH_NETFLT)"
4149# endif
4150
4151 InsertConfigString(pLunL0, "Driver", "IntNet");
4152 InsertConfigNode(pLunL0, "Config", &pCfg);
4153 InsertConfigString(pCfg, "Trunk", pszTrunk);
4154 InsertConfigInteger(pCfg, "TrunkType", kIntNetTrunkType_NetFlt);
4155 InsertConfigInteger(pCfg, "IgnoreConnectFailure", (uint64_t)fIgnoreConnectFailure);
4156 InsertConfigString(pCfg, "IfPolicyPromisc", pszPromiscuousGuestPolicy);
4157 char szNetwork[INTNET_MAX_NETWORK_NAME];
4158
4159#if defined(RT_OS_SOLARIS) || defined(RT_OS_DARWIN)
4160 /*
4161 * 'pszTrunk' contains just the interface name required in ring-0, while 'pszBridgedIfName' contains
4162 * interface name + optional description. We must not pass any description to the VM as it can differ
4163 * for the same interface name, eg: "nge0 - ethernet" (GUI) vs "nge0" (VBoxManage).
4164 */
4165 RTStrPrintf(szNetwork, sizeof(szNetwork), "HostInterfaceNetworking-%s", pszTrunk);
4166#else
4167 RTStrPrintf(szNetwork, sizeof(szNetwork), "HostInterfaceNetworking-%s", pszBridgedIfName);
4168#endif
4169 InsertConfigString(pCfg, "Network", szNetwork);
4170 networkName = Bstr(szNetwork);
4171 trunkName = Bstr(pszTrunk);
4172 trunkType = Bstr(TRUNKTYPE_NETFLT);
4173
4174# if defined(RT_OS_DARWIN)
4175 /** @todo Come up with a better deal here. Problem is that IHostNetworkInterface is completely useless here. */
4176 if ( strstr(pszBridgedIfName, "Wireless")
4177 || strstr(pszBridgedIfName, "AirPort" ))
4178 InsertConfigInteger(pCfg, "SharedMacOnWire", true);
4179# elif defined(RT_OS_LINUX)
4180 int iSock = socket(AF_INET, SOCK_DGRAM, 0);
4181 if (iSock >= 0)
4182 {
4183 struct iwreq WRq;
4184
4185 memset(&WRq, 0, sizeof(WRq));
4186 strncpy(WRq.ifr_name, pszBridgedIfName, IFNAMSIZ);
4187 bool fSharedMacOnWire = ioctl(iSock, SIOCGIWNAME, &WRq) >= 0;
4188 close(iSock);
4189 if (fSharedMacOnWire)
4190 {
4191 InsertConfigInteger(pCfg, "SharedMacOnWire", true);
4192 Log(("Set SharedMacOnWire\n"));
4193 }
4194 else
4195 Log(("Failed to get wireless name\n"));
4196 }
4197 else
4198 Log(("Failed to open wireless socket\n"));
4199# elif defined(RT_OS_FREEBSD)
4200 int iSock = socket(AF_INET, SOCK_DGRAM, 0);
4201 if (iSock >= 0)
4202 {
4203 struct ieee80211req WReq;
4204 uint8_t abData[32];
4205
4206 memset(&WReq, 0, sizeof(WReq));
4207 strncpy(WReq.i_name, pszBridgedIfName, sizeof(WReq.i_name));
4208 WReq.i_type = IEEE80211_IOC_SSID;
4209 WReq.i_val = -1;
4210 WReq.i_data = abData;
4211 WReq.i_len = sizeof(abData);
4212
4213 bool fSharedMacOnWire = ioctl(iSock, SIOCG80211, &WReq) >= 0;
4214 close(iSock);
4215 if (fSharedMacOnWire)
4216 {
4217 InsertConfigInteger(pCfg, "SharedMacOnWire", true);
4218 Log(("Set SharedMacOnWire\n"));
4219 }
4220 else
4221 Log(("Failed to get wireless name\n"));
4222 }
4223 else
4224 Log(("Failed to open wireless socket\n"));
4225# elif defined(RT_OS_WINDOWS)
4226# define DEVNAME_PREFIX L"\\\\.\\"
4227 /* we are getting the medium type via IOCTL_NDIS_QUERY_GLOBAL_STATS Io Control
4228 * there is a pretty long way till there though since we need to obtain the symbolic link name
4229 * for the adapter device we are going to query given the device Guid */
4230
4231
4232 /* prepend the "\\\\.\\" to the bind name to obtain the link name */
4233
4234 wchar_t FileName[MAX_PATH];
4235 wcscpy(FileName, DEVNAME_PREFIX);
4236 wcscpy((wchar_t*)(((char*)FileName) + sizeof(DEVNAME_PREFIX) - sizeof(FileName[0])), pswzBindName);
4237
4238 /* open the device */
4239 HANDLE hDevice = CreateFile(FileName,
4240 GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE,
4241 NULL,
4242 OPEN_EXISTING,
4243 FILE_ATTRIBUTE_NORMAL,
4244 NULL);
4245
4246 if (hDevice != INVALID_HANDLE_VALUE)
4247 {
4248 bool fSharedMacOnWire = false;
4249
4250 /* now issue the OID_GEN_PHYSICAL_MEDIUM query */
4251 DWORD Oid = OID_GEN_PHYSICAL_MEDIUM;
4252 NDIS_PHYSICAL_MEDIUM PhMedium;
4253 DWORD cbResult;
4254 if (DeviceIoControl(hDevice,
4255 IOCTL_NDIS_QUERY_GLOBAL_STATS,
4256 &Oid,
4257 sizeof(Oid),
4258 &PhMedium,
4259 sizeof(PhMedium),
4260 &cbResult,
4261 NULL))
4262 {
4263 /* that was simple, now examine PhMedium */
4264 if ( PhMedium == NdisPhysicalMediumWirelessWan
4265 || PhMedium == NdisPhysicalMediumWirelessLan
4266 || PhMedium == NdisPhysicalMediumNative802_11
4267 || PhMedium == NdisPhysicalMediumBluetooth)
4268 fSharedMacOnWire = true;
4269 }
4270 else
4271 {
4272 int winEr = GetLastError();
4273 LogRel(("Console::configNetwork: DeviceIoControl failed, err (0x%x), ignoring\n", winEr));
4274 Assert(winEr == ERROR_INVALID_PARAMETER || winEr == ERROR_NOT_SUPPORTED || winEr == ERROR_BAD_COMMAND);
4275 }
4276 CloseHandle(hDevice);
4277
4278 if (fSharedMacOnWire)
4279 {
4280 Log(("this is a wireless adapter"));
4281 InsertConfigInteger(pCfg, "SharedMacOnWire", true);
4282 Log(("Set SharedMacOnWire\n"));
4283 }
4284 else
4285 Log(("this is NOT a wireless adapter"));
4286 }
4287 else
4288 {
4289 int winEr = GetLastError();
4290 AssertLogRelMsgFailed(("Console::configNetwork: CreateFile failed, err (0x%x), ignoring\n", winEr));
4291 }
4292
4293 CoTaskMemFree(pswzBindName);
4294
4295 pAdaptorComponent.setNull();
4296 /* release the pNc finally */
4297 VBoxNetCfgWinReleaseINetCfg(pNc, FALSE /*fHasWriteLock*/);
4298# else
4299 /** @todo PORTME: wireless detection */
4300# endif
4301
4302# if defined(RT_OS_SOLARIS)
4303# if 0 /* bird: this is a bit questionable and might cause more trouble than its worth. */
4304 /* Zone access restriction, don't allow snooping the global zone. */
4305 zoneid_t ZoneId = getzoneid();
4306 if (ZoneId != GLOBAL_ZONEID)
4307 {
4308 InsertConfigInteger(pCfg, "IgnoreAllPromisc", true);
4309 }
4310# endif
4311# endif
4312
4313#elif defined(RT_OS_WINDOWS) /* not defined NetFlt */
4314 /* NOTHING TO DO HERE */
4315#elif defined(RT_OS_LINUX)
4316/// @todo aleksey: is there anything to be done here?
4317#elif defined(RT_OS_FREEBSD)
4318/** @todo FreeBSD: Check out this later (HIF networking). */
4319#else
4320# error "Port me"
4321#endif
4322 break;
4323 }
4324
4325 case NetworkAttachmentType_Internal:
4326 {
4327 hrc = aNetworkAdapter->COMGETTER(InternalNetwork)(bstr.asOutParam()); H();
4328 if (!bstr.isEmpty())
4329 {
4330 InsertConfigString(pLunL0, "Driver", "IntNet");
4331 InsertConfigNode(pLunL0, "Config", &pCfg);
4332 InsertConfigString(pCfg, "Network", bstr);
4333 InsertConfigInteger(pCfg, "TrunkType", kIntNetTrunkType_WhateverNone);
4334 InsertConfigString(pCfg, "IfPolicyPromisc", pszPromiscuousGuestPolicy);
4335 networkName = bstr;
4336 trunkType = Bstr(TRUNKTYPE_WHATEVER);
4337 }
4338 break;
4339 }
4340
4341 case NetworkAttachmentType_HostOnly:
4342 {
4343 InsertConfigString(pLunL0, "Driver", "IntNet");
4344 InsertConfigNode(pLunL0, "Config", &pCfg);
4345
4346 Bstr HostOnlyName;
4347 hrc = aNetworkAdapter->COMGETTER(HostOnlyInterface)(HostOnlyName.asOutParam());
4348 if (FAILED(hrc))
4349 {
4350 LogRel(("NetworkAttachmentType_HostOnly: COMGETTER(HostOnlyInterface) failed, hrc (0x%x)\n", hrc));
4351 H();
4352 }
4353
4354 Utf8Str HostOnlyNameUtf8(HostOnlyName);
4355 const char *pszHostOnlyName = HostOnlyNameUtf8.c_str();
4356 ComPtr<IHostNetworkInterface> hostInterface;
4357 rc = host->FindHostNetworkInterfaceByName(HostOnlyName.raw(),
4358 hostInterface.asOutParam());
4359 if (!SUCCEEDED(rc))
4360 {
4361 LogRel(("NetworkAttachmentType_HostOnly: FindByName failed, rc (0x%x)\n", rc));
4362 return VMSetError(pVM, VERR_INTERNAL_ERROR, RT_SRC_POS,
4363 N_("Nonexistent host networking interface, name '%ls'"),
4364 HostOnlyName.raw());
4365 }
4366
4367 char szNetwork[INTNET_MAX_NETWORK_NAME];
4368 RTStrPrintf(szNetwork, sizeof(szNetwork), "HostInterfaceNetworking-%s", pszHostOnlyName);
4369
4370#if defined(RT_OS_WINDOWS)
4371# ifndef VBOX_WITH_NETFLT
4372 hrc = E_NOTIMPL;
4373 LogRel(("NetworkAttachmentType_HostOnly: Not Implemented\n"));
4374 H();
4375# else /* defined VBOX_WITH_NETFLT*/
4376 /** @todo r=bird: Put this in a function. */
4377
4378 HostNetworkInterfaceType_T eIfType;
4379 hrc = hostInterface->COMGETTER(InterfaceType)(&eIfType);
4380 if (FAILED(hrc))
4381 {
4382 LogRel(("NetworkAttachmentType_HostOnly: COMGETTER(InterfaceType) failed, hrc (0x%x)\n", hrc));
4383 H();
4384 }
4385
4386 if (eIfType != HostNetworkInterfaceType_HostOnly)
4387 return VMSetError(pVM, VERR_INTERNAL_ERROR, RT_SRC_POS,
4388 N_("Interface ('%ls') is not a Host-Only Adapter interface"),
4389 HostOnlyName.raw());
4390
4391 hrc = hostInterface->COMGETTER(Id)(bstr.asOutParam());
4392 if (FAILED(hrc))
4393 {
4394 LogRel(("NetworkAttachmentType_HostOnly: COMGETTER(Id) failed, hrc (0x%x)\n", hrc));
4395 H();
4396 }
4397 Guid hostIFGuid(bstr);
4398
4399 INetCfg *pNc;
4400 ComPtr<INetCfgComponent> pAdaptorComponent;
4401 LPWSTR pszApp;
4402 hrc = VBoxNetCfgWinQueryINetCfg(&pNc, FALSE, L"VirtualBox", 10, &pszApp);
4403 Assert(hrc == S_OK);
4404 if (hrc != S_OK)
4405 {
4406 LogRel(("NetworkAttachmentType_HostOnly: Failed to get NetCfg, hrc=%Rhrc (0x%x)\n", hrc, hrc));
4407 H();
4408 }
4409
4410 /* get the adapter's INetCfgComponent*/
4411 hrc = VBoxNetCfgWinGetComponentByGuid(pNc, &GUID_DEVCLASS_NET, (GUID*)hostIFGuid.raw(), pAdaptorComponent.asOutParam());
4412 if (hrc != S_OK)
4413 {
4414 VBoxNetCfgWinReleaseINetCfg(pNc, FALSE /*fHasWriteLock*/);
4415 LogRel(("NetworkAttachmentType_HostOnly: VBoxNetCfgWinGetComponentByGuid failed, hrc=%Rhrc (0x%x)\n", hrc, hrc));
4416 H();
4417 }
4418# define VBOX_WIN_BINDNAME_PREFIX "\\DEVICE\\"
4419 char szTrunkName[INTNET_MAX_TRUNK_NAME];
4420 char *pszTrunkName = szTrunkName;
4421 wchar_t * pswzBindName;
4422 hrc = pAdaptorComponent->GetBindName(&pswzBindName);
4423 Assert(hrc == S_OK);
4424 if (hrc == S_OK)
4425 {
4426 int cwBindName = (int)wcslen(pswzBindName) + 1;
4427 int cbFullBindNamePrefix = sizeof(VBOX_WIN_BINDNAME_PREFIX);
4428 if (sizeof(szTrunkName) > cbFullBindNamePrefix + cwBindName)
4429 {
4430 strcpy(szTrunkName, VBOX_WIN_BINDNAME_PREFIX);
4431 pszTrunkName += cbFullBindNamePrefix-1;
4432 if (!WideCharToMultiByte(CP_ACP, 0, pswzBindName, cwBindName, pszTrunkName,
4433 sizeof(szTrunkName) - cbFullBindNamePrefix + 1, NULL, NULL))
4434 {
4435 DWORD err = GetLastError();
4436 hrc = HRESULT_FROM_WIN32(err);
4437 AssertLogRelMsgFailed(("NetworkAttachmentType_HostOnly: WideCharToMultiByte failed, hr=%Rhrc (0x%x) err=%u\n", hrc, hrc, err));
4438 }
4439 }
4440 else
4441 {
4442 AssertLogRelMsgFailed(("NetworkAttachmentType_HostOnly: insufficient szTrunkName buffer space\n"));
4443 /** @todo set appropriate error code */
4444 hrc = E_FAIL;
4445 }
4446
4447 if (hrc != S_OK)
4448 {
4449 AssertFailed();
4450 CoTaskMemFree(pswzBindName);
4451 VBoxNetCfgWinReleaseINetCfg(pNc, FALSE /*fHasWriteLock*/);
4452 H();
4453 }
4454 }
4455 else
4456 {
4457 VBoxNetCfgWinReleaseINetCfg(pNc, FALSE /*fHasWriteLock*/);
4458 AssertLogRelMsgFailed(("NetworkAttachmentType_HostOnly: VBoxNetCfgWinGetComponentByGuid failed, hrc=%Rhrc (0x%x)\n", hrc, hrc));
4459 H();
4460 }
4461
4462
4463 CoTaskMemFree(pswzBindName);
4464
4465 pAdaptorComponent.setNull();
4466 /* release the pNc finally */
4467 VBoxNetCfgWinReleaseINetCfg(pNc, FALSE /*fHasWriteLock*/);
4468
4469 const char *pszTrunk = szTrunkName;
4470
4471 InsertConfigInteger(pCfg, "TrunkType", kIntNetTrunkType_NetAdp);
4472 InsertConfigString(pCfg, "Trunk", pszTrunk);
4473 InsertConfigString(pCfg, "Network", szNetwork);
4474 InsertConfigInteger(pCfg, "IgnoreConnectFailure", (uint64_t)fIgnoreConnectFailure); /** @todo why is this windows only?? */
4475 networkName = Bstr(szNetwork);
4476 trunkName = Bstr(pszTrunk);
4477 trunkType = TRUNKTYPE_NETADP;
4478# endif /* defined VBOX_WITH_NETFLT*/
4479#elif defined(RT_OS_DARWIN)
4480 InsertConfigString(pCfg, "Trunk", pszHostOnlyName);
4481 InsertConfigString(pCfg, "Network", szNetwork);
4482 InsertConfigInteger(pCfg, "TrunkType", kIntNetTrunkType_NetAdp);
4483 networkName = Bstr(szNetwork);
4484 trunkName = Bstr(pszHostOnlyName);
4485 trunkType = TRUNKTYPE_NETADP;
4486#else
4487 InsertConfigString(pCfg, "Trunk", pszHostOnlyName);
4488 InsertConfigString(pCfg, "Network", szNetwork);
4489 InsertConfigInteger(pCfg, "TrunkType", kIntNetTrunkType_NetFlt);
4490 networkName = Bstr(szNetwork);
4491 trunkName = Bstr(pszHostOnlyName);
4492 trunkType = TRUNKTYPE_NETFLT;
4493#endif
4494 InsertConfigString(pCfg, "IfPolicyPromisc", pszPromiscuousGuestPolicy);
4495
4496#if !defined(RT_OS_WINDOWS) && defined(VBOX_WITH_NETFLT)
4497
4498 Bstr tmpAddr, tmpMask;
4499
4500 hrc = virtualBox->GetExtraData(BstrFmt("HostOnly/%s/IPAddress",
4501 pszHostOnlyName).raw(),
4502 tmpAddr.asOutParam());
4503 if (SUCCEEDED(hrc) && !tmpAddr.isEmpty())
4504 {
4505 hrc = virtualBox->GetExtraData(BstrFmt("HostOnly/%s/IPNetMask",
4506 pszHostOnlyName).raw(),
4507 tmpMask.asOutParam());
4508 if (SUCCEEDED(hrc) && !tmpMask.isEmpty())
4509 hrc = hostInterface->EnableStaticIpConfig(tmpAddr.raw(),
4510 tmpMask.raw());
4511 else
4512 hrc = hostInterface->EnableStaticIpConfig(tmpAddr.raw(),
4513 Bstr(VBOXNET_IPV4MASK_DEFAULT).raw());
4514 }
4515 else
4516 {
4517 /* Grab the IP number from the 'vboxnetX' instance number (see netif.h) */
4518 hrc = hostInterface->EnableStaticIpConfig(getDefaultIPv4Address(Bstr(pszHostOnlyName)).raw(),
4519 Bstr(VBOXNET_IPV4MASK_DEFAULT).raw());
4520 }
4521
4522 ComAssertComRC(hrc); /** @todo r=bird: Why this isn't fatal? (H()) */
4523
4524 hrc = virtualBox->GetExtraData(BstrFmt("HostOnly/%s/IPV6Address",
4525 pszHostOnlyName).raw(),
4526 tmpAddr.asOutParam());
4527 if (SUCCEEDED(hrc))
4528 hrc = virtualBox->GetExtraData(BstrFmt("HostOnly/%s/IPV6NetMask", pszHostOnlyName).raw(),
4529 tmpMask.asOutParam());
4530 if (SUCCEEDED(hrc) && !tmpAddr.isEmpty() && !tmpMask.isEmpty())
4531 {
4532 hrc = hostInterface->EnableStaticIpConfigV6(tmpAddr.raw(),
4533 Utf8Str(tmpMask).toUInt32());
4534 ComAssertComRC(hrc); /** @todo r=bird: Why this isn't fatal? (H()) */
4535 }
4536#endif
4537 break;
4538 }
4539
4540 case NetworkAttachmentType_Generic:
4541 {
4542 hrc = aNetworkAdapter->COMGETTER(GenericDriver)(bstr.asOutParam()); H();
4543 SafeArray<BSTR> names;
4544 SafeArray<BSTR> values;
4545 hrc = aNetworkAdapter->GetProperties(Bstr().raw(),
4546 ComSafeArrayAsOutParam(names),
4547 ComSafeArrayAsOutParam(values)); H();
4548
4549 InsertConfigString(pLunL0, "Driver", bstr);
4550 InsertConfigNode(pLunL0, "Config", &pCfg);
4551 for (size_t ii = 0; ii < names.size(); ++ii)
4552 {
4553 if (values[ii] && *values[ii])
4554 {
4555 Utf8Str name = names[ii];
4556 Utf8Str value = values[ii];
4557 InsertConfigString(pCfg, name.c_str(), value);
4558 }
4559 }
4560 break;
4561 }
4562
4563 default:
4564 AssertMsgFailed(("should not get here!\n"));
4565 break;
4566 }
4567
4568 /*
4569 * Attempt to attach the driver.
4570 */
4571 switch (eAttachmentType)
4572 {
4573 case NetworkAttachmentType_Null:
4574 break;
4575
4576 case NetworkAttachmentType_Bridged:
4577 case NetworkAttachmentType_Internal:
4578 case NetworkAttachmentType_HostOnly:
4579 case NetworkAttachmentType_NAT:
4580 case NetworkAttachmentType_Generic:
4581 {
4582 if (SUCCEEDED(hrc) && SUCCEEDED(rc))
4583 {
4584 if (fAttachDetach)
4585 {
4586 rc = PDMR3DriverAttach(pVM, pszDevice, uInstance, uLun, 0 /*fFlags*/, NULL /* ppBase */);
4587 //AssertRC(rc);
4588 }
4589
4590 {
4591 /** @todo pritesh: get the dhcp server name from the
4592 * previous network configuration and then stop the server
4593 * else it may conflict with the dhcp server running with
4594 * the current attachment type
4595 */
4596 /* Stop the hostonly DHCP Server */
4597 }
4598
4599 if (!networkName.isEmpty())
4600 {
4601 /*
4602 * Until we implement service reference counters DHCP Server will be stopped
4603 * by DHCPServerRunner destructor.
4604 */
4605 ComPtr<IDHCPServer> dhcpServer;
4606 hrc = virtualBox->FindDHCPServerByNetworkName(networkName.raw(),
4607 dhcpServer.asOutParam());
4608 if (SUCCEEDED(hrc))
4609 {
4610 /* there is a DHCP server available for this network */
4611 BOOL fEnabledDhcp;
4612 hrc = dhcpServer->COMGETTER(Enabled)(&fEnabledDhcp);
4613 if (FAILED(hrc))
4614 {
4615 LogRel(("DHCP svr: COMGETTER(Enabled) failed, hrc (%Rhrc)", hrc));
4616 H();
4617 }
4618
4619 if (fEnabledDhcp)
4620 hrc = dhcpServer->Start(networkName.raw(),
4621 trunkName.raw(),
4622 trunkType.raw());
4623 }
4624 else
4625 hrc = S_OK;
4626 }
4627 }
4628
4629 break;
4630 }
4631
4632 default:
4633 AssertMsgFailed(("should not get here!\n"));
4634 break;
4635 }
4636
4637 meAttachmentType[uInstance] = eAttachmentType;
4638 }
4639 catch (ConfigError &x)
4640 {
4641 // InsertConfig threw something:
4642 return x.m_vrc;
4643 }
4644
4645#undef H
4646
4647 return VINF_SUCCESS;
4648}
4649
4650#ifdef VBOX_WITH_GUEST_PROPS
4651/**
4652 * Set an array of guest properties
4653 */
4654static void configSetProperties(VMMDev * const pVMMDev,
4655 void *names,
4656 void *values,
4657 void *timestamps,
4658 void *flags)
4659{
4660 VBOXHGCMSVCPARM parms[4];
4661
4662 parms[0].type = VBOX_HGCM_SVC_PARM_PTR;
4663 parms[0].u.pointer.addr = names;
4664 parms[0].u.pointer.size = 0; /* We don't actually care. */
4665 parms[1].type = VBOX_HGCM_SVC_PARM_PTR;
4666 parms[1].u.pointer.addr = values;
4667 parms[1].u.pointer.size = 0; /* We don't actually care. */
4668 parms[2].type = VBOX_HGCM_SVC_PARM_PTR;
4669 parms[2].u.pointer.addr = timestamps;
4670 parms[2].u.pointer.size = 0; /* We don't actually care. */
4671 parms[3].type = VBOX_HGCM_SVC_PARM_PTR;
4672 parms[3].u.pointer.addr = flags;
4673 parms[3].u.pointer.size = 0; /* We don't actually care. */
4674
4675 pVMMDev->hgcmHostCall("VBoxGuestPropSvc",
4676 guestProp::SET_PROPS_HOST,
4677 4,
4678 &parms[0]);
4679}
4680
4681/**
4682 * Set a single guest property
4683 */
4684static void configSetProperty(VMMDev * const pVMMDev,
4685 const char *pszName,
4686 const char *pszValue,
4687 const char *pszFlags)
4688{
4689 VBOXHGCMSVCPARM parms[4];
4690
4691 AssertPtrReturnVoid(pszName);
4692 AssertPtrReturnVoid(pszValue);
4693 AssertPtrReturnVoid(pszFlags);
4694 parms[0].type = VBOX_HGCM_SVC_PARM_PTR;
4695 parms[0].u.pointer.addr = (void *)pszName;
4696 parms[0].u.pointer.size = strlen(pszName) + 1;
4697 parms[1].type = VBOX_HGCM_SVC_PARM_PTR;
4698 parms[1].u.pointer.addr = (void *)pszValue;
4699 parms[1].u.pointer.size = strlen(pszValue) + 1;
4700 parms[2].type = VBOX_HGCM_SVC_PARM_PTR;
4701 parms[2].u.pointer.addr = (void *)pszFlags;
4702 parms[2].u.pointer.size = strlen(pszFlags) + 1;
4703 pVMMDev->hgcmHostCall("VBoxGuestPropSvc", guestProp::SET_PROP_HOST, 3,
4704 &parms[0]);
4705}
4706
4707/**
4708 * Set the global flags value by calling the service
4709 * @returns the status returned by the call to the service
4710 *
4711 * @param pTable the service instance handle
4712 * @param eFlags the flags to set
4713 */
4714int configSetGlobalPropertyFlags(VMMDev * const pVMMDev,
4715 guestProp::ePropFlags eFlags)
4716{
4717 VBOXHGCMSVCPARM paParm;
4718 paParm.setUInt32(eFlags);
4719 int rc = pVMMDev->hgcmHostCall("VBoxGuestPropSvc",
4720 guestProp::SET_GLOBAL_FLAGS_HOST, 1,
4721 &paParm);
4722 if (RT_FAILURE(rc))
4723 {
4724 char szFlags[guestProp::MAX_FLAGS_LEN];
4725 if (RT_FAILURE(writeFlags(eFlags, szFlags)))
4726 Log(("Failed to set the global flags.\n"));
4727 else
4728 Log(("Failed to set the global flags \"%s\".\n", szFlags));
4729 }
4730 return rc;
4731}
4732#endif /* VBOX_WITH_GUEST_PROPS */
4733
4734/**
4735 * Set up the Guest Property service, populate it with properties read from
4736 * the machine XML and set a couple of initial properties.
4737 */
4738/* static */ int Console::configGuestProperties(void *pvConsole, PVM pVM)
4739{
4740#ifdef VBOX_WITH_GUEST_PROPS
4741 AssertReturn(pvConsole, VERR_GENERAL_FAILURE);
4742 ComObjPtr<Console> pConsole = static_cast<Console *>(pvConsole);
4743 AssertReturn(pConsole->m_pVMMDev, VERR_GENERAL_FAILURE);
4744
4745 /* Load the service */
4746 int rc = pConsole->m_pVMMDev->hgcmLoadService("VBoxGuestPropSvc", "VBoxGuestPropSvc");
4747
4748 if (RT_FAILURE(rc))
4749 {
4750 LogRel(("VBoxGuestPropSvc is not available. rc = %Rrc\n", rc));
4751 /* That is not a fatal failure. */
4752 rc = VINF_SUCCESS;
4753 }
4754 else
4755 {
4756 /*
4757 * Initialize built-in properties that can be changed and saved.
4758 *
4759 * These are typically transient properties that the guest cannot
4760 * change.
4761 */
4762
4763 {
4764 VBOXHGCMSVCPARM Params[2];
4765 pConsole->m_pVMMDev->hgcmHostCall("VBoxGuestPropSvc", guestProp::GET_DBGF_INFO_FN, 2, &Params[0]);
4766 PFNDBGFHANDLEREXT pfnHandler = (PFNDBGFHANDLEREXT)(uintptr_t)Params[0].u.pointer.addr;
4767 void *pService = (void*)Params[1].u.pointer.addr;
4768 DBGFR3InfoRegisterExternal(pVM, "guestprops", "Display the guest properties", pfnHandler, pService);
4769 }
4770
4771 /* Sysprep execution by VBoxService. */
4772 configSetProperty(pConsole->m_pVMMDev,
4773 "/VirtualBox/HostGuest/SysprepExec", "",
4774 "TRANSIENT, RDONLYGUEST");
4775 configSetProperty(pConsole->m_pVMMDev,
4776 "/VirtualBox/HostGuest/SysprepArgs", "",
4777 "TRANSIENT, RDONLYGUEST");
4778
4779 /*
4780 * Pull over the properties from the server.
4781 */
4782 SafeArray<BSTR> namesOut;
4783 SafeArray<BSTR> valuesOut;
4784 SafeArray<LONG64> timestampsOut;
4785 SafeArray<BSTR> flagsOut;
4786 HRESULT hrc;
4787 hrc = pConsole->mControl->PullGuestProperties(ComSafeArrayAsOutParam(namesOut),
4788 ComSafeArrayAsOutParam(valuesOut),
4789 ComSafeArrayAsOutParam(timestampsOut),
4790 ComSafeArrayAsOutParam(flagsOut));
4791 AssertMsgReturn(SUCCEEDED(hrc), ("hrc=%Rrc\n", hrc), VERR_GENERAL_FAILURE);
4792 size_t cProps = namesOut.size();
4793 size_t cAlloc = cProps + 1;
4794 if ( valuesOut.size() != cProps
4795 || timestampsOut.size() != cProps
4796 || flagsOut.size() != cProps
4797 )
4798 AssertFailedReturn(VERR_INVALID_PARAMETER);
4799
4800 char **papszNames, **papszValues, **papszFlags;
4801 char szEmpty[] = "";
4802 LONG64 *pai64Timestamps;
4803 papszNames = (char **)RTMemTmpAllocZ(sizeof(void *) * cAlloc);
4804 papszValues = (char **)RTMemTmpAllocZ(sizeof(void *) * cAlloc);
4805 pai64Timestamps = (LONG64 *)RTMemTmpAllocZ(sizeof(LONG64) * cAlloc);
4806 papszFlags = (char **)RTMemTmpAllocZ(sizeof(void *) * cAlloc);
4807 if (papszNames && papszValues && pai64Timestamps && papszFlags)
4808 {
4809 for (unsigned i = 0; RT_SUCCESS(rc) && i < cProps; ++i)
4810 {
4811 AssertPtrReturn(namesOut[i], VERR_INVALID_PARAMETER);
4812 rc = RTUtf16ToUtf8(namesOut[i], &papszNames[i]);
4813 if (RT_FAILURE(rc))
4814 break;
4815 if (valuesOut[i])
4816 rc = RTUtf16ToUtf8(valuesOut[i], &papszValues[i]);
4817 else
4818 papszValues[i] = szEmpty;
4819 if (RT_FAILURE(rc))
4820 break;
4821 pai64Timestamps[i] = timestampsOut[i];
4822 if (flagsOut[i])
4823 rc = RTUtf16ToUtf8(flagsOut[i], &papszFlags[i]);
4824 else
4825 papszFlags[i] = szEmpty;
4826 }
4827 if (RT_SUCCESS(rc))
4828 configSetProperties(pConsole->m_pVMMDev,
4829 (void *)papszNames,
4830 (void *)papszValues,
4831 (void *)pai64Timestamps,
4832 (void *)papszFlags);
4833 for (unsigned i = 0; i < cProps; ++i)
4834 {
4835 RTStrFree(papszNames[i]);
4836 if (valuesOut[i])
4837 RTStrFree(papszValues[i]);
4838 if (flagsOut[i])
4839 RTStrFree(papszFlags[i]);
4840 }
4841 }
4842 else
4843 rc = VERR_NO_MEMORY;
4844 RTMemTmpFree(papszNames);
4845 RTMemTmpFree(papszValues);
4846 RTMemTmpFree(pai64Timestamps);
4847 RTMemTmpFree(papszFlags);
4848 AssertRCReturn(rc, rc);
4849
4850 /*
4851 * These properties have to be set before pulling over the properties
4852 * from the machine XML, to ensure that properties saved in the XML
4853 * will override them.
4854 */
4855 /* Set the raw VBox version string as a guest property. Used for host/guest
4856 * version comparison. */
4857 configSetProperty(pConsole->m_pVMMDev, "/VirtualBox/HostInfo/VBoxVer",
4858 VBOX_VERSION_STRING_RAW, "TRANSIENT, RDONLYGUEST");
4859 /* Set the full VBox version string as a guest property. Can contain vendor-specific
4860 * information/branding and/or pre-release tags. */
4861 configSetProperty(pConsole->m_pVMMDev, "/VirtualBox/HostInfo/VBoxVerExt",
4862 VBOX_VERSION_STRING, "TRANSIENT, RDONLYGUEST");
4863 /* Set the VBox SVN revision as a guest property */
4864 configSetProperty(pConsole->m_pVMMDev, "/VirtualBox/HostInfo/VBoxRev",
4865 RTBldCfgRevisionStr(), "TRANSIENT, RDONLYGUEST");
4866
4867 /*
4868 * Register the host notification callback
4869 */
4870 HGCMSVCEXTHANDLE hDummy;
4871 HGCMHostRegisterServiceExtension(&hDummy, "VBoxGuestPropSvc",
4872 Console::doGuestPropNotification,
4873 pvConsole);
4874
4875#ifdef VBOX_WITH_GUEST_PROPS_RDONLY_GUEST
4876 rc = configSetGlobalPropertyFlags(pConsole->m_pVMMDev,
4877 guestProp::RDONLYGUEST);
4878 AssertRCReturn(rc, rc);
4879#endif
4880
4881 Log(("Set VBoxGuestPropSvc property store\n"));
4882 }
4883 return VINF_SUCCESS;
4884#else /* !VBOX_WITH_GUEST_PROPS */
4885 return VERR_NOT_SUPPORTED;
4886#endif /* !VBOX_WITH_GUEST_PROPS */
4887}
4888
4889/**
4890 * Set up the Guest Control service.
4891 */
4892/* static */ int Console::configGuestControl(void *pvConsole)
4893{
4894#ifdef VBOX_WITH_GUEST_CONTROL
4895 AssertReturn(pvConsole, VERR_GENERAL_FAILURE);
4896 ComObjPtr<Console> pConsole = static_cast<Console *>(pvConsole);
4897
4898 /* Load the service */
4899 int rc = pConsole->m_pVMMDev->hgcmLoadService("VBoxGuestControlSvc", "VBoxGuestControlSvc");
4900
4901 if (RT_FAILURE(rc))
4902 {
4903 LogRel(("VBoxGuestControlSvc is not available. rc = %Rrc\n", rc));
4904 /* That is not a fatal failure. */
4905 rc = VINF_SUCCESS;
4906 }
4907 else
4908 {
4909 HGCMSVCEXTHANDLE hDummy;
4910 rc = HGCMHostRegisterServiceExtension(&hDummy, "VBoxGuestControlSvc",
4911 &Guest::notifyCtrlDispatcher,
4912 pConsole->getGuest());
4913 if (RT_FAILURE(rc))
4914 Log(("Cannot register VBoxGuestControlSvc extension!\n"));
4915 else
4916 Log(("VBoxGuestControlSvc loaded\n"));
4917 }
4918
4919 return rc;
4920#else /* !VBOX_WITH_GUEST_CONTROL */
4921 return VERR_NOT_SUPPORTED;
4922#endif /* !VBOX_WITH_GUEST_CONTROL */
4923}
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