VirtualBox

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

Last change on this file since 93931 was 93444, checked in by vboxsync, 3 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
Line 
1/* $Id: VMMDevInterface.cpp 93444 2022-01-26 18:01:15Z vboxsync $ */
2/** @file
3 * VirtualBox Driver Interface to VMM device.
4 */
5
6/*
7 * Copyright (C) 2006-2022 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#endif
36
37//
38// defines
39//
40
41#ifdef RT_OS_OS2
42# define VBOXSHAREDFOLDERS_DLL "VBoxSFld"
43#else
44# define VBOXSHAREDFOLDERS_DLL "VBoxSharedFolders"
45#endif
46
47//
48// globals
49//
50
51
52/**
53 * VMMDev driver instance data.
54 */
55typedef struct DRVMAINVMMDEV
56{
57 /** Pointer to the VMMDev object. */
58 VMMDev *pVMMDev;
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;
65
66#ifdef VBOX_WITH_HGCM
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
72
73#ifdef VBOX_WITH_GUEST_PROPS
74 HGCMSVCEXTHANDLE hHgcmSvcExtGstProps;
75#endif
76#ifdef VBOX_WITH_GUEST_CONTROL
77 HGCMSVCEXTHANDLE hHgcmSvcExtGstCtrl;
78#endif
79} DRVMAINVMMDEV, *PDRVMAINVMMDEV;
80
81//
82// constructor / destructor
83//
84VMMDev::VMMDev(Console *console)
85 : mpDrv(NULL)
86 , mParent(console)
87{
88 int rc = RTSemEventCreate(&mCredentialsEvent);
89 AssertRC(rc);
90#ifdef VBOX_WITH_HGCM
91 rc = HGCMHostInit();
92 AssertRC(rc);
93 m_fHGCMActive = true;
94#endif /* VBOX_WITH_HGCM */
95 mu32CredentialsFlags = 0;
96}
97
98VMMDev::~VMMDev()
99{
100#ifdef VBOX_WITH_HGCM
101 if (ASMAtomicCmpXchgBool(&m_fHGCMActive, false, true))
102 HGCMHostShutdown(true /*fUvmIsInvalid*/);
103#endif
104 RTSemEventDestroy(mCredentialsEvent);
105 if (mpDrv)
106 mpDrv->pVMMDev = NULL;
107 mpDrv = NULL;
108}
109
110PPDMIVMMDEVPORT VMMDev::getVMMDevPort()
111{
112 if (!mpDrv)
113 return NULL;
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 */
126int VMMDev::WaitCredentialsJudgement(uint32_t u32Timeout, uint32_t *pu32CredentialsFlags)
127{
128 if (u32Timeout == 0)
129 {
130 u32Timeout = 5000;
131 }
132
133 int rc = RTSemEventWait(mCredentialsEvent, u32Timeout);
134
135 if (RT_SUCCESS(rc))
136 {
137 *pu32CredentialsFlags = mu32CredentialsFlags;
138 }
139
140 return rc;
141}
142
143int VMMDev::SetCredentialsJudgementResult(uint32_t u32Flags)
144{
145 mu32CredentialsFlags = u32Flags;
146
147 int rc = RTSemEventSignal(mCredentialsEvent);
148 AssertRC(rc);
149
150 return rc;
151}
152
153
154/**
155 * @interface_method_impl{PDMIVMMDEVCONNECTOR,pfnUpdateGuestStatus}
156 */
157DECLCALLBACK(void) vmmdevUpdateGuestStatus(PPDMIVMMDEVCONNECTOR pInterface, uint32_t uFacility, uint16_t uStatus,
158 uint32_t fFlags, PCRTTIMESPEC pTimeSpecTS)
159{
160 PDRVMAINVMMDEV pDrv = RT_FROM_MEMBER(pInterface, DRVMAINVMMDEV, Connector);
161 Console *pConsole = pDrv->pVMMDev->getParent();
162
163 /* Store that information in IGuest */
164 Guest* guest = pConsole->i_getGuest();
165 AssertPtrReturnVoid(guest);
166
167 guest->i_setAdditionsStatus((VBoxGuestFacilityType)uFacility, (VBoxGuestFacilityStatus)uStatus, fFlags, pTimeSpecTS);
168 pConsole->i_onAdditionsStateChange();
169}
170
171
172/**
173 * @interface_method_impl{PDMIVMMDEVCONNECTOR,pfnUpdateGuestUserState}
174 */
175DECLCALLBACK(void) vmmdevUpdateGuestUserState(PPDMIVMMDEVCONNECTOR pInterface,
176 const char *pszUser, const char *pszDomain,
177 uint32_t uState,
178 const uint8_t *pabDetails, uint32_t cbDetails)
179{
180 PDRVMAINVMMDEV pDrv = RT_FROM_MEMBER(pInterface, DRVMAINVMMDEV, Connector);
181 AssertPtr(pDrv);
182 Console *pConsole = pDrv->pVMMDev->getParent();
183 AssertPtr(pConsole);
184
185 /* Store that information in IGuest. */
186 Guest* pGuest = pConsole->i_getGuest();
187 AssertPtrReturnVoid(pGuest);
188
189 pGuest->i_onUserStateChanged(Utf8Str(pszUser), Utf8Str(pszDomain), (VBoxGuestUserState)uState, pabDetails, cbDetails);
190}
191
192
193/**
194 * Reports Guest Additions API and OS version.
195 *
196 * Called whenever the Additions issue a guest version report request or the VM
197 * is reset.
198 *
199 * @param pInterface Pointer to this interface.
200 * @param guestInfo Pointer to guest information structure.
201 * @thread The emulation thread.
202 */
203DECLCALLBACK(void) vmmdevUpdateGuestInfo(PPDMIVMMDEVCONNECTOR pInterface, const VBoxGuestInfo *guestInfo)
204{
205 AssertPtrReturnVoid(guestInfo);
206
207 PDRVMAINVMMDEV pDrv = RT_FROM_MEMBER(pInterface, DRVMAINVMMDEV, Connector);
208 Console *pConsole = pDrv->pVMMDev->getParent();
209
210 /* Store that information in IGuest */
211 Guest* guest = pConsole->i_getGuest();
212 AssertPtrReturnVoid(guest);
213
214 if (guestInfo->interfaceVersion != 0)
215 {
216 char version[16];
217 RTStrPrintf(version, sizeof(version), "%d", guestInfo->interfaceVersion);
218 guest->i_setAdditionsInfo(Bstr(version), guestInfo->osType);
219
220 /*
221 * Tell the console interface about the event
222 * so that it can notify its consumers.
223 */
224 pConsole->i_onAdditionsStateChange();
225
226 if (guestInfo->interfaceVersion < VMMDEV_VERSION)
227 pConsole->i_onAdditionsOutdated();
228 }
229 else
230 {
231 /*
232 * The Guest Additions was disabled because of a reset
233 * or driver unload.
234 */
235 guest->i_setAdditionsInfo(Bstr(), guestInfo->osType); /* Clear interface version + OS type. */
236 /** @todo Would be better if GuestImpl.cpp did all this in the above method call
237 * while holding down the. */
238 guest->i_setAdditionsInfo2(0, "", 0, 0); /* Clear Guest Additions version. */
239 RTTIMESPEC TimeSpecTS;
240 RTTimeNow(&TimeSpecTS);
241 guest->i_setAdditionsStatus(VBoxGuestFacilityType_All, VBoxGuestFacilityStatus_Inactive, 0 /*fFlags*/, &TimeSpecTS);
242 pConsole->i_onAdditionsStateChange();
243 }
244}
245
246/**
247 * @interface_method_impl{PDMIVMMDEVCONNECTOR,pfnUpdateGuestInfo2}
248 */
249DECLCALLBACK(void) vmmdevUpdateGuestInfo2(PPDMIVMMDEVCONNECTOR pInterface, uint32_t uFullVersion,
250 const char *pszName, uint32_t uRevision, uint32_t fFeatures)
251{
252 PDRVMAINVMMDEV pDrv = RT_FROM_MEMBER(pInterface, DRVMAINVMMDEV, Connector);
253 AssertPtr(pszName);
254 Assert(uFullVersion);
255
256 /* Store that information in IGuest. */
257 Guest *pGuest = pDrv->pVMMDev->getParent()->i_getGuest();
258 AssertPtrReturnVoid(pGuest);
259
260 /* Just pass it on... */
261 pGuest->i_setAdditionsInfo2(uFullVersion, pszName, uRevision, fFeatures);
262
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 */
268}
269
270/**
271 * Update the Guest Additions capabilities.
272 * This is called when the Guest Additions capabilities change. The new capabilities
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{
281 PDRVMAINVMMDEV pDrv = RT_FROM_MEMBER(pInterface, DRVMAINVMMDEV, Connector);
282 AssertPtr(pDrv);
283 Console *pConsole = pDrv->pVMMDev->getParent();
284
285 /* store that information in IGuest */
286 Guest* pGuest = pConsole->i_getGuest();
287 AssertPtrReturnVoid(pGuest);
288
289 /*
290 * Report our current capabilities (and assume none is active yet).
291 */
292 pGuest->i_setSupportedFeatures(newCapabilities);
293
294 /*
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);
300 pDisplay->i_handleUpdateVMMDevSupportsGraphics(RT_BOOL(newCapabilities & VMMDEV_GUEST_SUPPORTS_GRAPHICS));
301
302 /*
303 * Tell the console interface about the event
304 * so that it can notify its consumers.
305 */
306 pConsole->i_onAdditionsStateChange();
307}
308
309/**
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.
315 * @param fNewCaps New capabilities.
316 * @thread The emulation thread.
317 */
318DECLCALLBACK(void) vmmdevUpdateMouseCapabilities(PPDMIVMMDEVCONNECTOR pInterface, uint32_t fNewCaps)
319{
320 PDRVMAINVMMDEV pDrv = RT_FROM_MEMBER(pInterface, DRVMAINVMMDEV, Connector);
321 Console *pConsole = pDrv->pVMMDev->getParent();
322
323 /*
324 * Tell the console interface about the event
325 * so that it can notify its consumers.
326 */
327 Mouse *pMouse = pConsole->i_getMouse();
328 if (pMouse) /** @todo and if not? Can that actually happen? */
329 pMouse->i_onVMMDevGuestCapsChange(fNewCaps & VMMDEV_MOUSE_GUEST_MASK);
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{
353 PDRVMAINVMMDEV pDrv = RT_FROM_MEMBER(pInterface, DRVMAINVMMDEV, Connector);
354 Console *pConsole = pDrv->pVMMDev->getParent();
355
356 /* tell the console about it */
357 uint32_t cbShape = 0;
358 if (pShape)
359 {
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 */
362 }
363 pConsole->i_onMousePointerShapeChange(fVisible, fAlpha, xHot, yHot, width, height, (uint8_t *)pShape, cbShape);
364}
365
366DECLCALLBACK(int) iface_VideoAccelEnable(PPDMIVMMDEVCONNECTOR pInterface, bool fEnable, VBVAMEMORY *pVbvaMemory)
367{
368 PDRVMAINVMMDEV pDrv = RT_FROM_MEMBER(pInterface, DRVMAINVMMDEV, Connector);
369 Console *pConsole = pDrv->pVMMDev->getParent();
370
371 Display *display = pConsole->i_getDisplay();
372
373 if (display)
374 {
375 Log9(("MAIN::VMMDevInterface::iface_VideoAccelEnable: %d, %p\n", fEnable, pVbvaMemory));
376 return display->VideoAccelEnableVMMDev(fEnable, pVbvaMemory);
377 }
378
379 return VERR_NOT_SUPPORTED;
380}
381DECLCALLBACK(void) iface_VideoAccelFlush(PPDMIVMMDEVCONNECTOR pInterface)
382{
383 PDRVMAINVMMDEV pDrv = RT_FROM_MEMBER(pInterface, DRVMAINVMMDEV, Connector);
384 Console *pConsole = pDrv->pVMMDev->getParent();
385
386 Display *display = pConsole->i_getDisplay();
387
388 if (display)
389 {
390 Log9(("MAIN::VMMDevInterface::iface_VideoAccelFlush\n"));
391 display->VideoAccelFlushVMMDev();
392 }
393}
394
395DECLCALLBACK(int) vmmdevVideoModeSupported(PPDMIVMMDEVCONNECTOR pInterface, uint32_t display, uint32_t width, uint32_t height,
396 uint32_t bpp, bool *fSupported)
397{
398 PDRVMAINVMMDEV pDrv = RT_FROM_MEMBER(pInterface, DRVMAINVMMDEV, Connector);
399 Console *pConsole = pDrv->pVMMDev->getParent();
400
401 if (!fSupported)
402 return VERR_INVALID_PARAMETER;
403#ifdef DEBUG_sunlover
404 Log(("vmmdevVideoModeSupported: [%d]: %dx%dx%d\n", display, width, height, bpp));
405#endif
406 IFramebuffer *framebuffer = NULL;
407 HRESULT hrc = pConsole->i_getDisplay()->QueryFramebuffer(display, &framebuffer);
408 if (SUCCEEDED(hrc) && framebuffer)
409 {
410 framebuffer->VideoModeSupported(width, height, bpp, (BOOL*)fSupported);
411 framebuffer->Release();
412 }
413 else
414 {
415#ifdef DEBUG_sunlover
416 Log(("vmmdevVideoModeSupported: hrc %x, framebuffer %p!!!\n", hrc, framebuffer));
417#endif
418 *fSupported = true;
419 }
420 return VINF_SUCCESS;
421}
422
423DECLCALLBACK(int) vmmdevGetHeightReduction(PPDMIVMMDEVCONNECTOR pInterface, uint32_t *heightReduction)
424{
425 PDRVMAINVMMDEV pDrv = RT_FROM_MEMBER(pInterface, DRVMAINVMMDEV, Connector);
426 Console *pConsole = pDrv->pVMMDev->getParent();
427
428 if (!heightReduction)
429 return VERR_INVALID_PARAMETER;
430 IFramebuffer *framebuffer = NULL;
431 HRESULT hrc = pConsole->i_getDisplay()->QueryFramebuffer(0, &framebuffer);
432 if (SUCCEEDED(hrc) && framebuffer)
433 {
434 framebuffer->COMGETTER(HeightReduction)((ULONG*)heightReduction);
435 framebuffer->Release();
436 }
437 else
438 *heightReduction = 0;
439 return VINF_SUCCESS;
440}
441
442DECLCALLBACK(int) vmmdevSetCredentialsJudgementResult(PPDMIVMMDEVCONNECTOR pInterface, uint32_t u32Flags)
443{
444 PDRVMAINVMMDEV pDrv = RT_FROM_MEMBER(pInterface, DRVMAINVMMDEV, Connector);
445
446 if (pDrv->pVMMDev)
447 return pDrv->pVMMDev->SetCredentialsJudgementResult(u32Flags);
448
449 return VERR_GENERAL_FAILURE;
450}
451
452DECLCALLBACK(int) vmmdevSetVisibleRegion(PPDMIVMMDEVCONNECTOR pInterface, uint32_t cRect, PRTRECT pRect)
453{
454 PDRVMAINVMMDEV pDrv = RT_FROM_MEMBER(pInterface, DRVMAINVMMDEV, Connector);
455 Console *pConsole = pDrv->pVMMDev->getParent();
456
457 /* Forward to Display, which calls corresponding framebuffers. */
458 pConsole->i_getDisplay()->i_handleSetVisibleRegion(cRect, pRect);
459
460 return VINF_SUCCESS;
461}
462
463/**
464 * @interface_method_impl{PDMIVMMDEVCONNECTOR,pfnUpdateMonitorPositions}
465 */
466static DECLCALLBACK(int) vmmdevUpdateMonitorPositions(PPDMIVMMDEVCONNECTOR pInterface, uint32_t cPositions, PCRTPOINT paPositions)
467{
468 PDRVMAINVMMDEV pDrv = RT_FROM_MEMBER(pInterface, DRVMAINVMMDEV, Connector);
469 Console *pConsole = pDrv->pVMMDev->getParent();
470
471 pConsole->i_getDisplay()->i_handleUpdateMonitorPositions(cPositions, paPositions);
472
473 return VINF_SUCCESS;
474}
475
476DECLCALLBACK(int) vmmdevQueryVisibleRegion(PPDMIVMMDEVCONNECTOR pInterface, uint32_t *pcRects, PRTRECT paRects)
477{
478 PDRVMAINVMMDEV pDrv = RT_FROM_MEMBER(pInterface, DRVMAINVMMDEV, Connector);
479 Console *pConsole = pDrv->pVMMDev->getParent();
480
481 /* Forward to Display, which calls corresponding framebuffers. */
482 pConsole->i_getDisplay()->i_handleQueryVisibleRegion(pcRects, paRects);
483
484 return VINF_SUCCESS;
485}
486
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{
497 PDRVMAINVMMDEV pDrv = RT_FROM_MEMBER(pInterface, DRVMAINVMMDEV, Connector);
498 Console *pConsole = pDrv->pVMMDev->getParent();
499 ULONG val = 0;
500
501 if (!pulInterval)
502 return VERR_INVALID_POINTER;
503
504 /* store that information in IGuest */
505 Guest* guest = pConsole->i_getGuest();
506 AssertPtrReturn(guest, VERR_GENERAL_FAILURE);
507
508 guest->COMGETTER(StatisticsUpdateInterval)(&val);
509 *pulInterval = val;
510 return VINF_SUCCESS;
511}
512
513/**
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{
523 PDRVMAINVMMDEV pDrv = RT_FROM_MEMBER(pInterface, DRVMAINVMMDEV, Connector);
524 Console *pConsole = pDrv->pVMMDev->getParent();
525 ULONG val = 0;
526
527 if (!pcbBalloon)
528 return VERR_INVALID_POINTER;
529
530 /* store that information in IGuest */
531 Guest* guest = pConsole->i_getGuest();
532 AssertPtrReturn(guest, VERR_GENERAL_FAILURE);
533
534 guest->COMGETTER(MemoryBalloonSize)(&val);
535 *pcbBalloon = val;
536 return VINF_SUCCESS;
537}
538
539/**
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{
549 PDRVMAINVMMDEV pDrv = RT_FROM_MEMBER(pInterface, DRVMAINVMMDEV, Connector);
550 Console *pConsole = pDrv->pVMMDev->getParent();
551
552 if (!pfPageFusionEnabled)
553 return VERR_INVALID_POINTER;
554
555 /* store that information in IGuest */
556 Guest* guest = pConsole->i_getGuest();
557 AssertPtrReturn(guest, VERR_GENERAL_FAILURE);
558
559 *pfPageFusionEnabled = !!guest->i_isPageFusionEnabled();
560 return VINF_SUCCESS;
561}
562
563/**
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{
573 PDRVMAINVMMDEV pDrv = RT_FROM_MEMBER(pInterface, DRVMAINVMMDEV, Connector);
574 Console *pConsole = pDrv->pVMMDev->getParent();
575
576 AssertPtrReturn(pGuestStats, VERR_INVALID_POINTER);
577
578 /* store that information in IGuest */
579 Guest* guest = pConsole->i_getGuest();
580 AssertPtrReturn(guest, VERR_GENERAL_FAILURE);
581
582 if (pGuestStats->u32StatCaps & VBOX_GUEST_STAT_CPU_LOAD_IDLE)
583 guest->i_setStatistic(pGuestStats->u32CpuId, GUESTSTATTYPE_CPUIDLE, pGuestStats->u32CpuLoad_Idle);
584
585 if (pGuestStats->u32StatCaps & VBOX_GUEST_STAT_CPU_LOAD_KERNEL)
586 guest->i_setStatistic(pGuestStats->u32CpuId, GUESTSTATTYPE_CPUKERNEL, pGuestStats->u32CpuLoad_Kernel);
587
588 if (pGuestStats->u32StatCaps & VBOX_GUEST_STAT_CPU_LOAD_USER)
589 guest->i_setStatistic(pGuestStats->u32CpuId, GUESTSTATTYPE_CPUUSER, pGuestStats->u32CpuLoad_User);
590
591
592 /** @todo r=bird: Convert from 4KB to 1KB units?
593 * CollectorGuestHAL::i_getGuestMemLoad says it returns KB units to
594 * preCollect(). I might be wrong ofc, this is convoluted code... */
595 if (pGuestStats->u32StatCaps & VBOX_GUEST_STAT_PHYS_MEM_TOTAL)
596 guest->i_setStatistic(pGuestStats->u32CpuId, GUESTSTATTYPE_MEMTOTAL, pGuestStats->u32PhysMemTotal);
597
598 if (pGuestStats->u32StatCaps & VBOX_GUEST_STAT_PHYS_MEM_AVAIL)
599 guest->i_setStatistic(pGuestStats->u32CpuId, GUESTSTATTYPE_MEMFREE, pGuestStats->u32PhysMemAvail);
600
601 if (pGuestStats->u32StatCaps & VBOX_GUEST_STAT_PHYS_MEM_BALLOON)
602 guest->i_setStatistic(pGuestStats->u32CpuId, GUESTSTATTYPE_MEMBALLOON, pGuestStats->u32PhysMemBalloon);
603
604 if (pGuestStats->u32StatCaps & VBOX_GUEST_STAT_MEM_SYSTEM_CACHE)
605 guest->i_setStatistic(pGuestStats->u32CpuId, GUESTSTATTYPE_MEMCACHE, pGuestStats->u32MemSystemCache);
606
607 if (pGuestStats->u32StatCaps & VBOX_GUEST_STAT_PAGE_FILE_SIZE)
608 guest->i_setStatistic(pGuestStats->u32CpuId, GUESTSTATTYPE_PAGETOTAL, pGuestStats->u32PageFileSize);
609
610 return VINF_SUCCESS;
611}
612
613#ifdef VBOX_WITH_HGCM
614
615/* HGCM connector interface */
616
617static DECLCALLBACK(int) iface_hgcmConnect(PPDMIHGCMCONNECTOR pInterface, PVBOXHGCMCMD pCmd,
618 PHGCMSERVICELOCATION pServiceLocation,
619 uint32_t *pu32ClientID)
620{
621 Log9(("Enter\n"));
622
623 PDRVMAINVMMDEV pDrv = RT_FROM_MEMBER(pInterface, DRVMAINVMMDEV, HGCMConnector);
624
625 if ( !pServiceLocation
626 || ( pServiceLocation->type != VMMDevHGCMLoc_LocalHost
627 && pServiceLocation->type != VMMDevHGCMLoc_LocalHost_Existing))
628 {
629 return VERR_INVALID_PARAMETER;
630 }
631
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
639 if (!pDrv->pVMMDev || !pDrv->pVMMDev->hgcmIsActive())
640 return VERR_INVALID_STATE;
641 return HGCMGuestConnect(pDrv->pHGCMPort, pCmd, pServiceLocation->u.host.achName, pu32ClientID);
642}
643
644static DECLCALLBACK(int) iface_hgcmDisconnect(PPDMIHGCMCONNECTOR pInterface, PVBOXHGCMCMD pCmd, uint32_t u32ClientID)
645{
646 Log9(("Enter\n"));
647
648 PDRVMAINVMMDEV pDrv = RT_FROM_MEMBER(pInterface, DRVMAINVMMDEV, HGCMConnector);
649
650 if (!pDrv->pVMMDev || !pDrv->pVMMDev->hgcmIsActive())
651 return VERR_INVALID_STATE;
652
653 return HGCMGuestDisconnect(pDrv->pHGCMPort, pCmd, u32ClientID);
654}
655
656static DECLCALLBACK(int) iface_hgcmCall(PPDMIHGCMCONNECTOR pInterface, PVBOXHGCMCMD pCmd, uint32_t u32ClientID,
657 uint32_t u32Function, uint32_t cParms, PVBOXHGCMSVCPARM paParms, uint64_t tsArrival)
658{
659 Log9(("Enter\n"));
660
661 PDRVMAINVMMDEV pDrv = RT_FROM_MEMBER(pInterface, DRVMAINVMMDEV, HGCMConnector);
662
663 if (!pDrv->pVMMDev || !pDrv->pVMMDev->hgcmIsActive())
664 return VERR_INVALID_STATE;
665
666 return HGCMGuestCall(pDrv->pHGCMPort, pCmd, u32ClientID, u32Function, cParms, paParms, tsArrival);
667}
668
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
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 */
686/*static*/ DECLCALLBACK(int) VMMDev::hgcmSave(PPDMDRVINS pDrvIns, PSSMHANDLE pSSM)
687{
688 PDRVMAINVMMDEV pThis = PDMINS_2_DATA(pDrvIns, PDRVMAINVMMDEV);
689 Log9(("Enter\n"));
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());
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.
704 * @param uVersion Data layout version.
705 * @param uPass The data pass.
706 */
707/*static*/ DECLCALLBACK(int) VMMDev::hgcmLoad(PPDMDRVINS pDrvIns, PSSMHANDLE pSSM, uint32_t uVersion, uint32_t uPass)
708{
709 PDRVMAINVMMDEV pThis = PDMINS_2_DATA(pDrvIns, PDRVMAINVMMDEV);
710 LogFlowFunc(("Enter\n"));
711
712 if ( uVersion != HGCM_SAVED_STATE_VERSION
713 && uVersion != HGCM_SAVED_STATE_VERSION_V2)
714 return VERR_SSM_UNSUPPORTED_DATA_UNIT_VERSION;
715 Assert(uPass == SSM_PASS_FINAL); NOREF(uPass);
716
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);
721}
722
723int VMMDev::hgcmLoadService(const char *pszServiceLibrary, const char *pszServiceName)
724{
725 if (!hgcmIsActive())
726 return VERR_INVALID_STATE;
727
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 );
736 Console::SafeVMPtrQuiet ptrVM(mParent);
737 return HGCMHostLoad(pszServiceLibrary, pszServiceName, ptrVM.rawUVM(), ptrVM.vtable(), mpDrv ? mpDrv->pHGCMPort : NULL);
738}
739
740int VMMDev::hgcmHostCall(const char *pszServiceName, uint32_t u32Function,
741 uint32_t cParms, PVBOXHGCMSVCPARM paParms)
742{
743 if (!hgcmIsActive())
744 return VERR_INVALID_STATE;
745 return HGCMHostCall(pszServiceName, u32Function, cParms, paParms);
746}
747
748/**
749 * Used by Console::i_powerDown to shut down the services before the VM is destroyed.
750 */
751void VMMDev::hgcmShutdown(bool fUvmIsInvalid /*= false*/)
752{
753#ifdef VBOX_WITH_GUEST_PROPS
754 if (mpDrv && mpDrv->hHgcmSvcExtGstProps)
755 {
756 HGCMHostUnregisterServiceExtension(mpDrv->hHgcmSvcExtGstProps);
757 mpDrv->hHgcmSvcExtGstProps = NULL;
758 }
759#endif
760
761#ifdef VBOX_WITH_GUEST_CONTROL
762 if (mpDrv && mpDrv->hHgcmSvcExtGstCtrl)
763 {
764 HGCMHostUnregisterServiceExtension(mpDrv->hHgcmSvcExtGstCtrl);
765 mpDrv->hHgcmSvcExtGstCtrl = NULL;
766 }
767#endif
768
769 if (ASMAtomicCmpXchgBool(&m_fHGCMActive, false, true))
770 HGCMHostShutdown(fUvmIsInvalid);
771}
772
773#endif /* HGCM */
774
775
776/**
777 * @interface_method_impl{PDMIBASE,pfnQueryInterface}
778 */
779DECLCALLBACK(void *) VMMDev::drvQueryInterface(PPDMIBASE pInterface, const char *pszIID)
780{
781 PPDMDRVINS pDrvIns = PDMIBASE_2_PDMDRV(pInterface);
782 PDRVMAINVMMDEV pDrv = PDMINS_2_DATA(pDrvIns, PDRVMAINVMMDEV);
783
784 PDMIBASE_RETURN_INTERFACE(pszIID, PDMIBASE, &pDrvIns->IBase);
785 PDMIBASE_RETURN_INTERFACE(pszIID, PDMIVMMDEVCONNECTOR, &pDrv->Connector);
786#ifdef VBOX_WITH_HGCM
787 PDMIBASE_RETURN_INTERFACE(pszIID, PDMIHGCMCONNECTOR, &pDrv->HGCMConnector);
788#endif
789 return NULL;
790}
791
792/**
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/**
837 * @interface_method_impl{PDMDRVREG,pfnReset}
838 */
839DECLCALLBACK(void) VMMDev::drvReset(PPDMDRVINS pDrvIns)
840{
841 RT_NOREF(pDrvIns);
842 LogFlow(("VMMDev::drvReset: iInstance=%d\n", pDrvIns->iInstance));
843#ifdef VBOX_WITH_HGCM
844 HGCMHostReset(false /*fForShutdown*/);
845#endif
846}
847
848/**
849 * @interface_method_impl{PDMDRVREG,pfnDestruct}
850 */
851DECLCALLBACK(void) VMMDev::drvDestruct(PPDMDRVINS pDrvIns)
852{
853 PDMDRV_CHECK_VERSIONS_RETURN_VOID(pDrvIns);
854 PDRVMAINVMMDEV pThis = PDMINS_2_DATA(pDrvIns, PDRVMAINVMMDEV);
855 LogFlow(("VMMDev::drvDestruct: iInstance=%d\n", pDrvIns->iInstance));
856
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
873 if (pThis->pVMMDev)
874 {
875#ifdef VBOX_WITH_HGCM
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
881 pThis->pVMMDev->mpDrv = NULL;
882 }
883}
884
885#ifdef VBOX_WITH_GUEST_PROPS
886
887/**
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
966 /*
967 * Load the service
968 */
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 */
1041 HGCMHostRegisterServiceExtension(&mpDrv->hHgcmSvcExtGstProps, "VBoxGuestPropSvc", Console::i_doGuestPropNotification, ptrConsole.m_p);
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/**
1055 * @interface_method_impl{PDMDRVREG,pfnConstruct}
1056 */
1057DECLCALLBACK(int) VMMDev::drvConstruct(PPDMDRVINS pDrvIns, PCFGMNODE pCfg, uint32_t fFlags)
1058{
1059 PDMDRV_CHECK_VERSIONS_RETURN(pDrvIns);
1060 RT_NOREF(fFlags, pCfg);
1061 PDRVMAINVMMDEV pThis = PDMINS_2_DATA(pDrvIns, PDRVMAINVMMDEV);
1062 LogFlow(("Keyboard::drvConstruct: iInstance=%d\n", pDrvIns->iInstance));
1063
1064 /*
1065 * Validate configuration.
1066 */
1067 PDMDRV_VALIDATE_CONFIG_RETURN(pDrvIns, "", "");
1068 AssertMsgReturn(PDMDrvHlpNoAttach(pDrvIns) == VERR_PDM_NO_ATTACHED_DRIVER,
1069 ("Configuration error: Not possible to attach anything to this driver!\n"),
1070 VERR_PDM_DRVINS_NO_ATTACH);
1071
1072 /*
1073 * IBase.
1074 */
1075 pDrvIns->IBase.pfnQueryInterface = VMMDev::drvQueryInterface;
1076
1077 pThis->Connector.pfnUpdateGuestStatus = vmmdevUpdateGuestStatus;
1078 pThis->Connector.pfnUpdateGuestUserState = vmmdevUpdateGuestUserState;
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;
1090 pThis->Connector.pfnUpdateMonitorPositions = vmmdevUpdateMonitorPositions;
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;
1096
1097#ifdef VBOX_WITH_HGCM
1098 pThis->HGCMConnector.pfnConnect = iface_hgcmConnect;
1099 pThis->HGCMConnector.pfnDisconnect = iface_hgcmDisconnect;
1100 pThis->HGCMConnector.pfnCall = iface_hgcmCall;
1101 pThis->HGCMConnector.pfnCancelled = iface_hgcmCancelled;
1102#endif
1103
1104 /*
1105 * Get the IVMMDevPort interface of the above driver/device.
1106 */
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);
1109
1110#ifdef VBOX_WITH_HGCM
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);
1113#endif
1114
1115 /*
1116 * Get the Console object pointer and update the mpDrv member.
1117 */
1118 com::Guid uuid(VMMDEV_OID);
1119 pThis->pVMMDev = (VMMDev *)PDMDrvHlpQueryGenericUserObject(pDrvIns, uuid.raw());
1120 if (!pThis->pVMMDev)
1121 {
1122 AssertMsgFailed(("Configuration error: No/bad VMMDev object!\n"));
1123 return VERR_NOT_FOUND;
1124 }
1125 pThis->pVMMDev->mpDrv = pThis;
1126
1127 int rc = VINF_SUCCESS;
1128#ifdef VBOX_WITH_HGCM
1129 /*
1130 * Load & configure the shared folders service.
1131 */
1132 rc = pThis->pVMMDev->hgcmLoadService(VBOXSHAREDFOLDERS_DLL, "VBoxSharedFolders");
1133 pThis->pVMMDev->fSharedFolderActive = RT_SUCCESS(rc);
1134 if (RT_SUCCESS(rc))
1135 {
1136 PPDMLED pLed;
1137 PPDMILEDPORTS pLedPort;
1138
1139 LogRel(("Shared Folders service loaded\n"));
1140 pLedPort = PDMIBASE_QUERY_INTERFACE(pDrvIns->pUpBase, PDMILEDPORTS);
1141 AssertMsgReturn(pLedPort, ("Configuration error: No LED port interface above!\n"), VERR_PDM_MISSING_INTERFACE_ABOVE);
1142 rc = pLedPort->pfnQueryStatusLed(pLedPort, 0, &pLed);
1143 if (RT_SUCCESS(rc) && pLed)
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
1154 AssertMsgFailed(("pfnQueryStatusLed failed with %Rrc (pLed=%x)\n", rc, pLed));
1155 }
1156 else
1157 LogRel(("Failed to load Shared Folders service %Rrc\n", rc));
1158
1159
1160 /*
1161 * Load and configure the guest control service.
1162 */
1163# ifdef VBOX_WITH_GUEST_CONTROL
1164 rc = pThis->pVMMDev->hgcmLoadService("VBoxGuestControlSvc", "VBoxGuestControlSvc");
1165 if (RT_SUCCESS(rc))
1166 {
1167 rc = HGCMHostRegisterServiceExtension(&pThis->hHgcmSvcExtGstCtrl, "VBoxGuestControlSvc",
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 /*
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 /*
1190 * The HGCM saved state.
1191 */
1192 rc = PDMDrvHlpSSMRegisterEx(pDrvIns, HGCM_SAVED_STATE_VERSION, 4096 /* bad guess */,
1193 NULL, NULL, NULL,
1194 NULL, VMMDev::hgcmSave, NULL,
1195 NULL, VMMDev::hgcmLoad, NULL);
1196 if (RT_FAILURE(rc))
1197 return rc;
1198
1199#endif /* VBOX_WITH_HGCM */
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,
1212 /* szName */
1213 "HGCM",
1214 /* szRCMod */
1215 "",
1216 /* szR0Mod */
1217 "",
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 */
1225 ~0U,
1226 /* cbInstance */
1227 sizeof(DRVMAINVMMDEV),
1228 /* pfnConstruct */
1229 VMMDev::drvConstruct,
1230 /* pfnDestruct */
1231 VMMDev::drvDestruct,
1232 /* pfnRelocate */
1233 NULL,
1234 /* pfnIOCtl */
1235 NULL,
1236 /* pfnPowerOn */
1237 VMMDev::drvPowerOn,
1238 /* pfnReset */
1239 VMMDev::drvReset,
1240 /* pfnSuspend */
1241 VMMDev::drvSuspend,
1242 /* pfnResume */
1243 VMMDev::drvResume,
1244 /* pfnAttach */
1245 NULL,
1246 /* pfnDetach */
1247 NULL,
1248 /* pfnPowerOff */
1249 VMMDev::drvPowerOff,
1250 /* pfnSoftReset */
1251 NULL,
1252 /* u32EndVersion */
1253 PDM_DRVREG_VERSION
1254};
1255/* 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