1 | /* $Id: VMMDev.cpp 81693 2019-11-06 01:11:29Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VMMDev - Guest <-> VMM/Host communication device.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2006-2019 Oracle Corporation
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
10 | * available from http://www.virtualbox.org. This file is free software;
|
---|
11 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
12 | * General Public License (GPL) as published by the Free Software
|
---|
13 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
14 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
15 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
16 | */
|
---|
17 |
|
---|
18 | /** @page pg_vmmdev The VMM Device.
|
---|
19 | *
|
---|
20 | * The VMM device is a custom hardware device emulation for communicating with
|
---|
21 | * the guest additions.
|
---|
22 | *
|
---|
23 | * Whenever host wants to inform guest about something an IRQ notification will
|
---|
24 | * be raised.
|
---|
25 | *
|
---|
26 | * VMMDev PDM interface will contain the guest notification method.
|
---|
27 | *
|
---|
28 | * There is a 32 bit event mask which will be read by guest on an interrupt. A
|
---|
29 | * non zero bit in the mask means that the specific event occurred and requires
|
---|
30 | * processing on guest side.
|
---|
31 | *
|
---|
32 | * After reading the event mask guest must issue a generic request
|
---|
33 | * AcknowlegdeEvents.
|
---|
34 | *
|
---|
35 | * IRQ line is set to 1 (request) if there are unprocessed events, that is the
|
---|
36 | * event mask is not zero.
|
---|
37 | *
|
---|
38 | * After receiving an interrupt and checking event mask, the guest must process
|
---|
39 | * events using the event specific mechanism.
|
---|
40 | *
|
---|
41 | * That is if mouse capabilities were changed, guest will use
|
---|
42 | * VMMDev_GetMouseStatus generic request.
|
---|
43 | *
|
---|
44 | * Event mask is only a set of flags indicating that guest must proceed with a
|
---|
45 | * procedure.
|
---|
46 | *
|
---|
47 | * Unsupported events are therefore ignored. The guest additions must inform
|
---|
48 | * host which events they want to receive, to avoid unnecessary IRQ processing.
|
---|
49 | * By default no events are signalled to guest.
|
---|
50 | *
|
---|
51 | * This seems to be fast method. It requires only one context switch for an
|
---|
52 | * event processing.
|
---|
53 | *
|
---|
54 | *
|
---|
55 | * @section sec_vmmdev_heartbeat Heartbeat
|
---|
56 | *
|
---|
57 | * The heartbeat is a feature to monitor whether the guest OS is hung or not.
|
---|
58 | *
|
---|
59 | * The main kernel component of the guest additions, VBoxGuest, sets up a timer
|
---|
60 | * at a frequency returned by VMMDevReq_HeartbeatConfigure
|
---|
61 | * (VMMDevReqHeartbeat::cNsInterval, VMMDEV::cNsHeartbeatInterval) and performs
|
---|
62 | * a VMMDevReq_GuestHeartbeat request every time the timer ticks.
|
---|
63 | *
|
---|
64 | * The host side (VMMDev) arms a timer with a more distant deadline
|
---|
65 | * (VMMDEV::cNsHeartbeatTimeout), twice cNsHeartbeatInterval by default. Each
|
---|
66 | * time a VMMDevReq_GuestHeartbeat request comes in, the timer is rearmed with
|
---|
67 | * the same relative deadline. So, as long as VMMDevReq_GuestHeartbeat comes
|
---|
68 | * when they should, the host timer will never fire.
|
---|
69 | *
|
---|
70 | * When the timer fires, we consider the guest as hung / flatlined / dead.
|
---|
71 | * Currently we only LogRel that, but it's easy to extend this with an event in
|
---|
72 | * Main API.
|
---|
73 | *
|
---|
74 | * Should the guest reawaken at some later point, we LogRel that event and
|
---|
75 | * continue as normal. Again something which would merit an API event.
|
---|
76 | *
|
---|
77 | */
|
---|
78 |
|
---|
79 |
|
---|
80 | /*********************************************************************************************************************************
|
---|
81 | * Header Files *
|
---|
82 | *********************************************************************************************************************************/
|
---|
83 | /* Enable dev_vmm Log3 statements to get IRQ-related logging. */
|
---|
84 | #define LOG_GROUP LOG_GROUP_DEV_VMM
|
---|
85 | #include <VBox/AssertGuest.h>
|
---|
86 | #include <VBox/VMMDev.h>
|
---|
87 | #include <VBox/vmm/dbgf.h>
|
---|
88 | #include <VBox/vmm/mm.h>
|
---|
89 | #include <VBox/log.h>
|
---|
90 | #include <VBox/param.h>
|
---|
91 | #include <iprt/path.h>
|
---|
92 | #include <iprt/dir.h>
|
---|
93 | #include <iprt/file.h>
|
---|
94 | #include <VBox/vmm/pgm.h>
|
---|
95 | #include <VBox/err.h>
|
---|
96 | #include <VBox/dbg.h>
|
---|
97 | #include <VBox/version.h>
|
---|
98 |
|
---|
99 | #include <iprt/asm.h>
|
---|
100 | #include <iprt/asm-amd64-x86.h>
|
---|
101 | #include <iprt/assert.h>
|
---|
102 | #include <iprt/buildconfig.h>
|
---|
103 | #include <iprt/string.h>
|
---|
104 | #include <iprt/time.h>
|
---|
105 | #ifndef IN_RC
|
---|
106 | # include <iprt/mem.h>
|
---|
107 | # include <iprt/memsafer.h>
|
---|
108 | #endif
|
---|
109 | #ifdef IN_RING3
|
---|
110 | # include <iprt/uuid.h>
|
---|
111 | #endif
|
---|
112 |
|
---|
113 | #include "VMMDevState.h"
|
---|
114 | #ifdef VBOX_WITH_HGCM
|
---|
115 | # include "VMMDevHGCM.h"
|
---|
116 | #endif
|
---|
117 | #ifndef VBOX_WITHOUT_TESTING_FEATURES
|
---|
118 | # include "VMMDevTesting.h"
|
---|
119 | #endif
|
---|
120 |
|
---|
121 |
|
---|
122 | /*********************************************************************************************************************************
|
---|
123 | * Defined Constants And Macros *
|
---|
124 | *********************************************************************************************************************************/
|
---|
125 | #define VMMDEV_INTERFACE_VERSION_IS_1_03(s) \
|
---|
126 | ( RT_HIWORD((s)->guestInfo.interfaceVersion) == 1 \
|
---|
127 | && RT_LOWORD((s)->guestInfo.interfaceVersion) == 3 )
|
---|
128 |
|
---|
129 | #define VMMDEV_INTERFACE_VERSION_IS_OK(additionsVersion) \
|
---|
130 | ( RT_HIWORD(additionsVersion) == RT_HIWORD(VMMDEV_VERSION) \
|
---|
131 | && RT_LOWORD(additionsVersion) <= RT_LOWORD(VMMDEV_VERSION) )
|
---|
132 |
|
---|
133 | #define VMMDEV_INTERFACE_VERSION_IS_OLD(additionsVersion) \
|
---|
134 | ( (RT_HIWORD(additionsVersion) < RT_HIWORD(VMMDEV_VERSION) \
|
---|
135 | || ( RT_HIWORD(additionsVersion) == RT_HIWORD(VMMDEV_VERSION) \
|
---|
136 | && RT_LOWORD(additionsVersion) <= RT_LOWORD(VMMDEV_VERSION) ) )
|
---|
137 |
|
---|
138 | #define VMMDEV_INTERFACE_VERSION_IS_TOO_OLD(additionsVersion) \
|
---|
139 | ( RT_HIWORD(additionsVersion) < RT_HIWORD(VMMDEV_VERSION) )
|
---|
140 |
|
---|
141 | #define VMMDEV_INTERFACE_VERSION_IS_NEW(additionsVersion) \
|
---|
142 | ( RT_HIWORD(additionsVersion) > RT_HIWORD(VMMDEV_VERSION) \
|
---|
143 | || ( RT_HIWORD(additionsVersion) == RT_HIWORD(VMMDEV_VERSION) \
|
---|
144 | && RT_LOWORD(additionsVersion) > RT_LOWORD(VMMDEV_VERSION) ) )
|
---|
145 |
|
---|
146 | /** Default interval in nanoseconds between guest heartbeats.
|
---|
147 | * Used when no HeartbeatInterval is set in CFGM and for setting
|
---|
148 | * HB check timer if the guest's heartbeat frequency is less than 1Hz. */
|
---|
149 | #define VMMDEV_HEARTBEAT_DEFAULT_INTERVAL (2U*RT_NS_1SEC_64)
|
---|
150 |
|
---|
151 |
|
---|
152 | #ifndef VBOX_DEVICE_STRUCT_TESTCASE
|
---|
153 | #ifdef IN_RING3
|
---|
154 |
|
---|
155 | /* -=-=-=-=- Misc Helpers -=-=-=-=- */
|
---|
156 |
|
---|
157 | /**
|
---|
158 | * Log information about the Guest Additions.
|
---|
159 | *
|
---|
160 | * @param pGuestInfo The information we've got from the Guest Additions driver.
|
---|
161 | */
|
---|
162 | static void vmmdevLogGuestOsInfo(VBoxGuestInfo *pGuestInfo)
|
---|
163 | {
|
---|
164 | const char *pszOs;
|
---|
165 | switch (pGuestInfo->osType & ~VBOXOSTYPE_x64)
|
---|
166 | {
|
---|
167 | case VBOXOSTYPE_DOS: pszOs = "DOS"; break;
|
---|
168 | case VBOXOSTYPE_Win31: pszOs = "Windows 3.1"; break;
|
---|
169 | case VBOXOSTYPE_Win9x: pszOs = "Windows 9x"; break;
|
---|
170 | case VBOXOSTYPE_Win95: pszOs = "Windows 95"; break;
|
---|
171 | case VBOXOSTYPE_Win98: pszOs = "Windows 98"; break;
|
---|
172 | case VBOXOSTYPE_WinMe: pszOs = "Windows Me"; break;
|
---|
173 | case VBOXOSTYPE_WinNT: pszOs = "Windows NT"; break;
|
---|
174 | case VBOXOSTYPE_WinNT3x: pszOs = "Windows NT 3.x"; break;
|
---|
175 | case VBOXOSTYPE_WinNT4: pszOs = "Windows NT4"; break;
|
---|
176 | case VBOXOSTYPE_Win2k: pszOs = "Windows 2k"; break;
|
---|
177 | case VBOXOSTYPE_WinXP: pszOs = "Windows XP"; break;
|
---|
178 | case VBOXOSTYPE_Win2k3: pszOs = "Windows 2k3"; break;
|
---|
179 | case VBOXOSTYPE_WinVista: pszOs = "Windows Vista"; break;
|
---|
180 | case VBOXOSTYPE_Win2k8: pszOs = "Windows 2k8"; break;
|
---|
181 | case VBOXOSTYPE_Win7: pszOs = "Windows 7"; break;
|
---|
182 | case VBOXOSTYPE_Win8: pszOs = "Windows 8"; break;
|
---|
183 | case VBOXOSTYPE_Win2k12_x64 & ~VBOXOSTYPE_x64: pszOs = "Windows 2k12"; break;
|
---|
184 | case VBOXOSTYPE_Win81: pszOs = "Windows 8.1"; break;
|
---|
185 | case VBOXOSTYPE_Win10: pszOs = "Windows 10"; break;
|
---|
186 | case VBOXOSTYPE_Win2k16_x64 & ~VBOXOSTYPE_x64: pszOs = "Windows 2k16"; break;
|
---|
187 | case VBOXOSTYPE_OS2: pszOs = "OS/2"; break;
|
---|
188 | case VBOXOSTYPE_OS2Warp3: pszOs = "OS/2 Warp 3"; break;
|
---|
189 | case VBOXOSTYPE_OS2Warp4: pszOs = "OS/2 Warp 4"; break;
|
---|
190 | case VBOXOSTYPE_OS2Warp45: pszOs = "OS/2 Warp 4.5"; break;
|
---|
191 | case VBOXOSTYPE_ECS: pszOs = "OS/2 ECS"; break;
|
---|
192 | case VBOXOSTYPE_OS21x: pszOs = "OS/2 2.1x"; break;
|
---|
193 | case VBOXOSTYPE_Linux: pszOs = "Linux"; break;
|
---|
194 | case VBOXOSTYPE_Linux22: pszOs = "Linux 2.2"; break;
|
---|
195 | case VBOXOSTYPE_Linux24: pszOs = "Linux 2.4"; break;
|
---|
196 | case VBOXOSTYPE_Linux26: pszOs = "Linux >= 2.6"; break;
|
---|
197 | case VBOXOSTYPE_ArchLinux: pszOs = "ArchLinux"; break;
|
---|
198 | case VBOXOSTYPE_Debian: pszOs = "Debian"; break;
|
---|
199 | case VBOXOSTYPE_OpenSUSE: pszOs = "openSUSE"; break;
|
---|
200 | case VBOXOSTYPE_FedoraCore: pszOs = "Fedora"; break;
|
---|
201 | case VBOXOSTYPE_Gentoo: pszOs = "Gentoo"; break;
|
---|
202 | case VBOXOSTYPE_Mandriva: pszOs = "Mandriva"; break;
|
---|
203 | case VBOXOSTYPE_RedHat: pszOs = "RedHat"; break;
|
---|
204 | case VBOXOSTYPE_Turbolinux: pszOs = "TurboLinux"; break;
|
---|
205 | case VBOXOSTYPE_Ubuntu: pszOs = "Ubuntu"; break;
|
---|
206 | case VBOXOSTYPE_Xandros: pszOs = "Xandros"; break;
|
---|
207 | case VBOXOSTYPE_Oracle: pszOs = "Oracle Linux"; break;
|
---|
208 | case VBOXOSTYPE_FreeBSD: pszOs = "FreeBSD"; break;
|
---|
209 | case VBOXOSTYPE_OpenBSD: pszOs = "OpenBSD"; break;
|
---|
210 | case VBOXOSTYPE_NetBSD: pszOs = "NetBSD"; break;
|
---|
211 | case VBOXOSTYPE_Netware: pszOs = "Netware"; break;
|
---|
212 | case VBOXOSTYPE_Solaris: pszOs = "Solaris"; break;
|
---|
213 | case VBOXOSTYPE_OpenSolaris: pszOs = "OpenSolaris"; break;
|
---|
214 | case VBOXOSTYPE_Solaris11_x64 & ~VBOXOSTYPE_x64: pszOs = "Solaris 11"; break;
|
---|
215 | case VBOXOSTYPE_MacOS: pszOs = "Mac OS X"; break;
|
---|
216 | case VBOXOSTYPE_MacOS106: pszOs = "Mac OS X 10.6"; break;
|
---|
217 | case VBOXOSTYPE_MacOS107_x64 & ~VBOXOSTYPE_x64: pszOs = "Mac OS X 10.7"; break;
|
---|
218 | case VBOXOSTYPE_MacOS108_x64 & ~VBOXOSTYPE_x64: pszOs = "Mac OS X 10.8"; break;
|
---|
219 | case VBOXOSTYPE_MacOS109_x64 & ~VBOXOSTYPE_x64: pszOs = "Mac OS X 10.9"; break;
|
---|
220 | case VBOXOSTYPE_MacOS1010_x64 & ~VBOXOSTYPE_x64: pszOs = "Mac OS X 10.10"; break;
|
---|
221 | case VBOXOSTYPE_MacOS1011_x64 & ~VBOXOSTYPE_x64: pszOs = "Mac OS X 10.11"; break;
|
---|
222 | case VBOXOSTYPE_MacOS1012_x64 & ~VBOXOSTYPE_x64: pszOs = "macOS 10.12"; break;
|
---|
223 | case VBOXOSTYPE_MacOS1013_x64 & ~VBOXOSTYPE_x64: pszOs = "macOS 10.13"; break;
|
---|
224 | case VBOXOSTYPE_Haiku: pszOs = "Haiku"; break;
|
---|
225 | default: pszOs = "unknown"; break;
|
---|
226 | }
|
---|
227 | LogRel(("VMMDev: Guest Additions information report: Interface = 0x%08X osType = 0x%08X (%s, %u-bit)\n",
|
---|
228 | pGuestInfo->interfaceVersion, pGuestInfo->osType, pszOs,
|
---|
229 | pGuestInfo->osType & VBOXOSTYPE_x64 ? 64 : 32));
|
---|
230 | }
|
---|
231 |
|
---|
232 |
|
---|
233 | /**
|
---|
234 | * Sets the IRQ (raise it or lower it) for 1.03 additions.
|
---|
235 | *
|
---|
236 | * @param pDevIns The device instance.
|
---|
237 | * @param pThis The VMMDev shared instance data.
|
---|
238 | * @param pThisCC The VMMDev ring-3 instance data.
|
---|
239 | * @thread Any.
|
---|
240 | * @remarks Must be called owning the critical section.
|
---|
241 | */
|
---|
242 | static void vmmdevSetIRQ_Legacy(PPDMDEVINS pDevIns, PVMMDEV pThis, PVMMDEVCC pThisCC)
|
---|
243 | {
|
---|
244 | if (pThis->fu32AdditionsOk)
|
---|
245 | {
|
---|
246 | /* Filter unsupported events */
|
---|
247 | uint32_t fEvents = pThis->fHostEventFlags & pThisCC->CTX_SUFF(pVMMDevRAM)->V.V1_03.u32GuestEventMask;
|
---|
248 |
|
---|
249 | Log(("vmmdevSetIRQ: fEvents=%#010x, fHostEventFlags=%#010x, u32GuestEventMask=%#010x.\n",
|
---|
250 | fEvents, pThis->fHostEventFlags, pThisCC->CTX_SUFF(pVMMDevRAM)->V.V1_03.u32GuestEventMask));
|
---|
251 |
|
---|
252 | /* Move event flags to VMMDev RAM */
|
---|
253 | pThisCC->CTX_SUFF(pVMMDevRAM)->V.V1_03.u32HostEvents = fEvents;
|
---|
254 |
|
---|
255 | uint32_t uIRQLevel = 0;
|
---|
256 | if (fEvents)
|
---|
257 | {
|
---|
258 | /* Clear host flags which will be delivered to guest. */
|
---|
259 | pThis->fHostEventFlags &= ~fEvents;
|
---|
260 | Log(("vmmdevSetIRQ: fHostEventFlags=%#010x\n", pThis->fHostEventFlags));
|
---|
261 | uIRQLevel = 1;
|
---|
262 | }
|
---|
263 |
|
---|
264 | /* Set IRQ level for pin 0 (see NoWait comment in vmmdevMaybeSetIRQ). */
|
---|
265 | /** @todo make IRQ pin configurable, at least a symbolic constant */
|
---|
266 | PDMDevHlpPCISetIrqNoWait(pDevIns, 0, uIRQLevel);
|
---|
267 | Log(("vmmdevSetIRQ: IRQ set %d\n", uIRQLevel));
|
---|
268 | }
|
---|
269 | else
|
---|
270 | Log(("vmmdevSetIRQ: IRQ is not generated, guest has not yet reported to us.\n"));
|
---|
271 | }
|
---|
272 |
|
---|
273 |
|
---|
274 | /**
|
---|
275 | * Sets the IRQ if there are events to be delivered.
|
---|
276 | *
|
---|
277 | * @param pDevIns The device instance.
|
---|
278 | * @param pThis The VMMDev shared instance data.
|
---|
279 | * @param pThisCC The VMMDev ring-3 instance data.
|
---|
280 | * @thread Any.
|
---|
281 | * @remarks Must be called owning the critical section.
|
---|
282 | */
|
---|
283 | static void vmmdevMaybeSetIRQ(PPDMDEVINS pDevIns, PVMMDEV pThis, PVMMDEVCC pThisCC)
|
---|
284 | {
|
---|
285 | Log3(("vmmdevMaybeSetIRQ: fHostEventFlags=%#010x, fGuestFilterMask=%#010x.\n",
|
---|
286 | pThis->fHostEventFlags, pThis->fGuestFilterMask));
|
---|
287 |
|
---|
288 | if (pThis->fHostEventFlags & pThis->fGuestFilterMask)
|
---|
289 | {
|
---|
290 | /*
|
---|
291 | * Note! No need to wait for the IRQs to be set (if we're not luck
|
---|
292 | * with the locks, etc). It is a notification about something,
|
---|
293 | * which has already happened.
|
---|
294 | */
|
---|
295 | pThisCC->pVMMDevRAMR3->V.V1_04.fHaveEvents = true;
|
---|
296 | PDMDevHlpPCISetIrqNoWait(pDevIns, 0, 1);
|
---|
297 | Log3(("vmmdevMaybeSetIRQ: IRQ set.\n"));
|
---|
298 | }
|
---|
299 | }
|
---|
300 |
|
---|
301 | /**
|
---|
302 | * Notifies the guest about new events (@a fAddEvents).
|
---|
303 | *
|
---|
304 | * @param pDevIns The device instance.
|
---|
305 | * @param pThis The VMMDev shared instance data.
|
---|
306 | * @param pThisCC The VMMDev ring-3 instance data.
|
---|
307 | * @param fAddEvents New events to add.
|
---|
308 | * @thread Any.
|
---|
309 | * @remarks Must be called owning the critical section.
|
---|
310 | */
|
---|
311 | static void vmmdevNotifyGuestWorker(PPDMDEVINS pDevIns, PVMMDEV pThis, PVMMDEVCC pThisCC, uint32_t fAddEvents)
|
---|
312 | {
|
---|
313 | Log3(("vmmdevNotifyGuestWorker: fAddEvents=%#010x.\n", fAddEvents));
|
---|
314 | Assert(PDMCritSectIsOwner(&pThis->CritSect));
|
---|
315 |
|
---|
316 | if (!VMMDEV_INTERFACE_VERSION_IS_1_03(pThis))
|
---|
317 | {
|
---|
318 | Log3(("vmmdevNotifyGuestWorker: New additions detected.\n"));
|
---|
319 |
|
---|
320 | if (pThis->fu32AdditionsOk)
|
---|
321 | {
|
---|
322 | const bool fHadEvents = (pThis->fHostEventFlags & pThis->fGuestFilterMask) != 0;
|
---|
323 |
|
---|
324 | Log3(("vmmdevNotifyGuestWorker: fHadEvents=%d, fHostEventFlags=%#010x, fGuestFilterMask=%#010x.\n",
|
---|
325 | fHadEvents, pThis->fHostEventFlags, pThis->fGuestFilterMask));
|
---|
326 |
|
---|
327 | pThis->fHostEventFlags |= fAddEvents;
|
---|
328 |
|
---|
329 | if (!fHadEvents)
|
---|
330 | vmmdevMaybeSetIRQ(pDevIns, pThis, pThisCC);
|
---|
331 | }
|
---|
332 | else
|
---|
333 | {
|
---|
334 | pThis->fHostEventFlags |= fAddEvents;
|
---|
335 | Log(("vmmdevNotifyGuestWorker: IRQ is not generated, guest has not yet reported to us.\n"));
|
---|
336 | }
|
---|
337 | }
|
---|
338 | else
|
---|
339 | {
|
---|
340 | Log3(("vmmdevNotifyGuestWorker: Old additions detected.\n"));
|
---|
341 |
|
---|
342 | pThis->fHostEventFlags |= fAddEvents;
|
---|
343 | vmmdevSetIRQ_Legacy(pDevIns, pThis, pThisCC);
|
---|
344 | }
|
---|
345 | }
|
---|
346 |
|
---|
347 |
|
---|
348 |
|
---|
349 | /* -=-=-=-=- Interfaces shared with VMMDevHGCM.cpp -=-=-=-=- */
|
---|
350 |
|
---|
351 | /**
|
---|
352 | * Notifies the guest about new events (@a fAddEvents).
|
---|
353 | *
|
---|
354 | * This is used by VMMDev.cpp as well as VMMDevHGCM.cpp.
|
---|
355 | *
|
---|
356 | * @param pDevIns The device instance.
|
---|
357 | * @param pThis The VMMDev shared instance data.
|
---|
358 | * @param pThisCC The VMMDev ring-3 instance data.
|
---|
359 | * @param fAddEvents New events to add.
|
---|
360 | * @thread Any.
|
---|
361 | */
|
---|
362 | void VMMDevNotifyGuest(PPDMDEVINS pDevIns, PVMMDEV pThis, PVMMDEVCC pThisCC, uint32_t fAddEvents)
|
---|
363 | {
|
---|
364 | Log3(("VMMDevNotifyGuest: fAddEvents=%#010x\n", fAddEvents));
|
---|
365 |
|
---|
366 | /*
|
---|
367 | * Only notify the VM when it's running.
|
---|
368 | */
|
---|
369 | VMSTATE enmVMState = PDMDevHlpVMState(pDevIns);
|
---|
370 | if ( enmVMState == VMSTATE_RUNNING
|
---|
371 | || enmVMState == VMSTATE_RUNNING_LS
|
---|
372 | || enmVMState == VMSTATE_LOADING
|
---|
373 | || enmVMState == VMSTATE_RESUMING
|
---|
374 | || enmVMState == VMSTATE_SUSPENDING
|
---|
375 | || enmVMState == VMSTATE_SUSPENDING_LS
|
---|
376 | || enmVMState == VMSTATE_SUSPENDING_EXT_LS
|
---|
377 | || enmVMState == VMSTATE_DEBUGGING
|
---|
378 | || enmVMState == VMSTATE_DEBUGGING_LS
|
---|
379 | )
|
---|
380 | {
|
---|
381 | PDMDevHlpCritSectEnter(pDevIns, &pThis->CritSect, VERR_IGNORED);
|
---|
382 | vmmdevNotifyGuestWorker(pDevIns, pThis, pThisCC, fAddEvents);
|
---|
383 | PDMDevHlpCritSectLeave(pDevIns, &pThis->CritSect);
|
---|
384 | }
|
---|
385 | else
|
---|
386 | LogRel(("VMMDevNotifyGuest: fAddEvents=%#x ignored because enmVMState=%d\n", fAddEvents, enmVMState));
|
---|
387 | }
|
---|
388 |
|
---|
389 | /**
|
---|
390 | * Code shared by VMMDevReq_CtlGuestFilterMask and HGCM for controlling the
|
---|
391 | * events the guest are interested in.
|
---|
392 | *
|
---|
393 | * @param pDevIns The device instance.
|
---|
394 | * @param pThis The VMMDev shared instance data.
|
---|
395 | * @param pThisCC The VMMDev ring-3 instance data.
|
---|
396 | * @param fOrMask Events to add (VMMDEV_EVENT_XXX). Pass 0 for no
|
---|
397 | * change.
|
---|
398 | * @param fNotMask Events to remove (VMMDEV_EVENT_XXX). Pass 0 for no
|
---|
399 | * change.
|
---|
400 | *
|
---|
401 | * @remarks When HGCM will automatically enable VMMDEV_EVENT_HGCM when the guest
|
---|
402 | * starts submitting HGCM requests. Otherwise, the events are
|
---|
403 | * controlled by the guest.
|
---|
404 | */
|
---|
405 | void VMMDevCtlSetGuestFilterMask(PPDMDEVINS pDevIns, PVMMDEV pThis, PVMMDEVCC pThisCC, uint32_t fOrMask, uint32_t fNotMask)
|
---|
406 | {
|
---|
407 | PDMDevHlpCritSectEnter(pDevIns, &pThis->CritSect, VERR_IGNORED);
|
---|
408 |
|
---|
409 | const bool fHadEvents = (pThis->fHostEventFlags & pThis->fGuestFilterMask) != 0;
|
---|
410 |
|
---|
411 | Log(("VMMDevCtlSetGuestFilterMask: fOrMask=%#010x, u32NotMask=%#010x, fHadEvents=%d.\n", fOrMask, fNotMask, fHadEvents));
|
---|
412 | if (fHadEvents)
|
---|
413 | {
|
---|
414 | if (!pThis->fNewGuestFilterMaskValid)
|
---|
415 | pThis->fNewGuestFilterMask = pThis->fGuestFilterMask;
|
---|
416 |
|
---|
417 | pThis->fNewGuestFilterMask |= fOrMask;
|
---|
418 | pThis->fNewGuestFilterMask &= ~fNotMask;
|
---|
419 | pThis->fNewGuestFilterMaskValid = true;
|
---|
420 | }
|
---|
421 | else
|
---|
422 | {
|
---|
423 | pThis->fGuestFilterMask |= fOrMask;
|
---|
424 | pThis->fGuestFilterMask &= ~fNotMask;
|
---|
425 | vmmdevMaybeSetIRQ(pDevIns, pThis, pThisCC);
|
---|
426 | }
|
---|
427 |
|
---|
428 | PDMDevHlpCritSectLeave(pDevIns, &pThis->CritSect);
|
---|
429 | }
|
---|
430 |
|
---|
431 |
|
---|
432 |
|
---|
433 | /* -=-=-=-=- Request processing functions. -=-=-=-=- */
|
---|
434 |
|
---|
435 | /**
|
---|
436 | * Handles VMMDevReq_ReportGuestInfo.
|
---|
437 | *
|
---|
438 | * @returns VBox status code that the guest should see.
|
---|
439 | * @param pDevIns The device instance.
|
---|
440 | * @param pThis The VMMDev shared instance data.
|
---|
441 | * @param pThisCC The VMMDev ring-3 instance data.
|
---|
442 | * @param pRequestHeader The header of the request to handle.
|
---|
443 | */
|
---|
444 | static int vmmdevReqHandler_ReportGuestInfo(PPDMDEVINS pDevIns, PVMMDEV pThis, PVMMDEVCC pThisCC,
|
---|
445 | VMMDevRequestHeader *pRequestHeader)
|
---|
446 | {
|
---|
447 | AssertMsgReturn(pRequestHeader->size == sizeof(VMMDevReportGuestInfo), ("%u\n", pRequestHeader->size), VERR_INVALID_PARAMETER);
|
---|
448 | VBoxGuestInfo const *pInfo = &((VMMDevReportGuestInfo *)pRequestHeader)->guestInfo;
|
---|
449 |
|
---|
450 | if (memcmp(&pThis->guestInfo, pInfo, sizeof(*pInfo)) != 0)
|
---|
451 | {
|
---|
452 | /* Make a copy of supplied information. */
|
---|
453 | pThis->guestInfo = *pInfo;
|
---|
454 |
|
---|
455 | /* Check additions interface version. */
|
---|
456 | pThis->fu32AdditionsOk = VMMDEV_INTERFACE_VERSION_IS_OK(pThis->guestInfo.interfaceVersion);
|
---|
457 |
|
---|
458 | vmmdevLogGuestOsInfo(&pThis->guestInfo);
|
---|
459 |
|
---|
460 | if (pThisCC->pDrv && pThisCC->pDrv->pfnUpdateGuestInfo)
|
---|
461 | pThisCC->pDrv->pfnUpdateGuestInfo(pThisCC->pDrv, &pThis->guestInfo);
|
---|
462 | }
|
---|
463 |
|
---|
464 | if (!pThis->fu32AdditionsOk)
|
---|
465 | return VERR_VERSION_MISMATCH;
|
---|
466 |
|
---|
467 | /* Clear our IRQ in case it was high for whatever reason. */
|
---|
468 | PDMDevHlpPCISetIrqNoWait(pDevIns, 0, 0);
|
---|
469 |
|
---|
470 | return VINF_SUCCESS;
|
---|
471 | }
|
---|
472 |
|
---|
473 |
|
---|
474 | /**
|
---|
475 | * Handles VMMDevReq_GuestHeartbeat.
|
---|
476 | *
|
---|
477 | * @returns VBox status code that the guest should see.
|
---|
478 | * @param pDevIns The device instance.
|
---|
479 | * @param pThis The VMMDev shared instance data.
|
---|
480 | */
|
---|
481 | static int vmmDevReqHandler_GuestHeartbeat(PPDMDEVINS pDevIns, PVMMDEV pThis)
|
---|
482 | {
|
---|
483 | int rc;
|
---|
484 | if (pThis->fHeartbeatActive)
|
---|
485 | {
|
---|
486 | uint64_t const nsNowTS = PDMDevHlpTimerGetNano(pDevIns, pThis->hFlatlinedTimer);
|
---|
487 | if (!pThis->fFlatlined)
|
---|
488 | { /* likely */ }
|
---|
489 | else
|
---|
490 | {
|
---|
491 | LogRel(("VMMDev: GuestHeartBeat: Guest is alive (gone %'llu ns)\n", nsNowTS - pThis->nsLastHeartbeatTS));
|
---|
492 | ASMAtomicWriteBool(&pThis->fFlatlined, false);
|
---|
493 | }
|
---|
494 | ASMAtomicWriteU64(&pThis->nsLastHeartbeatTS, nsNowTS);
|
---|
495 |
|
---|
496 | /* Postpone (or restart if we missed a beat) the timeout timer. */
|
---|
497 | rc = PDMDevHlpTimerSetNano(pDevIns, pThis->hFlatlinedTimer, pThis->cNsHeartbeatTimeout);
|
---|
498 | }
|
---|
499 | else
|
---|
500 | rc = VINF_SUCCESS;
|
---|
501 | return rc;
|
---|
502 | }
|
---|
503 |
|
---|
504 |
|
---|
505 | /**
|
---|
506 | * Timer that fires when where have been no heartbeats for a given time.
|
---|
507 | *
|
---|
508 | * @remarks Does not take the VMMDev critsect.
|
---|
509 | */
|
---|
510 | static DECLCALLBACK(void) vmmDevHeartbeatFlatlinedTimer(PPDMDEVINS pDevIns, PTMTIMER pTimer, void *pvUser)
|
---|
511 | {
|
---|
512 | RT_NOREF(pDevIns);
|
---|
513 | PVMMDEV pThis = (PVMMDEV)pvUser;
|
---|
514 | if (pThis->fHeartbeatActive)
|
---|
515 | {
|
---|
516 | uint64_t cNsElapsed = TMTimerGetNano(pTimer) - pThis->nsLastHeartbeatTS;
|
---|
517 | if ( !pThis->fFlatlined
|
---|
518 | && cNsElapsed >= pThis->cNsHeartbeatInterval)
|
---|
519 | {
|
---|
520 | LogRel(("VMMDev: vmmDevHeartbeatFlatlinedTimer: Guest seems to be unresponsive. Last heartbeat received %RU64 seconds ago\n",
|
---|
521 | cNsElapsed / RT_NS_1SEC));
|
---|
522 | ASMAtomicWriteBool(&pThis->fFlatlined, true);
|
---|
523 | }
|
---|
524 | }
|
---|
525 | }
|
---|
526 |
|
---|
527 |
|
---|
528 | /**
|
---|
529 | * Handles VMMDevReq_HeartbeatConfigure.
|
---|
530 | *
|
---|
531 | * @returns VBox status code that the guest should see.
|
---|
532 | * @param pDevIns The device instance.
|
---|
533 | * @param pThis The VMMDev shared instance data.
|
---|
534 | * @param pReqHdr The header of the request to handle.
|
---|
535 | */
|
---|
536 | static int vmmDevReqHandler_HeartbeatConfigure(PPDMDEVINS pDevIns, PVMMDEV pThis, VMMDevRequestHeader *pReqHdr)
|
---|
537 | {
|
---|
538 | AssertMsgReturn(pReqHdr->size == sizeof(VMMDevReqHeartbeat), ("%u\n", pReqHdr->size), VERR_INVALID_PARAMETER);
|
---|
539 | VMMDevReqHeartbeat *pReq = (VMMDevReqHeartbeat *)pReqHdr;
|
---|
540 | int rc;
|
---|
541 |
|
---|
542 | pReq->cNsInterval = pThis->cNsHeartbeatInterval;
|
---|
543 |
|
---|
544 | if (pReq->fEnabled != pThis->fHeartbeatActive)
|
---|
545 | {
|
---|
546 | ASMAtomicWriteBool(&pThis->fHeartbeatActive, pReq->fEnabled);
|
---|
547 | if (pReq->fEnabled)
|
---|
548 | {
|
---|
549 | /*
|
---|
550 | * Activate the heartbeat monitor.
|
---|
551 | */
|
---|
552 | pThis->nsLastHeartbeatTS = PDMDevHlpTimerGetNano(pDevIns, pThis->hFlatlinedTimer);
|
---|
553 | rc = PDMDevHlpTimerSetNano(pDevIns, pThis->hFlatlinedTimer, pThis->cNsHeartbeatTimeout);
|
---|
554 | if (RT_SUCCESS(rc))
|
---|
555 | LogRel(("VMMDev: Heartbeat flatline timer set to trigger after %'RU64 ns\n", pThis->cNsHeartbeatTimeout));
|
---|
556 | else
|
---|
557 | LogRel(("VMMDev: Error starting flatline timer (heartbeat): %Rrc\n", rc));
|
---|
558 | }
|
---|
559 | else
|
---|
560 | {
|
---|
561 | /*
|
---|
562 | * Deactivate the heartbeat monitor.
|
---|
563 | */
|
---|
564 | rc = PDMDevHlpTimerStop(pDevIns, pThis->hFlatlinedTimer);
|
---|
565 | LogRel(("VMMDev: Heartbeat checking timer has been stopped (rc=%Rrc)\n", rc));
|
---|
566 | }
|
---|
567 | }
|
---|
568 | else
|
---|
569 | {
|
---|
570 | LogRel(("VMMDev: vmmDevReqHandler_HeartbeatConfigure: No change (fHeartbeatActive=%RTbool)\n", pThis->fHeartbeatActive));
|
---|
571 | rc = VINF_SUCCESS;
|
---|
572 | }
|
---|
573 |
|
---|
574 | return rc;
|
---|
575 | }
|
---|
576 |
|
---|
577 |
|
---|
578 | /**
|
---|
579 | * Handles VMMDevReq_NtBugCheck.
|
---|
580 | *
|
---|
581 | * @returns VBox status code that the guest should see.
|
---|
582 | * @param pDevIns The device instance.
|
---|
583 | * @param pReqHdr The header of the request to handle.
|
---|
584 | */
|
---|
585 | static int vmmDevReqHandler_NtBugCheck(PPDMDEVINS pDevIns, VMMDevRequestHeader *pReqHdr)
|
---|
586 | {
|
---|
587 | if (pReqHdr->size == sizeof(VMMDevReqNtBugCheck))
|
---|
588 | {
|
---|
589 | VMMDevReqNtBugCheck const *pReq = (VMMDevReqNtBugCheck const *)pReqHdr;
|
---|
590 | DBGFR3ReportBugCheck(PDMDevHlpGetVM(pDevIns), PDMDevHlpGetVMCPU(pDevIns), DBGFEVENT_BSOD_VMMDEV,
|
---|
591 | pReq->uBugCheck, pReq->auParameters[0], pReq->auParameters[1],
|
---|
592 | pReq->auParameters[2], pReq->auParameters[3]);
|
---|
593 | }
|
---|
594 | else if (pReqHdr->size == sizeof(VMMDevRequestHeader))
|
---|
595 | {
|
---|
596 | LogRel(("VMMDev: NT BugCheck w/o data.\n"));
|
---|
597 | DBGFR3ReportBugCheck(PDMDevHlpGetVM(pDevIns), PDMDevHlpGetVMCPU(pDevIns), DBGFEVENT_BSOD_VMMDEV,
|
---|
598 | 0, 0, 0, 0, 0);
|
---|
599 | }
|
---|
600 | else
|
---|
601 | return VERR_INVALID_PARAMETER;
|
---|
602 | return VINF_SUCCESS;
|
---|
603 | }
|
---|
604 |
|
---|
605 |
|
---|
606 | /**
|
---|
607 | * Validates a publisher tag.
|
---|
608 | *
|
---|
609 | * @returns true / false.
|
---|
610 | * @param pszTag Tag to validate.
|
---|
611 | */
|
---|
612 | static bool vmmdevReqIsValidPublisherTag(const char *pszTag)
|
---|
613 | {
|
---|
614 | /* Note! This character set is also found in Config.kmk. */
|
---|
615 | static char const s_szValidChars[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz()[]{}+-.,";
|
---|
616 |
|
---|
617 | while (*pszTag != '\0')
|
---|
618 | {
|
---|
619 | if (!strchr(s_szValidChars, *pszTag))
|
---|
620 | return false;
|
---|
621 | pszTag++;
|
---|
622 | }
|
---|
623 | return true;
|
---|
624 | }
|
---|
625 |
|
---|
626 |
|
---|
627 | /**
|
---|
628 | * Validates a build tag.
|
---|
629 | *
|
---|
630 | * @returns true / false.
|
---|
631 | * @param pszTag Tag to validate.
|
---|
632 | */
|
---|
633 | static bool vmmdevReqIsValidBuildTag(const char *pszTag)
|
---|
634 | {
|
---|
635 | int cchPrefix;
|
---|
636 | if (!strncmp(pszTag, "RC", 2))
|
---|
637 | cchPrefix = 2;
|
---|
638 | else if (!strncmp(pszTag, "BETA", 4))
|
---|
639 | cchPrefix = 4;
|
---|
640 | else if (!strncmp(pszTag, "ALPHA", 5))
|
---|
641 | cchPrefix = 5;
|
---|
642 | else
|
---|
643 | return false;
|
---|
644 |
|
---|
645 | if (pszTag[cchPrefix] == '\0')
|
---|
646 | return true;
|
---|
647 |
|
---|
648 | uint8_t u8;
|
---|
649 | int rc = RTStrToUInt8Full(&pszTag[cchPrefix], 10, &u8);
|
---|
650 | return rc == VINF_SUCCESS;
|
---|
651 | }
|
---|
652 |
|
---|
653 |
|
---|
654 | /**
|
---|
655 | * Handles VMMDevReq_ReportGuestInfo2.
|
---|
656 | *
|
---|
657 | * @returns VBox status code that the guest should see.
|
---|
658 | * @param pDevIns The device instance.
|
---|
659 | * @param pThis The VMMDev shared instance data.
|
---|
660 | * @param pThisCC The VMMDev ring-3 instance data.
|
---|
661 | * @param pReqHdr The header of the request to handle.
|
---|
662 | */
|
---|
663 | static int vmmdevReqHandler_ReportGuestInfo2(PPDMDEVINS pDevIns, PVMMDEV pThis, PVMMDEVCC pThisCC, VMMDevRequestHeader *pReqHdr)
|
---|
664 | {
|
---|
665 | AssertMsgReturn(pReqHdr->size == sizeof(VMMDevReportGuestInfo2), ("%u\n", pReqHdr->size), VERR_INVALID_PARAMETER);
|
---|
666 | VBoxGuestInfo2 const *pInfo2 = &((VMMDevReportGuestInfo2 *)pReqHdr)->guestInfo;
|
---|
667 |
|
---|
668 | LogRel(("VMMDev: Guest Additions information report: Version %d.%d.%d r%d '%.*s'\n",
|
---|
669 | pInfo2->additionsMajor, pInfo2->additionsMinor, pInfo2->additionsBuild,
|
---|
670 | pInfo2->additionsRevision, sizeof(pInfo2->szName), pInfo2->szName));
|
---|
671 |
|
---|
672 | /* The interface was introduced in 3.2 and will definitely not be
|
---|
673 | backported beyond 3.0 (bird). */
|
---|
674 | AssertMsgReturn(pInfo2->additionsMajor >= 3,
|
---|
675 | ("%u.%u.%u\n", pInfo2->additionsMajor, pInfo2->additionsMinor, pInfo2->additionsBuild),
|
---|
676 | VERR_INVALID_PARAMETER);
|
---|
677 |
|
---|
678 | /* The version must fit in a full version compression. */
|
---|
679 | uint32_t uFullVersion = VBOX_FULL_VERSION_MAKE(pInfo2->additionsMajor, pInfo2->additionsMinor, pInfo2->additionsBuild);
|
---|
680 | AssertMsgReturn( VBOX_FULL_VERSION_GET_MAJOR(uFullVersion) == pInfo2->additionsMajor
|
---|
681 | && VBOX_FULL_VERSION_GET_MINOR(uFullVersion) == pInfo2->additionsMinor
|
---|
682 | && VBOX_FULL_VERSION_GET_BUILD(uFullVersion) == pInfo2->additionsBuild,
|
---|
683 | ("%u.%u.%u\n", pInfo2->additionsMajor, pInfo2->additionsMinor, pInfo2->additionsBuild),
|
---|
684 | VERR_OUT_OF_RANGE);
|
---|
685 |
|
---|
686 | /*
|
---|
687 | * Validate the name.
|
---|
688 | * Be less strict towards older additions (< v4.1.50).
|
---|
689 | */
|
---|
690 | AssertCompile(sizeof(pThis->guestInfo2.szName) == sizeof(pInfo2->szName));
|
---|
691 | AssertReturn(RTStrEnd(pInfo2->szName, sizeof(pInfo2->szName)) != NULL, VERR_INVALID_PARAMETER);
|
---|
692 | const char *pszName = pInfo2->szName;
|
---|
693 |
|
---|
694 | /* The version number which shouldn't be there. */
|
---|
695 | char szTmp[sizeof(pInfo2->szName)];
|
---|
696 | size_t cchStart = RTStrPrintf(szTmp, sizeof(szTmp), "%u.%u.%u", pInfo2->additionsMajor, pInfo2->additionsMinor, pInfo2->additionsBuild);
|
---|
697 | AssertMsgReturn(!strncmp(pszName, szTmp, cchStart), ("%s != %s\n", pszName, szTmp), VERR_INVALID_PARAMETER);
|
---|
698 | pszName += cchStart;
|
---|
699 |
|
---|
700 | /* Now we can either have nothing or a build tag or/and a publisher tag. */
|
---|
701 | if (*pszName != '\0')
|
---|
702 | {
|
---|
703 | const char *pszRelaxedName = "";
|
---|
704 | bool const fStrict = pInfo2->additionsMajor > 4
|
---|
705 | || (pInfo2->additionsMajor == 4 && pInfo2->additionsMinor > 1)
|
---|
706 | || (pInfo2->additionsMajor == 4 && pInfo2->additionsMinor == 1 && pInfo2->additionsBuild >= 50);
|
---|
707 | bool fOk = false;
|
---|
708 | if (*pszName == '_')
|
---|
709 | {
|
---|
710 | pszName++;
|
---|
711 | strcpy(szTmp, pszName);
|
---|
712 | char *pszTag2 = strchr(szTmp, '_');
|
---|
713 | if (!pszTag2)
|
---|
714 | {
|
---|
715 | fOk = vmmdevReqIsValidBuildTag(szTmp)
|
---|
716 | || vmmdevReqIsValidPublisherTag(szTmp);
|
---|
717 | }
|
---|
718 | else
|
---|
719 | {
|
---|
720 | *pszTag2++ = '\0';
|
---|
721 | fOk = vmmdevReqIsValidBuildTag(szTmp);
|
---|
722 | if (fOk)
|
---|
723 | {
|
---|
724 | fOk = vmmdevReqIsValidPublisherTag(pszTag2);
|
---|
725 | if (!fOk)
|
---|
726 | pszRelaxedName = szTmp;
|
---|
727 | }
|
---|
728 | }
|
---|
729 | }
|
---|
730 |
|
---|
731 | if (!fOk)
|
---|
732 | {
|
---|
733 | AssertLogRelMsgReturn(!fStrict, ("%s", pszName), VERR_INVALID_PARAMETER);
|
---|
734 |
|
---|
735 | /* non-strict mode, just zap the extra stuff. */
|
---|
736 | LogRel(("VMMDev: ReportGuestInfo2: Ignoring unparsable version name bits: '%s' -> '%s'.\n", pszName, pszRelaxedName));
|
---|
737 | pszName = pszRelaxedName;
|
---|
738 | }
|
---|
739 | }
|
---|
740 |
|
---|
741 | /*
|
---|
742 | * Save the info and tell Main or whoever is listening.
|
---|
743 | */
|
---|
744 | pThis->guestInfo2.uFullVersion = uFullVersion;
|
---|
745 | pThis->guestInfo2.uRevision = pInfo2->additionsRevision;
|
---|
746 | pThis->guestInfo2.fFeatures = pInfo2->additionsFeatures;
|
---|
747 | strcpy(pThis->guestInfo2.szName, pszName);
|
---|
748 |
|
---|
749 | if (pThisCC->pDrv && pThisCC->pDrv->pfnUpdateGuestInfo2)
|
---|
750 | pThisCC->pDrv->pfnUpdateGuestInfo2(pThisCC->pDrv, uFullVersion, pszName, pInfo2->additionsRevision,
|
---|
751 | pInfo2->additionsFeatures);
|
---|
752 |
|
---|
753 | /* Clear our IRQ in case it was high for whatever reason. */
|
---|
754 | PDMDevHlpPCISetIrqNoWait(pDevIns, 0, 0);
|
---|
755 |
|
---|
756 | return VINF_SUCCESS;
|
---|
757 | }
|
---|
758 |
|
---|
759 |
|
---|
760 | /**
|
---|
761 | * Allocates a new facility status entry, initializing it to inactive.
|
---|
762 | *
|
---|
763 | * @returns Pointer to a facility status entry on success, NULL on failure
|
---|
764 | * (table full).
|
---|
765 | * @param pThis The VMMDev shared instance data.
|
---|
766 | * @param enmFacility The facility type code.
|
---|
767 | * @param fFixed This is set when allocating the standard entries
|
---|
768 | * from the constructor.
|
---|
769 | * @param pTimeSpecNow Optionally giving the entry timestamp to use (ctor).
|
---|
770 | */
|
---|
771 | static PVMMDEVFACILITYSTATUSENTRY
|
---|
772 | vmmdevAllocFacilityStatusEntry(PVMMDEV pThis, VBoxGuestFacilityType enmFacility, bool fFixed, PCRTTIMESPEC pTimeSpecNow)
|
---|
773 | {
|
---|
774 | /* If full, expunge one inactive entry. */
|
---|
775 | if (pThis->cFacilityStatuses == RT_ELEMENTS(pThis->aFacilityStatuses))
|
---|
776 | {
|
---|
777 | uint32_t i = pThis->cFacilityStatuses;
|
---|
778 | while (i-- > 0)
|
---|
779 | {
|
---|
780 | if ( pThis->aFacilityStatuses[i].enmStatus == VBoxGuestFacilityStatus_Inactive
|
---|
781 | && !pThis->aFacilityStatuses[i].fFixed)
|
---|
782 | {
|
---|
783 | pThis->cFacilityStatuses--;
|
---|
784 | int cToMove = pThis->cFacilityStatuses - i;
|
---|
785 | if (cToMove)
|
---|
786 | memmove(&pThis->aFacilityStatuses[i], &pThis->aFacilityStatuses[i + 1],
|
---|
787 | cToMove * sizeof(pThis->aFacilityStatuses[i]));
|
---|
788 | RT_ZERO(pThis->aFacilityStatuses[pThis->cFacilityStatuses]);
|
---|
789 | break;
|
---|
790 | }
|
---|
791 | }
|
---|
792 |
|
---|
793 | if (pThis->cFacilityStatuses == RT_ELEMENTS(pThis->aFacilityStatuses))
|
---|
794 | return NULL;
|
---|
795 | }
|
---|
796 |
|
---|
797 | /* Find location in array (it's sorted). */
|
---|
798 | uint32_t i = pThis->cFacilityStatuses;
|
---|
799 | while (i-- > 0)
|
---|
800 | if ((uint32_t)pThis->aFacilityStatuses[i].enmFacility < (uint32_t)enmFacility)
|
---|
801 | break;
|
---|
802 | i++;
|
---|
803 |
|
---|
804 | /* Move. */
|
---|
805 | int cToMove = pThis->cFacilityStatuses - i;
|
---|
806 | if (cToMove > 0)
|
---|
807 | memmove(&pThis->aFacilityStatuses[i + 1], &pThis->aFacilityStatuses[i],
|
---|
808 | cToMove * sizeof(pThis->aFacilityStatuses[i]));
|
---|
809 | pThis->cFacilityStatuses++;
|
---|
810 |
|
---|
811 | /* Initialize. */
|
---|
812 | pThis->aFacilityStatuses[i].enmFacility = enmFacility;
|
---|
813 | pThis->aFacilityStatuses[i].enmStatus = VBoxGuestFacilityStatus_Inactive;
|
---|
814 | pThis->aFacilityStatuses[i].fFixed = fFixed;
|
---|
815 | pThis->aFacilityStatuses[i].afPadding[0] = 0;
|
---|
816 | pThis->aFacilityStatuses[i].afPadding[1] = 0;
|
---|
817 | pThis->aFacilityStatuses[i].afPadding[2] = 0;
|
---|
818 | pThis->aFacilityStatuses[i].fFlags = 0;
|
---|
819 | if (pTimeSpecNow)
|
---|
820 | pThis->aFacilityStatuses[i].TimeSpecTS = *pTimeSpecNow;
|
---|
821 | else
|
---|
822 | RTTimeSpecSetNano(&pThis->aFacilityStatuses[i].TimeSpecTS, 0);
|
---|
823 |
|
---|
824 | return &pThis->aFacilityStatuses[i];
|
---|
825 | }
|
---|
826 |
|
---|
827 |
|
---|
828 | /**
|
---|
829 | * Gets a facility status entry, allocating a new one if not already present.
|
---|
830 | *
|
---|
831 | * @returns Pointer to a facility status entry on success, NULL on failure
|
---|
832 | * (table full).
|
---|
833 | * @param pThis The VMMDev shared instance data.
|
---|
834 | * @param enmFacility The facility type code.
|
---|
835 | */
|
---|
836 | static PVMMDEVFACILITYSTATUSENTRY vmmdevGetFacilityStatusEntry(PVMMDEV pThis, VBoxGuestFacilityType enmFacility)
|
---|
837 | {
|
---|
838 | /** @todo change to binary search. */
|
---|
839 | uint32_t i = pThis->cFacilityStatuses;
|
---|
840 | while (i-- > 0)
|
---|
841 | {
|
---|
842 | if (pThis->aFacilityStatuses[i].enmFacility == enmFacility)
|
---|
843 | return &pThis->aFacilityStatuses[i];
|
---|
844 | if ((uint32_t)pThis->aFacilityStatuses[i].enmFacility < (uint32_t)enmFacility)
|
---|
845 | break;
|
---|
846 | }
|
---|
847 | return vmmdevAllocFacilityStatusEntry(pThis, enmFacility, false /*fFixed*/, NULL);
|
---|
848 | }
|
---|
849 |
|
---|
850 |
|
---|
851 | /**
|
---|
852 | * Handles VMMDevReq_ReportGuestStatus.
|
---|
853 | *
|
---|
854 | * @returns VBox status code that the guest should see.
|
---|
855 | * @param pThis The VMMDev shared instance data.
|
---|
856 | * @param pThisCC The VMMDev ring-3 instance data.
|
---|
857 | * @param pReqHdr The header of the request to handle.
|
---|
858 | */
|
---|
859 | static int vmmdevReqHandler_ReportGuestStatus(PVMMDEV pThis, PVMMDEVCC pThisCC, VMMDevRequestHeader *pReqHdr)
|
---|
860 | {
|
---|
861 | /*
|
---|
862 | * Validate input.
|
---|
863 | */
|
---|
864 | AssertMsgReturn(pReqHdr->size == sizeof(VMMDevReportGuestStatus), ("%u\n", pReqHdr->size), VERR_INVALID_PARAMETER);
|
---|
865 | VBoxGuestStatus *pStatus = &((VMMDevReportGuestStatus *)pReqHdr)->guestStatus;
|
---|
866 | AssertMsgReturn( pStatus->facility > VBoxGuestFacilityType_Unknown
|
---|
867 | && pStatus->facility <= VBoxGuestFacilityType_All,
|
---|
868 | ("%d\n", pStatus->facility),
|
---|
869 | VERR_INVALID_PARAMETER);
|
---|
870 | AssertMsgReturn(pStatus->status == (VBoxGuestFacilityStatus)(uint16_t)pStatus->status,
|
---|
871 | ("%#x (%u)\n", pStatus->status, pStatus->status),
|
---|
872 | VERR_OUT_OF_RANGE);
|
---|
873 |
|
---|
874 | /*
|
---|
875 | * Do the update.
|
---|
876 | */
|
---|
877 | RTTIMESPEC Now;
|
---|
878 | RTTimeNow(&Now);
|
---|
879 | if (pStatus->facility == VBoxGuestFacilityType_All)
|
---|
880 | {
|
---|
881 | uint32_t i = pThis->cFacilityStatuses;
|
---|
882 | while (i-- > 0)
|
---|
883 | {
|
---|
884 | pThis->aFacilityStatuses[i].TimeSpecTS = Now;
|
---|
885 | pThis->aFacilityStatuses[i].enmStatus = pStatus->status;
|
---|
886 | pThis->aFacilityStatuses[i].fFlags = pStatus->flags;
|
---|
887 | }
|
---|
888 | }
|
---|
889 | else
|
---|
890 | {
|
---|
891 | PVMMDEVFACILITYSTATUSENTRY pEntry = vmmdevGetFacilityStatusEntry(pThis, pStatus->facility);
|
---|
892 | if (!pEntry)
|
---|
893 | {
|
---|
894 | LogRelMax(10, ("VMMDev: Facility table is full - facility=%u status=%u\n", pStatus->facility, pStatus->status));
|
---|
895 | return VERR_OUT_OF_RESOURCES;
|
---|
896 | }
|
---|
897 |
|
---|
898 | pEntry->TimeSpecTS = Now;
|
---|
899 | pEntry->enmStatus = pStatus->status;
|
---|
900 | pEntry->fFlags = pStatus->flags;
|
---|
901 | }
|
---|
902 |
|
---|
903 | if (pThisCC->pDrv && pThisCC->pDrv->pfnUpdateGuestStatus)
|
---|
904 | pThisCC->pDrv->pfnUpdateGuestStatus(pThisCC->pDrv, pStatus->facility, pStatus->status, pStatus->flags, &Now);
|
---|
905 |
|
---|
906 | return VINF_SUCCESS;
|
---|
907 | }
|
---|
908 |
|
---|
909 |
|
---|
910 | /**
|
---|
911 | * Handles VMMDevReq_ReportGuestUserState.
|
---|
912 | *
|
---|
913 | * @returns VBox status code that the guest should see.
|
---|
914 | * @param pThisCC The VMMDev ring-3 instance data.
|
---|
915 | * @param pReqHdr The header of the request to handle.
|
---|
916 | */
|
---|
917 | static int vmmdevReqHandler_ReportGuestUserState(PVMMDEVCC pThisCC, VMMDevRequestHeader *pReqHdr)
|
---|
918 | {
|
---|
919 | /*
|
---|
920 | * Validate input.
|
---|
921 | */
|
---|
922 | VMMDevReportGuestUserState *pReq = (VMMDevReportGuestUserState *)pReqHdr;
|
---|
923 | AssertMsgReturn(pReq->header.size >= sizeof(*pReq), ("%u\n", pReqHdr->size), VERR_INVALID_PARAMETER);
|
---|
924 |
|
---|
925 | if ( pThisCC->pDrv
|
---|
926 | && pThisCC->pDrv->pfnUpdateGuestUserState)
|
---|
927 | {
|
---|
928 | /* Play safe. */
|
---|
929 | AssertReturn(pReq->header.size <= _2K, VERR_TOO_MUCH_DATA);
|
---|
930 | AssertReturn(pReq->status.cbUser <= 256, VERR_TOO_MUCH_DATA);
|
---|
931 | AssertReturn(pReq->status.cbDomain <= 256, VERR_TOO_MUCH_DATA);
|
---|
932 | AssertReturn(pReq->status.cbDetails <= _1K, VERR_TOO_MUCH_DATA);
|
---|
933 |
|
---|
934 | /* pbDynamic marks the beginning of the struct's dynamically
|
---|
935 | * allocated data area. */
|
---|
936 | uint8_t *pbDynamic = (uint8_t *)&pReq->status.szUser;
|
---|
937 | uint32_t cbLeft = pReqHdr->size - RT_UOFFSETOF(VMMDevReportGuestUserState, status.szUser);
|
---|
938 |
|
---|
939 | /* The user. */
|
---|
940 | AssertReturn(pReq->status.cbUser > 0, VERR_INVALID_PARAMETER); /* User name is required. */
|
---|
941 | AssertReturn(pReq->status.cbUser <= cbLeft, VERR_INVALID_PARAMETER);
|
---|
942 | const char *pszUser = (const char *)pbDynamic;
|
---|
943 | AssertReturn(RTStrEnd(pszUser, pReq->status.cbUser), VERR_INVALID_PARAMETER);
|
---|
944 | int rc = RTStrValidateEncoding(pszUser);
|
---|
945 | AssertRCReturn(rc, rc);
|
---|
946 |
|
---|
947 | /* Advance to the next field. */
|
---|
948 | pbDynamic += pReq->status.cbUser;
|
---|
949 | cbLeft -= pReq->status.cbUser;
|
---|
950 |
|
---|
951 | /* pszDomain can be NULL. */
|
---|
952 | AssertReturn(pReq->status.cbDomain <= cbLeft, VERR_INVALID_PARAMETER);
|
---|
953 | const char *pszDomain = NULL;
|
---|
954 | if (pReq->status.cbDomain)
|
---|
955 | {
|
---|
956 | pszDomain = (const char *)pbDynamic;
|
---|
957 | AssertReturn(RTStrEnd(pszDomain, pReq->status.cbDomain), VERR_INVALID_PARAMETER);
|
---|
958 | rc = RTStrValidateEncoding(pszDomain);
|
---|
959 | AssertRCReturn(rc, rc);
|
---|
960 |
|
---|
961 | /* Advance to the next field. */
|
---|
962 | pbDynamic += pReq->status.cbDomain;
|
---|
963 | cbLeft -= pReq->status.cbDomain;
|
---|
964 | }
|
---|
965 |
|
---|
966 | /* pbDetails can be NULL. */
|
---|
967 | const uint8_t *pbDetails = NULL;
|
---|
968 | AssertReturn(pReq->status.cbDetails <= cbLeft, VERR_INVALID_PARAMETER);
|
---|
969 | if (pReq->status.cbDetails > 0)
|
---|
970 | pbDetails = pbDynamic;
|
---|
971 |
|
---|
972 | pThisCC->pDrv->pfnUpdateGuestUserState(pThisCC->pDrv, pszUser, pszDomain, (uint32_t)pReq->status.state,
|
---|
973 | pbDetails, pReq->status.cbDetails);
|
---|
974 | }
|
---|
975 |
|
---|
976 | return VINF_SUCCESS;
|
---|
977 | }
|
---|
978 |
|
---|
979 |
|
---|
980 | /**
|
---|
981 | * Handles VMMDevReq_ReportGuestCapabilities.
|
---|
982 | *
|
---|
983 | * @returns VBox status code that the guest should see.
|
---|
984 | * @param pThis The VMMDev shared instance data.
|
---|
985 | * @param pThisCC The VMMDev ring-3 instance data.
|
---|
986 | * @param pReqHdr The header of the request to handle.
|
---|
987 | */
|
---|
988 | static int vmmdevReqHandler_ReportGuestCapabilities(PVMMDEV pThis, PVMMDEVCC pThisCC, VMMDevRequestHeader *pReqHdr)
|
---|
989 | {
|
---|
990 | VMMDevReqGuestCapabilities *pReq = (VMMDevReqGuestCapabilities *)pReqHdr;
|
---|
991 | AssertMsgReturn(pReq->header.size == sizeof(*pReq), ("%u\n", pReq->header.size), VERR_INVALID_PARAMETER);
|
---|
992 |
|
---|
993 | /* Enable VMMDEV_GUEST_SUPPORTS_GRAPHICS automatically for guests using the old
|
---|
994 | * request to report their capabilities.
|
---|
995 | */
|
---|
996 | const uint32_t fu32Caps = pReq->caps | VMMDEV_GUEST_SUPPORTS_GRAPHICS;
|
---|
997 |
|
---|
998 | if (pThis->fGuestCaps != fu32Caps)
|
---|
999 | {
|
---|
1000 | /* make a copy of supplied information */
|
---|
1001 | pThis->fGuestCaps = fu32Caps;
|
---|
1002 |
|
---|
1003 | LogRel(("VMMDev: Guest Additions capability report (legacy): (0x%x) seamless: %s, hostWindowMapping: %s, graphics: yes\n",
|
---|
1004 | fu32Caps,
|
---|
1005 | fu32Caps & VMMDEV_GUEST_SUPPORTS_SEAMLESS ? "yes" : "no",
|
---|
1006 | fu32Caps & VMMDEV_GUEST_SUPPORTS_GUEST_HOST_WINDOW_MAPPING ? "yes" : "no"));
|
---|
1007 |
|
---|
1008 | if (pThisCC->pDrv && pThisCC->pDrv->pfnUpdateGuestCapabilities)
|
---|
1009 | pThisCC->pDrv->pfnUpdateGuestCapabilities(pThisCC->pDrv, fu32Caps);
|
---|
1010 | }
|
---|
1011 | return VINF_SUCCESS;
|
---|
1012 | }
|
---|
1013 |
|
---|
1014 |
|
---|
1015 | /**
|
---|
1016 | * Handles VMMDevReq_SetGuestCapabilities.
|
---|
1017 | *
|
---|
1018 | * @returns VBox status code that the guest should see.
|
---|
1019 | * @param pThis The VMMDev shared instance data.
|
---|
1020 | * @param pThisCC The VMMDev ring-3 instance data.
|
---|
1021 | * @param pReqHdr The header of the request to handle.
|
---|
1022 | */
|
---|
1023 | static int vmmdevReqHandler_SetGuestCapabilities(PVMMDEV pThis, PVMMDEVCC pThisCC, VMMDevRequestHeader *pReqHdr)
|
---|
1024 | {
|
---|
1025 | VMMDevReqGuestCapabilities2 *pReq = (VMMDevReqGuestCapabilities2 *)pReqHdr;
|
---|
1026 | AssertMsgReturn(pReq->header.size == sizeof(*pReq), ("%u\n", pReq->header.size), VERR_INVALID_PARAMETER);
|
---|
1027 |
|
---|
1028 | uint32_t fu32Caps = pThis->fGuestCaps;
|
---|
1029 | fu32Caps |= pReq->u32OrMask;
|
---|
1030 | fu32Caps &= ~pReq->u32NotMask;
|
---|
1031 |
|
---|
1032 | LogRel(("VMMDev: Guest Additions capability report: (%#x -> %#x) seamless: %s, hostWindowMapping: %s, graphics: %s\n",
|
---|
1033 | pThis->fGuestCaps, fu32Caps,
|
---|
1034 | fu32Caps & VMMDEV_GUEST_SUPPORTS_SEAMLESS ? "yes" : "no",
|
---|
1035 | fu32Caps & VMMDEV_GUEST_SUPPORTS_GUEST_HOST_WINDOW_MAPPING ? "yes" : "no",
|
---|
1036 | fu32Caps & VMMDEV_GUEST_SUPPORTS_GRAPHICS ? "yes" : "no"));
|
---|
1037 |
|
---|
1038 | pThis->fGuestCaps = fu32Caps;
|
---|
1039 |
|
---|
1040 | if (pThisCC->pDrv && pThisCC->pDrv->pfnUpdateGuestCapabilities)
|
---|
1041 | pThisCC->pDrv->pfnUpdateGuestCapabilities(pThisCC->pDrv, fu32Caps);
|
---|
1042 |
|
---|
1043 | return VINF_SUCCESS;
|
---|
1044 | }
|
---|
1045 |
|
---|
1046 |
|
---|
1047 | /**
|
---|
1048 | * Handles VMMDevReq_GetMouseStatus.
|
---|
1049 | *
|
---|
1050 | * @returns VBox status code that the guest should see.
|
---|
1051 | * @param pThis The VMMDev shared instance data.
|
---|
1052 | * @param pReqHdr The header of the request to handle.
|
---|
1053 | */
|
---|
1054 | static int vmmdevReqHandler_GetMouseStatus(PVMMDEV pThis, VMMDevRequestHeader *pReqHdr)
|
---|
1055 | {
|
---|
1056 | VMMDevReqMouseStatus *pReq = (VMMDevReqMouseStatus *)pReqHdr;
|
---|
1057 | AssertMsgReturn(pReq->header.size == sizeof(*pReq), ("%u\n", pReq->header.size), VERR_INVALID_PARAMETER);
|
---|
1058 |
|
---|
1059 | pReq->mouseFeatures = pThis->fMouseCapabilities
|
---|
1060 | & VMMDEV_MOUSE_MASK;
|
---|
1061 | pReq->pointerXPos = pThis->xMouseAbs;
|
---|
1062 | pReq->pointerYPos = pThis->yMouseAbs;
|
---|
1063 | LogRel2(("VMMDev: vmmdevReqHandler_GetMouseStatus: mouseFeatures=%#x, xAbs=%d, yAbs=%d\n",
|
---|
1064 | pReq->mouseFeatures, pReq->pointerXPos, pReq->pointerYPos));
|
---|
1065 | return VINF_SUCCESS;
|
---|
1066 | }
|
---|
1067 |
|
---|
1068 |
|
---|
1069 | /**
|
---|
1070 | * Handles VMMDevReq_SetMouseStatus.
|
---|
1071 | *
|
---|
1072 | * @returns VBox status code that the guest should see.
|
---|
1073 | * @param pThis The VMMDev shared instance data.
|
---|
1074 | * @param pThisCC The VMMDev ring-3 instance data.
|
---|
1075 | * @param pReqHdr The header of the request to handle.
|
---|
1076 | */
|
---|
1077 | static int vmmdevReqHandler_SetMouseStatus(PVMMDEV pThis, PVMMDEVCC pThisCC, VMMDevRequestHeader *pReqHdr)
|
---|
1078 | {
|
---|
1079 | VMMDevReqMouseStatus *pReq = (VMMDevReqMouseStatus *)pReqHdr;
|
---|
1080 | AssertMsgReturn(pReq->header.size == sizeof(*pReq), ("%u\n", pReq->header.size), VERR_INVALID_PARAMETER);
|
---|
1081 |
|
---|
1082 | LogRelFlow(("VMMDev: vmmdevReqHandler_SetMouseStatus: mouseFeatures=%#x\n", pReq->mouseFeatures));
|
---|
1083 |
|
---|
1084 | bool fNotify = false;
|
---|
1085 | if ( (pReq->mouseFeatures & VMMDEV_MOUSE_NOTIFY_HOST_MASK)
|
---|
1086 | != ( pThis->fMouseCapabilities
|
---|
1087 | & VMMDEV_MOUSE_NOTIFY_HOST_MASK))
|
---|
1088 | fNotify = true;
|
---|
1089 |
|
---|
1090 | pThis->fMouseCapabilities &= ~VMMDEV_MOUSE_GUEST_MASK;
|
---|
1091 | pThis->fMouseCapabilities |= (pReq->mouseFeatures & VMMDEV_MOUSE_GUEST_MASK);
|
---|
1092 |
|
---|
1093 | LogRelFlow(("VMMDev: vmmdevReqHandler_SetMouseStatus: New host capabilities: %#x\n", pThis->fMouseCapabilities));
|
---|
1094 |
|
---|
1095 | /*
|
---|
1096 | * Notify connector if something changed.
|
---|
1097 | */
|
---|
1098 | if (fNotify)
|
---|
1099 | {
|
---|
1100 | LogRelFlow(("VMMDev: vmmdevReqHandler_SetMouseStatus: Notifying connector\n"));
|
---|
1101 | pThisCC->pDrv->pfnUpdateMouseCapabilities(pThisCC->pDrv, pThis->fMouseCapabilities);
|
---|
1102 | }
|
---|
1103 |
|
---|
1104 | return VINF_SUCCESS;
|
---|
1105 | }
|
---|
1106 |
|
---|
1107 | static int vmmdevVerifyPointerShape(VMMDevReqMousePointer *pReq)
|
---|
1108 | {
|
---|
1109 | /* Should be enough for most mouse pointers. */
|
---|
1110 | if (pReq->width > 8192 || pReq->height > 8192)
|
---|
1111 | return VERR_INVALID_PARAMETER;
|
---|
1112 |
|
---|
1113 | uint32_t cbShape = (pReq->width + 7) / 8 * pReq->height; /* size of the AND mask */
|
---|
1114 | cbShape = ((cbShape + 3) & ~3) + pReq->width * 4 * pReq->height; /* + gap + size of the XOR mask */
|
---|
1115 | if (RT_UOFFSETOF(VMMDevReqMousePointer, pointerData) + cbShape > pReq->header.size)
|
---|
1116 | return VERR_INVALID_PARAMETER;
|
---|
1117 |
|
---|
1118 | return VINF_SUCCESS;
|
---|
1119 | }
|
---|
1120 |
|
---|
1121 | /**
|
---|
1122 | * Handles VMMDevReq_SetPointerShape.
|
---|
1123 | *
|
---|
1124 | * @returns VBox status code that the guest should see.
|
---|
1125 | * @param pThis The VMMDev shared instance data.
|
---|
1126 | * @param pThisCC The VMMDev ring-3 instance data.
|
---|
1127 | * @param pReqHdr The header of the request to handle.
|
---|
1128 | */
|
---|
1129 | static int vmmdevReqHandler_SetPointerShape(PVMMDEV pThis, PVMMDEVCC pThisCC, VMMDevRequestHeader *pReqHdr)
|
---|
1130 | {
|
---|
1131 | VMMDevReqMousePointer *pReq = (VMMDevReqMousePointer *)pReqHdr;
|
---|
1132 | if (pReq->header.size < sizeof(*pReq))
|
---|
1133 | {
|
---|
1134 | AssertMsg(pReq->header.size == 0x10028 && pReq->header.version == 10000, /* don't complain about legacy!!! */
|
---|
1135 | ("VMMDev mouse shape structure has invalid size %d (%#x) version=%d!\n",
|
---|
1136 | pReq->header.size, pReq->header.size, pReq->header.version));
|
---|
1137 | return VERR_INVALID_PARAMETER;
|
---|
1138 | }
|
---|
1139 |
|
---|
1140 | bool fVisible = RT_BOOL(pReq->fFlags & VBOX_MOUSE_POINTER_VISIBLE);
|
---|
1141 | bool fAlpha = RT_BOOL(pReq->fFlags & VBOX_MOUSE_POINTER_ALPHA);
|
---|
1142 | bool fShape = RT_BOOL(pReq->fFlags & VBOX_MOUSE_POINTER_SHAPE);
|
---|
1143 |
|
---|
1144 | Log(("VMMDevReq_SetPointerShape: visible: %d, alpha: %d, shape = %d, width: %d, height: %d\n",
|
---|
1145 | fVisible, fAlpha, fShape, pReq->width, pReq->height));
|
---|
1146 |
|
---|
1147 | if (pReq->header.size == sizeof(VMMDevReqMousePointer))
|
---|
1148 | {
|
---|
1149 | /* The guest did not provide the shape actually. */
|
---|
1150 | fShape = false;
|
---|
1151 | }
|
---|
1152 |
|
---|
1153 | /* forward call to driver */
|
---|
1154 | if (fShape)
|
---|
1155 | {
|
---|
1156 | int rc = vmmdevVerifyPointerShape(pReq);
|
---|
1157 | if (RT_FAILURE(rc))
|
---|
1158 | return rc;
|
---|
1159 |
|
---|
1160 | pThisCC->pDrv->pfnUpdatePointerShape(pThisCC->pDrv,
|
---|
1161 | fVisible,
|
---|
1162 | fAlpha,
|
---|
1163 | pReq->xHot, pReq->yHot,
|
---|
1164 | pReq->width, pReq->height,
|
---|
1165 | pReq->pointerData);
|
---|
1166 | }
|
---|
1167 | else
|
---|
1168 | {
|
---|
1169 | pThisCC->pDrv->pfnUpdatePointerShape(pThisCC->pDrv,
|
---|
1170 | fVisible,
|
---|
1171 | 0,
|
---|
1172 | 0, 0,
|
---|
1173 | 0, 0,
|
---|
1174 | NULL);
|
---|
1175 | }
|
---|
1176 |
|
---|
1177 | pThis->fHostCursorRequested = fVisible;
|
---|
1178 | return VINF_SUCCESS;
|
---|
1179 | }
|
---|
1180 |
|
---|
1181 |
|
---|
1182 | /**
|
---|
1183 | * Handles VMMDevReq_GetHostTime.
|
---|
1184 | *
|
---|
1185 | * @returns VBox status code that the guest should see.
|
---|
1186 | * @param pDevIns The device instance.
|
---|
1187 | * @param pThis The VMMDev shared instance data.
|
---|
1188 | * @param pReqHdr The header of the request to handle.
|
---|
1189 | */
|
---|
1190 | static int vmmdevReqHandler_GetHostTime(PPDMDEVINS pDevIns, PVMMDEV pThis, VMMDevRequestHeader *pReqHdr)
|
---|
1191 | {
|
---|
1192 | VMMDevReqHostTime *pReq = (VMMDevReqHostTime *)pReqHdr;
|
---|
1193 | AssertMsgReturn(pReq->header.size == sizeof(*pReq), ("%u\n", pReq->header.size), VERR_INVALID_PARAMETER);
|
---|
1194 |
|
---|
1195 | if (RT_LIKELY(!pThis->fGetHostTimeDisabled))
|
---|
1196 | {
|
---|
1197 | RTTIMESPEC now;
|
---|
1198 | pReq->time = RTTimeSpecGetMilli(PDMDevHlpTMUtcNow(pDevIns, &now));
|
---|
1199 | return VINF_SUCCESS;
|
---|
1200 | }
|
---|
1201 | return VERR_NOT_SUPPORTED;
|
---|
1202 | }
|
---|
1203 |
|
---|
1204 |
|
---|
1205 | /**
|
---|
1206 | * Handles VMMDevReq_GetHypervisorInfo.
|
---|
1207 | *
|
---|
1208 | * @returns VBox status code that the guest should see.
|
---|
1209 | * @param pDevIns The device instance.
|
---|
1210 | * @param pReqHdr The header of the request to handle.
|
---|
1211 | */
|
---|
1212 | static int vmmdevReqHandler_GetHypervisorInfo(PPDMDEVINS pDevIns, VMMDevRequestHeader *pReqHdr)
|
---|
1213 | {
|
---|
1214 | VMMDevReqHypervisorInfo *pReq = (VMMDevReqHypervisorInfo *)pReqHdr;
|
---|
1215 | AssertMsgReturn(pReq->header.size == sizeof(*pReq), ("%u\n", pReq->header.size), VERR_INVALID_PARAMETER);
|
---|
1216 |
|
---|
1217 | return PGMR3MappingsSize(PDMDevHlpGetVM(pDevIns), &pReq->hypervisorSize);
|
---|
1218 | }
|
---|
1219 |
|
---|
1220 |
|
---|
1221 | /**
|
---|
1222 | * Handles VMMDevReq_SetHypervisorInfo.
|
---|
1223 | *
|
---|
1224 | * @returns VBox status code that the guest should see.
|
---|
1225 | * @param pDevIns The device instance.
|
---|
1226 | * @param pThis The VMMDev shared instance data.
|
---|
1227 | * @param pReqHdr The header of the request to handle.
|
---|
1228 | */
|
---|
1229 | static int vmmdevReqHandler_SetHypervisorInfo(PPDMDEVINS pDevIns, VMMDevRequestHeader *pReqHdr)
|
---|
1230 | {
|
---|
1231 | VMMDevReqHypervisorInfo *pReq = (VMMDevReqHypervisorInfo *)pReqHdr;
|
---|
1232 | AssertMsgReturn(pReq->header.size == sizeof(*pReq), ("%u\n", pReq->header.size), VERR_INVALID_PARAMETER);
|
---|
1233 |
|
---|
1234 | int rc;
|
---|
1235 | PVM pVM = PDMDevHlpGetVM(pDevIns);
|
---|
1236 | if (pReq->hypervisorStart == 0)
|
---|
1237 | rc = PGMR3MappingsUnfix(pVM);
|
---|
1238 | else
|
---|
1239 | {
|
---|
1240 | /* only if the client has queried the size before! */
|
---|
1241 | uint32_t cbMappings;
|
---|
1242 | rc = PGMR3MappingsSize(pVM, &cbMappings);
|
---|
1243 | if (RT_SUCCESS(rc) && pReq->hypervisorSize == cbMappings)
|
---|
1244 | {
|
---|
1245 | /* new reservation */
|
---|
1246 | rc = PGMR3MappingsFix(pVM, pReq->hypervisorStart, pReq->hypervisorSize);
|
---|
1247 | LogRel(("VMMDev: Guest reported fixed hypervisor window at 0%010x LB %#x (rc=%Rrc)\n",
|
---|
1248 | pReq->hypervisorStart, pReq->hypervisorSize, rc));
|
---|
1249 | }
|
---|
1250 | else if (RT_FAILURE(rc))
|
---|
1251 | rc = VERR_TRY_AGAIN;
|
---|
1252 | }
|
---|
1253 | return rc;
|
---|
1254 | }
|
---|
1255 |
|
---|
1256 |
|
---|
1257 | /**
|
---|
1258 | * Handles VMMDevReq_RegisterPatchMemory.
|
---|
1259 | *
|
---|
1260 | * @returns VBox status code that the guest should see.
|
---|
1261 | * @param pDevIns The device instance.
|
---|
1262 | * @param pReqHdr The header of the request to handle.
|
---|
1263 | */
|
---|
1264 | static int vmmdevReqHandler_RegisterPatchMemory(PPDMDEVINS pDevIns, VMMDevRequestHeader *pReqHdr)
|
---|
1265 | {
|
---|
1266 | VMMDevReqPatchMemory *pReq = (VMMDevReqPatchMemory *)pReqHdr;
|
---|
1267 | AssertMsgReturn(pReq->header.size == sizeof(*pReq), ("%u\n", pReq->header.size), VERR_INVALID_PARAMETER);
|
---|
1268 |
|
---|
1269 | return VMMR3RegisterPatchMemory(PDMDevHlpGetVM(pDevIns), pReq->pPatchMem, pReq->cbPatchMem);
|
---|
1270 | }
|
---|
1271 |
|
---|
1272 |
|
---|
1273 | /**
|
---|
1274 | * Handles VMMDevReq_DeregisterPatchMemory.
|
---|
1275 | *
|
---|
1276 | * @returns VBox status code that the guest should see.
|
---|
1277 | * @param pDevIns The device instance.
|
---|
1278 | * @param pReqHdr The header of the request to handle.
|
---|
1279 | */
|
---|
1280 | static int vmmdevReqHandler_DeregisterPatchMemory(PPDMDEVINS pDevIns, VMMDevRequestHeader *pReqHdr)
|
---|
1281 | {
|
---|
1282 | VMMDevReqPatchMemory *pReq = (VMMDevReqPatchMemory *)pReqHdr;
|
---|
1283 | AssertMsgReturn(pReq->header.size == sizeof(*pReq), ("%u\n", pReq->header.size), VERR_INVALID_PARAMETER);
|
---|
1284 |
|
---|
1285 | return VMMR3DeregisterPatchMemory(PDMDevHlpGetVM(pDevIns), pReq->pPatchMem, pReq->cbPatchMem);
|
---|
1286 | }
|
---|
1287 |
|
---|
1288 |
|
---|
1289 | /**
|
---|
1290 | * Handles VMMDevReq_SetPowerStatus.
|
---|
1291 | *
|
---|
1292 | * @returns VBox status code that the guest should see.
|
---|
1293 | * @param pDevIns The device instance.
|
---|
1294 | * @param pThis The VMMDev shared instance data.
|
---|
1295 | * @param pReqHdr The header of the request to handle.
|
---|
1296 | */
|
---|
1297 | static int vmmdevReqHandler_SetPowerStatus(PPDMDEVINS pDevIns, PVMMDEV pThis, VMMDevRequestHeader *pReqHdr)
|
---|
1298 | {
|
---|
1299 | VMMDevPowerStateRequest *pReq = (VMMDevPowerStateRequest *)pReqHdr;
|
---|
1300 | AssertMsgReturn(pReq->header.size == sizeof(*pReq), ("%u\n", pReq->header.size), VERR_INVALID_PARAMETER);
|
---|
1301 |
|
---|
1302 | switch (pReq->powerState)
|
---|
1303 | {
|
---|
1304 | case VMMDevPowerState_Pause:
|
---|
1305 | {
|
---|
1306 | LogRel(("VMMDev: Guest requests the VM to be suspended (paused)\n"));
|
---|
1307 | return PDMDevHlpVMSuspend(pDevIns);
|
---|
1308 | }
|
---|
1309 |
|
---|
1310 | case VMMDevPowerState_PowerOff:
|
---|
1311 | {
|
---|
1312 | LogRel(("VMMDev: Guest requests the VM to be turned off\n"));
|
---|
1313 | return PDMDevHlpVMPowerOff(pDevIns);
|
---|
1314 | }
|
---|
1315 |
|
---|
1316 | case VMMDevPowerState_SaveState:
|
---|
1317 | {
|
---|
1318 | if (pThis->fAllowGuestToSaveState)
|
---|
1319 | {
|
---|
1320 | LogRel(("VMMDev: Guest requests the VM to be saved and powered off\n"));
|
---|
1321 | return PDMDevHlpVMSuspendSaveAndPowerOff(pDevIns);
|
---|
1322 | }
|
---|
1323 | LogRel(("VMMDev: Guest requests the VM to be saved and powered off, declined\n"));
|
---|
1324 | return VERR_ACCESS_DENIED;
|
---|
1325 | }
|
---|
1326 |
|
---|
1327 | default:
|
---|
1328 | AssertMsgFailed(("VMMDev: Invalid power state request: %d\n", pReq->powerState));
|
---|
1329 | return VERR_INVALID_PARAMETER;
|
---|
1330 | }
|
---|
1331 | }
|
---|
1332 |
|
---|
1333 |
|
---|
1334 | /**
|
---|
1335 | * Handles VMMDevReq_GetDisplayChangeRequest
|
---|
1336 | *
|
---|
1337 | * @returns VBox status code that the guest should see.
|
---|
1338 | * @param pThis The VMMDev shared instance data.
|
---|
1339 | * @param pReqHdr The header of the request to handle.
|
---|
1340 | * @remarks Deprecated.
|
---|
1341 | */
|
---|
1342 | static int vmmdevReqHandler_GetDisplayChangeRequest(PVMMDEV pThis, VMMDevRequestHeader *pReqHdr)
|
---|
1343 | {
|
---|
1344 | VMMDevDisplayChangeRequest *pReq = (VMMDevDisplayChangeRequest *)pReqHdr;
|
---|
1345 | AssertMsgReturn(pReq->header.size == sizeof(*pReq), ("%u\n", pReq->header.size), VERR_INVALID_PARAMETER);
|
---|
1346 |
|
---|
1347 | DISPLAYCHANGEREQUEST *pDispRequest = &pThis->displayChangeData.aRequests[0];
|
---|
1348 |
|
---|
1349 | if (pReq->eventAck == VMMDEV_EVENT_DISPLAY_CHANGE_REQUEST)
|
---|
1350 | {
|
---|
1351 | /* Current request has been read at least once. */
|
---|
1352 | pDispRequest->fPending = false;
|
---|
1353 |
|
---|
1354 | /* Remember which resolution the client has queried, subsequent reads
|
---|
1355 | * will return the same values. */
|
---|
1356 | pDispRequest->lastReadDisplayChangeRequest = pDispRequest->displayChangeRequest;
|
---|
1357 | pThis->displayChangeData.fGuestSentChangeEventAck = true;
|
---|
1358 | }
|
---|
1359 |
|
---|
1360 | /* If not a response to a VMMDEV_EVENT_DISPLAY_CHANGE_REQUEST, just
|
---|
1361 | * read the last valid video mode hint. This happens when the guest X server
|
---|
1362 | * determines the initial mode. */
|
---|
1363 | VMMDevDisplayDef const *pDisplayDef = pThis->displayChangeData.fGuestSentChangeEventAck ?
|
---|
1364 | &pDispRequest->lastReadDisplayChangeRequest :
|
---|
1365 | &pDispRequest->displayChangeRequest;
|
---|
1366 | pReq->xres = RT_BOOL(pDisplayDef->fDisplayFlags & VMMDEV_DISPLAY_CX) ? pDisplayDef->cx : 0;
|
---|
1367 | pReq->yres = RT_BOOL(pDisplayDef->fDisplayFlags & VMMDEV_DISPLAY_CY) ? pDisplayDef->cy : 0;
|
---|
1368 | pReq->bpp = RT_BOOL(pDisplayDef->fDisplayFlags & VMMDEV_DISPLAY_BPP) ? pDisplayDef->cBitsPerPixel : 0;
|
---|
1369 |
|
---|
1370 | Log(("VMMDev: returning display change request xres = %d, yres = %d, bpp = %d\n", pReq->xres, pReq->yres, pReq->bpp));
|
---|
1371 |
|
---|
1372 | return VINF_SUCCESS;
|
---|
1373 | }
|
---|
1374 |
|
---|
1375 |
|
---|
1376 | /**
|
---|
1377 | * Handles VMMDevReq_GetDisplayChangeRequest2.
|
---|
1378 | *
|
---|
1379 | * @returns VBox status code that the guest should see.
|
---|
1380 | * @param pDevIns The device instance.
|
---|
1381 | * @param pThis The VMMDev shared instance data.
|
---|
1382 | * @param pThisCC The VMMDev ring-3 instance data.
|
---|
1383 | * @param pReqHdr The header of the request to handle.
|
---|
1384 | */
|
---|
1385 | static int vmmdevReqHandler_GetDisplayChangeRequest2(PPDMDEVINS pDevIns, PVMMDEV pThis, PVMMDEVCC pThisCC,
|
---|
1386 | VMMDevRequestHeader *pReqHdr)
|
---|
1387 | {
|
---|
1388 | VMMDevDisplayChangeRequest2 *pReq = (VMMDevDisplayChangeRequest2 *)pReqHdr;
|
---|
1389 | AssertMsgReturn(pReq->header.size == sizeof(*pReq), ("%u\n", pReq->header.size), VERR_INVALID_PARAMETER);
|
---|
1390 |
|
---|
1391 | DISPLAYCHANGEREQUEST *pDispRequest = NULL;
|
---|
1392 |
|
---|
1393 | if (pReq->eventAck == VMMDEV_EVENT_DISPLAY_CHANGE_REQUEST)
|
---|
1394 | {
|
---|
1395 | /* Select a pending request to report. */
|
---|
1396 | unsigned i;
|
---|
1397 | for (i = 0; i < RT_ELEMENTS(pThis->displayChangeData.aRequests); i++)
|
---|
1398 | {
|
---|
1399 | if (pThis->displayChangeData.aRequests[i].fPending)
|
---|
1400 | {
|
---|
1401 | pDispRequest = &pThis->displayChangeData.aRequests[i];
|
---|
1402 | /* Remember which request should be reported. */
|
---|
1403 | pThis->displayChangeData.iCurrentMonitor = i;
|
---|
1404 | Log3(("VMMDev: will report pending request for %u\n", i));
|
---|
1405 | break;
|
---|
1406 | }
|
---|
1407 | }
|
---|
1408 |
|
---|
1409 | /* Check if there are more pending requests. */
|
---|
1410 | i++;
|
---|
1411 | for (; i < RT_ELEMENTS(pThis->displayChangeData.aRequests); i++)
|
---|
1412 | {
|
---|
1413 | if (pThis->displayChangeData.aRequests[i].fPending)
|
---|
1414 | {
|
---|
1415 | VMMDevNotifyGuest(pDevIns, pThis, pThisCC, VMMDEV_EVENT_DISPLAY_CHANGE_REQUEST);
|
---|
1416 | Log3(("VMMDev: another pending at %u\n", i));
|
---|
1417 | break;
|
---|
1418 | }
|
---|
1419 | }
|
---|
1420 |
|
---|
1421 | if (pDispRequest)
|
---|
1422 | {
|
---|
1423 | /* Current request has been read at least once. */
|
---|
1424 | pDispRequest->fPending = false;
|
---|
1425 |
|
---|
1426 | /* Remember which resolution the client has queried, subsequent reads
|
---|
1427 | * will return the same values. */
|
---|
1428 | pDispRequest->lastReadDisplayChangeRequest = pDispRequest->displayChangeRequest;
|
---|
1429 | pThis->displayChangeData.fGuestSentChangeEventAck = true;
|
---|
1430 | }
|
---|
1431 | else
|
---|
1432 | {
|
---|
1433 | Log3(("VMMDev: no pending request!!!\n"));
|
---|
1434 | }
|
---|
1435 | }
|
---|
1436 |
|
---|
1437 | if (!pDispRequest)
|
---|
1438 | {
|
---|
1439 | Log3(("VMMDev: default to %d\n", pThis->displayChangeData.iCurrentMonitor));
|
---|
1440 | pDispRequest = &pThis->displayChangeData.aRequests[pThis->displayChangeData.iCurrentMonitor];
|
---|
1441 | }
|
---|
1442 |
|
---|
1443 | /* If not a response to a VMMDEV_EVENT_DISPLAY_CHANGE_REQUEST, just
|
---|
1444 | * read the last valid video mode hint. This happens when the guest X server
|
---|
1445 | * determines the initial mode. */
|
---|
1446 | VMMDevDisplayDef const *pDisplayDef = pThis->displayChangeData.fGuestSentChangeEventAck ?
|
---|
1447 | &pDispRequest->lastReadDisplayChangeRequest :
|
---|
1448 | &pDispRequest->displayChangeRequest;
|
---|
1449 | pReq->xres = RT_BOOL(pDisplayDef->fDisplayFlags & VMMDEV_DISPLAY_CX) ? pDisplayDef->cx : 0;
|
---|
1450 | pReq->yres = RT_BOOL(pDisplayDef->fDisplayFlags & VMMDEV_DISPLAY_CY) ? pDisplayDef->cy : 0;
|
---|
1451 | pReq->bpp = RT_BOOL(pDisplayDef->fDisplayFlags & VMMDEV_DISPLAY_BPP) ? pDisplayDef->cBitsPerPixel : 0;
|
---|
1452 | pReq->display = pDisplayDef->idDisplay;
|
---|
1453 |
|
---|
1454 | Log(("VMMDev: returning display change request xres = %d, yres = %d, bpp = %d at %d\n",
|
---|
1455 | pReq->xres, pReq->yres, pReq->bpp, pReq->display));
|
---|
1456 |
|
---|
1457 | return VINF_SUCCESS;
|
---|
1458 | }
|
---|
1459 |
|
---|
1460 |
|
---|
1461 | /**
|
---|
1462 | * Handles VMMDevReq_GetDisplayChangeRequestEx.
|
---|
1463 | *
|
---|
1464 | * @returns VBox status code that the guest should see.
|
---|
1465 | * @param pDevIns The device instance.
|
---|
1466 | * @param pThis The VMMDev shared instance data.
|
---|
1467 | * @param pThisCC The VMMDev ring-3 instance data.
|
---|
1468 | * @param pReqHdr The header of the request to handle.
|
---|
1469 | */
|
---|
1470 | static int vmmdevReqHandler_GetDisplayChangeRequestEx(PPDMDEVINS pDevIns, PVMMDEV pThis, PVMMDEVCC pThisCC,
|
---|
1471 | VMMDevRequestHeader *pReqHdr)
|
---|
1472 | {
|
---|
1473 | VMMDevDisplayChangeRequestEx *pReq = (VMMDevDisplayChangeRequestEx *)pReqHdr;
|
---|
1474 | AssertMsgReturn(pReq->header.size == sizeof(*pReq), ("%u\n", pReq->header.size), VERR_INVALID_PARAMETER);
|
---|
1475 |
|
---|
1476 | DISPLAYCHANGEREQUEST *pDispRequest = NULL;
|
---|
1477 |
|
---|
1478 | if (pReq->eventAck == VMMDEV_EVENT_DISPLAY_CHANGE_REQUEST)
|
---|
1479 | {
|
---|
1480 | /* Select a pending request to report. */
|
---|
1481 | unsigned i;
|
---|
1482 | for (i = 0; i < RT_ELEMENTS(pThis->displayChangeData.aRequests); i++)
|
---|
1483 | {
|
---|
1484 | if (pThis->displayChangeData.aRequests[i].fPending)
|
---|
1485 | {
|
---|
1486 | pDispRequest = &pThis->displayChangeData.aRequests[i];
|
---|
1487 | /* Remember which request should be reported. */
|
---|
1488 | pThis->displayChangeData.iCurrentMonitor = i;
|
---|
1489 | Log3(("VMMDev: will report pending request for %d\n",
|
---|
1490 | i));
|
---|
1491 | break;
|
---|
1492 | }
|
---|
1493 | }
|
---|
1494 |
|
---|
1495 | /* Check if there are more pending requests. */
|
---|
1496 | i++;
|
---|
1497 | for (; i < RT_ELEMENTS(pThis->displayChangeData.aRequests); i++)
|
---|
1498 | {
|
---|
1499 | if (pThis->displayChangeData.aRequests[i].fPending)
|
---|
1500 | {
|
---|
1501 | VMMDevNotifyGuest(pDevIns, pThis, pThisCC, VMMDEV_EVENT_DISPLAY_CHANGE_REQUEST);
|
---|
1502 | Log3(("VMMDev: another pending at %d\n",
|
---|
1503 | i));
|
---|
1504 | break;
|
---|
1505 | }
|
---|
1506 | }
|
---|
1507 |
|
---|
1508 | if (pDispRequest)
|
---|
1509 | {
|
---|
1510 | /* Current request has been read at least once. */
|
---|
1511 | pDispRequest->fPending = false;
|
---|
1512 |
|
---|
1513 | /* Remember which resolution the client has queried, subsequent reads
|
---|
1514 | * will return the same values. */
|
---|
1515 | pDispRequest->lastReadDisplayChangeRequest = pDispRequest->displayChangeRequest;
|
---|
1516 | pThis->displayChangeData.fGuestSentChangeEventAck = true;
|
---|
1517 | }
|
---|
1518 | else
|
---|
1519 | {
|
---|
1520 | Log3(("VMMDev: no pending request!!!\n"));
|
---|
1521 | }
|
---|
1522 | }
|
---|
1523 |
|
---|
1524 | if (!pDispRequest)
|
---|
1525 | {
|
---|
1526 | Log3(("VMMDev: default to %d\n",
|
---|
1527 | pThis->displayChangeData.iCurrentMonitor));
|
---|
1528 | pDispRequest = &pThis->displayChangeData.aRequests[pThis->displayChangeData.iCurrentMonitor];
|
---|
1529 | }
|
---|
1530 |
|
---|
1531 | /* If not a response to a VMMDEV_EVENT_DISPLAY_CHANGE_REQUEST, just
|
---|
1532 | * read the last valid video mode hint. This happens when the guest X server
|
---|
1533 | * determines the initial mode. */
|
---|
1534 | VMMDevDisplayDef const *pDisplayDef = pThis->displayChangeData.fGuestSentChangeEventAck ?
|
---|
1535 | &pDispRequest->lastReadDisplayChangeRequest :
|
---|
1536 | &pDispRequest->displayChangeRequest;
|
---|
1537 | pReq->xres = RT_BOOL(pDisplayDef->fDisplayFlags & VMMDEV_DISPLAY_CX) ? pDisplayDef->cx : 0;
|
---|
1538 | pReq->yres = RT_BOOL(pDisplayDef->fDisplayFlags & VMMDEV_DISPLAY_CY) ? pDisplayDef->cy : 0;
|
---|
1539 | pReq->bpp = RT_BOOL(pDisplayDef->fDisplayFlags & VMMDEV_DISPLAY_BPP) ? pDisplayDef->cBitsPerPixel : 0;
|
---|
1540 | pReq->display = pDisplayDef->idDisplay;
|
---|
1541 | pReq->cxOrigin = pDisplayDef->xOrigin;
|
---|
1542 | pReq->cyOrigin = pDisplayDef->yOrigin;
|
---|
1543 | pReq->fEnabled = !RT_BOOL(pDisplayDef->fDisplayFlags & VMMDEV_DISPLAY_DISABLED);
|
---|
1544 | pReq->fChangeOrigin = RT_BOOL(pDisplayDef->fDisplayFlags & VMMDEV_DISPLAY_ORIGIN);
|
---|
1545 |
|
---|
1546 | Log(("VMMDevEx: returning display change request xres = %d, yres = %d, bpp = %d id %d xPos = %d, yPos = %d & Enabled=%d\n",
|
---|
1547 | pReq->xres, pReq->yres, pReq->bpp, pReq->display, pReq->cxOrigin, pReq->cyOrigin, pReq->fEnabled));
|
---|
1548 |
|
---|
1549 | return VINF_SUCCESS;
|
---|
1550 | }
|
---|
1551 |
|
---|
1552 |
|
---|
1553 | /**
|
---|
1554 | * Handles VMMDevReq_GetDisplayChangeRequestMulti.
|
---|
1555 | *
|
---|
1556 | * @returns VBox status code that the guest should see.
|
---|
1557 | * @param pThis The VMMDev shared instance data.
|
---|
1558 | * @param pReqHdr The header of the request to handle.
|
---|
1559 | */
|
---|
1560 | static int vmmdevReqHandler_GetDisplayChangeRequestMulti(PVMMDEV pThis, VMMDevRequestHeader *pReqHdr)
|
---|
1561 | {
|
---|
1562 | VMMDevDisplayChangeRequestMulti *pReq = (VMMDevDisplayChangeRequestMulti *)pReqHdr;
|
---|
1563 | unsigned i;
|
---|
1564 |
|
---|
1565 | ASSERT_GUEST_MSG_RETURN(pReq->header.size >= sizeof(*pReq),
|
---|
1566 | ("%u\n", pReq->header.size), VERR_INVALID_PARAMETER);
|
---|
1567 | RT_UNTRUSTED_VALIDATED_FENCE();
|
---|
1568 |
|
---|
1569 | uint32_t const cDisplays = pReq->cDisplays;
|
---|
1570 | ASSERT_GUEST_MSG_RETURN(cDisplays > 0 && cDisplays <= RT_ELEMENTS(pThis->displayChangeData.aRequests),
|
---|
1571 | ("cDisplays %u\n", cDisplays), VERR_INVALID_PARAMETER);
|
---|
1572 | RT_UNTRUSTED_VALIDATED_FENCE();
|
---|
1573 |
|
---|
1574 | ASSERT_GUEST_MSG_RETURN(pReq->header.size >= sizeof(*pReq) + (cDisplays - 1) * sizeof(VMMDevDisplayDef),
|
---|
1575 | ("%u\n", pReq->header.size), VERR_INVALID_PARAMETER);
|
---|
1576 | RT_UNTRUSTED_VALIDATED_FENCE();
|
---|
1577 |
|
---|
1578 | if (pReq->eventAck == VMMDEV_EVENT_DISPLAY_CHANGE_REQUEST)
|
---|
1579 | {
|
---|
1580 | uint32_t cDisplaysOut = 0;
|
---|
1581 | /* Remember which resolution the client has queried, subsequent reads
|
---|
1582 | * will return the same values. */
|
---|
1583 | for (i = 0; i < RT_ELEMENTS(pThis->displayChangeData.aRequests); ++i)
|
---|
1584 | {
|
---|
1585 | DISPLAYCHANGEREQUEST *pDCR = &pThis->displayChangeData.aRequests[i];
|
---|
1586 |
|
---|
1587 | pDCR->lastReadDisplayChangeRequest = pDCR->displayChangeRequest;
|
---|
1588 |
|
---|
1589 | if (pDCR->fPending)
|
---|
1590 | {
|
---|
1591 | if (cDisplaysOut < cDisplays)
|
---|
1592 | pReq->aDisplays[cDisplaysOut] = pDCR->lastReadDisplayChangeRequest;
|
---|
1593 |
|
---|
1594 | cDisplaysOut++;
|
---|
1595 | pDCR->fPending = false;
|
---|
1596 | }
|
---|
1597 | }
|
---|
1598 |
|
---|
1599 | pReq->cDisplays = cDisplaysOut;
|
---|
1600 | pThis->displayChangeData.fGuestSentChangeEventAck = true;
|
---|
1601 | }
|
---|
1602 | else
|
---|
1603 | {
|
---|
1604 | /* Fill the guest request with monitor layout data. */
|
---|
1605 | for (i = 0; i < cDisplays; ++i)
|
---|
1606 | {
|
---|
1607 | /* If not a response to a VMMDEV_EVENT_DISPLAY_CHANGE_REQUEST, just
|
---|
1608 | * read the last valid video mode hint. This happens when the guest X server
|
---|
1609 | * determines the initial mode. */
|
---|
1610 | DISPLAYCHANGEREQUEST const *pDCR = &pThis->displayChangeData.aRequests[i];
|
---|
1611 | VMMDevDisplayDef const *pDisplayDef = pThis->displayChangeData.fGuestSentChangeEventAck ?
|
---|
1612 | &pDCR->lastReadDisplayChangeRequest :
|
---|
1613 | &pDCR->displayChangeRequest;
|
---|
1614 | pReq->aDisplays[i] = *pDisplayDef;
|
---|
1615 | }
|
---|
1616 | }
|
---|
1617 |
|
---|
1618 | Log(("VMMDev: returning multimonitor display change request cDisplays %d\n", cDisplays));
|
---|
1619 |
|
---|
1620 | return VINF_SUCCESS;
|
---|
1621 | }
|
---|
1622 |
|
---|
1623 |
|
---|
1624 | /**
|
---|
1625 | * Handles VMMDevReq_VideoModeSupported.
|
---|
1626 | *
|
---|
1627 | * Query whether the given video mode is supported.
|
---|
1628 | *
|
---|
1629 | * @returns VBox status code that the guest should see.
|
---|
1630 | * @param pThisCC The VMMDev ring-3 instance data.
|
---|
1631 | * @param pReqHdr The header of the request to handle.
|
---|
1632 | */
|
---|
1633 | static int vmmdevReqHandler_VideoModeSupported(PVMMDEVCC pThisCC, VMMDevRequestHeader *pReqHdr)
|
---|
1634 | {
|
---|
1635 | VMMDevVideoModeSupportedRequest *pReq = (VMMDevVideoModeSupportedRequest *)pReqHdr;
|
---|
1636 | AssertMsgReturn(pReq->header.size == sizeof(*pReq), ("%u\n", pReq->header.size), VERR_INVALID_PARAMETER);
|
---|
1637 |
|
---|
1638 | /* forward the call */
|
---|
1639 | return pThisCC->pDrv->pfnVideoModeSupported(pThisCC->pDrv,
|
---|
1640 | 0, /* primary screen. */
|
---|
1641 | pReq->width,
|
---|
1642 | pReq->height,
|
---|
1643 | pReq->bpp,
|
---|
1644 | &pReq->fSupported);
|
---|
1645 | }
|
---|
1646 |
|
---|
1647 |
|
---|
1648 | /**
|
---|
1649 | * Handles VMMDevReq_VideoModeSupported2.
|
---|
1650 | *
|
---|
1651 | * Query whether the given video mode is supported for a specific display
|
---|
1652 | *
|
---|
1653 | * @returns VBox status code that the guest should see.
|
---|
1654 | * @param pThisCC The VMMDev ring-3 instance data.
|
---|
1655 | * @param pReqHdr The header of the request to handle.
|
---|
1656 | */
|
---|
1657 | static int vmmdevReqHandler_VideoModeSupported2(PVMMDEVCC pThisCC, VMMDevRequestHeader *pReqHdr)
|
---|
1658 | {
|
---|
1659 | VMMDevVideoModeSupportedRequest2 *pReq = (VMMDevVideoModeSupportedRequest2 *)pReqHdr;
|
---|
1660 | AssertMsgReturn(pReq->header.size == sizeof(*pReq), ("%u\n", pReq->header.size), VERR_INVALID_PARAMETER);
|
---|
1661 |
|
---|
1662 | /* forward the call */
|
---|
1663 | return pThisCC->pDrv->pfnVideoModeSupported(pThisCC->pDrv,
|
---|
1664 | pReq->display,
|
---|
1665 | pReq->width,
|
---|
1666 | pReq->height,
|
---|
1667 | pReq->bpp,
|
---|
1668 | &pReq->fSupported);
|
---|
1669 | }
|
---|
1670 |
|
---|
1671 |
|
---|
1672 |
|
---|
1673 | /**
|
---|
1674 | * Handles VMMDevReq_GetHeightReduction.
|
---|
1675 | *
|
---|
1676 | * @returns VBox status code that the guest should see.
|
---|
1677 | * @param pThis The VMMDev ring-3 instance data.
|
---|
1678 | * @param pReqHdr The header of the request to handle.
|
---|
1679 | */
|
---|
1680 | static int vmmdevReqHandler_GetHeightReduction(PVMMDEVCC pThisCC, VMMDevRequestHeader *pReqHdr)
|
---|
1681 | {
|
---|
1682 | VMMDevGetHeightReductionRequest *pReq = (VMMDevGetHeightReductionRequest *)pReqHdr;
|
---|
1683 | AssertMsgReturn(pReq->header.size == sizeof(*pReq), ("%u\n", pReq->header.size), VERR_INVALID_PARAMETER);
|
---|
1684 |
|
---|
1685 | /* forward the call */
|
---|
1686 | return pThisCC->pDrv->pfnGetHeightReduction(pThisCC->pDrv, &pReq->heightReduction);
|
---|
1687 | }
|
---|
1688 |
|
---|
1689 |
|
---|
1690 | /**
|
---|
1691 | * Handles VMMDevReq_AcknowledgeEvents.
|
---|
1692 | *
|
---|
1693 | * @returns VBox status code that the guest should see.
|
---|
1694 | * @param pDevIns The device instance.
|
---|
1695 | * @param pThis The VMMDev shared instance data.
|
---|
1696 | * @param pThisCC The VMMDev ring-3 instance data.
|
---|
1697 | * @param pReqHdr The header of the request to handle.
|
---|
1698 | */
|
---|
1699 | static int vmmdevReqHandler_AcknowledgeEvents(PPDMDEVINS pDevIns, PVMMDEV pThis, PVMMDEVCC pThisCC, VMMDevRequestHeader *pReqHdr)
|
---|
1700 | {
|
---|
1701 | VMMDevEvents *pReq = (VMMDevEvents *)pReqHdr;
|
---|
1702 | AssertMsgReturn(pReq->header.size == sizeof(*pReq), ("%u\n", pReq->header.size), VERR_INVALID_PARAMETER);
|
---|
1703 | STAM_REL_COUNTER_INC(&pThis->StatSlowIrqAck);
|
---|
1704 |
|
---|
1705 | if (!VMMDEV_INTERFACE_VERSION_IS_1_03(pThis))
|
---|
1706 | {
|
---|
1707 | /*
|
---|
1708 | * Note! This code is duplicated in vmmdevFastRequestIrqAck.
|
---|
1709 | */
|
---|
1710 | if (pThis->fNewGuestFilterMaskValid)
|
---|
1711 | {
|
---|
1712 | pThis->fNewGuestFilterMaskValid = false;
|
---|
1713 | pThis->fGuestFilterMask = pThis->fNewGuestFilterMask;
|
---|
1714 | }
|
---|
1715 |
|
---|
1716 | pReq->events = pThis->fHostEventFlags & pThis->fGuestFilterMask;
|
---|
1717 |
|
---|
1718 | pThis->fHostEventFlags &= ~pThis->fGuestFilterMask;
|
---|
1719 | pThisCC->CTX_SUFF(pVMMDevRAM)->V.V1_04.fHaveEvents = false;
|
---|
1720 |
|
---|
1721 | PDMDevHlpPCISetIrqNoWait(pDevIns, 0, 0);
|
---|
1722 | }
|
---|
1723 | else
|
---|
1724 | vmmdevSetIRQ_Legacy(pDevIns, pThis, pThisCC);
|
---|
1725 | return VINF_SUCCESS;
|
---|
1726 | }
|
---|
1727 |
|
---|
1728 |
|
---|
1729 | /**
|
---|
1730 | * Handles VMMDevReq_CtlGuestFilterMask.
|
---|
1731 | *
|
---|
1732 | * @returns VBox status code that the guest should see.
|
---|
1733 | * @param pDevIns The device instance.
|
---|
1734 | * @param pThis The VMMDev shared instance data.
|
---|
1735 | * @param pThisCC The VMMDev ring-3 instance data.
|
---|
1736 | * @param pReqHdr The header of the request to handle.
|
---|
1737 | */
|
---|
1738 | static int vmmdevReqHandler_CtlGuestFilterMask(PPDMDEVINS pDevIns, PVMMDEV pThis, PVMMDEVCC pThisCC, VMMDevRequestHeader *pReqHdr)
|
---|
1739 | {
|
---|
1740 | VMMDevCtlGuestFilterMask *pReq = (VMMDevCtlGuestFilterMask *)pReqHdr;
|
---|
1741 | AssertMsgReturn(pReq->header.size == sizeof(*pReq), ("%u\n", pReq->header.size), VERR_INVALID_PARAMETER);
|
---|
1742 |
|
---|
1743 | LogRelFlow(("VMMDev: vmmdevReqHandler_CtlGuestFilterMask: OR mask: %#x, NOT mask: %#x\n", pReq->u32OrMask, pReq->u32NotMask));
|
---|
1744 |
|
---|
1745 | /* HGCM event notification is enabled by the VMMDev device
|
---|
1746 | * automatically when any HGCM command is issued. The guest
|
---|
1747 | * cannot disable these notifications. */
|
---|
1748 | VMMDevCtlSetGuestFilterMask(pDevIns, pThis, pThisCC, pReq->u32OrMask, pReq->u32NotMask & ~VMMDEV_EVENT_HGCM);
|
---|
1749 | return VINF_SUCCESS;
|
---|
1750 | }
|
---|
1751 |
|
---|
1752 | #ifdef VBOX_WITH_HGCM
|
---|
1753 |
|
---|
1754 | /**
|
---|
1755 | * Handles VMMDevReq_HGCMConnect.
|
---|
1756 | *
|
---|
1757 | * @returns VBox status code that the guest should see.
|
---|
1758 | * @param pDevIns The device instance.
|
---|
1759 | * @param pThis The VMMDev shared instance data.
|
---|
1760 | * @param pThisCC The VMMDev ring-3 instance data.
|
---|
1761 | * @param pReqHdr The header of the request to handle.
|
---|
1762 | * @param GCPhysReqHdr The guest physical address of the request header.
|
---|
1763 | */
|
---|
1764 | static int vmmdevReqHandler_HGCMConnect(PPDMDEVINS pDevIns, PVMMDEV pThis, PVMMDEVCC pThisCC,
|
---|
1765 | VMMDevRequestHeader *pReqHdr, RTGCPHYS GCPhysReqHdr)
|
---|
1766 | {
|
---|
1767 | VMMDevHGCMConnect *pReq = (VMMDevHGCMConnect *)pReqHdr;
|
---|
1768 | AssertMsgReturn(pReq->header.header.size >= sizeof(*pReq), ("%u\n", pReq->header.header.size), VERR_INVALID_PARAMETER); /** @todo Not sure why this is >= ... */
|
---|
1769 |
|
---|
1770 | if (pThisCC->pHGCMDrv)
|
---|
1771 | {
|
---|
1772 | Log(("VMMDevReq_HGCMConnect\n"));
|
---|
1773 | return vmmdevR3HgcmConnect(pDevIns, pThis, pThisCC, pReq, GCPhysReqHdr);
|
---|
1774 | }
|
---|
1775 |
|
---|
1776 | Log(("VMMDevReq_HGCMConnect: HGCM Connector is NULL!\n"));
|
---|
1777 | return VERR_NOT_SUPPORTED;
|
---|
1778 | }
|
---|
1779 |
|
---|
1780 |
|
---|
1781 | /**
|
---|
1782 | * Handles VMMDevReq_HGCMDisconnect.
|
---|
1783 | *
|
---|
1784 | * @returns VBox status code that the guest should see.
|
---|
1785 | * @param pDevIns The device instance.
|
---|
1786 | * @param pThis The VMMDev shared instance data.
|
---|
1787 | * @param pThisCC The VMMDev ring-3 instance data.
|
---|
1788 | * @param pReqHdr The header of the request to handle.
|
---|
1789 | * @param GCPhysReqHdr The guest physical address of the request header.
|
---|
1790 | */
|
---|
1791 | static int vmmdevReqHandler_HGCMDisconnect(PPDMDEVINS pDevIns, PVMMDEV pThis, PVMMDEVCC pThisCC,
|
---|
1792 | VMMDevRequestHeader *pReqHdr, RTGCPHYS GCPhysReqHdr)
|
---|
1793 | {
|
---|
1794 | VMMDevHGCMDisconnect *pReq = (VMMDevHGCMDisconnect *)pReqHdr;
|
---|
1795 | AssertMsgReturn(pReq->header.header.size >= sizeof(*pReq), ("%u\n", pReq->header.header.size), VERR_INVALID_PARAMETER); /** @todo Not sure why this >= ... */
|
---|
1796 |
|
---|
1797 | if (pThisCC->pHGCMDrv)
|
---|
1798 | {
|
---|
1799 | Log(("VMMDevReq_VMMDevHGCMDisconnect\n"));
|
---|
1800 | return vmmdevR3HgcmDisconnect(pDevIns, pThis, pThisCC, pReq, GCPhysReqHdr);
|
---|
1801 | }
|
---|
1802 |
|
---|
1803 | Log(("VMMDevReq_VMMDevHGCMDisconnect: HGCM Connector is NULL!\n"));
|
---|
1804 | return VERR_NOT_SUPPORTED;
|
---|
1805 | }
|
---|
1806 |
|
---|
1807 |
|
---|
1808 | /**
|
---|
1809 | * Handles VMMDevReq_HGCMCall32 and VMMDevReq_HGCMCall64.
|
---|
1810 | *
|
---|
1811 | * @returns VBox status code that the guest should see.
|
---|
1812 | * @param pDevIns The device instance.
|
---|
1813 | * @param pThis The VMMDev shared instance data.
|
---|
1814 | * @param pThisCC The VMMDev ring-3 instance data.
|
---|
1815 | * @param pReqHdr The header of the request to handle.
|
---|
1816 | * @param GCPhysReqHdr The guest physical address of the request header.
|
---|
1817 | * @param tsArrival The STAM_GET_TS() value when the request arrived.
|
---|
1818 | * @param ppLock Pointer to the lock info pointer (latter can be
|
---|
1819 | * NULL). Set to NULL if HGCM takes lock ownership.
|
---|
1820 | */
|
---|
1821 | static int vmmdevReqHandler_HGCMCall(PPDMDEVINS pDevIns, PVMMDEV pThis, PVMMDEVCC pThisCC, VMMDevRequestHeader *pReqHdr,
|
---|
1822 | RTGCPHYS GCPhysReqHdr, uint64_t tsArrival, PVMMDEVREQLOCK *ppLock)
|
---|
1823 | {
|
---|
1824 | VMMDevHGCMCall *pReq = (VMMDevHGCMCall *)pReqHdr;
|
---|
1825 | AssertMsgReturn(pReq->header.header.size >= sizeof(*pReq), ("%u\n", pReq->header.header.size), VERR_INVALID_PARAMETER);
|
---|
1826 |
|
---|
1827 | if (pThisCC->pHGCMDrv)
|
---|
1828 | {
|
---|
1829 | Log2(("VMMDevReq_HGCMCall: sizeof(VMMDevHGCMRequest) = %04X\n", sizeof(VMMDevHGCMCall)));
|
---|
1830 | Log2(("%.*Rhxd\n", pReq->header.header.size, pReq));
|
---|
1831 |
|
---|
1832 | return vmmdevR3HgcmCall(pDevIns, pThis, pThisCC, pReq, pReq->header.header.size, GCPhysReqHdr,
|
---|
1833 | pReq->header.header.requestType, tsArrival, ppLock);
|
---|
1834 | }
|
---|
1835 |
|
---|
1836 | Log(("VMMDevReq_HGCMCall: HGCM Connector is NULL!\n"));
|
---|
1837 | return VERR_NOT_SUPPORTED;
|
---|
1838 | }
|
---|
1839 |
|
---|
1840 | /**
|
---|
1841 | * Handles VMMDevReq_HGCMCancel.
|
---|
1842 | *
|
---|
1843 | * @returns VBox status code that the guest should see.
|
---|
1844 | * @param pThisCC The VMMDev ring-3 instance data.
|
---|
1845 | * @param pReqHdr The header of the request to handle.
|
---|
1846 | * @param GCPhysReqHdr The guest physical address of the request header.
|
---|
1847 | */
|
---|
1848 | static int vmmdevReqHandler_HGCMCancel(PVMMDEVCC pThisCC, VMMDevRequestHeader *pReqHdr, RTGCPHYS GCPhysReqHdr)
|
---|
1849 | {
|
---|
1850 | VMMDevHGCMCancel *pReq = (VMMDevHGCMCancel *)pReqHdr;
|
---|
1851 | AssertMsgReturn(pReq->header.header.size >= sizeof(*pReq), ("%u\n", pReq->header.header.size), VERR_INVALID_PARAMETER); /** @todo Not sure why this >= ... */
|
---|
1852 |
|
---|
1853 | if (pThisCC->pHGCMDrv)
|
---|
1854 | {
|
---|
1855 | Log(("VMMDevReq_VMMDevHGCMCancel\n"));
|
---|
1856 | return vmmdevR3HgcmCancel(pThisCC, pReq, GCPhysReqHdr);
|
---|
1857 | }
|
---|
1858 |
|
---|
1859 | Log(("VMMDevReq_VMMDevHGCMCancel: HGCM Connector is NULL!\n"));
|
---|
1860 | return VERR_NOT_SUPPORTED;
|
---|
1861 | }
|
---|
1862 |
|
---|
1863 |
|
---|
1864 | /**
|
---|
1865 | * Handles VMMDevReq_HGCMCancel2.
|
---|
1866 | *
|
---|
1867 | * @returns VBox status code that the guest should see.
|
---|
1868 | * @param pThisCC The VMMDev ring-3 instance data.
|
---|
1869 | * @param pReqHdr The header of the request to handle.
|
---|
1870 | */
|
---|
1871 | static int vmmdevReqHandler_HGCMCancel2(PVMMDEVCC pThisCC, VMMDevRequestHeader *pReqHdr)
|
---|
1872 | {
|
---|
1873 | VMMDevHGCMCancel2 *pReq = (VMMDevHGCMCancel2 *)pReqHdr;
|
---|
1874 | AssertMsgReturn(pReq->header.size >= sizeof(*pReq), ("%u\n", pReq->header.size), VERR_INVALID_PARAMETER); /** @todo Not sure why this >= ... */
|
---|
1875 |
|
---|
1876 | if (pThisCC->pHGCMDrv)
|
---|
1877 | {
|
---|
1878 | Log(("VMMDevReq_HGCMCancel2\n"));
|
---|
1879 | return vmmdevR3HgcmCancel2(pThisCC, pReq->physReqToCancel);
|
---|
1880 | }
|
---|
1881 |
|
---|
1882 | Log(("VMMDevReq_HGCMCancel2: HGCM Connector is NULL!\n"));
|
---|
1883 | return VERR_NOT_SUPPORTED;
|
---|
1884 | }
|
---|
1885 |
|
---|
1886 | #endif /* VBOX_WITH_HGCM */
|
---|
1887 |
|
---|
1888 |
|
---|
1889 | /**
|
---|
1890 | * Handles VMMDevReq_VideoAccelEnable.
|
---|
1891 | *
|
---|
1892 | * @returns VBox status code that the guest should see.
|
---|
1893 | * @param pThis The VMMDev shared instance data.
|
---|
1894 | * @param pThisCC The VMMDev ring-3 instance data.
|
---|
1895 | * @param pReqHdr The header of the request to handle.
|
---|
1896 | */
|
---|
1897 | static int vmmdevReqHandler_VideoAccelEnable(PVMMDEV pThis, PVMMDEVCC pThisCC, VMMDevRequestHeader *pReqHdr)
|
---|
1898 | {
|
---|
1899 | VMMDevVideoAccelEnable *pReq = (VMMDevVideoAccelEnable *)pReqHdr;
|
---|
1900 | AssertMsgReturn(pReq->header.size >= sizeof(*pReq), ("%u\n", pReq->header.size), VERR_INVALID_PARAMETER); /** @todo Not sure why this >= ... */
|
---|
1901 |
|
---|
1902 | if (!pThisCC->pDrv)
|
---|
1903 | {
|
---|
1904 | Log(("VMMDevReq_VideoAccelEnable Connector is NULL!!\n"));
|
---|
1905 | return VERR_NOT_SUPPORTED;
|
---|
1906 | }
|
---|
1907 |
|
---|
1908 | if (pReq->cbRingBuffer != VMMDEV_VBVA_RING_BUFFER_SIZE)
|
---|
1909 | {
|
---|
1910 | /* The guest driver seems compiled with different headers. */
|
---|
1911 | LogRelMax(16,("VMMDevReq_VideoAccelEnable guest ring buffer size %#x, should be %#x!!\n", pReq->cbRingBuffer, VMMDEV_VBVA_RING_BUFFER_SIZE));
|
---|
1912 | return VERR_INVALID_PARAMETER;
|
---|
1913 | }
|
---|
1914 |
|
---|
1915 | /* The request is correct. */
|
---|
1916 | pReq->fu32Status |= VBVA_F_STATUS_ACCEPTED;
|
---|
1917 |
|
---|
1918 | LogFlow(("VMMDevReq_VideoAccelEnable pReq->u32Enable = %d\n", pReq->u32Enable));
|
---|
1919 |
|
---|
1920 | int rc = pReq->u32Enable
|
---|
1921 | ? pThisCC->pDrv->pfnVideoAccelEnable(pThisCC->pDrv, true, &pThisCC->pVMMDevRAMR3->vbvaMemory)
|
---|
1922 | : pThisCC->pDrv->pfnVideoAccelEnable(pThisCC->pDrv, false, NULL);
|
---|
1923 |
|
---|
1924 | if ( pReq->u32Enable
|
---|
1925 | && RT_SUCCESS(rc))
|
---|
1926 | {
|
---|
1927 | pReq->fu32Status |= VBVA_F_STATUS_ENABLED;
|
---|
1928 |
|
---|
1929 | /* Remember that guest successfully enabled acceleration.
|
---|
1930 | * We need to reestablish it on restoring the VM from saved state.
|
---|
1931 | */
|
---|
1932 | pThis->u32VideoAccelEnabled = 1;
|
---|
1933 | }
|
---|
1934 | else
|
---|
1935 | {
|
---|
1936 | /* The acceleration was not enabled. Remember that. */
|
---|
1937 | pThis->u32VideoAccelEnabled = 0;
|
---|
1938 | }
|
---|
1939 | return VINF_SUCCESS;
|
---|
1940 | }
|
---|
1941 |
|
---|
1942 |
|
---|
1943 | /**
|
---|
1944 | * Handles VMMDevReq_VideoAccelFlush.
|
---|
1945 | *
|
---|
1946 | * @returns VBox status code that the guest should see.
|
---|
1947 | * @param pThisCC The VMMDev ring-3 instance data.
|
---|
1948 | * @param pReqHdr The header of the request to handle.
|
---|
1949 | */
|
---|
1950 | static int vmmdevReqHandler_VideoAccelFlush(PVMMDEVCC pThisCC, VMMDevRequestHeader *pReqHdr)
|
---|
1951 | {
|
---|
1952 | VMMDevVideoAccelFlush *pReq = (VMMDevVideoAccelFlush *)pReqHdr;
|
---|
1953 | AssertMsgReturn(pReq->header.size >= sizeof(*pReq), ("%u\n", pReq->header.size), VERR_INVALID_PARAMETER); /** @todo Not sure why this >= ... */
|
---|
1954 |
|
---|
1955 | if (!pThisCC->pDrv)
|
---|
1956 | {
|
---|
1957 | Log(("VMMDevReq_VideoAccelFlush: Connector is NULL!!!\n"));
|
---|
1958 | return VERR_NOT_SUPPORTED;
|
---|
1959 | }
|
---|
1960 |
|
---|
1961 | pThisCC->pDrv->pfnVideoAccelFlush(pThisCC->pDrv);
|
---|
1962 | return VINF_SUCCESS;
|
---|
1963 | }
|
---|
1964 |
|
---|
1965 |
|
---|
1966 | /**
|
---|
1967 | * Handles VMMDevReq_VideoSetVisibleRegion.
|
---|
1968 | *
|
---|
1969 | * @returns VBox status code that the guest should see.
|
---|
1970 | * @param pThisCC The VMMDev ring-3 instance data.
|
---|
1971 | * @param pReqHdr The header of the request to handle.
|
---|
1972 | */
|
---|
1973 | static int vmmdevReqHandler_VideoSetVisibleRegion(PVMMDEVCC pThisCC, VMMDevRequestHeader *pReqHdr)
|
---|
1974 | {
|
---|
1975 | VMMDevVideoSetVisibleRegion *pReq = (VMMDevVideoSetVisibleRegion *)pReqHdr;
|
---|
1976 | AssertMsgReturn(pReq->header.size + sizeof(RTRECT) >= sizeof(*pReq), ("%u\n", pReq->header.size), VERR_INVALID_PARAMETER);
|
---|
1977 |
|
---|
1978 | if (!pThisCC->pDrv)
|
---|
1979 | {
|
---|
1980 | Log(("VMMDevReq_VideoSetVisibleRegion: Connector is NULL!!!\n"));
|
---|
1981 | return VERR_NOT_SUPPORTED;
|
---|
1982 | }
|
---|
1983 |
|
---|
1984 | if ( pReq->cRect > _1M /* restrict to sane range */
|
---|
1985 | || pReq->header.size != sizeof(VMMDevVideoSetVisibleRegion) + pReq->cRect * sizeof(RTRECT) - sizeof(RTRECT))
|
---|
1986 | {
|
---|
1987 | Log(("VMMDevReq_VideoSetVisibleRegion: cRects=%#x doesn't match size=%#x or is out of bounds\n",
|
---|
1988 | pReq->cRect, pReq->header.size));
|
---|
1989 | return VERR_INVALID_PARAMETER;
|
---|
1990 | }
|
---|
1991 |
|
---|
1992 | Log(("VMMDevReq_VideoSetVisibleRegion %d rectangles\n", pReq->cRect));
|
---|
1993 | /* forward the call */
|
---|
1994 | return pThisCC->pDrv->pfnSetVisibleRegion(pThisCC->pDrv, pReq->cRect, &pReq->Rect);
|
---|
1995 | }
|
---|
1996 |
|
---|
1997 |
|
---|
1998 | /**
|
---|
1999 | * Handles VMMDevReq_GetSeamlessChangeRequest.
|
---|
2000 | *
|
---|
2001 | * @returns VBox status code that the guest should see.
|
---|
2002 | * @param pThis The VMMDev shared instance data.
|
---|
2003 | * @param pReqHdr The header of the request to handle.
|
---|
2004 | */
|
---|
2005 | static int vmmdevReqHandler_GetSeamlessChangeRequest(PVMMDEV pThis, VMMDevRequestHeader *pReqHdr)
|
---|
2006 | {
|
---|
2007 | VMMDevSeamlessChangeRequest *pReq = (VMMDevSeamlessChangeRequest *)pReqHdr;
|
---|
2008 | AssertMsgReturn(pReq->header.size == sizeof(*pReq), ("%u\n", pReq->header.size), VERR_INVALID_PARAMETER);
|
---|
2009 |
|
---|
2010 | /* just pass on the information */
|
---|
2011 | Log(("VMMDev: returning seamless change request mode=%d\n", pThis->fSeamlessEnabled));
|
---|
2012 | if (pThis->fSeamlessEnabled)
|
---|
2013 | pReq->mode = VMMDev_Seamless_Visible_Region;
|
---|
2014 | else
|
---|
2015 | pReq->mode = VMMDev_Seamless_Disabled;
|
---|
2016 |
|
---|
2017 | if (pReq->eventAck == VMMDEV_EVENT_SEAMLESS_MODE_CHANGE_REQUEST)
|
---|
2018 | {
|
---|
2019 | /* Remember which mode the client has queried. */
|
---|
2020 | pThis->fLastSeamlessEnabled = pThis->fSeamlessEnabled;
|
---|
2021 | }
|
---|
2022 |
|
---|
2023 | return VINF_SUCCESS;
|
---|
2024 | }
|
---|
2025 |
|
---|
2026 |
|
---|
2027 | /**
|
---|
2028 | * Handles VMMDevReq_GetVRDPChangeRequest.
|
---|
2029 | *
|
---|
2030 | * @returns VBox status code that the guest should see.
|
---|
2031 | * @param pThis The VMMDev shared instance data.
|
---|
2032 | * @param pReqHdr The header of the request to handle.
|
---|
2033 | */
|
---|
2034 | static int vmmdevReqHandler_GetVRDPChangeRequest(PVMMDEV pThis, VMMDevRequestHeader *pReqHdr)
|
---|
2035 | {
|
---|
2036 | VMMDevVRDPChangeRequest *pReq = (VMMDevVRDPChangeRequest *)pReqHdr;
|
---|
2037 | AssertMsgReturn(pReq->header.size == sizeof(*pReq), ("%u\n", pReq->header.size), VERR_INVALID_PARAMETER);
|
---|
2038 |
|
---|
2039 | /* just pass on the information */
|
---|
2040 | Log(("VMMDev: returning VRDP status %d level %d\n", pThis->fVRDPEnabled, pThis->uVRDPExperienceLevel));
|
---|
2041 |
|
---|
2042 | pReq->u8VRDPActive = pThis->fVRDPEnabled;
|
---|
2043 | pReq->u32VRDPExperienceLevel = pThis->uVRDPExperienceLevel;
|
---|
2044 |
|
---|
2045 | return VINF_SUCCESS;
|
---|
2046 | }
|
---|
2047 |
|
---|
2048 |
|
---|
2049 | /**
|
---|
2050 | * Handles VMMDevReq_GetMemBalloonChangeRequest.
|
---|
2051 | *
|
---|
2052 | * @returns VBox status code that the guest should see.
|
---|
2053 | * @param pThis The VMMDev shared instance data.
|
---|
2054 | * @param pReqHdr The header of the request to handle.
|
---|
2055 | */
|
---|
2056 | static int vmmdevReqHandler_GetMemBalloonChangeRequest(PVMMDEV pThis, VMMDevRequestHeader *pReqHdr)
|
---|
2057 | {
|
---|
2058 | VMMDevGetMemBalloonChangeRequest *pReq = (VMMDevGetMemBalloonChangeRequest *)pReqHdr;
|
---|
2059 | AssertMsgReturn(pReq->header.size == sizeof(*pReq), ("%u\n", pReq->header.size), VERR_INVALID_PARAMETER);
|
---|
2060 |
|
---|
2061 | /* just pass on the information */
|
---|
2062 | Log(("VMMDev: returning memory balloon size =%d\n", pThis->cMbMemoryBalloon));
|
---|
2063 | pReq->cBalloonChunks = pThis->cMbMemoryBalloon;
|
---|
2064 | pReq->cPhysMemChunks = pThis->cbGuestRAM / (uint64_t)_1M;
|
---|
2065 |
|
---|
2066 | if (pReq->eventAck == VMMDEV_EVENT_BALLOON_CHANGE_REQUEST)
|
---|
2067 | {
|
---|
2068 | /* Remember which mode the client has queried. */
|
---|
2069 | pThis->cMbMemoryBalloonLast = pThis->cMbMemoryBalloon;
|
---|
2070 | }
|
---|
2071 |
|
---|
2072 | return VINF_SUCCESS;
|
---|
2073 | }
|
---|
2074 |
|
---|
2075 |
|
---|
2076 | /**
|
---|
2077 | * Handles VMMDevReq_ChangeMemBalloon.
|
---|
2078 | *
|
---|
2079 | * @returns VBox status code that the guest should see.
|
---|
2080 | * @param pDevIns The device instance.
|
---|
2081 | * @param pThis The VMMDev shared instance data.
|
---|
2082 | * @param pReqHdr The header of the request to handle.
|
---|
2083 | */
|
---|
2084 | static int vmmdevReqHandler_ChangeMemBalloon(PPDMDEVINS pDevIns, PVMMDEV pThis, VMMDevRequestHeader *pReqHdr)
|
---|
2085 | {
|
---|
2086 | VMMDevChangeMemBalloon *pReq = (VMMDevChangeMemBalloon *)pReqHdr;
|
---|
2087 | AssertMsgReturn(pReq->header.size >= sizeof(*pReq), ("%u\n", pReq->header.size), VERR_INVALID_PARAMETER);
|
---|
2088 | AssertMsgReturn(pReq->cPages == VMMDEV_MEMORY_BALLOON_CHUNK_PAGES, ("%u\n", pReq->cPages), VERR_INVALID_PARAMETER);
|
---|
2089 | AssertMsgReturn(pReq->header.size == (uint32_t)RT_UOFFSETOF_DYN(VMMDevChangeMemBalloon, aPhysPage[pReq->cPages]),
|
---|
2090 | ("%u\n", pReq->header.size), VERR_INVALID_PARAMETER);
|
---|
2091 |
|
---|
2092 | Log(("VMMDevReq_ChangeMemBalloon\n"));
|
---|
2093 | int rc = PGMR3PhysChangeMemBalloon(PDMDevHlpGetVM(pDevIns), !!pReq->fInflate, pReq->cPages, pReq->aPhysPage);
|
---|
2094 | if (pReq->fInflate)
|
---|
2095 | STAM_REL_U32_INC(&pThis->StatMemBalloonChunks);
|
---|
2096 | else
|
---|
2097 | STAM_REL_U32_DEC(&pThis->StatMemBalloonChunks);
|
---|
2098 | return rc;
|
---|
2099 | }
|
---|
2100 |
|
---|
2101 |
|
---|
2102 | /**
|
---|
2103 | * Handles VMMDevReq_GetStatisticsChangeRequest.
|
---|
2104 | *
|
---|
2105 | * @returns VBox status code that the guest should see.
|
---|
2106 | * @param pThis The VMMDev shared instance data.
|
---|
2107 | * @param pReqHdr The header of the request to handle.
|
---|
2108 | */
|
---|
2109 | static int vmmdevReqHandler_GetStatisticsChangeRequest(PVMMDEV pThis, VMMDevRequestHeader *pReqHdr)
|
---|
2110 | {
|
---|
2111 | VMMDevGetStatisticsChangeRequest *pReq = (VMMDevGetStatisticsChangeRequest *)pReqHdr;
|
---|
2112 | AssertMsgReturn(pReq->header.size == sizeof(*pReq), ("%u\n", pReq->header.size), VERR_INVALID_PARAMETER);
|
---|
2113 |
|
---|
2114 | Log(("VMMDevReq_GetStatisticsChangeRequest\n"));
|
---|
2115 | /* just pass on the information */
|
---|
2116 | Log(("VMMDev: returning statistics interval %d seconds\n", pThis->cSecsStatInterval));
|
---|
2117 | pReq->u32StatInterval = pThis->cSecsStatInterval;
|
---|
2118 |
|
---|
2119 | if (pReq->eventAck == VMMDEV_EVENT_STATISTICS_INTERVAL_CHANGE_REQUEST)
|
---|
2120 | {
|
---|
2121 | /* Remember which mode the client has queried. */
|
---|
2122 | pThis->cSecsLastStatInterval = pThis->cSecsStatInterval;
|
---|
2123 | }
|
---|
2124 |
|
---|
2125 | return VINF_SUCCESS;
|
---|
2126 | }
|
---|
2127 |
|
---|
2128 |
|
---|
2129 | /**
|
---|
2130 | * Handles VMMDevReq_ReportGuestStats.
|
---|
2131 | *
|
---|
2132 | * @returns VBox status code that the guest should see.
|
---|
2133 | * @param pThisCC The VMMDev ring-3 instance data.
|
---|
2134 | * @param pReqHdr The header of the request to handle.
|
---|
2135 | */
|
---|
2136 | static int vmmdevReqHandler_ReportGuestStats(PVMMDEVCC pThisCC, VMMDevRequestHeader *pReqHdr)
|
---|
2137 | {
|
---|
2138 | VMMDevReportGuestStats *pReq = (VMMDevReportGuestStats *)pReqHdr;
|
---|
2139 | AssertMsgReturn(pReq->header.size == sizeof(*pReq), ("%u\n", pReq->header.size), VERR_INVALID_PARAMETER);
|
---|
2140 |
|
---|
2141 | Log(("VMMDevReq_ReportGuestStats\n"));
|
---|
2142 | #ifdef LOG_ENABLED
|
---|
2143 | VBoxGuestStatistics *pGuestStats = &pReq->guestStats;
|
---|
2144 |
|
---|
2145 | Log(("Current statistics:\n"));
|
---|
2146 | if (pGuestStats->u32StatCaps & VBOX_GUEST_STAT_CPU_LOAD_IDLE)
|
---|
2147 | Log(("CPU%u: CPU Load Idle %-3d%%\n", pGuestStats->u32CpuId, pGuestStats->u32CpuLoad_Idle));
|
---|
2148 |
|
---|
2149 | if (pGuestStats->u32StatCaps & VBOX_GUEST_STAT_CPU_LOAD_KERNEL)
|
---|
2150 | Log(("CPU%u: CPU Load Kernel %-3d%%\n", pGuestStats->u32CpuId, pGuestStats->u32CpuLoad_Kernel));
|
---|
2151 |
|
---|
2152 | if (pGuestStats->u32StatCaps & VBOX_GUEST_STAT_CPU_LOAD_USER)
|
---|
2153 | Log(("CPU%u: CPU Load User %-3d%%\n", pGuestStats->u32CpuId, pGuestStats->u32CpuLoad_User));
|
---|
2154 |
|
---|
2155 | if (pGuestStats->u32StatCaps & VBOX_GUEST_STAT_THREADS)
|
---|
2156 | Log(("CPU%u: Thread %d\n", pGuestStats->u32CpuId, pGuestStats->u32Threads));
|
---|
2157 |
|
---|
2158 | if (pGuestStats->u32StatCaps & VBOX_GUEST_STAT_PROCESSES)
|
---|
2159 | Log(("CPU%u: Processes %d\n", pGuestStats->u32CpuId, pGuestStats->u32Processes));
|
---|
2160 |
|
---|
2161 | if (pGuestStats->u32StatCaps & VBOX_GUEST_STAT_HANDLES)
|
---|
2162 | Log(("CPU%u: Handles %d\n", pGuestStats->u32CpuId, pGuestStats->u32Handles));
|
---|
2163 |
|
---|
2164 | if (pGuestStats->u32StatCaps & VBOX_GUEST_STAT_MEMORY_LOAD)
|
---|
2165 | Log(("CPU%u: Memory Load %d%%\n", pGuestStats->u32CpuId, pGuestStats->u32MemoryLoad));
|
---|
2166 |
|
---|
2167 | /* Note that reported values are in pages; upper layers expect them in megabytes */
|
---|
2168 | Log(("CPU%u: Page size %-4d bytes\n", pGuestStats->u32CpuId, pGuestStats->u32PageSize));
|
---|
2169 | Assert(pGuestStats->u32PageSize == 4096);
|
---|
2170 |
|
---|
2171 | if (pGuestStats->u32StatCaps & VBOX_GUEST_STAT_PHYS_MEM_TOTAL)
|
---|
2172 | Log(("CPU%u: Total physical memory %-4d MB\n", pGuestStats->u32CpuId, (pGuestStats->u32PhysMemTotal + (_1M/_4K)-1) / (_1M/_4K)));
|
---|
2173 |
|
---|
2174 | if (pGuestStats->u32StatCaps & VBOX_GUEST_STAT_PHYS_MEM_AVAIL)
|
---|
2175 | Log(("CPU%u: Free physical memory %-4d MB\n", pGuestStats->u32CpuId, pGuestStats->u32PhysMemAvail / (_1M/_4K)));
|
---|
2176 |
|
---|
2177 | if (pGuestStats->u32StatCaps & VBOX_GUEST_STAT_PHYS_MEM_BALLOON)
|
---|
2178 | Log(("CPU%u: Memory balloon size %-4d MB\n", pGuestStats->u32CpuId, pGuestStats->u32PhysMemBalloon / (_1M/_4K)));
|
---|
2179 |
|
---|
2180 | if (pGuestStats->u32StatCaps & VBOX_GUEST_STAT_MEM_COMMIT_TOTAL)
|
---|
2181 | Log(("CPU%u: Committed memory %-4d MB\n", pGuestStats->u32CpuId, pGuestStats->u32MemCommitTotal / (_1M/_4K)));
|
---|
2182 |
|
---|
2183 | if (pGuestStats->u32StatCaps & VBOX_GUEST_STAT_MEM_KERNEL_TOTAL)
|
---|
2184 | Log(("CPU%u: Total kernel memory %-4d MB\n", pGuestStats->u32CpuId, pGuestStats->u32MemKernelTotal / (_1M/_4K)));
|
---|
2185 |
|
---|
2186 | if (pGuestStats->u32StatCaps & VBOX_GUEST_STAT_MEM_KERNEL_PAGED)
|
---|
2187 | Log(("CPU%u: Paged kernel memory %-4d MB\n", pGuestStats->u32CpuId, pGuestStats->u32MemKernelPaged / (_1M/_4K)));
|
---|
2188 |
|
---|
2189 | if (pGuestStats->u32StatCaps & VBOX_GUEST_STAT_MEM_KERNEL_NONPAGED)
|
---|
2190 | Log(("CPU%u: Nonpaged kernel memory %-4d MB\n", pGuestStats->u32CpuId, pGuestStats->u32MemKernelNonPaged / (_1M/_4K)));
|
---|
2191 |
|
---|
2192 | if (pGuestStats->u32StatCaps & VBOX_GUEST_STAT_MEM_SYSTEM_CACHE)
|
---|
2193 | Log(("CPU%u: System cache size %-4d MB\n", pGuestStats->u32CpuId, pGuestStats->u32MemSystemCache / (_1M/_4K)));
|
---|
2194 |
|
---|
2195 | if (pGuestStats->u32StatCaps & VBOX_GUEST_STAT_PAGE_FILE_SIZE)
|
---|
2196 | Log(("CPU%u: Page file size %-4d MB\n", pGuestStats->u32CpuId, pGuestStats->u32PageFileSize / (_1M/_4K)));
|
---|
2197 | Log(("Statistics end *******************\n"));
|
---|
2198 | #endif /* LOG_ENABLED */
|
---|
2199 |
|
---|
2200 | /* forward the call */
|
---|
2201 | return pThisCC->pDrv->pfnReportStatistics(pThisCC->pDrv, &pReq->guestStats);
|
---|
2202 | }
|
---|
2203 |
|
---|
2204 |
|
---|
2205 | /**
|
---|
2206 | * Handles VMMDevReq_QueryCredentials.
|
---|
2207 | *
|
---|
2208 | * @returns VBox status code that the guest should see.
|
---|
2209 | * @param pThis The VMMDev shared instance data.
|
---|
2210 | * @param pThisCC The VMMDev ring-3 instance data.
|
---|
2211 | * @param pReqHdr The header of the request to handle.
|
---|
2212 | */
|
---|
2213 | static int vmmdevReqHandler_QueryCredentials(PVMMDEV pThis, PVMMDEVCC pThisCC, VMMDevRequestHeader *pReqHdr)
|
---|
2214 | {
|
---|
2215 | VMMDevCredentials *pReq = (VMMDevCredentials *)pReqHdr;
|
---|
2216 | AssertMsgReturn(pReq->header.size == sizeof(*pReq), ("%u\n", pReq->header.size), VERR_INVALID_PARAMETER);
|
---|
2217 | VMMDEVCREDS *pCredentials = pThisCC->pCredentials;
|
---|
2218 | AssertPtrReturn(pCredentials, VERR_NOT_SUPPORTED);
|
---|
2219 |
|
---|
2220 | /* let's start by nulling out the data */
|
---|
2221 | RT_ZERO(pReq->szUserName);
|
---|
2222 | RT_ZERO(pReq->szPassword);
|
---|
2223 | RT_ZERO(pReq->szDomain);
|
---|
2224 |
|
---|
2225 | /* should we return whether we got credentials for a logon? */
|
---|
2226 | if (pReq->u32Flags & VMMDEV_CREDENTIALS_QUERYPRESENCE)
|
---|
2227 | {
|
---|
2228 | if ( pCredentials->Logon.szUserName[0]
|
---|
2229 | || pCredentials->Logon.szPassword[0]
|
---|
2230 | || pCredentials->Logon.szDomain[0])
|
---|
2231 | pReq->u32Flags |= VMMDEV_CREDENTIALS_PRESENT;
|
---|
2232 | else
|
---|
2233 | pReq->u32Flags &= ~VMMDEV_CREDENTIALS_PRESENT;
|
---|
2234 | }
|
---|
2235 |
|
---|
2236 | /* does the guest want to read logon credentials? */
|
---|
2237 | if (pReq->u32Flags & VMMDEV_CREDENTIALS_READ)
|
---|
2238 | {
|
---|
2239 | if (pCredentials->Logon.szUserName[0])
|
---|
2240 | RTStrCopy(pReq->szUserName, sizeof(pReq->szUserName), pCredentials->Logon.szUserName);
|
---|
2241 | if (pCredentials->Logon.szPassword[0])
|
---|
2242 | RTStrCopy(pReq->szPassword, sizeof(pReq->szPassword), pCredentials->Logon.szPassword);
|
---|
2243 | if (pCredentials->Logon.szDomain[0])
|
---|
2244 | RTStrCopy(pReq->szDomain, sizeof(pReq->szDomain), pCredentials->Logon.szDomain);
|
---|
2245 | if (!pCredentials->Logon.fAllowInteractiveLogon)
|
---|
2246 | pReq->u32Flags |= VMMDEV_CREDENTIALS_NOLOCALLOGON;
|
---|
2247 | else
|
---|
2248 | pReq->u32Flags &= ~VMMDEV_CREDENTIALS_NOLOCALLOGON;
|
---|
2249 | }
|
---|
2250 |
|
---|
2251 | if (!pThis->fKeepCredentials)
|
---|
2252 | {
|
---|
2253 | /* does the caller want us to destroy the logon credentials? */
|
---|
2254 | if (pReq->u32Flags & VMMDEV_CREDENTIALS_CLEAR)
|
---|
2255 | {
|
---|
2256 | RT_ZERO(pCredentials->Logon.szUserName);
|
---|
2257 | RT_ZERO(pCredentials->Logon.szPassword);
|
---|
2258 | RT_ZERO(pCredentials->Logon.szDomain);
|
---|
2259 | }
|
---|
2260 | }
|
---|
2261 |
|
---|
2262 | /* does the guest want to read credentials for verification? */
|
---|
2263 | if (pReq->u32Flags & VMMDEV_CREDENTIALS_READJUDGE)
|
---|
2264 | {
|
---|
2265 | if (pCredentials->Judge.szUserName[0])
|
---|
2266 | RTStrCopy(pReq->szUserName, sizeof(pReq->szUserName), pCredentials->Judge.szUserName);
|
---|
2267 | if (pCredentials->Judge.szPassword[0])
|
---|
2268 | RTStrCopy(pReq->szPassword, sizeof(pReq->szPassword), pCredentials->Judge.szPassword);
|
---|
2269 | if (pCredentials->Judge.szDomain[0])
|
---|
2270 | RTStrCopy(pReq->szDomain, sizeof(pReq->szDomain), pCredentials->Judge.szDomain);
|
---|
2271 | }
|
---|
2272 |
|
---|
2273 | /* does the caller want us to destroy the judgement credentials? */
|
---|
2274 | if (pReq->u32Flags & VMMDEV_CREDENTIALS_CLEARJUDGE)
|
---|
2275 | {
|
---|
2276 | RT_ZERO(pCredentials->Judge.szUserName);
|
---|
2277 | RT_ZERO(pCredentials->Judge.szPassword);
|
---|
2278 | RT_ZERO(pCredentials->Judge.szDomain);
|
---|
2279 | }
|
---|
2280 |
|
---|
2281 | return VINF_SUCCESS;
|
---|
2282 | }
|
---|
2283 |
|
---|
2284 |
|
---|
2285 | /**
|
---|
2286 | * Handles VMMDevReq_ReportCredentialsJudgement.
|
---|
2287 | *
|
---|
2288 | * @returns VBox status code that the guest should see.
|
---|
2289 | * @param pThisCC The VMMDev ring-3 instance data.
|
---|
2290 | * @param pReqHdr The header of the request to handle.
|
---|
2291 | */
|
---|
2292 | static int vmmdevReqHandler_ReportCredentialsJudgement(PVMMDEVCC pThisCC, VMMDevRequestHeader *pReqHdr)
|
---|
2293 | {
|
---|
2294 | VMMDevCredentials *pReq = (VMMDevCredentials *)pReqHdr;
|
---|
2295 | AssertMsgReturn(pReq->header.size == sizeof(*pReq), ("%u\n", pReq->header.size), VERR_INVALID_PARAMETER);
|
---|
2296 |
|
---|
2297 | /* what does the guest think about the credentials? (note: the order is important here!) */
|
---|
2298 | if (pReq->u32Flags & VMMDEV_CREDENTIALS_JUDGE_DENY)
|
---|
2299 | pThisCC->pDrv->pfnSetCredentialsJudgementResult(pThisCC->pDrv, VMMDEV_CREDENTIALS_JUDGE_DENY);
|
---|
2300 | else if (pReq->u32Flags & VMMDEV_CREDENTIALS_JUDGE_NOJUDGEMENT)
|
---|
2301 | pThisCC->pDrv->pfnSetCredentialsJudgementResult(pThisCC->pDrv, VMMDEV_CREDENTIALS_JUDGE_NOJUDGEMENT);
|
---|
2302 | else if (pReq->u32Flags & VMMDEV_CREDENTIALS_JUDGE_OK)
|
---|
2303 | pThisCC->pDrv->pfnSetCredentialsJudgementResult(pThisCC->pDrv, VMMDEV_CREDENTIALS_JUDGE_OK);
|
---|
2304 | else
|
---|
2305 | {
|
---|
2306 | Log(("VMMDevReq_ReportCredentialsJudgement: invalid flags: %d!!!\n", pReq->u32Flags));
|
---|
2307 | /** @todo why don't we return VERR_INVALID_PARAMETER to the guest? */
|
---|
2308 | }
|
---|
2309 |
|
---|
2310 | return VINF_SUCCESS;
|
---|
2311 | }
|
---|
2312 |
|
---|
2313 |
|
---|
2314 | /**
|
---|
2315 | * Handles VMMDevReq_GetHostVersion.
|
---|
2316 | *
|
---|
2317 | * @returns VBox status code that the guest should see.
|
---|
2318 | * @param pReqHdr The header of the request to handle.
|
---|
2319 | * @since 3.1.0
|
---|
2320 | * @note The ring-0 VBoxGuestLib uses this to check whether
|
---|
2321 | * VMMDevHGCMParmType_PageList is supported.
|
---|
2322 | */
|
---|
2323 | static int vmmdevReqHandler_GetHostVersion(VMMDevRequestHeader *pReqHdr)
|
---|
2324 | {
|
---|
2325 | VMMDevReqHostVersion *pReq = (VMMDevReqHostVersion *)pReqHdr;
|
---|
2326 | AssertMsgReturn(pReq->header.size == sizeof(*pReq), ("%u\n", pReq->header.size), VERR_INVALID_PARAMETER);
|
---|
2327 |
|
---|
2328 | pReq->major = RTBldCfgVersionMajor();
|
---|
2329 | pReq->minor = RTBldCfgVersionMinor();
|
---|
2330 | pReq->build = RTBldCfgVersionBuild();
|
---|
2331 | pReq->revision = RTBldCfgRevision();
|
---|
2332 | pReq->features = VMMDEV_HVF_HGCM_PHYS_PAGE_LIST
|
---|
2333 | | VMMDEV_HVF_HGCM_EMBEDDED_BUFFERS
|
---|
2334 | | VMMDEV_HVF_HGCM_CONTIGUOUS_PAGE_LIST
|
---|
2335 | | VMMDEV_HVF_HGCM_NO_BOUNCE_PAGE_LIST
|
---|
2336 | | VMMDEV_HVF_FAST_IRQ_ACK;
|
---|
2337 | return VINF_SUCCESS;
|
---|
2338 | }
|
---|
2339 |
|
---|
2340 |
|
---|
2341 | /**
|
---|
2342 | * Handles VMMDevReq_GetCpuHotPlugRequest.
|
---|
2343 | *
|
---|
2344 | * @returns VBox status code that the guest should see.
|
---|
2345 | * @param pThis The VMMDev shared instance data.
|
---|
2346 | * @param pReqHdr The header of the request to handle.
|
---|
2347 | */
|
---|
2348 | static int vmmdevReqHandler_GetCpuHotPlugRequest(PVMMDEV pThis, VMMDevRequestHeader *pReqHdr)
|
---|
2349 | {
|
---|
2350 | VMMDevGetCpuHotPlugRequest *pReq = (VMMDevGetCpuHotPlugRequest *)pReqHdr;
|
---|
2351 | AssertMsgReturn(pReq->header.size == sizeof(*pReq), ("%u\n", pReq->header.size), VERR_INVALID_PARAMETER);
|
---|
2352 |
|
---|
2353 | pReq->enmEventType = pThis->enmCpuHotPlugEvent;
|
---|
2354 | pReq->idCpuCore = pThis->idCpuCore;
|
---|
2355 | pReq->idCpuPackage = pThis->idCpuPackage;
|
---|
2356 |
|
---|
2357 | /* Clear the event */
|
---|
2358 | pThis->enmCpuHotPlugEvent = VMMDevCpuEventType_None;
|
---|
2359 | pThis->idCpuCore = UINT32_MAX;
|
---|
2360 | pThis->idCpuPackage = UINT32_MAX;
|
---|
2361 |
|
---|
2362 | return VINF_SUCCESS;
|
---|
2363 | }
|
---|
2364 |
|
---|
2365 |
|
---|
2366 | /**
|
---|
2367 | * Handles VMMDevReq_SetCpuHotPlugStatus.
|
---|
2368 | *
|
---|
2369 | * @returns VBox status code that the guest should see.
|
---|
2370 | * @param pThis The VMMDev shared instance data.
|
---|
2371 | * @param pReqHdr The header of the request to handle.
|
---|
2372 | */
|
---|
2373 | static int vmmdevReqHandler_SetCpuHotPlugStatus(PVMMDEV pThis, VMMDevRequestHeader *pReqHdr)
|
---|
2374 | {
|
---|
2375 | VMMDevCpuHotPlugStatusRequest *pReq = (VMMDevCpuHotPlugStatusRequest *)pReqHdr;
|
---|
2376 | AssertMsgReturn(pReq->header.size == sizeof(*pReq), ("%u\n", pReq->header.size), VERR_INVALID_PARAMETER);
|
---|
2377 |
|
---|
2378 | if (pReq->enmStatusType == VMMDevCpuStatusType_Disable)
|
---|
2379 | pThis->fCpuHotPlugEventsEnabled = false;
|
---|
2380 | else if (pReq->enmStatusType == VMMDevCpuStatusType_Enable)
|
---|
2381 | pThis->fCpuHotPlugEventsEnabled = true;
|
---|
2382 | else
|
---|
2383 | return VERR_INVALID_PARAMETER;
|
---|
2384 | return VINF_SUCCESS;
|
---|
2385 | }
|
---|
2386 |
|
---|
2387 |
|
---|
2388 | #ifdef DEBUG
|
---|
2389 | /**
|
---|
2390 | * Handles VMMDevReq_LogString.
|
---|
2391 | *
|
---|
2392 | * @returns VBox status code that the guest should see.
|
---|
2393 | * @param pReqHdr The header of the request to handle.
|
---|
2394 | */
|
---|
2395 | static int vmmdevReqHandler_LogString(VMMDevRequestHeader *pReqHdr)
|
---|
2396 | {
|
---|
2397 | VMMDevReqLogString *pReq = (VMMDevReqLogString *)pReqHdr;
|
---|
2398 | AssertMsgReturn(pReq->header.size >= sizeof(*pReq), ("%u\n", pReq->header.size), VERR_INVALID_PARAMETER);
|
---|
2399 | AssertMsgReturn(pReq->szString[pReq->header.size - RT_UOFFSETOF(VMMDevReqLogString, szString) - 1] == '\0',
|
---|
2400 | ("not null terminated\n"), VERR_INVALID_PARAMETER);
|
---|
2401 |
|
---|
2402 | LogIt(RTLOGGRPFLAGS_LEVEL_1, LOG_GROUP_DEV_VMM_BACKDOOR, ("DEBUG LOG: %s", pReq->szString));
|
---|
2403 | return VINF_SUCCESS;
|
---|
2404 | }
|
---|
2405 | #endif /* DEBUG */
|
---|
2406 |
|
---|
2407 | /**
|
---|
2408 | * Handles VMMDevReq_GetSessionId.
|
---|
2409 | *
|
---|
2410 | * Get a unique "session" ID for this VM, where the ID will be different after each
|
---|
2411 | * start, reset or restore of the VM. This can be used for restore detection
|
---|
2412 | * inside the guest.
|
---|
2413 | *
|
---|
2414 | * @returns VBox status code that the guest should see.
|
---|
2415 | * @param pThis The VMMDev shared instance data.
|
---|
2416 | * @param pReqHdr The header of the request to handle.
|
---|
2417 | */
|
---|
2418 | static int vmmdevReqHandler_GetSessionId(PVMMDEV pThis, VMMDevRequestHeader *pReqHdr)
|
---|
2419 | {
|
---|
2420 | VMMDevReqSessionId *pReq = (VMMDevReqSessionId *)pReqHdr;
|
---|
2421 | AssertMsgReturn(pReq->header.size == sizeof(*pReq), ("%u\n", pReq->header.size), VERR_INVALID_PARAMETER);
|
---|
2422 |
|
---|
2423 | pReq->idSession = pThis->idSession;
|
---|
2424 | return VINF_SUCCESS;
|
---|
2425 | }
|
---|
2426 |
|
---|
2427 |
|
---|
2428 | #ifdef VBOX_WITH_PAGE_SHARING
|
---|
2429 |
|
---|
2430 | /**
|
---|
2431 | * Handles VMMDevReq_RegisterSharedModule.
|
---|
2432 | *
|
---|
2433 | * @returns VBox status code that the guest should see.
|
---|
2434 | * @param pDevIns The device instance.
|
---|
2435 | * @param pReqHdr The header of the request to handle.
|
---|
2436 | */
|
---|
2437 | static int vmmdevReqHandler_RegisterSharedModule(PPDMDEVINS pDevIns, VMMDevRequestHeader *pReqHdr)
|
---|
2438 | {
|
---|
2439 | /*
|
---|
2440 | * Basic input validation (more done by GMM).
|
---|
2441 | */
|
---|
2442 | VMMDevSharedModuleRegistrationRequest *pReq = (VMMDevSharedModuleRegistrationRequest *)pReqHdr;
|
---|
2443 | AssertMsgReturn(pReq->header.size >= sizeof(VMMDevSharedModuleRegistrationRequest),
|
---|
2444 | ("%u\n", pReq->header.size), VERR_INVALID_PARAMETER);
|
---|
2445 | AssertMsgReturn(pReq->header.size == RT_UOFFSETOF_DYN(VMMDevSharedModuleRegistrationRequest, aRegions[pReq->cRegions]),
|
---|
2446 | ("%u cRegions=%u\n", pReq->header.size, pReq->cRegions), VERR_INVALID_PARAMETER);
|
---|
2447 |
|
---|
2448 | AssertReturn(RTStrEnd(pReq->szName, sizeof(pReq->szName)), VERR_INVALID_PARAMETER);
|
---|
2449 | AssertReturn(RTStrEnd(pReq->szVersion, sizeof(pReq->szVersion)), VERR_INVALID_PARAMETER);
|
---|
2450 | int rc = RTStrValidateEncoding(pReq->szName);
|
---|
2451 | AssertRCReturn(rc, rc);
|
---|
2452 | rc = RTStrValidateEncoding(pReq->szVersion);
|
---|
2453 | AssertRCReturn(rc, rc);
|
---|
2454 |
|
---|
2455 | /*
|
---|
2456 | * Forward the request to the VMM.
|
---|
2457 | */
|
---|
2458 | return PGMR3SharedModuleRegister(PDMDevHlpGetVM(pDevIns), pReq->enmGuestOS, pReq->szName, pReq->szVersion,
|
---|
2459 | pReq->GCBaseAddr, pReq->cbModule, pReq->cRegions, pReq->aRegions);
|
---|
2460 | }
|
---|
2461 |
|
---|
2462 | /**
|
---|
2463 | * Handles VMMDevReq_UnregisterSharedModule.
|
---|
2464 | *
|
---|
2465 | * @returns VBox status code that the guest should see.
|
---|
2466 | * @param pDevIns The device instance.
|
---|
2467 | * @param pReqHdr The header of the request to handle.
|
---|
2468 | */
|
---|
2469 | static int vmmdevReqHandler_UnregisterSharedModule(PPDMDEVINS pDevIns, VMMDevRequestHeader *pReqHdr)
|
---|
2470 | {
|
---|
2471 | /*
|
---|
2472 | * Basic input validation.
|
---|
2473 | */
|
---|
2474 | VMMDevSharedModuleUnregistrationRequest *pReq = (VMMDevSharedModuleUnregistrationRequest *)pReqHdr;
|
---|
2475 | AssertMsgReturn(pReq->header.size == sizeof(VMMDevSharedModuleUnregistrationRequest),
|
---|
2476 | ("%u\n", pReq->header.size), VERR_INVALID_PARAMETER);
|
---|
2477 |
|
---|
2478 | AssertReturn(RTStrEnd(pReq->szName, sizeof(pReq->szName)), VERR_INVALID_PARAMETER);
|
---|
2479 | AssertReturn(RTStrEnd(pReq->szVersion, sizeof(pReq->szVersion)), VERR_INVALID_PARAMETER);
|
---|
2480 | int rc = RTStrValidateEncoding(pReq->szName);
|
---|
2481 | AssertRCReturn(rc, rc);
|
---|
2482 | rc = RTStrValidateEncoding(pReq->szVersion);
|
---|
2483 | AssertRCReturn(rc, rc);
|
---|
2484 |
|
---|
2485 | /*
|
---|
2486 | * Forward the request to the VMM.
|
---|
2487 | */
|
---|
2488 | return PGMR3SharedModuleUnregister(PDMDevHlpGetVM(pDevIns), pReq->szName, pReq->szVersion,
|
---|
2489 | pReq->GCBaseAddr, pReq->cbModule);
|
---|
2490 | }
|
---|
2491 |
|
---|
2492 | /**
|
---|
2493 | * Handles VMMDevReq_CheckSharedModules.
|
---|
2494 | *
|
---|
2495 | * @returns VBox status code that the guest should see.
|
---|
2496 | * @param pDevIns The device instance.
|
---|
2497 | * @param pReqHdr The header of the request to handle.
|
---|
2498 | */
|
---|
2499 | static int vmmdevReqHandler_CheckSharedModules(PPDMDEVINS pDevIns, VMMDevRequestHeader *pReqHdr)
|
---|
2500 | {
|
---|
2501 | VMMDevSharedModuleCheckRequest *pReq = (VMMDevSharedModuleCheckRequest *)pReqHdr;
|
---|
2502 | AssertMsgReturn(pReq->header.size == sizeof(VMMDevSharedModuleCheckRequest),
|
---|
2503 | ("%u\n", pReq->header.size), VERR_INVALID_PARAMETER);
|
---|
2504 | return PGMR3SharedModuleCheckAll(PDMDevHlpGetVM(pDevIns));
|
---|
2505 | }
|
---|
2506 |
|
---|
2507 | /**
|
---|
2508 | * Handles VMMDevReq_GetPageSharingStatus.
|
---|
2509 | *
|
---|
2510 | * @returns VBox status code that the guest should see.
|
---|
2511 | * @param pThisCC The VMMDev ring-3 instance data.
|
---|
2512 | * @param pReqHdr The header of the request to handle.
|
---|
2513 | */
|
---|
2514 | static int vmmdevReqHandler_GetPageSharingStatus(PVMMDEVCC pThisCC, VMMDevRequestHeader *pReqHdr)
|
---|
2515 | {
|
---|
2516 | VMMDevPageSharingStatusRequest *pReq = (VMMDevPageSharingStatusRequest *)pReqHdr;
|
---|
2517 | AssertMsgReturn(pReq->header.size == sizeof(VMMDevPageSharingStatusRequest),
|
---|
2518 | ("%u\n", pReq->header.size), VERR_INVALID_PARAMETER);
|
---|
2519 |
|
---|
2520 | pReq->fEnabled = false;
|
---|
2521 | int rc = pThisCC->pDrv->pfnIsPageFusionEnabled(pThisCC->pDrv, &pReq->fEnabled);
|
---|
2522 | if (RT_FAILURE(rc))
|
---|
2523 | pReq->fEnabled = false;
|
---|
2524 | return VINF_SUCCESS;
|
---|
2525 | }
|
---|
2526 |
|
---|
2527 |
|
---|
2528 | /**
|
---|
2529 | * Handles VMMDevReq_DebugIsPageShared.
|
---|
2530 | *
|
---|
2531 | * @returns VBox status code that the guest should see.
|
---|
2532 | * @param pDevIns The device instance.
|
---|
2533 | * @param pReqHdr The header of the request to handle.
|
---|
2534 | */
|
---|
2535 | static int vmmdevReqHandler_DebugIsPageShared(PPDMDEVINS pDevIns, VMMDevRequestHeader *pReqHdr)
|
---|
2536 | {
|
---|
2537 | VMMDevPageIsSharedRequest *pReq = (VMMDevPageIsSharedRequest *)pReqHdr;
|
---|
2538 | AssertMsgReturn(pReq->header.size == sizeof(VMMDevPageIsSharedRequest),
|
---|
2539 | ("%u\n", pReq->header.size), VERR_INVALID_PARAMETER);
|
---|
2540 |
|
---|
2541 | # ifdef DEBUG
|
---|
2542 | return PGMR3SharedModuleGetPageState(PDMDevHlpGetVM(pDevIns), pReq->GCPtrPage, &pReq->fShared, &pReq->uPageFlags);
|
---|
2543 | # else
|
---|
2544 | RT_NOREF(pDevIns);
|
---|
2545 | return VERR_NOT_IMPLEMENTED;
|
---|
2546 | # endif
|
---|
2547 | }
|
---|
2548 |
|
---|
2549 | #endif /* VBOX_WITH_PAGE_SHARING */
|
---|
2550 |
|
---|
2551 |
|
---|
2552 | /**
|
---|
2553 | * Handles VMMDevReq_WriteCoreDumpe
|
---|
2554 | *
|
---|
2555 | * @returns VBox status code that the guest should see.
|
---|
2556 | * @param pDevIns The device instance.
|
---|
2557 | * @param pThis The VMMDev shared instance data.
|
---|
2558 | * @param pReqHdr Pointer to the request header.
|
---|
2559 | */
|
---|
2560 | static int vmmdevReqHandler_WriteCoreDump(PPDMDEVINS pDevIns, PVMMDEV pThis, VMMDevRequestHeader *pReqHdr)
|
---|
2561 | {
|
---|
2562 | VMMDevReqWriteCoreDump *pReq = (VMMDevReqWriteCoreDump *)pReqHdr;
|
---|
2563 | AssertMsgReturn(pReq->header.size == sizeof(VMMDevReqWriteCoreDump), ("%u\n", pReq->header.size), VERR_INVALID_PARAMETER);
|
---|
2564 |
|
---|
2565 | /*
|
---|
2566 | * Only available if explicitly enabled by the user.
|
---|
2567 | */
|
---|
2568 | if (!pThis->fGuestCoreDumpEnabled)
|
---|
2569 | return VERR_ACCESS_DENIED;
|
---|
2570 |
|
---|
2571 | /*
|
---|
2572 | * User makes sure the directory exists before composing the path.
|
---|
2573 | */
|
---|
2574 | if (!RTDirExists(pThis->szGuestCoreDumpDir))
|
---|
2575 | return VERR_PATH_NOT_FOUND;
|
---|
2576 |
|
---|
2577 | char szCorePath[RTPATH_MAX];
|
---|
2578 | RTStrCopy(szCorePath, sizeof(szCorePath), pThis->szGuestCoreDumpDir);
|
---|
2579 | RTPathAppend(szCorePath, sizeof(szCorePath), "VBox.core");
|
---|
2580 |
|
---|
2581 | /*
|
---|
2582 | * Rotate existing cores based on number of additional cores to keep around.
|
---|
2583 | */
|
---|
2584 | if (pThis->cGuestCoreDumps > 0)
|
---|
2585 | for (int64_t i = pThis->cGuestCoreDumps - 1; i >= 0; i--)
|
---|
2586 | {
|
---|
2587 | char szFilePathOld[RTPATH_MAX];
|
---|
2588 | if (i == 0)
|
---|
2589 | RTStrCopy(szFilePathOld, sizeof(szFilePathOld), szCorePath);
|
---|
2590 | else
|
---|
2591 | RTStrPrintf(szFilePathOld, sizeof(szFilePathOld), "%s.%lld", szCorePath, i);
|
---|
2592 |
|
---|
2593 | char szFilePathNew[RTPATH_MAX];
|
---|
2594 | RTStrPrintf(szFilePathNew, sizeof(szFilePathNew), "%s.%lld", szCorePath, i + 1);
|
---|
2595 | int vrc = RTFileMove(szFilePathOld, szFilePathNew, RTFILEMOVE_FLAGS_REPLACE);
|
---|
2596 | if (vrc == VERR_FILE_NOT_FOUND)
|
---|
2597 | RTFileDelete(szFilePathNew);
|
---|
2598 | }
|
---|
2599 |
|
---|
2600 | /*
|
---|
2601 | * Write the core file.
|
---|
2602 | */
|
---|
2603 | PUVM pUVM = PDMDevHlpGetUVM(pDevIns);
|
---|
2604 | return DBGFR3CoreWrite(pUVM, szCorePath, true /*fReplaceFile*/);
|
---|
2605 | }
|
---|
2606 |
|
---|
2607 |
|
---|
2608 | /**
|
---|
2609 | * Sets request status to VINF_HGCM_ASYNC_EXECUTE.
|
---|
2610 | *
|
---|
2611 | * @param pDevIns The device instance.
|
---|
2612 | * @param pThis The VMM device instance data.
|
---|
2613 | * @param GCPhysReqHdr The guest physical address of the request.
|
---|
2614 | * @param pLock Pointer to the request locking info. NULL if not
|
---|
2615 | * locked.
|
---|
2616 | */
|
---|
2617 | DECLINLINE(void) vmmdevReqHdrSetHgcmAsyncExecute(PPDMDEVINS pDevIns, RTGCPHYS GCPhysReqHdr, PVMMDEVREQLOCK pLock)
|
---|
2618 | {
|
---|
2619 | if (pLock)
|
---|
2620 | ((VMMDevRequestHeader volatile *)pLock->pvReq)->rc = VINF_HGCM_ASYNC_EXECUTE;
|
---|
2621 | else
|
---|
2622 | {
|
---|
2623 | int32_t rcReq = VINF_HGCM_ASYNC_EXECUTE;
|
---|
2624 | PDMDevHlpPhysWrite(pDevIns, GCPhysReqHdr + RT_UOFFSETOF(VMMDevRequestHeader, rc), &rcReq, sizeof(rcReq));
|
---|
2625 | }
|
---|
2626 | }
|
---|
2627 |
|
---|
2628 |
|
---|
2629 | /** @name VMMDEVREQDISP_POST_F_XXX - post dispatcher optimizations.
|
---|
2630 | * @{ */
|
---|
2631 | #define VMMDEVREQDISP_POST_F_NO_WRITE_OUT RT_BIT_32(0)
|
---|
2632 | /** @} */
|
---|
2633 |
|
---|
2634 |
|
---|
2635 | /**
|
---|
2636 | * Dispatch the request to the appropriate handler function.
|
---|
2637 | *
|
---|
2638 | * @returns Port I/O handler exit code.
|
---|
2639 | * @param pDevIns The device instance.
|
---|
2640 | * @param pThis The VMMDev shared instance data.
|
---|
2641 | * @param pThisCC The VMMDev ring-3 instance data.
|
---|
2642 | * @param pReqHdr The request header (cached in host memory).
|
---|
2643 | * @param GCPhysReqHdr The guest physical address of the request (for
|
---|
2644 | * HGCM).
|
---|
2645 | * @param tsArrival The STAM_GET_TS() value when the request arrived.
|
---|
2646 | * @param pfPostOptimize HGCM optimizations, VMMDEVREQDISP_POST_F_XXX.
|
---|
2647 | * @param ppLock Pointer to the lock info pointer (latter can be
|
---|
2648 | * NULL). Set to NULL if HGCM takes lock ownership.
|
---|
2649 | */
|
---|
2650 | static VBOXSTRICTRC vmmdevReqDispatcher(PPDMDEVINS pDevIns, PVMMDEV pThis, PVMMDEVCC pThisCC, VMMDevRequestHeader *pReqHdr,
|
---|
2651 | RTGCPHYS GCPhysReqHdr, uint64_t tsArrival, uint32_t *pfPostOptimize,
|
---|
2652 | PVMMDEVREQLOCK *ppLock)
|
---|
2653 | {
|
---|
2654 | int rcRet = VINF_SUCCESS;
|
---|
2655 | Assert(*pfPostOptimize == 0);
|
---|
2656 |
|
---|
2657 | switch (pReqHdr->requestType)
|
---|
2658 | {
|
---|
2659 | case VMMDevReq_ReportGuestInfo:
|
---|
2660 | pReqHdr->rc = vmmdevReqHandler_ReportGuestInfo(pDevIns, pThis, pThisCC, pReqHdr);
|
---|
2661 | break;
|
---|
2662 |
|
---|
2663 | case VMMDevReq_ReportGuestInfo2:
|
---|
2664 | pReqHdr->rc = vmmdevReqHandler_ReportGuestInfo2(pDevIns, pThis, pThisCC, pReqHdr);
|
---|
2665 | break;
|
---|
2666 |
|
---|
2667 | case VMMDevReq_ReportGuestStatus:
|
---|
2668 | pReqHdr->rc = vmmdevReqHandler_ReportGuestStatus(pThis, pThisCC, pReqHdr);
|
---|
2669 | break;
|
---|
2670 |
|
---|
2671 | case VMMDevReq_ReportGuestUserState:
|
---|
2672 | pReqHdr->rc = vmmdevReqHandler_ReportGuestUserState(pThisCC, pReqHdr);
|
---|
2673 | break;
|
---|
2674 |
|
---|
2675 | case VMMDevReq_ReportGuestCapabilities:
|
---|
2676 | pReqHdr->rc = vmmdevReqHandler_ReportGuestCapabilities(pThis, pThisCC, pReqHdr);
|
---|
2677 | break;
|
---|
2678 |
|
---|
2679 | case VMMDevReq_SetGuestCapabilities:
|
---|
2680 | pReqHdr->rc = vmmdevReqHandler_SetGuestCapabilities(pThis, pThisCC, pReqHdr);
|
---|
2681 | break;
|
---|
2682 |
|
---|
2683 | case VMMDevReq_WriteCoreDump:
|
---|
2684 | pReqHdr->rc = vmmdevReqHandler_WriteCoreDump(pDevIns, pThis, pReqHdr);
|
---|
2685 | break;
|
---|
2686 |
|
---|
2687 | case VMMDevReq_GetMouseStatus:
|
---|
2688 | pReqHdr->rc = vmmdevReqHandler_GetMouseStatus(pThis, pReqHdr);
|
---|
2689 | break;
|
---|
2690 |
|
---|
2691 | case VMMDevReq_SetMouseStatus:
|
---|
2692 | pReqHdr->rc = vmmdevReqHandler_SetMouseStatus(pThis, pThisCC, pReqHdr);
|
---|
2693 | break;
|
---|
2694 |
|
---|
2695 | case VMMDevReq_SetPointerShape:
|
---|
2696 | pReqHdr->rc = vmmdevReqHandler_SetPointerShape(pThis, pThisCC, pReqHdr);
|
---|
2697 | break;
|
---|
2698 |
|
---|
2699 | case VMMDevReq_GetHostTime:
|
---|
2700 | pReqHdr->rc = vmmdevReqHandler_GetHostTime(pDevIns, pThis, pReqHdr);
|
---|
2701 | break;
|
---|
2702 |
|
---|
2703 | case VMMDevReq_GetHypervisorInfo:
|
---|
2704 | pReqHdr->rc = vmmdevReqHandler_GetHypervisorInfo(pDevIns, pReqHdr);
|
---|
2705 | break;
|
---|
2706 |
|
---|
2707 | case VMMDevReq_SetHypervisorInfo:
|
---|
2708 | pReqHdr->rc = vmmdevReqHandler_SetHypervisorInfo(pDevIns, pReqHdr);
|
---|
2709 | break;
|
---|
2710 |
|
---|
2711 | case VMMDevReq_RegisterPatchMemory:
|
---|
2712 | pReqHdr->rc = vmmdevReqHandler_RegisterPatchMemory(pDevIns, pReqHdr);
|
---|
2713 | break;
|
---|
2714 |
|
---|
2715 | case VMMDevReq_DeregisterPatchMemory:
|
---|
2716 | pReqHdr->rc = vmmdevReqHandler_DeregisterPatchMemory(pDevIns, pReqHdr);
|
---|
2717 | break;
|
---|
2718 |
|
---|
2719 | case VMMDevReq_SetPowerStatus:
|
---|
2720 | {
|
---|
2721 | int rc = pReqHdr->rc = vmmdevReqHandler_SetPowerStatus(pDevIns, pThis, pReqHdr);
|
---|
2722 | if (rc != VINF_SUCCESS && RT_SUCCESS(rc))
|
---|
2723 | rcRet = rc;
|
---|
2724 | break;
|
---|
2725 | }
|
---|
2726 |
|
---|
2727 | case VMMDevReq_GetDisplayChangeRequest:
|
---|
2728 | pReqHdr->rc = vmmdevReqHandler_GetDisplayChangeRequest(pThis, pReqHdr);
|
---|
2729 | break;
|
---|
2730 |
|
---|
2731 | case VMMDevReq_GetDisplayChangeRequest2:
|
---|
2732 | pReqHdr->rc = vmmdevReqHandler_GetDisplayChangeRequest2(pDevIns, pThis, pThisCC, pReqHdr);
|
---|
2733 | break;
|
---|
2734 |
|
---|
2735 | case VMMDevReq_GetDisplayChangeRequestEx:
|
---|
2736 | pReqHdr->rc = vmmdevReqHandler_GetDisplayChangeRequestEx(pDevIns, pThis, pThisCC, pReqHdr);
|
---|
2737 | break;
|
---|
2738 |
|
---|
2739 | case VMMDevReq_GetDisplayChangeRequestMulti:
|
---|
2740 | pReqHdr->rc = vmmdevReqHandler_GetDisplayChangeRequestMulti(pThis, pReqHdr);
|
---|
2741 | break;
|
---|
2742 |
|
---|
2743 | case VMMDevReq_VideoModeSupported:
|
---|
2744 | pReqHdr->rc = vmmdevReqHandler_VideoModeSupported(pThisCC, pReqHdr);
|
---|
2745 | break;
|
---|
2746 |
|
---|
2747 | case VMMDevReq_VideoModeSupported2:
|
---|
2748 | pReqHdr->rc = vmmdevReqHandler_VideoModeSupported2(pThisCC, pReqHdr);
|
---|
2749 | break;
|
---|
2750 |
|
---|
2751 | case VMMDevReq_GetHeightReduction:
|
---|
2752 | pReqHdr->rc = vmmdevReqHandler_GetHeightReduction(pThisCC, pReqHdr);
|
---|
2753 | break;
|
---|
2754 |
|
---|
2755 | case VMMDevReq_AcknowledgeEvents:
|
---|
2756 | pReqHdr->rc = vmmdevReqHandler_AcknowledgeEvents(pDevIns, pThis, pThisCC, pReqHdr);
|
---|
2757 | break;
|
---|
2758 |
|
---|
2759 | case VMMDevReq_CtlGuestFilterMask:
|
---|
2760 | pReqHdr->rc = vmmdevReqHandler_CtlGuestFilterMask(pDevIns, pThis, pThisCC, pReqHdr);
|
---|
2761 | break;
|
---|
2762 |
|
---|
2763 | #ifdef VBOX_WITH_HGCM
|
---|
2764 | case VMMDevReq_HGCMConnect:
|
---|
2765 | vmmdevReqHdrSetHgcmAsyncExecute(pDevIns, GCPhysReqHdr, *ppLock);
|
---|
2766 | pReqHdr->rc = vmmdevReqHandler_HGCMConnect(pDevIns, pThis, pThisCC, pReqHdr, GCPhysReqHdr);
|
---|
2767 | Assert(pReqHdr->rc == VINF_HGCM_ASYNC_EXECUTE || RT_FAILURE_NP(pReqHdr->rc));
|
---|
2768 | if (RT_SUCCESS(pReqHdr->rc))
|
---|
2769 | *pfPostOptimize |= VMMDEVREQDISP_POST_F_NO_WRITE_OUT;
|
---|
2770 | break;
|
---|
2771 |
|
---|
2772 | case VMMDevReq_HGCMDisconnect:
|
---|
2773 | vmmdevReqHdrSetHgcmAsyncExecute(pDevIns, GCPhysReqHdr, *ppLock);
|
---|
2774 | pReqHdr->rc = vmmdevReqHandler_HGCMDisconnect(pDevIns, pThis, pThisCC, pReqHdr, GCPhysReqHdr);
|
---|
2775 | Assert(pReqHdr->rc == VINF_HGCM_ASYNC_EXECUTE || RT_FAILURE_NP(pReqHdr->rc));
|
---|
2776 | if (RT_SUCCESS(pReqHdr->rc))
|
---|
2777 | *pfPostOptimize |= VMMDEVREQDISP_POST_F_NO_WRITE_OUT;
|
---|
2778 | break;
|
---|
2779 |
|
---|
2780 | # ifdef VBOX_WITH_64_BITS_GUESTS
|
---|
2781 | case VMMDevReq_HGCMCall64:
|
---|
2782 | # endif
|
---|
2783 | case VMMDevReq_HGCMCall32:
|
---|
2784 | vmmdevReqHdrSetHgcmAsyncExecute(pDevIns, GCPhysReqHdr, *ppLock);
|
---|
2785 | pReqHdr->rc = vmmdevReqHandler_HGCMCall(pDevIns, pThis, pThisCC, pReqHdr, GCPhysReqHdr, tsArrival, ppLock);
|
---|
2786 | Assert(pReqHdr->rc == VINF_HGCM_ASYNC_EXECUTE || RT_FAILURE_NP(pReqHdr->rc));
|
---|
2787 | if (RT_SUCCESS(pReqHdr->rc))
|
---|
2788 | *pfPostOptimize |= VMMDEVREQDISP_POST_F_NO_WRITE_OUT;
|
---|
2789 | break;
|
---|
2790 |
|
---|
2791 | case VMMDevReq_HGCMCancel:
|
---|
2792 | pReqHdr->rc = vmmdevReqHandler_HGCMCancel(pThisCC, pReqHdr, GCPhysReqHdr);
|
---|
2793 | break;
|
---|
2794 |
|
---|
2795 | case VMMDevReq_HGCMCancel2:
|
---|
2796 | pReqHdr->rc = vmmdevReqHandler_HGCMCancel2(pThisCC, pReqHdr);
|
---|
2797 | break;
|
---|
2798 | #endif /* VBOX_WITH_HGCM */
|
---|
2799 |
|
---|
2800 | case VMMDevReq_VideoAccelEnable:
|
---|
2801 | pReqHdr->rc = vmmdevReqHandler_VideoAccelEnable(pThis, pThisCC, pReqHdr);
|
---|
2802 | break;
|
---|
2803 |
|
---|
2804 | case VMMDevReq_VideoAccelFlush:
|
---|
2805 | pReqHdr->rc = vmmdevReqHandler_VideoAccelFlush(pThisCC, pReqHdr);
|
---|
2806 | break;
|
---|
2807 |
|
---|
2808 | case VMMDevReq_VideoSetVisibleRegion:
|
---|
2809 | pReqHdr->rc = vmmdevReqHandler_VideoSetVisibleRegion(pThisCC, pReqHdr);
|
---|
2810 | break;
|
---|
2811 |
|
---|
2812 | case VMMDevReq_GetSeamlessChangeRequest:
|
---|
2813 | pReqHdr->rc = vmmdevReqHandler_GetSeamlessChangeRequest(pThis, pReqHdr);
|
---|
2814 | break;
|
---|
2815 |
|
---|
2816 | case VMMDevReq_GetVRDPChangeRequest:
|
---|
2817 | pReqHdr->rc = vmmdevReqHandler_GetVRDPChangeRequest(pThis, pReqHdr);
|
---|
2818 | break;
|
---|
2819 |
|
---|
2820 | case VMMDevReq_GetMemBalloonChangeRequest:
|
---|
2821 | pReqHdr->rc = vmmdevReqHandler_GetMemBalloonChangeRequest(pThis, pReqHdr);
|
---|
2822 | break;
|
---|
2823 |
|
---|
2824 | case VMMDevReq_ChangeMemBalloon:
|
---|
2825 | pReqHdr->rc = vmmdevReqHandler_ChangeMemBalloon(pDevIns, pThis, pReqHdr);
|
---|
2826 | break;
|
---|
2827 |
|
---|
2828 | case VMMDevReq_GetStatisticsChangeRequest:
|
---|
2829 | pReqHdr->rc = vmmdevReqHandler_GetStatisticsChangeRequest(pThis, pReqHdr);
|
---|
2830 | break;
|
---|
2831 |
|
---|
2832 | case VMMDevReq_ReportGuestStats:
|
---|
2833 | pReqHdr->rc = vmmdevReqHandler_ReportGuestStats(pThisCC, pReqHdr);
|
---|
2834 | break;
|
---|
2835 |
|
---|
2836 | case VMMDevReq_QueryCredentials:
|
---|
2837 | pReqHdr->rc = vmmdevReqHandler_QueryCredentials(pThis, pThisCC, pReqHdr);
|
---|
2838 | break;
|
---|
2839 |
|
---|
2840 | case VMMDevReq_ReportCredentialsJudgement:
|
---|
2841 | pReqHdr->rc = vmmdevReqHandler_ReportCredentialsJudgement(pThisCC, pReqHdr);
|
---|
2842 | break;
|
---|
2843 |
|
---|
2844 | case VMMDevReq_GetHostVersion:
|
---|
2845 | pReqHdr->rc = vmmdevReqHandler_GetHostVersion(pReqHdr);
|
---|
2846 | break;
|
---|
2847 |
|
---|
2848 | case VMMDevReq_GetCpuHotPlugRequest:
|
---|
2849 | pReqHdr->rc = vmmdevReqHandler_GetCpuHotPlugRequest(pThis, pReqHdr);
|
---|
2850 | break;
|
---|
2851 |
|
---|
2852 | case VMMDevReq_SetCpuHotPlugStatus:
|
---|
2853 | pReqHdr->rc = vmmdevReqHandler_SetCpuHotPlugStatus(pThis, pReqHdr);
|
---|
2854 | break;
|
---|
2855 |
|
---|
2856 | #ifdef VBOX_WITH_PAGE_SHARING
|
---|
2857 | case VMMDevReq_RegisterSharedModule:
|
---|
2858 | pReqHdr->rc = vmmdevReqHandler_RegisterSharedModule(pDevIns, pReqHdr);
|
---|
2859 | break;
|
---|
2860 |
|
---|
2861 | case VMMDevReq_UnregisterSharedModule:
|
---|
2862 | pReqHdr->rc = vmmdevReqHandler_UnregisterSharedModule(pDevIns, pReqHdr);
|
---|
2863 | break;
|
---|
2864 |
|
---|
2865 | case VMMDevReq_CheckSharedModules:
|
---|
2866 | pReqHdr->rc = vmmdevReqHandler_CheckSharedModules(pDevIns, pReqHdr);
|
---|
2867 | break;
|
---|
2868 |
|
---|
2869 | case VMMDevReq_GetPageSharingStatus:
|
---|
2870 | pReqHdr->rc = vmmdevReqHandler_GetPageSharingStatus(pThisCC, pReqHdr);
|
---|
2871 | break;
|
---|
2872 |
|
---|
2873 | case VMMDevReq_DebugIsPageShared:
|
---|
2874 | pReqHdr->rc = vmmdevReqHandler_DebugIsPageShared(pDevIns, pReqHdr);
|
---|
2875 | break;
|
---|
2876 |
|
---|
2877 | #endif /* VBOX_WITH_PAGE_SHARING */
|
---|
2878 |
|
---|
2879 | #ifdef DEBUG
|
---|
2880 | case VMMDevReq_LogString:
|
---|
2881 | pReqHdr->rc = vmmdevReqHandler_LogString(pReqHdr);
|
---|
2882 | break;
|
---|
2883 | #endif
|
---|
2884 |
|
---|
2885 | case VMMDevReq_GetSessionId:
|
---|
2886 | pReqHdr->rc = vmmdevReqHandler_GetSessionId(pThis, pReqHdr);
|
---|
2887 | break;
|
---|
2888 |
|
---|
2889 | /*
|
---|
2890 | * Guest wants to give up a timeslice.
|
---|
2891 | * Note! This was only ever used by experimental GAs!
|
---|
2892 | */
|
---|
2893 | /** @todo maybe we could just remove this? */
|
---|
2894 | case VMMDevReq_Idle:
|
---|
2895 | {
|
---|
2896 | /* just return to EMT telling it that we want to halt */
|
---|
2897 | rcRet = VINF_EM_HALT;
|
---|
2898 | break;
|
---|
2899 | }
|
---|
2900 |
|
---|
2901 | case VMMDevReq_GuestHeartbeat:
|
---|
2902 | pReqHdr->rc = vmmDevReqHandler_GuestHeartbeat(pDevIns, pThis);
|
---|
2903 | break;
|
---|
2904 |
|
---|
2905 | case VMMDevReq_HeartbeatConfigure:
|
---|
2906 | pReqHdr->rc = vmmDevReqHandler_HeartbeatConfigure(pDevIns, pThis, pReqHdr);
|
---|
2907 | break;
|
---|
2908 |
|
---|
2909 | case VMMDevReq_NtBugCheck:
|
---|
2910 | pReqHdr->rc = vmmDevReqHandler_NtBugCheck(pDevIns, pReqHdr);
|
---|
2911 | break;
|
---|
2912 |
|
---|
2913 | default:
|
---|
2914 | {
|
---|
2915 | pReqHdr->rc = VERR_NOT_IMPLEMENTED;
|
---|
2916 | Log(("VMMDev unknown request type %d\n", pReqHdr->requestType));
|
---|
2917 | break;
|
---|
2918 | }
|
---|
2919 | }
|
---|
2920 | return rcRet;
|
---|
2921 | }
|
---|
2922 |
|
---|
2923 |
|
---|
2924 | /**
|
---|
2925 | * @callback_method_impl{FNIOMIOPORTNEWOUT,
|
---|
2926 | * Port I/O write andler for the generic request interface.}
|
---|
2927 | */
|
---|
2928 | static DECLCALLBACK(VBOXSTRICTRC)
|
---|
2929 | vmmdevRequestHandler(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT offPort, uint32_t u32, unsigned cb)
|
---|
2930 | {
|
---|
2931 | uint64_t tsArrival;
|
---|
2932 | STAM_GET_TS(tsArrival);
|
---|
2933 |
|
---|
2934 | RT_NOREF(offPort, cb, pvUser);
|
---|
2935 |
|
---|
2936 | /*
|
---|
2937 | * The caller has passed the guest context physical address of the request
|
---|
2938 | * structure. We'll copy all of it into a heap buffer eventually, but we
|
---|
2939 | * will have to start off with the header.
|
---|
2940 | */
|
---|
2941 | VMMDevRequestHeader requestHeader;
|
---|
2942 | RT_ZERO(requestHeader);
|
---|
2943 | PDMDevHlpPhysRead(pDevIns, (RTGCPHYS)u32, &requestHeader, sizeof(requestHeader));
|
---|
2944 |
|
---|
2945 | /* The structure size must be greater or equal to the header size. */
|
---|
2946 | if (requestHeader.size < sizeof(VMMDevRequestHeader))
|
---|
2947 | {
|
---|
2948 | Log(("VMMDev request header size too small! size = %d\n", requestHeader.size));
|
---|
2949 | return VINF_SUCCESS;
|
---|
2950 | }
|
---|
2951 |
|
---|
2952 | /* Check the version of the header structure. */
|
---|
2953 | if (requestHeader.version != VMMDEV_REQUEST_HEADER_VERSION)
|
---|
2954 | {
|
---|
2955 | Log(("VMMDev: guest header version (0x%08X) differs from ours (0x%08X)\n", requestHeader.version, VMMDEV_REQUEST_HEADER_VERSION));
|
---|
2956 | return VINF_SUCCESS;
|
---|
2957 | }
|
---|
2958 |
|
---|
2959 | Log2(("VMMDev request issued: %d\n", requestHeader.requestType));
|
---|
2960 |
|
---|
2961 | VBOXSTRICTRC rcRet = VINF_SUCCESS;
|
---|
2962 | /* Check that is doesn't exceed the max packet size. */
|
---|
2963 | if (requestHeader.size <= VMMDEV_MAX_VMMDEVREQ_SIZE)
|
---|
2964 | {
|
---|
2965 | PVMMDEV pThis = PDMDEVINS_2_DATA(pDevIns, PVMMDEV);
|
---|
2966 | PVMMDEVCC pThisCC = PDMDEVINS_2_DATA_CC(pDevIns, PVMMDEVCC);
|
---|
2967 |
|
---|
2968 | /*
|
---|
2969 | * We require the GAs to report it's information before we let it have
|
---|
2970 | * access to all the functions. The VMMDevReq_ReportGuestInfo request
|
---|
2971 | * is the one which unlocks the access. Newer additions will first
|
---|
2972 | * issue VMMDevReq_ReportGuestInfo2, older ones doesn't know this one.
|
---|
2973 | * Two exceptions: VMMDevReq_GetHostVersion and VMMDevReq_WriteCoreDump.
|
---|
2974 | */
|
---|
2975 | if ( pThis->fu32AdditionsOk
|
---|
2976 | || requestHeader.requestType == VMMDevReq_ReportGuestInfo2
|
---|
2977 | || requestHeader.requestType == VMMDevReq_ReportGuestInfo
|
---|
2978 | || requestHeader.requestType == VMMDevReq_WriteCoreDump
|
---|
2979 | || requestHeader.requestType == VMMDevReq_GetHostVersion
|
---|
2980 | )
|
---|
2981 | {
|
---|
2982 | /*
|
---|
2983 | * The request looks fine. Copy it into a buffer.
|
---|
2984 | *
|
---|
2985 | * The buffer is only used while on this thread, and this thread is one
|
---|
2986 | * of the EMTs, so we keep a 4KB buffer for each EMT around to avoid
|
---|
2987 | * wasting time with the heap. Larger allocations goes to the heap, though.
|
---|
2988 | */
|
---|
2989 | VMCPUID iCpu = PDMDevHlpGetCurrentCpuId(pDevIns);
|
---|
2990 | VMMDevRequestHeader *pRequestHeaderFree = NULL;
|
---|
2991 | VMMDevRequestHeader *pRequestHeader = NULL;
|
---|
2992 | if ( requestHeader.size <= _4K
|
---|
2993 | && iCpu < RT_ELEMENTS(pThisCC->apReqBufs))
|
---|
2994 | {
|
---|
2995 | pRequestHeader = pThisCC->apReqBufs[iCpu];
|
---|
2996 | if (pRequestHeader)
|
---|
2997 | { /* likely */ }
|
---|
2998 | else
|
---|
2999 | pThisCC->apReqBufs[iCpu] = pRequestHeader = (VMMDevRequestHeader *)RTMemPageAlloc(_4K);
|
---|
3000 | }
|
---|
3001 | else
|
---|
3002 | {
|
---|
3003 | Assert(iCpu != NIL_VMCPUID);
|
---|
3004 | STAM_REL_COUNTER_INC(&pThisCC->StatReqBufAllocs);
|
---|
3005 | pRequestHeaderFree = pRequestHeader = (VMMDevRequestHeader *)RTMemAlloc(RT_MAX(requestHeader.size, 512));
|
---|
3006 | }
|
---|
3007 | if (pRequestHeader)
|
---|
3008 | {
|
---|
3009 | memcpy(pRequestHeader, &requestHeader, sizeof(VMMDevRequestHeader));
|
---|
3010 |
|
---|
3011 | /* Try lock the request if it's a HGCM call and not crossing a page boundrary.
|
---|
3012 | Saves on PGM interaction. */
|
---|
3013 | VMMDEVREQLOCK Lock = { NULL, { 0, NULL } };
|
---|
3014 | PVMMDEVREQLOCK pLock = NULL;
|
---|
3015 | size_t cbLeft = requestHeader.size - sizeof(VMMDevRequestHeader);
|
---|
3016 | if (cbLeft)
|
---|
3017 | {
|
---|
3018 | if ( ( requestHeader.requestType == VMMDevReq_HGCMCall32
|
---|
3019 | || requestHeader.requestType == VMMDevReq_HGCMCall64)
|
---|
3020 | && ((u32 + requestHeader.size) >> X86_PAGE_SHIFT) == (u32 >> X86_PAGE_SHIFT)
|
---|
3021 | && RT_SUCCESS(PDMDevHlpPhysGCPhys2CCPtr(pDevIns, u32, 0 /*fFlags*/, &Lock.pvReq, &Lock.Lock)) )
|
---|
3022 | {
|
---|
3023 | memcpy((uint8_t *)pRequestHeader + sizeof(VMMDevRequestHeader),
|
---|
3024 | (uint8_t *)Lock.pvReq + sizeof(VMMDevRequestHeader), cbLeft);
|
---|
3025 | pLock = &Lock;
|
---|
3026 | }
|
---|
3027 | else
|
---|
3028 | PDMDevHlpPhysRead(pDevIns,
|
---|
3029 | (RTGCPHYS)u32 + sizeof(VMMDevRequestHeader),
|
---|
3030 | (uint8_t *)pRequestHeader + sizeof(VMMDevRequestHeader),
|
---|
3031 | cbLeft);
|
---|
3032 | }
|
---|
3033 |
|
---|
3034 | /*
|
---|
3035 | * Feed buffered request thru the dispatcher.
|
---|
3036 | */
|
---|
3037 | uint32_t fPostOptimize = 0;
|
---|
3038 | PDMDevHlpCritSectEnter(pDevIns, &pThis->CritSect, VERR_IGNORED);
|
---|
3039 | rcRet = vmmdevReqDispatcher(pDevIns, pThis, pThisCC, pRequestHeader, u32, tsArrival, &fPostOptimize, &pLock);
|
---|
3040 | PDMDevHlpCritSectLeave(pDevIns, &pThis->CritSect);
|
---|
3041 |
|
---|
3042 | /*
|
---|
3043 | * Write the result back to guest memory (unless it is a locked HGCM call).
|
---|
3044 | */
|
---|
3045 | if (!(fPostOptimize & VMMDEVREQDISP_POST_F_NO_WRITE_OUT))
|
---|
3046 | {
|
---|
3047 | if (pLock)
|
---|
3048 | memcpy(pLock->pvReq, pRequestHeader, pRequestHeader->size);
|
---|
3049 | else
|
---|
3050 | PDMDevHlpPhysWrite(pDevIns, u32, pRequestHeader, pRequestHeader->size);
|
---|
3051 | }
|
---|
3052 |
|
---|
3053 | if (!pRequestHeaderFree)
|
---|
3054 | { /* likely */ }
|
---|
3055 | else
|
---|
3056 | RTMemFree(pRequestHeaderFree);
|
---|
3057 | return rcRet;
|
---|
3058 | }
|
---|
3059 |
|
---|
3060 | Log(("VMMDev: RTMemAlloc failed!\n"));
|
---|
3061 | requestHeader.rc = VERR_NO_MEMORY;
|
---|
3062 | }
|
---|
3063 | else
|
---|
3064 | {
|
---|
3065 | LogRelMax(10, ("VMMDev: Guest has not yet reported to us -- refusing operation of request #%d\n",
|
---|
3066 | requestHeader.requestType));
|
---|
3067 | requestHeader.rc = VERR_NOT_SUPPORTED;
|
---|
3068 | }
|
---|
3069 | }
|
---|
3070 | else
|
---|
3071 | {
|
---|
3072 | LogRelMax(50, ("VMMDev: Request packet too big (%x), refusing operation\n", requestHeader.size));
|
---|
3073 | requestHeader.rc = VERR_NOT_SUPPORTED;
|
---|
3074 | }
|
---|
3075 |
|
---|
3076 | /*
|
---|
3077 | * Write the result back to guest memory.
|
---|
3078 | */
|
---|
3079 | PDMDevHlpPhysWrite(pDevIns, u32, &requestHeader, sizeof(requestHeader));
|
---|
3080 |
|
---|
3081 | return rcRet;
|
---|
3082 | }
|
---|
3083 |
|
---|
3084 | #endif /* IN_RING3 */
|
---|
3085 |
|
---|
3086 |
|
---|
3087 | /**
|
---|
3088 | * @callback_method_impl{FNIOMIOPORTOUT, Port I/O write handler for requests
|
---|
3089 | * that can be handled w/o going to ring-3.}
|
---|
3090 | */
|
---|
3091 | static DECLCALLBACK(VBOXSTRICTRC)
|
---|
3092 | vmmdevFastRequestHandler(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT offPort, uint32_t u32, unsigned cb)
|
---|
3093 | {
|
---|
3094 | #ifndef IN_RING3
|
---|
3095 | # if 0 /* This functionality is offered through reading the port (vmmdevFastRequestIrqAck). Leaving it here for later. */
|
---|
3096 | PVMMDEV pThis = PDMDEVINS_2_DATA(pDevIns, PVMMDEV);
|
---|
3097 | RT_NOREF(pvUser, Port, cb);
|
---|
3098 |
|
---|
3099 | /*
|
---|
3100 | * We only process a limited set of requests here, reflecting the rest down
|
---|
3101 | * to ring-3. So, try read the whole request into a stack buffer and check
|
---|
3102 | * if we can handle it.
|
---|
3103 | */
|
---|
3104 | union
|
---|
3105 | {
|
---|
3106 | VMMDevRequestHeader Hdr;
|
---|
3107 | VMMDevEvents Ack;
|
---|
3108 | } uReq;
|
---|
3109 | RT_ZERO(uReq);
|
---|
3110 |
|
---|
3111 | VBOXSTRICTRC rcStrict;
|
---|
3112 | if (pThis->fu32AdditionsOk)
|
---|
3113 | {
|
---|
3114 | /* Read it into memory. */
|
---|
3115 | uint32_t cbToRead = sizeof(uReq); /* (Adjust to stay within a page if we support more than ack requests.) */
|
---|
3116 | rcStrict = PDMDevHlpPhysRead(pDevIns, u32, &uReq, cbToRead);
|
---|
3117 | if (rcStrict == VINF_SUCCESS)
|
---|
3118 | {
|
---|
3119 | /*
|
---|
3120 | * Validate the request and check that we want to handle it here.
|
---|
3121 | */
|
---|
3122 | if ( uReq.Hdr.size >= sizeof(uReq.Hdr)
|
---|
3123 | && uReq.Hdr.version == VMMDEV_REQUEST_HEADER_VERSION
|
---|
3124 | && ( uReq.Hdr.requestType == VMMDevReq_AcknowledgeEvents
|
---|
3125 | && uReq.Hdr.size == sizeof(uReq.Ack)
|
---|
3126 | && cbToRead == sizeof(uReq.Ack)
|
---|
3127 | && pThisCC->CTX_SUFF(pVMMDevRAM) != NULL)
|
---|
3128 | )
|
---|
3129 | {
|
---|
3130 | RT_UNTRUSTED_VALIDATED_FENCE();
|
---|
3131 |
|
---|
3132 | /*
|
---|
3133 | * Try grab the critical section.
|
---|
3134 | */
|
---|
3135 | int rc2 = PDMDevHlpCritSectEnter(pDevIns, &pThis->CritSect, VINF_IOM_R3_IOPORT_WRITE);
|
---|
3136 | if (rc2 == VINF_SUCCESS)
|
---|
3137 | {
|
---|
3138 | /*
|
---|
3139 | * Handle the request and write back the result to the guest.
|
---|
3140 | */
|
---|
3141 | uReq.Hdr.rc = vmmdevReqHandler_AcknowledgeEvents(pThis, &uReq.Hdr);
|
---|
3142 |
|
---|
3143 | rcStrict = PDMDevHlpPhysWrite(pDevIns, u32, &uReq, uReq.Hdr.size);
|
---|
3144 | PDMDevHlpCritSectLeave(pDevIns, &pThis->CritSect);
|
---|
3145 | if (rcStrict == VINF_SUCCESS)
|
---|
3146 | { /* likely */ }
|
---|
3147 | else
|
---|
3148 | Log(("vmmdevFastRequestHandler: PDMDevHlpPhysWrite(%#RX32+rc,4) -> %Rrc (%RTbool)\n",
|
---|
3149 | u32, VBOXSTRICTRC_VAL(rcStrict), PGM_PHYS_RW_IS_SUCCESS(rcStrict) ));
|
---|
3150 | }
|
---|
3151 | else
|
---|
3152 | {
|
---|
3153 | Log(("vmmdevFastRequestHandler: PDMCritSectEnter -> %Rrc\n", rc2));
|
---|
3154 | rcStrict = rc2;
|
---|
3155 | }
|
---|
3156 | }
|
---|
3157 | else
|
---|
3158 | {
|
---|
3159 | Log(("vmmdevFastRequestHandler: size=%#x version=%#x requestType=%d (pVMMDevRAM=%p) -> R3\n",
|
---|
3160 | uReq.Hdr.size, uReq.Hdr.version, uReq.Hdr.requestType, pThisCC->CTX_SUFF(pVMMDevRAM) ));
|
---|
3161 | rcStrict = VINF_IOM_R3_IOPORT_WRITE;
|
---|
3162 | }
|
---|
3163 | }
|
---|
3164 | else
|
---|
3165 | Log(("vmmdevFastRequestHandler: PDMDevHlpPhysRead(%#RX32,%#RX32) -> %Rrc\n", u32, cbToRead, VBOXSTRICTRC_VAL(rcStrict)));
|
---|
3166 | }
|
---|
3167 | else
|
---|
3168 | {
|
---|
3169 | Log(("vmmdevFastRequestHandler: additions nok-okay\n"));
|
---|
3170 | rcStrict = VINF_IOM_R3_IOPORT_WRITE;
|
---|
3171 | }
|
---|
3172 |
|
---|
3173 | return VBOXSTRICTRC_VAL(rcStrict);
|
---|
3174 | # else
|
---|
3175 | RT_NOREF(pDevIns, pvUser, offPort, u32, cb);
|
---|
3176 | return VINF_IOM_R3_IOPORT_WRITE;
|
---|
3177 | # endif
|
---|
3178 |
|
---|
3179 | #else /* IN_RING3 */
|
---|
3180 | return vmmdevRequestHandler(pDevIns, pvUser, offPort, u32, cb);
|
---|
3181 | #endif /* IN_RING3 */
|
---|
3182 | }
|
---|
3183 |
|
---|
3184 |
|
---|
3185 | /**
|
---|
3186 | * @callback_method_impl{FNIOMIOPORTNEWIN,
|
---|
3187 | * Port I/O read handler for IRQ acknowledging and getting pending events (same
|
---|
3188 | * as VMMDevReq_AcknowledgeEvents - just faster).}
|
---|
3189 | */
|
---|
3190 | static DECLCALLBACK(VBOXSTRICTRC)
|
---|
3191 | vmmdevFastRequestIrqAck(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT offPort, uint32_t *pu32, unsigned cb)
|
---|
3192 | {
|
---|
3193 | PVMMDEV pThis = PDMDEVINS_2_DATA(pDevIns, PVMMDEV);
|
---|
3194 | PVMMDEVCC pThisCC = PDMDEVINS_2_DATA_CC(pDevIns, PVMMDEVCC);
|
---|
3195 | Assert(PDMDEVINS_2_DATA(pDevIns, PVMMDEV) == pThis);
|
---|
3196 | RT_NOREF(pvUser, offPort);
|
---|
3197 |
|
---|
3198 | /* Only 32-bit accesses. */
|
---|
3199 | ASSERT_GUEST_MSG_RETURN(cb == sizeof(uint32_t), ("cb=%d\n", cb), VERR_IOM_IOPORT_UNUSED);
|
---|
3200 |
|
---|
3201 | /* The VMMDev memory mapping might've failed, go to ring-3 in that case. */
|
---|
3202 | VBOXSTRICTRC rcStrict;
|
---|
3203 | #ifndef IN_RING3
|
---|
3204 | if (pThisCC->CTX_SUFF(pVMMDevRAM) != NULL)
|
---|
3205 | #endif
|
---|
3206 | {
|
---|
3207 | /* Enter critical section and check that the additions has been properly
|
---|
3208 | initialized and that we're not in legacy v1.3 device mode. */
|
---|
3209 | rcStrict = PDMDevHlpCritSectEnter(pDevIns, &pThis->CritSect, VINF_IOM_R3_IOPORT_READ);
|
---|
3210 | if (rcStrict == VINF_SUCCESS)
|
---|
3211 | {
|
---|
3212 | if ( pThis->fu32AdditionsOk
|
---|
3213 | && !VMMDEV_INTERFACE_VERSION_IS_1_03(pThis))
|
---|
3214 | {
|
---|
3215 | /*
|
---|
3216 | * Do the job.
|
---|
3217 | *
|
---|
3218 | * Note! This code is duplicated in vmmdevReqHandler_AcknowledgeEvents.
|
---|
3219 | */
|
---|
3220 | STAM_REL_COUNTER_INC(&pThis->CTX_SUFF_Z(StatFastIrqAck));
|
---|
3221 |
|
---|
3222 | if (pThis->fNewGuestFilterMaskValid)
|
---|
3223 | {
|
---|
3224 | pThis->fNewGuestFilterMaskValid = false;
|
---|
3225 | pThis->fGuestFilterMask = pThis->fNewGuestFilterMask;
|
---|
3226 | }
|
---|
3227 |
|
---|
3228 | *pu32 = pThis->fHostEventFlags & pThis->fGuestFilterMask;
|
---|
3229 |
|
---|
3230 | pThis->fHostEventFlags &= ~pThis->fGuestFilterMask;
|
---|
3231 | pThisCC->CTX_SUFF(pVMMDevRAM)->V.V1_04.fHaveEvents = false;
|
---|
3232 |
|
---|
3233 | PDMDevHlpPCISetIrqNoWait(pDevIns, 0, 0);
|
---|
3234 | }
|
---|
3235 | else
|
---|
3236 | {
|
---|
3237 | Log(("vmmdevFastRequestIrqAck: fu32AdditionsOk=%d interfaceVersion=%#x\n", pThis->fu32AdditionsOk,
|
---|
3238 | pThis->guestInfo.interfaceVersion));
|
---|
3239 | *pu32 = UINT32_MAX;
|
---|
3240 | }
|
---|
3241 |
|
---|
3242 | PDMDevHlpCritSectLeave(pDevIns, &pThis->CritSect);
|
---|
3243 | }
|
---|
3244 | }
|
---|
3245 | #ifndef IN_RING3
|
---|
3246 | else
|
---|
3247 | rcStrict = VINF_IOM_R3_IOPORT_READ;
|
---|
3248 | #endif
|
---|
3249 | return rcStrict;
|
---|
3250 | }
|
---|
3251 |
|
---|
3252 |
|
---|
3253 |
|
---|
3254 | #ifdef IN_RING3
|
---|
3255 |
|
---|
3256 | /* -=-=-=-=-=- PCI Device -=-=-=-=-=- */
|
---|
3257 |
|
---|
3258 | /**
|
---|
3259 | * @callback_method_impl{FNPCIIOREGIONMAP,I/O Port Region}
|
---|
3260 | */
|
---|
3261 | static DECLCALLBACK(int) vmmdevIOPortRegionMap(PPDMDEVINS pDevIns, PPDMPCIDEV pPciDev, uint32_t iRegion,
|
---|
3262 | RTGCPHYS GCPhysAddress, RTGCPHYS cb, PCIADDRESSSPACE enmType)
|
---|
3263 | {
|
---|
3264 | PVMMDEV pThis = PDMDEVINS_2_DATA(pDevIns, PVMMDEV);
|
---|
3265 | LogFlow(("vmmdevIOPortRegionMap: iRegion=%d GCPhysAddress=%RGp cb=%RGp enmType=%d\n", iRegion, GCPhysAddress, cb, enmType));
|
---|
3266 | RT_NOREF(pPciDev, iRegion, cb, enmType);
|
---|
3267 |
|
---|
3268 | Assert(pPciDev == pDevIns->apPciDevs[0]);
|
---|
3269 | Assert(enmType == PCI_ADDRESS_SPACE_IO);
|
---|
3270 | Assert(iRegion == 0);
|
---|
3271 |
|
---|
3272 | int rc;
|
---|
3273 | if (GCPhysAddress != NIL_RTGCPHYS)
|
---|
3274 | {
|
---|
3275 | AssertMsg(RT_ALIGN(GCPhysAddress, 8) == GCPhysAddress, ("Expected 8 byte alignment. GCPhysAddress=%#RGp\n", GCPhysAddress));
|
---|
3276 |
|
---|
3277 | rc = PDMDevHlpIoPortMap(pDevIns, pThis->hIoPortReq, (RTIOPORT)GCPhysAddress + VMMDEV_PORT_OFF_REQUEST);
|
---|
3278 | AssertLogRelRCReturn(rc, rc);
|
---|
3279 |
|
---|
3280 | rc = PDMDevHlpIoPortMap(pDevIns, pThis->hIoPortFast, (RTIOPORT)GCPhysAddress + VMMDEV_PORT_OFF_REQUEST_FAST);
|
---|
3281 | AssertLogRelRCReturn(rc, rc);
|
---|
3282 | }
|
---|
3283 | else
|
---|
3284 | {
|
---|
3285 | rc = PDMDevHlpIoPortUnmap(pDevIns, pThis->hIoPortReq);
|
---|
3286 | AssertLogRelRCReturn(rc, rc);
|
---|
3287 |
|
---|
3288 | rc = PDMDevHlpIoPortUnmap(pDevIns, pThis->hIoPortFast);
|
---|
3289 | AssertLogRelRCReturn(rc, rc);
|
---|
3290 | }
|
---|
3291 | return rc;
|
---|
3292 | }
|
---|
3293 |
|
---|
3294 |
|
---|
3295 | /**
|
---|
3296 | * @callback_method_impl{FNPCIIOREGIONMAP,VMMDev heap (MMIO2)}
|
---|
3297 | */
|
---|
3298 | static DECLCALLBACK(int) vmmdevMmio2HeapRegionMap(PPDMDEVINS pDevIns, PPDMPCIDEV pPciDev, uint32_t iRegion,
|
---|
3299 | RTGCPHYS GCPhysAddress, RTGCPHYS cb, PCIADDRESSSPACE enmType)
|
---|
3300 | {
|
---|
3301 | PVMMDEVCC pThisCC = PDMDEVINS_2_DATA_CC(pDevIns, PVMMDEVCC);
|
---|
3302 | LogFlow(("vmmdevR3IORAMRegionMap: iRegion=%d GCPhysAddress=%RGp cb=%RGp enmType=%d\n", iRegion, GCPhysAddress, cb, enmType));
|
---|
3303 | RT_NOREF(cb, pPciDev);
|
---|
3304 |
|
---|
3305 | Assert(pPciDev == pDevIns->apPciDevs[0]);
|
---|
3306 | AssertReturn(iRegion == 2, VERR_INTERNAL_ERROR_2);
|
---|
3307 | AssertReturn(enmType == PCI_ADDRESS_SPACE_MEM_PREFETCH, VERR_INTERNAL_ERROR_3);
|
---|
3308 | Assert(pThisCC->pVMMDevHeapR3 != NULL);
|
---|
3309 |
|
---|
3310 | int rc;
|
---|
3311 | if (GCPhysAddress != NIL_RTGCPHYS)
|
---|
3312 | {
|
---|
3313 | rc = PDMDevHlpRegisterVMMDevHeap(pDevIns, GCPhysAddress, pThisCC->pVMMDevHeapR3, VMMDEV_HEAP_SIZE);
|
---|
3314 | AssertRC(rc);
|
---|
3315 | }
|
---|
3316 | else
|
---|
3317 | {
|
---|
3318 | rc = PDMDevHlpRegisterVMMDevHeap(pDevIns, NIL_RTGCPHYS, pThisCC->pVMMDevHeapR3, VMMDEV_HEAP_SIZE);
|
---|
3319 | AssertRCStmt(rc, rc = VINF_SUCCESS);
|
---|
3320 | }
|
---|
3321 |
|
---|
3322 | return rc;
|
---|
3323 | }
|
---|
3324 |
|
---|
3325 |
|
---|
3326 | /* -=-=-=-=-=- Backdoor Logging and Time Sync. -=-=-=-=-=- */
|
---|
3327 |
|
---|
3328 | /**
|
---|
3329 | * @callback_method_impl{FNIOMIOPORTNEWOUT, Backdoor Logging.}
|
---|
3330 | */
|
---|
3331 | static DECLCALLBACK(VBOXSTRICTRC)
|
---|
3332 | vmmdevBackdoorLog(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT offPort, uint32_t u32, unsigned cb)
|
---|
3333 | {
|
---|
3334 | PVMMDEV pThis = PDMDEVINS_2_DATA(pDevIns, PVMMDEV);
|
---|
3335 | RT_NOREF(pvUser, offPort);
|
---|
3336 | Assert(offPort == 0);
|
---|
3337 |
|
---|
3338 | if (!pThis->fBackdoorLogDisabled && cb == 1)
|
---|
3339 | {
|
---|
3340 |
|
---|
3341 | /* The raw version. */
|
---|
3342 | switch (u32)
|
---|
3343 | {
|
---|
3344 | case '\r': LogIt(RTLOGGRPFLAGS_LEVEL_2, LOG_GROUP_DEV_VMM_BACKDOOR, ("vmmdev: <return>\n")); break;
|
---|
3345 | case '\n': LogIt(RTLOGGRPFLAGS_LEVEL_2, LOG_GROUP_DEV_VMM_BACKDOOR, ("vmmdev: <newline>\n")); break;
|
---|
3346 | case '\t': LogIt(RTLOGGRPFLAGS_LEVEL_2, LOG_GROUP_DEV_VMM_BACKDOOR, ("vmmdev: <tab>\n")); break;
|
---|
3347 | default: LogIt(RTLOGGRPFLAGS_LEVEL_2, LOG_GROUP_DEV_VMM_BACKDOOR, ("vmmdev: %c (%02x)\n", u32, u32)); break;
|
---|
3348 | }
|
---|
3349 |
|
---|
3350 | /* The readable, buffered version. */
|
---|
3351 | uint32_t offMsg = RT_MIN(pThis->offMsg, sizeof(pThis->szMsg) - 1);
|
---|
3352 | if (u32 == '\n' || u32 == '\r')
|
---|
3353 | {
|
---|
3354 | pThis->szMsg[offMsg] = '\0';
|
---|
3355 | if (offMsg)
|
---|
3356 | LogRelIt(RTLOGGRPFLAGS_LEVEL_1, LOG_GROUP_DEV_VMM_BACKDOOR, ("VMMDev: Guest Log: %.*s\n", offMsg, pThis->szMsg));
|
---|
3357 | pThis->offMsg = 0;
|
---|
3358 | }
|
---|
3359 | else
|
---|
3360 | {
|
---|
3361 | if (offMsg >= sizeof(pThis->szMsg) - 1)
|
---|
3362 | {
|
---|
3363 | pThis->szMsg[sizeof(pThis->szMsg) - 1] = '\0';
|
---|
3364 | LogRelIt(RTLOGGRPFLAGS_LEVEL_1, LOG_GROUP_DEV_VMM_BACKDOOR,
|
---|
3365 | ("VMMDev: Guest Log: %.*s\n", sizeof(pThis->szMsg) - 1, pThis->szMsg));
|
---|
3366 | offMsg = 0;
|
---|
3367 | }
|
---|
3368 | pThis->szMsg[offMsg++] = (char )u32;
|
---|
3369 | pThis->szMsg[offMsg] = '\0';
|
---|
3370 | pThis->offMsg = offMsg;
|
---|
3371 | }
|
---|
3372 | }
|
---|
3373 | return VINF_SUCCESS;
|
---|
3374 | }
|
---|
3375 |
|
---|
3376 | #ifdef VMMDEV_WITH_ALT_TIMESYNC
|
---|
3377 |
|
---|
3378 | /**
|
---|
3379 | * @callback_method_impl{FNIOMIOPORTNEWOUT, Alternative time synchronization.}
|
---|
3380 | */
|
---|
3381 | static DECLCALLBACK(VBOXSTRICTRC)
|
---|
3382 | vmmdevAltTimeSyncWrite(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT offPort, uint32_t u32, unsigned cb)
|
---|
3383 | {
|
---|
3384 | RT_NOREF(pvUser, offPort);
|
---|
3385 | PVMMDEV pThis = PDMDEVINS_2_DATA(pDevIns, PVMMDEV);
|
---|
3386 | if (cb == 4)
|
---|
3387 | {
|
---|
3388 | /* Selects high (0) or low (1) DWORD. The high has to be read first. */
|
---|
3389 | switch (u32)
|
---|
3390 | {
|
---|
3391 | case 0:
|
---|
3392 | pThis->fTimesyncBackdoorLo = false;
|
---|
3393 | break;
|
---|
3394 | case 1:
|
---|
3395 | pThis->fTimesyncBackdoorLo = true;
|
---|
3396 | break;
|
---|
3397 | default:
|
---|
3398 | Log(("vmmdevAltTimeSyncWrite: Invalid access cb=%#x u32=%#x\n", cb, u32));
|
---|
3399 | break;
|
---|
3400 | }
|
---|
3401 | }
|
---|
3402 | else
|
---|
3403 | Log(("vmmdevAltTimeSyncWrite: Invalid access cb=%#x u32=%#x\n", cb, u32));
|
---|
3404 | return VINF_SUCCESS;
|
---|
3405 | }
|
---|
3406 |
|
---|
3407 | /**
|
---|
3408 | * @callback_method_impl{FNIOMIOPORTOUT, Alternative time synchronization.}
|
---|
3409 | */
|
---|
3410 | static DECLCALLBACK(VBOXSTRICTRC)
|
---|
3411 | vmmdevAltTimeSyncRead(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT offPort, uint32_t *pu32, unsigned cb)
|
---|
3412 | {
|
---|
3413 | RT_NOREF(pvUser, offPort);
|
---|
3414 | PVMMDEV pThis = PDMDEVINS_2_DATA(pDevIns, PVMMDEV);
|
---|
3415 | VBOXSTRICTRC rc;
|
---|
3416 | if (cb == 4)
|
---|
3417 | {
|
---|
3418 | if (pThis->fTimesyncBackdoorLo)
|
---|
3419 | *pu32 = (uint32_t)pThis->msLatchedHostTime;
|
---|
3420 | else
|
---|
3421 | {
|
---|
3422 | /* Reading the high dword gets and saves the current time. */
|
---|
3423 | RTTIMESPEC Now;
|
---|
3424 | pThis->msLatchedHostTime = RTTimeSpecGetMilli(PDMDevHlpTMUtcNow(pDevIns, &Now));
|
---|
3425 | *pu32 = (uint32_t)(pThis->msLatchedHostTime >> 32);
|
---|
3426 | }
|
---|
3427 | rc = VINF_SUCCESS;
|
---|
3428 | }
|
---|
3429 | else
|
---|
3430 | {
|
---|
3431 | Log(("vmmdevAltTimeSyncRead: Invalid access cb=%#x\n", cb));
|
---|
3432 | rc = VERR_IOM_IOPORT_UNUSED;
|
---|
3433 | }
|
---|
3434 | return rc;
|
---|
3435 | }
|
---|
3436 |
|
---|
3437 | #endif /* VMMDEV_WITH_ALT_TIMESYNC */
|
---|
3438 |
|
---|
3439 |
|
---|
3440 | /* -=-=-=-=-=- IBase -=-=-=-=-=- */
|
---|
3441 |
|
---|
3442 | /**
|
---|
3443 | * @interface_method_impl{PDMIBASE,pfnQueryInterface}
|
---|
3444 | */
|
---|
3445 | static DECLCALLBACK(void *) vmmdevPortQueryInterface(PPDMIBASE pInterface, const char *pszIID)
|
---|
3446 | {
|
---|
3447 | PVMMDEVCC pThisCC = RT_FROM_MEMBER(pInterface, VMMDEVCC, IBase);
|
---|
3448 |
|
---|
3449 | PDMIBASE_RETURN_INTERFACE(pszIID, PDMIBASE, &pThisCC->IBase);
|
---|
3450 | PDMIBASE_RETURN_INTERFACE(pszIID, PDMIVMMDEVPORT, &pThisCC->IPort);
|
---|
3451 | #ifdef VBOX_WITH_HGCM
|
---|
3452 | PDMIBASE_RETURN_INTERFACE(pszIID, PDMIHGCMPORT, &pThisCC->IHGCMPort);
|
---|
3453 | #endif
|
---|
3454 | /* Currently only for shared folders. */
|
---|
3455 | PDMIBASE_RETURN_INTERFACE(pszIID, PDMILEDPORTS, &pThisCC->SharedFolders.ILeds);
|
---|
3456 | return NULL;
|
---|
3457 | }
|
---|
3458 |
|
---|
3459 |
|
---|
3460 | /* -=-=-=-=-=- ILeds -=-=-=-=-=- */
|
---|
3461 |
|
---|
3462 | /**
|
---|
3463 | * Gets the pointer to the status LED of a unit.
|
---|
3464 | *
|
---|
3465 | * @returns VBox status code.
|
---|
3466 | * @param pInterface Pointer to the interface structure containing the called function pointer.
|
---|
3467 | * @param iLUN The unit which status LED we desire.
|
---|
3468 | * @param ppLed Where to store the LED pointer.
|
---|
3469 | */
|
---|
3470 | static DECLCALLBACK(int) vmmdevQueryStatusLed(PPDMILEDPORTS pInterface, unsigned iLUN, PPDMLED *ppLed)
|
---|
3471 | {
|
---|
3472 | PVMMDEVCC pThisCC = RT_FROM_MEMBER(pInterface, VMMDEVCC, SharedFolders.ILeds);
|
---|
3473 | if (iLUN == 0) /* LUN 0 is shared folders */
|
---|
3474 | {
|
---|
3475 | *ppLed = &pThisCC->SharedFolders.Led;
|
---|
3476 | return VINF_SUCCESS;
|
---|
3477 | }
|
---|
3478 | return VERR_PDM_LUN_NOT_FOUND;
|
---|
3479 | }
|
---|
3480 |
|
---|
3481 |
|
---|
3482 | /* -=-=-=-=-=- PDMIVMMDEVPORT (VMMDEV::IPort) -=-=-=-=-=- */
|
---|
3483 |
|
---|
3484 | /**
|
---|
3485 | * @interface_method_impl{PDMIVMMDEVPORT,pfnQueryAbsoluteMouse}
|
---|
3486 | */
|
---|
3487 | static DECLCALLBACK(int) vmmdevIPort_QueryAbsoluteMouse(PPDMIVMMDEVPORT pInterface, int32_t *pxAbs, int32_t *pyAbs)
|
---|
3488 | {
|
---|
3489 | PVMMDEVCC pThisCC = RT_FROM_MEMBER(pInterface, VMMDEVCC, IPort);
|
---|
3490 | PVMMDEV pThis = PDMDEVINS_2_DATA(pThisCC->pDevIns, PVMMDEV);
|
---|
3491 |
|
---|
3492 | /** @todo at the first sign of trouble in this area, just enter the critsect.
|
---|
3493 | * As indicated by the comment below, the atomic reads serves no real purpose
|
---|
3494 | * here since we can assume cache coherency protocoles and int32_t alignment
|
---|
3495 | * rules making sure we won't see a halfwritten value. */
|
---|
3496 | if (pxAbs)
|
---|
3497 | *pxAbs = ASMAtomicReadS32(&pThis->xMouseAbs); /* why the atomic read? */
|
---|
3498 | if (pyAbs)
|
---|
3499 | *pyAbs = ASMAtomicReadS32(&pThis->yMouseAbs);
|
---|
3500 |
|
---|
3501 | return VINF_SUCCESS;
|
---|
3502 | }
|
---|
3503 |
|
---|
3504 | /**
|
---|
3505 | * @interface_method_impl{PDMIVMMDEVPORT,pfnSetAbsoluteMouse}
|
---|
3506 | */
|
---|
3507 | static DECLCALLBACK(int) vmmdevIPort_SetAbsoluteMouse(PPDMIVMMDEVPORT pInterface, int32_t xAbs, int32_t yAbs)
|
---|
3508 | {
|
---|
3509 | PVMMDEVCC pThisCC = RT_FROM_MEMBER(pInterface, VMMDEVCC, IPort);
|
---|
3510 | PPDMDEVINS pDevIns = pThisCC->pDevIns;
|
---|
3511 | PVMMDEV pThis = PDMDEVINS_2_DATA(pDevIns, PVMMDEV);
|
---|
3512 | PDMDevHlpCritSectEnter(pDevIns, &pThis->CritSect, VERR_IGNORED);
|
---|
3513 |
|
---|
3514 | if ( pThis->xMouseAbs != xAbs
|
---|
3515 | || pThis->yMouseAbs != yAbs)
|
---|
3516 | {
|
---|
3517 | Log2(("vmmdevIPort_SetAbsoluteMouse : settings absolute position to x = %d, y = %d\n", xAbs, yAbs));
|
---|
3518 | pThis->xMouseAbs = xAbs;
|
---|
3519 | pThis->yMouseAbs = yAbs;
|
---|
3520 | VMMDevNotifyGuest(pDevIns, pThis, pThisCC, VMMDEV_EVENT_MOUSE_POSITION_CHANGED);
|
---|
3521 | }
|
---|
3522 |
|
---|
3523 | PDMDevHlpCritSectLeave(pDevIns, &pThis->CritSect);
|
---|
3524 | return VINF_SUCCESS;
|
---|
3525 | }
|
---|
3526 |
|
---|
3527 | /**
|
---|
3528 | * @interface_method_impl{PDMIVMMDEVPORT,pfnQueryMouseCapabilities}
|
---|
3529 | */
|
---|
3530 | static DECLCALLBACK(int) vmmdevIPort_QueryMouseCapabilities(PPDMIVMMDEVPORT pInterface, uint32_t *pfCapabilities)
|
---|
3531 | {
|
---|
3532 | PVMMDEVCC pThisCC = RT_FROM_MEMBER(pInterface, VMMDEVCC, IPort);
|
---|
3533 | PVMMDEV pThis = PDMDEVINS_2_DATA(pThisCC->pDevIns, PVMMDEV);
|
---|
3534 | AssertPtrReturn(pfCapabilities, VERR_INVALID_PARAMETER);
|
---|
3535 |
|
---|
3536 | *pfCapabilities = pThis->fMouseCapabilities;
|
---|
3537 | return VINF_SUCCESS;
|
---|
3538 | }
|
---|
3539 |
|
---|
3540 | /**
|
---|
3541 | * @interface_method_impl{PDMIVMMDEVPORT,pfnUpdateMouseCapabilities}
|
---|
3542 | */
|
---|
3543 | static DECLCALLBACK(int)
|
---|
3544 | vmmdevIPort_UpdateMouseCapabilities(PPDMIVMMDEVPORT pInterface, uint32_t fCapsAdded, uint32_t fCapsRemoved)
|
---|
3545 | {
|
---|
3546 | PVMMDEVCC pThisCC = RT_FROM_MEMBER(pInterface, VMMDEVCC, IPort);
|
---|
3547 | PPDMDEVINS pDevIns = pThisCC->pDevIns;
|
---|
3548 | PVMMDEV pThis = PDMDEVINS_2_DATA(pDevIns, PVMMDEV);
|
---|
3549 | PDMDevHlpCritSectEnter(pDevIns, &pThis->CritSect, VERR_IGNORED);
|
---|
3550 |
|
---|
3551 | uint32_t fOldCaps = pThis->fMouseCapabilities;
|
---|
3552 | pThis->fMouseCapabilities &= ~(fCapsRemoved & VMMDEV_MOUSE_HOST_MASK);
|
---|
3553 | pThis->fMouseCapabilities |= (fCapsAdded & VMMDEV_MOUSE_HOST_MASK)
|
---|
3554 | | VMMDEV_MOUSE_HOST_RECHECKS_NEEDS_HOST_CURSOR;
|
---|
3555 | bool fNotify = fOldCaps != pThis->fMouseCapabilities;
|
---|
3556 |
|
---|
3557 | LogRelFlow(("VMMDev: vmmdevIPort_UpdateMouseCapabilities: fCapsAdded=0x%x, fCapsRemoved=0x%x, fNotify=%RTbool\n", fCapsAdded,
|
---|
3558 | fCapsRemoved, fNotify));
|
---|
3559 |
|
---|
3560 | if (fNotify)
|
---|
3561 | VMMDevNotifyGuest(pDevIns, pThis, pThisCC, VMMDEV_EVENT_MOUSE_CAPABILITIES_CHANGED);
|
---|
3562 |
|
---|
3563 | PDMDevHlpCritSectLeave(pDevIns, &pThis->CritSect);
|
---|
3564 | return VINF_SUCCESS;
|
---|
3565 | }
|
---|
3566 |
|
---|
3567 | static bool vmmdevIsMonitorDefEqual(VMMDevDisplayDef const *pNew, VMMDevDisplayDef const *pOld)
|
---|
3568 | {
|
---|
3569 | bool fEqual = pNew->idDisplay == pOld->idDisplay;
|
---|
3570 |
|
---|
3571 | fEqual = fEqual && ( !RT_BOOL(pNew->fDisplayFlags & VMMDEV_DISPLAY_ORIGIN) /* No change. */
|
---|
3572 | || ( RT_BOOL(pOld->fDisplayFlags & VMMDEV_DISPLAY_ORIGIN) /* Old value exists and */
|
---|
3573 | && pNew->xOrigin == pOld->xOrigin /* the old is equal to the new. */
|
---|
3574 | && pNew->yOrigin == pOld->yOrigin));
|
---|
3575 |
|
---|
3576 | fEqual = fEqual && ( !RT_BOOL(pNew->fDisplayFlags & VMMDEV_DISPLAY_CX)
|
---|
3577 | || ( RT_BOOL(pOld->fDisplayFlags & VMMDEV_DISPLAY_CX)
|
---|
3578 | && pNew->cx == pOld->cx));
|
---|
3579 |
|
---|
3580 | fEqual = fEqual && ( !RT_BOOL(pNew->fDisplayFlags & VMMDEV_DISPLAY_CY)
|
---|
3581 | || ( RT_BOOL(pOld->fDisplayFlags & VMMDEV_DISPLAY_CY)
|
---|
3582 | && pNew->cy == pOld->cy));
|
---|
3583 |
|
---|
3584 | fEqual = fEqual && ( !RT_BOOL(pNew->fDisplayFlags & VMMDEV_DISPLAY_BPP)
|
---|
3585 | || ( RT_BOOL(pOld->fDisplayFlags & VMMDEV_DISPLAY_BPP)
|
---|
3586 | && pNew->cBitsPerPixel == pOld->cBitsPerPixel));
|
---|
3587 |
|
---|
3588 | fEqual = fEqual && ( RT_BOOL(pNew->fDisplayFlags & VMMDEV_DISPLAY_DISABLED)
|
---|
3589 | == RT_BOOL(pOld->fDisplayFlags & VMMDEV_DISPLAY_DISABLED));
|
---|
3590 |
|
---|
3591 | fEqual = fEqual && ( RT_BOOL(pNew->fDisplayFlags & VMMDEV_DISPLAY_PRIMARY)
|
---|
3592 | == RT_BOOL(pOld->fDisplayFlags & VMMDEV_DISPLAY_PRIMARY));
|
---|
3593 |
|
---|
3594 | return fEqual;
|
---|
3595 | }
|
---|
3596 |
|
---|
3597 | /**
|
---|
3598 | * @interface_method_impl{PDMIVMMDEVPORT,pfnRequestDisplayChange}
|
---|
3599 | */
|
---|
3600 | static DECLCALLBACK(int)
|
---|
3601 | vmmdevIPort_RequestDisplayChange(PPDMIVMMDEVPORT pInterface, uint32_t cDisplays, VMMDevDisplayDef const *paDisplays, bool fForce, bool fMayNotify)
|
---|
3602 | {
|
---|
3603 | PVMMDEVCC pThisCC = RT_FROM_MEMBER(pInterface, VMMDEVCC, IPort);
|
---|
3604 | PPDMDEVINS pDevIns = pThisCC->pDevIns;
|
---|
3605 | PVMMDEV pThis = PDMDEVINS_2_DATA(pDevIns, PVMMDEV);
|
---|
3606 | int rc = VINF_SUCCESS;
|
---|
3607 | bool fNotifyGuest = false;
|
---|
3608 |
|
---|
3609 | PDMDevHlpCritSectEnter(pDevIns, &pThis->CritSect, VERR_IGNORED);
|
---|
3610 |
|
---|
3611 | uint32_t i;
|
---|
3612 | for (i = 0; i < cDisplays; ++i)
|
---|
3613 | {
|
---|
3614 | VMMDevDisplayDef const *p = &paDisplays[i];
|
---|
3615 |
|
---|
3616 | /* Either one display definition is provided or the display id must be equal to the array index. */
|
---|
3617 | AssertBreakStmt(cDisplays == 1 || p->idDisplay == i, rc = VERR_INVALID_PARAMETER);
|
---|
3618 | AssertBreakStmt(p->idDisplay < RT_ELEMENTS(pThis->displayChangeData.aRequests), rc = VERR_INVALID_PARAMETER);
|
---|
3619 |
|
---|
3620 | DISPLAYCHANGEREQUEST *pRequest = &pThis->displayChangeData.aRequests[p->idDisplay];
|
---|
3621 |
|
---|
3622 | VMMDevDisplayDef const *pLastRead = &pRequest->lastReadDisplayChangeRequest;
|
---|
3623 |
|
---|
3624 | /* Verify that the new resolution is different and that guest does not yet know about it. */
|
---|
3625 | bool const fDifferentResolution = fForce || !vmmdevIsMonitorDefEqual(p, pLastRead);
|
---|
3626 |
|
---|
3627 | LogFunc(("same=%d. New: %dx%d, cBits=%d, id=%d. Old: %dx%d, cBits=%d, id=%d. @%d,%d, Enabled=%d, ChangeOrigin=%d\n",
|
---|
3628 | !fDifferentResolution, p->cx, p->cy, p->cBitsPerPixel, p->idDisplay,
|
---|
3629 | pLastRead->cx, pLastRead->cy, pLastRead->cBitsPerPixel, pLastRead->idDisplay,
|
---|
3630 | p->xOrigin, p->yOrigin,
|
---|
3631 | !RT_BOOL(p->fDisplayFlags & VMMDEV_DISPLAY_DISABLED),
|
---|
3632 | RT_BOOL(p->fDisplayFlags & VMMDEV_DISPLAY_ORIGIN)));
|
---|
3633 |
|
---|
3634 | /* We could validate the information here but hey, the guest can do that as well! */
|
---|
3635 | pRequest->displayChangeRequest = *p;
|
---|
3636 | pRequest->fPending = fDifferentResolution && fMayNotify;
|
---|
3637 |
|
---|
3638 | fNotifyGuest = fNotifyGuest || fDifferentResolution;
|
---|
3639 | }
|
---|
3640 |
|
---|
3641 | if (RT_SUCCESS(rc) && fMayNotify)
|
---|
3642 | {
|
---|
3643 | if (fNotifyGuest)
|
---|
3644 | {
|
---|
3645 | for (i = 0; i < RT_ELEMENTS(pThis->displayChangeData.aRequests); ++i)
|
---|
3646 | {
|
---|
3647 | DISPLAYCHANGEREQUEST *pRequest = &pThis->displayChangeData.aRequests[i];
|
---|
3648 | if (pRequest->fPending)
|
---|
3649 | {
|
---|
3650 | VMMDevDisplayDef const *p = &pRequest->displayChangeRequest;
|
---|
3651 | LogRel(("VMMDev: SetVideoModeHint: Got a video mode hint (%dx%dx%d)@(%dx%d),(%d;%d) at %d\n",
|
---|
3652 | p->cx, p->cy, p->cBitsPerPixel, p->xOrigin, p->yOrigin,
|
---|
3653 | !RT_BOOL(p->fDisplayFlags & VMMDEV_DISPLAY_DISABLED),
|
---|
3654 | RT_BOOL(p->fDisplayFlags & VMMDEV_DISPLAY_ORIGIN), i));
|
---|
3655 | }
|
---|
3656 | }
|
---|
3657 |
|
---|
3658 | /* IRQ so the guest knows what's going on */
|
---|
3659 | VMMDevNotifyGuest(pDevIns, pThis, pThisCC, VMMDEV_EVENT_DISPLAY_CHANGE_REQUEST);
|
---|
3660 | }
|
---|
3661 | }
|
---|
3662 |
|
---|
3663 | PDMDevHlpCritSectLeave(pDevIns, &pThis->CritSect);
|
---|
3664 | return rc;
|
---|
3665 | }
|
---|
3666 |
|
---|
3667 | /**
|
---|
3668 | * @interface_method_impl{PDMIVMMDEVPORT,pfnRequestSeamlessChange}
|
---|
3669 | */
|
---|
3670 | static DECLCALLBACK(int) vmmdevIPort_RequestSeamlessChange(PPDMIVMMDEVPORT pInterface, bool fEnabled)
|
---|
3671 | {
|
---|
3672 | PVMMDEVCC pThisCC = RT_FROM_MEMBER(pInterface, VMMDEVCC, IPort);
|
---|
3673 | PPDMDEVINS pDevIns = pThisCC->pDevIns;
|
---|
3674 | PVMMDEV pThis = PDMDEVINS_2_DATA(pDevIns, PVMMDEV);
|
---|
3675 | PDMDevHlpCritSectEnter(pDevIns, &pThis->CritSect, VERR_IGNORED);
|
---|
3676 |
|
---|
3677 | /* Verify that the new resolution is different and that guest does not yet know about it. */
|
---|
3678 | bool fSameMode = (pThis->fLastSeamlessEnabled == fEnabled);
|
---|
3679 |
|
---|
3680 | Log(("vmmdevIPort_RequestSeamlessChange: same=%d. new=%d\n", fSameMode, fEnabled));
|
---|
3681 |
|
---|
3682 | if (!fSameMode)
|
---|
3683 | {
|
---|
3684 | /* we could validate the information here but hey, the guest can do that as well! */
|
---|
3685 | pThis->fSeamlessEnabled = fEnabled;
|
---|
3686 |
|
---|
3687 | /* IRQ so the guest knows what's going on */
|
---|
3688 | VMMDevNotifyGuest(pDevIns, pThis, pThisCC, VMMDEV_EVENT_SEAMLESS_MODE_CHANGE_REQUEST);
|
---|
3689 | }
|
---|
3690 |
|
---|
3691 | PDMDevHlpCritSectLeave(pDevIns, &pThis->CritSect);
|
---|
3692 | return VINF_SUCCESS;
|
---|
3693 | }
|
---|
3694 |
|
---|
3695 | /**
|
---|
3696 | * @interface_method_impl{PDMIVMMDEVPORT,pfnSetMemoryBalloon}
|
---|
3697 | */
|
---|
3698 | static DECLCALLBACK(int) vmmdevIPort_SetMemoryBalloon(PPDMIVMMDEVPORT pInterface, uint32_t cMbBalloon)
|
---|
3699 | {
|
---|
3700 | PVMMDEVCC pThisCC = RT_FROM_MEMBER(pInterface, VMMDEVCC, IPort);
|
---|
3701 | PPDMDEVINS pDevIns = pThisCC->pDevIns;
|
---|
3702 | PVMMDEV pThis = PDMDEVINS_2_DATA(pDevIns, PVMMDEV);
|
---|
3703 | PDMDevHlpCritSectEnter(pDevIns, &pThis->CritSect, VERR_IGNORED);
|
---|
3704 |
|
---|
3705 | /* Verify that the new resolution is different and that guest does not yet know about it. */
|
---|
3706 | Log(("vmmdevIPort_SetMemoryBalloon: old=%u new=%u\n", pThis->cMbMemoryBalloonLast, cMbBalloon));
|
---|
3707 | if (pThis->cMbMemoryBalloonLast != cMbBalloon)
|
---|
3708 | {
|
---|
3709 | /* we could validate the information here but hey, the guest can do that as well! */
|
---|
3710 | pThis->cMbMemoryBalloon = cMbBalloon;
|
---|
3711 |
|
---|
3712 | /* IRQ so the guest knows what's going on */
|
---|
3713 | VMMDevNotifyGuest(pDevIns, pThis, pThisCC, VMMDEV_EVENT_BALLOON_CHANGE_REQUEST);
|
---|
3714 | }
|
---|
3715 |
|
---|
3716 | PDMDevHlpCritSectLeave(pDevIns, &pThis->CritSect);
|
---|
3717 | return VINF_SUCCESS;
|
---|
3718 | }
|
---|
3719 |
|
---|
3720 | /**
|
---|
3721 | * @interface_method_impl{PDMIVMMDEVPORT,pfnVRDPChange}
|
---|
3722 | */
|
---|
3723 | static DECLCALLBACK(int) vmmdevIPort_VRDPChange(PPDMIVMMDEVPORT pInterface, bool fVRDPEnabled, uint32_t uVRDPExperienceLevel)
|
---|
3724 | {
|
---|
3725 | PVMMDEVCC pThisCC = RT_FROM_MEMBER(pInterface, VMMDEVCC, IPort);
|
---|
3726 | PPDMDEVINS pDevIns = pThisCC->pDevIns;
|
---|
3727 | PVMMDEV pThis = PDMDEVINS_2_DATA(pDevIns, PVMMDEV);
|
---|
3728 | PDMDevHlpCritSectEnter(pDevIns, &pThis->CritSect, VERR_IGNORED);
|
---|
3729 |
|
---|
3730 | bool fSame = (pThis->fVRDPEnabled == fVRDPEnabled);
|
---|
3731 |
|
---|
3732 | Log(("vmmdevIPort_VRDPChange: old=%d. new=%d\n", pThis->fVRDPEnabled, fVRDPEnabled));
|
---|
3733 |
|
---|
3734 | if (!fSame)
|
---|
3735 | {
|
---|
3736 | pThis->fVRDPEnabled = fVRDPEnabled;
|
---|
3737 | pThis->uVRDPExperienceLevel = uVRDPExperienceLevel;
|
---|
3738 |
|
---|
3739 | VMMDevNotifyGuest(pDevIns, pThis, pThisCC, VMMDEV_EVENT_VRDP);
|
---|
3740 | }
|
---|
3741 |
|
---|
3742 | PDMDevHlpCritSectLeave(pDevIns, &pThis->CritSect);
|
---|
3743 | return VINF_SUCCESS;
|
---|
3744 | }
|
---|
3745 |
|
---|
3746 | /**
|
---|
3747 | * @interface_method_impl{PDMIVMMDEVPORT,pfnSetStatisticsInterval}
|
---|
3748 | */
|
---|
3749 | static DECLCALLBACK(int) vmmdevIPort_SetStatisticsInterval(PPDMIVMMDEVPORT pInterface, uint32_t cSecsStatInterval)
|
---|
3750 | {
|
---|
3751 | PVMMDEVCC pThisCC = RT_FROM_MEMBER(pInterface, VMMDEVCC, IPort);
|
---|
3752 | PPDMDEVINS pDevIns = pThisCC->pDevIns;
|
---|
3753 | PVMMDEV pThis = PDMDEVINS_2_DATA(pDevIns, PVMMDEV);
|
---|
3754 | PDMDevHlpCritSectEnter(pDevIns, &pThis->CritSect, VERR_IGNORED);
|
---|
3755 |
|
---|
3756 | /* Verify that the new resolution is different and that guest does not yet know about it. */
|
---|
3757 | bool fSame = (pThis->cSecsLastStatInterval == cSecsStatInterval);
|
---|
3758 |
|
---|
3759 | Log(("vmmdevIPort_SetStatisticsInterval: old=%d. new=%d\n", pThis->cSecsLastStatInterval, cSecsStatInterval));
|
---|
3760 |
|
---|
3761 | if (!fSame)
|
---|
3762 | {
|
---|
3763 | /* we could validate the information here but hey, the guest can do that as well! */
|
---|
3764 | pThis->cSecsStatInterval = cSecsStatInterval;
|
---|
3765 |
|
---|
3766 | /* IRQ so the guest knows what's going on */
|
---|
3767 | VMMDevNotifyGuest(pDevIns, pThis, pThisCC, VMMDEV_EVENT_STATISTICS_INTERVAL_CHANGE_REQUEST);
|
---|
3768 | }
|
---|
3769 |
|
---|
3770 | PDMDevHlpCritSectLeave(pDevIns, &pThis->CritSect);
|
---|
3771 | return VINF_SUCCESS;
|
---|
3772 | }
|
---|
3773 |
|
---|
3774 | /**
|
---|
3775 | * @interface_method_impl{PDMIVMMDEVPORT,pfnSetCredentials}
|
---|
3776 | */
|
---|
3777 | static DECLCALLBACK(int) vmmdevIPort_SetCredentials(PPDMIVMMDEVPORT pInterface, const char *pszUsername,
|
---|
3778 | const char *pszPassword, const char *pszDomain, uint32_t fFlags)
|
---|
3779 | {
|
---|
3780 | PVMMDEVCC pThisCC = RT_FROM_MEMBER(pInterface, VMMDEVCC, IPort);
|
---|
3781 | PPDMDEVINS pDevIns = pThisCC->pDevIns;
|
---|
3782 | PVMMDEV pThis = PDMDEVINS_2_DATA(pDevIns, PVMMDEV);
|
---|
3783 |
|
---|
3784 | AssertReturn(fFlags & (VMMDEV_SETCREDENTIALS_GUESTLOGON | VMMDEV_SETCREDENTIALS_JUDGE), VERR_INVALID_PARAMETER);
|
---|
3785 | size_t const cchUsername = strlen(pszUsername);
|
---|
3786 | AssertReturn(cchUsername < VMMDEV_CREDENTIALS_SZ_SIZE, VERR_BUFFER_OVERFLOW);
|
---|
3787 | size_t const cchPassword = strlen(pszPassword);
|
---|
3788 | AssertReturn(cchPassword < VMMDEV_CREDENTIALS_SZ_SIZE, VERR_BUFFER_OVERFLOW);
|
---|
3789 | size_t const cchDomain = strlen(pszDomain);
|
---|
3790 | AssertReturn(cchDomain < VMMDEV_CREDENTIALS_SZ_SIZE, VERR_BUFFER_OVERFLOW);
|
---|
3791 |
|
---|
3792 | VMMDEVCREDS *pCredentials = pThisCC->pCredentials;
|
---|
3793 | AssertPtrReturn(pCredentials, VERR_NOT_SUPPORTED);
|
---|
3794 |
|
---|
3795 | PDMDevHlpCritSectEnter(pDevIns, &pThis->CritSect, VERR_IGNORED);
|
---|
3796 |
|
---|
3797 | /*
|
---|
3798 | * Logon mode
|
---|
3799 | */
|
---|
3800 | if (fFlags & VMMDEV_SETCREDENTIALS_GUESTLOGON)
|
---|
3801 | {
|
---|
3802 | /* memorize the data */
|
---|
3803 | memcpy(pCredentials->Logon.szUserName, pszUsername, cchUsername);
|
---|
3804 | pThisCC->pCredentials->Logon.szUserName[cchUsername] = '\0';
|
---|
3805 | memcpy(pCredentials->Logon.szPassword, pszPassword, cchPassword);
|
---|
3806 | pCredentials->Logon.szPassword[cchPassword] = '\0';
|
---|
3807 | memcpy(pCredentials->Logon.szDomain, pszDomain, cchDomain);
|
---|
3808 | pCredentials->Logon.szDomain[cchDomain] = '\0';
|
---|
3809 | pCredentials->Logon.fAllowInteractiveLogon = !(fFlags & VMMDEV_SETCREDENTIALS_NOLOCALLOGON);
|
---|
3810 | }
|
---|
3811 | /*
|
---|
3812 | * Credentials verification mode?
|
---|
3813 | */
|
---|
3814 | else
|
---|
3815 | {
|
---|
3816 | /* memorize the data */
|
---|
3817 | memcpy(pCredentials->Judge.szUserName, pszUsername, cchUsername);
|
---|
3818 | pCredentials->Judge.szUserName[cchUsername] = '\0';
|
---|
3819 | memcpy(pCredentials->Judge.szPassword, pszPassword, cchPassword);
|
---|
3820 | pCredentials->Judge.szPassword[cchPassword] = '\0';
|
---|
3821 | memcpy(pCredentials->Judge.szDomain, pszDomain, cchDomain);
|
---|
3822 | pCredentials->Judge.szDomain[cchDomain] = '\0';
|
---|
3823 |
|
---|
3824 | VMMDevNotifyGuest(pDevIns, pThis, pThisCC, VMMDEV_EVENT_JUDGE_CREDENTIALS);
|
---|
3825 | }
|
---|
3826 |
|
---|
3827 | PDMDevHlpCritSectLeave(pDevIns, &pThis->CritSect);
|
---|
3828 | return VINF_SUCCESS;
|
---|
3829 | }
|
---|
3830 |
|
---|
3831 | /**
|
---|
3832 | * @interface_method_impl{PDMIVMMDEVPORT,pfnVBVAChange}
|
---|
3833 | *
|
---|
3834 | * Notification from the Display. Especially useful when acceleration is
|
---|
3835 | * disabled after a video mode change.
|
---|
3836 | */
|
---|
3837 | static DECLCALLBACK(void) vmmdevIPort_VBVAChange(PPDMIVMMDEVPORT pInterface, bool fEnabled)
|
---|
3838 | {
|
---|
3839 | PVMMDEVCC pThisCC = RT_FROM_MEMBER(pInterface, VMMDEVCC, IPort);
|
---|
3840 | PVMMDEV pThis = PDMDEVINS_2_DATA(pThisCC->pDevIns, PVMMDEV);
|
---|
3841 | Log(("vmmdevIPort_VBVAChange: fEnabled = %d\n", fEnabled));
|
---|
3842 |
|
---|
3843 | /* Only used by saved state, which I guess is why we don't bother with locking here. */
|
---|
3844 | pThis->u32VideoAccelEnabled = fEnabled;
|
---|
3845 | }
|
---|
3846 |
|
---|
3847 | /**
|
---|
3848 | * @interface_method_impl{PDMIVMMDEVPORT,pfnCpuHotUnplug}
|
---|
3849 | */
|
---|
3850 | static DECLCALLBACK(int) vmmdevIPort_CpuHotUnplug(PPDMIVMMDEVPORT pInterface, uint32_t idCpuCore, uint32_t idCpuPackage)
|
---|
3851 | {
|
---|
3852 | PVMMDEVCC pThisCC = RT_FROM_MEMBER(pInterface, VMMDEVCC, IPort);
|
---|
3853 | PPDMDEVINS pDevIns = pThisCC->pDevIns;
|
---|
3854 | PVMMDEV pThis = PDMDEVINS_2_DATA(pDevIns, PVMMDEV);
|
---|
3855 | int rc = VINF_SUCCESS;
|
---|
3856 |
|
---|
3857 | Log(("vmmdevIPort_CpuHotUnplug: idCpuCore=%u idCpuPackage=%u\n", idCpuCore, idCpuPackage));
|
---|
3858 |
|
---|
3859 | PDMDevHlpCritSectEnter(pDevIns, &pThis->CritSect, VERR_IGNORED);
|
---|
3860 |
|
---|
3861 | if (pThis->fCpuHotPlugEventsEnabled)
|
---|
3862 | {
|
---|
3863 | pThis->enmCpuHotPlugEvent = VMMDevCpuEventType_Unplug;
|
---|
3864 | pThis->idCpuCore = idCpuCore;
|
---|
3865 | pThis->idCpuPackage = idCpuPackage;
|
---|
3866 | VMMDevNotifyGuest(pDevIns, pThis, pThisCC, VMMDEV_EVENT_CPU_HOTPLUG);
|
---|
3867 | }
|
---|
3868 | else
|
---|
3869 | rc = VERR_VMMDEV_CPU_HOTPLUG_NOT_MONITORED_BY_GUEST;
|
---|
3870 |
|
---|
3871 | PDMDevHlpCritSectLeave(pDevIns, &pThis->CritSect);
|
---|
3872 | return rc;
|
---|
3873 | }
|
---|
3874 |
|
---|
3875 | /**
|
---|
3876 | * @interface_method_impl{PDMIVMMDEVPORT,pfnCpuHotPlug}
|
---|
3877 | */
|
---|
3878 | static DECLCALLBACK(int) vmmdevIPort_CpuHotPlug(PPDMIVMMDEVPORT pInterface, uint32_t idCpuCore, uint32_t idCpuPackage)
|
---|
3879 | {
|
---|
3880 | PVMMDEVCC pThisCC = RT_FROM_MEMBER(pInterface, VMMDEVCC, IPort);
|
---|
3881 | PPDMDEVINS pDevIns = pThisCC->pDevIns;
|
---|
3882 | PVMMDEV pThis = PDMDEVINS_2_DATA(pDevIns, PVMMDEV);
|
---|
3883 | int rc = VINF_SUCCESS;
|
---|
3884 |
|
---|
3885 | Log(("vmmdevCpuPlug: idCpuCore=%u idCpuPackage=%u\n", idCpuCore, idCpuPackage));
|
---|
3886 |
|
---|
3887 | PDMDevHlpCritSectEnter(pDevIns, &pThis->CritSect, VERR_IGNORED);
|
---|
3888 |
|
---|
3889 | if (pThis->fCpuHotPlugEventsEnabled)
|
---|
3890 | {
|
---|
3891 | pThis->enmCpuHotPlugEvent = VMMDevCpuEventType_Plug;
|
---|
3892 | pThis->idCpuCore = idCpuCore;
|
---|
3893 | pThis->idCpuPackage = idCpuPackage;
|
---|
3894 | VMMDevNotifyGuest(pDevIns, pThis, pThisCC, VMMDEV_EVENT_CPU_HOTPLUG);
|
---|
3895 | }
|
---|
3896 | else
|
---|
3897 | rc = VERR_VMMDEV_CPU_HOTPLUG_NOT_MONITORED_BY_GUEST;
|
---|
3898 |
|
---|
3899 | PDMDevHlpCritSectLeave(pDevIns, &pThis->CritSect);
|
---|
3900 | return rc;
|
---|
3901 | }
|
---|
3902 |
|
---|
3903 |
|
---|
3904 | /* -=-=-=-=-=- Saved State -=-=-=-=-=- */
|
---|
3905 |
|
---|
3906 | /**
|
---|
3907 | * @callback_method_impl{FNSSMDEVLIVEEXEC}
|
---|
3908 | */
|
---|
3909 | static DECLCALLBACK(int) vmmdevLiveExec(PPDMDEVINS pDevIns, PSSMHANDLE pSSM, uint32_t uPass)
|
---|
3910 | {
|
---|
3911 | RT_NOREF(uPass);
|
---|
3912 | PVMMDEV pThis = PDMDEVINS_2_DATA(pDevIns, PVMMDEV);
|
---|
3913 |
|
---|
3914 | SSMR3PutBool(pSSM, pThis->fGetHostTimeDisabled);
|
---|
3915 | SSMR3PutBool(pSSM, pThis->fBackdoorLogDisabled);
|
---|
3916 | SSMR3PutBool(pSSM, pThis->fKeepCredentials);
|
---|
3917 | SSMR3PutBool(pSSM, pThis->fHeapEnabled);
|
---|
3918 |
|
---|
3919 | return VINF_SSM_DONT_CALL_AGAIN;
|
---|
3920 | }
|
---|
3921 |
|
---|
3922 |
|
---|
3923 | /**
|
---|
3924 | * @callback_method_impl{FNSSMDEVSAVEEXEC}
|
---|
3925 | */
|
---|
3926 | static DECLCALLBACK(int) vmmdevSaveExec(PPDMDEVINS pDevIns, PSSMHANDLE pSSM)
|
---|
3927 | {
|
---|
3928 | PVMMDEV pThis = PDMDEVINS_2_DATA(pDevIns, PVMMDEV);
|
---|
3929 | PVMMDEVCC pThisCC = PDMDEVINS_2_DATA_CC(pDevIns, PVMMDEVCC);
|
---|
3930 | PCPDMDEVHLPR3 pHlp = pDevIns->pHlpR3;
|
---|
3931 | PDMDevHlpCritSectEnter(pDevIns, &pThis->CritSect, VERR_IGNORED);
|
---|
3932 |
|
---|
3933 | vmmdevLiveExec(pDevIns, pSSM, SSM_PASS_FINAL);
|
---|
3934 |
|
---|
3935 | pHlp->pfnSSMPutU32(pSSM, 0 /*was pThis->hypervisorSize, which was always zero*/);
|
---|
3936 | pHlp->pfnSSMPutU32(pSSM, pThis->fMouseCapabilities);
|
---|
3937 | pHlp->pfnSSMPutS32(pSSM, pThis->xMouseAbs);
|
---|
3938 | pHlp->pfnSSMPutS32(pSSM, pThis->yMouseAbs);
|
---|
3939 |
|
---|
3940 | pHlp->pfnSSMPutBool(pSSM, pThis->fNewGuestFilterMaskValid);
|
---|
3941 | pHlp->pfnSSMPutU32(pSSM, pThis->fNewGuestFilterMask);
|
---|
3942 | pHlp->pfnSSMPutU32(pSSM, pThis->fGuestFilterMask);
|
---|
3943 | pHlp->pfnSSMPutU32(pSSM, pThis->fHostEventFlags);
|
---|
3944 | /* The following is not strictly necessary as PGM restores MMIO2, keeping it for historical reasons. */
|
---|
3945 | pHlp->pfnSSMPutMem(pSSM, &pThisCC->pVMMDevRAMR3->V, sizeof(pThisCC->pVMMDevRAMR3->V));
|
---|
3946 |
|
---|
3947 | pHlp->pfnSSMPutMem(pSSM, &pThis->guestInfo, sizeof(pThis->guestInfo));
|
---|
3948 | pHlp->pfnSSMPutU32(pSSM, pThis->fu32AdditionsOk);
|
---|
3949 | pHlp->pfnSSMPutU32(pSSM, pThis->u32VideoAccelEnabled);
|
---|
3950 | pHlp->pfnSSMPutBool(pSSM, pThis->displayChangeData.fGuestSentChangeEventAck);
|
---|
3951 |
|
---|
3952 | pHlp->pfnSSMPutU32(pSSM, pThis->fGuestCaps);
|
---|
3953 |
|
---|
3954 | #ifdef VBOX_WITH_HGCM
|
---|
3955 | vmmdevR3HgcmSaveState(pThisCC, pSSM);
|
---|
3956 | #endif /* VBOX_WITH_HGCM */
|
---|
3957 |
|
---|
3958 | pHlp->pfnSSMPutU32(pSSM, pThis->fHostCursorRequested);
|
---|
3959 |
|
---|
3960 | pHlp->pfnSSMPutU32(pSSM, pThis->guestInfo2.uFullVersion);
|
---|
3961 | pHlp->pfnSSMPutU32(pSSM, pThis->guestInfo2.uRevision);
|
---|
3962 | pHlp->pfnSSMPutU32(pSSM, pThis->guestInfo2.fFeatures);
|
---|
3963 | pHlp->pfnSSMPutStrZ(pSSM, pThis->guestInfo2.szName);
|
---|
3964 | pHlp->pfnSSMPutU32(pSSM, pThis->cFacilityStatuses);
|
---|
3965 | for (uint32_t i = 0; i < pThis->cFacilityStatuses; i++)
|
---|
3966 | {
|
---|
3967 | pHlp->pfnSSMPutU32(pSSM, pThis->aFacilityStatuses[i].enmFacility);
|
---|
3968 | pHlp->pfnSSMPutU32(pSSM, pThis->aFacilityStatuses[i].fFlags);
|
---|
3969 | pHlp->pfnSSMPutU16(pSSM, (uint16_t)pThis->aFacilityStatuses[i].enmStatus);
|
---|
3970 | pHlp->pfnSSMPutS64(pSSM, RTTimeSpecGetNano(&pThis->aFacilityStatuses[i].TimeSpecTS));
|
---|
3971 | }
|
---|
3972 |
|
---|
3973 | /* Heartbeat: */
|
---|
3974 | pHlp->pfnSSMPutBool(pSSM, pThis->fHeartbeatActive);
|
---|
3975 | pHlp->pfnSSMPutBool(pSSM, pThis->fFlatlined);
|
---|
3976 | pHlp->pfnSSMPutU64(pSSM, pThis->nsLastHeartbeatTS);
|
---|
3977 | PDMDevHlpTimerSave(pDevIns, pThis->hFlatlinedTimer, pSSM);
|
---|
3978 |
|
---|
3979 | PDMDevHlpCritSectLeave(pDevIns, &pThis->CritSect);
|
---|
3980 | return VINF_SUCCESS;
|
---|
3981 | }
|
---|
3982 |
|
---|
3983 | /**
|
---|
3984 | * @callback_method_impl{FNSSMDEVLOADEXEC}
|
---|
3985 | */
|
---|
3986 | static DECLCALLBACK(int) vmmdevLoadExec(PPDMDEVINS pDevIns, PSSMHANDLE pSSM, uint32_t uVersion, uint32_t uPass)
|
---|
3987 | {
|
---|
3988 | PVMMDEV pThis = PDMDEVINS_2_DATA(pDevIns, PVMMDEV);
|
---|
3989 | PVMMDEVCC pThisCC = PDMDEVINS_2_DATA_CC(pDevIns, PVMMDEVCC);
|
---|
3990 | PCPDMDEVHLPR3 pHlp = pDevIns->pHlpR3;
|
---|
3991 | int rc;
|
---|
3992 |
|
---|
3993 | if ( uVersion > VMMDEV_SAVED_STATE_VERSION
|
---|
3994 | || uVersion < 6)
|
---|
3995 | return VERR_SSM_UNSUPPORTED_DATA_UNIT_VERSION;
|
---|
3996 |
|
---|
3997 | /* config */
|
---|
3998 | if (uVersion > VMMDEV_SAVED_STATE_VERSION_VBOX_30)
|
---|
3999 | {
|
---|
4000 | bool f;
|
---|
4001 | rc = pHlp->pfnSSMGetBool(pSSM, &f); AssertRCReturn(rc, rc);
|
---|
4002 | if (pThis->fGetHostTimeDisabled != f)
|
---|
4003 | LogRel(("VMMDev: Config mismatch - fGetHostTimeDisabled: config=%RTbool saved=%RTbool\n", pThis->fGetHostTimeDisabled, f));
|
---|
4004 |
|
---|
4005 | rc = pHlp->pfnSSMGetBool(pSSM, &f); AssertRCReturn(rc, rc);
|
---|
4006 | if (pThis->fBackdoorLogDisabled != f)
|
---|
4007 | LogRel(("VMMDev: Config mismatch - fBackdoorLogDisabled: config=%RTbool saved=%RTbool\n", pThis->fBackdoorLogDisabled, f));
|
---|
4008 |
|
---|
4009 | rc = pHlp->pfnSSMGetBool(pSSM, &f); AssertRCReturn(rc, rc);
|
---|
4010 | if (pThis->fKeepCredentials != f)
|
---|
4011 | return pHlp->pfnSSMSetCfgError(pSSM, RT_SRC_POS, N_("Config mismatch - fKeepCredentials: config=%RTbool saved=%RTbool"),
|
---|
4012 | pThis->fKeepCredentials, f);
|
---|
4013 | rc = pHlp->pfnSSMGetBool(pSSM, &f); AssertRCReturn(rc, rc);
|
---|
4014 | if (pThis->fHeapEnabled != f)
|
---|
4015 | return pHlp->pfnSSMSetCfgError(pSSM, RT_SRC_POS, N_("Config mismatch - fHeapEnabled: config=%RTbool saved=%RTbool"),
|
---|
4016 | pThis->fHeapEnabled, f);
|
---|
4017 | }
|
---|
4018 |
|
---|
4019 | if (uPass != SSM_PASS_FINAL)
|
---|
4020 | return VINF_SUCCESS;
|
---|
4021 |
|
---|
4022 | /* state */
|
---|
4023 | uint32_t uIgn;
|
---|
4024 | pHlp->pfnSSMGetU32(pSSM, &uIgn);
|
---|
4025 | pHlp->pfnSSMGetU32(pSSM, &pThis->fMouseCapabilities);
|
---|
4026 | pHlp->pfnSSMGetS32(pSSM, &pThis->xMouseAbs);
|
---|
4027 | pHlp->pfnSSMGetS32(pSSM, &pThis->yMouseAbs);
|
---|
4028 |
|
---|
4029 | pHlp->pfnSSMGetBool(pSSM, &pThis->fNewGuestFilterMaskValid);
|
---|
4030 | pHlp->pfnSSMGetU32(pSSM, &pThis->fNewGuestFilterMask);
|
---|
4031 | pHlp->pfnSSMGetU32(pSSM, &pThis->fGuestFilterMask);
|
---|
4032 | pHlp->pfnSSMGetU32(pSSM, &pThis->fHostEventFlags);
|
---|
4033 |
|
---|
4034 | //pHlp->pfnSSMGetBool(pSSM, &pThis->pVMMDevRAMR3->fHaveEvents);
|
---|
4035 | // here be dragons (probably)
|
---|
4036 | pHlp->pfnSSMGetMem(pSSM, &pThisCC->pVMMDevRAMR3->V, sizeof(pThisCC->pVMMDevRAMR3->V));
|
---|
4037 |
|
---|
4038 | pHlp->pfnSSMGetMem(pSSM, &pThis->guestInfo, sizeof(pThis->guestInfo));
|
---|
4039 | pHlp->pfnSSMGetU32(pSSM, &pThis->fu32AdditionsOk);
|
---|
4040 | pHlp->pfnSSMGetU32(pSSM, &pThis->u32VideoAccelEnabled);
|
---|
4041 | if (uVersion > 10)
|
---|
4042 | pHlp->pfnSSMGetBool(pSSM, &pThis->displayChangeData.fGuestSentChangeEventAck);
|
---|
4043 |
|
---|
4044 | rc = pHlp->pfnSSMGetU32(pSSM, &pThis->fGuestCaps);
|
---|
4045 |
|
---|
4046 | /* Attributes which were temporarily introduced in r30072 */
|
---|
4047 | if (uVersion == 7)
|
---|
4048 | {
|
---|
4049 | uint32_t temp;
|
---|
4050 | pHlp->pfnSSMGetU32(pSSM, &temp);
|
---|
4051 | rc = pHlp->pfnSSMGetU32(pSSM, &temp);
|
---|
4052 | }
|
---|
4053 | AssertRCReturn(rc, rc);
|
---|
4054 |
|
---|
4055 | #ifdef VBOX_WITH_HGCM
|
---|
4056 | rc = vmmdevR3HgcmLoadState(pDevIns, pThis, pThisCC, pSSM, uVersion);
|
---|
4057 | AssertRCReturn(rc, rc);
|
---|
4058 | #endif /* VBOX_WITH_HGCM */
|
---|
4059 |
|
---|
4060 | if (uVersion >= 10)
|
---|
4061 | rc = pHlp->pfnSSMGetU32(pSSM, &pThis->fHostCursorRequested);
|
---|
4062 | AssertRCReturn(rc, rc);
|
---|
4063 |
|
---|
4064 | if (uVersion > VMMDEV_SAVED_STATE_VERSION_MISSING_GUEST_INFO_2)
|
---|
4065 | {
|
---|
4066 | pHlp->pfnSSMGetU32(pSSM, &pThis->guestInfo2.uFullVersion);
|
---|
4067 | pHlp->pfnSSMGetU32(pSSM, &pThis->guestInfo2.uRevision);
|
---|
4068 | pHlp->pfnSSMGetU32(pSSM, &pThis->guestInfo2.fFeatures);
|
---|
4069 | rc = pHlp->pfnSSMGetStrZ(pSSM, &pThis->guestInfo2.szName[0], sizeof(pThis->guestInfo2.szName));
|
---|
4070 | AssertRCReturn(rc, rc);
|
---|
4071 | }
|
---|
4072 |
|
---|
4073 | if (uVersion > VMMDEV_SAVED_STATE_VERSION_MISSING_FACILITY_STATUSES)
|
---|
4074 | {
|
---|
4075 | uint32_t cFacilityStatuses;
|
---|
4076 | rc = pHlp->pfnSSMGetU32(pSSM, &cFacilityStatuses);
|
---|
4077 | AssertRCReturn(rc, rc);
|
---|
4078 |
|
---|
4079 | for (uint32_t i = 0; i < cFacilityStatuses; i++)
|
---|
4080 | {
|
---|
4081 | uint32_t uFacility, fFlags;
|
---|
4082 | uint16_t uStatus;
|
---|
4083 | int64_t iTimeStampNano;
|
---|
4084 |
|
---|
4085 | pHlp->pfnSSMGetU32(pSSM, &uFacility);
|
---|
4086 | pHlp->pfnSSMGetU32(pSSM, &fFlags);
|
---|
4087 | pHlp->pfnSSMGetU16(pSSM, &uStatus);
|
---|
4088 | rc = pHlp->pfnSSMGetS64(pSSM, &iTimeStampNano);
|
---|
4089 | AssertRCReturn(rc, rc);
|
---|
4090 |
|
---|
4091 | PVMMDEVFACILITYSTATUSENTRY pEntry = vmmdevGetFacilityStatusEntry(pThis, (VBoxGuestFacilityType)uFacility);
|
---|
4092 | AssertLogRelMsgReturn(pEntry,
|
---|
4093 | ("VMMDev: Ran out of entries restoring the guest facility statuses. Saved state has %u.\n", cFacilityStatuses),
|
---|
4094 | VERR_OUT_OF_RESOURCES);
|
---|
4095 | pEntry->enmStatus = (VBoxGuestFacilityStatus)uStatus;
|
---|
4096 | pEntry->fFlags = fFlags;
|
---|
4097 | RTTimeSpecSetNano(&pEntry->TimeSpecTS, iTimeStampNano);
|
---|
4098 | }
|
---|
4099 | }
|
---|
4100 |
|
---|
4101 | /*
|
---|
4102 | * Heartbeat.
|
---|
4103 | */
|
---|
4104 | if (uVersion >= VMMDEV_SAVED_STATE_VERSION_HEARTBEAT)
|
---|
4105 | {
|
---|
4106 | pHlp->pfnSSMGetBool(pSSM, (bool *)&pThis->fHeartbeatActive);
|
---|
4107 | pHlp->pfnSSMGetBool(pSSM, (bool *)&pThis->fFlatlined);
|
---|
4108 | pHlp->pfnSSMGetU64(pSSM, (uint64_t *)&pThis->nsLastHeartbeatTS);
|
---|
4109 | rc = PDMDevHlpTimerLoad(pDevIns, pThis->hFlatlinedTimer, pSSM);
|
---|
4110 | AssertRCReturn(rc, rc);
|
---|
4111 | if (pThis->fFlatlined)
|
---|
4112 | LogRel(("vmmdevLoadState: Guest has flatlined. Last heartbeat %'RU64 ns before state was saved.\n",
|
---|
4113 | PDMDevHlpTimerGetNano(pDevIns, pThis->hFlatlinedTimer) - pThis->nsLastHeartbeatTS));
|
---|
4114 | }
|
---|
4115 |
|
---|
4116 | /*
|
---|
4117 | * On a resume, we send the capabilities changed message so
|
---|
4118 | * that listeners can sync their state again
|
---|
4119 | */
|
---|
4120 | Log(("vmmdevLoadState: capabilities changed (%x), informing connector\n", pThis->fMouseCapabilities));
|
---|
4121 | if (pThisCC->pDrv)
|
---|
4122 | {
|
---|
4123 | pThisCC->pDrv->pfnUpdateMouseCapabilities(pThisCC->pDrv, pThis->fMouseCapabilities);
|
---|
4124 | if (uVersion >= 10)
|
---|
4125 | pThisCC->pDrv->pfnUpdatePointerShape(pThisCC->pDrv,
|
---|
4126 | /*fVisible=*/!!pThis->fHostCursorRequested,
|
---|
4127 | /*fAlpha=*/false,
|
---|
4128 | /*xHot=*/0, /*yHot=*/0,
|
---|
4129 | /*cx=*/0, /*cy=*/0,
|
---|
4130 | /*pvShape=*/NULL);
|
---|
4131 | }
|
---|
4132 |
|
---|
4133 | if (pThis->fu32AdditionsOk)
|
---|
4134 | {
|
---|
4135 | vmmdevLogGuestOsInfo(&pThis->guestInfo);
|
---|
4136 | if (pThisCC->pDrv)
|
---|
4137 | {
|
---|
4138 | if (pThis->guestInfo2.uFullVersion && pThisCC->pDrv->pfnUpdateGuestInfo2)
|
---|
4139 | pThisCC->pDrv->pfnUpdateGuestInfo2(pThisCC->pDrv, pThis->guestInfo2.uFullVersion, pThis->guestInfo2.szName,
|
---|
4140 | pThis->guestInfo2.uRevision, pThis->guestInfo2.fFeatures);
|
---|
4141 | if (pThisCC->pDrv->pfnUpdateGuestInfo)
|
---|
4142 | pThisCC->pDrv->pfnUpdateGuestInfo(pThisCC->pDrv, &pThis->guestInfo);
|
---|
4143 |
|
---|
4144 | if (pThisCC->pDrv->pfnUpdateGuestStatus)
|
---|
4145 | {
|
---|
4146 | for (uint32_t i = 0; i < pThis->cFacilityStatuses; i++) /* ascending order! */
|
---|
4147 | if ( pThis->aFacilityStatuses[i].enmStatus != VBoxGuestFacilityStatus_Inactive
|
---|
4148 | || !pThis->aFacilityStatuses[i].fFixed)
|
---|
4149 | pThisCC->pDrv->pfnUpdateGuestStatus(pThisCC->pDrv,
|
---|
4150 | pThis->aFacilityStatuses[i].enmFacility,
|
---|
4151 | (uint16_t)pThis->aFacilityStatuses[i].enmStatus,
|
---|
4152 | pThis->aFacilityStatuses[i].fFlags,
|
---|
4153 | &pThis->aFacilityStatuses[i].TimeSpecTS);
|
---|
4154 | }
|
---|
4155 | }
|
---|
4156 | }
|
---|
4157 | if (pThisCC->pDrv && pThisCC->pDrv->pfnUpdateGuestCapabilities)
|
---|
4158 | pThisCC->pDrv->pfnUpdateGuestCapabilities(pThisCC->pDrv, pThis->fGuestCaps);
|
---|
4159 |
|
---|
4160 | return VINF_SUCCESS;
|
---|
4161 | }
|
---|
4162 |
|
---|
4163 | /**
|
---|
4164 | * Load state done callback. Notify guest of restore event.
|
---|
4165 | *
|
---|
4166 | * @returns VBox status code.
|
---|
4167 | * @param pDevIns The device instance.
|
---|
4168 | * @param pSSM The handle to the saved state.
|
---|
4169 | */
|
---|
4170 | static DECLCALLBACK(int) vmmdevLoadStateDone(PPDMDEVINS pDevIns, PSSMHANDLE pSSM)
|
---|
4171 | {
|
---|
4172 | PVMMDEV pThis = PDMDEVINS_2_DATA(pDevIns, PVMMDEV);
|
---|
4173 | PVMMDEVCC pThisCC = PDMDEVINS_2_DATA_CC(pDevIns, PVMMDEVCC);
|
---|
4174 | RT_NOREF(pSSM);
|
---|
4175 |
|
---|
4176 | #ifdef VBOX_WITH_HGCM
|
---|
4177 | int rc = vmmdevR3HgcmLoadStateDone(pDevIns, pThis, pThisCC);
|
---|
4178 | AssertLogRelRCReturn(rc, rc);
|
---|
4179 | #endif /* VBOX_WITH_HGCM */
|
---|
4180 |
|
---|
4181 | /* Reestablish the acceleration status. */
|
---|
4182 | if ( pThis->u32VideoAccelEnabled
|
---|
4183 | && pThisCC->pDrv)
|
---|
4184 | pThisCC->pDrv->pfnVideoAccelEnable(pThisCC->pDrv, !!pThis->u32VideoAccelEnabled, &pThisCC->pVMMDevRAMR3->vbvaMemory);
|
---|
4185 |
|
---|
4186 | VMMDevNotifyGuest(pDevIns, pThis, pThisCC, VMMDEV_EVENT_RESTORED);
|
---|
4187 |
|
---|
4188 | return VINF_SUCCESS;
|
---|
4189 | }
|
---|
4190 |
|
---|
4191 |
|
---|
4192 | /* -=-=-=-=- PDMDEVREG -=-=-=-=- */
|
---|
4193 |
|
---|
4194 | /**
|
---|
4195 | * (Re-)initializes the MMIO2 data.
|
---|
4196 | *
|
---|
4197 | * @param pThisCC The VMMDev ring-3 instance data.
|
---|
4198 | */
|
---|
4199 | static void vmmdevInitRam(PVMMDEVCC pThisCC)
|
---|
4200 | {
|
---|
4201 | memset(pThisCC->pVMMDevRAMR3, 0, sizeof(VMMDevMemory));
|
---|
4202 | pThisCC->pVMMDevRAMR3->u32Size = sizeof(VMMDevMemory);
|
---|
4203 | pThisCC->pVMMDevRAMR3->u32Version = VMMDEV_MEMORY_VERSION;
|
---|
4204 | }
|
---|
4205 |
|
---|
4206 |
|
---|
4207 | /**
|
---|
4208 | * @interface_method_impl{PDMDEVREG,pfnReset}
|
---|
4209 | */
|
---|
4210 | static DECLCALLBACK(void) vmmdevReset(PPDMDEVINS pDevIns)
|
---|
4211 | {
|
---|
4212 | PVMMDEV pThis = PDMDEVINS_2_DATA(pDevIns, PVMMDEV);
|
---|
4213 | PVMMDEVCC pThisCC = PDMDEVINS_2_DATA_CC(pDevIns, PVMMDEVCC);
|
---|
4214 | PDMDevHlpCritSectEnter(pDevIns, &pThis->CritSect, VERR_IGNORED);
|
---|
4215 |
|
---|
4216 | /*
|
---|
4217 | * Reset the mouse integration feature bits
|
---|
4218 | */
|
---|
4219 | if (pThis->fMouseCapabilities & VMMDEV_MOUSE_GUEST_MASK)
|
---|
4220 | {
|
---|
4221 | pThis->fMouseCapabilities &= ~VMMDEV_MOUSE_GUEST_MASK;
|
---|
4222 | /* notify the connector */
|
---|
4223 | Log(("vmmdevReset: capabilities changed (%x), informing connector\n", pThis->fMouseCapabilities));
|
---|
4224 | pThisCC->pDrv->pfnUpdateMouseCapabilities(pThisCC->pDrv, pThis->fMouseCapabilities);
|
---|
4225 | }
|
---|
4226 | pThis->fHostCursorRequested = false;
|
---|
4227 |
|
---|
4228 | /* re-initialize the VMMDev memory */
|
---|
4229 | if (pThisCC->pVMMDevRAMR3)
|
---|
4230 | vmmdevInitRam(pThisCC);
|
---|
4231 |
|
---|
4232 | /* credentials have to go away (by default) */
|
---|
4233 | VMMDEVCREDS *pCredentials = pThisCC->pCredentials;
|
---|
4234 | if (pCredentials)
|
---|
4235 | {
|
---|
4236 | if (!pThis->fKeepCredentials)
|
---|
4237 | {
|
---|
4238 | RT_ZERO(pCredentials->Logon.szUserName);
|
---|
4239 | RT_ZERO(pCredentials->Logon.szPassword);
|
---|
4240 | RT_ZERO(pCredentials->Logon.szDomain);
|
---|
4241 | }
|
---|
4242 | RT_ZERO(pCredentials->Judge.szUserName);
|
---|
4243 | RT_ZERO(pCredentials->Judge.szPassword);
|
---|
4244 | RT_ZERO(pCredentials->Judge.szDomain);
|
---|
4245 | }
|
---|
4246 |
|
---|
4247 | /* Reset means that additions will report again. */
|
---|
4248 | const bool fVersionChanged = pThis->fu32AdditionsOk
|
---|
4249 | || pThis->guestInfo.interfaceVersion
|
---|
4250 | || pThis->guestInfo.osType != VBOXOSTYPE_Unknown;
|
---|
4251 | if (fVersionChanged)
|
---|
4252 | Log(("vmmdevReset: fu32AdditionsOk=%d additionsVersion=%x osType=%#x\n",
|
---|
4253 | pThis->fu32AdditionsOk, pThis->guestInfo.interfaceVersion, pThis->guestInfo.osType));
|
---|
4254 | pThis->fu32AdditionsOk = false;
|
---|
4255 | memset (&pThis->guestInfo, 0, sizeof (pThis->guestInfo));
|
---|
4256 | RT_ZERO(pThis->guestInfo2);
|
---|
4257 | const bool fCapsChanged = pThis->fGuestCaps != 0; /* Report transition to 0. */
|
---|
4258 | pThis->fGuestCaps = 0;
|
---|
4259 |
|
---|
4260 | /* Clear facilities. No need to tell Main as it will get a
|
---|
4261 | pfnUpdateGuestInfo callback. */
|
---|
4262 | RTTIMESPEC TimeStampNow;
|
---|
4263 | RTTimeNow(&TimeStampNow);
|
---|
4264 | uint32_t iFacility = pThis->cFacilityStatuses;
|
---|
4265 | while (iFacility-- > 0)
|
---|
4266 | {
|
---|
4267 | pThis->aFacilityStatuses[iFacility].enmStatus = VBoxGuestFacilityStatus_Inactive;
|
---|
4268 | pThis->aFacilityStatuses[iFacility].TimeSpecTS = TimeStampNow;
|
---|
4269 | }
|
---|
4270 |
|
---|
4271 | /* clear pending display change request. */
|
---|
4272 | for (unsigned i = 0; i < RT_ELEMENTS(pThis->displayChangeData.aRequests); i++)
|
---|
4273 | {
|
---|
4274 | DISPLAYCHANGEREQUEST *pRequest = &pThis->displayChangeData.aRequests[i];
|
---|
4275 | memset (&pRequest->lastReadDisplayChangeRequest, 0, sizeof (pRequest->lastReadDisplayChangeRequest));
|
---|
4276 | }
|
---|
4277 | pThis->displayChangeData.iCurrentMonitor = 0;
|
---|
4278 | pThis->displayChangeData.fGuestSentChangeEventAck = false;
|
---|
4279 |
|
---|
4280 | /* disable seamless mode */
|
---|
4281 | pThis->fLastSeamlessEnabled = false;
|
---|
4282 |
|
---|
4283 | /* disabled memory ballooning */
|
---|
4284 | pThis->cMbMemoryBalloonLast = 0;
|
---|
4285 |
|
---|
4286 | /* disabled statistics updating */
|
---|
4287 | pThis->cSecsLastStatInterval = 0;
|
---|
4288 |
|
---|
4289 | #ifdef VBOX_WITH_HGCM
|
---|
4290 | /* Clear the "HGCM event enabled" flag so the event can be automatically reenabled. */
|
---|
4291 | pThisCC->u32HGCMEnabled = 0;
|
---|
4292 | #endif
|
---|
4293 |
|
---|
4294 | /*
|
---|
4295 | * Deactive heartbeat.
|
---|
4296 | */
|
---|
4297 | if (pThis->fHeartbeatActive)
|
---|
4298 | {
|
---|
4299 | PDMDevHlpTimerStop(pDevIns, pThis->hFlatlinedTimer);
|
---|
4300 | pThis->fFlatlined = false;
|
---|
4301 | pThis->fHeartbeatActive = true;
|
---|
4302 | }
|
---|
4303 |
|
---|
4304 | /*
|
---|
4305 | * Clear the event variables.
|
---|
4306 | *
|
---|
4307 | * XXX By design we should NOT clear pThis->fHostEventFlags because it is designed
|
---|
4308 | * that way so host events do not depend on guest resets. However, the pending
|
---|
4309 | * event flags actually _were_ cleared since ages so we mask out events from
|
---|
4310 | * clearing which we really need to survive the reset. See xtracker 5767.
|
---|
4311 | */
|
---|
4312 | pThis->fHostEventFlags &= VMMDEV_EVENT_DISPLAY_CHANGE_REQUEST;
|
---|
4313 | pThis->fGuestFilterMask = 0;
|
---|
4314 | pThis->fNewGuestFilterMask = 0;
|
---|
4315 | pThis->fNewGuestFilterMaskValid = 0;
|
---|
4316 |
|
---|
4317 | /*
|
---|
4318 | * Call the update functions as required.
|
---|
4319 | */
|
---|
4320 | if (fVersionChanged && pThisCC->pDrv && pThisCC->pDrv->pfnUpdateGuestInfo)
|
---|
4321 | pThisCC->pDrv->pfnUpdateGuestInfo(pThisCC->pDrv, &pThis->guestInfo);
|
---|
4322 | if (fCapsChanged && pThisCC->pDrv && pThisCC->pDrv->pfnUpdateGuestCapabilities)
|
---|
4323 | pThisCC->pDrv->pfnUpdateGuestCapabilities(pThisCC->pDrv, pThis->fGuestCaps);
|
---|
4324 |
|
---|
4325 | /*
|
---|
4326 | * Generate a unique session id for this VM; it will be changed for each start, reset or restore.
|
---|
4327 | * This can be used for restore detection inside the guest.
|
---|
4328 | */
|
---|
4329 | pThis->idSession = ASMReadTSC();
|
---|
4330 |
|
---|
4331 | PDMDevHlpCritSectLeave(pDevIns, &pThis->CritSect);
|
---|
4332 | }
|
---|
4333 |
|
---|
4334 |
|
---|
4335 | #ifdef VBOX_WITH_RAW_MODE_KEEP
|
---|
4336 | /**
|
---|
4337 | * @interface_method_impl{PDMDEVREG,pfnRelocate}
|
---|
4338 | */
|
---|
4339 | static DECLCALLBACK(void) vmmdevRelocate(PPDMDEVINS pDevIns, RTGCINTPTR offDelta)
|
---|
4340 | {
|
---|
4341 | if (offDelta)
|
---|
4342 | {
|
---|
4343 | PVMMDEV pThis = PDMDEVINS_2_DATA(pDevIns, PVMMDEV);
|
---|
4344 | LogFlow(("vmmdevRelocate: offDelta=%RGv\n", offDelta));
|
---|
4345 |
|
---|
4346 | if (pThis->pVMMDevRAMRC)
|
---|
4347 | pThis->pVMMDevRAMRC += offDelta;
|
---|
4348 | pThis->pDevInsRC = PDMDEVINS_2_RCPTR(pDevIns);
|
---|
4349 | }
|
---|
4350 | }
|
---|
4351 | #endif
|
---|
4352 |
|
---|
4353 |
|
---|
4354 | /**
|
---|
4355 | * @interface_method_impl{PDMDEVREG,pfnDestruct}
|
---|
4356 | */
|
---|
4357 | static DECLCALLBACK(int) vmmdevDestruct(PPDMDEVINS pDevIns)
|
---|
4358 | {
|
---|
4359 | PDMDEV_CHECK_VERSIONS_RETURN(pDevIns);
|
---|
4360 | PVMMDEVCC pThisCC = PDMDEVINS_2_DATA_CC(pDevIns, PVMMDEVCC);
|
---|
4361 |
|
---|
4362 | /*
|
---|
4363 | * Wipe and free the credentials.
|
---|
4364 | */
|
---|
4365 | VMMDEVCREDS *pCredentials = pThisCC->pCredentials;
|
---|
4366 | pThisCC->pCredentials = NULL;
|
---|
4367 | if (pCredentials)
|
---|
4368 | {
|
---|
4369 | if (pThisCC->fSaferCredentials)
|
---|
4370 | RTMemSaferFree(pCredentials, sizeof(*pCredentials));
|
---|
4371 | else
|
---|
4372 | {
|
---|
4373 | RTMemWipeThoroughly(pCredentials, sizeof(*pCredentials), 10);
|
---|
4374 | RTMemFree(pCredentials);
|
---|
4375 | }
|
---|
4376 | }
|
---|
4377 |
|
---|
4378 | #ifdef VBOX_WITH_HGCM
|
---|
4379 | /*
|
---|
4380 | * Everything HGCM.
|
---|
4381 | */
|
---|
4382 | vmmdevR3HgcmDestroy(pDevIns, pThisCC);
|
---|
4383 | #endif
|
---|
4384 |
|
---|
4385 | /*
|
---|
4386 | * Free the request buffers.
|
---|
4387 | */
|
---|
4388 | for (uint32_t iCpu = 0; iCpu < RT_ELEMENTS(pThisCC->apReqBufs); iCpu++)
|
---|
4389 | {
|
---|
4390 | RTMemPageFree(pThisCC->apReqBufs[iCpu], _4K);
|
---|
4391 | pThisCC->apReqBufs[iCpu] = NULL;
|
---|
4392 | }
|
---|
4393 |
|
---|
4394 | #ifndef VBOX_WITHOUT_TESTING_FEATURES
|
---|
4395 | /*
|
---|
4396 | * Clean up the testing device.
|
---|
4397 | */
|
---|
4398 | vmmdevR3TestingTerminate(pDevIns);
|
---|
4399 | #endif
|
---|
4400 |
|
---|
4401 | return VINF_SUCCESS;
|
---|
4402 | }
|
---|
4403 |
|
---|
4404 |
|
---|
4405 | /**
|
---|
4406 | * @interface_method_impl{PDMDEVREG,pfnConstruct}
|
---|
4407 | */
|
---|
4408 | static DECLCALLBACK(int) vmmdevConstruct(PPDMDEVINS pDevIns, int iInstance, PCFGMNODE pCfg)
|
---|
4409 | {
|
---|
4410 | PDMDEV_CHECK_VERSIONS_RETURN(pDevIns);
|
---|
4411 | PVMMDEVCC pThisCC = PDMDEVINS_2_DATA_CC(pDevIns, PVMMDEVCC);
|
---|
4412 | PVMMDEV pThis = PDMDEVINS_2_DATA(pDevIns, PVMMDEV);
|
---|
4413 | PCPDMDEVHLPR3 pHlp = pDevIns->pHlpR3;
|
---|
4414 | int rc;
|
---|
4415 |
|
---|
4416 | Assert(iInstance == 0);
|
---|
4417 | RT_NOREF(iInstance);
|
---|
4418 |
|
---|
4419 | /*
|
---|
4420 | * Initialize data (most of it anyway).
|
---|
4421 | */
|
---|
4422 | pThisCC->pDevIns = pDevIns;
|
---|
4423 |
|
---|
4424 | pThis->hFlatlinedTimer = NIL_TMTIMERHANDLE;
|
---|
4425 | pThis->hIoPortBackdoorLog = NIL_IOMIOPORTHANDLE;
|
---|
4426 | pThis->hIoPortAltTimesync = NIL_IOMIOPORTHANDLE;
|
---|
4427 | pThis->hIoPortReq = NIL_IOMIOPORTHANDLE;
|
---|
4428 | pThis->hIoPortFast = NIL_IOMIOPORTHANDLE;
|
---|
4429 | pThis->hMmio2VMMDevRAM = NIL_PGMMMIO2HANDLE;
|
---|
4430 | pThis->hMmio2Heap = NIL_PGMMMIO2HANDLE;
|
---|
4431 | #ifndef VBOX_WITHOUT_TESTING_FEATURES
|
---|
4432 | pThis->hIoPortTesting = NIL_IOMIOPORTHANDLE;
|
---|
4433 | pThis->hMmioTesting = NIL_IOMMMIOHANDLE;
|
---|
4434 | #endif
|
---|
4435 |
|
---|
4436 | PPDMPCIDEV pPciDev = pDevIns->apPciDevs[0];
|
---|
4437 | PDMPCIDEV_ASSERT_VALID(pDevIns, pPciDev);
|
---|
4438 |
|
---|
4439 | /* PCI vendor, just a free bogus value */
|
---|
4440 | PDMPciDevSetVendorId(pPciDev, 0x80ee);
|
---|
4441 | /* device ID */
|
---|
4442 | PDMPciDevSetDeviceId(pPciDev, 0xcafe);
|
---|
4443 | /* class sub code (other type of system peripheral) */
|
---|
4444 | PDMPciDevSetClassSub(pPciDev, 0x80);
|
---|
4445 | /* class base code (base system peripheral) */
|
---|
4446 | PDMPciDevSetClassBase(pPciDev, 0x08);
|
---|
4447 | /* header type */
|
---|
4448 | PDMPciDevSetHeaderType(pPciDev, 0x00);
|
---|
4449 | /* interrupt on pin 0 */
|
---|
4450 | PDMPciDevSetInterruptPin(pPciDev, 0x01);
|
---|
4451 |
|
---|
4452 | RTTIMESPEC TimeStampNow;
|
---|
4453 | RTTimeNow(&TimeStampNow);
|
---|
4454 | vmmdevAllocFacilityStatusEntry(pThis, VBoxGuestFacilityType_VBoxGuestDriver, true /*fFixed*/, &TimeStampNow);
|
---|
4455 | vmmdevAllocFacilityStatusEntry(pThis, VBoxGuestFacilityType_VBoxService, true /*fFixed*/, &TimeStampNow);
|
---|
4456 | vmmdevAllocFacilityStatusEntry(pThis, VBoxGuestFacilityType_VBoxTrayClient, true /*fFixed*/, &TimeStampNow);
|
---|
4457 | vmmdevAllocFacilityStatusEntry(pThis, VBoxGuestFacilityType_Seamless, true /*fFixed*/, &TimeStampNow);
|
---|
4458 | vmmdevAllocFacilityStatusEntry(pThis, VBoxGuestFacilityType_Graphics, true /*fFixed*/, &TimeStampNow);
|
---|
4459 | Assert(pThis->cFacilityStatuses == 5);
|
---|
4460 |
|
---|
4461 | /*
|
---|
4462 | * Interfaces
|
---|
4463 | */
|
---|
4464 | /* IBase */
|
---|
4465 | pThisCC->IBase.pfnQueryInterface = vmmdevPortQueryInterface;
|
---|
4466 |
|
---|
4467 | /* VMMDev port */
|
---|
4468 | pThisCC->IPort.pfnQueryAbsoluteMouse = vmmdevIPort_QueryAbsoluteMouse;
|
---|
4469 | pThisCC->IPort.pfnSetAbsoluteMouse = vmmdevIPort_SetAbsoluteMouse ;
|
---|
4470 | pThisCC->IPort.pfnQueryMouseCapabilities = vmmdevIPort_QueryMouseCapabilities;
|
---|
4471 | pThisCC->IPort.pfnUpdateMouseCapabilities = vmmdevIPort_UpdateMouseCapabilities;
|
---|
4472 | pThisCC->IPort.pfnRequestDisplayChange = vmmdevIPort_RequestDisplayChange;
|
---|
4473 | pThisCC->IPort.pfnSetCredentials = vmmdevIPort_SetCredentials;
|
---|
4474 | pThisCC->IPort.pfnVBVAChange = vmmdevIPort_VBVAChange;
|
---|
4475 | pThisCC->IPort.pfnRequestSeamlessChange = vmmdevIPort_RequestSeamlessChange;
|
---|
4476 | pThisCC->IPort.pfnSetMemoryBalloon = vmmdevIPort_SetMemoryBalloon;
|
---|
4477 | pThisCC->IPort.pfnSetStatisticsInterval = vmmdevIPort_SetStatisticsInterval;
|
---|
4478 | pThisCC->IPort.pfnVRDPChange = vmmdevIPort_VRDPChange;
|
---|
4479 | pThisCC->IPort.pfnCpuHotUnplug = vmmdevIPort_CpuHotUnplug;
|
---|
4480 | pThisCC->IPort.pfnCpuHotPlug = vmmdevIPort_CpuHotPlug;
|
---|
4481 |
|
---|
4482 | /* Shared folder LED */
|
---|
4483 | pThisCC->SharedFolders.Led.u32Magic = PDMLED_MAGIC;
|
---|
4484 | pThisCC->SharedFolders.ILeds.pfnQueryStatusLed = vmmdevQueryStatusLed;
|
---|
4485 |
|
---|
4486 | #ifdef VBOX_WITH_HGCM
|
---|
4487 | /* HGCM port */
|
---|
4488 | pThisCC->IHGCMPort.pfnCompleted = hgcmR3Completed;
|
---|
4489 | pThisCC->IHGCMPort.pfnIsCmdRestored = hgcmR3IsCmdRestored;
|
---|
4490 | pThisCC->IHGCMPort.pfnIsCmdCancelled = hgcmR3IsCmdCancelled;
|
---|
4491 | pThisCC->IHGCMPort.pfnGetRequestor = hgcmR3GetRequestor;
|
---|
4492 | pThisCC->IHGCMPort.pfnGetVMMDevSessionId = hgcmR3GetVMMDevSessionId;
|
---|
4493 | #endif
|
---|
4494 |
|
---|
4495 | pThisCC->pCredentials = (VMMDEVCREDS *)RTMemSaferAllocZ(sizeof(*pThisCC->pCredentials));
|
---|
4496 | if (pThisCC->pCredentials)
|
---|
4497 | pThisCC->fSaferCredentials = true;
|
---|
4498 | else
|
---|
4499 | {
|
---|
4500 | pThisCC->pCredentials = (VMMDEVCREDS *)RTMemAllocZ(sizeof(*pThisCC->pCredentials));
|
---|
4501 | AssertReturn(pThisCC->pCredentials, VERR_NO_MEMORY);
|
---|
4502 | }
|
---|
4503 |
|
---|
4504 |
|
---|
4505 | /*
|
---|
4506 | * Validate and read the configuration.
|
---|
4507 | */
|
---|
4508 | PDMDEV_VALIDATE_CONFIG_RETURN(pDevIns,
|
---|
4509 | "AllowGuestToSaveState|"
|
---|
4510 | "GetHostTimeDisabled|"
|
---|
4511 | "BackdoorLogDisabled|"
|
---|
4512 | "KeepCredentials|"
|
---|
4513 | "HeapEnabled|"
|
---|
4514 | "GuestCoreDumpEnabled|"
|
---|
4515 | "GuestCoreDumpDir|"
|
---|
4516 | "GuestCoreDumpCount|"
|
---|
4517 | "HeartbeatInterval|"
|
---|
4518 | "HeartbeatTimeout|"
|
---|
4519 | "TestingEnabled|"
|
---|
4520 | "TestingMMIO|"
|
---|
4521 | "TestintXmlOutputFile"
|
---|
4522 | ,
|
---|
4523 | "");
|
---|
4524 |
|
---|
4525 | rc = pHlp->pfnCFGMQueryBoolDef(pCfg, "AllowGuestToSaveState", &pThis->fAllowGuestToSaveState, true);
|
---|
4526 | if (RT_FAILURE(rc))
|
---|
4527 | return PDMDEV_SET_ERROR(pDevIns, rc,
|
---|
4528 | N_("Configuration error: Failed querying \"AllowGuestToSaveState\" as a boolean"));
|
---|
4529 |
|
---|
4530 | rc = pHlp->pfnCFGMQueryBoolDef(pCfg, "GetHostTimeDisabled", &pThis->fGetHostTimeDisabled, false);
|
---|
4531 | if (RT_FAILURE(rc))
|
---|
4532 | return PDMDEV_SET_ERROR(pDevIns, rc,
|
---|
4533 | N_("Configuration error: Failed querying \"GetHostTimeDisabled\" as a boolean"));
|
---|
4534 |
|
---|
4535 | rc = pHlp->pfnCFGMQueryBoolDef(pCfg, "BackdoorLogDisabled", &pThis->fBackdoorLogDisabled, false);
|
---|
4536 | if (RT_FAILURE(rc))
|
---|
4537 | return PDMDEV_SET_ERROR(pDevIns, rc,
|
---|
4538 | N_("Configuration error: Failed querying \"BackdoorLogDisabled\" as a boolean"));
|
---|
4539 |
|
---|
4540 | rc = pHlp->pfnCFGMQueryBoolDef(pCfg, "KeepCredentials", &pThis->fKeepCredentials, false);
|
---|
4541 | if (RT_FAILURE(rc))
|
---|
4542 | return PDMDEV_SET_ERROR(pDevIns, rc,
|
---|
4543 | N_("Configuration error: Failed querying \"KeepCredentials\" as a boolean"));
|
---|
4544 |
|
---|
4545 | rc = pHlp->pfnCFGMQueryBoolDef(pCfg, "HeapEnabled", &pThis->fHeapEnabled, true);
|
---|
4546 | if (RT_FAILURE(rc))
|
---|
4547 | return PDMDEV_SET_ERROR(pDevIns, rc,
|
---|
4548 | N_("Configuration error: Failed querying \"HeapEnabled\" as a boolean"));
|
---|
4549 |
|
---|
4550 | rc = pHlp->pfnCFGMQueryBoolDef(pCfg, "GuestCoreDumpEnabled", &pThis->fGuestCoreDumpEnabled, false);
|
---|
4551 | if (RT_FAILURE(rc))
|
---|
4552 | return PDMDEV_SET_ERROR(pDevIns, rc, N_("Configuration error: Failed querying \"GuestCoreDumpEnabled\" as a boolean"));
|
---|
4553 |
|
---|
4554 | char *pszGuestCoreDumpDir = NULL;
|
---|
4555 | rc = pHlp->pfnCFGMQueryStringAllocDef(pCfg, "GuestCoreDumpDir", &pszGuestCoreDumpDir, "");
|
---|
4556 | if (RT_FAILURE(rc))
|
---|
4557 | return PDMDEV_SET_ERROR(pDevIns, rc, N_("Configuration error: Failed querying \"GuestCoreDumpDir\" as a string"));
|
---|
4558 |
|
---|
4559 | RTStrCopy(pThis->szGuestCoreDumpDir, sizeof(pThis->szGuestCoreDumpDir), pszGuestCoreDumpDir);
|
---|
4560 | MMR3HeapFree(pszGuestCoreDumpDir);
|
---|
4561 |
|
---|
4562 | rc = pHlp->pfnCFGMQueryU32Def(pCfg, "GuestCoreDumpCount", &pThis->cGuestCoreDumps, 3);
|
---|
4563 | if (RT_FAILURE(rc))
|
---|
4564 | return PDMDEV_SET_ERROR(pDevIns, rc,
|
---|
4565 | N_("Configuration error: Failed querying \"GuestCoreDumpCount\" as a 32-bit unsigned integer"));
|
---|
4566 |
|
---|
4567 | rc = pHlp->pfnCFGMQueryU64Def(pCfg, "HeartbeatInterval", &pThis->cNsHeartbeatInterval, VMMDEV_HEARTBEAT_DEFAULT_INTERVAL);
|
---|
4568 | if (RT_FAILURE(rc))
|
---|
4569 | return PDMDEV_SET_ERROR(pDevIns, rc,
|
---|
4570 | N_("Configuration error: Failed querying \"HeartbeatInterval\" as a 64-bit unsigned integer"));
|
---|
4571 | if (pThis->cNsHeartbeatInterval < RT_NS_100MS / 2)
|
---|
4572 | return PDMDEV_SET_ERROR(pDevIns, rc,
|
---|
4573 | N_("Configuration error: Heartbeat interval \"HeartbeatInterval\" too small"));
|
---|
4574 |
|
---|
4575 | rc = pHlp->pfnCFGMQueryU64Def(pCfg, "HeartbeatTimeout", &pThis->cNsHeartbeatTimeout, pThis->cNsHeartbeatInterval * 2);
|
---|
4576 | if (RT_FAILURE(rc))
|
---|
4577 | return PDMDEV_SET_ERROR(pDevIns, rc,
|
---|
4578 | N_("Configuration error: Failed querying \"HeartbeatTimeout\" as a 64-bit unsigned integer"));
|
---|
4579 | if (pThis->cNsHeartbeatTimeout < RT_NS_100MS)
|
---|
4580 | return PDMDEV_SET_ERROR(pDevIns, rc, N_("Configuration error: Heartbeat timeout \"HeartbeatTimeout\" too small"));
|
---|
4581 | if (pThis->cNsHeartbeatTimeout <= pThis->cNsHeartbeatInterval + RT_NS_10MS)
|
---|
4582 | return PDMDevHlpVMSetError(pDevIns, rc, RT_SRC_POS,
|
---|
4583 | N_("Configuration error: Heartbeat timeout \"HeartbeatTimeout\" value (%'ull ns) is too close to the interval (%'ull ns)"),
|
---|
4584 | pThis->cNsHeartbeatTimeout, pThis->cNsHeartbeatInterval);
|
---|
4585 |
|
---|
4586 | #ifndef VBOX_WITHOUT_TESTING_FEATURES
|
---|
4587 | rc = pHlp->pfnCFGMQueryBoolDef(pCfg, "TestingEnabled", &pThis->fTestingEnabled, false);
|
---|
4588 | if (RT_FAILURE(rc))
|
---|
4589 | return PDMDEV_SET_ERROR(pDevIns, rc, N_("Configuration error: Failed querying \"TestingEnabled\" as a boolean"));
|
---|
4590 | rc = pHlp->pfnCFGMQueryBoolDef(pCfg, "TestingMMIO", &pThis->fTestingMMIO, false);
|
---|
4591 | if (RT_FAILURE(rc))
|
---|
4592 | return PDMDEV_SET_ERROR(pDevIns, rc, N_("Configuration error: Failed querying \"TestingMMIO\" as a boolean"));
|
---|
4593 | rc = pHlp->pfnCFGMQueryStringAllocDef(pCfg, "TestintXmlOutputFile", &pThisCC->pszTestingXmlOutput, NULL);
|
---|
4594 | if (RT_FAILURE(rc))
|
---|
4595 | return PDMDEV_SET_ERROR(pDevIns, rc, N_("Configuration error: Failed querying \"TestintXmlOutputFile\" as a string"));
|
---|
4596 |
|
---|
4597 | /** @todo image-to-load-filename? */
|
---|
4598 | #endif
|
---|
4599 |
|
---|
4600 | pThis->cbGuestRAM = MMR3PhysGetRamSize(PDMDevHlpGetVM(pDevIns));
|
---|
4601 |
|
---|
4602 | /*
|
---|
4603 | * We do our own locking entirely. So, install NOP critsect for the device
|
---|
4604 | * and create our own critsect for use where it really matters (++).
|
---|
4605 | */
|
---|
4606 | rc = PDMDevHlpSetDeviceCritSect(pDevIns, PDMDevHlpCritSectGetNop(pDevIns));
|
---|
4607 | AssertRCReturn(rc, rc);
|
---|
4608 | rc = PDMDevHlpCritSectInit(pDevIns, &pThis->CritSect, RT_SRC_POS, "VMMDev#%u", iInstance);
|
---|
4609 | AssertRCReturn(rc, rc);
|
---|
4610 |
|
---|
4611 | /*
|
---|
4612 | * Register the backdoor logging port
|
---|
4613 | */
|
---|
4614 | rc = PDMDevHlpIoPortCreateAndMap(pDevIns, RTLOG_DEBUG_PORT, 1, vmmdevBackdoorLog, NULL /*pfnIn*/,
|
---|
4615 | "VMMDev backdoor logging", NULL, &pThis->hIoPortBackdoorLog);
|
---|
4616 | AssertRCReturn(rc, rc);
|
---|
4617 |
|
---|
4618 | #ifdef VMMDEV_WITH_ALT_TIMESYNC
|
---|
4619 | /*
|
---|
4620 | * Alternative timesync source.
|
---|
4621 | *
|
---|
4622 | * This was orignally added for creating a simple time sync service in an
|
---|
4623 | * OpenBSD guest without requiring VBoxGuest and VBoxService to be ported
|
---|
4624 | * first. We keep it in case it comes in handy.
|
---|
4625 | */
|
---|
4626 | rc = PDMDevHlpIoPortCreateAndMap(pDevIns, 0x505, 1, vmmdevAltTimeSyncWrite, vmmdevAltTimeSyncRead,
|
---|
4627 | "VMMDev timesync backdoor", NULL /*paExtDescs*/, &pThis->hIoPortAltTimesync);
|
---|
4628 | AssertRCReturn(rc, rc);
|
---|
4629 | #endif
|
---|
4630 |
|
---|
4631 | /*
|
---|
4632 | * Register the PCI device.
|
---|
4633 | */
|
---|
4634 | rc = PDMDevHlpPCIRegister(pDevIns, pPciDev);
|
---|
4635 | if (RT_FAILURE(rc))
|
---|
4636 | return rc;
|
---|
4637 | if (pPciDev->uDevFn != 32 || iInstance != 0)
|
---|
4638 | Log(("!!WARNING!!: pThis->PciDev.uDevFn=%d (ignore if testcase or no started by Main)\n", pPciDev->uDevFn));
|
---|
4639 |
|
---|
4640 | /*
|
---|
4641 | * The I/O ports, PCI region #0. This has two separate I/O port mappings in it,
|
---|
4642 | * so we have to do it via the mapper callback.
|
---|
4643 | */
|
---|
4644 | rc = PDMDevHlpIoPortCreate(pDevIns, 1 /*cPorts*/, pPciDev, RT_MAKE_U32(0, 0), vmmdevRequestHandler, NULL /*pfnIn*/,
|
---|
4645 | NULL /*pvUser*/, "VMMDev Request Handler", NULL, &pThis->hIoPortReq);
|
---|
4646 | AssertRCReturn(rc, rc);
|
---|
4647 |
|
---|
4648 | rc = PDMDevHlpIoPortCreate(pDevIns, 1 /*cPorts*/, pPciDev, RT_MAKE_U32(1, 0), vmmdevFastRequestHandler,
|
---|
4649 | vmmdevFastRequestIrqAck, NULL, "VMMDev Fast R0/RC Requests", NULL /*pvUser*/, &pThis->hIoPortFast);
|
---|
4650 | AssertRCReturn(rc, rc);
|
---|
4651 |
|
---|
4652 | rc = PDMDevHlpPCIIORegionRegisterIoCustom(pDevIns, 0, 0x20, vmmdevIOPortRegionMap);
|
---|
4653 | AssertRCReturn(rc, rc);
|
---|
4654 |
|
---|
4655 | /*
|
---|
4656 | * Allocate and initialize the MMIO2 memory, PCI region #1.
|
---|
4657 | */
|
---|
4658 | rc = PDMDevHlpPCIIORegionCreateMmio2(pDevIns, 1 /*iPciRegion*/, VMMDEV_RAM_SIZE, PCI_ADDRESS_SPACE_MEM, "VMMDev",
|
---|
4659 | (void **)&pThisCC->pVMMDevRAMR3, &pThis->hMmio2VMMDevRAM);
|
---|
4660 | if (RT_FAILURE(rc))
|
---|
4661 | return PDMDevHlpVMSetError(pDevIns, rc, RT_SRC_POS,
|
---|
4662 | N_("Failed to create the %u (%#x) byte MMIO2 region for the VMM device"),
|
---|
4663 | VMMDEV_RAM_SIZE, VMMDEV_RAM_SIZE);
|
---|
4664 | vmmdevInitRam(pThisCC);
|
---|
4665 |
|
---|
4666 | /*
|
---|
4667 | * The MMIO2 heap (used for real-mode VT-x trickery), PCI region #2.
|
---|
4668 | */
|
---|
4669 | if (pThis->fHeapEnabled)
|
---|
4670 | {
|
---|
4671 | rc = PDMDevHlpPCIIORegionCreateMmio2Ex(pDevIns, 2 /*iPciRegion*/, VMMDEV_HEAP_SIZE, PCI_ADDRESS_SPACE_MEM_PREFETCH,
|
---|
4672 | 0 /*fFlags*/, vmmdevMmio2HeapRegionMap, "VMMDev Heap",
|
---|
4673 | (void **)&pThisCC->pVMMDevHeapR3, &pThis->hMmio2Heap);
|
---|
4674 | if (RT_FAILURE(rc))
|
---|
4675 | return PDMDevHlpVMSetError(pDevIns, rc, RT_SRC_POS,
|
---|
4676 | N_("Failed to create the %u (%#x) bytes MMIO2 heap region for the VMM device"),
|
---|
4677 | VMMDEV_HEAP_SIZE, VMMDEV_HEAP_SIZE);
|
---|
4678 |
|
---|
4679 | /* Register the memory area with PDM so HM can access it before it's mapped. */
|
---|
4680 | rc = PDMDevHlpRegisterVMMDevHeap(pDevIns, NIL_RTGCPHYS, pThisCC->pVMMDevHeapR3, VMMDEV_HEAP_SIZE);
|
---|
4681 | AssertLogRelRCReturn(rc, rc);
|
---|
4682 | }
|
---|
4683 |
|
---|
4684 | #ifndef VBOX_WITHOUT_TESTING_FEATURES
|
---|
4685 | /*
|
---|
4686 | * Initialize testing.
|
---|
4687 | */
|
---|
4688 | rc = vmmdevR3TestingInitialize(pDevIns);
|
---|
4689 | if (RT_FAILURE(rc))
|
---|
4690 | return rc;
|
---|
4691 | #endif
|
---|
4692 |
|
---|
4693 | /*
|
---|
4694 | * Get the corresponding connector interface
|
---|
4695 | */
|
---|
4696 | rc = PDMDevHlpDriverAttach(pDevIns, 0, &pThisCC->IBase, &pThisCC->pDrvBase, "VMM Driver Port");
|
---|
4697 | if (RT_SUCCESS(rc))
|
---|
4698 | {
|
---|
4699 | pThisCC->pDrv = PDMIBASE_QUERY_INTERFACE(pThisCC->pDrvBase, PDMIVMMDEVCONNECTOR);
|
---|
4700 | AssertMsgReturn(pThisCC->pDrv, ("LUN #0 doesn't have a VMMDev connector interface!\n"), VERR_PDM_MISSING_INTERFACE);
|
---|
4701 | #ifdef VBOX_WITH_HGCM
|
---|
4702 | pThisCC->pHGCMDrv = PDMIBASE_QUERY_INTERFACE(pThisCC->pDrvBase, PDMIHGCMCONNECTOR);
|
---|
4703 | if (!pThisCC->pHGCMDrv)
|
---|
4704 | {
|
---|
4705 | Log(("LUN #0 doesn't have a HGCM connector interface, HGCM is not supported. rc=%Rrc\n", rc));
|
---|
4706 | /* this is not actually an error, just means that there is no support for HGCM */
|
---|
4707 | }
|
---|
4708 | #endif
|
---|
4709 | /* Query the initial balloon size. */
|
---|
4710 | AssertPtr(pThisCC->pDrv->pfnQueryBalloonSize);
|
---|
4711 | rc = pThisCC->pDrv->pfnQueryBalloonSize(pThisCC->pDrv, &pThis->cMbMemoryBalloon);
|
---|
4712 | AssertRC(rc);
|
---|
4713 |
|
---|
4714 | Log(("Initial balloon size %x\n", pThis->cMbMemoryBalloon));
|
---|
4715 | }
|
---|
4716 | else if (rc == VERR_PDM_NO_ATTACHED_DRIVER)
|
---|
4717 | {
|
---|
4718 | Log(("%s/%d: warning: no driver attached to LUN #0!\n", pDevIns->pReg->szName, pDevIns->iInstance));
|
---|
4719 | rc = VINF_SUCCESS;
|
---|
4720 | }
|
---|
4721 | else
|
---|
4722 | AssertMsgFailedReturn(("Failed to attach LUN #0! rc=%Rrc\n", rc), rc);
|
---|
4723 |
|
---|
4724 | /*
|
---|
4725 | * Attach status driver for shared folders (optional).
|
---|
4726 | */
|
---|
4727 | PPDMIBASE pBase;
|
---|
4728 | rc = PDMDevHlpDriverAttach(pDevIns, PDM_STATUS_LUN, &pThisCC->IBase, &pBase, "Status Port");
|
---|
4729 | if (RT_SUCCESS(rc))
|
---|
4730 | pThisCC->SharedFolders.pLedsConnector = PDMIBASE_QUERY_INTERFACE(pBase, PDMILEDCONNECTORS);
|
---|
4731 | else if (rc != VERR_PDM_NO_ATTACHED_DRIVER)
|
---|
4732 | {
|
---|
4733 | AssertMsgFailed(("Failed to attach to status driver. rc=%Rrc\n", rc));
|
---|
4734 | return rc;
|
---|
4735 | }
|
---|
4736 |
|
---|
4737 | /*
|
---|
4738 | * Register saved state and init the HGCM CmdList critsect.
|
---|
4739 | */
|
---|
4740 | rc = PDMDevHlpSSMRegisterEx(pDevIns, VMMDEV_SAVED_STATE_VERSION, sizeof(*pThis), NULL,
|
---|
4741 | NULL, vmmdevLiveExec, NULL,
|
---|
4742 | NULL, vmmdevSaveExec, NULL,
|
---|
4743 | NULL, vmmdevLoadExec, vmmdevLoadStateDone);
|
---|
4744 | AssertRCReturn(rc, rc);
|
---|
4745 |
|
---|
4746 | /*
|
---|
4747 | * Create heartbeat checking timer.
|
---|
4748 | */
|
---|
4749 | rc = PDMDevHlpTimerCreate(pDevIns, TMCLOCK_VIRTUAL, vmmDevHeartbeatFlatlinedTimer, pThis,
|
---|
4750 | TMTIMER_FLAGS_NO_CRIT_SECT, "Heartbeat flatlined", &pThis->hFlatlinedTimer);
|
---|
4751 | AssertRCReturn(rc, rc);
|
---|
4752 |
|
---|
4753 | #ifdef VBOX_WITH_HGCM
|
---|
4754 | rc = vmmdevR3HgcmInit(pThisCC);
|
---|
4755 | AssertRCReturn(rc, rc);
|
---|
4756 | #endif
|
---|
4757 |
|
---|
4758 | /*
|
---|
4759 | * In this version of VirtualBox the GUI checks whether "needs host cursor"
|
---|
4760 | * changes.
|
---|
4761 | */
|
---|
4762 | pThis->fMouseCapabilities |= VMMDEV_MOUSE_HOST_RECHECKS_NEEDS_HOST_CURSOR;
|
---|
4763 |
|
---|
4764 | /*
|
---|
4765 | * Statistics.
|
---|
4766 | */
|
---|
4767 | PDMDevHlpSTAMRegisterF(pDevIns, &pThis->StatMemBalloonChunks, STAMTYPE_U32, STAMVISIBILITY_ALWAYS, STAMUNIT_COUNT,
|
---|
4768 | "Memory balloon size", "BalloonChunks");
|
---|
4769 | PDMDevHlpSTAMRegisterF(pDevIns, &pThis->StatFastIrqAckR3, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_COUNT,
|
---|
4770 | "Fast IRQ acknowledgments handled in ring-3.", "FastIrqAckR3");
|
---|
4771 | PDMDevHlpSTAMRegisterF(pDevIns, &pThis->StatFastIrqAckRZ, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_COUNT,
|
---|
4772 | "Fast IRQ acknowledgments handled in ring-0 or raw-mode.", "FastIrqAckRZ");
|
---|
4773 | PDMDevHlpSTAMRegisterF(pDevIns, &pThis->StatSlowIrqAck, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_COUNT,
|
---|
4774 | "Slow IRQ acknowledgments (old style).", "SlowIrqAck");
|
---|
4775 | PDMDevHlpSTAMRegisterF(pDevIns, &pThisCC->StatReqBufAllocs, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_COUNT,
|
---|
4776 | "Times a larger request buffer was required.", "LargeReqBufAllocs");
|
---|
4777 | #ifdef VBOX_WITH_HGCM
|
---|
4778 | PDMDevHlpSTAMRegisterF(pDevIns, &pThisCC->StatHgcmCmdArrival, STAMTYPE_PROFILE, STAMVISIBILITY_ALWAYS, STAMUNIT_TICKS_PER_CALL,
|
---|
4779 | "Profiling HGCM call arrival processing", "/HGCM/MsgArrival");
|
---|
4780 | PDMDevHlpSTAMRegisterF(pDevIns, &pThisCC->StatHgcmCmdCompletion, STAMTYPE_PROFILE, STAMVISIBILITY_ALWAYS, STAMUNIT_TICKS_PER_CALL,
|
---|
4781 | "Profiling HGCM call completion processing", "/HGCM/MsgCompletion");
|
---|
4782 | PDMDevHlpSTAMRegisterF(pDevIns, &pThisCC->StatHgcmCmdTotal, STAMTYPE_PROFILE, STAMVISIBILITY_ALWAYS, STAMUNIT_TICKS_PER_CALL,
|
---|
4783 | "Profiling whole HGCM call.", "/HGCM/MsgTotal");
|
---|
4784 | PDMDevHlpSTAMRegisterF(pDevIns, &pThisCC->StatHgcmLargeCmdAllocs,STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_COUNT,
|
---|
4785 | "Times the allocation cache could not be used.", "/HGCM/LargeCmdAllocs");
|
---|
4786 | PDMDevHlpSTAMRegisterF(pDevIns, &pThisCC->StatHgcmFailedPageListLocking,STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_COUNT,
|
---|
4787 | "Times no-bounce page list locking failed.", "/HGCM/FailedPageListLocking");
|
---|
4788 | #endif
|
---|
4789 |
|
---|
4790 | /*
|
---|
4791 | * Generate a unique session id for this VM; it will be changed for each
|
---|
4792 | * start, reset or restore. This can be used for restore detection inside
|
---|
4793 | * the guest.
|
---|
4794 | */
|
---|
4795 | pThis->idSession = ASMReadTSC();
|
---|
4796 | return rc;
|
---|
4797 | }
|
---|
4798 |
|
---|
4799 | #else /* !IN_RING3 */
|
---|
4800 |
|
---|
4801 | /**
|
---|
4802 | * @callback_method_impl{PDMDEVREGR0,pfnConstruct}
|
---|
4803 | */
|
---|
4804 | static DECLCALLBACK(int) vmmdevRZConstruct(PPDMDEVINS pDevIns)
|
---|
4805 | {
|
---|
4806 | PDMDEV_CHECK_VERSIONS_RETURN(pDevIns);
|
---|
4807 | PVMMDEV pThis = PDMDEVINS_2_DATA(pDevIns, PVMMDEV);
|
---|
4808 | PVMMDEVCC pThisCC = PDMDEVINS_2_DATA_CC(pDevIns, PVMMDEVCC);
|
---|
4809 |
|
---|
4810 | int rc = PDMDevHlpSetDeviceCritSect(pDevIns, PDMDevHlpCritSectGetNop(pDevIns));
|
---|
4811 | AssertRCReturn(rc, rc);
|
---|
4812 |
|
---|
4813 | #if 0
|
---|
4814 | rc = PDMDevHlpIoPortSetUpContext(pDevIns, pThis->hIoPortBackdoorLog, vmmdevBackdoorLog, NULL /*pfnIn*/, NULL /*pvUser*/);
|
---|
4815 | AssertRCReturn(rc, rc);
|
---|
4816 | #endif
|
---|
4817 | #if 0 && defined(VMMDEV_WITH_ALT_TIMESYNC)
|
---|
4818 | rc = PDMDevHlpIoPortSetUpContext(pDevIns, pThis->hIoPortAltTimesync, vmmdevAltTimeSyncWrite, vmmdevAltTimeSyncRead, NULL);
|
---|
4819 | AssertRCReturn(rc, rc);
|
---|
4820 | #endif
|
---|
4821 |
|
---|
4822 | /*
|
---|
4823 | * We map the first page of the VMMDevRAM into raw-mode and kernel contexts so we
|
---|
4824 | * can handle interrupt acknowledge requests more timely (vmmdevFastRequestIrqAck).
|
---|
4825 | */
|
---|
4826 | rc = PDMDevHlpMmio2SetUpContext(pDevIns, pThis->hMmio2VMMDevRAM, 0, PAGE_SIZE, (void **)&pThisCC->CTX_SUFF(pVMMDevRAM));
|
---|
4827 | AssertRCReturn(rc, rc);
|
---|
4828 |
|
---|
4829 | rc = PDMDevHlpIoPortSetUpContext(pDevIns, pThis->hIoPortFast, vmmdevFastRequestHandler, vmmdevFastRequestIrqAck, NULL);
|
---|
4830 | AssertRCReturn(rc, rc);
|
---|
4831 |
|
---|
4832 | # ifndef VBOX_WITHOUT_TESTING_FEATURES
|
---|
4833 | /*
|
---|
4834 | * Initialize testing.
|
---|
4835 | */
|
---|
4836 | rc = vmmdevRZTestingInitialize(pDevIns);
|
---|
4837 | AssertRCReturn(rc, rc);
|
---|
4838 | # endif
|
---|
4839 |
|
---|
4840 | return VINF_SUCCESS;
|
---|
4841 | }
|
---|
4842 |
|
---|
4843 | #endif /* !IN_RING3 */
|
---|
4844 |
|
---|
4845 | /**
|
---|
4846 | * The device registration structure.
|
---|
4847 | */
|
---|
4848 | extern "C" const PDMDEVREG g_DeviceVMMDev =
|
---|
4849 | {
|
---|
4850 | /* .u32Version = */ PDM_DEVREG_VERSION,
|
---|
4851 | /* .uReserved0 = */ 0,
|
---|
4852 | /* .szName = */ "VMMDev",
|
---|
4853 | /* .fFlags = */ PDM_DEVREG_FLAGS_DEFAULT_BITS | PDM_DEVREG_FLAGS_RZ,
|
---|
4854 | /* .fClass = */ PDM_DEVREG_CLASS_VMM_DEV,
|
---|
4855 | /* .cMaxInstances = */ 1,
|
---|
4856 | /* .uSharedVersion = */ 42,
|
---|
4857 | /* .cbInstanceShared = */ sizeof(VMMDEV),
|
---|
4858 | /* .cbInstanceCC = */ sizeof(VMMDEVCC),
|
---|
4859 | /* .cbInstanceRC = */ sizeof(VMMDEVRC),
|
---|
4860 | /* .cMaxPciDevices = */ 1,
|
---|
4861 | /* .cMaxMsixVectors = */ 0,
|
---|
4862 | /* .pszDescription = */ "VirtualBox VMM Device\n",
|
---|
4863 | #if defined(IN_RING3)
|
---|
4864 | /* .pszRCMod = */ "VBoxDDRC.rc",
|
---|
4865 | /* .pszR0Mod = */ "VBoxDDR0.r0",
|
---|
4866 | /* .pfnConstruct = */ vmmdevConstruct,
|
---|
4867 | /* .pfnDestruct = */ vmmdevDestruct,
|
---|
4868 | # ifdef VBOX_WITH_RAW_MODE_KEEP
|
---|
4869 | /* .pfnRelocate = */ vmmdevRelocate,
|
---|
4870 | # else
|
---|
4871 | /* .pfnRelocate = */ NULL,
|
---|
4872 | # endif
|
---|
4873 | /* .pfnMemSetup = */ NULL,
|
---|
4874 | /* .pfnPowerOn = */ NULL,
|
---|
4875 | /* .pfnReset = */ vmmdevReset,
|
---|
4876 | /* .pfnSuspend = */ NULL,
|
---|
4877 | /* .pfnResume = */ NULL,
|
---|
4878 | /* .pfnAttach = */ NULL,
|
---|
4879 | /* .pfnDetach = */ NULL,
|
---|
4880 | /* .pfnQueryInterface = */ NULL,
|
---|
4881 | /* .pfnInitComplete = */ NULL,
|
---|
4882 | /* .pfnPowerOff = */ NULL,
|
---|
4883 | /* .pfnSoftReset = */ NULL,
|
---|
4884 | /* .pfnReserved0 = */ NULL,
|
---|
4885 | /* .pfnReserved1 = */ NULL,
|
---|
4886 | /* .pfnReserved2 = */ NULL,
|
---|
4887 | /* .pfnReserved3 = */ NULL,
|
---|
4888 | /* .pfnReserved4 = */ NULL,
|
---|
4889 | /* .pfnReserved5 = */ NULL,
|
---|
4890 | /* .pfnReserved6 = */ NULL,
|
---|
4891 | /* .pfnReserved7 = */ NULL,
|
---|
4892 | #elif defined(IN_RING0)
|
---|
4893 | /* .pfnEarlyConstruct = */ NULL,
|
---|
4894 | /* .pfnConstruct = */ vmmdevRZConstruct,
|
---|
4895 | /* .pfnDestruct = */ NULL,
|
---|
4896 | /* .pfnFinalDestruct = */ NULL,
|
---|
4897 | /* .pfnRequest = */ NULL,
|
---|
4898 | /* .pfnReserved0 = */ NULL,
|
---|
4899 | /* .pfnReserved1 = */ NULL,
|
---|
4900 | /* .pfnReserved2 = */ NULL,
|
---|
4901 | /* .pfnReserved3 = */ NULL,
|
---|
4902 | /* .pfnReserved4 = */ NULL,
|
---|
4903 | /* .pfnReserved5 = */ NULL,
|
---|
4904 | /* .pfnReserved6 = */ NULL,
|
---|
4905 | /* .pfnReserved7 = */ NULL,
|
---|
4906 | #elif defined(IN_RC)
|
---|
4907 | /* .pfnConstruct = */ vmmdevRZConstruct,
|
---|
4908 | /* .pfnReserved0 = */ NULL,
|
---|
4909 | /* .pfnReserved1 = */ NULL,
|
---|
4910 | /* .pfnReserved2 = */ NULL,
|
---|
4911 | /* .pfnReserved3 = */ NULL,
|
---|
4912 | /* .pfnReserved4 = */ NULL,
|
---|
4913 | /* .pfnReserved5 = */ NULL,
|
---|
4914 | /* .pfnReserved6 = */ NULL,
|
---|
4915 | /* .pfnReserved7 = */ NULL,
|
---|
4916 | #else
|
---|
4917 | # error "Not in IN_RING3, IN_RING0 or IN_RC!"
|
---|
4918 | #endif
|
---|
4919 | /* .u32VersionEnd = */ PDM_DEVREG_VERSION
|
---|
4920 | };
|
---|
4921 |
|
---|
4922 | #endif /* !VBOX_DEVICE_STRUCT_TESTCASE */
|
---|