PDMDriver.cpp revision 06dc6eb95cf33b2b83f0d07c602d1ca20a575663
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync/* $Id$ */
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync/** @file
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync * PDM - Pluggable Device and Driver Manager, Driver parts.
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync */
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync/*
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync * Copyright (C) 2006-2007 Sun Microsystems, Inc.
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync *
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync * available from http://www.virtualbox.org. This file is free software;
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync * you can redistribute it and/or modify it under the terms of the GNU
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync * General Public License (GPL) as published by the Free Software
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync *
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync * Clara, CA 95054 USA or visit http://www.sun.com if you need
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync * additional information or have any questions.
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync */
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync/*******************************************************************************
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync* Header Files *
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync*******************************************************************************/
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync#define LOG_GROUP LOG_GROUP_PDM_DRIVER
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync#include "PDMInternal.h"
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync#include <VBox/pdm.h>
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync#include <VBox/mm.h>
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync#include <VBox/cfgm.h>
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync#include <VBox/vmm.h>
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync#include <VBox/sup.h>
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync#include <VBox/vm.h>
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync#include <VBox/version.h>
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync#include <VBox/err.h>
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync#include <VBox/log.h>
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync#include <iprt/assert.h>
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync#include <iprt/thread.h>
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync#include <iprt/string.h>
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync#include <iprt/asm.h>
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync#include <iprt/alloc.h>
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync#include <iprt/path.h>
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync/*******************************************************************************
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync* Structures and Typedefs *
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync*******************************************************************************/
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync/**
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync * Internal callback structure pointer.
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync *
2c95722bb302f4ce9454d04324b09314c0ccc038vboxsync * The main purpose is to define the extra data we associate
2c95722bb302f4ce9454d04324b09314c0ccc038vboxsync * with PDMDRVREGCB so we can find the VM instance and so on.
2c95722bb302f4ce9454d04324b09314c0ccc038vboxsync */
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsynctypedef struct PDMDRVREGCBINT
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync{
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync /** The callback structure. */
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync PDMDRVREGCB Core;
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync /** A bit of padding. */
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync uint32_t u32[4];
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync /** VM Handle. */
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync PVM pVM;
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync} PDMDRVREGCBINT, *PPDMDRVREGCBINT;
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsynctypedef const PDMDRVREGCBINT *PCPDMDRVREGCBINT;
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync/*******************************************************************************
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync* Internal Functions *
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync*******************************************************************************/
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsyncstatic DECLCALLBACK(int) pdmR3DrvRegister(PCPDMDRVREGCB pCallbacks, PCPDMDRVREG pReg);
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsyncstatic int pdmR3DrvLoad(PVM pVM, PPDMDRVREGCBINT pRegCB, const char *pszFilename, const char *pszName);
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync/**
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync * Register external drivers
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync *
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync * @returns VBox status code.
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync * @param pVM The VM to operate on.
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync * @param pfnCallback Driver registration callback
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync */
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsyncVMMR3DECL(int) PDMR3RegisterDrivers(PVM pVM, FNPDMVBOXDRIVERSREGISTER pfnCallback)
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync{
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync /*
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync * The registration callbacks.
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync */
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync PDMDRVREGCBINT RegCB;
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync RegCB.Core.u32Version = PDM_DRVREG_CB_VERSION;
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync RegCB.Core.pfnRegister = pdmR3DrvRegister;
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync RegCB.pVM = pVM;
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync int rc = pfnCallback(&RegCB.Core, VBOX_VERSION);
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync if (RT_FAILURE(rc))
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync AssertMsgFailed(("VBoxDriversRegister failed with rc=%Rrc\n"));
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync return rc;
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync}
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync/**
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync * This function will initialize the drivers for this VM instance.
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync *
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync * First of all this mean loading the builtin drivers and letting them
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync * register themselves. Beyond that any additional driver modules are
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync * loaded and called for registration.
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync *
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync * @returns VBox status code.
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync * @param pVM VM Handle.
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync */
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsyncint pdmR3DrvInit(PVM pVM)
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync{
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync LogFlow(("pdmR3DrvInit:\n"));
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync AssertRelease(!(RT_OFFSETOF(PDMDRVINS, achInstanceData) & 15));
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync PPDMDRVINS pDrvInsAssert;
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync AssertRelease(sizeof(pDrvInsAssert->Internal.s) <= sizeof(pDrvInsAssert->Internal.padding));
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync /*
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync * The registration callbacks.
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync */
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync PDMDRVREGCBINT RegCB;
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync RegCB.Core.u32Version = PDM_DRVREG_CB_VERSION;
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync RegCB.Core.pfnRegister = pdmR3DrvRegister;
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync RegCB.pVM = pVM;
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync /*
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync * Load the builtin module
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync */
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync PCFGMNODE pDriversNode = CFGMR3GetChild(CFGMR3GetRoot(pVM), "PDM/Drivers");
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync bool fLoadBuiltin;
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync int rc = CFGMR3QueryBool(pDriversNode, "LoadBuiltin", &fLoadBuiltin);
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync if (rc == VERR_CFGM_VALUE_NOT_FOUND || rc == VERR_CFGM_NO_PARENT)
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync fLoadBuiltin = true;
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync else if (RT_FAILURE(rc))
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync {
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync AssertMsgFailed(("Configuration error: Querying boolean \"LoadBuiltin\" failed with %Rrc\n", rc));
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync return rc;
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync }
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync if (fLoadBuiltin)
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync {
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync /* make filename */
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync char *pszFilename = pdmR3FileR3("VBoxDD", /*fShared=*/true);
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync if (!pszFilename)
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync return VERR_NO_TMP_MEMORY;
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync rc = pdmR3DrvLoad(pVM, &RegCB, pszFilename, "VBoxDD");
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync RTMemTmpFree(pszFilename);
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync if (RT_FAILURE(rc))
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync return rc;
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync }
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync /*
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync * Load additional driver modules.
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync */
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync for (PCFGMNODE pCur = CFGMR3GetFirstChild(pDriversNode); pCur; pCur = CFGMR3GetNextChild(pCur))
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync {
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync /*
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync * Get the name and path.
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync */
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync char szName[PDMMOD_NAME_LEN];
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync rc = CFGMR3GetName(pCur, &szName[0], sizeof(szName));
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync if (rc == VERR_CFGM_NOT_ENOUGH_SPACE)
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync {
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync AssertMsgFailed(("configuration error: The module name is too long, cchName=%zu.\n", CFGMR3GetNameLen(pCur)));
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync return VERR_PDM_MODULE_NAME_TOO_LONG;
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync }
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync else if (RT_FAILURE(rc))
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync {
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync AssertMsgFailed(("CFGMR3GetName -> %Rrc.\n", rc));
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync return rc;
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync }
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync /* the path is optional, if no path the module name + path is used. */
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync char szFilename[RTPATH_MAX];
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync rc = CFGMR3QueryString(pCur, "Path", &szFilename[0], sizeof(szFilename));
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync if (rc == VERR_CFGM_VALUE_NOT_FOUND || rc == VERR_CFGM_NO_PARENT)
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync strcpy(szFilename, szName);
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync else if (RT_FAILURE(rc))
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync {
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync AssertMsgFailed(("configuration error: Failure to query the module path, rc=%Rrc.\n", rc));
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync return rc;
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync }
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync /* prepend path? */
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync if (!RTPathHavePath(szFilename))
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync {
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync char *psz = pdmR3FileR3(szFilename);
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync if (!psz)
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync return VERR_NO_TMP_MEMORY;
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync size_t cch = strlen(psz) + 1;
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync if (cch > sizeof(szFilename))
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync {
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync RTMemTmpFree(psz);
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync AssertMsgFailed(("Filename too long! cch=%d '%s'\n", cch, psz));
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync return VERR_FILENAME_TOO_LONG;
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync }
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync memcpy(szFilename, psz, cch);
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync RTMemTmpFree(psz);
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync }
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync /*
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync * Load the module and register it's drivers.
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync */
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync rc = pdmR3DrvLoad(pVM, &RegCB, szFilename, szName);
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync if (RT_FAILURE(rc))
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync return rc;
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync }
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync LogFlow(("pdmR3DrvInit: returns VINF_SUCCESS\n"));
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync return VINF_SUCCESS;
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync}
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync/**
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync * Loads one driver module and call the registration entry point.
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync *
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync * @returns VBox status code.
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync * @param pVM VM handle.
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync * @param pRegCB The registration callback stuff.
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync * @param pszFilename Module filename.
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync * @param pszName Module name.
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync */
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsyncstatic int pdmR3DrvLoad(PVM pVM, PPDMDRVREGCBINT pRegCB, const char *pszFilename, const char *pszName)
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync{
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync /*
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync * Load it.
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync */
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync int rc = pdmR3LoadR3U(pVM->pUVM, pszFilename, pszName);
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync if (RT_SUCCESS(rc))
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync {
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync /*
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync * Get the registration export and call it.
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync */
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync FNPDMVBOXDRIVERSREGISTER *pfnVBoxDriversRegister;
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync rc = PDMR3LdrGetSymbolR3(pVM, pszName, "VBoxDriversRegister", (void **)&pfnVBoxDriversRegister);
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync if (RT_SUCCESS(rc))
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync {
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync Log(("PDM: Calling VBoxDriversRegister (%p) of %s (%s)\n", pfnVBoxDriversRegister, pszName, pszFilename));
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync rc = pfnVBoxDriversRegister(&pRegCB->Core, VBOX_VERSION);
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync if (RT_SUCCESS(rc))
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync Log(("PDM: Successfully loaded driver module %s (%s).\n", pszName, pszFilename));
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync else
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync AssertMsgFailed(("VBoxDriversRegister failed with rc=%Rrc\n"));
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync }
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync else
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync {
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync AssertMsgFailed(("Failed to locate 'VBoxDriversRegister' in %s (%s) rc=%Rrc\n", pszName, pszFilename, rc));
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync if (rc == VERR_SYMBOL_NOT_FOUND)
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync rc = VERR_PDM_NO_REGISTRATION_EXPORT;
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync }
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync }
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync else
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync AssertMsgFailed(("Failed to load %s (%s) rc=%Rrc!\n", pszName, pszFilename, rc));
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync return rc;
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync}
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync/** @interface_method_impl{PDMDRVREGCB,pfnRegister} */
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsyncstatic DECLCALLBACK(int) pdmR3DrvRegister(PCPDMDRVREGCB pCallbacks, PCPDMDRVREG pReg)
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync{
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync /*
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync * Validate the registration structure.
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync */
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync AssertPtrReturn(pReg, VERR_INVALID_POINTER);
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync AssertMsgReturn(pReg->u32Version == PDM_DRVREG_VERSION,
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync ("%#x\n", pReg->u32Version),
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync VERR_PDM_UNKNOWN_DRVREG_VERSION);
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync AssertReturn(pReg->szName[0], VERR_PDM_INVALID_DRIVER_REGISTRATION);
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync AssertMsgReturn(memchr(pReg->szName, '\0', sizeof(pReg->szName)),
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync (".*s\n", sizeof(pReg->szName), pReg->szName),
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync VERR_PDM_INVALID_DRIVER_REGISTRATION);
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync AssertMsgReturn( !(pReg->fFlags & PDM_DRVREG_FLAGS_R0)
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync || ( pReg->szR0Mod[0]
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync && memchr(pReg->szR0Mod, '\0', sizeof(pReg->szR0Mod))),
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync ("%s: %.*s\n", pReg->szName, sizeof(pReg->szR0Mod), pReg->szR0Mod),
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync VERR_PDM_INVALID_DRIVER_REGISTRATION);
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync AssertMsgReturn( !(pReg->fFlags & PDM_DRVREG_FLAGS_RC)
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync || ( pReg->szRCMod[0]
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync && memchr(pReg->szRCMod, '\0', sizeof(pReg->szRCMod))),
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync ("%s: %.*s\n", pReg->szName, sizeof(pReg->szRCMod), pReg->szRCMod),
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync VERR_PDM_INVALID_DRIVER_REGISTRATION);
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync AssertMsgReturn(VALID_PTR(pReg->pszDescription),
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync ("%s: %p\n", pReg->szName, pReg->pszDescription),
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync VERR_PDM_INVALID_DRIVER_REGISTRATION);
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync AssertMsgReturn(!(pReg->fFlags & ~(PDM_DRVREG_FLAGS_HOST_BITS_MASK | PDM_DRVREG_FLAGS_R0 | PDM_DRVREG_FLAGS_RC)),
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync ("%s: %#x\n", pReg->szName, pReg->fFlags),
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync VERR_PDM_INVALID_DRIVER_REGISTRATION);
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync AssertMsgReturn((pReg->fFlags & PDM_DRVREG_FLAGS_HOST_BITS_MASK) == PDM_DRVREG_FLAGS_HOST_BITS_DEFAULT,
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync ("%s: %#x\n", pReg->szName, pReg->fFlags),
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync VERR_PDM_INVALID_DRIVER_HOST_BITS);
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync AssertMsgReturn(pReg->cMaxInstances > 0,
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync ("%s: %#x\n", pReg->szName, pReg->cMaxInstances),
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync VERR_PDM_INVALID_DRIVER_REGISTRATION);
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync AssertMsgReturn(pReg->cbInstance <= _1M,
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync ("%s: %#x\n", pReg->szName, pReg->cbInstance),
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync VERR_PDM_INVALID_DRIVER_REGISTRATION);
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync AssertMsgReturn(VALID_PTR(pReg->pfnConstruct),
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync ("%s: %p\n", pReg->szName, pReg->pfnConstruct),
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync VERR_PDM_INVALID_DRIVER_REGISTRATION);
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync AssertMsgReturn(VALID_PTR(pReg->pfnRelocate) || !(pReg->fFlags & PDM_DRVREG_FLAGS_RC),
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync ("%s: %#x\n", pReg->szName, pReg->cbInstance),
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync VERR_PDM_INVALID_DRIVER_REGISTRATION);
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync AssertMsgReturn(pReg->pfnSoftReset == NULL,
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync ("%s: %p\n", pReg->szName, pReg->pfnSoftReset),
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync VERR_PDM_INVALID_DRIVER_REGISTRATION);
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync AssertMsgReturn(pReg->u32VersionEnd == PDM_DRVREG_VERSION,
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync ("%s: #x\n", pReg->szName, pReg->u32VersionEnd),
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync VERR_PDM_INVALID_DRIVER_REGISTRATION);
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync /*
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync * Check for duplicate and find FIFO entry at the same time.
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync */
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync PCPDMDRVREGCBINT pRegCB = (PCPDMDRVREGCBINT)pCallbacks;
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync PPDMDRV pDrvPrev = NULL;
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync PPDMDRV pDrv = pRegCB->pVM->pdm.s.pDrvs;
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync for (; pDrv; pDrvPrev = pDrv, pDrv = pDrv->pNext)
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync {
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync if (!strcmp(pDrv->pReg->szName, pReg->szName))
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync {
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync AssertMsgFailed(("Driver '%s' already exists\n", pReg->szName));
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync return VERR_PDM_DRIVER_NAME_CLASH;
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync }
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync }
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync /*
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync * Allocate new driver structure and insert it into the list.
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync */
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync pDrv = (PPDMDRV)MMR3HeapAlloc(pRegCB->pVM, MM_TAG_PDM_DRIVER, sizeof(*pDrv));
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync if (pDrv)
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync {
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync pDrv->pNext = NULL;
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync pDrv->cInstances = 0;
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync pDrv->iNextInstance = 0;
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync pDrv->pReg = pReg;
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync if (pDrvPrev)
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync pDrvPrev->pNext = pDrv;
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync else
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync pRegCB->pVM->pdm.s.pDrvs = pDrv;
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync Log(("PDM: Registered driver '%s'\n", pReg->szName));
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync return VINF_SUCCESS;
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync }
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync return VERR_NO_MEMORY;
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync}
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync/**
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync * Lookups a driver structure by name.
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync * @internal
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync */
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsyncPPDMDRV pdmR3DrvLookup(PVM pVM, const char *pszName)
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync{
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync for (PPDMDRV pDrv = pVM->pdm.s.pDrvs; pDrv; pDrv = pDrv->pNext)
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync if (!strcmp(pDrv->pReg->szName, pszName))
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync return pDrv;
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync return NULL;
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync}
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync/**
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync * Instantiate a driver.
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync *
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync * @returns VBox status code, including informational statuses.
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync *
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync * @param pVM The VM handle.
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync * @param pNode The CFGM node for the driver.
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync * @param pBaseInterface The base interface.
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync * @param pDrvAbove The driver above it. NULL if it's the top-most
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync * driver.
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync * @param pLun The LUN the driver is being attached to. NULL
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync * if we're instantiating a driver chain before
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync * attaching it - untested.
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync * @param ppBaseInterface Where to return the pointer to the base
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync * interface of the newly created driver.
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync *
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync * @remarks Recursive calls to this function is normal as the drivers will
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync * attach to anything below them during the pfnContruct call.
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync */
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsyncint pdmR3DrvInstantiate(PVM pVM, PCFGMNODE pNode, PPDMIBASE pBaseInterface, PPDMDRVINS pDrvAbove,
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync PPDMLUN pLun, PPDMIBASE *ppBaseInterface)
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync{
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync Assert(!pDrvAbove || !pDrvAbove->Internal.s.pDown);
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync Assert(!pDrvAbove || !pDrvAbove->pDownBase);
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync Assert(pBaseInterface->pfnQueryInterface(pBaseInterface, PDMIBASE_IID) == pBaseInterface);
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync /*
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync * Find the driver.
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync */
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync char *pszName;
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync int rc = CFGMR3QueryStringAlloc(pNode, "Driver", &pszName);
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync if (RT_SUCCESS(rc))
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync {
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync PPDMDRV pDrv = pdmR3DrvLookup(pVM, pszName);
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync MMR3HeapFree(pszName);
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync if ( pDrv
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync && pDrv->cInstances < pDrv->pReg->cMaxInstances)
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync {
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync /* config node */
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync PCFGMNODE pConfigNode = CFGMR3GetChild(pNode, "Config");
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync if (!pConfigNode)
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync rc = CFGMR3InsertNode(pNode, "Config", &pConfigNode);
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync if (RT_SUCCESS(rc))
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync {
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync CFGMR3SetRestrictedRoot(pConfigNode);
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync /*
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync * Allocate the driver instance.
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync */
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync size_t cb = RT_OFFSETOF(PDMDRVINS, achInstanceData[pDrv->pReg->cbInstance]);
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync cb = RT_ALIGN_Z(cb, 16);
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync bool const fHyperHeap = !!(pDrv->pReg->fFlags & (PDM_DRVREG_FLAGS_R0 | PDM_DRVREG_FLAGS_RC));
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync PPDMDRVINS pNew;
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync if (fHyperHeap)
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync rc = MMHyperAlloc(pVM, cb, 64, MM_TAG_PDM_DRIVER, (void **)&pNew);
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync else
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync rc = MMR3HeapAllocZEx(pVM, MM_TAG_PDM_DRIVER, cb, (void **)&pNew);
67c73271505adae0686ddbc74eaeef778ef16792vboxsync if (pNew)
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync {
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync /*
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync * Initialize the instance structure (declaration order).
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync */
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync pNew->u32Version = PDM_DRVINS_VERSION;
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync pNew->Internal.s.pUp = pDrvAbove ? pDrvAbove : NULL;
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync //pNew->Internal.s.pDown = NULL;
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync pNew->Internal.s.pLun = pLun;
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync pNew->Internal.s.pDrv = pDrv;
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync pNew->Internal.s.pVMR3 = pVM;
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync pNew->Internal.s.pVMR0 = pDrv->pReg->fFlags & PDM_DRVREG_FLAGS_R0 ? pVM->pVMR0 : NIL_RTR0PTR;
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync pNew->Internal.s.pVMRC = pDrv->pReg->fFlags & PDM_DRVREG_FLAGS_RC ? pVM->pVMRC : NIL_RTRCPTR;
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync //pNew->Internal.s.fDetaching = false;
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync pNew->Internal.s.fVMSuspended = true;
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync //pNew->Internal.s.fVMReset = false;
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync pNew->Internal.s.fHyperHeap = fHyperHeap;
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync //pNew->Internal.s.pfnAsyncNotify = NULL;
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync pNew->Internal.s.pCfgHandle = pNode;
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync pNew->pReg = pDrv->pReg;
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync pNew->pCfg = pConfigNode;
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync pNew->iInstance = pDrv->iNextInstance;
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync pNew->pUpBase = pBaseInterface;
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync Assert(!pDrvAbove || pBaseInterface == &pDrvAbove->IBase);
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync //pNew->pDownBase = NULL;
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync //pNew->IBase.pfnQueryInterface = NULL;
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync pNew->pHlpR3 = &g_pdmR3DrvHlp;
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync pNew->pvInstanceDataR3 = &pNew->achInstanceData[0];
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync if (pDrv->pReg->fFlags & PDM_DRVREG_FLAGS_R0)
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync {
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync pNew->pvInstanceDataR0 = MMHyperR3ToR0(pVM, &pNew->achInstanceData[0]);
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync rc = PDMR3LdrGetSymbolR0(pVM, NULL, "g_pdmR0DrvHlp", &pNew->pHlpR0);
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync AssertReleaseRCReturn(rc, rc);
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync }
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync if (pDrv->pReg->fFlags & PDM_DRVREG_FLAGS_RC)
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync {
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync pNew->pvInstanceDataR0 = MMHyperR3ToRC(pVM, &pNew->achInstanceData[0]);
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync rc = PDMR3LdrGetSymbolRC(pVM, NULL, "g_pdmRCDrvHlp", &pNew->pHlpRC);
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync AssertReleaseRCReturn(rc, rc);
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync }
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync pDrv->iNextInstance++;
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync pDrv->cInstances++;
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync /*
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync * Link with it with the driver above / LUN.
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync */
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync if (pDrvAbove)
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync {
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync pDrvAbove->pDownBase = &pNew->IBase;
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync pDrvAbove->Internal.s.pDown = pNew;
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync }
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync else if (pLun)
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync pLun->pTop = pNew;
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync if (pLun)
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync pLun->pBottom = pNew;
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync /*
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync * Invoke the constructor.
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync */
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync rc = pDrv->pReg->pfnConstruct(pNew, pNew->pCfg, 0 /*fFlags*/);
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync if (RT_SUCCESS(rc))
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync {
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync AssertPtr(pNew->IBase.pfnQueryInterface);
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync Assert(pNew->IBase.pfnQueryInterface(&pNew->IBase, PDMIBASE_IID) == &pNew->IBase);
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync /* Success! */
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync *ppBaseInterface = &pNew->IBase;
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync if (pLun)
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync Log(("PDM: Attached driver %p:'%s'/%d to LUN#%d on device '%s'/%d, pDrvAbove=%p:'%s'/%d\n",
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync pNew, pDrv->pReg->szName, pNew->iInstance,
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync pLun->iLun,
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync pLun->pDevIns ? pLun->pDevIns->pReg->szName : pLun->pUsbIns->pReg->szName,
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync pLun->pDevIns ? pLun->pDevIns->iInstance : pLun->pUsbIns->iInstance,
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync pDrvAbove, pDrvAbove ? pDrvAbove->pReg->szName : "", pDrvAbove ? pDrvAbove->iInstance : -1));
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync else
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync Log(("PDM: Attached driver %p:'%s'/%d, pDrvAbove=%p:'%s'/%d\n",
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync pNew, pDrv->pReg->szName, pNew->iInstance,
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync pDrvAbove, pDrvAbove ? pDrvAbove->pReg->szName : "", pDrvAbove ? pDrvAbove->iInstance : -1));
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync }
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync else
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync pdmR3DrvDestroyChain(pNew, PDM_TACH_FLAGS_NO_CALLBACKS);
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync }
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync else
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync {
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync AssertMsgFailed(("Failed to allocate %d bytes for instantiating driver '%s'\n", cb, pszName));
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync rc = VERR_NO_MEMORY;
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync }
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync }
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync else
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync AssertMsgFailed(("Failed to create Config node! rc=%Rrc\n", rc));
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync }
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync else if (pDrv)
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync {
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync AssertMsgFailed(("Too many instances of driver '%s', max is %u\n", pszName, pDrv->pReg->cMaxInstances));
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync rc = VERR_PDM_TOO_MANY_DRIVER_INSTANCES;
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync }
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync else
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync {
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync AssertMsgFailed(("Driver '%s' wasn't found!\n", pszName));
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync rc = VERR_PDM_DRIVER_NOT_FOUND;
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync }
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync }
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync else
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync {
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync AssertMsgFailed(("Query for string value of \"Driver\" -> %Rrc\n", rc));
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync if (rc == VERR_CFGM_VALUE_NOT_FOUND)
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync rc = VERR_PDM_CFG_MISSING_DRIVER_NAME;
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync }
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync return rc;
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync}
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync/**
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync * Detaches a driver from whatever it's attached to.
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync * This will of course lead to the destruction of the driver and all drivers below it in the chain.
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync *
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync * @returns VINF_SUCCESS
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync * @param pDrvIns The driver instance to detach.
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync * @param fFlags Flags, combination of the PDMDEVATT_FLAGS_* \#defines.
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync */
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsyncint pdmR3DrvDetach(PPDMDRVINS pDrvIns, uint32_t fFlags)
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync{
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync PDMDRV_ASSERT_DRVINS(pDrvIns);
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync LogFlow(("pdmR3DrvDetach: pDrvIns=%p '%s'/%d\n", pDrvIns, pDrvIns->pReg->szName, pDrvIns->iInstance));
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync VM_ASSERT_EMT(pDrvIns->Internal.s.pVMR3);
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync /*
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync * Check that we're not doing this recursively, that could have unwanted sideeffects!
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync */
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync if (pDrvIns->Internal.s.fDetaching)
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync {
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync AssertMsgFailed(("Recursive detach! '%s'/%d\n", pDrvIns->pReg->szName, pDrvIns->iInstance));
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync return VINF_SUCCESS; }
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync /*
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync * Check that we actually can detach this instance.
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync * The requirement is that the driver/device above has a detach method.
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync */
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync if (pDrvIns->Internal.s.pUp
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync ? !pDrvIns->Internal.s.pUp->pReg->pfnDetach
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync : !pDrvIns->Internal.s.pLun->pDevIns->pReg->pfnDetach)
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync {
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync AssertMsgFailed(("Cannot detach driver instance because the driver/device above doesn't support it!\n"));
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync return VERR_PDM_DRIVER_DETACH_NOT_POSSIBLE;
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync }
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync /*
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync * Join paths with pdmR3DrvDestroyChain.
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync */
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync pdmR3DrvDestroyChain(pDrvIns, fFlags);
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync return VINF_SUCCESS;
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync}
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync/**
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync * Destroys a driver chain starting with the specified driver.
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync *
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync * This is used when unplugging a device at run time.
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync *
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync * @param pDrvIns Pointer to the driver instance to start with.
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync * @param fFlags PDM_TACH_FLAGS_NOT_HOT_PLUG, PDM_TACH_FLAGS_NO_CALLBACKS
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync * or 0.
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync */
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsyncvoid pdmR3DrvDestroyChain(PPDMDRVINS pDrvIns, uint32_t fFlags)
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync{
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync PVM pVM = pDrvIns->Internal.s.pVMR3;
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync VM_ASSERT_EMT(pVM);
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync /*
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync * Detach the bottommost driver until we've detached pDrvIns.
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync */
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync pDrvIns->Internal.s.fDetaching = true;
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync PPDMDRVINS pCur;
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync do
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync {
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync /* find the driver to detach. */
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync pCur = pDrvIns;
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync while (pCur->Internal.s.pDown)
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync pCur = pCur->Internal.s.pDown;
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync LogFlow(("pdmR3DrvDestroyChain: pCur=%p '%s'/%d\n", pCur, pCur->pReg->szName, pCur->iInstance));
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync /*
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync * Unlink it and notify parent.
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync */
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync pCur->Internal.s.fDetaching = true;
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync PPDMLUN pLun = pCur->Internal.s.pLun;
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync Assert(pLun->pBottom == pCur);
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync pLun->pBottom = pCur->Internal.s.pUp;
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync if (pCur->Internal.s.pUp)
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync {
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync /* driver parent */
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync PPDMDRVINS pParent = pCur->Internal.s.pUp;
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync pCur->Internal.s.pUp = NULL;
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync pParent->Internal.s.pDown = NULL;
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync if (!(fFlags & PDM_TACH_FLAGS_NO_CALLBACKS) && pParent->pReg->pfnDetach)
ae41886ba231ade1b868dd32ff24ee49813ebbabvboxsync pParent->pReg->pfnDetach(pParent, fFlags);
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsync
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsync pParent->pDownBase = NULL;
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsync }
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsync else
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsync {
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsync /* device parent */
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsync Assert(pLun->pTop == pCur);
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsync pLun->pTop = NULL;
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsync if (!(fFlags & PDM_TACH_FLAGS_NO_CALLBACKS) && pLun->pDevIns->pReg->pfnDetach)
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsync pLun->pDevIns->pReg->pfnDetach(pLun->pDevIns, pLun->iLun, fFlags);
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsync }
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsync
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsync /*
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsync * Call destructor.
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsync */
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsync pCur->pUpBase = NULL;
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsync if (pCur->pReg->pfnDestruct)
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsync pCur->pReg->pfnDestruct(pCur);
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsync pCur->Internal.s.pDrv->cInstances--;
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsync
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsync /*
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsync * Free all resources allocated by the driver.
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsync */
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsync /* Queues. */
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsync int rc = PDMR3QueueDestroyDriver(pVM, pCur);
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsync AssertRC(rc);
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsync
b377a71756cce9f39d25b561f72bfa33ce8a39devboxsync /* Timers. */
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsync rc = TMR3TimerDestroyDriver(pVM, pCur);
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsync AssertRC(rc);
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsync
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsync /* SSM data units. */
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsync rc = SSMR3DeregisterDriver(pVM, pCur, NULL, 0);
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsync AssertRC(rc);
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsync
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsync /* PDM threads. */
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsync rc = pdmR3ThreadDestroyDriver(pVM, pCur);
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsync AssertRC(rc);
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsync
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsync /* Finally, the driver it self. */
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsync bool fHyperHeap = pCur->Internal.s.fHyperHeap;
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsync ASMMemFill32(pCur, RT_OFFSETOF(PDMDRVINS, achInstanceData[pCur->pReg->cbInstance]), 0xdeadd0d0);
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsync if (fHyperHeap)
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsync MMHyperFree(pVM, pCur);
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsync else
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsync MMR3HeapFree(pCur);
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsync
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsync } while (pCur != pDrvIns);
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsync}
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsync
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsync
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsync
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsync
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsync/** @name Driver Helpers
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsync * @{
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsync */
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsync
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsync/** @interface_method_impl{PDMDRVHLP,pfnAttach} */
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsyncstatic DECLCALLBACK(int) pdmR3DrvHlp_Attach(PPDMDRVINS pDrvIns, uint32_t fFlags, PPDMIBASE *ppBaseInterface)
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsync{
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsync PDMDRV_ASSERT_DRVINS(pDrvIns);
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsync PVM pVM = pDrvIns->Internal.s.pVMR3;
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsync VM_ASSERT_EMT(pVM);
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsync LogFlow(("pdmR3DrvHlp_Attach: caller='%s'/%d: fFlags=%#x\n", pDrvIns->pReg->szName, pDrvIns->iInstance, fFlags));
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsync Assert(!(fFlags & ~(PDM_TACH_FLAGS_NOT_HOT_PLUG)));
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsync
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsync /*
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsync * Check that there isn't anything attached already.
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsync */
b377a71756cce9f39d25b561f72bfa33ce8a39devboxsync int rc;
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsync if (!pDrvIns->Internal.s.pDown)
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsync {
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsync Assert(pDrvIns->Internal.s.pLun->pBottom == pDrvIns);
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsync
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsync /*
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsync * Get the attached driver configuration.
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsync */
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsync PCFGMNODE pNode = CFGMR3GetChild(pDrvIns->Internal.s.pCfgHandle, "AttachedDriver");
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsync if (pNode)
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsync rc = pdmR3DrvInstantiate(pVM, pNode, &pDrvIns->IBase, pDrvIns, pDrvIns->Internal.s.pLun, ppBaseInterface);
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsync else
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsync rc = VERR_PDM_NO_ATTACHED_DRIVER;
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsync }
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsync else
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsync {
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsync AssertMsgFailed(("Already got a driver attached. The driver should keep track of such things!\n"));
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsync rc = VERR_PDM_DRIVER_ALREADY_ATTACHED;
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsync }
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsync
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsync LogFlow(("pdmR3DrvHlp_Attach: caller='%s'/%d: return %Rrc\n",
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsync pDrvIns->pReg->szName, pDrvIns->iInstance, rc));
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsync return rc;
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsync}
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsync
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsync
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsync/** @interface_method_impl{PDMDRVHLP,pfnDetach} */
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsyncstatic DECLCALLBACK(int) pdmR3DrvHlp_Detach(PPDMDRVINS pDrvIns, uint32_t fFlags)
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsync{
b377a71756cce9f39d25b561f72bfa33ce8a39devboxsync PDMDRV_ASSERT_DRVINS(pDrvIns);
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsync LogFlow(("pdmR3DrvHlp_Detach: caller='%s'/%d: fFlags=%#x\n",
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsync pDrvIns->pReg->szName, pDrvIns->iInstance, fFlags));
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsync VM_ASSERT_EMT(pDrvIns->Internal.s.pVMR3);
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsync
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsync /*
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsync * Anything attached?
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsync */
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsync int rc;
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsync if (pDrvIns->Internal.s.pDown)
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsync rc = pdmR3DrvDetach(pDrvIns->Internal.s.pDown, fFlags);
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsync else
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsync {
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsync AssertMsgFailed(("Nothing attached!\n"));
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsync rc = VERR_PDM_NO_DRIVER_ATTACHED;
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsync }
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsync
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsync LogFlow(("pdmR3DrvHlp_Detach: caller='%s'/%d: returns %Rrc\n",
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsync pDrvIns->pReg->szName, pDrvIns->iInstance, rc));
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsync return rc;
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsync}
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsync
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsync
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsync/** @interface_method_impl{PDMDRVHLP,pfnDetachSelf} */
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsyncstatic DECLCALLBACK(int) pdmR3DrvHlp_DetachSelf(PPDMDRVINS pDrvIns, uint32_t fFlags)
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsync{
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsync PDMDRV_ASSERT_DRVINS(pDrvIns);
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsync LogFlow(("pdmR3DrvHlp_DetachSelf: caller='%s'/%d: fFlags=%#x\n",
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsync pDrvIns->pReg->szName, pDrvIns->iInstance, fFlags));
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsync VM_ASSERT_EMT(pDrvIns->Internal.s.pVMR3);
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsync
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsync int rc = pdmR3DrvDetach(pDrvIns, fFlags);
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsync
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsync LogFlow(("pdmR3DrvHlp_Detach: returns %Rrc\n", rc)); /* pDrvIns is freed by now. */
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsync return rc;
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsync}
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsync
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsync
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsync/** @interface_method_impl{PDMDRVHLP,pfnMountPrepare} */
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsyncstatic DECLCALLBACK(int) pdmR3DrvHlp_MountPrepare(PPDMDRVINS pDrvIns, const char *pszFilename, const char *pszCoreDriver)
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsync{
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsync PDMDRV_ASSERT_DRVINS(pDrvIns);
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsync LogFlow(("pdmR3DrvHlp_MountPrepare: caller='%s'/%d: pszFilename=%p:{%s} pszCoreDriver=%p:{%s}\n",
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsync pDrvIns->pReg->szName, pDrvIns->iInstance, pszFilename, pszFilename, pszCoreDriver, pszCoreDriver));
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsync VM_ASSERT_EMT(pDrvIns->Internal.s.pVMR3);
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsync
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsync /*
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsync * Do the caller have anything attached below itself?
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsync */
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsync if (pDrvIns->Internal.s.pDown)
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsync {
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsync AssertMsgFailed(("Cannot prepare a mount when something's attached to you!\n"));
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsync return VERR_PDM_DRIVER_ALREADY_ATTACHED;
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsync }
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsync
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsync /*
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsync * We're asked to prepare, so we'll start off by nuking the
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsync * attached configuration tree.
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsync */
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsync PCFGMNODE pNode = CFGMR3GetChild(pDrvIns->Internal.s.pCfgHandle, "AttachedDriver");
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsync if (pNode)
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsync CFGMR3RemoveNode(pNode);
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsync
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsync /*
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsync * If there is no core driver, we'll have to probe for it.
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsync */
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsync if (!pszCoreDriver)
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsync {
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsync /** @todo implement image probing. */
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsync AssertReleaseMsgFailed(("Not implemented!\n"));
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsync return VERR_NOT_IMPLEMENTED;
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsync }
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsync
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsync /*
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsync * Construct the basic attached driver configuration.
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsync */
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsync int rc = CFGMR3InsertNode(pDrvIns->Internal.s.pCfgHandle, "AttachedDriver", &pNode);
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsync if (RT_SUCCESS(rc))
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsync {
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsync rc = CFGMR3InsertString(pNode, "Driver", pszCoreDriver);
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsync if (RT_SUCCESS(rc))
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsync {
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsync PCFGMNODE pCfg;
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsync rc = CFGMR3InsertNode(pNode, "Config", &pCfg);
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsync if (RT_SUCCESS(rc))
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsync {
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsync rc = CFGMR3InsertString(pCfg, "Path", pszFilename);
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsync if (RT_SUCCESS(rc))
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsync {
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsync LogFlow(("pdmR3DrvHlp_MountPrepare: caller='%s'/%d: returns %Rrc (Driver=%s)\n",
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsync pDrvIns->pReg->szName, pDrvIns->iInstance, rc, pszCoreDriver));
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsync return rc;
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsync }
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsync else
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsync AssertMsgFailed(("Path string insert failed, rc=%Rrc\n", rc));
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsync }
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsync else
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsync AssertMsgFailed(("Config node failed, rc=%Rrc\n", rc));
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsync }
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsync else
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsync AssertMsgFailed(("Driver string insert failed, rc=%Rrc\n", rc));
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsync CFGMR3RemoveNode(pNode);
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsync }
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsync else
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsync AssertMsgFailed(("AttachedDriver node insert failed, rc=%Rrc\n", rc));
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsync
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsync LogFlow(("pdmR3DrvHlp_MountPrepare: caller='%s'/%d: returns %Rrc\n",
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsync pDrvIns->pReg->szName, pDrvIns->iInstance, rc));
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsync return rc;
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsync}
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsync
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsync
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsync/** @interface_method_impl{PDMDRVHLP,pfnAssertEMT} */
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsyncstatic DECLCALLBACK(bool) pdmR3DrvHlp_AssertEMT(PPDMDRVINS pDrvIns, const char *pszFile, unsigned iLine, const char *pszFunction)
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsync{
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsync PDMDRV_ASSERT_DRVINS(pDrvIns);
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsync if (VM_IS_EMT(pDrvIns->Internal.s.pVMR3))
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsync return true;
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsync
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsync char szMsg[100];
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsync RTStrPrintf(szMsg, sizeof(szMsg), "AssertEMT '%s'/%d\n", pDrvIns->pReg->szName, pDrvIns->iInstance);
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsync RTAssertMsg1Weak(szMsg, iLine, pszFile, pszFunction);
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsync AssertBreakpoint();
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsync VM_ASSERT_EMT(pDrvIns->Internal.s.pVMR3);
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsync return false;
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsync}
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsync
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsync
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsync/** @interface_method_impl{PDMDRVHLP,pfnAssertOther} */
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsyncstatic DECLCALLBACK(bool) pdmR3DrvHlp_AssertOther(PPDMDRVINS pDrvIns, const char *pszFile, unsigned iLine, const char *pszFunction)
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsync{
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsync PDMDRV_ASSERT_DRVINS(pDrvIns);
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsync if (!VM_IS_EMT(pDrvIns->Internal.s.pVMR3))
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsync return true;
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsync
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsync char szMsg[100];
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsync RTStrPrintf(szMsg, sizeof(szMsg), "AssertOther '%s'/%d\n", pDrvIns->pReg->szName, pDrvIns->iInstance);
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsync RTAssertMsg1Weak(szMsg, iLine, pszFile, pszFunction);
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsync AssertBreakpoint();
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsync VM_ASSERT_EMT(pDrvIns->Internal.s.pVMR3);
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsync return false;
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsync}
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsync
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsync
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsync/** @interface_method_impl{PDMDRVHLP,pfnVMSetError} */
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsyncstatic DECLCALLBACK(int) pdmR3DrvHlp_VMSetError(PPDMDRVINS pDrvIns, int rc, RT_SRC_POS_DECL, const char *pszFormat, ...)
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsync{
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsync PDMDRV_ASSERT_DRVINS(pDrvIns);
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsync va_list args;
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsync va_start(args, pszFormat);
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsync int rc2 = VMSetErrorV(pDrvIns->Internal.s.pVMR3, rc, RT_SRC_POS_ARGS, pszFormat, args); Assert(rc2 == rc); NOREF(rc2);
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsync va_end(args);
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsync return rc;
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsync}
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsync
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsync
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsync/** @interface_method_impl{PDMDRVHLP,pfnVMSetErrorV} */
bc0c1e33e433d1276ea1606ace81f61594ee3838vboxsyncstatic DECLCALLBACK(int) pdmR3DrvHlp_VMSetErrorV(PPDMDRVINS pDrvIns, int rc, RT_SRC_POS_DECL, const char *pszFormat, va_list va)
{
PDMDRV_ASSERT_DRVINS(pDrvIns);
int rc2 = VMSetErrorV(pDrvIns->Internal.s.pVMR3, rc, RT_SRC_POS_ARGS, pszFormat, va); Assert(rc2 == rc); NOREF(rc2);
return rc;
}
/** @interface_method_impl{PDMDRVHLP,pfnVMSetRuntimeError} */
static DECLCALLBACK(int) pdmR3DrvHlp_VMSetRuntimeError(PPDMDRVINS pDrvIns, uint32_t fFlags, const char *pszErrorId, const char *pszFormat, ...)
{
PDMDRV_ASSERT_DRVINS(pDrvIns);
va_list args;
va_start(args, pszFormat);
int rc = VMSetRuntimeErrorV(pDrvIns->Internal.s.pVMR3, fFlags, pszErrorId, pszFormat, args);
va_end(args);
return rc;
}
/** @interface_method_impl{PDMDRVHLP,pfnVMSetRuntimeErrorV} */
static DECLCALLBACK(int) pdmR3DrvHlp_VMSetRuntimeErrorV(PPDMDRVINS pDrvIns, uint32_t fFlags, const char *pszErrorId, const char *pszFormat, va_list va)
{
PDMDRV_ASSERT_DRVINS(pDrvIns);
int rc = VMSetRuntimeErrorV(pDrvIns->Internal.s.pVMR3, fFlags, pszErrorId, pszFormat, va);
return rc;
}
/** @interface_method_impl{PDMDEVHLPR3,pfnVMState} */
static DECLCALLBACK(VMSTATE) pdmR3DrvHlp_VMState(PPDMDRVINS pDrvIns)
{
PDMDRV_ASSERT_DRVINS(pDrvIns);
VMSTATE enmVMState = VMR3GetState(pDrvIns->Internal.s.pVMR3);
LogFlow(("pdmR3DrvHlp_VMState: caller='%s'/%d: returns %d (%s)\n", pDrvIns->pReg->szName, pDrvIns->iInstance,
enmVMState, VMR3GetStateName(enmVMState)));
return enmVMState;
}
/** @interface_method_impl{PDMDEVHLPR3,pfnVMTeleportedAndNotFullyResumedYet} */
static DECLCALLBACK(bool) pdmR3DrvHlp_VMTeleportedAndNotFullyResumedYet(PPDMDRVINS pDrvIns)
{
PDMDRV_ASSERT_DRVINS(pDrvIns);
bool fRc = VMR3TeleportedAndNotFullyResumedYet(pDrvIns->Internal.s.pVMR3);
LogFlow(("pdmR3DrvHlp_VMState: caller='%s'/%d: returns %RTbool)\n", pDrvIns->pReg->szName, pDrvIns->iInstance,
fRc));
return fRc;
}
/** @interface_method_impl{PDMDRVHLP,pfnPDMQueueCreate} */
static DECLCALLBACK(int) pdmR3DrvHlp_PDMQueueCreate(PPDMDRVINS pDrvIns, uint32_t cbItem, uint32_t cItems, uint32_t cMilliesInterval,
PFNPDMQUEUEDRV pfnCallback, const char *pszName, PPDMQUEUE *ppQueue)
{
PDMDRV_ASSERT_DRVINS(pDrvIns);
LogFlow(("pdmR3DrvHlp_PDMQueueCreate: caller='%s'/%d: cbItem=%d cItems=%d cMilliesInterval=%d pfnCallback=%p pszName=%p:{%s} ppQueue=%p\n",
pDrvIns->pReg->szName, pDrvIns->iInstance, cbItem, cItems, cMilliesInterval, pfnCallback, pszName, pszName, ppQueue, ppQueue));
PVM pVM = pDrvIns->Internal.s.pVMR3;
VM_ASSERT_EMT(pVM);
if (pDrvIns->iInstance > 0)
{
pszName = MMR3HeapAPrintf(pVM, MM_TAG_PDM_DRIVER_DESC, "%s_%u", pszName, pDrvIns->iInstance);
AssertLogRelReturn(pszName, VERR_NO_MEMORY);
}
int rc = PDMR3QueueCreateDriver(pVM, pDrvIns, cbItem, cItems, cMilliesInterval, pfnCallback, pszName, ppQueue);
LogFlow(("pdmR3DrvHlp_PDMQueueCreate: caller='%s'/%d: returns %Rrc *ppQueue=%p\n", pDrvIns->pReg->szName, pDrvIns->iInstance, rc, *ppQueue));
return rc;
}
/** @interface_method_impl{PDMDRVHLP,pfnTMGetVirtualFreq} */
static DECLCALLBACK(uint64_t) pdmR3DrvHlp_TMGetVirtualFreq(PPDMDRVINS pDrvIns)
{
PDMDRV_ASSERT_DRVINS(pDrvIns);
return TMVirtualGetFreq(pDrvIns->Internal.s.pVMR3);
}
/** @interface_method_impl{PDMDRVHLP,pfnTMGetVirtualTime} */
static DECLCALLBACK(uint64_t) pdmR3DrvHlp_TMGetVirtualTime(PPDMDRVINS pDrvIns)
{
PDMDRV_ASSERT_DRVINS(pDrvIns);
return TMVirtualGet(pDrvIns->Internal.s.pVMR3);
}
/** @interface_method_impl{PDMDRVHLP,pfnTMTimerCreate} */
static DECLCALLBACK(int) pdmR3DrvHlp_TMTimerCreate(PPDMDRVINS pDrvIns, TMCLOCK enmClock, PFNTMTIMERDRV pfnCallback, void *pvUser, uint32_t fFlags, const char *pszDesc, PPTMTIMERR3 ppTimer)
{
PDMDRV_ASSERT_DRVINS(pDrvIns);
LogFlow(("pdmR3DrvHlp_TMTimerCreate: caller='%s'/%d: enmClock=%d pfnCallback=%p pvUser=%p fFlags=%#x pszDesc=%p:{%s} ppTimer=%p\n",
pDrvIns->pReg->szName, pDrvIns->iInstance, enmClock, pfnCallback, pvUser, fFlags, pszDesc, pszDesc, ppTimer));
int rc = TMR3TimerCreateDriver(pDrvIns->Internal.s.pVMR3, pDrvIns, enmClock, pfnCallback, pvUser, fFlags, pszDesc, ppTimer);
LogFlow(("pdmR3DrvHlp_TMTimerCreate: caller='%s'/%d: returns %Rrc *ppTimer=%p\n", pDrvIns->pReg->szName, pDrvIns->iInstance, rc, *ppTimer));
return rc;
}
/** @interface_method_impl{PDMDRVHLP,pfnSSMRegister} */
static DECLCALLBACK(int) pdmR3DrvHlp_SSMRegister(PPDMDRVINS pDrvIns, uint32_t uVersion, size_t cbGuess,
PFNSSMDRVLIVEPREP pfnLivePrep, PFNSSMDRVLIVEEXEC pfnLiveExec, PFNSSMDRVLIVEVOTE pfnLiveVote,
PFNSSMDRVSAVEPREP pfnSavePrep, PFNSSMDRVSAVEEXEC pfnSaveExec, PFNSSMDRVSAVEDONE pfnSaveDone,
PFNSSMDRVLOADPREP pfnLoadPrep, PFNSSMDRVLOADEXEC pfnLoadExec, PFNSSMDRVLOADDONE pfnLoadDone)
{
PDMDRV_ASSERT_DRVINS(pDrvIns);
VM_ASSERT_EMT(pDrvIns->Internal.s.pVMR3);
LogFlow(("pdmR3DrvHlp_SSMRegister: caller='%s'/%d: uVersion=#x cbGuess=%#x \n"
" pfnLivePrep=%p pfnLiveExec=%p pfnLiveVote=%p pfnSavePrep=%p pfnSaveExec=%p pfnSaveDone=%p pszLoadPrep=%p pfnLoadExec=%p pfnLoaddone=%p\n",
pDrvIns->pReg->szName, pDrvIns->iInstance, uVersion, cbGuess,
pfnLivePrep, pfnLiveExec, pfnLiveVote,
pfnSavePrep, pfnSaveExec, pfnSaveDone, pfnLoadPrep, pfnLoadExec, pfnLoadDone));
int rc = SSMR3RegisterDriver(pDrvIns->Internal.s.pVMR3, pDrvIns, pDrvIns->pReg->szName, pDrvIns->iInstance,
uVersion, cbGuess,
pfnLivePrep, pfnLiveExec, pfnLiveVote,
pfnSavePrep, pfnSaveExec, pfnSaveDone,
pfnLoadPrep, pfnLoadExec, pfnLoadDone);
LogFlow(("pdmR3DrvHlp_SSMRegister: caller='%s'/%d: returns %Rrc\n", pDrvIns->pReg->szName, pDrvIns->iInstance, rc));
return rc;
}
/** @interface_method_impl{PDMDRVHLP,pfnSSMDeregister} */
static DECLCALLBACK(int) pdmR3DrvHlp_SSMDeregister(PPDMDRVINS pDrvIns, const char *pszName, uint32_t u32Instance)
{
PDMDRV_ASSERT_DRVINS(pDrvIns);
VM_ASSERT_EMT(pDrvIns->Internal.s.pVMR3);
LogFlow(("pdmR3DrvHlp_SSMDeregister: caller='%s'/%d: pszName=%p:{%s} u32Instance=%#x\n",
pDrvIns->pReg->szName, pDrvIns->iInstance, pszName, pszName, u32Instance));
int rc = SSMR3DeregisterDriver(pDrvIns->Internal.s.pVMR3, pDrvIns, pszName, u32Instance);
LogFlow(("pdmR3DrvHlp_SSMDeregister: caller='%s'/%d: returns %Rrc\n", pDrvIns->pReg->szName, pDrvIns->iInstance, rc));
return rc;
}
/** @interface_method_impl{PDMDRVHLP,pfnSTAMRegister} */
static DECLCALLBACK(void) pdmR3DrvHlp_STAMRegister(PPDMDRVINS pDrvIns, void *pvSample, STAMTYPE enmType, const char *pszName, STAMUNIT enmUnit, const char *pszDesc)
{
PDMDRV_ASSERT_DRVINS(pDrvIns);
VM_ASSERT_EMT(pDrvIns->Internal.s.pVMR3);
STAM_REG(pDrvIns->Internal.s.pVMR3, pvSample, enmType, pszName, enmUnit, pszDesc);
/** @todo track the samples so they can be dumped & deregistered when the driver instance is destroyed.
* For now we just have to be careful not to use this call for drivers which can be unloaded. */
}
/** @interface_method_impl{PDMDRVHLP,pfnSTAMRegisterF} */
static DECLCALLBACK(void) pdmR3DrvHlp_STAMRegisterF(PPDMDRVINS pDrvIns, void *pvSample, STAMTYPE enmType, STAMVISIBILITY enmVisibility,
STAMUNIT enmUnit, const char *pszDesc, const char *pszName, ...)
{
PDMDRV_ASSERT_DRVINS(pDrvIns);
VM_ASSERT_EMT(pDrvIns->Internal.s.pVMR3);
va_list args;
va_start(args, pszName);
int rc = STAMR3RegisterV(pDrvIns->Internal.s.pVMR3, pvSample, enmType, enmVisibility, enmUnit, pszDesc, pszName, args);
va_end(args);
AssertRC(rc);
}
/** @interface_method_impl{PDMDRVHLP,pfnSTAMRegisterV} */
static DECLCALLBACK(void) pdmR3DrvHlp_STAMRegisterV(PPDMDRVINS pDrvIns, void *pvSample, STAMTYPE enmType, STAMVISIBILITY enmVisibility,
STAMUNIT enmUnit, const char *pszDesc, const char *pszName, va_list args)
{
PDMDRV_ASSERT_DRVINS(pDrvIns);
VM_ASSERT_EMT(pDrvIns->Internal.s.pVMR3);
int rc = STAMR3RegisterV(pDrvIns->Internal.s.pVMR3, pvSample, enmType, enmVisibility, enmUnit, pszDesc, pszName, args);
AssertRC(rc);
}
/** @interface_method_impl{PDMDRVHLP,pfnSTAMDeregister} */
static DECLCALLBACK(int) pdmR3DrvHlp_STAMDeregister(PPDMDRVINS pDrvIns, void *pvSample)
{
PDMDRV_ASSERT_DRVINS(pDrvIns);
VM_ASSERT_EMT(pDrvIns->Internal.s.pVMR3);
int rc = STAMR3DeregisterU(pDrvIns->Internal.s.pVMR3->pUVM, pvSample);
AssertRC(rc);
return rc;
}
/** @interface_method_impl{PDMDRVHLP,pfnSUPCallVMMR0Ex} */
static DECLCALLBACK(int) pdmR3DrvHlp_SUPCallVMMR0Ex(PPDMDRVINS pDrvIns, unsigned uOperation, void *pvArg, unsigned cbArg)
{
PDMDRV_ASSERT_DRVINS(pDrvIns);
LogFlow(("pdmR3DrvHlp_SSMCallVMMR0Ex: caller='%s'/%d: uOperation=%u pvArg=%p cbArg=%d\n",
pDrvIns->pReg->szName, pDrvIns->iInstance, uOperation, pvArg, cbArg));
int rc;
if ( uOperation >= VMMR0_DO_SRV_START
&& uOperation < VMMR0_DO_SRV_END)
rc = SUPR3CallVMMR0Ex(pDrvIns->Internal.s.pVMR3->pVMR0, NIL_VMCPUID, uOperation, 0, (PSUPVMMR0REQHDR)pvArg);
else
{
AssertMsgFailed(("Invalid uOperation=%u\n", uOperation));
rc = VERR_INVALID_PARAMETER;
}
LogFlow(("pdmR3DrvHlp_SUPCallVMMR0Ex: caller='%s'/%d: returns %Rrc\n", pDrvIns->pReg->szName, pDrvIns->iInstance, rc));
return rc;
}
/** @interface_method_impl{PDMDRVHLP,pfnUSBRegisterHub} */
static DECLCALLBACK(int) pdmR3DrvHlp_USBRegisterHub(PPDMDRVINS pDrvIns, uint32_t fVersions, uint32_t cPorts, PCPDMUSBHUBREG pUsbHubReg, PPCPDMUSBHUBHLP ppUsbHubHlp)
{
PDMDRV_ASSERT_DRVINS(pDrvIns);
VM_ASSERT_EMT(pDrvIns->Internal.s.pVMR3);
LogFlow(("pdmR3DrvHlp_USBRegisterHub: caller='%s'/%d: fVersions=%#x cPorts=%#x pUsbHubReg=%p ppUsbHubHlp=%p\n",
pDrvIns->pReg->szName, pDrvIns->iInstance, fVersions, cPorts, pUsbHubReg, ppUsbHubHlp));
#ifdef VBOX_WITH_USB
int rc = pdmR3UsbRegisterHub(pDrvIns->Internal.s.pVMR3, pDrvIns, fVersions, cPorts, pUsbHubReg, ppUsbHubHlp);
#else
int rc = VERR_NOT_SUPPORTED;
#endif
LogFlow(("pdmR3DrvHlp_USBRegisterHub: caller='%s'/%d: returns %Rrc\n", pDrvIns->pReg->szName, pDrvIns->iInstance, rc));
return rc;
}
/** @interface_method_impl{PDMDRVHLP,pfnSetAsyncNotification} */
static DECLCALLBACK(int) pdmR3DrvHlp_SetAsyncNotification(PPDMDRVINS pDrvIns, PFNPDMDRVASYNCNOTIFY pfnAsyncNotify)
{
PDMDRV_ASSERT_DRVINS(pDrvIns);
VM_ASSERT_EMT0(pDrvIns->Internal.s.pVMR3);
LogFlow(("pdmR3DrvHlp_SetAsyncNotification: caller='%s'/%d: pfnAsyncNotify=%p\n", pDrvIns->pReg->szName, pDrvIns->iInstance, pfnAsyncNotify));
int rc = VINF_SUCCESS;
AssertStmt(pfnAsyncNotify, rc = VERR_INVALID_PARAMETER);
AssertStmt(!pDrvIns->Internal.s.pfnAsyncNotify, rc = VERR_WRONG_ORDER);
AssertStmt(pDrvIns->Internal.s.fVMSuspended || pDrvIns->Internal.s.fVMReset, rc = VERR_WRONG_ORDER);
VMSTATE enmVMState = VMR3GetState(pDrvIns->Internal.s.pVMR3);
AssertStmt( enmVMState == VMSTATE_SUSPENDING
|| enmVMState == VMSTATE_SUSPENDING_EXT_LS
|| enmVMState == VMSTATE_SUSPENDING_LS
|| enmVMState == VMSTATE_RESETTING
|| enmVMState == VMSTATE_RESETTING_LS
|| enmVMState == VMSTATE_POWERING_OFF
|| enmVMState == VMSTATE_POWERING_OFF_LS,
rc = VERR_INVALID_STATE);
if (RT_SUCCESS(rc))
pDrvIns->Internal.s.pfnAsyncNotify = pfnAsyncNotify;
LogFlow(("pdmR3DrvHlp_SetAsyncNotification: caller='%s'/%d: returns %Rrc\n", pDrvIns->pReg->szName, pDrvIns->iInstance, rc));
return rc;
}
/** @interface_method_impl{PDMDRVHLP,pfnAsyncNotificationCompleted} */
static DECLCALLBACK(void) pdmR3DrvHlp_AsyncNotificationCompleted(PPDMDRVINS pDrvIns)
{
PDMDRV_ASSERT_DRVINS(pDrvIns);
PVM pVM = pDrvIns->Internal.s.pVMR3;
VMSTATE enmVMState = VMR3GetState(pVM);
if ( enmVMState == VMSTATE_SUSPENDING
|| enmVMState == VMSTATE_SUSPENDING_EXT_LS
|| enmVMState == VMSTATE_SUSPENDING_LS
|| enmVMState == VMSTATE_RESETTING
|| enmVMState == VMSTATE_RESETTING_LS
|| enmVMState == VMSTATE_POWERING_OFF
|| enmVMState == VMSTATE_POWERING_OFF_LS)
{
LogFlow(("pdmR3DrvHlp_AsyncNotificationCompleted: caller='%s'/%d:\n", pDrvIns->pReg->szName, pDrvIns->iInstance));
VMR3AsyncPdmNotificationWakeupU(pVM->pUVM);
}
else
LogFlow(("pdmR3DrvHlp_AsyncNotificationCompleted: caller='%s'/%d: enmVMState=%d\n", pDrvIns->pReg->szName, pDrvIns->iInstance, enmVMState));
}
/** @interface_method_impl{PDMDRVHLP,pfnPDMThreadCreate} */
static DECLCALLBACK(int) pdmR3DrvHlp_PDMThreadCreate(PPDMDRVINS pDrvIns, PPPDMTHREAD ppThread, void *pvUser, PFNPDMTHREADDRV pfnThread,
PFNPDMTHREADWAKEUPDRV pfnWakeup, size_t cbStack, RTTHREADTYPE enmType, const char *pszName)
{
PDMDRV_ASSERT_DRVINS(pDrvIns);
VM_ASSERT_EMT(pDrvIns->Internal.s.pVMR3);
LogFlow(("pdmR3DrvHlp_PDMThreadCreate: caller='%s'/%d: ppThread=%p pvUser=%p pfnThread=%p pfnWakeup=%p cbStack=%#zx enmType=%d pszName=%p:{%s}\n",
pDrvIns->pReg->szName, pDrvIns->iInstance, ppThread, pvUser, pfnThread, pfnWakeup, cbStack, enmType, pszName, pszName));
int rc = pdmR3ThreadCreateDriver(pDrvIns->Internal.s.pVMR3, pDrvIns, ppThread, pvUser, pfnThread, pfnWakeup, cbStack, enmType, pszName);
LogFlow(("pdmR3DrvHlp_PDMThreadCreate: caller='%s'/%d: returns %Rrc *ppThread=%RTthrd\n", pDrvIns->pReg->szName, pDrvIns->iInstance,
rc, *ppThread));
return rc;
}
/** @interface_method_impl{PDMDRVHLP,pfnPDMAsyncCompletionTemplateCreate} */
static DECLCALLBACK(int) pdmR3DrvHlp_PDMAsyncCompletionTemplateCreate(PPDMDRVINS pDrvIns, PPPDMASYNCCOMPLETIONTEMPLATE ppTemplate,
PFNPDMASYNCCOMPLETEDRV pfnCompleted, void *pvTemplateUser,
const char *pszDesc)
{
PDMDRV_ASSERT_DRVINS(pDrvIns);
VM_ASSERT_EMT(pDrvIns->Internal.s.pVMR3);
LogFlow(("pdmR3DrvHlp_PDMAsyncCompletionTemplateCreate: caller='%s'/%d: ppTemplate=%p pfnCompleted=%p pszDesc=%p:{%s}\n",
pDrvIns->pReg->szName, pDrvIns->iInstance, ppTemplate, pfnCompleted, pszDesc, pszDesc));
int rc = PDMR3AsyncCompletionTemplateCreateDriver(pDrvIns->Internal.s.pVMR3, pDrvIns, ppTemplate, pfnCompleted, pvTemplateUser, pszDesc);
LogFlow(("pdmR3DrvHlp_PDMAsyncCompletionTemplateCreate: caller='%s'/%d: returns %Rrc *ppThread=%p\n", pDrvIns->pReg->szName,
pDrvIns->iInstance, rc, *ppTemplate));
return rc;
}
/** @interface_method_impl{PDMDRVHLP,pfnPDMLdrGetRCInterfaceSymbols} */
static DECLCALLBACK(int) pdmR3DrvHlp_PDMLdrGetRCInterfaceSymbols(PPDMDRVINS pDrvIns, void *pvInterface, size_t cbInterface,
const char *pszSymPrefix, const char *pszSymList)
{
PDMDRV_ASSERT_DRVINS(pDrvIns);
VM_ASSERT_EMT(pDrvIns->Internal.s.pVMR3);
LogFlow(("pdmR3DrvHlp_PDMLdrGetRCInterfaceSymbols: caller='%s'/%d: pvInterface=%p cbInterface=%zu pszSymPrefix=%p:{%s} pszSymList=%p:{%s}\n",
pDrvIns->pReg->szName, pDrvIns->iInstance, pvInterface, cbInterface, pszSymPrefix, pszSymPrefix, pszSymList, pszSymList));
int rc;
if ( strncmp(pszSymPrefix, "drv", 3) == 0
&& RTStrIStr(pszSymPrefix + 3, pDrvIns->pReg->szName) != NULL)
{
if (pDrvIns->pReg->fFlags & PDM_DRVREG_FLAGS_RC)
rc = PDMR3LdrGetInterfaceSymbols(pDrvIns->Internal.s.pVMR3, pvInterface, cbInterface,
pDrvIns->pReg->szName, pszSymPrefix, pszSymList,
false /*fRing0OrRC*/);
else
{
AssertMsgFailed(("Not a raw-mode enabled driver\n"));
rc = VERR_PERMISSION_DENIED;
}
}
else
{
AssertMsgFailed(("Invalid prefix '%s' for '%s'; must start with 'drv' and contain the driver name!\n",
pszSymPrefix, pDrvIns->pReg->szName));
rc = VERR_INVALID_NAME;
}
LogFlow(("pdmR3DrvHlp_PDMLdrGetRCInterfaceSymbols: caller='%s'/%d: returns %Rrc\n", pDrvIns->pReg->szName,
pDrvIns->iInstance, rc));
return rc;
}
/** @interface_method_impl{PDMDRVHLP,pfnPDMLdrGetR0InterfaceSymbols} */
static DECLCALLBACK(int) pdmR3DrvHlp_PDMLdrGetR0InterfaceSymbols(PPDMDRVINS pDrvIns, void *pvInterface, size_t cbInterface,
const char *pszSymPrefix, const char *pszSymList)
{
PDMDRV_ASSERT_DRVINS(pDrvIns);
VM_ASSERT_EMT(pDrvIns->Internal.s.pVMR3);
LogFlow(("pdmR3DrvHlp_PDMLdrGetR0InterfaceSymbols: caller='%s'/%d: pvInterface=%p cbInterface=%zu pszSymPrefix=%p:{%s} pszSymList=%p:{%s}\n",
pDrvIns->pReg->szName, pDrvIns->iInstance, pvInterface, cbInterface, pszSymPrefix, pszSymPrefix, pszSymList, pszSymList));
int rc;
if ( strncmp(pszSymPrefix, "drv", 3) == 0
&& RTStrIStr(pszSymPrefix + 3, pDrvIns->pReg->szName) != NULL)
{
if (pDrvIns->pReg->fFlags & PDM_DRVREG_FLAGS_R0)
rc = PDMR3LdrGetInterfaceSymbols(pDrvIns->Internal.s.pVMR3, pvInterface, cbInterface,
pDrvIns->pReg->szName, pszSymPrefix, pszSymList,
true /*fRing0OrRC*/);
else
{
AssertMsgFailed(("Not a ring-0 enabled driver\n"));
rc = VERR_PERMISSION_DENIED;
}
}
else
{
AssertMsgFailed(("Invalid prefix '%s' for '%s'; must start with 'drv' and contain the driver name!\n",
pszSymPrefix, pDrvIns->pReg->szName));
rc = VERR_INVALID_NAME;
}
LogFlow(("pdmR3DrvHlp_PDMLdrGetR0InterfaceSymbols: caller='%s'/%d: returns %Rrc\n", pDrvIns->pReg->szName,
pDrvIns->iInstance, rc));
return rc;
}
/**
* The driver helper structure.
*/
const PDMDRVHLPR3 g_pdmR3DrvHlp =
{
PDM_DRVHLPR3_VERSION,
pdmR3DrvHlp_Attach,
pdmR3DrvHlp_Detach,
pdmR3DrvHlp_DetachSelf,
pdmR3DrvHlp_MountPrepare,
pdmR3DrvHlp_AssertEMT,
pdmR3DrvHlp_AssertOther,
pdmR3DrvHlp_VMSetError,
pdmR3DrvHlp_VMSetErrorV,
pdmR3DrvHlp_VMSetRuntimeError,
pdmR3DrvHlp_VMSetRuntimeErrorV,
pdmR3DrvHlp_VMState,
pdmR3DrvHlp_VMTeleportedAndNotFullyResumedYet,
pdmR3DrvHlp_PDMQueueCreate,
pdmR3DrvHlp_TMGetVirtualFreq,
pdmR3DrvHlp_TMGetVirtualTime,
pdmR3DrvHlp_TMTimerCreate,
pdmR3DrvHlp_SSMRegister,
pdmR3DrvHlp_SSMDeregister,
pdmR3DrvHlp_STAMRegister,
pdmR3DrvHlp_STAMRegisterF,
pdmR3DrvHlp_STAMRegisterV,
pdmR3DrvHlp_STAMDeregister,
pdmR3DrvHlp_SUPCallVMMR0Ex,
pdmR3DrvHlp_USBRegisterHub,
pdmR3DrvHlp_SetAsyncNotification,
pdmR3DrvHlp_AsyncNotificationCompleted,
pdmR3DrvHlp_PDMThreadCreate,
pdmR3DrvHlp_PDMAsyncCompletionTemplateCreate,
pdmR3DrvHlp_PDMLdrGetRCInterfaceSymbols,
pdmR3DrvHlp_PDMLdrGetR0InterfaceSymbols,
PDM_DRVHLPR3_VERSION /* u32TheEnd */
};
/** @} */