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