VirtualBox

source: vbox/trunk/src/VBox/Main/ConsoleImpl2.cpp@ 33907

Last change on this file since 33907 was 33907, checked in by vboxsync, 15 years ago

Main: more PCI assignment rules

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