VirtualBox

source: vbox/trunk/src/VBox/Devices/VMMDev/VMMDev.cpp@ 43416

Last change on this file since 43416 was 43320, checked in by vboxsync, 12 years ago

Devices/VMMDev: clear IRQ on reset or Additions start.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 141.3 KB
Line 
1/* $Id: VMMDev.cpp 43320 2012-09-13 14:28:30Z vboxsync $ */
2/** @file
3 * VMMDev - Guest <-> VMM/Host communication device.
4 */
5
6/*
7 * Copyright (C) 2006-2012 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
19/*******************************************************************************
20* Header Files *
21*******************************************************************************/
22
23/* Enable dev_vmm Log3 statements to get IRQ-related logging. */
24
25#define LOG_GROUP LOG_GROUP_DEV_VMM
26#include <VBox/VMMDev.h>
27#include <VBox/vmm/mm.h>
28#include <VBox/log.h>
29#include <VBox/param.h>
30#include <iprt/path.h>
31#include <iprt/dir.h>
32#include <iprt/file.h>
33#include <VBox/vmm/pgm.h>
34#include <VBox/err.h>
35#include <VBox/vmm/vm.h> /* for VM_IS_EMT */
36#include <VBox/dbg.h>
37#include <VBox/version.h>
38
39#include <iprt/asm.h>
40#include <iprt/asm-amd64-x86.h>
41#include <iprt/assert.h>
42#include <iprt/buildconfig.h>
43#include <iprt/string.h>
44#include <iprt/time.h>
45#ifndef IN_RC
46# include <iprt/mem.h>
47#endif
48#ifdef IN_RING3
49# include <iprt/uuid.h>
50#endif
51
52#include "VMMDevState.h"
53#ifdef VBOX_WITH_HGCM
54# include "VMMDevHGCM.h"
55#endif
56#ifndef VBOX_WITHOUT_TESTING_FEATURES
57# include "VMMDevTesting.h"
58#endif
59
60
61/*******************************************************************************
62* Defined Constants And Macros *
63*******************************************************************************/
64#define PCIDEV_2_VMMDEVSTATE(pPciDev) ( (VMMDevState *)(pPciDev) )
65#define VMMDEVSTATE_2_DEVINS(pVMMDevState) ( (pVMMDevState)->pDevIns )
66
67#define VBOX_GUEST_INTERFACE_VERSION_1_03(s) \
68 ( RT_HIWORD((s)->guestInfo.interfaceVersion) == 1 \
69 && RT_LOWORD((s)->guestInfo.interfaceVersion) == 3 )
70
71#define VBOX_GUEST_INTERFACE_VERSION_OK(additionsVersion) \
72 ( RT_HIWORD(additionsVersion) == RT_HIWORD(VMMDEV_VERSION) \
73 && RT_LOWORD(additionsVersion) <= RT_LOWORD(VMMDEV_VERSION) )
74
75#define VBOX_GUEST_INTERFACE_VERSION_OLD(additionsVersion) \
76 ( (RT_HIWORD(additionsVersion) < RT_HIWORD(VMMDEV_VERSION) \
77 || ( RT_HIWORD(additionsVersion) == RT_HIWORD(VMMDEV_VERSION) \
78 && RT_LOWORD(additionsVersion) <= RT_LOWORD(VMMDEV_VERSION) ) )
79
80#define VBOX_GUEST_INTERFACE_VERSION_TOO_OLD(additionsVersion) \
81 ( RT_HIWORD(additionsVersion) < RT_HIWORD(VMMDEV_VERSION) )
82
83#define VBOX_GUEST_INTERFACE_VERSION_NEW(additionsVersion) \
84 ( RT_HIWORD(additionsVersion) > RT_HIWORD(VMMDEV_VERSION) \
85 || ( RT_HIWORD(additionsVersion) == RT_HIWORD(VMMDEV_VERSION) \
86 && RT_LOWORD(additionsVersion) > RT_LOWORD(VMMDEV_VERSION) ) )
87
88/** The saved state version. */
89#define VMMDEV_SAVED_STATE_VERSION 15
90/** The saved state version which is missing the guest facility statuses. */
91#define VMMDEV_SAVED_STATE_VERSION_MISSING_FACILITY_STATUSES 14
92/** The saved state version which is missing the guestInfo2 bits. */
93#define VMMDEV_SAVED_STATE_VERSION_MISSING_GUEST_INFO_2 13
94/** The saved state version used by VirtualBox 3.0.
95 * This doesn't have the config part. */
96#define VMMDEV_SAVED_STATE_VERSION_VBOX_30 11
97
98
99#ifndef VBOX_DEVICE_STRUCT_TESTCASE
100
101/* Whenever host wants to inform guest about something
102 * an IRQ notification will be raised.
103 *
104 * VMMDev PDM interface will contain the guest notification method.
105 *
106 * There is a 32 bit event mask which will be read
107 * by guest on an interrupt. A non zero bit in the mask
108 * means that the specific event occurred and requires
109 * processing on guest side.
110 *
111 * After reading the event mask guest must issue a
112 * generic request AcknowlegdeEvents.
113 *
114 * IRQ line is set to 1 (request) if there are unprocessed
115 * events, that is the event mask is not zero.
116 *
117 * After receiving an interrupt and checking event mask,
118 * the guest must process events using the event specific
119 * mechanism.
120 *
121 * That is if mouse capabilities were changed,
122 * guest will use VMMDev_GetMouseStatus generic request.
123 *
124 * Event mask is only a set of flags indicating that guest
125 * must proceed with a procedure.
126 *
127 * Unsupported events are therefore ignored.
128 * The guest additions must inform host which events they
129 * want to receive, to avoid unnecessary IRQ processing.
130 * By default no events are signalled to guest.
131 *
132 * This seems to be fast method. It requires
133 * only one context switch for an event processing.
134 *
135 */
136
137static void vmmdevSetIRQ_Legacy_EMT (VMMDevState *pVMMDevState)
138{
139 if (!pVMMDevState->fu32AdditionsOk)
140 {
141 Log(("vmmdevSetIRQ: IRQ is not generated, guest has not yet reported to us.\n"));
142 return;
143 }
144
145 uint32_t u32IRQLevel = 0;
146
147 /* Filter unsupported events */
148 uint32_t u32EventFlags =
149 pVMMDevState->u32HostEventFlags
150 & pVMMDevState->pVMMDevRAMR3->V.V1_03.u32GuestEventMask;
151
152 Log(("vmmdevSetIRQ: u32EventFlags = 0x%08X, "
153 "pVMMDevState->u32HostEventFlags = 0x%08X, "
154 "pVMMDevState->pVMMDevRAMR3->u32GuestEventMask = 0x%08X\n",
155 u32EventFlags,
156 pVMMDevState->u32HostEventFlags,
157 pVMMDevState->pVMMDevRAMR3->V.V1_03.u32GuestEventMask));
158
159 /* Move event flags to VMMDev RAM */
160 pVMMDevState->pVMMDevRAMR3->V.V1_03.u32HostEvents = u32EventFlags;
161
162 if (u32EventFlags)
163 {
164 /* Clear host flags which will be delivered to guest. */
165 pVMMDevState->u32HostEventFlags &= ~u32EventFlags;
166 Log(("vmmdevSetIRQ: pVMMDevState->u32HostEventFlags = 0x%08X\n",
167 pVMMDevState->u32HostEventFlags));
168 u32IRQLevel = 1;
169 }
170
171 /* Set IRQ level for pin 0 */
172 /** @todo make IRQ pin configurable, at least a symbolic constant */
173 PPDMDEVINS pDevIns = VMMDEVSTATE_2_DEVINS(pVMMDevState);
174 PDMDevHlpPCISetIrqNoWait(pDevIns, 0, u32IRQLevel);
175 Log(("vmmdevSetIRQ: IRQ set %d\n", u32IRQLevel));
176}
177
178static void vmmdevMaybeSetIRQ_EMT (VMMDevState *pVMMDevState)
179{
180 PPDMDEVINS pDevIns = VMMDEVSTATE_2_DEVINS (pVMMDevState);
181
182 Log3(("vmmdevMaybeSetIRQ_EMT: u32HostEventFlags = 0x%08X, u32GuestFilterMask = 0x%08X.\n",
183 pVMMDevState->u32HostEventFlags, pVMMDevState->u32GuestFilterMask));
184
185 if (pVMMDevState->u32HostEventFlags & pVMMDevState->u32GuestFilterMask)
186 {
187 pVMMDevState->pVMMDevRAMR3->V.V1_04.fHaveEvents = true;
188 PDMDevHlpPCISetIrqNoWait (pDevIns, 0, 1);
189 Log3(("vmmdevMaybeSetIRQ_EMT: IRQ set.\n"));
190 }
191}
192
193static void vmmdevNotifyGuest_EMT (VMMDevState *pVMMDevState, uint32_t u32EventMask)
194{
195 Log3(("VMMDevNotifyGuest_EMT: u32EventMask = 0x%08X.\n", u32EventMask));
196
197 if (VBOX_GUEST_INTERFACE_VERSION_1_03 (pVMMDevState))
198 {
199 Log3(("VMMDevNotifyGuest_EMT: Old additions detected.\n"));
200
201 pVMMDevState->u32HostEventFlags |= u32EventMask;
202 vmmdevSetIRQ_Legacy_EMT (pVMMDevState);
203 }
204 else
205 {
206 Log3(("VMMDevNotifyGuest_EMT: New additions detected.\n"));
207
208 if (!pVMMDevState->fu32AdditionsOk)
209 {
210 pVMMDevState->u32HostEventFlags |= u32EventMask;
211 Log(("vmmdevNotifyGuest_EMT: IRQ is not generated, guest has not yet reported to us.\n"));
212 return;
213 }
214
215 const bool fHadEvents =
216 (pVMMDevState->u32HostEventFlags & pVMMDevState->u32GuestFilterMask) != 0;
217
218 Log3(("VMMDevNotifyGuest_EMT: fHadEvents = %d, u32HostEventFlags = 0x%08X, u32GuestFilterMask = 0x%08X.\n",
219 fHadEvents, pVMMDevState->u32HostEventFlags, pVMMDevState->u32GuestFilterMask));
220
221 pVMMDevState->u32HostEventFlags |= u32EventMask;
222
223 if (!fHadEvents)
224 vmmdevMaybeSetIRQ_EMT (pVMMDevState);
225 }
226}
227
228void VMMDevCtlSetGuestFilterMask (VMMDevState *pVMMDevState,
229 uint32_t u32OrMask,
230 uint32_t u32NotMask)
231{
232 PDMCritSectEnter(&pVMMDevState->CritSect, VERR_SEM_BUSY);
233
234 const bool fHadEvents =
235 (pVMMDevState->u32HostEventFlags & pVMMDevState->u32GuestFilterMask) != 0;
236
237 Log(("VMMDevCtlSetGuestFilterMask: u32OrMask = 0x%08X, u32NotMask = 0x%08X, fHadEvents = %d.\n", u32OrMask, u32NotMask, fHadEvents));
238 if (fHadEvents)
239 {
240 if (!pVMMDevState->fNewGuestFilterMask)
241 pVMMDevState->u32NewGuestFilterMask = pVMMDevState->u32GuestFilterMask;
242
243 pVMMDevState->u32NewGuestFilterMask |= u32OrMask;
244 pVMMDevState->u32NewGuestFilterMask &= ~u32NotMask;
245 pVMMDevState->fNewGuestFilterMask = true;
246 }
247 else
248 {
249 pVMMDevState->u32GuestFilterMask |= u32OrMask;
250 pVMMDevState->u32GuestFilterMask &= ~u32NotMask;
251 vmmdevMaybeSetIRQ_EMT (pVMMDevState);
252 }
253 PDMCritSectLeave(&pVMMDevState->CritSect);
254}
255
256void VMMDevNotifyGuest (VMMDevState *pVMMDevState, uint32_t u32EventMask)
257{
258 PPDMDEVINS pDevIns = VMMDEVSTATE_2_DEVINS(pVMMDevState);
259
260 Log3(("VMMDevNotifyGuest: u32EventMask = 0x%08X.\n", u32EventMask));
261
262 /*
263 * Drop notifications if the VM is not running yet/anymore.
264 */
265 VMSTATE enmVMState = PDMDevHlpVMState(pDevIns);
266 if ( enmVMState != VMSTATE_RUNNING
267 && enmVMState != VMSTATE_RUNNING_LS)
268 return;
269
270 PDMCritSectEnter(&pVMMDevState->CritSect, VERR_SEM_BUSY);
271 /* No need to wait for the completion of this request. It is a notification
272 * about something, which has already happened.
273 */
274 vmmdevNotifyGuest_EMT(pVMMDevState, u32EventMask);
275 PDMCritSectLeave(&pVMMDevState->CritSect);
276}
277
278/**
279 * Port I/O Handler for OUT operations.
280 *
281 * @returns VBox status code.
282 *
283 * @param pDevIns The device instance.
284 * @param pvUser User argument - ignored.
285 * @param uPort Port number used for the IN operation.
286 * @param u32 The value to output.
287 * @param cb The value size in bytes.
288 */
289static DECLCALLBACK(int) vmmdevBackdoorLog(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT Port, uint32_t u32, unsigned cb)
290{
291 VMMDevState *pThis = PDMINS_2_DATA(pDevIns, VMMDevState *);
292
293 if (!pThis->fBackdoorLogDisabled && cb == 1 && Port == RTLOG_DEBUG_PORT)
294 {
295
296 /* The raw version. */
297 switch (u32)
298 {
299 case '\r': LogIt(LOG_INSTANCE, RTLOGGRPFLAGS_LEVEL_2, LOG_GROUP_DEV_VMM_BACKDOOR, ("vmmdev: <return>\n")); break;
300 case '\n': LogIt(LOG_INSTANCE, RTLOGGRPFLAGS_LEVEL_2, LOG_GROUP_DEV_VMM_BACKDOOR, ("vmmdev: <newline>\n")); break;
301 case '\t': LogIt(LOG_INSTANCE, RTLOGGRPFLAGS_LEVEL_2, LOG_GROUP_DEV_VMM_BACKDOOR, ("vmmdev: <tab>\n")); break;
302 default: LogIt(LOG_INSTANCE, RTLOGGRPFLAGS_LEVEL_2, LOG_GROUP_DEV_VMM_BACKDOOR, ("vmmdev: %c (%02x)\n", u32, u32)); break;
303 }
304
305 /* The readable, buffered version. */
306 if (u32 == '\n' || u32 == '\r')
307 {
308 pThis->szMsg[pThis->iMsg] = '\0';
309 if (pThis->iMsg)
310 LogRelIt(LOG_REL_INSTANCE, RTLOGGRPFLAGS_LEVEL_1, LOG_GROUP_DEV_VMM_BACKDOOR, ("Guest Log: %s\n", pThis->szMsg));
311 pThis->iMsg = 0;
312 }
313 else
314 {
315 if (pThis->iMsg >= sizeof(pThis->szMsg)-1)
316 {
317 pThis->szMsg[pThis->iMsg] = '\0';
318 LogRelIt(LOG_REL_INSTANCE, RTLOGGRPFLAGS_LEVEL_1, LOG_GROUP_DEV_VMM_BACKDOOR, ("Guest Log: %s\n", pThis->szMsg));
319 pThis->iMsg = 0;
320 }
321 pThis->szMsg[pThis->iMsg] = (char )u32;
322 pThis->szMsg[++pThis->iMsg] = '\0';
323 }
324 }
325 return VINF_SUCCESS;
326}
327
328#ifdef TIMESYNC_BACKDOOR
329/**
330 * Port I/O Handler for OUT operations.
331 *
332 * @returns VBox status code.
333 *
334 * @param pDevIns The device instance.
335 * @param pvUser User argument - ignored.
336 * @param uPort Port number used for the IN operation.
337 * @param u32 The value to output.
338 * @param cb The value size in bytes.
339 */
340static DECLCALLBACK(int) vmmdevTimesyncBackdoorWrite(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT Port, uint32_t u32, unsigned cb)
341{
342 NOREF(pvUser);
343 if (cb == 4)
344 {
345 VMMDevState *pThis = PDMINS_2_DATA(pDevIns, VMMDevState *);
346 switch (u32)
347 {
348 case 0:
349 pThis->fTimesyncBackdoorLo = false;
350 break;
351 case 1:
352 pThis->fTimesyncBackdoorLo = true;
353 }
354 return VINF_SUCCESS;
355
356 }
357 return VINF_SUCCESS;
358}
359
360/**
361 * Port I/O Handler for backdoor timesync IN operations.
362 *
363 * @returns VBox status code.
364 *
365 * @param pDevIns The device instance.
366 * @param pvUser User argument - ignored.
367 * @param uPort Port number used for the IN operation.
368 * @param pu32 Where to store the result.
369 * @param cb Number of bytes read.
370 */
371static DECLCALLBACK(int) vmmdevTimesyncBackdoorRead(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT Port, uint32_t *pu32, unsigned cb)
372{
373 int rc;
374 NOREF(pvUser);
375 if (cb == 4)
376 {
377 VMMDevState *pThis = PDMINS_2_DATA(pDevIns, VMMDevState *);
378 RTTIMESPEC now;
379
380 if (pThis->fTimesyncBackdoorLo)
381 *pu32 = (uint32_t)pThis->hostTime;
382 else
383 {
384 pThis->hostTime = RTTimeSpecGetMilli(PDMDevHlpTMUtcNow(pDevIns, &now));
385 *pu32 = (uint32_t)(pThis->hostTime >> 32);
386 }
387 rc = VINF_SUCCESS;
388 }
389 else
390 rc = VERR_IOM_IOPORT_UNUSED;
391 return rc;
392}
393#endif /* TIMESYNC_BACKDOOR */
394
395/**
396 * Validates a publisher tag.
397 *
398 * @returns true / false.
399 * @param pszTag Tag to validate.
400 */
401static bool vmmdevReqIsValidPublisherTag(const char *pszTag)
402{
403 /* Note! This character set is also found in Config.kmk. */
404 static char const s_szValidChars[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz()[]{}+-.,";
405
406 while (*pszTag != '\0')
407 {
408 if (!strchr(s_szValidChars, *pszTag))
409 return false;
410 pszTag++;
411 }
412 return true;
413}
414
415
416/**
417 * Validates a build tag.
418 *
419 * @returns true / false.
420 * @param pszTag Tag to validate.
421 */
422static bool vmmdevReqIsValidBuildTag(const char *pszTag)
423{
424 int cchPrefix;
425 if (!strncmp(pszTag, "RC", 2))
426 cchPrefix = 2;
427 else if (!strncmp(pszTag, "BETA", 4))
428 cchPrefix = 4;
429 else if (!strncmp(pszTag, "ALPHA", 5))
430 cchPrefix = 5;
431 else
432 return false;
433
434 if (pszTag[cchPrefix] == '\0')
435 return true;
436
437 uint8_t u8;
438 int rc = RTStrToUInt8Full(&pszTag[cchPrefix], 10, &u8);
439 return rc == VINF_SUCCESS;
440}
441
442/**
443 * Handles VMMDevReq_ReportGuestInfo2.
444 *
445 * @returns VBox status code that the guest should see.
446 * @param pThis The VMMDev instance data.
447 * @param pRequestHeader The header of the request to handle.
448 */
449static int vmmdevReqHandler_ReportGuestInfo2(VMMDevState *pThis, VMMDevRequestHeader *pRequestHeader)
450{
451 AssertMsgReturn(pRequestHeader->size == sizeof(VMMDevReportGuestInfo2), ("%u\n", pRequestHeader->size), VERR_INVALID_PARAMETER);
452 VBoxGuestInfo2 const *pInfo2 = &((VMMDevReportGuestInfo2 *)pRequestHeader)->guestInfo;
453
454 LogRel(("Guest Additions information report: Version %d.%d.%d r%d '%.*s'\n",
455 pInfo2->additionsMajor, pInfo2->additionsMinor, pInfo2->additionsBuild,
456 pInfo2->additionsRevision, sizeof(pInfo2->szName), pInfo2->szName));
457
458 /* The interface was introduced in 3.2 and will definitely not be
459 backported beyond 3.0 (bird). */
460 AssertMsgReturn(pInfo2->additionsMajor >= 3,
461 ("%u.%u.%u\n", pInfo2->additionsMajor, pInfo2->additionsMinor, pInfo2->additionsBuild),
462 VERR_INVALID_PARAMETER);
463
464 /* The version must fit in a full version compression. */
465 uint32_t uFullVersion = VBOX_FULL_VERSION_MAKE(pInfo2->additionsMajor, pInfo2->additionsMinor, pInfo2->additionsBuild);
466 AssertMsgReturn( VBOX_FULL_VERSION_GET_MAJOR(uFullVersion) == pInfo2->additionsMajor
467 && VBOX_FULL_VERSION_GET_MINOR(uFullVersion) == pInfo2->additionsMinor
468 && VBOX_FULL_VERSION_GET_BUILD(uFullVersion) == pInfo2->additionsBuild,
469 ("%u.%u.%u\n", pInfo2->additionsMajor, pInfo2->additionsMinor, pInfo2->additionsBuild),
470 VERR_OUT_OF_RANGE);
471
472 /*
473 * Validate the name.
474 * Be less strict towards older additions (< v4.1.50).
475 */
476 AssertCompile(sizeof(pThis->guestInfo2.szName) == sizeof(pInfo2->szName));
477 AssertReturn(memchr(pInfo2->szName, '\0', sizeof(pInfo2->szName)) != NULL, VERR_INVALID_PARAMETER);
478 const char *pszName = pInfo2->szName;
479
480 /* The version number which shouldn't be there. */
481 char szTmp[sizeof(pInfo2->szName)];
482 size_t cchStart = RTStrPrintf(szTmp, sizeof(szTmp), "%u.%u.%u", pInfo2->additionsMajor, pInfo2->additionsMinor, pInfo2->additionsBuild);
483 AssertMsgReturn(!strncmp(pszName, szTmp, cchStart), ("%s != %s\n", pszName, szTmp), VERR_INVALID_PARAMETER);
484 pszName += cchStart;
485
486 /* Now we can either have nothing or a build tag or/and a publisher tag. */
487 if (*pszName != '\0')
488 {
489 const char *pszRelaxedName = "";
490 bool const fStrict = pInfo2->additionsMajor > 4
491 || (pInfo2->additionsMajor == 4 && pInfo2->additionsMinor > 1)
492 || (pInfo2->additionsMajor == 4 && pInfo2->additionsMinor == 1 && pInfo2->additionsBuild >= 50);
493 bool fOk = false;
494 if (*pszName == '_')
495 {
496 pszName++;
497 strcpy(szTmp, pszName);
498 char *pszTag2 = strchr(szTmp, '_');
499 if (!pszTag2)
500 {
501 fOk = vmmdevReqIsValidBuildTag(szTmp)
502 || vmmdevReqIsValidPublisherTag(szTmp);
503 }
504 else
505 {
506 *pszTag2++ = '\0';
507 fOk = vmmdevReqIsValidBuildTag(szTmp);
508 if (fOk)
509 {
510 fOk = vmmdevReqIsValidPublisherTag(pszTag2);
511 if (!fOk)
512 pszRelaxedName = szTmp;
513 }
514 }
515 }
516
517 if (!fOk)
518 {
519 AssertLogRelMsgReturn(!fStrict, ("%s", pszName), VERR_INVALID_PARAMETER);
520
521 /* non-strict mode, just zap the extra stuff. */
522 LogRel(("ReportGuestInfo2: Ignoring unparsable version name bits: '%s' -> '%s'.\n", pszName, pszRelaxedName));
523 pszName = pszRelaxedName;
524 }
525 }
526
527 /*
528 * Save the info and tell Main or whoever is listening.
529 */
530 pThis->guestInfo2.uFullVersion = uFullVersion;
531 pThis->guestInfo2.uRevision = pInfo2->additionsRevision;
532 pThis->guestInfo2.fFeatures = pInfo2->additionsFeatures;
533 strcpy(pThis->guestInfo2.szName, pszName);
534
535 if (pThis->pDrv && pThis->pDrv->pfnUpdateGuestInfo2)
536 pThis->pDrv->pfnUpdateGuestInfo2(pThis->pDrv, uFullVersion, pszName, pInfo2->additionsRevision, pInfo2->additionsFeatures);
537
538 /* Clear our IRQ in case it was high for whatever reason. */
539 PDMDevHlpPCISetIrqNoWait (pThis->pDevIns, 0, 0);
540
541 return VINF_SUCCESS;
542}
543
544/**
545 * Allocates a new facility status entry, initializing it to inactive.
546 *
547 * @returns Pointer to a facility status entry on success, NULL on failure
548 * (table full).
549 * @param pThis The VMMDev instance data.
550 * @param uFacility The facility type code - VBoxGuestFacilityType.
551 * @param fFixed This is set when allocating the standard entries
552 * from the constructor.
553 * @param pTimeSpecNow Optionally giving the entry timestamp to use (ctor).
554 */
555static PVMMDEVFACILITYSTATUSENTRY
556vmmdevAllocFacilityStatusEntry(VMMDevState *pThis, uint32_t uFacility, bool fFixed, PCRTTIMESPEC pTimeSpecNow)
557{
558 /* If full, expunge one inactive entry. */
559 if (pThis->cFacilityStatuses == RT_ELEMENTS(pThis->aFacilityStatuses))
560 {
561 uint32_t i = pThis->cFacilityStatuses;
562 while (i-- > 0)
563 {
564 if ( pThis->aFacilityStatuses[i].uStatus == VBoxGuestFacilityStatus_Inactive
565 && !pThis->aFacilityStatuses[i].fFixed)
566 {
567 pThis->cFacilityStatuses--;
568 int cToMove = pThis->cFacilityStatuses - i;
569 if (cToMove)
570 memmove(&pThis->aFacilityStatuses[i], &pThis->aFacilityStatuses[i + 1],
571 cToMove * sizeof(pThis->aFacilityStatuses[i]));
572 RT_ZERO(pThis->aFacilityStatuses[pThis->cFacilityStatuses]);
573 break;
574 }
575 }
576
577 if (pThis->cFacilityStatuses == RT_ELEMENTS(pThis->aFacilityStatuses))
578 return NULL;
579 }
580
581 /* Find location in array (it's sorted). */
582 uint32_t i = pThis->cFacilityStatuses;
583 while (i-- > 0)
584 if (pThis->aFacilityStatuses[i].uFacility < uFacility)
585 break;
586 i++;
587
588 /* Move. */
589 int cToMove = pThis->cFacilityStatuses - i;
590 if (cToMove > 0)
591 memmove(&pThis->aFacilityStatuses[i + 1], &pThis->aFacilityStatuses[i],
592 cToMove * sizeof(pThis->aFacilityStatuses[i]));
593 pThis->cFacilityStatuses++;
594
595 /* Initialize. */
596 pThis->aFacilityStatuses[i].uFacility = uFacility;
597 pThis->aFacilityStatuses[i].uStatus = VBoxGuestFacilityStatus_Inactive;
598 pThis->aFacilityStatuses[i].fFixed = fFixed;
599 pThis->aFacilityStatuses[i].fPadding = 0;
600 pThis->aFacilityStatuses[i].fFlags = 0;
601 pThis->aFacilityStatuses[i].uPadding = 0;
602 if (pTimeSpecNow)
603 pThis->aFacilityStatuses[i].TimeSpecTS = *pTimeSpecNow;
604 else
605 RTTimeSpecSetNano(&pThis->aFacilityStatuses[i].TimeSpecTS, 0);
606
607 return &pThis->aFacilityStatuses[i];
608
609}
610
611/**
612 * Gets a facility status entry, allocating a new one if not already present.
613 *
614 * @returns Pointer to a facility status entry on success, NULL on failure
615 * (table full).
616 * @param pThis The VMMDev instance data.
617 * @param uFacility The facility type code - VBoxGuestFacilityType.
618 */
619static PVMMDEVFACILITYSTATUSENTRY vmmdevGetFacilityStatusEntry(VMMDevState *pThis, uint32_t uFacility)
620{
621 /** @todo change to binary search. */
622 uint32_t i = pThis->cFacilityStatuses;
623 while (i-- > 0)
624 {
625 if (pThis->aFacilityStatuses[i].uFacility == uFacility)
626 return &pThis->aFacilityStatuses[i];
627 if (pThis->aFacilityStatuses[i].uFacility < uFacility)
628 break;
629 }
630 return vmmdevAllocFacilityStatusEntry(pThis, uFacility, false /*fFixed*/, NULL);
631}
632
633/**
634 * Handles VMMDevReq_ReportGuestStatus.
635 *
636 * @returns VBox status code that the guest should see.
637 * @param pThis The VMMDev instance data.
638 * @param pRequestHeader The header of the request to handle.
639 */
640static int vmmdevReqHandler_ReportGuestStatus(VMMDevState *pThis, VMMDevRequestHeader *pRequestHeader)
641{
642 /*
643 * Validate input.
644 */
645 AssertMsgReturn(pRequestHeader->size == sizeof(VMMDevReportGuestStatus), ("%u\n", pRequestHeader->size), VERR_INVALID_PARAMETER);
646 VBoxGuestStatus *pStatus = &((VMMDevReportGuestStatus *)pRequestHeader)->guestStatus;
647 AssertMsgReturn( pStatus->facility > VBoxGuestFacilityType_Unknown
648 && pStatus->facility <= VBoxGuestFacilityType_All,
649 ("%d\n", pStatus->facility),
650 VERR_INVALID_PARAMETER);
651 AssertMsgReturn(pStatus->status == (VBoxGuestFacilityStatus)(uint16_t)pStatus->status,
652 ("%#x (%u)\n", pStatus->status, pStatus->status),
653 VERR_OUT_OF_RANGE);
654
655 /*
656 * Do the update.
657 */
658 RTTIMESPEC Now;
659 RTTimeNow(&Now);
660 if (pStatus->facility == VBoxGuestFacilityType_All)
661 {
662 uint32_t i = pThis->cFacilityStatuses;
663 while (i-- > 0)
664 {
665 pThis->aFacilityStatuses[i].TimeSpecTS = Now;
666 pThis->aFacilityStatuses[i].uStatus = (uint16_t)pStatus->status;
667 pThis->aFacilityStatuses[i].fFlags = pStatus->flags;
668 }
669 }
670 else
671 {
672 PVMMDEVFACILITYSTATUSENTRY pEntry = vmmdevGetFacilityStatusEntry(pThis, pStatus->facility);
673 if (!pEntry)
674 {
675 static int g_cLogEntries = 0;
676 if (g_cLogEntries++ < 10)
677 LogRel(("VMM: Facility table is full - facility=%u status=%u.\n", pStatus->facility, pStatus->status));
678 return VERR_OUT_OF_RESOURCES;
679 }
680
681 pEntry->TimeSpecTS = Now;
682 pEntry->uStatus = (uint16_t)pStatus->status;
683 pEntry->fFlags = pStatus->flags;
684 }
685
686 if (pThis->pDrv && pThis->pDrv->pfnUpdateGuestStatus)
687 pThis->pDrv->pfnUpdateGuestStatus(pThis->pDrv, pStatus->facility, pStatus->status, pStatus->flags, &Now);
688
689 return VINF_SUCCESS;
690}
691
692#ifdef VBOX_WITH_PAGE_SHARING
693
694/**
695 * Handles VMMDevReq_RegisterSharedModule.
696 *
697 * @returns VBox status code that the guest should see.
698 * @param pDevIns The VMMDev device instance.
699 * @param pReq Pointer to the request.
700 */
701static int vmmdevReqHandler_RegisterSharedModule(PPDMDEVINS pDevIns, VMMDevSharedModuleRegistrationRequest *pReq)
702{
703 /*
704 * Basic input validation (more done by GMM).
705 */
706 AssertMsgReturn(pReq->header.size >= sizeof(VMMDevSharedModuleRegistrationRequest),
707 ("%u\n", pReq->header.size), VERR_INVALID_PARAMETER);
708 AssertMsgReturn(pReq->header.size == RT_UOFFSETOF(VMMDevSharedModuleRegistrationRequest, aRegions[pReq->cRegions]),
709 ("%u cRegions=%u\n", pReq->header.size, pReq->cRegions), VERR_INVALID_PARAMETER);
710
711 AssertReturn(memchr(pReq->szName, '\0', sizeof(pReq->szName)), VERR_INVALID_PARAMETER);
712 AssertReturn(memchr(pReq->szVersion, '\0', sizeof(pReq->szVersion)), VERR_INVALID_PARAMETER);
713
714 /*
715 * Forward the request to the VMM.
716 */
717 return PGMR3SharedModuleRegister(PDMDevHlpGetVM(pDevIns), pReq->enmGuestOS, pReq->szName, pReq->szVersion,
718 pReq->GCBaseAddr, pReq->cbModule, pReq->cRegions, pReq->aRegions);
719}
720
721/**
722 * Handles VMMDevReq_UnregisterSharedModule.
723 *
724 * @returns VBox status code that the guest should see.
725 * @param pDevIns The VMMDev device instance.
726 * @param pReq Pointer to the request.
727 */
728static int vmmdevReqHandler_UnregisterSharedModule(PPDMDEVINS pDevIns, VMMDevSharedModuleUnregistrationRequest *pReq)
729{
730 /*
731 * Basic input validation.
732 */
733 AssertMsgReturn(pReq->header.size == sizeof(VMMDevSharedModuleUnregistrationRequest),
734 ("%u\n", pReq->header.size), VERR_INVALID_PARAMETER);
735
736 AssertReturn(memchr(pReq->szName, '\0', sizeof(pReq->szName)), VERR_INVALID_PARAMETER);
737 AssertReturn(memchr(pReq->szVersion, '\0', sizeof(pReq->szVersion)), VERR_INVALID_PARAMETER);
738
739 /*
740 * Forward the request to the VMM.
741 */
742 return PGMR3SharedModuleUnregister(PDMDevHlpGetVM(pDevIns), pReq->szName, pReq->szVersion,
743 pReq->GCBaseAddr, pReq->cbModule);
744}
745
746/**
747 * Handles VMMDevReq_CheckSharedModules.
748 *
749 * @returns VBox status code that the guest should see.
750 * @param pDevIns The VMMDev device instance.
751 * @param pReq Pointer to the request.
752 */
753static int vmmdevReqHandler_CheckSharedModules(PPDMDEVINS pDevIns, VMMDevSharedModuleCheckRequest *pReq)
754{
755 AssertMsgReturn(pReq->header.size == sizeof(VMMDevSharedModuleCheckRequest),
756 ("%u\n", pReq->header.size), VERR_INVALID_PARAMETER);
757 return PGMR3SharedModuleCheckAll(PDMDevHlpGetVM(pDevIns));
758}
759
760/**
761 * Handles VMMDevReq_GetPageSharingStatus.
762 *
763 * @returns VBox status code that the guest should see.
764 * @param pThis The VMMDev instance data.
765 * @param pReq Pointer to the request.
766 */
767static int vmmdevReqHandler_GetPageSharingStatus(VMMDevState *pThis, VMMDevPageSharingStatusRequest *pReq)
768{
769 AssertMsgReturn(pReq->header.size == sizeof(VMMDevPageSharingStatusRequest),
770 ("%u\n", pReq->header.size), VERR_INVALID_PARAMETER);
771
772 pReq->fEnabled = false;
773 int rc = pThis->pDrv->pfnIsPageFusionEnabled(pThis->pDrv, &pReq->fEnabled);
774 if (RT_FAILURE(rc))
775 pReq->fEnabled = false;
776 return VINF_SUCCESS;
777}
778
779
780/**
781 * Handles VMMDevReq_DebugIsPageShared.
782 *
783 * @returns VBox status code that the guest should see.
784 * @param pDevIns The VMMDev device instance.
785 * @param pReq Pointer to the request.
786 */
787static int vmmdevReqHandler_DebugIsPageShared(PPDMDEVINS pDevIns, VMMDevPageIsSharedRequest *pReq)
788{
789 AssertMsgReturn(pReq->header.size == sizeof(VMMDevPageIsSharedRequest),
790 ("%u\n", pReq->header.size), VERR_INVALID_PARAMETER);
791
792#ifdef DEBUG
793 return PGMR3SharedModuleGetPageState(PDMDevHlpGetVM(pDevIns), pReq->GCPtrPage, &pReq->fShared, &pReq->uPageFlags);
794#else
795 return VERR_NOT_IMPLEMENTED;
796#endif
797}
798
799#endif /* VBOX_WITH_PAGE_SHARING */
800
801/**
802 * Port I/O Handler for the generic request interface
803 * @see FNIOMIOPORTOUT for details.
804 *
805 * @todo This function is too long!! All new request SHALL be implemented as
806 * functions called from the switch! When making changes, please move the
807 * relevant cases into functions.
808 */
809static DECLCALLBACK(int) vmmdevRequestHandler(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT Port, uint32_t u32, unsigned cb)
810{
811 VMMDevState *pThis = (VMMDevState*)pvUser;
812 int rcRet = VINF_SUCCESS;
813 PDMCritSectEnter(&pThis->CritSect, VERR_SEM_BUSY);
814
815 /*
816 * The caller has passed the guest context physical address
817 * of the request structure. Copy the request packet.
818 */
819 VMMDevRequestHeader *pRequestHeader = NULL;
820 VMMDevRequestHeader requestHeader;
821 RT_ZERO(requestHeader);
822
823 PDMDevHlpPhysRead(pDevIns, (RTGCPHYS)u32, &requestHeader, sizeof(requestHeader));
824
825 /* the structure size must be greater or equal to the header size */
826 if (requestHeader.size < sizeof(VMMDevRequestHeader))
827 {
828 Log(("VMMDev request header size too small! size = %d\n", requestHeader.size));
829 rcRet = VINF_SUCCESS;
830 goto l_end; /** @todo shouldn't (/ no need to) write back.*/
831 }
832
833 /* check the version of the header structure */
834 if (requestHeader.version != VMMDEV_REQUEST_HEADER_VERSION)
835 {
836 Log(("VMMDev: guest header version (0x%08X) differs from ours (0x%08X)\n", requestHeader.version, VMMDEV_REQUEST_HEADER_VERSION));
837 rcRet = VINF_SUCCESS;
838 goto l_end; /** @todo shouldn't (/ no need to) write back.*/
839 }
840
841 Log2(("VMMDev request issued: %d\n", requestHeader.requestType));
842
843 /* Newer additions starts with VMMDevReq_ReportGuestInfo2, older additions
844 started with VMMDevReq_ReportGuestInfo. */
845 if ( !pThis->fu32AdditionsOk
846 && requestHeader.requestType != VMMDevReq_ReportGuestInfo2
847 && requestHeader.requestType != VMMDevReq_ReportGuestInfo
848 && requestHeader.requestType != VMMDevReq_WriteCoreDump
849 && requestHeader.requestType != VMMDevReq_GetHostVersion) /* Always allow the guest to query the host capabilities. */
850 {
851 Log(("VMMDev: guest has not yet reported to us. Refusing operation of request #%d!\n",
852 requestHeader.requestType));
853 requestHeader.rc = VERR_NOT_SUPPORTED;
854 static int cRelWarn;
855 if (cRelWarn < 10)
856 {
857 cRelWarn++;
858 LogRel(("VMMDev: the guest has not yet reported to us -- refusing operation of request #%d\n",
859 requestHeader.requestType));
860 }
861 rcRet = VINF_SUCCESS;
862 goto l_end;
863 }
864
865 /* Check upper limit */
866 if (requestHeader.size > VMMDEV_MAX_VMMDEVREQ_SIZE)
867 {
868 static int cRelWarn;
869 if (cRelWarn < 50)
870 {
871 cRelWarn++;
872 LogRel(("VMMDev: request packet too big (%x). Refusing operation.\n", requestHeader.size));
873 }
874 requestHeader.rc = VERR_NOT_SUPPORTED;
875 rcRet = VINF_SUCCESS;
876 goto l_end;
877 }
878
879 /* Read the entire request packet */
880 pRequestHeader = (VMMDevRequestHeader *)RTMemAlloc(requestHeader.size);
881 if (!pRequestHeader)
882 {
883 Log(("VMMDev: RTMemAlloc failed!\n"));
884 rcRet = VINF_SUCCESS;
885 requestHeader.rc = VERR_NO_MEMORY;
886 goto l_end;
887 }
888 PDMDevHlpPhysRead(pDevIns, (RTGCPHYS)u32, pRequestHeader, requestHeader.size);
889
890 /* which request was sent? */
891 switch (pRequestHeader->requestType)
892 {
893 /*
894 * Guest wants to give up a timeslice
895 */
896 case VMMDevReq_Idle:
897 {
898 /* just return to EMT telling it that we want to halt */
899 rcRet = VINF_EM_HALT;
900 break;
901 }
902
903 /*
904 * Guest is reporting its information
905 */
906 case VMMDevReq_ReportGuestInfo:
907 {
908 AssertMsgBreakStmt(pRequestHeader->size == sizeof(VMMDevReportGuestInfo), ("%u\n", pRequestHeader->size),
909 pRequestHeader->rc = VERR_INVALID_PARAMETER);
910 VBoxGuestInfo *pGuestInfo = &((VMMDevReportGuestInfo*)pRequestHeader)->guestInfo;
911
912 if (memcmp(&pThis->guestInfo, pGuestInfo, sizeof(*pGuestInfo)) != 0)
913 {
914 /* make a copy of supplied information */
915 pThis->guestInfo = *pGuestInfo;
916
917 /* Check additions version */
918 pThis->fu32AdditionsOk = VBOX_GUEST_INTERFACE_VERSION_OK(pThis->guestInfo.interfaceVersion);
919
920 LogRel(("Guest Additions information report: Interface = 0x%08X osType = 0x%08X\n",
921 pThis->guestInfo.interfaceVersion,
922 pThis->guestInfo.osType));
923 if (pThis->pDrv && pThis->pDrv->pfnUpdateGuestInfo)
924 pThis->pDrv->pfnUpdateGuestInfo(pThis->pDrv, &pThis->guestInfo);
925 }
926
927 if (pThis->fu32AdditionsOk)
928 {
929 pRequestHeader->rc = VINF_SUCCESS;
930 /* Clear our IRQ in case it was high for whatever reason. */
931 PDMDevHlpPCISetIrqNoWait (pThis->pDevIns, 0, 0);
932 }
933 else
934 pRequestHeader->rc = VERR_VERSION_MISMATCH;
935 break;
936 }
937
938 case VMMDevReq_ReportGuestInfo2:
939 {
940 pRequestHeader->rc = vmmdevReqHandler_ReportGuestInfo2(pThis, pRequestHeader);
941 break;
942 }
943
944 case VMMDevReq_WriteCoreDump:
945 {
946 if (pRequestHeader->size != sizeof(VMMDevReqWriteCoreDump))
947 {
948 AssertMsgFailed(("VMMDev WriteCoreDump structure has an invalid size!\n"));
949 pRequestHeader->rc = VERR_INVALID_PARAMETER;
950 }
951 else
952 {
953 if (pThis->fGuestCoreDumpEnabled)
954 {
955 /*
956 * User makes sure the directory exists.
957 */
958 if (!RTDirExists(pThis->szGuestCoreDumpDir))
959 return VERR_PATH_NOT_FOUND;
960
961 char szCorePath[RTPATH_MAX];
962 RTStrCopy(szCorePath, sizeof(szCorePath), pThis->szGuestCoreDumpDir);
963 RTPathAppend(szCorePath, sizeof(szCorePath), "VBox.core");
964
965 /*
966 * Rotate existing cores based on number of additional cores to keep around.
967 */
968 if (pThis->cGuestCoreDumps > 0)
969 for (int64_t i = pThis->cGuestCoreDumps - 1; i >= 0; i--)
970 {
971 char szFilePathOld[RTPATH_MAX];
972 if (i == 0)
973 RTStrCopy(szFilePathOld, sizeof(szFilePathOld), szCorePath);
974 else
975 RTStrPrintf(szFilePathOld, sizeof(szFilePathOld), "%s.%d", szCorePath, i);
976
977 char szFilePathNew[RTPATH_MAX];
978 RTStrPrintf(szFilePathNew, sizeof(szFilePathNew), "%s.%d", szCorePath, i + 1);
979 int vrc = RTFileMove(szFilePathOld, szFilePathNew, RTFILEMOVE_FLAGS_REPLACE);
980 if (vrc == VERR_FILE_NOT_FOUND)
981 RTFileDelete(szFilePathNew);
982 }
983
984 /*
985 * Write the core file.
986 */
987 PVM pVM = PDMDevHlpGetVM(pDevIns);
988 pRequestHeader->rc = DBGFR3CoreWrite(pVM, szCorePath, true /*fReplaceFile*/);
989 }
990 else
991 pRequestHeader->rc = VERR_ACCESS_DENIED;
992 }
993 break;
994 }
995
996 case VMMDevReq_ReportGuestStatus:
997 pRequestHeader->rc = vmmdevReqHandler_ReportGuestStatus(pThis, pRequestHeader);
998 break;
999
1000 /* Report guest capabilities */
1001 case VMMDevReq_ReportGuestCapabilities:
1002 {
1003 if (pRequestHeader->size != sizeof(VMMDevReqGuestCapabilities))
1004 {
1005 AssertMsgFailed(("VMMDev guest caps structure has invalid size!\n"));
1006 pRequestHeader->rc = VERR_INVALID_PARAMETER;
1007 }
1008 else
1009 {
1010 VMMDevReqGuestCapabilities *guestCaps = (VMMDevReqGuestCapabilities*)pRequestHeader;
1011
1012 /* Enable this automatically for guests using the old
1013 request to report their capabilities. */
1014 /** @todo change this when we next bump the interface version */
1015 guestCaps->caps |= VMMDEV_GUEST_SUPPORTS_GRAPHICS;
1016 if (pThis->guestCaps != guestCaps->caps)
1017 {
1018 /* make a copy of supplied information */
1019 pThis->guestCaps = guestCaps->caps;
1020
1021 LogRel(("Guest Additions capability report: (0x%x) "
1022 "seamless: %s, "
1023 "hostWindowMapping: %s, "
1024 "graphics: %s\n",
1025 guestCaps->caps,
1026 guestCaps->caps & VMMDEV_GUEST_SUPPORTS_SEAMLESS ? "yes" : "no",
1027 guestCaps->caps & VMMDEV_GUEST_SUPPORTS_GUEST_HOST_WINDOW_MAPPING ? "yes" : "no",
1028 guestCaps->caps & VMMDEV_GUEST_SUPPORTS_GRAPHICS ? "yes" : "no"));
1029
1030 if (pThis->pDrv && pThis->pDrv->pfnUpdateGuestCapabilities)
1031 pThis->pDrv->pfnUpdateGuestCapabilities(pThis->pDrv, guestCaps->caps);
1032 }
1033 pRequestHeader->rc = VINF_SUCCESS;
1034 }
1035 break;
1036 }
1037
1038 /* Change guest capabilities */
1039 case VMMDevReq_SetGuestCapabilities:
1040 {
1041 if (pRequestHeader->size != sizeof(VMMDevReqGuestCapabilities2))
1042 {
1043 AssertMsgFailed(("VMMDev guest caps structure has invalid size!\n"));
1044 pRequestHeader->rc = VERR_INVALID_PARAMETER;
1045 }
1046 else
1047 {
1048 VMMDevReqGuestCapabilities2 *guestCaps = (VMMDevReqGuestCapabilities2*)pRequestHeader;
1049
1050 pThis->guestCaps |= guestCaps->u32OrMask;
1051 pThis->guestCaps &= ~guestCaps->u32NotMask;
1052
1053 LogRel(("Guest Additions capability report: (0x%x) "
1054 "seamless: %s, "
1055 "hostWindowMapping: %s, "
1056 "graphics: %s\n",
1057 pThis->guestCaps,
1058 pThis->guestCaps & VMMDEV_GUEST_SUPPORTS_SEAMLESS ? "yes" : "no",
1059 pThis->guestCaps & VMMDEV_GUEST_SUPPORTS_GUEST_HOST_WINDOW_MAPPING ? "yes" : "no",
1060 pThis->guestCaps & VMMDEV_GUEST_SUPPORTS_GRAPHICS ? "yes" : "no"));
1061
1062 if (pThis->pDrv && pThis->pDrv->pfnUpdateGuestCapabilities)
1063 pThis->pDrv->pfnUpdateGuestCapabilities(pThis->pDrv, pThis->guestCaps);
1064 pRequestHeader->rc = VINF_SUCCESS;
1065 }
1066 break;
1067 }
1068
1069 /*
1070 * Retrieve mouse information
1071 */
1072 case VMMDevReq_GetMouseStatus:
1073 {
1074 if (pRequestHeader->size != sizeof(VMMDevReqMouseStatus))
1075 {
1076 AssertMsgFailed(("VMMDev mouse status structure has invalid size!\n"));
1077 pRequestHeader->rc = VERR_INVALID_PARAMETER;
1078 }
1079 else
1080 {
1081 VMMDevReqMouseStatus *mouseStatus = (VMMDevReqMouseStatus*)pRequestHeader;
1082 mouseStatus->mouseFeatures = pThis->mouseCapabilities
1083 & VMMDEV_MOUSE_MASK;
1084 mouseStatus->pointerXPos = pThis->mouseXAbs;
1085 mouseStatus->pointerYPos = pThis->mouseYAbs;
1086 LogRel2(("%s: VMMDevReq_GetMouseStatus: features = 0x%x, absX = %d, absY = %d\n",
1087 __PRETTY_FUNCTION__,
1088 mouseStatus->mouseFeatures,
1089 mouseStatus->pointerXPos,
1090 mouseStatus->pointerYPos));
1091 pRequestHeader->rc = VINF_SUCCESS;
1092 }
1093 break;
1094 }
1095
1096 /*
1097 * Set mouse information
1098 */
1099 case VMMDevReq_SetMouseStatus:
1100 {
1101 if (pRequestHeader->size != sizeof(VMMDevReqMouseStatus))
1102 {
1103 AssertMsgFailed(("VMMDev mouse status structure has invalid size %d (%#x) version=%d!\n",
1104 pRequestHeader->size, pRequestHeader->size, pRequestHeader->size, pRequestHeader->version));
1105 pRequestHeader->rc = VERR_INVALID_PARAMETER;
1106 }
1107 else
1108 {
1109 bool fNotify = false;
1110
1111 uint32_t fFeatures =
1112 ((VMMDevReqMouseStatus*)pRequestHeader)->mouseFeatures;
1113
1114 LogRelFlowFunc(("VMMDevReqMouseStatus: mouseFeatures = 0x%x\n",
1115 fFeatures));
1116
1117 if ( (fFeatures & VMMDEV_MOUSE_NOTIFY_HOST_MASK)
1118 != ( pThis->mouseCapabilities
1119 & VMMDEV_MOUSE_NOTIFY_HOST_MASK))
1120 fNotify = true;
1121 pThis->mouseCapabilities &= ~VMMDEV_MOUSE_GUEST_MASK;
1122 pThis->mouseCapabilities |=
1123 (fFeatures & VMMDEV_MOUSE_GUEST_MASK);
1124 LogRelFlowFunc(("VMMDevReq_SetMouseStatus: new host capabilities: 0x%x\n",
1125 pThis->mouseCapabilities));
1126
1127 /*
1128 * Notify connector if something has changed
1129 */
1130 if (fNotify)
1131 {
1132 LogRelFlowFunc(("VMMDevReq_SetMouseStatus: notifying connector\n"));
1133 pThis->pDrv->pfnUpdateMouseCapabilities(pThis->pDrv, pThis->mouseCapabilities);
1134 }
1135 pRequestHeader->rc = VINF_SUCCESS;
1136 }
1137
1138 break;
1139 }
1140
1141 /*
1142 * Set a new mouse pointer shape
1143 */
1144 case VMMDevReq_SetPointerShape:
1145 {
1146 if (pRequestHeader->size < sizeof(VMMDevReqMousePointer))
1147 {
1148 AssertMsg(pRequestHeader->size == 0x10028 && pRequestHeader->version == 10000, /* don't complain about legacy!!! */
1149 ("VMMDev mouse shape structure has invalid size %d (%#x) version=%d!\n",
1150 pRequestHeader->size, pRequestHeader->size, pRequestHeader->size, pRequestHeader->version));
1151 pRequestHeader->rc = VERR_INVALID_PARAMETER;
1152 }
1153 else
1154 {
1155 VMMDevReqMousePointer *pointerShape = (VMMDevReqMousePointer*)pRequestHeader;
1156
1157 bool fVisible = (pointerShape->fFlags & VBOX_MOUSE_POINTER_VISIBLE) != 0;
1158 bool fAlpha = (pointerShape->fFlags & VBOX_MOUSE_POINTER_ALPHA) != 0;
1159 bool fShape = (pointerShape->fFlags & VBOX_MOUSE_POINTER_SHAPE) != 0;
1160
1161 Log(("VMMDevReq_SetPointerShape: visible: %d, alpha: %d, shape = %d, width: %d, height: %d\n",
1162 fVisible, fAlpha, fShape, pointerShape->width, pointerShape->height));
1163
1164 if (pRequestHeader->size == sizeof(VMMDevReqMousePointer))
1165 {
1166 /* The guest did not provide the shape actually. */
1167 fShape = false;
1168 }
1169
1170 /* forward call to driver */
1171 if (fShape)
1172 {
1173 pThis->pDrv->pfnUpdatePointerShape(pThis->pDrv,
1174 fVisible,
1175 fAlpha,
1176 pointerShape->xHot, pointerShape->yHot,
1177 pointerShape->width, pointerShape->height,
1178 pointerShape->pointerData);
1179 }
1180 else
1181 {
1182 pThis->pDrv->pfnUpdatePointerShape(pThis->pDrv,
1183 fVisible,
1184 0,
1185 0, 0,
1186 0, 0,
1187 NULL);
1188 }
1189 pThis->fHostCursorRequested = fVisible;
1190 pRequestHeader->rc = VINF_SUCCESS;
1191 }
1192 break;
1193 }
1194
1195 /*
1196 * Query the system time from the host
1197 */
1198 case VMMDevReq_GetHostTime:
1199 {
1200 if (pRequestHeader->size != sizeof(VMMDevReqHostTime))
1201 {
1202 AssertMsgFailed(("VMMDev host time structure has invalid size!\n"));
1203 pRequestHeader->rc = VERR_INVALID_PARAMETER;
1204 }
1205 else if (RT_UNLIKELY(pThis->fGetHostTimeDisabled))
1206 pRequestHeader->rc = VERR_NOT_SUPPORTED;
1207 else
1208 {
1209 VMMDevReqHostTime *hostTimeReq = (VMMDevReqHostTime*)pRequestHeader;
1210 RTTIMESPEC now;
1211 hostTimeReq->time = RTTimeSpecGetMilli(PDMDevHlpTMUtcNow(pDevIns, &now));
1212 pRequestHeader->rc = VINF_SUCCESS;
1213 }
1214 break;
1215 }
1216
1217 /*
1218 * Query information about the hypervisor
1219 */
1220 case VMMDevReq_GetHypervisorInfo:
1221 {
1222 if (pRequestHeader->size != sizeof(VMMDevReqHypervisorInfo))
1223 {
1224 AssertMsgFailed(("VMMDev hypervisor info structure has invalid size!\n"));
1225 pRequestHeader->rc = VERR_INVALID_PARAMETER;
1226 }
1227 else
1228 {
1229 VMMDevReqHypervisorInfo *hypervisorInfo = (VMMDevReqHypervisorInfo*)pRequestHeader;
1230 PVM pVM = PDMDevHlpGetVM(pDevIns);
1231 pRequestHeader->rc = PGMR3MappingsSize(pVM, &hypervisorInfo->hypervisorSize);
1232 }
1233 break;
1234 }
1235
1236 /*
1237 * Set hypervisor information
1238 */
1239 case VMMDevReq_SetHypervisorInfo:
1240 {
1241 if (pRequestHeader->size != sizeof(VMMDevReqHypervisorInfo))
1242 {
1243 AssertMsgFailed(("VMMDev hypervisor info structure has invalid size!\n"));
1244 pRequestHeader->rc = VERR_INVALID_PARAMETER;
1245 }
1246 else
1247 {
1248 VMMDevReqHypervisorInfo *hypervisorInfo = (VMMDevReqHypervisorInfo*)pRequestHeader;
1249 PVM pVM = PDMDevHlpGetVM(pDevIns);
1250 if (hypervisorInfo->hypervisorStart == 0)
1251 pRequestHeader->rc = PGMR3MappingsUnfix(pVM);
1252 else
1253 {
1254 /* only if the client has queried the size before! */
1255 uint32_t mappingsSize;
1256 pRequestHeader->rc = PGMR3MappingsSize(pVM, &mappingsSize);
1257 if (RT_SUCCESS(pRequestHeader->rc) && hypervisorInfo->hypervisorSize == mappingsSize)
1258 {
1259 /* new reservation */
1260 pRequestHeader->rc = PGMR3MappingsFix(pVM, hypervisorInfo->hypervisorStart,
1261 hypervisorInfo->hypervisorSize);
1262 LogRel(("Guest reported fixed hypervisor window at 0x%p (size = 0x%x, rc = %Rrc)\n",
1263 (uintptr_t)hypervisorInfo->hypervisorStart,
1264 hypervisorInfo->hypervisorSize,
1265 pRequestHeader->rc));
1266 }
1267 }
1268 }
1269 break;
1270 }
1271
1272 case VMMDevReq_RegisterPatchMemory:
1273 {
1274 if (pRequestHeader->size != sizeof(VMMDevReqPatchMemory))
1275 {
1276 AssertMsgFailed(("VMMDevReq_RegisterPatchMemory structure has invalid size!\n"));
1277 pRequestHeader->rc = VERR_INVALID_PARAMETER;
1278 }
1279 else
1280 {
1281 VMMDevReqPatchMemory *pPatchRequest = (VMMDevReqPatchMemory*)pRequestHeader;
1282
1283 pRequestHeader->rc = VMMR3RegisterPatchMemory(PDMDevHlpGetVM(pDevIns), pPatchRequest->pPatchMem, pPatchRequest->cbPatchMem);
1284 }
1285 break;
1286 }
1287
1288 case VMMDevReq_DeregisterPatchMemory:
1289 {
1290 if (pRequestHeader->size != sizeof(VMMDevReqPatchMemory))
1291 {
1292 AssertMsgFailed(("VMMDevReq_DeregisterPatchMemory structure has invalid size!\n"));
1293 pRequestHeader->rc = VERR_INVALID_PARAMETER;
1294 }
1295 else
1296 {
1297 VMMDevReqPatchMemory *pPatchRequest = (VMMDevReqPatchMemory*)pRequestHeader;
1298
1299 pRequestHeader->rc = VMMR3DeregisterPatchMemory(PDMDevHlpGetVM(pDevIns), pPatchRequest->pPatchMem, pPatchRequest->cbPatchMem);
1300 }
1301 break;
1302 }
1303
1304 /*
1305 * Set the system power status
1306 */
1307 case VMMDevReq_SetPowerStatus:
1308 {
1309 if (pRequestHeader->size != sizeof(VMMDevPowerStateRequest))
1310 {
1311 AssertMsgFailed(("VMMDev power state request structure has invalid size!\n"));
1312 pRequestHeader->rc = VERR_INVALID_PARAMETER;
1313 }
1314 else
1315 {
1316 VMMDevPowerStateRequest *powerStateRequest = (VMMDevPowerStateRequest*)pRequestHeader;
1317 switch(powerStateRequest->powerState)
1318 {
1319 case VMMDevPowerState_Pause:
1320 {
1321 LogRel(("Guest requests the VM to be suspended (paused)\n"));
1322 pRequestHeader->rc = rcRet = PDMDevHlpVMSuspend(pDevIns);
1323 break;
1324 }
1325
1326 case VMMDevPowerState_PowerOff:
1327 {
1328 LogRel(("Guest requests the VM to be turned off\n"));
1329 pRequestHeader->rc = rcRet = PDMDevHlpVMPowerOff(pDevIns);
1330 break;
1331 }
1332
1333 case VMMDevPowerState_SaveState:
1334 {
1335 if (true /*pThis->fAllowGuestToSaveState*/)
1336 {
1337 LogRel(("Guest requests the VM to be saved and powered off\n"));
1338 pRequestHeader->rc = rcRet = PDMDevHlpVMSuspendSaveAndPowerOff(pDevIns);
1339 }
1340 else
1341 {
1342 LogRel(("Guest requests the VM to be saved and powered off, declined\n"));
1343 pRequestHeader->rc = VERR_ACCESS_DENIED;
1344 }
1345 break;
1346 }
1347
1348 default:
1349 AssertMsgFailed(("VMMDev invalid power state request: %d\n", powerStateRequest->powerState));
1350 pRequestHeader->rc = VERR_INVALID_PARAMETER;
1351 break;
1352 }
1353 }
1354 break;
1355 }
1356
1357 /*
1358 * Retrieve a display resize request sent by the host using
1359 * @a IDisplay:setVideoModeHint. Deprecated.
1360 * See documentation in VMMDev.h.
1361 */
1362 /**
1363 * @todo It looks like a multi-monitor guest which only uses
1364 * @a VMMDevReq_GetDisplayChangeRequest (not the *2 version)
1365 * will get into a @a VMMDEV_EVENT_DISPLAY_CHANGE_REQUEST event
1366 * loop if it tries to acknowlege host requests for additional
1367 * monitors. Should the loop which checks for those requests
1368 * be removed?
1369 */
1370 case VMMDevReq_GetDisplayChangeRequest:
1371 {
1372 if (pRequestHeader->size != sizeof(VMMDevDisplayChangeRequest))
1373 {
1374 /* Assert only if the size also not equal to a previous version size to prevent
1375 * assertion with old additions.
1376 */
1377 AssertMsg(pRequestHeader->size == sizeof(VMMDevDisplayChangeRequest) - sizeof (uint32_t),
1378 ("VMMDev display change request structure has invalid size!\n"));
1379 pRequestHeader->rc = VERR_INVALID_PARAMETER;
1380 }
1381 else
1382 {
1383 VMMDevDisplayChangeRequest *displayChangeRequest = (VMMDevDisplayChangeRequest*)pRequestHeader;
1384
1385 DISPLAYCHANGEREQUEST *pRequest = &pThis->displayChangeData.aRequests[0];
1386
1387 if (displayChangeRequest->eventAck == VMMDEV_EVENT_DISPLAY_CHANGE_REQUEST)
1388 {
1389 /* Current request has been read at least once. */
1390 pRequest->fPending = false;
1391
1392 /* Check if there are more pending requests. */
1393 for (unsigned i = 1; i < RT_ELEMENTS(pThis->displayChangeData.aRequests); i++)
1394 {
1395 if (pThis->displayChangeData.aRequests[i].fPending)
1396 {
1397 VMMDevNotifyGuest (pThis, VMMDEV_EVENT_DISPLAY_CHANGE_REQUEST);
1398 break;
1399 }
1400 }
1401
1402 /* Remember which resolution the client has queried, subsequent reads
1403 * will return the same values. */
1404 pRequest->lastReadDisplayChangeRequest = pRequest->displayChangeRequest;
1405 pThis->displayChangeData.fGuestSentChangeEventAck = true;
1406 }
1407
1408 if (pThis->displayChangeData.fGuestSentChangeEventAck)
1409 {
1410 displayChangeRequest->xres = pRequest->lastReadDisplayChangeRequest.xres;
1411 displayChangeRequest->yres = pRequest->lastReadDisplayChangeRequest.yres;
1412 displayChangeRequest->bpp = pRequest->lastReadDisplayChangeRequest.bpp;
1413 }
1414 else
1415 {
1416 /* This is not a response to a VMMDEV_EVENT_DISPLAY_CHANGE_REQUEST, just
1417 * read the last valid video mode hint. This happens when the guest X server
1418 * determines the initial mode. */
1419 displayChangeRequest->xres = pRequest->displayChangeRequest.xres;
1420 displayChangeRequest->yres = pRequest->displayChangeRequest.yres;
1421 displayChangeRequest->bpp = pRequest->displayChangeRequest.bpp;
1422 }
1423 Log(("VMMDev: returning display change request xres = %d, yres = %d, bpp = %d\n",
1424 displayChangeRequest->xres, displayChangeRequest->yres, displayChangeRequest->bpp));
1425
1426 pRequestHeader->rc = VINF_SUCCESS;
1427 }
1428 break;
1429 }
1430
1431 /*
1432 * Retrieve a display resize request sent by the host using
1433 * @a IDisplay:setVideoModeHint.
1434 * See documentation in VMMDev.h.
1435 */
1436 case VMMDevReq_GetDisplayChangeRequest2:
1437 {
1438 if (pRequestHeader->size != sizeof(VMMDevDisplayChangeRequest2))
1439 {
1440 pRequestHeader->rc = VERR_INVALID_PARAMETER;
1441 }
1442 else
1443 {
1444 VMMDevDisplayChangeRequest2 *displayChangeRequest = (VMMDevDisplayChangeRequest2*)pRequestHeader;
1445
1446 DISPLAYCHANGEREQUEST *pRequest = NULL;
1447
1448 if (displayChangeRequest->eventAck == VMMDEV_EVENT_DISPLAY_CHANGE_REQUEST)
1449 {
1450 /* Select a pending request to report. */
1451 unsigned i;
1452 for (i = 0; i < RT_ELEMENTS(pThis->displayChangeData.aRequests); i++)
1453 {
1454 if (pThis->displayChangeData.aRequests[i].fPending)
1455 {
1456 pRequest = &pThis->displayChangeData.aRequests[i];
1457 /* Remember which request should be reported. */
1458 pThis->displayChangeData.iCurrentMonitor = i;
1459 Log3(("VMMDev: will report pending request for %d\n",
1460 i));
1461 break;
1462 }
1463 }
1464
1465 /* Check if there are more pending requests. */
1466 i++;
1467 for (; i < RT_ELEMENTS(pThis->displayChangeData.aRequests); i++)
1468 {
1469 if (pThis->displayChangeData.aRequests[i].fPending)
1470 {
1471 VMMDevNotifyGuest (pThis, VMMDEV_EVENT_DISPLAY_CHANGE_REQUEST);
1472 Log3(("VMMDev: another pending at %d\n",
1473 i));
1474 break;
1475 }
1476 }
1477
1478 if (pRequest)
1479 {
1480 /* Current request has been read at least once. */
1481 pRequest->fPending = false;
1482
1483 /* Remember which resolution the client has queried, subsequent reads
1484 * will return the same values. */
1485 pRequest->lastReadDisplayChangeRequest = pRequest->displayChangeRequest;
1486 pThis->displayChangeData.fGuestSentChangeEventAck = true;
1487 }
1488 else
1489 {
1490 Log3(("VMMDev: no pending request!!!\n"));
1491 }
1492 }
1493
1494 if (!pRequest)
1495 {
1496 Log3(("VMMDev: default to %d\n",
1497 pThis->displayChangeData.iCurrentMonitor));
1498 pRequest = &pThis->displayChangeData.aRequests[pThis->displayChangeData.iCurrentMonitor];
1499 }
1500
1501 if (pThis->displayChangeData.fGuestSentChangeEventAck)
1502 {
1503 displayChangeRequest->xres = pRequest->lastReadDisplayChangeRequest.xres;
1504 displayChangeRequest->yres = pRequest->lastReadDisplayChangeRequest.yres;
1505 displayChangeRequest->bpp = pRequest->lastReadDisplayChangeRequest.bpp;
1506 displayChangeRequest->display = pRequest->lastReadDisplayChangeRequest.display;
1507 }
1508 else
1509 {
1510 /* This is not a response to a VMMDEV_EVENT_DISPLAY_CHANGE_REQUEST, just
1511 * read the last valid video mode hint. This happens when the guest X server
1512 * determines the initial video mode. */
1513 displayChangeRequest->xres = pRequest->displayChangeRequest.xres;
1514 displayChangeRequest->yres = pRequest->displayChangeRequest.yres;
1515 displayChangeRequest->bpp = pRequest->displayChangeRequest.bpp;
1516 displayChangeRequest->display = pRequest->displayChangeRequest.display;
1517 }
1518 Log(("VMMDev: returning display change request xres = %d, yres = %d, bpp = %d at %d\n",
1519 displayChangeRequest->xres, displayChangeRequest->yres, displayChangeRequest->bpp, displayChangeRequest->display));
1520
1521 pRequestHeader->rc = VINF_SUCCESS;
1522 }
1523 break;
1524 }
1525
1526 /*
1527 * Query whether the given video mode is supported
1528 */
1529 case VMMDevReq_VideoModeSupported:
1530 {
1531 if (pRequestHeader->size != sizeof(VMMDevVideoModeSupportedRequest))
1532 {
1533 AssertMsgFailed(("VMMDev video mode supported request structure has invalid size!\n"));
1534 pRequestHeader->rc = VERR_INVALID_PARAMETER;
1535 }
1536 else
1537 {
1538 VMMDevVideoModeSupportedRequest *videoModeSupportedRequest = (VMMDevVideoModeSupportedRequest*)pRequestHeader;
1539 /* forward the call */
1540 pRequestHeader->rc = pThis->pDrv->pfnVideoModeSupported(pThis->pDrv,
1541 0, /* primary screen. */
1542 videoModeSupportedRequest->width,
1543 videoModeSupportedRequest->height,
1544 videoModeSupportedRequest->bpp,
1545 &videoModeSupportedRequest->fSupported);
1546 }
1547 break;
1548 }
1549
1550 /*
1551 * Query whether the given video mode is supported for a specific display
1552 */
1553 case VMMDevReq_VideoModeSupported2:
1554 {
1555 if (pRequestHeader->size != sizeof(VMMDevVideoModeSupportedRequest2))
1556 {
1557 AssertMsgFailed(("VMMDev video mode supported request 2 structure has invalid size!\n"));
1558 pRequestHeader->rc = VERR_INVALID_PARAMETER;
1559 }
1560 else
1561 {
1562 VMMDevVideoModeSupportedRequest2 *videoModeSupportedRequest2 = (VMMDevVideoModeSupportedRequest2*)pRequestHeader;
1563 /* forward the call */
1564 pRequestHeader->rc = pThis->pDrv->pfnVideoModeSupported(pThis->pDrv,
1565 videoModeSupportedRequest2->display,
1566 videoModeSupportedRequest2->width,
1567 videoModeSupportedRequest2->height,
1568 videoModeSupportedRequest2->bpp,
1569 &videoModeSupportedRequest2->fSupported);
1570 }
1571 break;
1572 }
1573
1574 /*
1575 * Query the height reduction in pixels
1576 */
1577 case VMMDevReq_GetHeightReduction:
1578 {
1579 if (pRequestHeader->size != sizeof(VMMDevGetHeightReductionRequest))
1580 {
1581 AssertMsgFailed(("VMMDev height reduction request structure has invalid size!\n"));
1582 pRequestHeader->rc = VERR_INVALID_PARAMETER;
1583 }
1584 else
1585 {
1586 VMMDevGetHeightReductionRequest *heightReductionRequest = (VMMDevGetHeightReductionRequest*)pRequestHeader;
1587 /* forward the call */
1588 pRequestHeader->rc = pThis->pDrv->pfnGetHeightReduction(pThis->pDrv,
1589 &heightReductionRequest->heightReduction);
1590 }
1591 break;
1592 }
1593
1594 /*
1595 * Acknowledge VMMDev events
1596 */
1597 case VMMDevReq_AcknowledgeEvents:
1598 {
1599 if (pRequestHeader->size != sizeof(VMMDevEvents))
1600 {
1601 AssertMsgFailed(("VMMDevReq_AcknowledgeEvents structure has invalid size!\n"));
1602 pRequestHeader->rc = VERR_INVALID_PARAMETER;
1603 }
1604 else
1605 {
1606 if (VBOX_GUEST_INTERFACE_VERSION_1_03 (pThis))
1607 {
1608 vmmdevSetIRQ_Legacy_EMT (pThis);
1609 }
1610 else
1611 {
1612 VMMDevEvents *pAckRequest;
1613
1614 if (pThis->fNewGuestFilterMask)
1615 {
1616 pThis->fNewGuestFilterMask = false;
1617 pThis->u32GuestFilterMask = pThis->u32NewGuestFilterMask;
1618 }
1619
1620 pAckRequest = (VMMDevEvents *)pRequestHeader;
1621 pAckRequest->events =
1622 pThis->u32HostEventFlags & pThis->u32GuestFilterMask;
1623
1624 pThis->u32HostEventFlags &= ~pThis->u32GuestFilterMask;
1625 pThis->pVMMDevRAMR3->V.V1_04.fHaveEvents = false;
1626 PDMDevHlpPCISetIrqNoWait (pThis->pDevIns, 0, 0);
1627 }
1628 pRequestHeader->rc = VINF_SUCCESS;
1629 }
1630 break;
1631 }
1632
1633 /*
1634 * Change guest filter mask
1635 */
1636 case VMMDevReq_CtlGuestFilterMask:
1637 {
1638 if (pRequestHeader->size != sizeof(VMMDevCtlGuestFilterMask))
1639 {
1640 AssertMsgFailed(("VMMDevReq_AcknowledgeEvents structure has invalid size!\n"));
1641 pRequestHeader->rc = VERR_INVALID_PARAMETER;
1642 }
1643 else
1644 {
1645 VMMDevCtlGuestFilterMask *pCtlMaskRequest;
1646
1647 pCtlMaskRequest = (VMMDevCtlGuestFilterMask *)pRequestHeader;
1648 LogRelFlowFunc(("VMMDevCtlGuestFilterMask: or mask: 0x%x, not mask: 0x%x\n",
1649 pCtlMaskRequest->u32OrMask,
1650 pCtlMaskRequest->u32NotMask));
1651 /* HGCM event notification is enabled by the VMMDev device
1652 * automatically when any HGCM command is issued. The guest
1653 * cannot disable these notifications.
1654 */
1655 VMMDevCtlSetGuestFilterMask (pThis,
1656 pCtlMaskRequest->u32OrMask,
1657 pCtlMaskRequest->u32NotMask & ~VMMDEV_EVENT_HGCM);
1658 pRequestHeader->rc = VINF_SUCCESS;
1659
1660 }
1661 break;
1662 }
1663
1664#ifdef VBOX_WITH_HGCM
1665 /*
1666 * Process HGCM request
1667 */
1668 case VMMDevReq_HGCMConnect:
1669 {
1670 if (pRequestHeader->size < sizeof(VMMDevHGCMConnect))
1671 {
1672 AssertMsgFailed(("VMMDevReq_HGCMConnect structure has invalid size!\n"));
1673 pRequestHeader->rc = VERR_INVALID_PARAMETER;
1674 }
1675 else if (!pThis->pHGCMDrv)
1676 {
1677 Log(("VMMDevReq_HGCMConnect HGCM Connector is NULL!\n"));
1678 pRequestHeader->rc = VERR_NOT_SUPPORTED;
1679 }
1680 else
1681 {
1682 VMMDevHGCMConnect *pHGCMConnect = (VMMDevHGCMConnect *)pRequestHeader;
1683
1684 Log(("VMMDevReq_HGCMConnect\n"));
1685
1686 pRequestHeader->rc = vmmdevHGCMConnect (pThis, pHGCMConnect, (RTGCPHYS)u32);
1687 }
1688 break;
1689 }
1690
1691 case VMMDevReq_HGCMDisconnect:
1692 {
1693 if (pRequestHeader->size < sizeof(VMMDevHGCMDisconnect))
1694 {
1695 AssertMsgFailed(("VMMDevReq_HGCMDisconnect structure has invalid size!\n"));
1696 pRequestHeader->rc = VERR_INVALID_PARAMETER;
1697 }
1698 else if (!pThis->pHGCMDrv)
1699 {
1700 Log(("VMMDevReq_HGCMDisconnect HGCM Connector is NULL!\n"));
1701 pRequestHeader->rc = VERR_NOT_SUPPORTED;
1702 }
1703 else
1704 {
1705 VMMDevHGCMDisconnect *pHGCMDisconnect = (VMMDevHGCMDisconnect *)pRequestHeader;
1706
1707 Log(("VMMDevReq_VMMDevHGCMDisconnect\n"));
1708 pRequestHeader->rc = vmmdevHGCMDisconnect (pThis, pHGCMDisconnect, (RTGCPHYS)u32);
1709 }
1710 break;
1711 }
1712
1713#ifdef VBOX_WITH_64_BITS_GUESTS
1714 case VMMDevReq_HGCMCall32:
1715 case VMMDevReq_HGCMCall64:
1716#else
1717 case VMMDevReq_HGCMCall:
1718#endif /* VBOX_WITH_64_BITS_GUESTS */
1719 {
1720 if (pRequestHeader->size < sizeof(VMMDevHGCMCall))
1721 {
1722 AssertMsgFailed(("VMMDevReq_HGCMCall structure has invalid size!\n"));
1723 pRequestHeader->rc = VERR_INVALID_PARAMETER;
1724 }
1725 else if (!pThis->pHGCMDrv)
1726 {
1727 Log(("VMMDevReq_HGCMCall HGCM Connector is NULL!\n"));
1728 pRequestHeader->rc = VERR_NOT_SUPPORTED;
1729 }
1730 else
1731 {
1732 VMMDevHGCMCall *pHGCMCall = (VMMDevHGCMCall *)pRequestHeader;
1733
1734 Log2(("VMMDevReq_HGCMCall: sizeof (VMMDevHGCMRequest) = %04X\n", sizeof (VMMDevHGCMCall)));
1735 Log2(("%.*Rhxd\n", pRequestHeader->size, pRequestHeader));
1736
1737#ifdef VBOX_WITH_64_BITS_GUESTS
1738 bool f64Bits = (pRequestHeader->requestType == VMMDevReq_HGCMCall64);
1739#else
1740 bool f64Bits = false;
1741#endif /* VBOX_WITH_64_BITS_GUESTS */
1742
1743 pRequestHeader->rc = vmmdevHGCMCall (pThis, pHGCMCall, requestHeader.size, (RTGCPHYS)u32, f64Bits);
1744 }
1745 break;
1746 }
1747#endif /* VBOX_WITH_HGCM */
1748
1749 case VMMDevReq_HGCMCancel:
1750 {
1751 if (pRequestHeader->size < sizeof(VMMDevHGCMCancel))
1752 {
1753 AssertMsgFailed(("VMMDevReq_HGCMCancel structure has invalid size!\n"));
1754 pRequestHeader->rc = VERR_INVALID_PARAMETER;
1755 }
1756 else if (!pThis->pHGCMDrv)
1757 {
1758 Log(("VMMDevReq_HGCMCancel HGCM Connector is NULL!\n"));
1759 pRequestHeader->rc = VERR_NOT_SUPPORTED;
1760 }
1761 else
1762 {
1763 VMMDevHGCMCancel *pHGCMCancel = (VMMDevHGCMCancel *)pRequestHeader;
1764
1765 Log(("VMMDevReq_VMMDevHGCMCancel\n"));
1766 pRequestHeader->rc = vmmdevHGCMCancel (pThis, pHGCMCancel, (RTGCPHYS)u32);
1767 }
1768 break;
1769 }
1770
1771 case VMMDevReq_HGCMCancel2:
1772 {
1773 if (pRequestHeader->size != sizeof(VMMDevHGCMCancel2))
1774 {
1775 AssertMsgFailed(("VMMDevReq_HGCMCancel structure has invalid size!\n"));
1776 pRequestHeader->rc = VERR_INVALID_PARAMETER;
1777 }
1778 else if (!pThis->pHGCMDrv)
1779 {
1780 Log(("VMMDevReq_HGCMCancel HGCM Connector is NULL!\n"));
1781 pRequestHeader->rc = VERR_NOT_SUPPORTED;
1782 }
1783 else
1784 {
1785 VMMDevHGCMCancel2 *pHGCMCancel2 = (VMMDevHGCMCancel2 *)pRequestHeader;
1786
1787 Log(("VMMDevReq_VMMDevHGCMCancel\n"));
1788 pRequestHeader->rc = vmmdevHGCMCancel2 (pThis, pHGCMCancel2->physReqToCancel);
1789 }
1790 break;
1791 }
1792
1793 case VMMDevReq_VideoAccelEnable:
1794 {
1795 if (pRequestHeader->size < sizeof(VMMDevVideoAccelEnable))
1796 {
1797 Log(("VMMDevReq_VideoAccelEnable request size too small!!!\n"));
1798 pRequestHeader->rc = VERR_INVALID_PARAMETER;
1799 }
1800 else if (!pThis->pDrv)
1801 {
1802 Log(("VMMDevReq_VideoAccelEnable Connector is NULL!!!\n"));
1803 pRequestHeader->rc = VERR_NOT_SUPPORTED;
1804 }
1805 else
1806 {
1807 VMMDevVideoAccelEnable *ptr = (VMMDevVideoAccelEnable *)pRequestHeader;
1808
1809 if (ptr->cbRingBuffer != VBVA_RING_BUFFER_SIZE)
1810 {
1811 /* The guest driver seems compiled with another headers. */
1812 Log(("VMMDevReq_VideoAccelEnable guest ring buffer size %d, should be %d!!!\n", ptr->cbRingBuffer, VBVA_RING_BUFFER_SIZE));
1813 pRequestHeader->rc = VERR_INVALID_PARAMETER;
1814 }
1815 else
1816 {
1817 /* The request is correct. */
1818 ptr->fu32Status |= VBVA_F_STATUS_ACCEPTED;
1819
1820 LogFlow(("VMMDevReq_VideoAccelEnable ptr->u32Enable = %d\n", ptr->u32Enable));
1821
1822 pRequestHeader->rc = ptr->u32Enable?
1823 pThis->pDrv->pfnVideoAccelEnable (pThis->pDrv, true, &pThis->pVMMDevRAMR3->vbvaMemory):
1824 pThis->pDrv->pfnVideoAccelEnable (pThis->pDrv, false, NULL);
1825
1826 if ( ptr->u32Enable
1827 && RT_SUCCESS (pRequestHeader->rc))
1828 {
1829 ptr->fu32Status |= VBVA_F_STATUS_ENABLED;
1830
1831 /* Remember that guest successfully enabled acceleration.
1832 * We need to reestablish it on restoring the VM from saved state.
1833 */
1834 pThis->u32VideoAccelEnabled = 1;
1835 }
1836 else
1837 {
1838 /* The acceleration was not enabled. Remember that. */
1839 pThis->u32VideoAccelEnabled = 0;
1840 }
1841 }
1842 }
1843 break;
1844 }
1845
1846 case VMMDevReq_VideoAccelFlush:
1847 {
1848 if (pRequestHeader->size < sizeof(VMMDevVideoAccelFlush))
1849 {
1850 AssertMsgFailed(("VMMDevReq_VideoAccelFlush request size too small.\n"));
1851 pRequestHeader->rc = VERR_INVALID_PARAMETER;
1852 }
1853 else if (!pThis->pDrv)
1854 {
1855 Log(("VMMDevReq_VideoAccelFlush Connector is NULL!\n"));
1856 pRequestHeader->rc = VERR_NOT_SUPPORTED;
1857 }
1858 else
1859 {
1860 pThis->pDrv->pfnVideoAccelFlush (pThis->pDrv);
1861
1862 pRequestHeader->rc = VINF_SUCCESS;
1863 }
1864 break;
1865 }
1866
1867 case VMMDevReq_VideoSetVisibleRegion:
1868 {
1869 if ( pRequestHeader->size + sizeof(RTRECT)
1870 < sizeof(VMMDevVideoSetVisibleRegion))
1871 {
1872 Log(("VMMDevReq_VideoSetVisibleRegion request size too small!!!\n"));
1873 pRequestHeader->rc = VERR_INVALID_PARAMETER;
1874 }
1875 else if (!pThis->pDrv)
1876 {
1877 Log(("VMMDevReq_VideoSetVisibleRegion Connector is NULL!!!\n"));
1878 pRequestHeader->rc = VERR_NOT_SUPPORTED;
1879 }
1880 else
1881 {
1882 VMMDevVideoSetVisibleRegion *ptr = (VMMDevVideoSetVisibleRegion *)pRequestHeader;
1883
1884 if ( ptr->cRect > _1M /* restrict to sane range */
1885 || pRequestHeader->size != sizeof(VMMDevVideoSetVisibleRegion) + ptr->cRect * sizeof(RTRECT) - sizeof(RTRECT))
1886 {
1887 Log(("VMMDevReq_VideoSetVisibleRegion: cRects=%#x doesn't match size=%#x or is out of bounds\n",
1888 ptr->cRect, pRequestHeader->size));
1889 pRequestHeader->rc = VERR_INVALID_PARAMETER;
1890 }
1891 else
1892 {
1893 Log(("VMMDevReq_VideoSetVisibleRegion %d rectangles\n", ptr->cRect));
1894 /* forward the call */
1895 pRequestHeader->rc = pThis->pDrv->pfnSetVisibleRegion(pThis->pDrv, ptr->cRect, &ptr->Rect);
1896 }
1897 }
1898 break;
1899 }
1900
1901 case VMMDevReq_GetSeamlessChangeRequest:
1902 {
1903 if (pRequestHeader->size != sizeof(VMMDevSeamlessChangeRequest))
1904 {
1905 pRequestHeader->rc = VERR_INVALID_PARAMETER;
1906 }
1907 else
1908 {
1909 VMMDevSeamlessChangeRequest *seamlessChangeRequest = (VMMDevSeamlessChangeRequest*)pRequestHeader;
1910 /* just pass on the information */
1911 Log(("VMMDev: returning seamless change request mode=%d\n", pThis->fSeamlessEnabled));
1912 if (pThis->fSeamlessEnabled)
1913 seamlessChangeRequest->mode = VMMDev_Seamless_Visible_Region;
1914 else
1915 seamlessChangeRequest->mode = VMMDev_Seamless_Disabled;
1916
1917 if (seamlessChangeRequest->eventAck == VMMDEV_EVENT_SEAMLESS_MODE_CHANGE_REQUEST)
1918 {
1919 /* Remember which mode the client has queried. */
1920 pThis->fLastSeamlessEnabled = pThis->fSeamlessEnabled;
1921 }
1922
1923 pRequestHeader->rc = VINF_SUCCESS;
1924 }
1925 break;
1926 }
1927
1928 case VMMDevReq_GetVRDPChangeRequest:
1929 {
1930 if (pRequestHeader->size != sizeof(VMMDevVRDPChangeRequest))
1931 {
1932 pRequestHeader->rc = VERR_INVALID_PARAMETER;
1933 }
1934 else
1935 {
1936 VMMDevVRDPChangeRequest *vrdpChangeRequest = (VMMDevVRDPChangeRequest*)pRequestHeader;
1937 /* just pass on the information */
1938 Log(("VMMDev: returning VRDP status %d level %d\n", pThis->fVRDPEnabled, pThis->u32VRDPExperienceLevel));
1939
1940 vrdpChangeRequest->u8VRDPActive = pThis->fVRDPEnabled;
1941 vrdpChangeRequest->u32VRDPExperienceLevel = pThis->u32VRDPExperienceLevel;
1942
1943 pRequestHeader->rc = VINF_SUCCESS;
1944 }
1945 break;
1946 }
1947
1948 case VMMDevReq_GetMemBalloonChangeRequest:
1949 {
1950 Log(("VMMDevReq_GetMemBalloonChangeRequest\n"));
1951 if (pRequestHeader->size != sizeof(VMMDevGetMemBalloonChangeRequest))
1952 {
1953 AssertFailed();
1954 pRequestHeader->rc = VERR_INVALID_PARAMETER;
1955 }
1956 else
1957 {
1958 VMMDevGetMemBalloonChangeRequest *memBalloonChangeRequest = (VMMDevGetMemBalloonChangeRequest*)pRequestHeader;
1959 /* just pass on the information */
1960 Log(("VMMDev: returning memory balloon size =%d\n", pThis->u32MemoryBalloonSize));
1961 memBalloonChangeRequest->cBalloonChunks = pThis->u32MemoryBalloonSize;
1962 memBalloonChangeRequest->cPhysMemChunks = pThis->cbGuestRAM / (uint64_t)_1M;
1963
1964 if (memBalloonChangeRequest->eventAck == VMMDEV_EVENT_BALLOON_CHANGE_REQUEST)
1965 {
1966 /* Remember which mode the client has queried. */
1967 pThis->u32LastMemoryBalloonSize = pThis->u32MemoryBalloonSize;
1968 }
1969
1970 pRequestHeader->rc = VINF_SUCCESS;
1971 }
1972 break;
1973 }
1974
1975 case VMMDevReq_ChangeMemBalloon:
1976 {
1977 VMMDevChangeMemBalloon *memBalloonChange = (VMMDevChangeMemBalloon*)pRequestHeader;
1978
1979 Log(("VMMDevReq_ChangeMemBalloon\n"));
1980 if ( pRequestHeader->size < sizeof(VMMDevChangeMemBalloon)
1981 || memBalloonChange->cPages != VMMDEV_MEMORY_BALLOON_CHUNK_PAGES
1982 || pRequestHeader->size != (uint32_t)RT_OFFSETOF(VMMDevChangeMemBalloon, aPhysPage[memBalloonChange->cPages]))
1983 {
1984 AssertFailed();
1985 pRequestHeader->rc = VERR_INVALID_PARAMETER;
1986 }
1987 else
1988 {
1989 pRequestHeader->rc = PGMR3PhysChangeMemBalloon(PDMDevHlpGetVM(pDevIns), !!memBalloonChange->fInflate, memBalloonChange->cPages, memBalloonChange->aPhysPage);
1990 if (memBalloonChange->fInflate)
1991 STAM_REL_U32_INC(&pThis->StatMemBalloonChunks);
1992 else
1993 STAM_REL_U32_DEC(&pThis->StatMemBalloonChunks);
1994 }
1995 break;
1996 }
1997
1998 case VMMDevReq_GetStatisticsChangeRequest:
1999 {
2000 Log(("VMMDevReq_GetStatisticsChangeRequest\n"));
2001 if (pRequestHeader->size != sizeof(VMMDevGetStatisticsChangeRequest))
2002 {
2003 AssertFailed();
2004 pRequestHeader->rc = VERR_INVALID_PARAMETER;
2005 }
2006 else
2007 {
2008 VMMDevGetStatisticsChangeRequest *statIntervalChangeRequest = (VMMDevGetStatisticsChangeRequest*)pRequestHeader;
2009 /* just pass on the information */
2010 Log(("VMMDev: returning statistics interval %d seconds\n", pThis->u32StatIntervalSize));
2011 statIntervalChangeRequest->u32StatInterval = pThis->u32StatIntervalSize;
2012
2013 if (statIntervalChangeRequest->eventAck == VMMDEV_EVENT_STATISTICS_INTERVAL_CHANGE_REQUEST)
2014 {
2015 /* Remember which mode the client has queried. */
2016 pThis->u32LastStatIntervalSize= pThis->u32StatIntervalSize;
2017 }
2018
2019 pRequestHeader->rc = VINF_SUCCESS;
2020 }
2021 break;
2022 }
2023
2024 case VMMDevReq_ReportGuestStats:
2025 {
2026 Log(("VMMDevReq_ReportGuestStats\n"));
2027 if (pRequestHeader->size != sizeof(VMMDevReportGuestStats))
2028 {
2029 pRequestHeader->rc = VERR_INVALID_PARAMETER;
2030 }
2031 else
2032 {
2033 VMMDevReportGuestStats *stats = (VMMDevReportGuestStats*)pRequestHeader;
2034
2035#ifdef DEBUG
2036 VBoxGuestStatistics *pGuestStats = &stats->guestStats;
2037
2038 Log(("Current statistics:\n"));
2039 if (pGuestStats->u32StatCaps & VBOX_GUEST_STAT_CPU_LOAD_IDLE)
2040 Log(("CPU%d: CPU Load Idle %-3d%%\n", pGuestStats->u32CpuId, pGuestStats->u32CpuLoad_Idle));
2041
2042 if (pGuestStats->u32StatCaps & VBOX_GUEST_STAT_CPU_LOAD_KERNEL)
2043 Log(("CPU%d: CPU Load Kernel %-3d%%\n", pGuestStats->u32CpuId, pGuestStats->u32CpuLoad_Kernel));
2044
2045 if (pGuestStats->u32StatCaps & VBOX_GUEST_STAT_CPU_LOAD_USER)
2046 Log(("CPU%d: CPU Load User %-3d%%\n", pGuestStats->u32CpuId, pGuestStats->u32CpuLoad_User));
2047
2048 if (pGuestStats->u32StatCaps & VBOX_GUEST_STAT_THREADS)
2049 Log(("CPU%d: Thread %d\n", pGuestStats->u32CpuId, pGuestStats->u32Threads));
2050
2051 if (pGuestStats->u32StatCaps & VBOX_GUEST_STAT_PROCESSES)
2052 Log(("CPU%d: Processes %d\n", pGuestStats->u32CpuId, pGuestStats->u32Processes));
2053
2054 if (pGuestStats->u32StatCaps & VBOX_GUEST_STAT_HANDLES)
2055 Log(("CPU%d: Handles %d\n", pGuestStats->u32CpuId, pGuestStats->u32Handles));
2056
2057 if (pGuestStats->u32StatCaps & VBOX_GUEST_STAT_MEMORY_LOAD)
2058 Log(("CPU%d: Memory Load %d%%\n", pGuestStats->u32CpuId, pGuestStats->u32MemoryLoad));
2059
2060 /* Note that reported values are in pages; upper layers expect them in megabytes */
2061 Log(("CPU%d: Page size %-4d bytes\n", pGuestStats->u32CpuId, pGuestStats->u32PageSize));
2062 Assert(pGuestStats->u32PageSize == 4096);
2063
2064 if (pGuestStats->u32StatCaps & VBOX_GUEST_STAT_PHYS_MEM_TOTAL)
2065 Log(("CPU%d: Total physical memory %-4d MB\n", pGuestStats->u32CpuId, (pGuestStats->u32PhysMemTotal + (_1M/_4K)-1) / (_1M/_4K)));
2066
2067 if (pGuestStats->u32StatCaps & VBOX_GUEST_STAT_PHYS_MEM_AVAIL)
2068 Log(("CPU%d: Free physical memory %-4d MB\n", pGuestStats->u32CpuId, pGuestStats->u32PhysMemAvail / (_1M/_4K)));
2069
2070 if (pGuestStats->u32StatCaps & VBOX_GUEST_STAT_PHYS_MEM_BALLOON)
2071 Log(("CPU%d: Memory balloon size %-4d MB\n", pGuestStats->u32CpuId, pGuestStats->u32PhysMemBalloon / (_1M/_4K)));
2072
2073 if (pGuestStats->u32StatCaps & VBOX_GUEST_STAT_MEM_COMMIT_TOTAL)
2074 Log(("CPU%d: Committed memory %-4d MB\n", pGuestStats->u32CpuId, pGuestStats->u32MemCommitTotal / (_1M/_4K)));
2075
2076 if (pGuestStats->u32StatCaps & VBOX_GUEST_STAT_MEM_KERNEL_TOTAL)
2077 Log(("CPU%d: Total kernel memory %-4d MB\n", pGuestStats->u32CpuId, pGuestStats->u32MemKernelTotal / (_1M/_4K)));
2078
2079 if (pGuestStats->u32StatCaps & VBOX_GUEST_STAT_MEM_KERNEL_PAGED)
2080 Log(("CPU%d: Paged kernel memory %-4d MB\n", pGuestStats->u32CpuId, pGuestStats->u32MemKernelPaged / (_1M/_4K)));
2081
2082 if (pGuestStats->u32StatCaps & VBOX_GUEST_STAT_MEM_KERNEL_NONPAGED)
2083 Log(("CPU%d: Nonpaged kernel memory %-4d MB\n", pGuestStats->u32CpuId, pGuestStats->u32MemKernelNonPaged / (_1M/_4K)));
2084
2085 if (pGuestStats->u32StatCaps & VBOX_GUEST_STAT_MEM_SYSTEM_CACHE)
2086 Log(("CPU%d: System cache size %-4d MB\n", pGuestStats->u32CpuId, pGuestStats->u32MemSystemCache / (_1M/_4K)));
2087
2088 if (pGuestStats->u32StatCaps & VBOX_GUEST_STAT_PAGE_FILE_SIZE)
2089 Log(("CPU%d: Page file size %-4d MB\n", pGuestStats->u32CpuId, pGuestStats->u32PageFileSize / (_1M/_4K)));
2090 Log(("Statistics end *******************\n"));
2091#endif
2092
2093 /* forward the call */
2094 pRequestHeader->rc = pThis->pDrv->pfnReportStatistics(pThis->pDrv, &stats->guestStats);
2095 }
2096 break;
2097 }
2098
2099 case VMMDevReq_QueryCredentials:
2100 {
2101 if (pRequestHeader->size != sizeof(VMMDevCredentials))
2102 {
2103 AssertMsgFailed(("VMMDevReq_QueryCredentials request size too small.\n"));
2104 pRequestHeader->rc = VERR_INVALID_PARAMETER;
2105 }
2106 else
2107 {
2108 VMMDevCredentials *credentials = (VMMDevCredentials*)pRequestHeader;
2109
2110 /* let's start by nulling out the data */
2111 memset(credentials->szUserName, '\0', VMMDEV_CREDENTIALS_SZ_SIZE);
2112 memset(credentials->szPassword, '\0', VMMDEV_CREDENTIALS_SZ_SIZE);
2113 memset(credentials->szDomain, '\0', VMMDEV_CREDENTIALS_SZ_SIZE);
2114
2115 /* should we return whether we got credentials for a logon? */
2116 if (credentials->u32Flags & VMMDEV_CREDENTIALS_QUERYPRESENCE)
2117 {
2118 if ( pThis->pCredentials->Logon.szUserName[0]
2119 || pThis->pCredentials->Logon.szPassword[0]
2120 || pThis->pCredentials->Logon.szDomain[0])
2121 {
2122 credentials->u32Flags |= VMMDEV_CREDENTIALS_PRESENT;
2123 }
2124 else
2125 {
2126 credentials->u32Flags &= ~VMMDEV_CREDENTIALS_PRESENT;
2127 }
2128 }
2129
2130 /* does the guest want to read logon credentials? */
2131 if (credentials->u32Flags & VMMDEV_CREDENTIALS_READ)
2132 {
2133 if (pThis->pCredentials->Logon.szUserName[0])
2134 strcpy(credentials->szUserName, pThis->pCredentials->Logon.szUserName);
2135 if (pThis->pCredentials->Logon.szPassword[0])
2136 strcpy(credentials->szPassword, pThis->pCredentials->Logon.szPassword);
2137 if (pThis->pCredentials->Logon.szDomain[0])
2138 strcpy(credentials->szDomain, pThis->pCredentials->Logon.szDomain);
2139 if (!pThis->pCredentials->Logon.fAllowInteractiveLogon)
2140 credentials->u32Flags |= VMMDEV_CREDENTIALS_NOLOCALLOGON;
2141 else
2142 credentials->u32Flags &= ~VMMDEV_CREDENTIALS_NOLOCALLOGON;
2143 }
2144
2145 if (!pThis->fKeepCredentials)
2146 {
2147 /* does the caller want us to destroy the logon credentials? */
2148 if (credentials->u32Flags & VMMDEV_CREDENTIALS_CLEAR)
2149 {
2150 memset(pThis->pCredentials->Logon.szUserName, '\0', VMMDEV_CREDENTIALS_SZ_SIZE);
2151 memset(pThis->pCredentials->Logon.szPassword, '\0', VMMDEV_CREDENTIALS_SZ_SIZE);
2152 memset(pThis->pCredentials->Logon.szDomain, '\0', VMMDEV_CREDENTIALS_SZ_SIZE);
2153 }
2154 }
2155
2156 /* does the guest want to read credentials for verification? */
2157 if (credentials->u32Flags & VMMDEV_CREDENTIALS_READJUDGE)
2158 {
2159 if (pThis->pCredentials->Judge.szUserName[0])
2160 strcpy(credentials->szUserName, pThis->pCredentials->Judge.szUserName);
2161 if (pThis->pCredentials->Judge.szPassword[0])
2162 strcpy(credentials->szPassword, pThis->pCredentials->Judge.szPassword);
2163 if (pThis->pCredentials->Judge.szDomain[0])
2164 strcpy(credentials->szDomain, pThis->pCredentials->Judge.szDomain);
2165 }
2166
2167 /* does the caller want us to destroy the judgement credentials? */
2168 if (credentials->u32Flags & VMMDEV_CREDENTIALS_CLEARJUDGE)
2169 {
2170 memset(pThis->pCredentials->Judge.szUserName, '\0', VMMDEV_CREDENTIALS_SZ_SIZE);
2171 memset(pThis->pCredentials->Judge.szPassword, '\0', VMMDEV_CREDENTIALS_SZ_SIZE);
2172 memset(pThis->pCredentials->Judge.szDomain, '\0', VMMDEV_CREDENTIALS_SZ_SIZE);
2173 }
2174
2175 pRequestHeader->rc = VINF_SUCCESS;
2176 }
2177 break;
2178 }
2179
2180 case VMMDevReq_ReportCredentialsJudgement:
2181 {
2182 if (pRequestHeader->size != sizeof(VMMDevCredentials))
2183 {
2184 AssertMsgFailed(("VMMDevReq_ReportCredentialsJudgement request size too small.\n"));
2185 pRequestHeader->rc = VERR_INVALID_PARAMETER;
2186 }
2187 else
2188 {
2189 VMMDevCredentials *credentials = (VMMDevCredentials*)pRequestHeader;
2190
2191 /* what does the guest think about the credentials? (note: the order is important here!) */
2192 if (credentials->u32Flags & VMMDEV_CREDENTIALS_JUDGE_DENY)
2193 {
2194 pThis->pDrv->pfnSetCredentialsJudgementResult(pThis->pDrv, VMMDEV_CREDENTIALS_JUDGE_DENY);
2195 }
2196 else if (credentials->u32Flags & VMMDEV_CREDENTIALS_JUDGE_NOJUDGEMENT)
2197 {
2198 pThis->pDrv->pfnSetCredentialsJudgementResult(pThis->pDrv, VMMDEV_CREDENTIALS_JUDGE_NOJUDGEMENT);
2199 }
2200 else if (credentials->u32Flags & VMMDEV_CREDENTIALS_JUDGE_OK)
2201 {
2202 pThis->pDrv->pfnSetCredentialsJudgementResult(pThis->pDrv, VMMDEV_CREDENTIALS_JUDGE_OK);
2203 }
2204 else
2205 Log(("VMMDevReq_ReportCredentialsJudgement: invalid flags: %d!!!\n", credentials->u32Flags));
2206
2207 pRequestHeader->rc = VINF_SUCCESS;
2208 }
2209 break;
2210 }
2211
2212 /*
2213 * Implemented in 3.1.0.
2214 *
2215 * Note! The ring-0 VBoxGuestLib uses this to check whether
2216 * VMMDevHGCMParmType_PageList is supported.
2217 */
2218 case VMMDevReq_GetHostVersion:
2219 {
2220 AssertMsgBreakStmt(pRequestHeader->size == sizeof(VMMDevReqHostVersion),
2221 ("%#x < %#x\n", pRequestHeader->size, sizeof(VMMDevReqLogString)),
2222 pRequestHeader->rc = VERR_INVALID_PARAMETER);
2223 VMMDevReqHostVersion *pReqHostVer = (VMMDevReqHostVersion*)pRequestHeader;
2224 pReqHostVer->major = RTBldCfgVersionMajor();
2225 pReqHostVer->minor = RTBldCfgVersionMinor();
2226 pReqHostVer->build = RTBldCfgVersionBuild();
2227 pReqHostVer->revision = RTBldCfgRevision();
2228 pReqHostVer->features = VMMDEV_HVF_HGCM_PHYS_PAGE_LIST;
2229 pReqHostVer->header.rc = VINF_SUCCESS;
2230 break;
2231 }
2232
2233 case VMMDevReq_GetCpuHotPlugRequest:
2234 {
2235 VMMDevGetCpuHotPlugRequest *pReqCpuHotPlug = (VMMDevGetCpuHotPlugRequest *)pRequestHeader;
2236
2237 if (pRequestHeader->size != sizeof(VMMDevGetCpuHotPlugRequest))
2238 {
2239 pRequestHeader->rc = VERR_INVALID_PARAMETER;
2240 }
2241 else
2242 {
2243 pReqCpuHotPlug->enmEventType = pThis->enmCpuHotPlugEvent;
2244 pReqCpuHotPlug->idCpuCore = pThis->idCpuCore;
2245 pReqCpuHotPlug->idCpuPackage = pThis->idCpuPackage;
2246 pReqCpuHotPlug->header.rc = VINF_SUCCESS;
2247
2248 /* Clear the event */
2249 pThis->enmCpuHotPlugEvent = VMMDevCpuEventType_None;
2250 pThis->idCpuCore = UINT32_MAX;
2251 pThis->idCpuPackage = UINT32_MAX;
2252 }
2253 break;
2254 }
2255
2256 case VMMDevReq_SetCpuHotPlugStatus:
2257 {
2258 VMMDevCpuHotPlugStatusRequest *pReqCpuHotPlugStatus = (VMMDevCpuHotPlugStatusRequest *)pRequestHeader;
2259
2260 if (pRequestHeader->size != sizeof(VMMDevCpuHotPlugStatusRequest))
2261 {
2262 pRequestHeader->rc = VERR_INVALID_PARAMETER;
2263 }
2264 else
2265 {
2266 pRequestHeader->rc = VINF_SUCCESS;
2267
2268 if (pReqCpuHotPlugStatus->enmStatusType == VMMDevCpuStatusType_Disable)
2269 pThis->fCpuHotPlugEventsEnabled = false;
2270 else if (pReqCpuHotPlugStatus->enmStatusType == VMMDevCpuStatusType_Enable)
2271 pThis->fCpuHotPlugEventsEnabled = true;
2272 else
2273 pRequestHeader->rc = VERR_INVALID_PARAMETER;
2274 }
2275 break;
2276 }
2277
2278#ifdef VBOX_WITH_PAGE_SHARING
2279 case VMMDevReq_RegisterSharedModule:
2280 pRequestHeader->rc = vmmdevReqHandler_RegisterSharedModule(pDevIns,
2281 (VMMDevSharedModuleRegistrationRequest *)pRequestHeader);
2282 break;
2283
2284 case VMMDevReq_UnregisterSharedModule:
2285 pRequestHeader->rc = vmmdevReqHandler_UnregisterSharedModule(pDevIns,
2286 (VMMDevSharedModuleUnregistrationRequest *)pRequestHeader);
2287 break;
2288
2289 case VMMDevReq_CheckSharedModules:
2290 pRequestHeader->rc = vmmdevReqHandler_CheckSharedModules(pDevIns,
2291 (VMMDevSharedModuleCheckRequest *)pRequestHeader);
2292 break;
2293
2294 case VMMDevReq_GetPageSharingStatus:
2295 pRequestHeader->rc = vmmdevReqHandler_GetPageSharingStatus(pThis,
2296 (VMMDevPageSharingStatusRequest *)pRequestHeader);
2297 break;
2298
2299 case VMMDevReq_DebugIsPageShared:
2300 pRequestHeader->rc = vmmdevReqHandler_DebugIsPageShared(pDevIns, (VMMDevPageIsSharedRequest *)pRequestHeader);
2301 break;
2302
2303#endif /* VBOX_WITH_PAGE_SHARING */
2304
2305#ifdef DEBUG
2306 case VMMDevReq_LogString:
2307 {
2308 if (pRequestHeader->size < sizeof(VMMDevReqLogString))
2309 {
2310 AssertMsgFailed(("VMMDevReq_LogString request size too small.\n"));
2311 pRequestHeader->rc = VERR_INVALID_PARAMETER;
2312 }
2313 else
2314 {
2315 VMMDevReqLogString *pReqLogString = (VMMDevReqLogString *)pRequestHeader;
2316 LogIt(LOG_INSTANCE, RTLOGGRPFLAGS_LEVEL_1, LOG_GROUP_DEV_VMM_BACKDOOR,
2317 ("DEBUG LOG: %s", pReqLogString->szString));
2318 pRequestHeader->rc = VINF_SUCCESS;
2319 }
2320 break;
2321 }
2322#endif
2323
2324 /*
2325 * Get a unique session id for this VM; the id will be different after each start, reset or restore of the VM
2326 * This can be used for restore detection inside the guest.
2327 */
2328 case VMMDevReq_GetSessionId:
2329 {
2330 if (pRequestHeader->size != sizeof(VMMDevReqSessionId))
2331 {
2332 AssertMsgFailed(("VMMDevReq_GetSessionId request size too small.\n"));
2333 pRequestHeader->rc = VERR_INVALID_PARAMETER;
2334 }
2335 else
2336 {
2337 VMMDevReqSessionId *pReq = (VMMDevReqSessionId *)pRequestHeader;
2338 pReq->idSession = pThis->idSession;
2339 pRequestHeader->rc = VINF_SUCCESS;
2340 }
2341 break;
2342 }
2343
2344 default:
2345 {
2346 pRequestHeader->rc = VERR_NOT_IMPLEMENTED;
2347 Log(("VMMDev unknown request type %d\n", pRequestHeader->requestType));
2348 break;
2349 }
2350 }
2351
2352l_end:
2353 /* Write the result back to guest memory */
2354 if (pRequestHeader)
2355 {
2356 PDMDevHlpPhysWrite(pDevIns, (RTGCPHYS)u32, pRequestHeader, pRequestHeader->size);
2357 RTMemFree(pRequestHeader);
2358 }
2359 else
2360 {
2361 /* early error case; write back header only */
2362 PDMDevHlpPhysWrite(pDevIns, (RTGCPHYS)u32, &requestHeader, sizeof(requestHeader));
2363 }
2364
2365 PDMCritSectLeave(&pThis->CritSect);
2366 return rcRet;
2367}
2368
2369/**
2370 * Callback function for mapping an PCI I/O region.
2371 *
2372 * @return VBox status code.
2373 * @param pPciDev Pointer to PCI device. Use pPciDev->pDevIns to get the device instance.
2374 * @param iRegion The region number.
2375 * @param GCPhysAddress Physical address of the region. If iType is PCI_ADDRESS_SPACE_IO, this is an
2376 * I/O port, else it's a physical address.
2377 * This address is *NOT* relative to pci_mem_base like earlier!
2378 * @param enmType One of the PCI_ADDRESS_SPACE_* values.
2379 */
2380static DECLCALLBACK(int) vmmdevIORAMRegionMap(PPCIDEVICE pPciDev, /*unsigned*/ int iRegion, RTGCPHYS GCPhysAddress, uint32_t cb, PCIADDRESSSPACE enmType)
2381{
2382 LogFlow(("vmmdevR3IORAMRegionMap: iRegion=%d GCPhysAddress=%RGp cb=%#x enmType=%d\n", iRegion, GCPhysAddress, cb, enmType));
2383 VMMDevState *pThis = PCIDEV_2_VMMDEVSTATE(pPciDev);
2384 int rc;
2385
2386 if (iRegion == 1)
2387 {
2388 AssertReturn(enmType == PCI_ADDRESS_SPACE_MEM, VERR_INTERNAL_ERROR);
2389 Assert(pThis->pVMMDevRAMR3 != NULL);
2390 if (GCPhysAddress != NIL_RTGCPHYS)
2391 {
2392 /*
2393 * Map the MMIO2 memory.
2394 */
2395 pThis->GCPhysVMMDevRAM = GCPhysAddress;
2396 Assert(pThis->GCPhysVMMDevRAM == GCPhysAddress);
2397 rc = PDMDevHlpMMIO2Map(pPciDev->pDevIns, iRegion, GCPhysAddress);
2398 }
2399 else
2400 {
2401 /*
2402 * It is about to be unmapped, just clean up.
2403 */
2404 pThis->GCPhysVMMDevRAM = NIL_RTGCPHYS32;
2405 rc = VINF_SUCCESS;
2406 }
2407 }
2408 else if (iRegion == 2)
2409 {
2410 AssertReturn(enmType == PCI_ADDRESS_SPACE_MEM_PREFETCH, VERR_INTERNAL_ERROR);
2411 Assert(pThis->pVMMDevHeapR3 != NULL);
2412 if (GCPhysAddress != NIL_RTGCPHYS)
2413 {
2414 /*
2415 * Map the MMIO2 memory.
2416 */
2417 pThis->GCPhysVMMDevHeap = GCPhysAddress;
2418 Assert(pThis->GCPhysVMMDevHeap == GCPhysAddress);
2419 rc = PDMDevHlpMMIO2Map(pPciDev->pDevIns, iRegion, GCPhysAddress);
2420 if (RT_SUCCESS(rc))
2421 rc = PDMDevHlpRegisterVMMDevHeap(pPciDev->pDevIns, GCPhysAddress, pThis->pVMMDevHeapR3, VMMDEV_HEAP_SIZE);
2422 }
2423 else
2424 {
2425 /*
2426 * It is about to be unmapped, just clean up.
2427 */
2428 PDMDevHlpUnregisterVMMDevHeap(pPciDev->pDevIns, pThis->GCPhysVMMDevHeap);
2429 pThis->GCPhysVMMDevHeap = NIL_RTGCPHYS32;
2430 rc = VINF_SUCCESS;
2431 }
2432 }
2433 else
2434 {
2435 AssertMsgFailed(("%d\n", iRegion));
2436 rc = VERR_INVALID_PARAMETER;
2437 }
2438
2439 return rc;
2440}
2441
2442
2443/**
2444 * Callback function for mapping a PCI I/O region.
2445 *
2446 * @return VBox status code.
2447 * @param pPciDev Pointer to PCI device. Use pPciDev->pDevIns to get the device instance.
2448 * @param iRegion The region number.
2449 * @param GCPhysAddress Physical address of the region. If iType is PCI_ADDRESS_SPACE_IO, this is an
2450 * I/O port, else it's a physical address.
2451 * This address is *NOT* relative to pci_mem_base like earlier!
2452 * @param enmType One of the PCI_ADDRESS_SPACE_* values.
2453 */
2454static DECLCALLBACK(int) vmmdevIOPortRegionMap(PPCIDEVICE pPciDev, /*unsigned*/ int iRegion, RTGCPHYS GCPhysAddress, uint32_t cb, PCIADDRESSSPACE enmType)
2455{
2456 VMMDevState *pThis = PCIDEV_2_VMMDEVSTATE(pPciDev);
2457 int rc = VINF_SUCCESS;
2458
2459 Assert(enmType == PCI_ADDRESS_SPACE_IO);
2460 Assert(iRegion == 0);
2461 AssertMsg(RT_ALIGN(GCPhysAddress, 8) == GCPhysAddress, ("Expected 8 byte alignment. GCPhysAddress=%#x\n", GCPhysAddress));
2462
2463 /*
2464 * Save the base port address to simplify Port offset calculations.
2465 */
2466 pThis->PortBase = (RTIOPORT)GCPhysAddress;
2467
2468 /*
2469 * Register our port IO handlers.
2470 */
2471 rc = PDMDevHlpIOPortRegister(pPciDev->pDevIns,
2472 (RTIOPORT)GCPhysAddress + VMMDEV_PORT_OFF_REQUEST, 1,
2473 (void*)pThis, vmmdevRequestHandler,
2474 NULL, NULL, NULL, "VMMDev Request Handler");
2475 AssertRC(rc);
2476 return rc;
2477}
2478
2479/**
2480 * @interface_method_impl{PDMIBASE,pfnQueryInterface}
2481 */
2482static DECLCALLBACK(void *) vmmdevPortQueryInterface(PPDMIBASE pInterface, const char *pszIID)
2483{
2484 VMMDevState *pThis = RT_FROM_MEMBER(pInterface, VMMDevState, IBase);
2485
2486 PDMIBASE_RETURN_INTERFACE(pszIID, PDMIBASE, &pThis->IBase);
2487 PDMIBASE_RETURN_INTERFACE(pszIID, PDMIVMMDEVPORT, &pThis->IPort);
2488#ifdef VBOX_WITH_HGCM
2489 PDMIBASE_RETURN_INTERFACE(pszIID, PDMIHGCMPORT, &pThis->IHGCMPort);
2490#endif
2491 /* Currently only for shared folders. */
2492 PDMIBASE_RETURN_INTERFACE(pszIID, PDMILEDPORTS, &pThis->SharedFolders.ILeds);
2493 return NULL;
2494}
2495
2496/**
2497 * Gets the pointer to the status LED of a unit.
2498 *
2499 * @returns VBox status code.
2500 * @param pInterface Pointer to the interface structure containing the called function pointer.
2501 * @param iLUN The unit which status LED we desire.
2502 * @param ppLed Where to store the LED pointer.
2503 */
2504static DECLCALLBACK(int) vmmdevQueryStatusLed(PPDMILEDPORTS pInterface, unsigned iLUN, PPDMLED *ppLed)
2505{
2506 VMMDevState *pThis = (VMMDevState *)( (uintptr_t)pInterface - RT_OFFSETOF(VMMDevState, SharedFolders.ILeds) );
2507 if (iLUN == 0) /* LUN 0 is shared folders */
2508 {
2509 *ppLed = &pThis->SharedFolders.Led;
2510 return VINF_SUCCESS;
2511 }
2512 return VERR_PDM_LUN_NOT_FOUND;
2513}
2514
2515/* -=-=-=-=-=- IVMMDevPort -=-=-=-=-=- */
2516
2517/** Converts a VMMDev port interface pointer to a VMMDev state pointer. */
2518#define IVMMDEVPORT_2_VMMDEVSTATE(pInterface) ( (VMMDevState*)((uintptr_t)pInterface - RT_OFFSETOF(VMMDevState, IPort)) )
2519
2520
2521/**
2522 * Return the current absolute mouse position in pixels
2523 *
2524 * @returns VBox status code
2525 * @param pAbsX Pointer of result value, can be NULL
2526 * @param pAbsY Pointer of result value, can be NULL
2527 */
2528static DECLCALLBACK(int) vmmdevQueryAbsoluteMouse(PPDMIVMMDEVPORT pInterface, int32_t *pAbsX, int32_t *pAbsY)
2529{
2530 VMMDevState *pThis = IVMMDEVPORT_2_VMMDEVSTATE(pInterface);
2531 if (pAbsX)
2532 *pAbsX = ASMAtomicReadS32(&pThis->mouseXAbs); /* why the atomic read? */
2533 if (pAbsY)
2534 *pAbsY = ASMAtomicReadS32(&pThis->mouseYAbs);
2535 return VINF_SUCCESS;
2536}
2537
2538/**
2539 * Set the new absolute mouse position in pixels
2540 *
2541 * @returns VBox status code
2542 * @param absX New absolute X position
2543 * @param absY New absolute Y position
2544 */
2545static DECLCALLBACK(int) vmmdevSetAbsoluteMouse(PPDMIVMMDEVPORT pInterface, int32_t absX, int32_t absY)
2546{
2547 VMMDevState *pThis = IVMMDEVPORT_2_VMMDEVSTATE(pInterface);
2548 PDMCritSectEnter(&pThis->CritSect, VERR_SEM_BUSY);
2549
2550 if (pThis->mouseXAbs == absX && pThis->mouseYAbs == absY)
2551 {
2552 PDMCritSectLeave(&pThis->CritSect);
2553 return VINF_SUCCESS;
2554 }
2555 Log2(("vmmdevSetAbsoluteMouse: settings absolute position to x = %d, y = %d\n", absX, absY));
2556 pThis->mouseXAbs = absX;
2557 pThis->mouseYAbs = absY;
2558 VMMDevNotifyGuest (pThis, VMMDEV_EVENT_MOUSE_POSITION_CHANGED);
2559 PDMCritSectLeave(&pThis->CritSect);
2560 return VINF_SUCCESS;
2561}
2562
2563/**
2564 * Return the current mouse capability flags
2565 *
2566 * @returns VBox status code
2567 * @param pCapabilities Pointer of result value
2568 */
2569static DECLCALLBACK(int) vmmdevQueryMouseCapabilities(PPDMIVMMDEVPORT pInterface, uint32_t *pfCaps)
2570{
2571 VMMDevState *pThis = IVMMDEVPORT_2_VMMDEVSTATE(pInterface);
2572 if (!pfCaps)
2573 return VERR_INVALID_PARAMETER;
2574 *pfCaps = pThis->mouseCapabilities;
2575 return VINF_SUCCESS;
2576}
2577
2578/**
2579 * Set the current mouse capability flag (host side)
2580 *
2581 * @returns VBox status code
2582 * @param capabilities Capability mask
2583 */
2584static DECLCALLBACK(int) vmmdevUpdateMouseCapabilities(PPDMIVMMDEVPORT pInterface, uint32_t fCapsAdded, uint32_t fCapsRemoved)
2585{
2586 VMMDevState *pThis = IVMMDEVPORT_2_VMMDEVSTATE(pInterface);
2587 PDMCritSectEnter(&pThis->CritSect, VERR_SEM_BUSY);
2588
2589 uint32_t fOldCaps = pThis->mouseCapabilities;
2590 pThis->mouseCapabilities &= ~(fCapsRemoved & VMMDEV_MOUSE_HOST_MASK);
2591 pThis->mouseCapabilities |= (fCapsAdded & VMMDEV_MOUSE_HOST_MASK)
2592 | VMMDEV_MOUSE_HOST_RECHECKS_NEEDS_HOST_CURSOR;
2593 bool fNotify = fOldCaps != pThis->mouseCapabilities;
2594
2595 LogRelFlowFunc(("fCapsAdded=0x%x, fCapsRemoved=0x%x, fNotify %s\n",
2596 fCapsAdded, fCapsRemoved, fNotify ? "TRUE" : "FALSE"));
2597
2598 if (fNotify)
2599 VMMDevNotifyGuest (pThis, VMMDEV_EVENT_MOUSE_CAPABILITIES_CHANGED);
2600
2601 PDMCritSectLeave(&pThis->CritSect);
2602 return VINF_SUCCESS;
2603}
2604
2605
2606static DECLCALLBACK(int) vmmdevRequestDisplayChange(PPDMIVMMDEVPORT pInterface, uint32_t xres, uint32_t yres, uint32_t bpp, uint32_t display)
2607{
2608 VMMDevState *pThis = IVMMDEVPORT_2_VMMDEVSTATE(pInterface);
2609
2610 if (display >= RT_ELEMENTS(pThis->displayChangeData.aRequests))
2611 {
2612 return VERR_INVALID_PARAMETER;
2613 }
2614
2615 PDMCritSectEnter(&pThis->CritSect, VERR_SEM_BUSY);
2616
2617 DISPLAYCHANGEREQUEST *pRequest = &pThis->displayChangeData.aRequests[display];
2618
2619 /* Verify that the new resolution is different and that guest does not yet know about it. */
2620 bool fSameResolution = (!xres || (pRequest->lastReadDisplayChangeRequest.xres == xres)) &&
2621 (!yres || (pRequest->lastReadDisplayChangeRequest.yres == yres)) &&
2622 (!bpp || (pRequest->lastReadDisplayChangeRequest.bpp == bpp)) &&
2623 pRequest->lastReadDisplayChangeRequest.display == display;
2624
2625 if (!xres && !yres && !bpp)
2626 {
2627 /* Special case of reset video mode. */
2628 fSameResolution = false;
2629 }
2630
2631 Log3(("vmmdevRequestDisplayChange: same=%d. new: xres=%d, yres=%d, bpp=%d, display=%d. old: xres=%d, yres=%d, bpp=%d, display=%d.\n",
2632 fSameResolution, xres, yres, bpp, display, pRequest->lastReadDisplayChangeRequest.xres, pRequest->lastReadDisplayChangeRequest.yres, pRequest->lastReadDisplayChangeRequest.bpp, pRequest->lastReadDisplayChangeRequest.display));
2633
2634 if (!fSameResolution)
2635 {
2636 LogRel(("VMMDev::SetVideoModeHint: got a video mode hint (%dx%dx%d) at %d\n",
2637 xres, yres, bpp, display));
2638
2639 /* we could validate the information here but hey, the guest can do that as well! */
2640 pRequest->displayChangeRequest.xres = xres;
2641 pRequest->displayChangeRequest.yres = yres;
2642 pRequest->displayChangeRequest.bpp = bpp;
2643 pRequest->displayChangeRequest.display = display;
2644 pRequest->fPending = true;
2645
2646 /* IRQ so the guest knows what's going on */
2647 VMMDevNotifyGuest (pThis, VMMDEV_EVENT_DISPLAY_CHANGE_REQUEST);
2648 }
2649
2650 PDMCritSectLeave(&pThis->CritSect);
2651 return VINF_SUCCESS;
2652}
2653
2654static DECLCALLBACK(int) vmmdevRequestSeamlessChange(PPDMIVMMDEVPORT pInterface, bool fEnabled)
2655{
2656 VMMDevState *pThis = IVMMDEVPORT_2_VMMDEVSTATE(pInterface);
2657 PDMCritSectEnter(&pThis->CritSect, VERR_SEM_BUSY);
2658
2659 /* Verify that the new resolution is different and that guest does not yet know about it. */
2660 bool fSameMode = (pThis->fLastSeamlessEnabled == fEnabled);
2661
2662 Log(("vmmdevRequestSeamlessChange: same=%d. new=%d\n", fSameMode, fEnabled));
2663
2664 if (!fSameMode)
2665 {
2666 /* we could validate the information here but hey, the guest can do that as well! */
2667 pThis->fSeamlessEnabled = fEnabled;
2668
2669 /* IRQ so the guest knows what's going on */
2670 VMMDevNotifyGuest (pThis, VMMDEV_EVENT_SEAMLESS_MODE_CHANGE_REQUEST);
2671 }
2672
2673 PDMCritSectLeave(&pThis->CritSect);
2674 return VINF_SUCCESS;
2675}
2676
2677static DECLCALLBACK(int) vmmdevSetMemoryBalloon(PPDMIVMMDEVPORT pInterface, uint32_t ulBalloonSize)
2678{
2679 VMMDevState *pThis = IVMMDEVPORT_2_VMMDEVSTATE(pInterface);
2680 PDMCritSectEnter(&pThis->CritSect, VERR_SEM_BUSY);
2681
2682 /* Verify that the new resolution is different and that guest does not yet know about it. */
2683 bool fSame = (pThis->u32LastMemoryBalloonSize == ulBalloonSize);
2684
2685 Log(("vmmdevSetMemoryBalloon: old=%d. new=%d\n", pThis->u32LastMemoryBalloonSize, ulBalloonSize));
2686
2687 if (!fSame)
2688 {
2689 /* we could validate the information here but hey, the guest can do that as well! */
2690 pThis->u32MemoryBalloonSize = ulBalloonSize;
2691
2692 /* IRQ so the guest knows what's going on */
2693 VMMDevNotifyGuest (pThis, VMMDEV_EVENT_BALLOON_CHANGE_REQUEST);
2694 }
2695
2696 PDMCritSectLeave(&pThis->CritSect);
2697 return VINF_SUCCESS;
2698}
2699
2700static DECLCALLBACK(int) vmmdevVRDPChange(PPDMIVMMDEVPORT pInterface, bool fVRDPEnabled, uint32_t u32VRDPExperienceLevel)
2701{
2702 VMMDevState *pThis = IVMMDEVPORT_2_VMMDEVSTATE(pInterface);
2703 PDMCritSectEnter(&pThis->CritSect, VERR_SEM_BUSY);
2704
2705 bool fSame = (pThis->fVRDPEnabled == fVRDPEnabled);
2706
2707 Log(("vmmdevVRDPChange: old=%d. new=%d\n", pThis->fVRDPEnabled, fVRDPEnabled));
2708
2709 if (!fSame)
2710 {
2711 pThis->fVRDPEnabled = fVRDPEnabled;
2712 pThis->u32VRDPExperienceLevel = u32VRDPExperienceLevel;
2713
2714 VMMDevNotifyGuest (pThis, VMMDEV_EVENT_VRDP);
2715 }
2716
2717 PDMCritSectLeave(&pThis->CritSect);
2718 return VINF_SUCCESS;
2719}
2720
2721static DECLCALLBACK(int) vmmdevSetStatisticsInterval(PPDMIVMMDEVPORT pInterface, uint32_t ulStatInterval)
2722{
2723 VMMDevState *pThis = IVMMDEVPORT_2_VMMDEVSTATE(pInterface);
2724 PDMCritSectEnter(&pThis->CritSect, VERR_SEM_BUSY);
2725
2726 /* Verify that the new resolution is different and that guest does not yet know about it. */
2727 bool fSame = (pThis->u32LastStatIntervalSize == ulStatInterval);
2728
2729 Log(("vmmdevSetStatisticsInterval: old=%d. new=%d\n", pThis->u32LastStatIntervalSize, ulStatInterval));
2730
2731 if (!fSame)
2732 {
2733 /* we could validate the information here but hey, the guest can do that as well! */
2734 pThis->u32StatIntervalSize = ulStatInterval;
2735
2736 /* IRQ so the guest knows what's going on */
2737 VMMDevNotifyGuest (pThis, VMMDEV_EVENT_STATISTICS_INTERVAL_CHANGE_REQUEST);
2738 }
2739
2740 PDMCritSectLeave(&pThis->CritSect);
2741 return VINF_SUCCESS;
2742}
2743
2744
2745static DECLCALLBACK(int) vmmdevSetCredentials(PPDMIVMMDEVPORT pInterface, const char *pszUsername,
2746 const char *pszPassword, const char *pszDomain,
2747 uint32_t u32Flags)
2748{
2749 VMMDevState *pThis = IVMMDEVPORT_2_VMMDEVSTATE(pInterface);
2750 int rc = VINF_SUCCESS;
2751
2752 PDMCritSectEnter(&pThis->CritSect, VERR_SEM_BUSY);
2753
2754 /* logon mode? */
2755 if (u32Flags & VMMDEV_SETCREDENTIALS_GUESTLOGON)
2756 {
2757 /* memorize the data */
2758 strcpy(pThis->pCredentials->Logon.szUserName, pszUsername);
2759 strcpy(pThis->pCredentials->Logon.szPassword, pszPassword);
2760 strcpy(pThis->pCredentials->Logon.szDomain, pszDomain);
2761 pThis->pCredentials->Logon.fAllowInteractiveLogon = !(u32Flags & VMMDEV_SETCREDENTIALS_NOLOCALLOGON);
2762 }
2763 /* credentials verification mode? */
2764 else if (u32Flags & VMMDEV_SETCREDENTIALS_JUDGE)
2765 {
2766 /* memorize the data */
2767 strcpy(pThis->pCredentials->Judge.szUserName, pszUsername);
2768 strcpy(pThis->pCredentials->Judge.szPassword, pszPassword);
2769 strcpy(pThis->pCredentials->Judge.szDomain, pszDomain);
2770
2771 VMMDevNotifyGuest (pThis, VMMDEV_EVENT_JUDGE_CREDENTIALS);
2772 }
2773 else
2774 rc = VERR_INVALID_PARAMETER;
2775
2776 PDMCritSectLeave(&pThis->CritSect);
2777 return rc;
2778}
2779
2780/**
2781 * Notification from the Display. Especially useful when
2782 * acceleration is disabled after a video mode change.
2783 *
2784 * @param fEnable Current acceleration status.
2785 */
2786static DECLCALLBACK(void) vmmdevVBVAChange(PPDMIVMMDEVPORT pInterface, bool fEnabled)
2787{
2788 VMMDevState *pThis = IVMMDEVPORT_2_VMMDEVSTATE(pInterface);
2789
2790 Log(("vmmdevVBVAChange: fEnabled = %d\n", fEnabled));
2791
2792 if (pThis)
2793 {
2794 pThis->u32VideoAccelEnabled = fEnabled;
2795 }
2796 return;
2797}
2798
2799/**
2800 * Notification that a CPU is about to be unplugged from the VM.
2801 * The guest has to eject the CPU.
2802 *
2803 * @returns VBox status code.
2804 * @param idCpu The id of the CPU.
2805 * @param idCpuCore The core id of the CPU to remove.
2806 * @param idCpuPackage The package id of the CPU to remove.
2807 */
2808static DECLCALLBACK(int) vmmdevCpuHotUnplug(PPDMIVMMDEVPORT pInterface, uint32_t idCpuCore, uint32_t idCpuPackage)
2809{
2810 int rc = VINF_SUCCESS;
2811 VMMDevState *pThis = IVMMDEVPORT_2_VMMDEVSTATE(pInterface);
2812
2813 Log(("vmmdevCpuHotUnplug: idCpuCore=%u idCpuPackage=%u\n", idCpuCore, idCpuPackage));
2814
2815 PDMCritSectEnter(&pThis->CritSect, VERR_SEM_BUSY);
2816
2817 if (pThis->fCpuHotPlugEventsEnabled)
2818 {
2819 pThis->enmCpuHotPlugEvent = VMMDevCpuEventType_Unplug;
2820 pThis->idCpuCore = idCpuCore;
2821 pThis->idCpuPackage = idCpuPackage;
2822 VMMDevNotifyGuest (pThis, VMMDEV_EVENT_CPU_HOTPLUG);
2823 }
2824 else
2825 rc = VERR_CPU_HOTPLUG_NOT_MONITORED_BY_GUEST;
2826
2827 PDMCritSectLeave(&pThis->CritSect);
2828 return rc;
2829}
2830
2831/**
2832 * Notification that a CPU was attached to the VM
2833 * The guest may use it now.
2834 *
2835 * @returns VBox status code.
2836 * @param idCpuCore The core id of the CPU to add.
2837 * @param idCpuPackage The package id of the CPU to add.
2838 */
2839static DECLCALLBACK(int) vmmdevCpuHotPlug(PPDMIVMMDEVPORT pInterface, uint32_t idCpuCore, uint32_t idCpuPackage)
2840{
2841 int rc = VINF_SUCCESS;
2842 VMMDevState *pThis = IVMMDEVPORT_2_VMMDEVSTATE(pInterface);
2843
2844 Log(("vmmdevCpuPlug: idCpuCore=%u idCpuPackage=%u\n", idCpuCore, idCpuPackage));
2845
2846 PDMCritSectEnter(&pThis->CritSect, VERR_SEM_BUSY);
2847
2848 if (pThis->fCpuHotPlugEventsEnabled)
2849 {
2850 pThis->enmCpuHotPlugEvent = VMMDevCpuEventType_Plug;
2851 pThis->idCpuCore = idCpuCore;
2852 pThis->idCpuPackage = idCpuPackage;
2853 VMMDevNotifyGuest(pThis, VMMDEV_EVENT_CPU_HOTPLUG);
2854 }
2855 else
2856 rc = VERR_CPU_HOTPLUG_NOT_MONITORED_BY_GUEST;
2857
2858 PDMCritSectLeave(&pThis->CritSect);
2859 return rc;
2860}
2861
2862/* -=-=-=-=-=- Saved State -=-=-=-=-=- */
2863
2864/**
2865 * @copydoc FNSSMDEVLIVEEXEC
2866 */
2867static DECLCALLBACK(int) vmmdevLiveExec(PPDMDEVINS pDevIns, PSSMHANDLE pSSM, uint32_t uPass)
2868{
2869 VMMDevState *pThis = PDMINS_2_DATA(pDevIns, VMMDevState*);
2870
2871 SSMR3PutBool(pSSM, pThis->fGetHostTimeDisabled);
2872 SSMR3PutBool(pSSM, pThis->fBackdoorLogDisabled);
2873 SSMR3PutBool(pSSM, pThis->fKeepCredentials);
2874 SSMR3PutBool(pSSM, pThis->fHeapEnabled);
2875
2876 return VINF_SSM_DONT_CALL_AGAIN;
2877}
2878
2879
2880/**
2881 * @copydoc FNSSMDEVSAVEEXEC
2882 *
2883 */
2884static DECLCALLBACK(int) vmmdevSaveExec(PPDMDEVINS pDevIns, PSSMHANDLE pSSM)
2885{
2886 VMMDevState *pThis = PDMINS_2_DATA(pDevIns, VMMDevState*);
2887
2888 vmmdevLiveExec(pDevIns, pSSM, SSM_PASS_FINAL);
2889
2890 SSMR3PutU32(pSSM, pThis->hypervisorSize);
2891 SSMR3PutU32(pSSM, pThis->mouseCapabilities);
2892 SSMR3PutS32(pSSM, pThis->mouseXAbs);
2893 SSMR3PutS32(pSSM, pThis->mouseYAbs);
2894
2895 SSMR3PutBool(pSSM, pThis->fNewGuestFilterMask);
2896 SSMR3PutU32(pSSM, pThis->u32NewGuestFilterMask);
2897 SSMR3PutU32(pSSM, pThis->u32GuestFilterMask);
2898 SSMR3PutU32(pSSM, pThis->u32HostEventFlags);
2899 /* The following is not strictly necessary as PGM restores MMIO2, keeping it for historical reasons. */
2900 SSMR3PutMem(pSSM, &pThis->pVMMDevRAMR3->V, sizeof(pThis->pVMMDevRAMR3->V));
2901
2902 SSMR3PutMem(pSSM, &pThis->guestInfo, sizeof(pThis->guestInfo));
2903 SSMR3PutU32(pSSM, pThis->fu32AdditionsOk);
2904 SSMR3PutU32(pSSM, pThis->u32VideoAccelEnabled);
2905 SSMR3PutBool(pSSM, pThis->displayChangeData.fGuestSentChangeEventAck);
2906
2907 SSMR3PutU32(pSSM, pThis->guestCaps);
2908
2909#ifdef VBOX_WITH_HGCM
2910 vmmdevHGCMSaveState(pThis, pSSM);
2911#endif /* VBOX_WITH_HGCM */
2912
2913 SSMR3PutU32(pSSM, pThis->fHostCursorRequested);
2914
2915 SSMR3PutU32(pSSM, pThis->guestInfo2.uFullVersion);
2916 SSMR3PutU32(pSSM, pThis->guestInfo2.uRevision);
2917 SSMR3PutU32(pSSM, pThis->guestInfo2.fFeatures);
2918 SSMR3PutStrZ(pSSM, pThis->guestInfo2.szName);
2919 SSMR3PutU32(pSSM, pThis->cFacilityStatuses);
2920 for (uint32_t i = 0; i < pThis->cFacilityStatuses; i++)
2921 {
2922 SSMR3PutU32(pSSM, pThis->aFacilityStatuses[i].uFacility);
2923 SSMR3PutU32(pSSM, pThis->aFacilityStatuses[i].fFlags);
2924 SSMR3PutU16(pSSM, pThis->aFacilityStatuses[i].uStatus);
2925 SSMR3PutS64(pSSM, RTTimeSpecGetNano(&pThis->aFacilityStatuses[i].TimeSpecTS));
2926 }
2927
2928 return VINF_SUCCESS;
2929}
2930
2931/**
2932 * @copydoc FNSSMDEVLOADEXEC
2933 */
2934static DECLCALLBACK(int) vmmdevLoadExec(PPDMDEVINS pDevIns, PSSMHANDLE pSSM, uint32_t uVersion, uint32_t uPass)
2935{
2936 /** @todo The code load code is assuming we're always loaded into a freshly
2937 * constructed VM. */
2938 VMMDevState *pThis = PDMINS_2_DATA(pDevIns, VMMDevState*);
2939 int rc;
2940
2941 if ( uVersion > VMMDEV_SAVED_STATE_VERSION
2942 || uVersion < 6)
2943 return VERR_SSM_UNSUPPORTED_DATA_UNIT_VERSION;
2944
2945 /* config */
2946 if (uVersion > VMMDEV_SAVED_STATE_VERSION_VBOX_30)
2947 {
2948 bool f;
2949 rc = SSMR3GetBool(pSSM, &f); AssertRCReturn(rc, rc);
2950 if (pThis->fGetHostTimeDisabled != f)
2951 LogRel(("VMMDev: Config mismatch - fGetHostTimeDisabled: config=%RTbool saved=%RTbool\n", pThis->fGetHostTimeDisabled, f));
2952
2953 rc = SSMR3GetBool(pSSM, &f); AssertRCReturn(rc, rc);
2954 if (pThis->fBackdoorLogDisabled != f)
2955 LogRel(("VMMDev: Config mismatch - fBackdoorLogDisabled: config=%RTbool saved=%RTbool\n", pThis->fBackdoorLogDisabled, f));
2956
2957 rc = SSMR3GetBool(pSSM, &f); AssertRCReturn(rc, rc);
2958 if (pThis->fKeepCredentials != f)
2959 return SSMR3SetCfgError(pSSM, RT_SRC_POS, N_("Config mismatch - fKeepCredentials: config=%RTbool saved=%RTbool"),
2960 pThis->fKeepCredentials, f);
2961 rc = SSMR3GetBool(pSSM, &f); AssertRCReturn(rc, rc);
2962 if (pThis->fHeapEnabled != f)
2963 return SSMR3SetCfgError(pSSM, RT_SRC_POS, N_("Config mismatch - fHeapEnabled: config=%RTbool saved=%RTbool"),
2964 pThis->fHeapEnabled, f);
2965 }
2966
2967 if (uPass != SSM_PASS_FINAL)
2968 return VINF_SUCCESS;
2969
2970 /* state */
2971 SSMR3GetU32(pSSM, &pThis->hypervisorSize);
2972 SSMR3GetU32(pSSM, &pThis->mouseCapabilities);
2973 SSMR3GetS32(pSSM, &pThis->mouseXAbs);
2974 SSMR3GetS32(pSSM, &pThis->mouseYAbs);
2975
2976 SSMR3GetBool(pSSM, &pThis->fNewGuestFilterMask);
2977 SSMR3GetU32(pSSM, &pThis->u32NewGuestFilterMask);
2978 SSMR3GetU32(pSSM, &pThis->u32GuestFilterMask);
2979 SSMR3GetU32(pSSM, &pThis->u32HostEventFlags);
2980
2981// SSMR3GetBool(pSSM, &pThis->pVMMDevRAMR3->fHaveEvents);
2982 // here be dragons (probably)
2983 SSMR3GetMem(pSSM, &pThis->pVMMDevRAMR3->V, sizeof (pThis->pVMMDevRAMR3->V));
2984
2985 SSMR3GetMem(pSSM, &pThis->guestInfo, sizeof (pThis->guestInfo));
2986 SSMR3GetU32(pSSM, &pThis->fu32AdditionsOk);
2987 SSMR3GetU32(pSSM, &pThis->u32VideoAccelEnabled);
2988 if (uVersion > 10)
2989 SSMR3GetBool(pSSM, &pThis->displayChangeData.fGuestSentChangeEventAck);
2990
2991 rc = SSMR3GetU32(pSSM, &pThis->guestCaps);
2992
2993 /* Attributes which were temporarily introduced in r30072 */
2994 if (uVersion == 7)
2995 {
2996 uint32_t temp;
2997 SSMR3GetU32(pSSM, &temp);
2998 rc = SSMR3GetU32(pSSM, &temp);
2999 }
3000 AssertRCReturn(rc, rc);
3001
3002#ifdef VBOX_WITH_HGCM
3003 rc = vmmdevHGCMLoadState(pThis, pSSM, uVersion);
3004 AssertRCReturn(rc, rc);
3005#endif /* VBOX_WITH_HGCM */
3006
3007 if (uVersion >= 10)
3008 rc = SSMR3GetU32(pSSM, &pThis->fHostCursorRequested);
3009 AssertRCReturn(rc, rc);
3010
3011 if (uVersion > VMMDEV_SAVED_STATE_VERSION_MISSING_GUEST_INFO_2)
3012 {
3013 SSMR3GetU32(pSSM, &pThis->guestInfo2.uFullVersion);
3014 SSMR3GetU32(pSSM, &pThis->guestInfo2.uRevision);
3015 SSMR3GetU32(pSSM, &pThis->guestInfo2.fFeatures);
3016 rc = SSMR3GetStrZ(pSSM, &pThis->guestInfo2.szName[0], sizeof(pThis->guestInfo2.szName));
3017 AssertRCReturn(rc, rc);
3018 }
3019
3020 if (uVersion > VMMDEV_SAVED_STATE_VERSION_MISSING_FACILITY_STATUSES)
3021 {
3022 uint32_t cFacilityStatuses;
3023 rc = SSMR3GetU32(pSSM, &cFacilityStatuses);
3024 AssertRCReturn(rc, rc);
3025
3026 for (uint32_t i = 0; i < cFacilityStatuses; i++)
3027 {
3028 uint32_t uFacility, fFlags;
3029 uint16_t uStatus;
3030 int64_t iTimeStampNano;
3031
3032 SSMR3GetU32(pSSM, &uFacility);
3033 SSMR3GetU32(pSSM, &fFlags);
3034 SSMR3GetU16(pSSM, &uStatus);
3035 rc = SSMR3GetS64(pSSM, &iTimeStampNano);
3036 AssertRCReturn(rc, rc);
3037
3038 PVMMDEVFACILITYSTATUSENTRY pEntry = vmmdevGetFacilityStatusEntry(pThis, uFacility);
3039 AssertLogRelMsgReturn(pEntry,
3040 ("VMMDev: Ran out of entries restoring the guest facility statuses. Saved state has %u.\n", cFacilityStatuses),
3041 VERR_OUT_OF_RESOURCES);
3042 pEntry->uStatus = uStatus;
3043 pEntry->fFlags = fFlags;
3044 RTTimeSpecSetNano(&pEntry->TimeSpecTS, iTimeStampNano);
3045 }
3046 }
3047
3048
3049 /*
3050 * On a resume, we send the capabilities changed message so
3051 * that listeners can sync their state again
3052 */
3053 Log(("vmmdevLoadState: capabilities changed (%x), informing connector\n", pThis->mouseCapabilities));
3054 if (pThis->pDrv)
3055 {
3056 pThis->pDrv->pfnUpdateMouseCapabilities(pThis->pDrv, pThis->mouseCapabilities);
3057 if (uVersion >= 10)
3058 pThis->pDrv->pfnUpdatePointerShape(pThis->pDrv,
3059 /*fVisible=*/!!pThis->fHostCursorRequested,
3060 /*fAlpha=*/false,
3061 /*xHot=*/0, /*yHot=*/0,
3062 /*cx=*/0, /*cy=*/0,
3063 /*pvShape=*/NULL);
3064 }
3065
3066 /* Reestablish the acceleration status. */
3067 if ( pThis->u32VideoAccelEnabled
3068 && pThis->pDrv)
3069 {
3070 pThis->pDrv->pfnVideoAccelEnable(pThis->pDrv, !!pThis->u32VideoAccelEnabled, &pThis->pVMMDevRAMR3->vbvaMemory);
3071 }
3072
3073 if (pThis->fu32AdditionsOk)
3074 {
3075 LogRel(("Guest Additions information report: additionsVersion = 0x%08X, osType = 0x%08X\n",
3076 pThis->guestInfo.interfaceVersion,
3077 pThis->guestInfo.osType));
3078 if (pThis->pDrv)
3079 {
3080 if (pThis->guestInfo2.uFullVersion && pThis->pDrv->pfnUpdateGuestInfo2)
3081 pThis->pDrv->pfnUpdateGuestInfo2(pThis->pDrv, pThis->guestInfo2.uFullVersion, pThis->guestInfo2.szName,
3082 pThis->guestInfo2.uRevision, pThis->guestInfo2.fFeatures);
3083 if (pThis->pDrv->pfnUpdateGuestInfo)
3084 pThis->pDrv->pfnUpdateGuestInfo(pThis->pDrv, &pThis->guestInfo);
3085
3086 if (pThis->pDrv->pfnUpdateGuestStatus)
3087 {
3088 for (uint32_t i = 0; i < pThis->cFacilityStatuses; i++) /* ascending order! */
3089 if ( pThis->aFacilityStatuses[i].uStatus != VBoxGuestFacilityStatus_Inactive
3090 || !pThis->aFacilityStatuses[i].fFixed)
3091 pThis->pDrv->pfnUpdateGuestStatus(pThis->pDrv,
3092 pThis->aFacilityStatuses[i].uFacility,
3093 pThis->aFacilityStatuses[i].uStatus,
3094 pThis->aFacilityStatuses[i].fFlags,
3095 &pThis->aFacilityStatuses[i].TimeSpecTS);
3096 }
3097 }
3098 }
3099 if (pThis->pDrv && pThis->pDrv->pfnUpdateGuestCapabilities)
3100 pThis->pDrv->pfnUpdateGuestCapabilities(pThis->pDrv, pThis->guestCaps);
3101
3102 return VINF_SUCCESS;
3103}
3104
3105/**
3106 * Load state done callback. Notify guest of restore event.
3107 *
3108 * @returns VBox status code.
3109 * @param pDevIns The device instance.
3110 * @param pSSM The handle to the saved state.
3111 */
3112static DECLCALLBACK(int) vmmdevLoadStateDone(PPDMDEVINS pDevIns, PSSMHANDLE pSSM)
3113{
3114 VMMDevState *pThis = PDMINS_2_DATA(pDevIns, VMMDevState*);
3115
3116#ifdef VBOX_WITH_HGCM
3117 int rc = vmmdevHGCMLoadStateDone(pThis, pSSM);
3118 AssertLogRelRCReturn(rc, rc);
3119#endif /* VBOX_WITH_HGCM */
3120
3121 VMMDevNotifyGuest(pThis, VMMDEV_EVENT_RESTORED);
3122
3123 return VINF_SUCCESS;
3124}
3125
3126/* -=-=-=-=- PDMDEVREG -=-=-=-=- */
3127
3128/**
3129 * (Re-)initializes the MMIO2 data.
3130 *
3131 * @param pThis Pointer to the VMMDev instance data.
3132 */
3133static void vmmdevInitRam(VMMDevState *pThis)
3134{
3135 memset(pThis->pVMMDevRAMR3, 0, sizeof(VMMDevMemory));
3136 pThis->pVMMDevRAMR3->u32Size = sizeof(VMMDevMemory);
3137 pThis->pVMMDevRAMR3->u32Version = VMMDEV_MEMORY_VERSION;
3138}
3139
3140/**
3141 * Reset notification.
3142 *
3143 * @returns VBox status.
3144 * @param pDrvIns The driver instance data.
3145 */
3146static DECLCALLBACK(void) vmmdevReset(PPDMDEVINS pDevIns)
3147{
3148 VMMDevState *pThis = PDMINS_2_DATA(pDevIns, VMMDevState*);
3149
3150 /*
3151 * Reset the mouse integration feature bits
3152 */
3153 if (pThis->mouseCapabilities & VMMDEV_MOUSE_GUEST_MASK)
3154 {
3155 pThis->mouseCapabilities &= ~VMMDEV_MOUSE_GUEST_MASK;
3156 /* notify the connector */
3157 Log(("vmmdevReset: capabilities changed (%x), informing connector\n", pThis->mouseCapabilities));
3158 pThis->pDrv->pfnUpdateMouseCapabilities(pThis->pDrv, pThis->mouseCapabilities);
3159 }
3160 pThis->fHostCursorRequested = false;
3161
3162 pThis->hypervisorSize = 0;
3163
3164 /* re-initialize the VMMDev memory */
3165 if (pThis->pVMMDevRAMR3)
3166 vmmdevInitRam(pThis);
3167
3168 /* credentials have to go away (by default) */
3169 if (!pThis->fKeepCredentials)
3170 {
3171 memset(pThis->pCredentials->Logon.szUserName, '\0', VMMDEV_CREDENTIALS_SZ_SIZE);
3172 memset(pThis->pCredentials->Logon.szPassword, '\0', VMMDEV_CREDENTIALS_SZ_SIZE);
3173 memset(pThis->pCredentials->Logon.szDomain, '\0', VMMDEV_CREDENTIALS_SZ_SIZE);
3174 }
3175 memset(pThis->pCredentials->Judge.szUserName, '\0', VMMDEV_CREDENTIALS_SZ_SIZE);
3176 memset(pThis->pCredentials->Judge.szPassword, '\0', VMMDEV_CREDENTIALS_SZ_SIZE);
3177 memset(pThis->pCredentials->Judge.szDomain, '\0', VMMDEV_CREDENTIALS_SZ_SIZE);
3178
3179 /* Reset means that additions will report again. */
3180 const bool fVersionChanged = pThis->fu32AdditionsOk
3181 || pThis->guestInfo.interfaceVersion
3182 || pThis->guestInfo.osType != VBOXOSTYPE_Unknown;
3183 if (fVersionChanged)
3184 Log(("vmmdevReset: fu32AdditionsOk=%d additionsVersion=%x osType=%#x\n",
3185 pThis->fu32AdditionsOk, pThis->guestInfo.interfaceVersion, pThis->guestInfo.osType));
3186 pThis->fu32AdditionsOk = false;
3187 memset (&pThis->guestInfo, 0, sizeof (pThis->guestInfo));
3188 RT_ZERO(pThis->guestInfo2);
3189
3190 /* Clear facilities. No need to tell Main as it will get a
3191 pfnUpdateGuestInfo callback. */
3192 RTTIMESPEC TimeStampNow;
3193 RTTimeNow(&TimeStampNow);
3194 uint32_t iFacility = pThis->cFacilityStatuses;
3195 while (iFacility-- > 0)
3196 {
3197 pThis->aFacilityStatuses[iFacility].uStatus = VBoxGuestFacilityStatus_Inactive;
3198 pThis->aFacilityStatuses[iFacility].TimeSpecTS = TimeStampNow;
3199 }
3200
3201 /* clear pending display change request. */
3202 for (unsigned i = 0; i < RT_ELEMENTS(pThis->displayChangeData.aRequests); i++)
3203 {
3204 DISPLAYCHANGEREQUEST *pRequest = &pThis->displayChangeData.aRequests[i];
3205 memset (&pRequest->lastReadDisplayChangeRequest, 0, sizeof (pRequest->lastReadDisplayChangeRequest));
3206 }
3207 pThis->displayChangeData.iCurrentMonitor = 0;
3208 pThis->displayChangeData.fGuestSentChangeEventAck = false;
3209
3210 /* disable seamless mode */
3211 pThis->fLastSeamlessEnabled = false;
3212
3213 /* disabled memory ballooning */
3214 pThis->u32LastMemoryBalloonSize = 0;
3215
3216 /* disabled statistics updating */
3217 pThis->u32LastStatIntervalSize = 0;
3218
3219 /* Clear the "HGCM event enabled" flag so the event can be automatically reenabled. */
3220 pThis->u32HGCMEnabled = 0;
3221
3222 /*
3223 * Clear the event variables.
3224 *
3225 * XXX By design we should NOT clear pThis->u32HostEventFlags because it is designed
3226 * that way so host events do not depend on guest resets. However, the pending
3227 * event flags actually _were_ cleared since ages so we mask out events from
3228 * clearing which we really need to survive the reset. See xtracker 5767.
3229 */
3230 pThis->u32HostEventFlags &= VMMDEV_EVENT_DISPLAY_CHANGE_REQUEST;
3231 pThis->u32GuestFilterMask = 0;
3232 pThis->u32NewGuestFilterMask = 0;
3233 pThis->fNewGuestFilterMask = 0;
3234
3235 /* This is the default, as Windows and OS/2 guests take this for granted. (Actually, neither does...) */
3236 /** @todo change this when we next bump the interface version */
3237 const bool fCapsChanged = pThis->guestCaps != VMMDEV_GUEST_SUPPORTS_GRAPHICS;
3238 if (fCapsChanged)
3239 Log(("vmmdevReset: fCapsChanged=%#x -> %#x\n", pThis->guestCaps, VMMDEV_GUEST_SUPPORTS_GRAPHICS));
3240 pThis->guestCaps = VMMDEV_GUEST_SUPPORTS_GRAPHICS; /** @todo r=bird: why? I cannot see this being done at construction?*/
3241
3242 /*
3243 * Call the update functions as required.
3244 */
3245 if (fVersionChanged && pThis->pDrv && pThis->pDrv->pfnUpdateGuestInfo)
3246 pThis->pDrv->pfnUpdateGuestInfo(pThis->pDrv, &pThis->guestInfo);
3247 if (fCapsChanged && pThis->pDrv && pThis->pDrv->pfnUpdateGuestCapabilities)
3248 pThis->pDrv->pfnUpdateGuestCapabilities(pThis->pDrv, pThis->guestCaps);
3249
3250 /* Generate a unique session id for this VM; it will be changed for each start, reset or restore.
3251 * This can be used for restore detection inside the guest.
3252 */
3253 pThis->idSession = ASMReadTSC();
3254}
3255
3256
3257/**
3258 * @interface_method_impl{PDMDEVREG,pfnRelocate}
3259 */
3260static DECLCALLBACK(void) vmmdevRelocate(PPDMDEVINS pDevIns, RTGCINTPTR offDelta)
3261{
3262 NOREF(pDevIns);
3263 NOREF(offDelta);
3264}
3265
3266
3267/**
3268 * @interface_method_impl{PDMDEVREG,pfnDestruct}
3269 */
3270static DECLCALLBACK(int) vmmdevDestroy(PPDMDEVINS pDevIns)
3271{
3272 PDMDEV_CHECK_VERSIONS_RETURN(pDevIns);
3273 VMMDevState *pThis = PDMINS_2_DATA(pDevIns, VMMDevState *);
3274
3275 /*
3276 * Wipe and free the credentials.
3277 */
3278 if (pThis->pCredentials)
3279 {
3280 RTMemWipeThoroughly(pThis->pCredentials, sizeof(*pThis->pCredentials), 10);
3281 RTMemFree(pThis->pCredentials);
3282 pThis->pCredentials = NULL;
3283 }
3284
3285 return VINF_SUCCESS;
3286}
3287
3288
3289/**
3290 * @interface_method_impl{PDMDEVREG,pfnConstruct}
3291 */
3292static DECLCALLBACK(int) vmmdevConstruct(PPDMDEVINS pDevIns, int iInstance, PCFGMNODE pCfg)
3293{
3294 int rc;
3295 VMMDevState *pThis = PDMINS_2_DATA(pDevIns, VMMDevState *);
3296
3297 Assert(iInstance == 0);
3298 PDMDEV_CHECK_VERSIONS_RETURN(pDevIns);
3299
3300 /*
3301 * Initialize data (most of it anyway).
3302 */
3303 /* Save PDM device instance data for future reference. */
3304 pThis->pDevIns = pDevIns;
3305
3306 /* PCI vendor, just a free bogus value */
3307 PCIDevSetVendorId(&pThis->dev, 0x80ee);
3308 /* device ID */
3309 PCIDevSetDeviceId(&pThis->dev, 0xcafe);
3310 /* class sub code (other type of system peripheral) */
3311 PCIDevSetClassSub(&pThis->dev, 0x80);
3312 /* class base code (base system peripheral) */
3313 PCIDevSetClassBase(&pThis->dev, 0x08);
3314 /* header type */
3315 PCIDevSetHeaderType(&pThis->dev, 0x00);
3316 /* interrupt on pin 0 */
3317 PCIDevSetInterruptPin(&pThis->dev, 0x01);
3318
3319 RTTIMESPEC TimeStampNow;
3320 RTTimeNow(&TimeStampNow);
3321 vmmdevAllocFacilityStatusEntry(pThis, VBoxGuestFacilityType_VBoxGuestDriver, true /*fFixed*/, &TimeStampNow);
3322 vmmdevAllocFacilityStatusEntry(pThis, VBoxGuestFacilityType_VBoxService, true /*fFixed*/, &TimeStampNow);
3323 vmmdevAllocFacilityStatusEntry(pThis, VBoxGuestFacilityType_VBoxTrayClient, true /*fFixed*/, &TimeStampNow);
3324 vmmdevAllocFacilityStatusEntry(pThis, VBoxGuestFacilityType_Seamless, true /*fFixed*/, &TimeStampNow);
3325 vmmdevAllocFacilityStatusEntry(pThis, VBoxGuestFacilityType_Graphics, true /*fFixed*/, &TimeStampNow);
3326 Assert(pThis->cFacilityStatuses == 5);
3327
3328 /*
3329 * Interfaces
3330 */
3331 /* IBase */
3332 pThis->IBase.pfnQueryInterface = vmmdevPortQueryInterface;
3333
3334 /* VMMDev port */
3335 pThis->IPort.pfnQueryAbsoluteMouse = vmmdevQueryAbsoluteMouse;
3336 pThis->IPort.pfnSetAbsoluteMouse = vmmdevSetAbsoluteMouse;
3337 pThis->IPort.pfnQueryMouseCapabilities = vmmdevQueryMouseCapabilities;
3338 pThis->IPort.pfnUpdateMouseCapabilities = vmmdevUpdateMouseCapabilities;
3339 pThis->IPort.pfnRequestDisplayChange = vmmdevRequestDisplayChange;
3340 pThis->IPort.pfnSetCredentials = vmmdevSetCredentials;
3341 pThis->IPort.pfnVBVAChange = vmmdevVBVAChange;
3342 pThis->IPort.pfnRequestSeamlessChange = vmmdevRequestSeamlessChange;
3343 pThis->IPort.pfnSetMemoryBalloon = vmmdevSetMemoryBalloon;
3344 pThis->IPort.pfnSetStatisticsInterval = vmmdevSetStatisticsInterval;
3345 pThis->IPort.pfnVRDPChange = vmmdevVRDPChange;
3346 pThis->IPort.pfnCpuHotUnplug = vmmdevCpuHotUnplug;
3347 pThis->IPort.pfnCpuHotPlug = vmmdevCpuHotPlug;
3348
3349 /* Shared folder LED */
3350 pThis->SharedFolders.Led.u32Magic = PDMLED_MAGIC;
3351 pThis->SharedFolders.ILeds.pfnQueryStatusLed = vmmdevQueryStatusLed;
3352
3353#ifdef VBOX_WITH_HGCM
3354 /* HGCM port */
3355 pThis->IHGCMPort.pfnCompleted = hgcmCompleted;
3356#endif
3357
3358 pThis->pCredentials = (VMMDEVCREDS *)RTMemAllocZ(sizeof(*pThis->pCredentials));
3359 if (!pThis->pCredentials)
3360 return VERR_NO_MEMORY;
3361
3362
3363 /*
3364 * Validate and read the configuration.
3365 */
3366 PDMDEV_VALIDATE_CONFIG_RETURN(pDevIns,
3367 "GetHostTimeDisabled|"
3368 "BackdoorLogDisabled|"
3369 "KeepCredentials|"
3370 "HeapEnabled|"
3371 "RamSize|"
3372 "RZEnabled|"
3373 "GuestCoreDumpEnabled|"
3374 "GuestCoreDumpDir|"
3375 "GuestCoreDumpCount|"
3376 "TestingEnabled"
3377 ,
3378 "");
3379
3380 rc = CFGMR3QueryU64(pCfg, "RamSize", &pThis->cbGuestRAM);
3381 if (RT_FAILURE(rc))
3382 return PDMDEV_SET_ERROR(pDevIns, rc,
3383 N_("Configuration error: Failed querying \"RamSize\" as a 64-bit unsigned integer"));
3384
3385 rc = CFGMR3QueryBoolDef(pCfg, "GetHostTimeDisabled", &pThis->fGetHostTimeDisabled, false);
3386 if (RT_FAILURE(rc))
3387 return PDMDEV_SET_ERROR(pDevIns, rc,
3388 N_("Configuration error: Failed querying \"GetHostTimeDisabled\" as a boolean"));
3389
3390 rc = CFGMR3QueryBoolDef(pCfg, "BackdoorLogDisabled", &pThis->fBackdoorLogDisabled, false);
3391 if (RT_FAILURE(rc))
3392 return PDMDEV_SET_ERROR(pDevIns, rc,
3393 N_("Configuration error: Failed querying \"BackdoorLogDisabled\" as a boolean"));
3394
3395 rc = CFGMR3QueryBoolDef(pCfg, "KeepCredentials", &pThis->fKeepCredentials, false);
3396 if (RT_FAILURE(rc))
3397 return PDMDEV_SET_ERROR(pDevIns, rc,
3398 N_("Configuration error: Failed querying \"KeepCredentials\" as a boolean"));
3399
3400 rc = CFGMR3QueryBoolDef(pCfg, "HeapEnabled", &pThis->fHeapEnabled, true);
3401 if (RT_FAILURE(rc))
3402 return PDMDEV_SET_ERROR(pDevIns, rc,
3403 N_("Configuration error: Failed querying \"HeapEnabled\" as a boolean"));
3404
3405 rc = CFGMR3QueryBoolDef(pCfg, "RZEnabled", &pThis->fRZEnabled, true);
3406 if (RT_FAILURE(rc))
3407 return PDMDEV_SET_ERROR(pDevIns, rc,
3408 N_("Configuration error: Failed querying \"RZEnabled\" as a boolean"));
3409
3410 rc = CFGMR3QueryBoolDef(pCfg, "GuestCoreDumpEnabled", &pThis->fGuestCoreDumpEnabled, false);
3411 if (RT_FAILURE(rc))
3412 return PDMDEV_SET_ERROR(pDevIns, rc,
3413 N_("Configuration error: Failed querying \"GuestCoreDumpEnabled\" as a boolean"));
3414
3415 char *pszGuestCoreDumpDir = NULL;
3416 rc = CFGMR3QueryStringAllocDef(pCfg, "GuestCoreDumpDir", &pszGuestCoreDumpDir, "");
3417 if (RT_FAILURE(rc))
3418 return PDMDEV_SET_ERROR(pDevIns, rc,
3419 N_("Configuration error: Failed querying \"GuestCoreDumpDir\" as a string"));
3420
3421 RTStrCopy(pThis->szGuestCoreDumpDir, sizeof(pThis->szGuestCoreDumpDir), pszGuestCoreDumpDir);
3422 MMR3HeapFree(pszGuestCoreDumpDir);
3423
3424 rc = CFGMR3QueryU32Def(pCfg, "GuestCoreDumpCount", &pThis->cGuestCoreDumps, 3);
3425 if (RT_FAILURE(rc))
3426 return PDMDEV_SET_ERROR(pDevIns, rc,
3427 N_("Configuration error: Failed querying \"GuestCoreDumpCount\" as a 32-bit unsigned integer"));
3428
3429#ifndef VBOX_WITHOUT_TESTING_FEATURES
3430 rc = CFGMR3QueryBoolDef(pCfg, "TestingEnabled", &pThis->fTestingEnabled, false);
3431 if (RT_FAILURE(rc))
3432 return PDMDEV_SET_ERROR(pDevIns, rc,
3433 N_("Configuration error: Failed querying \"TestingEnabled\" as a boolean"));
3434 /** @todo image-to-load-filename? */
3435#endif
3436
3437 /*
3438 * Create the critical section for the device.
3439 */
3440 rc = PDMDevHlpCritSectInit(pDevIns, &pThis->CritSect, RT_SRC_POS, "VMMDev#u", iInstance);
3441 AssertRCReturn(rc, rc);
3442 /* Later: pDevIns->pCritSectR3 = &pThis->CritSect; */
3443
3444 /*
3445 * Register the backdoor logging port
3446 */
3447 rc = PDMDevHlpIOPortRegister(pDevIns, RTLOG_DEBUG_PORT, 1, NULL, vmmdevBackdoorLog, NULL, NULL, NULL, "VMMDev backdoor logging");
3448 AssertRCReturn(rc, rc);
3449
3450#ifdef TIMESYNC_BACKDOOR
3451 /*
3452 * Alternative timesync source (temporary!)
3453 */
3454 rc = PDMDevHlpIOPortRegister(pDevIns, 0x505, 1, NULL, vmmdevTimesyncBackdoorWrite, vmmdevTimesyncBackdoorRead, NULL, NULL, "VMMDev timesync backdoor");
3455 AssertRCReturn(rc, rc);
3456#endif
3457
3458 /*
3459 * Allocate and initialize the MMIO2 memory.
3460 */
3461 rc = PDMDevHlpMMIO2Register(pDevIns, 1 /*iRegion*/, VMMDEV_RAM_SIZE, 0 /*fFlags*/, (void **)&pThis->pVMMDevRAMR3, "VMMDev");
3462 if (RT_FAILURE(rc))
3463 return PDMDevHlpVMSetError(pDevIns, rc, RT_SRC_POS,
3464 N_("Failed to allocate %u bytes of memory for the VMM device"), VMMDEV_RAM_SIZE);
3465 vmmdevInitRam(pThis);
3466
3467 if (pThis->fHeapEnabled)
3468 {
3469 rc = PDMDevHlpMMIO2Register(pDevIns, 2 /*iRegion*/, VMMDEV_HEAP_SIZE, 0 /*fFlags*/, (void **)&pThis->pVMMDevHeapR3, "VMMDev Heap");
3470 if (RT_FAILURE(rc))
3471 return PDMDevHlpVMSetError(pDevIns, rc, RT_SRC_POS,
3472 N_("Failed to allocate %u bytes of memory for the VMM device heap"), PAGE_SIZE);
3473 }
3474
3475 /*
3476 * Register the PCI device.
3477 */
3478 rc = PDMDevHlpPCIRegister(pDevIns, &pThis->dev);
3479 if (RT_FAILURE(rc))
3480 return rc;
3481 if (pThis->dev.devfn != 32 || iInstance != 0)
3482 Log(("!!WARNING!!: pThis->dev.devfn=%d (ignore if testcase or no started by Main)\n", pThis->dev.devfn));
3483 rc = PDMDevHlpPCIIORegionRegister(pDevIns, 0, 0x20, PCI_ADDRESS_SPACE_IO, vmmdevIOPortRegionMap);
3484 if (RT_FAILURE(rc))
3485 return rc;
3486 rc = PDMDevHlpPCIIORegionRegister(pDevIns, 1, VMMDEV_RAM_SIZE, PCI_ADDRESS_SPACE_MEM, vmmdevIORAMRegionMap);
3487 if (RT_FAILURE(rc))
3488 return rc;
3489 if (pThis->fHeapEnabled)
3490 {
3491 rc = PDMDevHlpPCIIORegionRegister(pDevIns, 2, VMMDEV_HEAP_SIZE, PCI_ADDRESS_SPACE_MEM_PREFETCH, vmmdevIORAMRegionMap);
3492 if (RT_FAILURE(rc))
3493 return rc;
3494 }
3495
3496#ifndef VBOX_WITHOUT_TESTING_FEATURES
3497 /*
3498 * Initialize testing.
3499 */
3500 rc = vmmdevTestingInitialize(pDevIns);
3501 if (RT_FAILURE(rc))
3502 return rc;
3503#endif
3504
3505 /*
3506 * Get the corresponding connector interface
3507 */
3508 rc = PDMDevHlpDriverAttach(pDevIns, 0, &pThis->IBase, &pThis->pDrvBase, "VMM Driver Port");
3509 if (RT_SUCCESS(rc))
3510 {
3511 pThis->pDrv = PDMIBASE_QUERY_INTERFACE(pThis->pDrvBase, PDMIVMMDEVCONNECTOR);
3512 AssertMsgReturn(pThis->pDrv, ("LUN #0 doesn't have a VMMDev connector interface!\n"), VERR_PDM_MISSING_INTERFACE);
3513#ifdef VBOX_WITH_HGCM
3514 pThis->pHGCMDrv = PDMIBASE_QUERY_INTERFACE(pThis->pDrvBase, PDMIHGCMCONNECTOR);
3515 if (!pThis->pHGCMDrv)
3516 {
3517 Log(("LUN #0 doesn't have a HGCM connector interface, HGCM is not supported. rc=%Rrc\n", rc));
3518 /* this is not actually an error, just means that there is no support for HGCM */
3519 }
3520#endif
3521 /* Query the initial balloon size. */
3522 AssertPtr(pThis->pDrv->pfnQueryBalloonSize);
3523 rc = pThis->pDrv->pfnQueryBalloonSize(pThis->pDrv, &pThis->u32MemoryBalloonSize);
3524 AssertRC(rc);
3525
3526 Log(("Initial balloon size %x\n", pThis->u32MemoryBalloonSize));
3527 }
3528 else if (rc == VERR_PDM_NO_ATTACHED_DRIVER)
3529 {
3530 Log(("%s/%d: warning: no driver attached to LUN #0!\n", pDevIns->pReg->szName, pDevIns->iInstance));
3531 rc = VINF_SUCCESS;
3532 }
3533 else
3534 AssertMsgFailedReturn(("Failed to attach LUN #0! rc=%Rrc\n", rc), rc);
3535
3536 /*
3537 * Attach status driver for shared folders (optional).
3538 */
3539 PPDMIBASE pBase;
3540 rc = PDMDevHlpDriverAttach(pDevIns, PDM_STATUS_LUN, &pThis->IBase, &pBase, "Status Port");
3541 if (RT_SUCCESS(rc))
3542 pThis->SharedFolders.pLedsConnector = PDMIBASE_QUERY_INTERFACE(pBase, PDMILEDCONNECTORS);
3543 else if (rc != VERR_PDM_NO_ATTACHED_DRIVER)
3544 {
3545 AssertMsgFailed(("Failed to attach to status driver. rc=%Rrc\n", rc));
3546 return rc;
3547 }
3548
3549 /*
3550 * Register saved state and init the HGCM CmdList critsect.
3551 */
3552 rc = PDMDevHlpSSMRegisterEx(pDevIns, VMMDEV_SAVED_STATE_VERSION, sizeof(*pThis), NULL,
3553 NULL, vmmdevLiveExec, NULL,
3554 NULL, vmmdevSaveExec, NULL,
3555 NULL, vmmdevLoadExec, vmmdevLoadStateDone);
3556 AssertRCReturn(rc, rc);
3557
3558#ifdef VBOX_WITH_HGCM
3559 pThis->pHGCMCmdList = NULL;
3560 rc = RTCritSectInit(&pThis->critsectHGCMCmdList);
3561 AssertRCReturn(rc, rc);
3562 pThis->u32HGCMEnabled = 0;
3563#endif /* VBOX_WITH_HGCM */
3564
3565 /* In this version of VirtualBox the GUI checks whether "needs host cursor"
3566 * changes. */
3567 pThis->mouseCapabilities |= VMMDEV_MOUSE_HOST_RECHECKS_NEEDS_HOST_CURSOR;
3568
3569 PDMDevHlpSTAMRegisterF(pDevIns, &pThis->StatMemBalloonChunks, STAMTYPE_U32, STAMVISIBILITY_ALWAYS, STAMUNIT_COUNT, "Memory balloon size", "/Devices/VMMDev/BalloonChunks");
3570
3571 /* Generate a unique session id for this VM; it will be changed for each start, reset or restore.
3572 * This can be used for restore detection inside the guest.
3573 */
3574 pThis->idSession = ASMReadTSC();
3575 return rc;
3576}
3577
3578/**
3579 * The device registration structure.
3580 */
3581extern "C" const PDMDEVREG g_DeviceVMMDev =
3582{
3583 /* u32Version */
3584 PDM_DEVREG_VERSION,
3585 /* szName */
3586 "VMMDev",
3587 /* szRCMod */
3588 "VBoxDDGC.gc",
3589 /* szR0Mod */
3590 "VBoxDDR0.r0",
3591 /* pszDescription */
3592 "VirtualBox VMM Device\n",
3593 /* fFlags */
3594 PDM_DEVREG_FLAGS_HOST_BITS_DEFAULT | PDM_DEVREG_FLAGS_GUEST_BITS_DEFAULT | PDM_DEVREG_FLAGS_RC | PDM_DEVREG_FLAGS_R0,
3595 /* fClass */
3596 PDM_DEVREG_CLASS_VMM_DEV,
3597 /* cMaxInstances */
3598 1,
3599 /* cbInstance */
3600 sizeof(VMMDevState),
3601 /* pfnConstruct */
3602 vmmdevConstruct,
3603 /* pfnDestruct */
3604 NULL,
3605 /* pfnRelocate */
3606 vmmdevRelocate,
3607 /* pfnIOCtl */
3608 NULL,
3609 /* pfnPowerOn */
3610 NULL,
3611 /* pfnReset */
3612 vmmdevReset,
3613 /* pfnSuspend */
3614 NULL,
3615 /* pfnResume */
3616 NULL,
3617 /* pfnAttach */
3618 NULL,
3619 /* pfnDetach */
3620 NULL,
3621 /* pfnQueryInterface. */
3622 NULL,
3623 /* pfnInitComplete */
3624 NULL,
3625 /* pfnPowerOff */
3626 NULL,
3627 /* pfnSoftReset */
3628 NULL,
3629 /* u32VersionEnd */
3630 PDM_DEVREG_VERSION
3631};
3632#endif /* !VBOX_DEVICE_STRUCT_TESTCASE */
Note: See TracBrowser for help on using the repository browser.

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