VirtualBox

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

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

Main: allow multiple AHCI controllers

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

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