VirtualBox

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

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

Devices: refactoring, further PCI work

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

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