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