VirtualBox

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

Last change on this file since 31818 was 31818, checked in by vboxsync, 14 years ago

added HWVirtEx force property to API

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

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette