VirtualBox

source: vbox/trunk/src/VBox/VMM/PDMDriver.cpp@ 3741

Last change on this file since 3741 was 3520, checked in by vboxsync, 17 years ago

PDMThread (unfinished).

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 38.0 KB
Line 
1/* $Id: PDMDriver.cpp 3520 2007-07-10 11:37:32Z vboxsync $ */
2/** @file
3 * PDM - Pluggable Device and Driver Manager, Driver parts.
4 */
5
6/*
7 * Copyright (C) 2006-2007 innotek GmbH
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 as published by the Free Software Foundation,
13 * in version 2 as it comes in the "COPYING" file of the VirtualBox OSE
14 * distribution. VirtualBox OSE is distributed in the hope that it will
15 * be useful, but WITHOUT ANY WARRANTY of any kind.
16 *
17 * If you received this file as part of a commercial VirtualBox
18 * distribution, then only the terms of your commercial VirtualBox
19 * license agreement apply instead of the previous paragraph.
20 */
21
22
23/*******************************************************************************
24* Header Files *
25*******************************************************************************/
26#define LOG_GROUP LOG_GROUP_PDM_DRIVER
27#include "PDMInternal.h"
28#include <VBox/pdm.h>
29#include <VBox/mm.h>
30#include <VBox/cfgm.h>
31#include <VBox/vmm.h>
32#include <VBox/sup.h>
33#include <VBox/vm.h>
34#include <VBox/version.h>
35#include <VBox/err.h>
36
37#include <VBox/log.h>
38#include <iprt/assert.h>
39#include <iprt/thread.h>
40#include <iprt/string.h>
41#include <iprt/asm.h>
42#include <iprt/alloc.h>
43#include <iprt/path.h>
44
45
46/*******************************************************************************
47* Structures and Typedefs *
48*******************************************************************************/
49/**
50 * Internal callback structure pointer.
51 * The main purpose is to define the extra data we associate
52 * with PDMDRVREGCB so we can find the VM instance and so on.
53 */
54typedef struct PDMDRVREGCBINT
55{
56 /** The callback structure. */
57 PDMDRVREGCB Core;
58 /** A bit of padding. */
59 uint32_t u32[4];
60 /** VM Handle. */
61 PVM pVM;
62} PDMDRVREGCBINT, *PPDMDRVREGCBINT;
63typedef const PDMDRVREGCBINT *PCPDMDRVREGCBINT;
64
65
66/*******************************************************************************
67* Internal Functions *
68*******************************************************************************/
69/** @name Driver Helpers
70 * @{
71 */
72static DECLCALLBACK(int) pdmR3DrvHlp_Attach(PPDMDRVINS pDrvIns, PPDMIBASE *ppBaseInterface);
73static DECLCALLBACK(int) pdmR3DrvHlp_Detach(PPDMDRVINS pDrvIns);
74static DECLCALLBACK(int) pdmR3DrvHlp_DetachSelf(PPDMDRVINS pDrvIns);
75static DECLCALLBACK(int) pdmR3DrvHlp_MountPrepare(PPDMDRVINS pDrvIns, const char *pszFilename, const char *pszCoreDriver);
76static DECLCALLBACK(int) pdmR3DrvHlp_VMSetError(PPDMDRVINS pDrvIns, int rc, RT_SRC_POS_DECL, const char *pszFormat, ...);
77static DECLCALLBACK(int) pdmR3DrvHlp_VMSetErrorV(PPDMDRVINS pDrvIns, int rc, RT_SRC_POS_DECL, const char *pszFormat, va_list va);
78static DECLCALLBACK(int) pdmR3DrvHlp_VMSetRuntimeError(PPDMDRVINS pDrvIns, bool fFatal, const char *pszErrorID, const char *pszFormat, ...);
79static DECLCALLBACK(int) pdmR3DrvHlp_VMSetRuntimeErrorV(PPDMDRVINS pDrvIns, bool fFatal, const char *pszErrorID, const char *pszFormat, va_list va);
80static DECLCALLBACK(bool) pdmR3DrvHlp_AssertEMT(PPDMDRVINS pDrvIns, const char *pszFile, unsigned iLine, const char *pszFunction);
81static DECLCALLBACK(bool) pdmR3DrvHlp_AssertOther(PPDMDRVINS pDrvIns, const char *pszFile, unsigned iLine, const char *pszFunction);
82static DECLCALLBACK(int) pdmR3DrvHlp_PDMQueueCreate(PPDMDRVINS pDrvIns, RTUINT cbItem, RTUINT cItems, uint32_t cMilliesInterval, PFNPDMQUEUEDRV pfnCallback, PPDMQUEUE *ppQueue);
83static DECLCALLBACK(int) pdmR3DrvHlp_PDMPollerRegister(PPDMDRVINS pDrvIns, PFNPDMDRVPOLLER pfnPoller);
84static DECLCALLBACK(uint64_t) pdmR3DrvHlp_TMGetVirtualFreq(PPDMDRVINS pDrvIns);
85static DECLCALLBACK(uint64_t) pdmR3DrvHlp_TMGetVirtualTime(PPDMDRVINS pDrvIns);
86static DECLCALLBACK(int) pdmR3DrvHlp_TMTimerCreate(PPDMDRVINS pDrvIns, TMCLOCK enmClock, PFNTMTIMERDRV pfnCallback, const char *pszDesc, PPTMTIMERHC ppTimer);
87static DECLCALLBACK(int) pdmR3DrvHlp_SSMRegister(PPDMDRVINS pDrvIns, const char *pszName, uint32_t u32Instance, uint32_t u32Version, size_t cbGuess,
88 PFNSSMDRVSAVEPREP pfnSavePrep, PFNSSMDRVSAVEEXEC pfnSaveExec, PFNSSMDRVSAVEDONE pfnSaveDone,
89 PFNSSMDRVLOADPREP pfnLoadPrep, PFNSSMDRVLOADEXEC pfnLoadExec, PFNSSMDRVLOADDONE pfnLoadDone);
90static DECLCALLBACK(int) pdmR3DrvHlp_SSMDeregister(PPDMDRVINS pDrvIns, const char *pszName, uint32_t u32Instance);
91static DECLCALLBACK(void) pdmR3DrvHlp_STAMRegister(PPDMDRVINS pDrvIns, void *pvSample, STAMTYPE enmType, const char *pszName, STAMUNIT enmUnit, const char *pszDesc);
92static DECLCALLBACK(void) pdmR3DrvHlp_STAMRegisterF(PPDMDRVINS pDrvIns, void *pvSample, STAMTYPE enmType, STAMVISIBILITY enmVisibility, STAMUNIT enmUnit, const char *pszDesc, const char *pszName, ...);
93static DECLCALLBACK(void) pdmR3DrvHlp_STAMRegisterV(PPDMDRVINS pDrvIns, void *pvSample, STAMTYPE enmType, STAMVISIBILITY enmVisibility, STAMUNIT enmUnit, const char *pszDesc, const char *pszName, va_list args);
94static DECLCALLBACK(int) pdmR3DrvHlp_SUPCallVMMR0Ex(PPDMDRVINS pDrvIns, unsigned uOperation, void *pvArg, unsigned cbArg);
95
96/** @def PDMDRV_ASSERT_DRVINS
97 * Asserts the validity of the driver instance.
98 */
99#ifdef VBOX_STRICT
100# define PDMDRV_ASSERT_DRVINS(pDrvIns) do { Assert(pDrvIns); Assert(pDrvIns->u32Version == PDM_DRVINS_VERSION); Assert(pDrvIns->pvInstanceData == (void *)&pDrvIns->achInstanceData[0]); } while (0)
101#else
102# define PDMDRV_ASSERT_DRVINS(pDrvIns) do { } while (0)
103#endif
104/** @} */
105
106static DECLCALLBACK(int) pdmR3DrvRegister(PCPDMDRVREGCB pCallbacks, PCPDMDRVREG pDrvReg);
107static int pdmR3DrvLoad(PVM pVM, PPDMDRVREGCBINT pRegCB, const char *pszFilename, const char *pszName);
108
109
110/*******************************************************************************
111* Global Variables *
112*******************************************************************************/
113/**
114 * The driver helper structure.
115 */
116const PDMDRVHLP g_pdmR3DrvHlp =
117{
118 PDM_DRVHLP_VERSION,
119 pdmR3DrvHlp_Attach,
120 pdmR3DrvHlp_Detach,
121 pdmR3DrvHlp_DetachSelf,
122 pdmR3DrvHlp_MountPrepare,
123 pdmR3DrvHlp_AssertEMT,
124 pdmR3DrvHlp_AssertOther,
125 pdmR3DrvHlp_VMSetError,
126 pdmR3DrvHlp_VMSetErrorV,
127 pdmR3DrvHlp_VMSetRuntimeError,
128 pdmR3DrvHlp_VMSetRuntimeErrorV,
129 pdmR3DrvHlp_PDMQueueCreate,
130 pdmR3DrvHlp_PDMPollerRegister,
131 pdmR3DrvHlp_TMGetVirtualFreq,
132 pdmR3DrvHlp_TMGetVirtualTime,
133 pdmR3DrvHlp_TMTimerCreate,
134 pdmR3DrvHlp_SSMRegister,
135 pdmR3DrvHlp_SSMDeregister,
136 pdmR3DrvHlp_STAMRegister,
137 pdmR3DrvHlp_STAMRegisterF,
138 pdmR3DrvHlp_STAMRegisterV,
139 pdmR3DrvHlp_SUPCallVMMR0Ex,
140 0 /* the end */
141};
142
143
144/**
145 * Register external drivers
146 *
147 * @returns VBox status code.
148 * @param pVM The VM to operate on.
149 * @param pfnCallback Driver registration callback
150 */
151PDMR3DECL(int) PDMR3RegisterDrivers(PVM pVM, FNPDMVBOXDRIVERSREGISTER pfnCallback)
152{
153 /*
154 * The registration callbacks.
155 */
156 PDMDRVREGCBINT RegCB;
157 RegCB.Core.u32Version = PDM_DRVREG_CB_VERSION;
158 RegCB.Core.pfnRegister = pdmR3DrvRegister;
159 RegCB.pVM = pVM;
160
161 int rc = pfnCallback(&RegCB.Core, VBOX_VERSION);
162 if (VBOX_FAILURE(rc))
163 AssertMsgFailed(("VBoxDriversRegister failed with rc=%Vrc\n"));
164
165 return rc;
166}
167
168/**
169 * This function will initialize the drivers for this VM instance.
170 *
171 * First of all this mean loading the builtin drivers and letting them
172 * register themselves. Beyond that any additional driver modules are
173 * loaded and called for registration.
174 *
175 * @returns VBox status code.
176 * @param pVM VM Handle.
177 */
178int pdmR3DrvInit(PVM pVM)
179{
180 LogFlow(("pdmR3DrvInit:\n"));
181
182 AssertRelease(!(RT_OFFSETOF(PDMDRVINS, achInstanceData) & 15));
183 PPDMDRVINS pDrvInsAssert;
184 AssertRelease(sizeof(pDrvInsAssert->Internal.s) <= sizeof(pDrvInsAssert->Internal.padding));
185
186 /*
187 * The registration callbacks.
188 */
189 PDMDRVREGCBINT RegCB;
190 RegCB.Core.u32Version = PDM_DRVREG_CB_VERSION;
191 RegCB.Core.pfnRegister = pdmR3DrvRegister;
192 RegCB.pVM = pVM;
193
194 /*
195 * Load the builtin module
196 */
197 PCFGMNODE pDriversNode = CFGMR3GetChild(CFGMR3GetRoot(pVM), "PDM/Drivers");
198 bool fLoadBuiltin;
199 int rc = CFGMR3QueryBool(pDriversNode, "LoadBuiltin", &fLoadBuiltin);
200 if (rc == VERR_CFGM_VALUE_NOT_FOUND || rc == VERR_CFGM_NO_PARENT)
201 fLoadBuiltin = true;
202 else if (VBOX_FAILURE(rc))
203 {
204 AssertMsgFailed(("Configuration error: Querying boolean \"LoadBuiltin\" failed with %Vrc\n", rc));
205 return rc;
206 }
207 if (fLoadBuiltin)
208 {
209 /* make filename */
210 char *pszFilename = pdmR3FileR3("VBoxDD", /*fShared=*/true);
211 if (!pszFilename)
212 return VERR_NO_TMP_MEMORY;
213 rc = pdmR3DrvLoad(pVM, &RegCB, pszFilename, "VBoxDD");
214 RTMemTmpFree(pszFilename);
215 if (VBOX_FAILURE(rc))
216 return rc;
217 }
218
219 /*
220 * Load additional driver modules.
221 */
222 for (PCFGMNODE pCur = CFGMR3GetFirstChild(pDriversNode); pCur; pCur = CFGMR3GetNextChild(pCur))
223 {
224 /*
225 * Get the name and path.
226 */
227 char szName[PDMMOD_NAME_LEN];
228 rc = CFGMR3GetName(pCur, &szName[0], sizeof(szName));
229 if (rc == VERR_CFGM_NOT_ENOUGH_SPACE)
230 {
231 AssertMsgFailed(("configuration error: The module name is too long, cchName=%d.\n", CFGMR3GetNameLen(pCur)));
232 return VERR_PDM_MODULE_NAME_TOO_LONG;
233 }
234 else if (VBOX_FAILURE(rc))
235 {
236 AssertMsgFailed(("CFGMR3GetName -> %Vrc.\n", rc));
237 return rc;
238 }
239
240 /* the path is optional, if no path the module name + path is used. */
241 char szFilename[RTPATH_MAX];
242 rc = CFGMR3QueryString(pCur, "Path", &szFilename[0], sizeof(szFilename));
243 if (rc == VERR_CFGM_VALUE_NOT_FOUND || rc == VERR_CFGM_NO_PARENT)
244 strcpy(szFilename, szName);
245 else if (VBOX_FAILURE(rc))
246 {
247 AssertMsgFailed(("configuration error: Failure to query the module path, rc=%Vrc.\n", rc));
248 return rc;
249 }
250
251 /* prepend path? */
252 if (!RTPathHavePath(szFilename))
253 {
254 char *psz = pdmR3FileR3(szFilename);
255 if (!psz)
256 return VERR_NO_TMP_MEMORY;
257 size_t cch = strlen(psz) + 1;
258 if (cch > sizeof(szFilename))
259 {
260 RTMemTmpFree(psz);
261 AssertMsgFailed(("Filename too long! cch=%d '%s'\n", cch, psz));
262 return VERR_FILENAME_TOO_LONG;
263 }
264 memcpy(szFilename, psz, cch);
265 RTMemTmpFree(psz);
266 }
267
268 /*
269 * Load the module and register it's drivers.
270 */
271 rc = pdmR3DrvLoad(pVM, &RegCB, szFilename, szName);
272 if (VBOX_FAILURE(rc))
273 return rc;
274 }
275
276 LogFlow(("pdmR3DrvInit: returns VINF_SUCCESS\n"));
277 return VINF_SUCCESS;
278}
279
280
281/**
282 * Loads one driver module and call the registration entry point.
283 *
284 * @returns VBox status code.
285 * @param pVM VM handle.
286 * @param pRegCB The registration callback stuff.
287 * @param pszFilename Module filename.
288 * @param pszName Module name.
289 */
290static int pdmR3DrvLoad(PVM pVM, PPDMDRVREGCBINT pRegCB, const char *pszFilename, const char *pszName)
291{
292 /*
293 * Load it.
294 */
295 int rc = pdmR3LoadR3(pVM, pszFilename, pszName);
296 if (VBOX_SUCCESS(rc))
297 {
298 /*
299 * Get the registration export and call it.
300 */
301 FNPDMVBOXDRIVERSREGISTER *pfnVBoxDriversRegister;
302 rc = PDMR3GetSymbolR3(pVM, pszName, "VBoxDriversRegister", (void **)&pfnVBoxDriversRegister);
303 if (VBOX_SUCCESS(rc))
304 {
305 Log(("PDM: Calling VBoxDriversRegister (%p) of %s (%s)\n", pfnVBoxDriversRegister, pszName, pszFilename));
306 rc = pfnVBoxDriversRegister(&pRegCB->Core, VBOX_VERSION);
307 if (VBOX_SUCCESS(rc))
308 Log(("PDM: Successfully loaded driver module %s (%s).\n", pszName, pszFilename));
309 else
310 AssertMsgFailed(("VBoxDriversRegister failed with rc=%Vrc\n"));
311 }
312 else
313 {
314 AssertMsgFailed(("Failed to locate 'VBoxDriversRegister' in %s (%s) rc=%Vrc\n", pszName, pszFilename, rc));
315 if (rc == VERR_SYMBOL_NOT_FOUND)
316 rc = VERR_PDM_NO_REGISTRATION_EXPORT;
317 }
318 }
319 else
320 AssertMsgFailed(("Failed to load %s (%s) rc=%Vrc!\n", pszName, pszFilename, rc));
321 return rc;
322}
323
324
325/** @copydoc PDMDRVREGCB::pfnRegister */
326static DECLCALLBACK(int) pdmR3DrvRegister(PCPDMDRVREGCB pCallbacks, PCPDMDRVREG pDrvReg)
327{
328 /*
329 * Validate the registration structure.
330 */
331 Assert(pDrvReg);
332 if (pDrvReg->u32Version != PDM_DRVREG_VERSION)
333 {
334 AssertMsgFailed(("Unknown struct version %#x!\n", pDrvReg->u32Version));
335 return VERR_PDM_UNKNOWN_DRVREG_VERSION;
336 }
337 if ( !pDrvReg->szDriverName[0]
338 || strlen(pDrvReg->szDriverName) >= sizeof(pDrvReg->szDriverName))
339 {
340 AssertMsgFailed(("Invalid name '%s'\n", pDrvReg->szDriverName));
341 return VERR_PDM_INVALID_DRIVER_REGISTRATION;
342 }
343 if ((pDrvReg->fFlags & PDM_DRVREG_FLAGS_HOST_BITS_MASK) != PDM_DRVREG_FLAGS_HOST_BITS_DEFAULT)
344 {
345 AssertMsgFailed(("Invalid host bits flags! fFlags=%#x (Driver %s)\n", pDrvReg->fFlags, pDrvReg->szDriverName));
346 return VERR_PDM_INVALID_DRIVER_HOST_BITS;
347 }
348 if (pDrvReg->cMaxInstances <= 0)
349 {
350 AssertMsgFailed(("Max instances %u! (Driver %s)\n", pDrvReg->cMaxInstances, pDrvReg->szDriverName));
351 return VERR_PDM_INVALID_DRIVER_REGISTRATION;
352 }
353 if (pDrvReg->cbInstance > _1M)
354 {
355 AssertMsgFailed(("Instance size above 1MB, %d bytes! (Driver %s)\n", pDrvReg->cbInstance, pDrvReg->szDriverName));
356 return VERR_PDM_INVALID_DRIVER_REGISTRATION;
357 }
358 if (!pDrvReg->pfnConstruct)
359 {
360 AssertMsgFailed(("No constructore! (Driver %s)\n", pDrvReg->szDriverName));
361 return VERR_PDM_INVALID_DRIVER_REGISTRATION;
362 }
363
364 /*
365 * Check for duplicate and find FIFO entry at the same time.
366 */
367 PCPDMDRVREGCBINT pRegCB = (PCPDMDRVREGCBINT)pCallbacks;
368 PPDMDRV pDrvPrev = NULL;
369 PPDMDRV pDrv = pRegCB->pVM->pdm.s.pDrvs;
370 for (; pDrv; pDrvPrev = pDrv, pDrv = pDrv->pNext)
371 {
372 if (!strcmp(pDrv->pDrvReg->szDriverName, pDrvReg->szDriverName))
373 {
374 AssertMsgFailed(("Driver '%s' already exists\n", pDrvReg->szDriverName));
375 return VERR_PDM_DRIVER_NAME_CLASH;
376 }
377 }
378
379 /*
380 * Allocate new driver structure and insert it into the list.
381 */
382 pDrv = (PPDMDRV)MMR3HeapAlloc(pRegCB->pVM, MM_TAG_PDM_DRIVER, sizeof(*pDrv));
383 if (pDrv)
384 {
385 pDrv->pNext = NULL;
386 pDrv->cInstances = 0;
387 pDrv->pDrvReg = pDrvReg;
388
389 if (pDrvPrev)
390 pDrvPrev->pNext = pDrv;
391 else
392 pRegCB->pVM->pdm.s.pDrvs = pDrv;
393 Log(("PDM: Registered driver '%s'\n", pDrvReg->szDriverName));
394 return VINF_SUCCESS;
395 }
396 return VERR_NO_MEMORY;
397}
398
399
400/**
401 * Lookups a driver structure by name.
402 * @internal
403 */
404PPDMDRV pdmR3DrvLookup(PVM pVM, const char *pszName)
405{
406 for (PPDMDRV pDrv = pVM->pdm.s.pDrvs; pDrv; pDrv = pDrv->pNext)
407 if (!strcmp(pDrv->pDrvReg->szDriverName, pszName))
408 return pDrv;
409 return NULL;
410}
411
412
413/**
414 * Detaches a driver from whatever it's attached to.
415 * This will of course lead to the destruction of the driver and all drivers below it in the chain.
416 *
417 * @returns VINF_SUCCESS
418 * @param pDrvIns The driver instance to detach.
419 */
420int pdmR3DrvDetach(PPDMDRVINS pDrvIns)
421{
422 PDMDRV_ASSERT_DRVINS(pDrvIns);
423 LogFlow(("pdmR3DrvDetach: pDrvIns=%p '%s'/%d\n", pDrvIns, pDrvIns->pDrvReg->szDriverName, pDrvIns->iInstance));
424 VM_ASSERT_EMT(pDrvIns->Internal.s.pVM);
425
426 /*
427 * Check that we're not doing this recursively, that could have unwanted sideeffects!
428 */
429 if (pDrvIns->Internal.s.fDetaching)
430 {
431 AssertMsgFailed(("Recursive detach! '%s'/%d\n", pDrvIns->pDrvReg->szDriverName, pDrvIns->iInstance));
432 return VINF_SUCCESS;
433 }
434
435 /*
436 * Check that we actually can detach this instance.
437 * The requirement is that the driver/device above have a detach method.
438 */
439 if (pDrvIns->Internal.s.pUp
440 ? !pDrvIns->Internal.s.pUp->pDrvReg->pfnDetach
441 : !pDrvIns->Internal.s.pLun->pDevIns->pDevReg->pfnDetach)
442 {
443 AssertMsgFailed(("Cannot detach driver instance because the driver/device above doesn't support it!\n"));
444 return VERR_PDM_DRIVER_DETACH_NOT_POSSIBLE;
445 }
446
447 /*
448 * Detach the bottom most driver until we've detached pDrvIns.
449 */
450 pDrvIns->Internal.s.fDetaching = true;
451 PPDMDRVINS pCur;
452 do
453 {
454 /* find the driver to detach. */
455 pCur = pDrvIns;
456 while (pCur->Internal.s.pDown)
457 pCur = pCur->Internal.s.pDown;
458 LogFlow(("pdmR3DrvDetach: pCur=%p '%s'/%d\n", pCur, pCur->pDrvReg->szDriverName, pCur->iInstance));
459
460 /*
461 * Unlink it and notify parent.
462 */
463 pCur->Internal.s.fDetaching = true;
464 if (pCur->Internal.s.pUp)
465 {
466 /* driver parent */
467 PPDMDRVINS pParent = pCur->Internal.s.pUp;
468 pCur->Internal.s.pUp = NULL;
469 pParent->Internal.s.pDown = NULL;
470
471 if (pParent->pDrvReg->pfnDetach)
472 pParent->pDrvReg->pfnDetach(pParent);
473
474 pParent->pDownBase = NULL;
475 }
476 else
477 {
478 /* device parent */
479 PPDMLUN pLun = pCur->Internal.s.pLun;
480 pLun->pTop = NULL;
481 if (pLun->pDevIns->pDevReg->pfnDetach)
482 pLun->pDevIns->pDevReg->pfnDetach(pLun->pDevIns, pLun->iLun);
483 }
484
485 /*
486 * Call destructor.
487 */
488 pCur->pUpBase = NULL;
489 if (pCur->pDrvReg->pfnDestruct)
490 pCur->pDrvReg->pfnDestruct(pCur);
491
492 /*
493 * Free all resources allocated by the driver.
494 */
495 /* Queues. */
496 int rc = PDMR3QueueDestroyDriver(pCur->Internal.s.pVM, pCur);
497 AssertRC(rc);
498 /* Timers. */
499 rc = TMR3TimerDestroyDriver(pCur->Internal.s.pVM, pCur);
500 AssertRC(rc);
501 /* SSM data units. */
502 rc = SSMR3DeregisterDriver(pCur->Internal.s.pVM, pCur, NULL, 0);
503 AssertRC(rc);
504 /* PDM threads. */
505 ///@todo rc = pdmR3DestroyDriver(pCur->Internal.s.pVM, pCur);
506 AssertRC(rc);
507 /* Finally, the driver it self. */
508 ASMMemFill32(pCur, RT_OFFSETOF(PDMDRVINS, achInstanceData[pCur->pDrvReg->cbInstance]), 0xdeadd0d0);
509 MMR3HeapFree(pCur);
510
511 } while (pCur != pDrvIns);
512
513 return VINF_SUCCESS;
514}
515
516
517/** @copydoc PDMDRVHLP::pfnAttach */
518static DECLCALLBACK(int) pdmR3DrvHlp_Attach(PPDMDRVINS pDrvIns, PPDMIBASE *ppBaseInterface)
519{
520 PDMDRV_ASSERT_DRVINS(pDrvIns);
521 VM_ASSERT_EMT(pDrvIns->Internal.s.pVM);
522 LogFlow(("pdmR3DrvHlp_Attach: caller='%s'/%d:\n",
523 pDrvIns->pDrvReg->szDriverName, pDrvIns->iInstance));
524
525 /*
526 * Check that there isn't anything attached already.
527 */
528 int rc;
529 if (!pDrvIns->Internal.s.pDown)
530 {
531 /*
532 * Get the attached driver configuration.
533 */
534 PCFGMNODE pNode = CFGMR3GetChild(pDrvIns->Internal.s.pCfgHandle, "AttachedDriver");
535 if (pNode)
536 {
537 char *pszName;
538 rc = CFGMR3QueryStringAlloc(pNode, "Driver", &pszName);
539 if (VBOX_SUCCESS(rc))
540 {
541 /*
542 * Find the driver and allocate instance data.
543 */
544 PVM pVM = pDrvIns->Internal.s.pVM;
545 PPDMDRV pDrv = pdmR3DrvLookup(pVM, pszName);
546 if (pDrv)
547 {
548 /* config node */
549 PCFGMNODE pConfigNode = CFGMR3GetChild(pNode, "Config");
550 if (!pConfigNode)
551 rc = CFGMR3InsertNode(pNode, "Config", &pConfigNode);
552 if (VBOX_SUCCESS(rc))
553 {
554 CFGMR3SetRestrictedRoot(pConfigNode);
555
556 size_t cb = RT_OFFSETOF(PDMDRVINS, achInstanceData[pDrv->pDrvReg->cbInstance]);
557 cb = RT_ALIGN_Z(cb, 16);
558 PPDMDRVINS pNew = (PPDMDRVINS)MMR3HeapAllocZ(pVM, MM_TAG_PDM_DRIVER, cb);
559 if (pNew)
560 {
561 /*
562 * Initialize the instance structure (declaration order).
563 */
564 pNew->u32Version = PDM_DRVINS_VERSION;
565 pNew->Internal.s.pUp = pDrvIns;
566 pNew->Internal.s.pDown = NULL;
567 pNew->Internal.s.pLun = pDrvIns->Internal.s.pLun;
568 pNew->Internal.s.pDrv = pDrv;
569 pNew->Internal.s.pVM = pVM;
570 pNew->Internal.s.fDetaching = false;
571 pNew->Internal.s.pCfgHandle = pNode;
572 pNew->pDrvHlp = &g_pdmR3DrvHlp;
573 pNew->pDrvReg = pDrv->pDrvReg;
574 pNew->pCfgHandle = pConfigNode;
575 pNew->iInstance = pDrv->cInstances++;
576 pNew->pUpBase = &pDrvIns->IBase; /* This ain't safe, you can calc the pDrvIns of the up/down driver! */
577 pNew->pDownBase = NULL;
578 pNew->IBase.pfnQueryInterface = NULL;
579 pNew->pvInstanceData = &pNew->achInstanceData[0];
580
581 /*
582 * Hook it onto the chain and call the constructor.
583 */
584 pDrvIns->Internal.s.pDown = pNew;
585 Log(("PDM: Constructing driver '%s' instance %d...\n", pNew->pDrvReg->szDriverName, pNew->iInstance));
586 rc = pDrv->pDrvReg->pfnConstruct(pNew, pNew->pCfgHandle);
587 if (VBOX_SUCCESS(rc))
588 {
589 *ppBaseInterface = &pNew->IBase;
590 rc = VINF_SUCCESS;
591 }
592 else
593 {
594 /*
595 * Unlink and free the data.
596 */
597 pDrvIns->Internal.s.pDown = NULL;
598 ASMMemFill32(pNew, cb, 0xdeadd0d0);
599 MMR3HeapFree(pNew);
600 pDrv->cInstances--;
601 }
602 }
603 else
604 {
605 AssertMsgFailed(("Failed to allocate %d bytes for instantiating driver '%s'\n", cb, pszName));
606 rc = VERR_NO_MEMORY;
607 }
608 }
609 else
610 AssertMsgFailed(("Failed to create Config node! rc=%Vrc\n", rc));
611 }
612 else
613 {
614 AssertMsgFailed(("Driver '%s' wasn't found!\n", pszName));
615 rc = VERR_PDM_DRIVER_NOT_FOUND;
616 }
617 MMR3HeapFree(pszName);
618 }
619 else
620 {
621 AssertMsgFailed(("Query for string value of \"Driver\" -> %Vrc\n", rc));
622 if (rc == VERR_CFGM_VALUE_NOT_FOUND)
623 rc = VERR_PDM_CFG_MISSING_DRIVER_NAME;
624 }
625 }
626 else
627 rc = VERR_PDM_NO_ATTACHED_DRIVER;
628 }
629 else
630 {
631 AssertMsgFailed(("Already got a driver attached. The driver should keep track of such things!\n"));
632 rc = VERR_PDM_DRIVER_ALREADY_ATTACHED;
633 }
634
635 LogFlow(("pdmR3DrvHlp_Attach: caller='%s'/%d: return %Vrc\n",
636 pDrvIns->pDrvReg->szDriverName, pDrvIns->iInstance, rc));
637 return rc;
638}
639
640
641/** @copydoc PDMDRVHLP::pfnDetach */
642static DECLCALLBACK(int) pdmR3DrvHlp_Detach(PPDMDRVINS pDrvIns)
643{
644 PDMDRV_ASSERT_DRVINS(pDrvIns);
645 LogFlow(("pdmR3DrvHlp_Detach: caller='%s'/%d:\n",
646 pDrvIns->pDrvReg->szDriverName, pDrvIns->iInstance));
647 VM_ASSERT_EMT(pDrvIns->Internal.s.pVM);
648
649 /*
650 * Anything attached?
651 */
652 int rc;
653 if (pDrvIns->Internal.s.pDown)
654 {
655 rc = pdmR3DrvDetach(pDrvIns->Internal.s.pDown);
656 }
657 else
658 {
659 AssertMsgFailed(("Nothing attached!\n"));
660 rc = VERR_PDM_NO_DRIVER_ATTACHED;
661 }
662
663 LogFlow(("pdmR3DrvHlp_Detach: caller='%s'/%d: returns %Vrc\n",
664 pDrvIns->pDrvReg->szDriverName, pDrvIns->iInstance, rc));
665 return rc;
666}
667
668
669/** @copydoc PDMDRVHLP::pfnDetachSelf */
670static DECLCALLBACK(int) pdmR3DrvHlp_DetachSelf(PPDMDRVINS pDrvIns)
671{
672 PDMDRV_ASSERT_DRVINS(pDrvIns);
673 LogFlow(("pdmR3DrvHlp_DetachSelf: caller='%s'/%d:\n",
674 pDrvIns->pDrvReg->szDriverName, pDrvIns->iInstance));
675 VM_ASSERT_EMT(pDrvIns->Internal.s.pVM);
676
677 int rc = pdmR3DrvDetach(pDrvIns);
678
679 LogFlow(("pdmR3DrvHlp_Detach: returns %Vrc\n", rc)); /* pDrvIns is freed by now. */
680 return rc;
681}
682
683
684/** @copydoc PDMDRVHLP::pfnMountPrepare */
685static DECLCALLBACK(int) pdmR3DrvHlp_MountPrepare(PPDMDRVINS pDrvIns, const char *pszFilename, const char *pszCoreDriver)
686{
687 PDMDRV_ASSERT_DRVINS(pDrvIns);
688 LogFlow(("pdmR3DrvHlp_MountPrepare: caller='%s'/%d: pszFilename=%p:{%s} pszCoreDriver=%p:{%s}\n",
689 pDrvIns->pDrvReg->szDriverName, pDrvIns->iInstance, pszFilename, pszFilename, pszCoreDriver, pszCoreDriver));
690 VM_ASSERT_EMT(pDrvIns->Internal.s.pVM);
691
692 /*
693 * Do the caller have anything attached below itself?
694 */
695 if (pDrvIns->Internal.s.pDown)
696 {
697 AssertMsgFailed(("Cannot prepare a mount when something's attached to you!\n"));
698 return VERR_PDM_DRIVER_ALREADY_ATTACHED;
699 }
700
701 /*
702 * We're asked to prepare, so we'll start off by nuking the
703 * attached configuration tree.
704 */
705 PCFGMNODE pNode = CFGMR3GetChild(pDrvIns->Internal.s.pCfgHandle, "AttachedDriver");
706 if (pNode)
707 CFGMR3RemoveNode(pNode);
708
709 /*
710 * If there is no core driver, we'll have to probe for it.
711 */
712 if (!pszCoreDriver)
713 {
714 /** @todo implement image probing. */
715 AssertReleaseMsgFailed(("Not implemented!\n"));
716 return VERR_NOT_IMPLEMENTED;
717 }
718
719 /*
720 * Construct the basic attached driver configuration.
721 */
722 int rc = CFGMR3InsertNode(pDrvIns->Internal.s.pCfgHandle, "AttachedDriver", &pNode);
723 if (VBOX_SUCCESS(rc))
724 {
725 rc = CFGMR3InsertString(pNode, "Driver", pszCoreDriver);
726 if (VBOX_SUCCESS(rc))
727 {
728 PCFGMNODE pCfg;
729 rc = CFGMR3InsertNode(pNode, "Config", &pCfg);
730 if (VBOX_SUCCESS(rc))
731 {
732 rc = CFGMR3InsertString(pCfg, "Path", pszFilename);
733 if (VBOX_SUCCESS(rc))
734 {
735 LogFlow(("pdmR3DrvHlp_MountPrepare: caller='%s'/%d: returns %Vrc (Driver=%s)\n",
736 pDrvIns->pDrvReg->szDriverName, pDrvIns->iInstance, rc, pszCoreDriver));
737 return rc;
738 }
739 else
740 AssertMsgFailed(("Path string insert failed, rc=%Vrc\n", rc));
741 }
742 else
743 AssertMsgFailed(("Config node failed, rc=%Vrc\n", rc));
744 }
745 else
746 AssertMsgFailed(("Driver string insert failed, rc=%Vrc\n", rc));
747 CFGMR3RemoveNode(pNode);
748 }
749 else
750 AssertMsgFailed(("AttachedDriver node insert failed, rc=%Vrc\n", rc));
751
752 LogFlow(("pdmR3DrvHlp_MountPrepare: caller='%s'/%d: returns %Vrc\n",
753 pDrvIns->pDrvReg->szDriverName, pDrvIns->iInstance, rc));
754 return rc;
755}
756
757
758/** @copydoc PDMDRVHLP::pfnAssertEMT */
759static DECLCALLBACK(bool) pdmR3DrvHlp_AssertEMT(PPDMDRVINS pDrvIns, const char *pszFile, unsigned iLine, const char *pszFunction)
760{
761 PDMDRV_ASSERT_DRVINS(pDrvIns);
762 if (VM_IS_EMT(pDrvIns->Internal.s.pVM))
763 return true;
764
765 char szMsg[100];
766 RTStrPrintf(szMsg, sizeof(szMsg), "AssertEMT '%s'/%d\n", pDrvIns->pDrvReg->szDriverName, pDrvIns->iInstance);
767 AssertMsg1(szMsg, iLine, pszFile, pszFunction);
768 AssertBreakpoint();
769 VM_ASSERT_EMT(pDrvIns->Internal.s.pVM);
770 return false;
771}
772
773
774/** @copydoc PDMDRVHLP::pfnAssertOther */
775static DECLCALLBACK(bool) pdmR3DrvHlp_AssertOther(PPDMDRVINS pDrvIns, const char *pszFile, unsigned iLine, const char *pszFunction)
776{
777 PDMDRV_ASSERT_DRVINS(pDrvIns);
778 if (!VM_IS_EMT(pDrvIns->Internal.s.pVM))
779 return true;
780
781 char szMsg[100];
782 RTStrPrintf(szMsg, sizeof(szMsg), "AssertOther '%s'/%d\n", pDrvIns->pDrvReg->szDriverName, pDrvIns->iInstance);
783 AssertMsg1(szMsg, iLine, pszFile, pszFunction);
784 AssertBreakpoint();
785 VM_ASSERT_EMT(pDrvIns->Internal.s.pVM);
786 return false;
787}
788
789
790/** @copydoc PDMDRVHLP::pfnVMSetError */
791static DECLCALLBACK(int) pdmR3DrvHlp_VMSetError(PPDMDRVINS pDrvIns, int rc, RT_SRC_POS_DECL, const char *pszFormat, ...)
792{
793 PDMDRV_ASSERT_DRVINS(pDrvIns);
794 va_list args;
795 va_start(args, pszFormat);
796 int rc2 = VMSetErrorV(pDrvIns->Internal.s.pVM, rc, RT_SRC_POS_ARGS, pszFormat, args); Assert(rc2 == rc); NOREF(rc2);
797 va_end(args);
798 return rc;
799}
800
801
802/** @copydoc PDMDRVHLP::pfnVMSetErrorV */
803static DECLCALLBACK(int) pdmR3DrvHlp_VMSetErrorV(PPDMDRVINS pDrvIns, int rc, RT_SRC_POS_DECL, const char *pszFormat, va_list va)
804{
805 PDMDRV_ASSERT_DRVINS(pDrvIns);
806 int rc2 = VMSetErrorV(pDrvIns->Internal.s.pVM, rc, RT_SRC_POS_ARGS, pszFormat, va); Assert(rc2 == rc); NOREF(rc2);
807 return rc;
808}
809
810
811/** @copydoc PDMDRVHLP::pfnVMSetRuntimeError */
812static DECLCALLBACK(int) pdmR3DrvHlp_VMSetRuntimeError(PPDMDRVINS pDrvIns, bool fFatal, const char *pszErrorID, const char *pszFormat, ...)
813{
814 PDMDRV_ASSERT_DRVINS(pDrvIns);
815 va_list args;
816 va_start(args, pszFormat);
817 int rc = VMSetRuntimeErrorV(pDrvIns->Internal.s.pVM, fFatal, pszErrorID, pszFormat, args);
818 va_end(args);
819 return rc;
820}
821
822
823/** @copydoc PDMDRVHLP::pfnVMSetRuntimeErrorV */
824static DECLCALLBACK(int) pdmR3DrvHlp_VMSetRuntimeErrorV(PPDMDRVINS pDrvIns, bool fFatal, const char *pszErrorID, const char *pszFormat, va_list va)
825{
826 PDMDRV_ASSERT_DRVINS(pDrvIns);
827 int rc = VMSetRuntimeErrorV(pDrvIns->Internal.s.pVM, fFatal, pszErrorID, pszFormat, va);
828 return rc;
829}
830
831
832/** @copydoc PDMDRVHLP::pfnPDMQueueCreate */
833static DECLCALLBACK(int) pdmR3DrvHlp_PDMQueueCreate(PPDMDRVINS pDrvIns, RTUINT cbItem, RTUINT cItems, uint32_t cMilliesInterval, PFNPDMQUEUEDRV pfnCallback, PPDMQUEUE *ppQueue)
834{
835 PDMDRV_ASSERT_DRVINS(pDrvIns);
836 LogFlow(("pdmR3DrvHlp_PDMQueueCreate: caller='%s'/%d: cbItem=%d cItems=%d cMilliesInterval=%d pfnCallback=%p ppQueue=%p\n",
837 pDrvIns->pDrvReg->szDriverName, pDrvIns->iInstance, cbItem, cItems, cMilliesInterval, pfnCallback, ppQueue, ppQueue));
838 VM_ASSERT_EMT(pDrvIns->Internal.s.pVM);
839
840 int rc = PDMR3QueueCreateDriver(pDrvIns->Internal.s.pVM, pDrvIns, cbItem, cItems, cMilliesInterval, pfnCallback, ppQueue);
841
842 LogFlow(("pdmR3DrvHlp_PDMQueueCreate: caller='%s'/%d: returns %Vrc *ppQueue=%p\n", pDrvIns->pDrvReg->szDriverName, pDrvIns->iInstance, rc, *ppQueue));
843 return rc;
844}
845
846
847
848/** @copydoc PDMDRVHLP::pfnPDMPollerRegister */
849static DECLCALLBACK(int) pdmR3DrvHlp_PDMPollerRegister(PPDMDRVINS pDrvIns, PFNPDMDRVPOLLER pfnPoller)
850{
851 PDMDRV_ASSERT_DRVINS(pDrvIns);
852 LogFlow(("pdmR3DrvHlp_PDMPollerRegister: caller='%s'/%d: pfnPoller=%p\n",
853 pDrvIns->pDrvReg->szDriverName, pDrvIns->iInstance, pfnPoller));
854 VM_ASSERT_EMT(pDrvIns->Internal.s.pVM);
855
856 int rc = VINF_SUCCESS;
857 PVM pVM = pDrvIns->Internal.s.pVM;
858 if (pVM->pdm.s.cPollers < ELEMENTS(pVM->pdm.s.apfnPollers))
859 {
860 pVM->pdm.s.apfnPollers[pVM->pdm.s.cPollers] = pfnPoller;
861 pVM->pdm.s.aDrvInsPollers[pVM->pdm.s.cPollers] = pDrvIns;
862 pVM->pdm.s.cPollers++;
863 if (pVM->pdm.s.cPollers == 1)
864 TMTimerSetMillies(pVM->pdm.s.pTimerPollers, 5);
865 }
866 else
867 {
868 AssertMsgFailed(("Too many pollers!\n"));
869 rc = VERR_INTERNAL_ERROR;
870 }
871
872 LogFlow(("pdmR3DrvHlp_PDMPollerRegister: caller='%s'/%d: returns %Vrc\n", pDrvIns->pDrvReg->szDriverName, pDrvIns->iInstance, rc));
873 return rc;
874}
875
876
877/** @copydoc PDMDRVHLP::pfnTMGetVirtualFreq */
878static DECLCALLBACK(uint64_t) pdmR3DrvHlp_TMGetVirtualFreq(PPDMDRVINS pDrvIns)
879{
880 PDMDRV_ASSERT_DRVINS(pDrvIns);
881
882 return TMVirtualGetFreq(pDrvIns->Internal.s.pVM);
883}
884
885
886/** @copydoc PDMDRVHLP::pfnTMGetVirtualTime */
887static DECLCALLBACK(uint64_t) pdmR3DrvHlp_TMGetVirtualTime(PPDMDRVINS pDrvIns)
888{
889 PDMDRV_ASSERT_DRVINS(pDrvIns);
890
891 return TMVirtualGet(pDrvIns->Internal.s.pVM);
892}
893
894/** @copydoc PDMDRVHLP::pfnTMTimerCreate */
895static DECLCALLBACK(int) pdmR3DrvHlp_TMTimerCreate(PPDMDRVINS pDrvIns, TMCLOCK enmClock, PFNTMTIMERDRV pfnCallback, const char *pszDesc, PPTMTIMERHC ppTimer)
896{
897 PDMDRV_ASSERT_DRVINS(pDrvIns);
898 LogFlow(("pdmR3DrvHlp_TMTimerCreate: caller='%s'/%d: enmClock=%d pfnCallback=%p pszDesc=%p:{%s} ppTimer=%p\n",
899 pDrvIns->pDrvReg->szDriverName, pDrvIns->iInstance, enmClock, pfnCallback, pszDesc, pszDesc, ppTimer));
900
901 int rc = TMR3TimerCreateDriver(pDrvIns->Internal.s.pVM, pDrvIns, enmClock, pfnCallback, pszDesc, ppTimer);
902
903 LogFlow(("pdmR3DrvHlp_TMTimerCreate: caller='%s'/%d: returns %Vrc *ppTimer=%p\n", pDrvIns->pDrvReg->szDriverName, pDrvIns->iInstance, rc, *ppTimer));
904 return rc;
905}
906
907
908
909/** @copydoc PDMDRVHLP::pfnSSMRegister */
910static DECLCALLBACK(int) pdmR3DrvHlp_SSMRegister(PPDMDRVINS pDrvIns, const char *pszName, uint32_t u32Instance, uint32_t u32Version, size_t cbGuess,
911 PFNSSMDRVSAVEPREP pfnSavePrep, PFNSSMDRVSAVEEXEC pfnSaveExec, PFNSSMDRVSAVEDONE pfnSaveDone,
912 PFNSSMDRVLOADPREP pfnLoadPrep, PFNSSMDRVLOADEXEC pfnLoadExec, PFNSSMDRVLOADDONE pfnLoadDone)
913{
914 PDMDRV_ASSERT_DRVINS(pDrvIns);
915 VM_ASSERT_EMT(pDrvIns->Internal.s.pVM);
916 LogFlow(("pdmR3DrvHlp_SSMRegister: caller='%s'/%d: pszName=%p:{%s} u32Instance=%#x u32Version=#x cbGuess=%#x pfnSavePrep=%p pfnSaveExec=%p pfnSaveDone=%p pszLoadPrep=%p pfnLoadExec=%p pfnLoaddone=%p\n",
917 pDrvIns->pDrvReg->szDriverName, pDrvIns->iInstance, pszName, pszName, u32Instance, u32Version, cbGuess, pfnSavePrep, pfnSaveExec, pfnSaveDone, pfnLoadPrep, pfnLoadExec, pfnLoadDone));
918
919 int rc = SSMR3RegisterDriver(pDrvIns->Internal.s.pVM, pDrvIns, pszName, u32Instance, u32Version, cbGuess,
920 pfnSavePrep, pfnSaveExec, pfnSaveDone,
921 pfnLoadPrep, pfnLoadExec, pfnLoadDone);
922
923 LogFlow(("pdmR3DrvHlp_SSMRegister: caller='%s'/%d: returns %Vrc\n", pDrvIns->pDrvReg->szDriverName, pDrvIns->iInstance, rc));
924 return rc;
925}
926
927
928/** @copydoc PDMDRVHLP::pfnSSMDeregister */
929static DECLCALLBACK(int) pdmR3DrvHlp_SSMDeregister(PPDMDRVINS pDrvIns, const char *pszName, uint32_t u32Instance)
930{
931 PDMDRV_ASSERT_DRVINS(pDrvIns);
932 VM_ASSERT_EMT(pDrvIns->Internal.s.pVM);
933 LogFlow(("pdmR3DrvHlp_SSMDeregister: caller='%s'/%d: pszName=%p:{%s} u32Instance=%#x\n",
934 pDrvIns->pDrvReg->szDriverName, pDrvIns->iInstance, pszName, pszName, u32Instance));
935
936 int rc = SSMR3DeregisterDriver(pDrvIns->Internal.s.pVM, pDrvIns, pszName, u32Instance);
937
938 LogFlow(("pdmR3DrvHlp_SSMDeregister: caller='%s'/%d: returns %Vrc\n", pDrvIns->pDrvReg->szDriverName, pDrvIns->iInstance, rc));
939 return rc;
940}
941
942
943/** @copydoc PDMDRVHLP::pfnSTAMRegister */
944static DECLCALLBACK(void) pdmR3DrvHlp_STAMRegister(PPDMDRVINS pDrvIns, void *pvSample, STAMTYPE enmType, const char *pszName, STAMUNIT enmUnit, const char *pszDesc)
945{
946 PDMDRV_ASSERT_DRVINS(pDrvIns);
947 VM_ASSERT_EMT(pDrvIns->Internal.s.pVM);
948
949 STAM_REG(pDrvIns->Internal.s.pVM, pvSample, enmType, pszName, enmUnit, pszDesc);
950 /** @todo track the samples so they can be dumped & deregistered when the driver instance is destroyed.
951 * For now we just have to be careful not to use this call for drivers which can be unloaded. */
952}
953
954
955/** @copydoc PDMDRVHLP::pfnSTAMRegisterF */
956static DECLCALLBACK(void) pdmR3DrvHlp_STAMRegisterF(PPDMDRVINS pDrvIns, void *pvSample, STAMTYPE enmType, STAMVISIBILITY enmVisibility,
957 STAMUNIT enmUnit, const char *pszDesc, const char *pszName, ...)
958{
959 PDMDRV_ASSERT_DRVINS(pDrvIns);
960 VM_ASSERT_EMT(pDrvIns->Internal.s.pVM);
961
962 va_list args;
963 va_start(args, pszName);
964 int rc = STAMR3RegisterV(pDrvIns->Internal.s.pVM, pvSample, enmType, enmVisibility, enmUnit, pszDesc, pszName, args);
965 va_end(args);
966 AssertRC(rc);
967}
968
969
970/** @copydoc PDMDRVHLP::pfnSTAMRegisterV */
971static DECLCALLBACK(void) pdmR3DrvHlp_STAMRegisterV(PPDMDRVINS pDrvIns, void *pvSample, STAMTYPE enmType, STAMVISIBILITY enmVisibility,
972 STAMUNIT enmUnit, const char *pszDesc, const char *pszName, va_list args)
973{
974 PDMDRV_ASSERT_DRVINS(pDrvIns);
975 VM_ASSERT_EMT(pDrvIns->Internal.s.pVM);
976
977 int rc = STAMR3RegisterV(pDrvIns->Internal.s.pVM, pvSample, enmType, enmVisibility, enmUnit, pszDesc, pszName, args);
978 AssertRC(rc);
979}
980
981
982/** @copydoc PDMDRVHLP::pfnSUPCallVMMR0Ex */
983static DECLCALLBACK(int) pdmR3DrvHlp_SUPCallVMMR0Ex(PPDMDRVINS pDrvIns, unsigned uOperation, void *pvArg, unsigned cbArg)
984{
985 PDMDRV_ASSERT_DRVINS(pDrvIns);
986 LogFlow(("pdmR3DrvHlp_SSMCallVMMR0Ex: caller='%s'/%d: uOperation=%u pvArg=%p cbArg=%d\n",
987 pDrvIns->pDrvReg->szDriverName, pDrvIns->iInstance, uOperation, pvArg, cbArg));
988 int rc;
989 if ( uOperation >= VMMR0_DO_SRV_START
990 && uOperation < VMMR0_DO_SRV_END)
991 rc = SUPCallVMMR0Ex(pDrvIns->Internal.s.pVM->pVMR0, uOperation, pvArg, cbArg);
992 else
993 {
994 AssertMsgFailed(("Invalid uOperation=%u\n", uOperation));
995 rc = VERR_INVALID_PARAMETER;
996 }
997
998 LogFlow(("pdmR3DrvHlp_SSMDeregister: caller='%s'/%d: returns %Vrc\n", pDrvIns->pDrvReg->szDriverName, pDrvIns->iInstance, rc));
999 return rc;
1000}
1001
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