VirtualBox

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

最後變更 在這個檔案從32718是 32718,由 vboxsync 提交於 15 年 前

com/string: Remove bool conversion operator and other convenience error operators. They are hiding programming errors (like incorrect empty string checks, and in one case a free of the wrong pointer).

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

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