VirtualBox

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

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

scm whitespace cleanup

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