VirtualBox

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

Last change on this file since 42055 was 40054, checked in by vboxsync, 13 years ago

VMM,VMMDev: Page sharing cleanup.

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