VirtualBox

source: vbox/trunk/src/VBox/Main/src-client/VMMDevInterface.cpp@ 79361

Last change on this file since 79361 was 79263, checked in by vboxsync, 5 years ago

Main/VMMDevInterface.cpp: Don't crash in VMMDev::hgcmShutdown if it's called after a very early vm creation failure, like if the config constructor fails.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 41.3 KB
Line 
1/* $Id: VMMDevInterface.cpp 79263 2019-06-20 20:34:08Z vboxsync $ */
2/** @file
3 * VirtualBox Driver Interface to VMM device.
4 */
5
6/*
7 * Copyright (C) 2006-2019 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 */
17
18#define LOG_GROUP LOG_GROUP_MAIN_VMMDEVINTERFACES
19#include "LoggingNew.h"
20
21#include "VMMDev.h"
22#include "ConsoleImpl.h"
23#include "DisplayImpl.h"
24#include "GuestImpl.h"
25#include "MouseImpl.h"
26
27#include <VBox/vmm/pdmdrv.h>
28#include <VBox/VMMDev.h>
29#include <VBox/shflsvc.h>
30#include <iprt/asm.h>
31
32#ifdef VBOX_WITH_HGCM
33# include "HGCM.h"
34# include "HGCMObjects.h"
35# if defined(RT_OS_DARWIN) && defined(VBOX_WITH_CROGL)
36# include <VBox/HostServices/VBoxCrOpenGLSvc.h>
37# endif
38#endif
39
40//
41// defines
42//
43
44#ifdef RT_OS_OS2
45# define VBOXSHAREDFOLDERS_DLL "VBoxSFld"
46#else
47# define VBOXSHAREDFOLDERS_DLL "VBoxSharedFolders"
48#endif
49
50//
51// globals
52//
53
54
55/**
56 * VMMDev driver instance data.
57 */
58typedef struct DRVMAINVMMDEV
59{
60 /** Pointer to the VMMDev object. */
61 VMMDev *pVMMDev;
62 /** Pointer to the driver instance structure. */
63 PPDMDRVINS pDrvIns;
64 /** Pointer to the VMMDev port interface of the driver/device above us. */
65 PPDMIVMMDEVPORT pUpPort;
66 /** Our VMM device connector interface. */
67 PDMIVMMDEVCONNECTOR Connector;
68
69#ifdef VBOX_WITH_HGCM
70 /** Pointer to the HGCM port interface of the driver/device above us. */
71 PPDMIHGCMPORT pHGCMPort;
72 /** Our HGCM connector interface. */
73 PDMIHGCMCONNECTOR HGCMConnector;
74#endif
75
76#ifdef VBOX_WITH_GUEST_PROPS
77 HGCMSVCEXTHANDLE hHgcmSvcExtGstProps;
78#endif
79#ifdef VBOX_WITH_GUEST_CONTROL
80 HGCMSVCEXTHANDLE hHgcmSvcExtGstCtrl;
81#endif
82} DRVMAINVMMDEV, *PDRVMAINVMMDEV;
83
84//
85// constructor / destructor
86//
87VMMDev::VMMDev(Console *console)
88 : mpDrv(NULL)
89 , mParent(console)
90{
91 int rc = RTSemEventCreate(&mCredentialsEvent);
92 AssertRC(rc);
93#ifdef VBOX_WITH_HGCM
94 rc = HGCMHostInit();
95 AssertRC(rc);
96 m_fHGCMActive = true;
97#endif /* VBOX_WITH_HGCM */
98 mu32CredentialsFlags = 0;
99}
100
101VMMDev::~VMMDev()
102{
103#ifdef VBOX_WITH_HGCM
104 if (ASMAtomicCmpXchgBool(&m_fHGCMActive, false, true))
105 HGCMHostShutdown(true /*fUvmIsInvalid*/);
106#endif
107 RTSemEventDestroy(mCredentialsEvent);
108 if (mpDrv)
109 mpDrv->pVMMDev = NULL;
110 mpDrv = NULL;
111}
112
113PPDMIVMMDEVPORT VMMDev::getVMMDevPort()
114{
115 if (!mpDrv)
116 return NULL;
117 return mpDrv->pUpPort;
118}
119
120
121
122//
123// public methods
124//
125
126/**
127 * Wait on event semaphore for guest credential judgement result.
128 */
129int VMMDev::WaitCredentialsJudgement(uint32_t u32Timeout, uint32_t *pu32CredentialsFlags)
130{
131 if (u32Timeout == 0)
132 {
133 u32Timeout = 5000;
134 }
135
136 int rc = RTSemEventWait(mCredentialsEvent, u32Timeout);
137
138 if (RT_SUCCESS(rc))
139 {
140 *pu32CredentialsFlags = mu32CredentialsFlags;
141 }
142
143 return rc;
144}
145
146int VMMDev::SetCredentialsJudgementResult(uint32_t u32Flags)
147{
148 mu32CredentialsFlags = u32Flags;
149
150 int rc = RTSemEventSignal(mCredentialsEvent);
151 AssertRC(rc);
152
153 return rc;
154}
155
156
157/**
158 * @interface_method_impl{PDMIVMMDEVCONNECTOR,pfnUpdateGuestStatus}
159 */
160DECLCALLBACK(void) vmmdevUpdateGuestStatus(PPDMIVMMDEVCONNECTOR pInterface, uint32_t uFacility, uint16_t uStatus,
161 uint32_t fFlags, PCRTTIMESPEC pTimeSpecTS)
162{
163 PDRVMAINVMMDEV pDrv = RT_FROM_MEMBER(pInterface, DRVMAINVMMDEV, Connector);
164 Console *pConsole = pDrv->pVMMDev->getParent();
165
166 /* Store that information in IGuest */
167 Guest* guest = pConsole->i_getGuest();
168 AssertPtrReturnVoid(guest);
169
170 guest->i_setAdditionsStatus((VBoxGuestFacilityType)uFacility, (VBoxGuestFacilityStatus)uStatus, fFlags, pTimeSpecTS);
171 pConsole->i_onAdditionsStateChange();
172}
173
174
175/**
176 * @interface_method_impl{PDMIVMMDEVCONNECTOR,pfnUpdateGuestUserState}
177 */
178DECLCALLBACK(void) vmmdevUpdateGuestUserState(PPDMIVMMDEVCONNECTOR pInterface,
179 const char *pszUser, const char *pszDomain,
180 uint32_t uState,
181 const uint8_t *pabDetails, uint32_t cbDetails)
182{
183 PDRVMAINVMMDEV pDrv = RT_FROM_MEMBER(pInterface, DRVMAINVMMDEV, Connector);
184 AssertPtr(pDrv);
185 Console *pConsole = pDrv->pVMMDev->getParent();
186 AssertPtr(pConsole);
187
188 /* Store that information in IGuest. */
189 Guest* pGuest = pConsole->i_getGuest();
190 AssertPtrReturnVoid(pGuest);
191
192 pGuest->i_onUserStateChange(Bstr(pszUser), Bstr(pszDomain), (VBoxGuestUserState)uState,
193 pabDetails, cbDetails);
194}
195
196
197/**
198 * Reports Guest Additions API and OS version.
199 *
200 * Called whenever the Additions issue a guest version report request or the VM
201 * is reset.
202 *
203 * @param pInterface Pointer to this interface.
204 * @param guestInfo Pointer to guest information structure.
205 * @thread The emulation thread.
206 */
207DECLCALLBACK(void) vmmdevUpdateGuestInfo(PPDMIVMMDEVCONNECTOR pInterface, const VBoxGuestInfo *guestInfo)
208{
209 AssertPtrReturnVoid(guestInfo);
210
211 PDRVMAINVMMDEV pDrv = RT_FROM_MEMBER(pInterface, DRVMAINVMMDEV, Connector);
212 Console *pConsole = pDrv->pVMMDev->getParent();
213
214 /* Store that information in IGuest */
215 Guest* guest = pConsole->i_getGuest();
216 AssertPtrReturnVoid(guest);
217
218 if (guestInfo->interfaceVersion != 0)
219 {
220 char version[16];
221 RTStrPrintf(version, sizeof(version), "%d", guestInfo->interfaceVersion);
222 guest->i_setAdditionsInfo(Bstr(version), guestInfo->osType);
223
224 /*
225 * Tell the console interface about the event
226 * so that it can notify its consumers.
227 */
228 pConsole->i_onAdditionsStateChange();
229
230 if (guestInfo->interfaceVersion < VMMDEV_VERSION)
231 pConsole->i_onAdditionsOutdated();
232 }
233 else
234 {
235 /*
236 * The guest additions was disabled because of a reset
237 * or driver unload.
238 */
239 guest->i_setAdditionsInfo(Bstr(), guestInfo->osType); /* Clear interface version + OS type. */
240 /** @todo Would be better if GuestImpl.cpp did all this in the above method call
241 * while holding down the. */
242 guest->i_setAdditionsInfo2(0, "", 0, 0); /* Clear Guest Additions version. */
243 RTTIMESPEC TimeSpecTS;
244 RTTimeNow(&TimeSpecTS);
245 guest->i_setAdditionsStatus(VBoxGuestFacilityType_All, VBoxGuestFacilityStatus_Inactive, 0 /*fFlags*/, &TimeSpecTS);
246 pConsole->i_onAdditionsStateChange();
247 }
248}
249
250/**
251 * @interface_method_impl{PDMIVMMDEVCONNECTOR,pfnUpdateGuestInfo2}
252 */
253DECLCALLBACK(void) vmmdevUpdateGuestInfo2(PPDMIVMMDEVCONNECTOR pInterface, uint32_t uFullVersion,
254 const char *pszName, uint32_t uRevision, uint32_t fFeatures)
255{
256 PDRVMAINVMMDEV pDrv = RT_FROM_MEMBER(pInterface, DRVMAINVMMDEV, Connector);
257 AssertPtr(pszName);
258 Assert(uFullVersion);
259
260 /* Store that information in IGuest. */
261 Guest *pGuest = pDrv->pVMMDev->getParent()->i_getGuest();
262 AssertPtrReturnVoid(pGuest);
263
264 /* Just pass it on... */
265 pGuest->i_setAdditionsInfo2(uFullVersion, pszName, uRevision, fFeatures);
266
267 /*
268 * No need to tell the console interface about the update;
269 * vmmdevUpdateGuestInfo takes care of that when called as the
270 * last event in the chain.
271 */
272}
273
274/**
275 * Update the guest additions capabilities.
276 * This is called when the guest additions capabilities change. The new capabilities
277 * are given and the connector should update its internal state.
278 *
279 * @param pInterface Pointer to this interface.
280 * @param newCapabilities New capabilities.
281 * @thread The emulation thread.
282 */
283DECLCALLBACK(void) vmmdevUpdateGuestCapabilities(PPDMIVMMDEVCONNECTOR pInterface, uint32_t newCapabilities)
284{
285 PDRVMAINVMMDEV pDrv = RT_FROM_MEMBER(pInterface, DRVMAINVMMDEV, Connector);
286 AssertPtr(pDrv);
287 Console *pConsole = pDrv->pVMMDev->getParent();
288
289 /* store that information in IGuest */
290 Guest* pGuest = pConsole->i_getGuest();
291 AssertPtrReturnVoid(pGuest);
292
293 /*
294 * Report our current capabilities (and assume none is active yet).
295 */
296 pGuest->i_setSupportedFeatures(newCapabilities);
297
298 /*
299 * Tell the Display, so that it can update the "supports graphics"
300 * capability if the graphics card has not asserted it.
301 */
302 Display* pDisplay = pConsole->i_getDisplay();
303 AssertPtrReturnVoid(pDisplay);
304 pDisplay->i_handleUpdateVMMDevSupportsGraphics(RT_BOOL(newCapabilities & VMMDEV_GUEST_SUPPORTS_GRAPHICS));
305
306 /*
307 * Tell the console interface about the event
308 * so that it can notify its consumers.
309 */
310 pConsole->i_onAdditionsStateChange();
311}
312
313/**
314 * Update the mouse capabilities.
315 * This is called when the mouse capabilities change. The new capabilities
316 * are given and the connector should update its internal state.
317 *
318 * @param pInterface Pointer to this interface.
319 * @param fNewCaps New capabilities.
320 * @thread The emulation thread.
321 */
322DECLCALLBACK(void) vmmdevUpdateMouseCapabilities(PPDMIVMMDEVCONNECTOR pInterface, uint32_t fNewCaps)
323{
324 PDRVMAINVMMDEV pDrv = RT_FROM_MEMBER(pInterface, DRVMAINVMMDEV, Connector);
325 Console *pConsole = pDrv->pVMMDev->getParent();
326
327 /*
328 * Tell the console interface about the event
329 * so that it can notify its consumers.
330 */
331 Mouse *pMouse = pConsole->i_getMouse();
332 if (pMouse) /** @todo and if not? Can that actually happen? */
333 pMouse->i_onVMMDevGuestCapsChange(fNewCaps & VMMDEV_MOUSE_GUEST_MASK);
334}
335
336/**
337 * Update the pointer shape or visibility.
338 *
339 * This is called when the mouse pointer shape changes or pointer is hidden/displaying.
340 * The new shape is passed as a caller allocated buffer that will be freed after returning.
341 *
342 * @param pInterface Pointer to this interface.
343 * @param fVisible Whether the pointer is visible or not.
344 * @param fAlpha Alpha channel information is present.
345 * @param xHot Horizontal coordinate of the pointer hot spot.
346 * @param yHot Vertical coordinate of the pointer hot spot.
347 * @param width Pointer width in pixels.
348 * @param height Pointer height in pixels.
349 * @param pShape The shape buffer. If NULL, then only pointer visibility is being changed.
350 * @thread The emulation thread.
351 */
352DECLCALLBACK(void) vmmdevUpdatePointerShape(PPDMIVMMDEVCONNECTOR pInterface, bool fVisible, bool fAlpha,
353 uint32_t xHot, uint32_t yHot,
354 uint32_t width, uint32_t height,
355 void *pShape)
356{
357 PDRVMAINVMMDEV pDrv = RT_FROM_MEMBER(pInterface, DRVMAINVMMDEV, Connector);
358 Console *pConsole = pDrv->pVMMDev->getParent();
359
360 /* tell the console about it */
361 uint32_t cbShape = 0;
362 if (pShape)
363 {
364 cbShape = (width + 7) / 8 * height; /* size of the AND mask */
365 cbShape = ((cbShape + 3) & ~3) + width * 4 * height; /* + gap + size of the XOR mask */
366 }
367 pConsole->i_onMousePointerShapeChange(fVisible, fAlpha, xHot, yHot, width, height, (uint8_t *)pShape, cbShape);
368}
369
370DECLCALLBACK(int) iface_VideoAccelEnable(PPDMIVMMDEVCONNECTOR pInterface, bool fEnable, VBVAMEMORY *pVbvaMemory)
371{
372 PDRVMAINVMMDEV pDrv = RT_FROM_MEMBER(pInterface, DRVMAINVMMDEV, Connector);
373 Console *pConsole = pDrv->pVMMDev->getParent();
374
375 Display *display = pConsole->i_getDisplay();
376
377 if (display)
378 {
379 Log9(("MAIN::VMMDevInterface::iface_VideoAccelEnable: %d, %p\n", fEnable, pVbvaMemory));
380 return display->VideoAccelEnableVMMDev(fEnable, pVbvaMemory);
381 }
382
383 return VERR_NOT_SUPPORTED;
384}
385DECLCALLBACK(void) iface_VideoAccelFlush(PPDMIVMMDEVCONNECTOR pInterface)
386{
387 PDRVMAINVMMDEV pDrv = RT_FROM_MEMBER(pInterface, DRVMAINVMMDEV, Connector);
388 Console *pConsole = pDrv->pVMMDev->getParent();
389
390 Display *display = pConsole->i_getDisplay();
391
392 if (display)
393 {
394 Log9(("MAIN::VMMDevInterface::iface_VideoAccelFlush\n"));
395 display->VideoAccelFlushVMMDev();
396 }
397}
398
399DECLCALLBACK(int) vmmdevVideoModeSupported(PPDMIVMMDEVCONNECTOR pInterface, uint32_t display, uint32_t width, uint32_t height,
400 uint32_t bpp, bool *fSupported)
401{
402 PDRVMAINVMMDEV pDrv = RT_FROM_MEMBER(pInterface, DRVMAINVMMDEV, Connector);
403 Console *pConsole = pDrv->pVMMDev->getParent();
404
405 if (!fSupported)
406 return VERR_INVALID_PARAMETER;
407#ifdef DEBUG_sunlover
408 Log(("vmmdevVideoModeSupported: [%d]: %dx%dx%d\n", display, width, height, bpp));
409#endif
410 IFramebuffer *framebuffer = NULL;
411 HRESULT hrc = pConsole->i_getDisplay()->QueryFramebuffer(display, &framebuffer);
412 if (SUCCEEDED(hrc) && framebuffer)
413 {
414 framebuffer->VideoModeSupported(width, height, bpp, (BOOL*)fSupported);
415 framebuffer->Release();
416 }
417 else
418 {
419#ifdef DEBUG_sunlover
420 Log(("vmmdevVideoModeSupported: hrc %x, framebuffer %p!!!\n", hrc, framebuffer));
421#endif
422 *fSupported = true;
423 }
424 return VINF_SUCCESS;
425}
426
427DECLCALLBACK(int) vmmdevGetHeightReduction(PPDMIVMMDEVCONNECTOR pInterface, uint32_t *heightReduction)
428{
429 PDRVMAINVMMDEV pDrv = RT_FROM_MEMBER(pInterface, DRVMAINVMMDEV, Connector);
430 Console *pConsole = pDrv->pVMMDev->getParent();
431
432 if (!heightReduction)
433 return VERR_INVALID_PARAMETER;
434 IFramebuffer *framebuffer = NULL;
435 HRESULT hrc = pConsole->i_getDisplay()->QueryFramebuffer(0, &framebuffer);
436 if (SUCCEEDED(hrc) && framebuffer)
437 {
438 framebuffer->COMGETTER(HeightReduction)((ULONG*)heightReduction);
439 framebuffer->Release();
440 }
441 else
442 *heightReduction = 0;
443 return VINF_SUCCESS;
444}
445
446DECLCALLBACK(int) vmmdevSetCredentialsJudgementResult(PPDMIVMMDEVCONNECTOR pInterface, uint32_t u32Flags)
447{
448 PDRVMAINVMMDEV pDrv = RT_FROM_MEMBER(pInterface, DRVMAINVMMDEV, Connector);
449
450 if (pDrv->pVMMDev)
451 return pDrv->pVMMDev->SetCredentialsJudgementResult(u32Flags);
452
453 return VERR_GENERAL_FAILURE;
454}
455
456DECLCALLBACK(int) vmmdevSetVisibleRegion(PPDMIVMMDEVCONNECTOR pInterface, uint32_t cRect, PRTRECT pRect)
457{
458 PDRVMAINVMMDEV pDrv = RT_FROM_MEMBER(pInterface, DRVMAINVMMDEV, Connector);
459 Console *pConsole = pDrv->pVMMDev->getParent();
460
461 /* Forward to Display, which calls corresponding framebuffers. */
462 pConsole->i_getDisplay()->i_handleSetVisibleRegion(cRect, pRect);
463
464 return VINF_SUCCESS;
465}
466
467DECLCALLBACK(int) vmmdevQueryVisibleRegion(PPDMIVMMDEVCONNECTOR pInterface, uint32_t *pcRects, PRTRECT paRects)
468{
469 PDRVMAINVMMDEV pDrv = RT_FROM_MEMBER(pInterface, DRVMAINVMMDEV, Connector);
470 Console *pConsole = pDrv->pVMMDev->getParent();
471
472 /* Forward to Display, which calls corresponding framebuffers. */
473 pConsole->i_getDisplay()->i_handleQueryVisibleRegion(pcRects, paRects);
474
475 return VINF_SUCCESS;
476}
477
478/**
479 * Request the statistics interval
480 *
481 * @returns VBox status code.
482 * @param pInterface Pointer to this interface.
483 * @param pulInterval Pointer to interval in seconds
484 * @thread The emulation thread.
485 */
486DECLCALLBACK(int) vmmdevQueryStatisticsInterval(PPDMIVMMDEVCONNECTOR pInterface, uint32_t *pulInterval)
487{
488 PDRVMAINVMMDEV pDrv = RT_FROM_MEMBER(pInterface, DRVMAINVMMDEV, Connector);
489 Console *pConsole = pDrv->pVMMDev->getParent();
490 ULONG val = 0;
491
492 if (!pulInterval)
493 return VERR_INVALID_POINTER;
494
495 /* store that information in IGuest */
496 Guest* guest = pConsole->i_getGuest();
497 AssertPtrReturn(guest, VERR_GENERAL_FAILURE);
498
499 guest->COMGETTER(StatisticsUpdateInterval)(&val);
500 *pulInterval = val;
501 return VINF_SUCCESS;
502}
503
504/**
505 * Query the current balloon size
506 *
507 * @returns VBox status code.
508 * @param pInterface Pointer to this interface.
509 * @param pcbBalloon Balloon size
510 * @thread The emulation thread.
511 */
512DECLCALLBACK(int) vmmdevQueryBalloonSize(PPDMIVMMDEVCONNECTOR pInterface, uint32_t *pcbBalloon)
513{
514 PDRVMAINVMMDEV pDrv = RT_FROM_MEMBER(pInterface, DRVMAINVMMDEV, Connector);
515 Console *pConsole = pDrv->pVMMDev->getParent();
516 ULONG val = 0;
517
518 if (!pcbBalloon)
519 return VERR_INVALID_POINTER;
520
521 /* store that information in IGuest */
522 Guest* guest = pConsole->i_getGuest();
523 AssertPtrReturn(guest, VERR_GENERAL_FAILURE);
524
525 guest->COMGETTER(MemoryBalloonSize)(&val);
526 *pcbBalloon = val;
527 return VINF_SUCCESS;
528}
529
530/**
531 * Query the current page fusion setting
532 *
533 * @returns VBox status code.
534 * @param pInterface Pointer to this interface.
535 * @param pfPageFusionEnabled Pointer to boolean
536 * @thread The emulation thread.
537 */
538DECLCALLBACK(int) vmmdevIsPageFusionEnabled(PPDMIVMMDEVCONNECTOR pInterface, bool *pfPageFusionEnabled)
539{
540 PDRVMAINVMMDEV pDrv = RT_FROM_MEMBER(pInterface, DRVMAINVMMDEV, Connector);
541 Console *pConsole = pDrv->pVMMDev->getParent();
542
543 if (!pfPageFusionEnabled)
544 return VERR_INVALID_POINTER;
545
546 /* store that information in IGuest */
547 Guest* guest = pConsole->i_getGuest();
548 AssertPtrReturn(guest, VERR_GENERAL_FAILURE);
549
550 *pfPageFusionEnabled = !!guest->i_isPageFusionEnabled();
551 return VINF_SUCCESS;
552}
553
554/**
555 * Report new guest statistics
556 *
557 * @returns VBox status code.
558 * @param pInterface Pointer to this interface.
559 * @param pGuestStats Guest statistics
560 * @thread The emulation thread.
561 */
562DECLCALLBACK(int) vmmdevReportStatistics(PPDMIVMMDEVCONNECTOR pInterface, VBoxGuestStatistics *pGuestStats)
563{
564 PDRVMAINVMMDEV pDrv = RT_FROM_MEMBER(pInterface, DRVMAINVMMDEV, Connector);
565 Console *pConsole = pDrv->pVMMDev->getParent();
566
567 AssertPtrReturn(pGuestStats, VERR_INVALID_POINTER);
568
569 /* store that information in IGuest */
570 Guest* guest = pConsole->i_getGuest();
571 AssertPtrReturn(guest, VERR_GENERAL_FAILURE);
572
573 if (pGuestStats->u32StatCaps & VBOX_GUEST_STAT_CPU_LOAD_IDLE)
574 guest->i_setStatistic(pGuestStats->u32CpuId, GUESTSTATTYPE_CPUIDLE, pGuestStats->u32CpuLoad_Idle);
575
576 if (pGuestStats->u32StatCaps & VBOX_GUEST_STAT_CPU_LOAD_KERNEL)
577 guest->i_setStatistic(pGuestStats->u32CpuId, GUESTSTATTYPE_CPUKERNEL, pGuestStats->u32CpuLoad_Kernel);
578
579 if (pGuestStats->u32StatCaps & VBOX_GUEST_STAT_CPU_LOAD_USER)
580 guest->i_setStatistic(pGuestStats->u32CpuId, GUESTSTATTYPE_CPUUSER, pGuestStats->u32CpuLoad_User);
581
582
583 /** @todo r=bird: Convert from 4KB to 1KB units?
584 * CollectorGuestHAL::i_getGuestMemLoad says it returns KB units to
585 * preCollect(). I might be wrong ofc, this is convoluted code... */
586 if (pGuestStats->u32StatCaps & VBOX_GUEST_STAT_PHYS_MEM_TOTAL)
587 guest->i_setStatistic(pGuestStats->u32CpuId, GUESTSTATTYPE_MEMTOTAL, pGuestStats->u32PhysMemTotal);
588
589 if (pGuestStats->u32StatCaps & VBOX_GUEST_STAT_PHYS_MEM_AVAIL)
590 guest->i_setStatistic(pGuestStats->u32CpuId, GUESTSTATTYPE_MEMFREE, pGuestStats->u32PhysMemAvail);
591
592 if (pGuestStats->u32StatCaps & VBOX_GUEST_STAT_PHYS_MEM_BALLOON)
593 guest->i_setStatistic(pGuestStats->u32CpuId, GUESTSTATTYPE_MEMBALLOON, pGuestStats->u32PhysMemBalloon);
594
595 if (pGuestStats->u32StatCaps & VBOX_GUEST_STAT_MEM_SYSTEM_CACHE)
596 guest->i_setStatistic(pGuestStats->u32CpuId, GUESTSTATTYPE_MEMCACHE, pGuestStats->u32MemSystemCache);
597
598 if (pGuestStats->u32StatCaps & VBOX_GUEST_STAT_PAGE_FILE_SIZE)
599 guest->i_setStatistic(pGuestStats->u32CpuId, GUESTSTATTYPE_PAGETOTAL, pGuestStats->u32PageFileSize);
600
601 return VINF_SUCCESS;
602}
603
604#ifdef VBOX_WITH_HGCM
605
606/* HGCM connector interface */
607
608static DECLCALLBACK(int) iface_hgcmConnect(PPDMIHGCMCONNECTOR pInterface, PVBOXHGCMCMD pCmd,
609 PHGCMSERVICELOCATION pServiceLocation,
610 uint32_t *pu32ClientID)
611{
612 Log9(("Enter\n"));
613
614 PDRVMAINVMMDEV pDrv = RT_FROM_MEMBER(pInterface, DRVMAINVMMDEV, HGCMConnector);
615
616 if ( !pServiceLocation
617 || ( pServiceLocation->type != VMMDevHGCMLoc_LocalHost
618 && pServiceLocation->type != VMMDevHGCMLoc_LocalHost_Existing))
619 {
620 return VERR_INVALID_PARAMETER;
621 }
622
623 /* Check if service name is a string terminated by zero*/
624 size_t cchInfo = 0;
625 if (RTStrNLenEx(pServiceLocation->u.host.achName, sizeof(pServiceLocation->u.host.achName), &cchInfo) != VINF_SUCCESS)
626 {
627 return VERR_INVALID_PARAMETER;
628 }
629
630 if (!pDrv->pVMMDev || !pDrv->pVMMDev->hgcmIsActive())
631 return VERR_INVALID_STATE;
632 return HGCMGuestConnect(pDrv->pHGCMPort, pCmd, pServiceLocation->u.host.achName, pu32ClientID);
633}
634
635static DECLCALLBACK(int) iface_hgcmDisconnect(PPDMIHGCMCONNECTOR pInterface, PVBOXHGCMCMD pCmd, uint32_t u32ClientID)
636{
637 Log9(("Enter\n"));
638
639 PDRVMAINVMMDEV pDrv = RT_FROM_MEMBER(pInterface, DRVMAINVMMDEV, HGCMConnector);
640
641 if (!pDrv->pVMMDev || !pDrv->pVMMDev->hgcmIsActive())
642 return VERR_INVALID_STATE;
643
644 return HGCMGuestDisconnect(pDrv->pHGCMPort, pCmd, u32ClientID);
645}
646
647static DECLCALLBACK(int) iface_hgcmCall(PPDMIHGCMCONNECTOR pInterface, PVBOXHGCMCMD pCmd, uint32_t u32ClientID,
648 uint32_t u32Function, uint32_t cParms, PVBOXHGCMSVCPARM paParms, uint64_t tsArrival)
649{
650 Log9(("Enter\n"));
651
652 PDRVMAINVMMDEV pDrv = RT_FROM_MEMBER(pInterface, DRVMAINVMMDEV, HGCMConnector);
653
654 if (!pDrv->pVMMDev || !pDrv->pVMMDev->hgcmIsActive())
655 return VERR_INVALID_STATE;
656
657 return HGCMGuestCall(pDrv->pHGCMPort, pCmd, u32ClientID, u32Function, cParms, paParms, tsArrival);
658}
659
660static DECLCALLBACK(void) iface_hgcmCancelled(PPDMIHGCMCONNECTOR pInterface, PVBOXHGCMCMD pCmd, uint32_t idClient)
661{
662 Log9(("Enter\n"));
663
664 PDRVMAINVMMDEV pDrv = RT_FROM_MEMBER(pInterface, DRVMAINVMMDEV, HGCMConnector);
665 if ( pDrv->pVMMDev
666 && pDrv->pVMMDev->hgcmIsActive())
667 return HGCMGuestCancelled(pDrv->pHGCMPort, pCmd, idClient);
668}
669
670/**
671 * Execute state save operation.
672 *
673 * @returns VBox status code.
674 * @param pDrvIns Driver instance of the driver which registered the data unit.
675 * @param pSSM SSM operation handle.
676 */
677static DECLCALLBACK(int) iface_hgcmSave(PPDMDRVINS pDrvIns, PSSMHANDLE pSSM)
678{
679 RT_NOREF(pDrvIns);
680 Log9(("Enter\n"));
681 return HGCMHostSaveState(pSSM);
682}
683
684
685/**
686 * Execute state load operation.
687 *
688 * @returns VBox status code.
689 * @param pDrvIns Driver instance of the driver which registered the data unit.
690 * @param pSSM SSM operation handle.
691 * @param uVersion Data layout version.
692 * @param uPass The data pass.
693 */
694static DECLCALLBACK(int) iface_hgcmLoad(PPDMDRVINS pDrvIns, PSSMHANDLE pSSM, uint32_t uVersion, uint32_t uPass)
695{
696 RT_NOREF(pDrvIns);
697 LogFlowFunc(("Enter\n"));
698
699 if ( uVersion != HGCM_SAVED_STATE_VERSION
700 && uVersion != HGCM_SAVED_STATE_VERSION_V2)
701 return VERR_SSM_UNSUPPORTED_DATA_UNIT_VERSION;
702 Assert(uPass == SSM_PASS_FINAL); NOREF(uPass);
703
704 return HGCMHostLoadState(pSSM, uVersion);
705}
706
707int VMMDev::hgcmLoadService(const char *pszServiceLibrary, const char *pszServiceName)
708{
709 if (!hgcmIsActive())
710 return VERR_INVALID_STATE;
711
712 /** @todo Construct all the services in the VMMDev::drvConstruct()!! */
713 Assert( (mpDrv && mpDrv->pHGCMPort)
714 || !strcmp(pszServiceLibrary, "VBoxHostChannel")
715 || !strcmp(pszServiceLibrary, "VBoxSharedClipboard")
716 || !strcmp(pszServiceLibrary, "VBoxDragAndDropSvc")
717 || !strcmp(pszServiceLibrary, "VBoxGuestPropSvc")
718 || !strcmp(pszServiceLibrary, "VBoxSharedCrOpenGL")
719 );
720 Console::SafeVMPtrQuiet ptrVM(mParent);
721 return HGCMHostLoad(pszServiceLibrary, pszServiceName, ptrVM.rawUVM(), mpDrv ? mpDrv->pHGCMPort : NULL);
722}
723
724int VMMDev::hgcmHostCall(const char *pszServiceName, uint32_t u32Function,
725 uint32_t cParms, PVBOXHGCMSVCPARM paParms)
726{
727 if (!hgcmIsActive())
728 return VERR_INVALID_STATE;
729 return HGCMHostCall(pszServiceName, u32Function, cParms, paParms);
730}
731
732/**
733 * Used by Console::i_powerDown to shut down the services before the VM is destroyed.
734 */
735void VMMDev::hgcmShutdown(bool fUvmIsInvalid /*= false*/)
736{
737#ifdef VBOX_WITH_GUEST_PROPS
738 if (mpDrv && mpDrv->hHgcmSvcExtGstProps)
739 {
740 HGCMHostUnregisterServiceExtension(mpDrv->hHgcmSvcExtGstProps);
741 mpDrv->hHgcmSvcExtGstProps = NULL;
742 }
743#endif
744
745#ifdef VBOX_WITH_GUEST_CONTROL
746 if (mpDrv && mpDrv->hHgcmSvcExtGstCtrl)
747 {
748 HGCMHostUnregisterServiceExtension(mpDrv->hHgcmSvcExtGstCtrl);
749 mpDrv->hHgcmSvcExtGstCtrl = NULL;
750 }
751#endif
752
753 if (ASMAtomicCmpXchgBool(&m_fHGCMActive, false, true))
754 HGCMHostShutdown(fUvmIsInvalid);
755}
756
757# ifdef VBOX_WITH_CRHGSMI
758int VMMDev::hgcmHostSvcHandleCreate(const char *pszServiceName, HGCMCVSHANDLE * phSvc)
759{
760 if (!hgcmIsActive())
761 return VERR_INVALID_STATE;
762 return HGCMHostSvcHandleCreate(pszServiceName, phSvc);
763}
764
765int VMMDev::hgcmHostSvcHandleDestroy(HGCMCVSHANDLE hSvc)
766{
767 if (!hgcmIsActive())
768 return VERR_INVALID_STATE;
769 return HGCMHostSvcHandleDestroy(hSvc);
770}
771
772int VMMDev::hgcmHostFastCallAsync(HGCMCVSHANDLE hSvc, uint32_t function, PVBOXHGCMSVCPARM pParm,
773 PHGCMHOSTFASTCALLCB pfnCompletion, void *pvCompletion)
774{
775 if (!hgcmIsActive())
776 return VERR_INVALID_STATE;
777 return HGCMHostFastCallAsync(hSvc, function, pParm, pfnCompletion, pvCompletion);
778}
779# endif
780
781#endif /* HGCM */
782
783
784/**
785 * @interface_method_impl{PDMIBASE,pfnQueryInterface}
786 */
787DECLCALLBACK(void *) VMMDev::drvQueryInterface(PPDMIBASE pInterface, const char *pszIID)
788{
789 PPDMDRVINS pDrvIns = PDMIBASE_2_PDMDRV(pInterface);
790 PDRVMAINVMMDEV pDrv = PDMINS_2_DATA(pDrvIns, PDRVMAINVMMDEV);
791
792 PDMIBASE_RETURN_INTERFACE(pszIID, PDMIBASE, &pDrvIns->IBase);
793 PDMIBASE_RETURN_INTERFACE(pszIID, PDMIVMMDEVCONNECTOR, &pDrv->Connector);
794#ifdef VBOX_WITH_HGCM
795 PDMIBASE_RETURN_INTERFACE(pszIID, PDMIHGCMCONNECTOR, &pDrv->HGCMConnector);
796#endif
797 return NULL;
798}
799
800/**
801 * @interface_method_impl{PDMDRVREG,pfnSuspend}
802 */
803/*static*/ DECLCALLBACK(void) VMMDev::drvSuspend(PPDMDRVINS pDrvIns)
804{
805 RT_NOREF(pDrvIns);
806#ifdef VBOX_WITH_HGCM
807 HGCMBroadcastEvent(HGCMNOTIFYEVENT_SUSPEND);
808#endif
809}
810
811/**
812 * @interface_method_impl{PDMDRVREG,pfnResume}
813 */
814/*static*/ DECLCALLBACK(void) VMMDev::drvResume(PPDMDRVINS pDrvIns)
815{
816 RT_NOREF(pDrvIns);
817#ifdef VBOX_WITH_HGCM
818 HGCMBroadcastEvent(HGCMNOTIFYEVENT_RESUME);
819#endif
820}
821
822/**
823 * @interface_method_impl{PDMDRVREG,pfnPowerOff}
824 */
825/*static*/ DECLCALLBACK(void) VMMDev::drvPowerOff(PPDMDRVINS pDrvIns)
826{
827 RT_NOREF(pDrvIns);
828#ifdef VBOX_WITH_HGCM
829 HGCMBroadcastEvent(HGCMNOTIFYEVENT_POWER_ON);
830#endif
831}
832
833/**
834 * @interface_method_impl{PDMDRVREG,pfnPowerOn}
835 */
836/*static*/ DECLCALLBACK(void) VMMDev::drvPowerOn(PPDMDRVINS pDrvIns)
837{
838 RT_NOREF(pDrvIns);
839#ifdef VBOX_WITH_HGCM
840 HGCMBroadcastEvent(HGCMNOTIFYEVENT_POWER_ON);
841#endif
842}
843
844/**
845 * @interface_method_impl{PDMDRVREG,pfnReset}
846 */
847DECLCALLBACK(void) VMMDev::drvReset(PPDMDRVINS pDrvIns)
848{
849 RT_NOREF(pDrvIns);
850 LogFlow(("VMMDev::drvReset: iInstance=%d\n", pDrvIns->iInstance));
851#ifdef VBOX_WITH_HGCM
852 HGCMHostReset(false /*fForShutdown*/);
853#endif
854}
855
856/**
857 * @interface_method_impl{PDMDRVREG,pfnDestruct}
858 */
859DECLCALLBACK(void) VMMDev::drvDestruct(PPDMDRVINS pDrvIns)
860{
861 PDMDRV_CHECK_VERSIONS_RETURN_VOID(pDrvIns);
862 PDRVMAINVMMDEV pThis = PDMINS_2_DATA(pDrvIns, PDRVMAINVMMDEV);
863 LogFlow(("VMMDev::drvDestruct: iInstance=%d\n", pDrvIns->iInstance));
864
865#ifdef VBOX_WITH_GUEST_PROPS
866 if (pThis->hHgcmSvcExtGstProps)
867 {
868 HGCMHostUnregisterServiceExtension(pThis->hHgcmSvcExtGstProps);
869 pThis->hHgcmSvcExtGstProps = NULL;
870 }
871#endif
872
873#ifdef VBOX_WITH_GUEST_CONTROL
874 if (pThis->hHgcmSvcExtGstCtrl)
875 {
876 HGCMHostUnregisterServiceExtension(pThis->hHgcmSvcExtGstCtrl);
877 pThis->hHgcmSvcExtGstCtrl = NULL;
878 }
879#endif
880
881 if (pThis->pVMMDev)
882 {
883#ifdef VBOX_WITH_HGCM
884 /* When VM construction goes wrong, we prefer shutting down HGCM here
885 while pUVM is still valid, rather than in ~VMMDev. */
886 if (ASMAtomicCmpXchgBool(&pThis->pVMMDev->m_fHGCMActive, false, true))
887 HGCMHostShutdown();
888#endif
889 pThis->pVMMDev->mpDrv = NULL;
890 }
891}
892
893#ifdef VBOX_WITH_GUEST_PROPS
894
895/**
896 * Set an array of guest properties
897 */
898void VMMDev::i_guestPropSetMultiple(void *names, void *values, void *timestamps, void *flags)
899{
900 VBOXHGCMSVCPARM parms[4];
901
902 parms[0].type = VBOX_HGCM_SVC_PARM_PTR;
903 parms[0].u.pointer.addr = names;
904 parms[0].u.pointer.size = 0; /* We don't actually care. */
905 parms[1].type = VBOX_HGCM_SVC_PARM_PTR;
906 parms[1].u.pointer.addr = values;
907 parms[1].u.pointer.size = 0; /* We don't actually care. */
908 parms[2].type = VBOX_HGCM_SVC_PARM_PTR;
909 parms[2].u.pointer.addr = timestamps;
910 parms[2].u.pointer.size = 0; /* We don't actually care. */
911 parms[3].type = VBOX_HGCM_SVC_PARM_PTR;
912 parms[3].u.pointer.addr = flags;
913 parms[3].u.pointer.size = 0; /* We don't actually care. */
914
915 hgcmHostCall("VBoxGuestPropSvc", GUEST_PROP_FN_HOST_SET_PROPS, 4, &parms[0]);
916}
917
918/**
919 * Set a single guest property
920 */
921void VMMDev::i_guestPropSet(const char *pszName, const char *pszValue, const char *pszFlags)
922{
923 VBOXHGCMSVCPARM parms[4];
924
925 AssertPtrReturnVoid(pszName);
926 AssertPtrReturnVoid(pszValue);
927 AssertPtrReturnVoid(pszFlags);
928 parms[0].type = VBOX_HGCM_SVC_PARM_PTR;
929 parms[0].u.pointer.addr = (void *)pszName;
930 parms[0].u.pointer.size = (uint32_t)strlen(pszName) + 1;
931 parms[1].type = VBOX_HGCM_SVC_PARM_PTR;
932 parms[1].u.pointer.addr = (void *)pszValue;
933 parms[1].u.pointer.size = (uint32_t)strlen(pszValue) + 1;
934 parms[2].type = VBOX_HGCM_SVC_PARM_PTR;
935 parms[2].u.pointer.addr = (void *)pszFlags;
936 parms[2].u.pointer.size = (uint32_t)strlen(pszFlags) + 1;
937 hgcmHostCall("VBoxGuestPropSvc", GUEST_PROP_FN_HOST_SET_PROP, 3, &parms[0]);
938}
939
940/**
941 * Set the global flags value by calling the service
942 * @returns the status returned by the call to the service
943 *
944 * @param pTable the service instance handle
945 * @param eFlags the flags to set
946 */
947int VMMDev::i_guestPropSetGlobalPropertyFlags(uint32_t fFlags)
948{
949 VBOXHGCMSVCPARM parm;
950 HGCMSvcSetU32(&parm, fFlags);
951 int rc = hgcmHostCall("VBoxGuestPropSvc", GUEST_PROP_FN_HOST_SET_GLOBAL_FLAGS, 1, &parm);
952 if (RT_FAILURE(rc))
953 {
954 char szFlags[GUEST_PROP_MAX_FLAGS_LEN];
955 if (RT_FAILURE(GuestPropWriteFlags(fFlags, szFlags)))
956 Log(("Failed to set the global flags.\n"));
957 else
958 Log(("Failed to set the global flags \"%s\".\n", szFlags));
959 }
960 return rc;
961}
962
963
964/**
965 * Set up the Guest Property service, populate it with properties read from
966 * the machine XML and set a couple of initial properties.
967 */
968int VMMDev::i_guestPropLoadAndConfigure()
969{
970 Assert(mpDrv);
971 ComObjPtr<Console> ptrConsole = this->mParent;
972 AssertReturn(ptrConsole.isNotNull(), VERR_INVALID_POINTER);
973
974 /*
975 * Load the service
976 */
977 int rc = hgcmLoadService("VBoxGuestPropSvc", "VBoxGuestPropSvc");
978 if (RT_FAILURE(rc))
979 {
980 LogRel(("VBoxGuestPropSvc is not available. rc = %Rrc\n", rc));
981 return VINF_SUCCESS; /* That is not a fatal failure. */
982 }
983
984 /*
985 * Pull over the properties from the server.
986 */
987 SafeArray<BSTR> namesOut;
988 SafeArray<BSTR> valuesOut;
989 SafeArray<LONG64> timestampsOut;
990 SafeArray<BSTR> flagsOut;
991 HRESULT hrc = ptrConsole->i_pullGuestProperties(ComSafeArrayAsOutParam(namesOut),
992 ComSafeArrayAsOutParam(valuesOut),
993 ComSafeArrayAsOutParam(timestampsOut),
994 ComSafeArrayAsOutParam(flagsOut));
995 AssertLogRelMsgReturn(SUCCEEDED(hrc), ("hrc=%Rhrc\n", hrc), VERR_MAIN_CONFIG_CONSTRUCTOR_COM_ERROR);
996 size_t const cProps = namesOut.size();
997 size_t const cAlloc = cProps + 1;
998 AssertLogRelReturn(valuesOut.size() == cProps, VERR_INTERNAL_ERROR_2);
999 AssertLogRelReturn(timestampsOut.size() == cProps, VERR_INTERNAL_ERROR_3);
1000 AssertLogRelReturn(flagsOut.size() == cProps, VERR_INTERNAL_ERROR_4);
1001
1002 char szEmpty[] = "";
1003 char **papszNames = (char **)RTMemTmpAllocZ(sizeof(char *) * cAlloc);
1004 char **papszValues = (char **)RTMemTmpAllocZ(sizeof(char *) * cAlloc);
1005 LONG64 *pai64Timestamps = (LONG64 *)RTMemTmpAllocZ(sizeof(LONG64) * cAlloc);
1006 char **papszFlags = (char **)RTMemTmpAllocZ(sizeof(char *) * cAlloc);
1007 if (papszNames && papszValues && pai64Timestamps && papszFlags)
1008 {
1009 for (unsigned i = 0; RT_SUCCESS(rc) && i < cProps; ++i)
1010 {
1011 AssertPtrBreakStmt(namesOut[i], rc = VERR_INVALID_PARAMETER);
1012 rc = RTUtf16ToUtf8(namesOut[i], &papszNames[i]);
1013 if (RT_FAILURE(rc))
1014 break;
1015 if (valuesOut[i])
1016 rc = RTUtf16ToUtf8(valuesOut[i], &papszValues[i]);
1017 else
1018 papszValues[i] = szEmpty;
1019 if (RT_FAILURE(rc))
1020 break;
1021 pai64Timestamps[i] = timestampsOut[i];
1022 if (flagsOut[i])
1023 rc = RTUtf16ToUtf8(flagsOut[i], &papszFlags[i]);
1024 else
1025 papszFlags[i] = szEmpty;
1026 }
1027 if (RT_SUCCESS(rc))
1028 i_guestPropSetMultiple((void *)papszNames, (void *)papszValues, (void *)pai64Timestamps, (void *)papszFlags);
1029 for (unsigned i = 0; i < cProps; ++i)
1030 {
1031 RTStrFree(papszNames[i]);
1032 if (valuesOut[i])
1033 RTStrFree(papszValues[i]);
1034 if (flagsOut[i])
1035 RTStrFree(papszFlags[i]);
1036 }
1037 }
1038 else
1039 rc = VERR_NO_MEMORY;
1040 RTMemTmpFree(papszNames);
1041 RTMemTmpFree(papszValues);
1042 RTMemTmpFree(pai64Timestamps);
1043 RTMemTmpFree(papszFlags);
1044 AssertRCReturn(rc, rc);
1045
1046 /*
1047 * Register the host notification callback
1048 */
1049 HGCMHostRegisterServiceExtension(&mpDrv->hHgcmSvcExtGstProps, "VBoxGuestPropSvc", Console::i_doGuestPropNotification, ptrConsole.m_p);
1050
1051# ifdef VBOX_WITH_GUEST_PROPS_RDONLY_GUEST
1052 rc = i_guestPropSetGlobalPropertyFlags(GUEST_PROP_F_RDONLYGUEST);
1053 AssertRCReturn(rc, rc);
1054# endif
1055
1056 Log(("Set VBoxGuestPropSvc property store\n"));
1057 return VINF_SUCCESS;
1058}
1059
1060#endif /* VBOX_WITH_GUEST_PROPS */
1061
1062/**
1063 * @interface_method_impl{PDMDRVREG,pfnConstruct}
1064 */
1065DECLCALLBACK(int) VMMDev::drvConstruct(PPDMDRVINS pDrvIns, PCFGMNODE pCfgHandle, uint32_t fFlags)
1066{
1067 RT_NOREF(fFlags);
1068 PDMDRV_CHECK_VERSIONS_RETURN(pDrvIns);
1069 PDRVMAINVMMDEV pThis = PDMINS_2_DATA(pDrvIns, PDRVMAINVMMDEV);
1070 LogFlow(("Keyboard::drvConstruct: iInstance=%d\n", pDrvIns->iInstance));
1071
1072 /*
1073 * Validate configuration.
1074 */
1075 if (!CFGMR3AreValuesValid(pCfgHandle, "Object\0"))
1076 return VERR_PDM_DRVINS_UNKNOWN_CFG_VALUES;
1077 AssertMsgReturn(PDMDrvHlpNoAttach(pDrvIns) == VERR_PDM_NO_ATTACHED_DRIVER,
1078 ("Configuration error: Not possible to attach anything to this driver!\n"),
1079 VERR_PDM_DRVINS_NO_ATTACH);
1080
1081 /*
1082 * IBase.
1083 */
1084 pDrvIns->IBase.pfnQueryInterface = VMMDev::drvQueryInterface;
1085
1086 pThis->Connector.pfnUpdateGuestStatus = vmmdevUpdateGuestStatus;
1087 pThis->Connector.pfnUpdateGuestUserState = vmmdevUpdateGuestUserState;
1088 pThis->Connector.pfnUpdateGuestInfo = vmmdevUpdateGuestInfo;
1089 pThis->Connector.pfnUpdateGuestInfo2 = vmmdevUpdateGuestInfo2;
1090 pThis->Connector.pfnUpdateGuestCapabilities = vmmdevUpdateGuestCapabilities;
1091 pThis->Connector.pfnUpdateMouseCapabilities = vmmdevUpdateMouseCapabilities;
1092 pThis->Connector.pfnUpdatePointerShape = vmmdevUpdatePointerShape;
1093 pThis->Connector.pfnVideoAccelEnable = iface_VideoAccelEnable;
1094 pThis->Connector.pfnVideoAccelFlush = iface_VideoAccelFlush;
1095 pThis->Connector.pfnVideoModeSupported = vmmdevVideoModeSupported;
1096 pThis->Connector.pfnGetHeightReduction = vmmdevGetHeightReduction;
1097 pThis->Connector.pfnSetCredentialsJudgementResult = vmmdevSetCredentialsJudgementResult;
1098 pThis->Connector.pfnSetVisibleRegion = vmmdevSetVisibleRegion;
1099 pThis->Connector.pfnQueryVisibleRegion = vmmdevQueryVisibleRegion;
1100 pThis->Connector.pfnReportStatistics = vmmdevReportStatistics;
1101 pThis->Connector.pfnQueryStatisticsInterval = vmmdevQueryStatisticsInterval;
1102 pThis->Connector.pfnQueryBalloonSize = vmmdevQueryBalloonSize;
1103 pThis->Connector.pfnIsPageFusionEnabled = vmmdevIsPageFusionEnabled;
1104
1105#ifdef VBOX_WITH_HGCM
1106 pThis->HGCMConnector.pfnConnect = iface_hgcmConnect;
1107 pThis->HGCMConnector.pfnDisconnect = iface_hgcmDisconnect;
1108 pThis->HGCMConnector.pfnCall = iface_hgcmCall;
1109 pThis->HGCMConnector.pfnCancelled = iface_hgcmCancelled;
1110#endif
1111
1112 /*
1113 * Get the IVMMDevPort interface of the above driver/device.
1114 */
1115 pThis->pUpPort = PDMIBASE_QUERY_INTERFACE(pDrvIns->pUpBase, PDMIVMMDEVPORT);
1116 AssertMsgReturn(pThis->pUpPort, ("Configuration error: No VMMDev port interface above!\n"), VERR_PDM_MISSING_INTERFACE_ABOVE);
1117
1118#ifdef VBOX_WITH_HGCM
1119 pThis->pHGCMPort = PDMIBASE_QUERY_INTERFACE(pDrvIns->pUpBase, PDMIHGCMPORT);
1120 AssertMsgReturn(pThis->pHGCMPort, ("Configuration error: No HGCM port interface above!\n"), VERR_PDM_MISSING_INTERFACE_ABOVE);
1121#endif
1122
1123 /*
1124 * Get the Console object pointer and update the mpDrv member.
1125 */
1126 void *pv;
1127 int rc = CFGMR3QueryPtr(pCfgHandle, "Object", &pv);
1128 if (RT_FAILURE(rc))
1129 {
1130 AssertMsgFailed(("Configuration error: No/bad \"Object\" value! rc=%Rrc\n", rc));
1131 return rc;
1132 }
1133
1134 pThis->pVMMDev = (VMMDev*)pv; /** @todo Check this cast! */
1135 pThis->pVMMDev->mpDrv = pThis;
1136
1137#ifdef VBOX_WITH_HGCM
1138 /*
1139 * Load & configure the shared folders service.
1140 */
1141 rc = pThis->pVMMDev->hgcmLoadService(VBOXSHAREDFOLDERS_DLL, "VBoxSharedFolders");
1142 pThis->pVMMDev->fSharedFolderActive = RT_SUCCESS(rc);
1143 if (RT_SUCCESS(rc))
1144 {
1145 PPDMLED pLed;
1146 PPDMILEDPORTS pLedPort;
1147
1148 LogRel(("Shared Folders service loaded\n"));
1149 pLedPort = PDMIBASE_QUERY_INTERFACE(pDrvIns->pUpBase, PDMILEDPORTS);
1150 AssertMsgReturn(pLedPort, ("Configuration error: No LED port interface above!\n"), VERR_PDM_MISSING_INTERFACE_ABOVE);
1151 rc = pLedPort->pfnQueryStatusLed(pLedPort, 0, &pLed);
1152 if (RT_SUCCESS(rc) && pLed)
1153 {
1154 VBOXHGCMSVCPARM parm;
1155
1156 parm.type = VBOX_HGCM_SVC_PARM_PTR;
1157 parm.u.pointer.addr = pLed;
1158 parm.u.pointer.size = sizeof(*pLed);
1159
1160 rc = HGCMHostCall("VBoxSharedFolders", SHFL_FN_SET_STATUS_LED, 1, &parm);
1161 }
1162 else
1163 AssertMsgFailed(("pfnQueryStatusLed failed with %Rrc (pLed=%x)\n", rc, pLed));
1164 }
1165 else
1166 LogRel(("Failed to load Shared Folders service %Rrc\n", rc));
1167
1168
1169 /*
1170 * Load and configure the guest control service.
1171 */
1172# ifdef VBOX_WITH_GUEST_CONTROL
1173 rc = pThis->pVMMDev->hgcmLoadService("VBoxGuestControlSvc", "VBoxGuestControlSvc");
1174 if (RT_SUCCESS(rc))
1175 {
1176 rc = HGCMHostRegisterServiceExtension(&pThis->hHgcmSvcExtGstCtrl, "VBoxGuestControlSvc",
1177 &Guest::i_notifyCtrlDispatcher,
1178 pThis->pVMMDev->mParent->i_getGuest());
1179 if (RT_SUCCESS(rc))
1180 LogRel(("Guest Control service loaded\n"));
1181 else
1182 LogRel(("Warning: Cannot register VBoxGuestControlSvc extension! rc=%Rrc\n", rc));
1183 }
1184 else
1185 LogRel(("Warning!: Failed to load the Guest Control Service! %Rrc\n", rc));
1186# endif /* VBOX_WITH_GUEST_CONTROL */
1187
1188
1189 /*
1190 * Load and configure the guest properties service.
1191 */
1192# ifdef VBOX_WITH_GUEST_PROPS
1193 rc = pThis->pVMMDev->i_guestPropLoadAndConfigure();
1194 AssertLogRelRCReturn(rc, rc);
1195# endif
1196
1197
1198 /*
1199 * The HGCM saved state.
1200 */
1201 rc = PDMDrvHlpSSMRegisterEx(pDrvIns, HGCM_SAVED_STATE_VERSION, 4096 /* bad guess */,
1202 NULL, NULL, NULL,
1203 NULL, iface_hgcmSave, NULL,
1204 NULL, iface_hgcmLoad, NULL);
1205 if (RT_FAILURE(rc))
1206 return rc;
1207
1208#endif /* VBOX_WITH_HGCM */
1209
1210 return VINF_SUCCESS;
1211}
1212
1213
1214/**
1215 * VMMDevice driver registration record.
1216 */
1217const PDMDRVREG VMMDev::DrvReg =
1218{
1219 /* u32Version */
1220 PDM_DRVREG_VERSION,
1221 /* szName */
1222 "HGCM",
1223 /* szRCMod */
1224 "",
1225 /* szR0Mod */
1226 "",
1227 /* pszDescription */
1228 "Main VMMDev driver (Main as in the API).",
1229 /* fFlags */
1230 PDM_DRVREG_FLAGS_HOST_BITS_DEFAULT,
1231 /* fClass. */
1232 PDM_DRVREG_CLASS_VMMDEV,
1233 /* cMaxInstances */
1234 ~0U,
1235 /* cbInstance */
1236 sizeof(DRVMAINVMMDEV),
1237 /* pfnConstruct */
1238 VMMDev::drvConstruct,
1239 /* pfnDestruct */
1240 VMMDev::drvDestruct,
1241 /* pfnRelocate */
1242 NULL,
1243 /* pfnIOCtl */
1244 NULL,
1245 /* pfnPowerOn */
1246 VMMDev::drvPowerOn,
1247 /* pfnReset */
1248 VMMDev::drvReset,
1249 /* pfnSuspend */
1250 VMMDev::drvSuspend,
1251 /* pfnResume */
1252 VMMDev::drvResume,
1253 /* pfnAttach */
1254 NULL,
1255 /* pfnDetach */
1256 NULL,
1257 /* pfnPowerOff */
1258 VMMDev::drvPowerOff,
1259 /* pfnSoftReset */
1260 NULL,
1261 /* u32EndVersion */
1262 PDM_DRVREG_VERSION
1263};
1264/* vi: set tabstop=4 shiftwidth=4 expandtab: */
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