VirtualBox

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

Last change on this file since 94521 was 93444, checked in by vboxsync, 2 years ago

VMM,Main,HostServices: Use a function table for accessing the VBoxVMM.dll/so/dylib functionality, and load it dynamically when the Console object is initialized. Also converted a few drivers in Main to use device helpers to get config values and such. bugref:10074

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

© 2023 Oracle
ContactPrivacy policyTerms of Use