VirtualBox

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

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

Main, Device: fix saved states (PCI)

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

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