PDMLdr.cpp revision 108008bf37ebb349b5b04dacfe73da99dbb0106c
/* $Id$ */
/** @file
* PDM - Pluggable Device Manager, module loader.
*/
/*
* Copyright (C) 2006-2007 Oracle Corporation
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* General Public License (GPL) as published by the Free Software
* Foundation, in version 2 as it comes in the "COPYING" file of the
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
*/
//#define PDMLDR_FAKE_MODE
/*******************************************************************************
* Header Files *
*******************************************************************************/
#define LOG_GROUP LOG_GROUP_PDM_LDR
#include "PDMInternal.h"
#include <limits.h>
/*******************************************************************************
* Structures and Typedefs *
*******************************************************************************/
/**
* Structure which the user argument of the RTLdrGetBits() callback points to.
* @internal
*/
typedef struct PDMGETIMPORTARGS
{
/*******************************************************************************
* Internal Functions *
*******************************************************************************/
static DECLCALLBACK(int) pdmR3GetImportRC(RTLDRMOD hLdrMod, const char *pszModule, const char *pszSymbol, unsigned uSymbol, RTUINTPTR *pValue, void *pvUser);
static int pdmR3LoadR0U(PUVM pUVM, const char *pszFilename, const char *pszName, const char *pszSearchPath);
static char *pdmR3File(const char *pszFile, const char *pszDefaultExt, const char *pszSearchPath, bool fShared);
/**
* Loads the VMMR0.r0 module early in the init process.
*
* @returns VBox status code.
* @param pUVM Pointer to the user mode VM structure.
*/
{
}
/**
* Init the module loader part of PDM.
*
* This routine will load the Host Context Ring-0 and Guest
* Context VMM modules.
*
* @returns VBox status code.
* @param pUVM Pointer to the user mode VM structure.
* @param pvVMMR0Mod The opaque returned by PDMR3LdrLoadVMMR0.
*/
{
#if defined(PDMLDR_FAKE_MODE) || !defined(VBOX_WITH_RAW_MODE)
return VINF_SUCCESS;
#else
/*
* Load the mandatory GC module, the VMMR0.r0 is loaded before VM creation.
*/
#endif
}
/**
* Terminate the module loader part of PDM.
*
* This will unload and free all modules.
*
* @param pVM The VM handle.
*
* @remarks This is normally called twice during termination.
*/
{
/*
* Free the modules.
*/
while (pModule)
{
/* free loader item. */
{
}
/* free bits. */
{
case PDMMOD_TYPE_R0:
{
break;
}
#ifdef VBOX_WITH_RAW_MODE
case PDMMOD_TYPE_RC:
#endif
case PDMMOD_TYPE_R3:
/* MM will free this memory for us - it's alloc only memory. :-) */
break;
default:
break;
}
}
}
/**
* Applies relocations to GC modules.
*
* This must be done very early in the relocation
* process so that components can resolve GC symbols during relocation.
*
* @param pUVM Pointer to the user mode VM structure.
* @param offDelta Relocation delta relative to old location.
*/
{
#ifdef VBOX_WITH_RAW_MODE
/*
* GC Modules.
*/
{
/*
* The relocation have to be done in two passes so imports
* can be correctly resolved. The first pass will update
* the ImageBase saving the current value in OldImageBase.
* The second pass will do the actual relocation.
*/
/* pass 1 */
{
{
}
}
/* pass 2 */
{
{
pdmR3GetImportRC, &Args);
}
}
}
#endif
}
/**
* Loads a module into the host context ring-3.
*
* This is used by the driver and device init functions to load modules
* containing the drivers and devices. The function can be extended to
* load modules which are not native to the environment we're running in,
* but at the moment this is not required.
*
* No reference counting is kept, since we don't implement any facilities
* for unloading the module. But the module will naturally be released
* when the VM terminates.
*
* @returns VBox status code.
* @param pUVM Pointer to the user mode VM structure.
* @param pszFilename Filename of the module binary.
* @param pszName Module name. Case sensitive and the length is limited!
*/
{
/*
* Validate input.
*/
{
return VERR_INVALID_PARAMETER;
}
/*
* Try lookup the name and see if the module exists.
*/
int rc;
{
{
else
return rc;
}
}
/*
* Allocate the module list node and initialize it.
*/
const char *pszSuff = RTLdrGetSuff();
if (pModule)
{
/*
* Load the loader item.
*/
if (RT_SUCCESS(rc))
{
}
else
{
/* Something went wrong, most likely module not found. Don't consider other unlikely errors */
}
}
else
rc = VERR_NO_MEMORY;
return rc;
}
#ifdef VBOX_WITH_RAW_MODE
/**
* Resolve an external symbol during RTLdrGetBits() of a RC module.
*
* @returns VBox status code.
* @param hLdrMod The loader module handle.
* @param pszModule Module name.
* @param pszSymbol Symbol name, NULL if uSymbol should be used.
* @param uSymbol Symbol ordinal, ~0 if pszSymbol should be used.
* @param pValue Where to store the symbol value (address).
* @param pvUser User argument.
*/
static DECLCALLBACK(int) pdmR3GetImportRC(RTLDRMOD hLdrMod, const char *pszModule, const char *pszSymbol, unsigned uSymbol, RTUINTPTR *pValue, void *pvUser)
{
/*
* Adjust input.
*/
/*
* Builtin module.
*/
{
int rc = VINF_SUCCESS;
{
if (RT_SUCCESS(rc))
}
{
if (RT_SUCCESS(rc))
}
else
{
AssertMsg(!pszModule, ("Unknown builtin symbol '%s' for module '%s'!\n", pszSymbol, pModule->szName)); NOREF(pModule);
}
{
if (RT_FAILURE(rc))
return rc;
}
}
/*
* Search for module.
*/
while (pCur)
{
&& ( !pszModule
)
{
/* Search for the symbol. */
if (RT_SUCCESS(rc))
{
return rc;
}
if (pszModule)
{
AssertLogRelMsgFailed(("PDMLdr: Couldn't find symbol '%s' in module '%s'!\n", pszSymbol, pszModule));
return VERR_SYMBOL_NOT_FOUND;
}
}
/* next */
}
AssertLogRelMsgFailed(("Couldn't find module '%s' for resolving symbol '%s'!\n", pszModule, pszSymbol));
return VERR_SYMBOL_NOT_FOUND;
}
/**
* Loads a module into the guest context (i.e. into the Hypervisor memory region).
*
* @returns VBox status code.
* @param pVM The VM to load it into.
* @param pszFilename Filename of the module binary.
* @param pszName Module name. Case sensitive and the length is limited!
*/
{
/*
* Validate input.
*/
while (pCur)
{
{
return VERR_PDM_MODULE_NAME_CLASH;
}
/* next */
}
/*
* Find the file if not specified.
*/
if (!pszFilename)
/*
* Allocate the module list node.
*/
if (!pModule)
{
return VERR_NO_MEMORY;
}
("pazName is too long (%d chars) max is %d chars.\n", strlen(pszName), sizeof(pModule->szName) - 1));
/*
* Open the loader item.
*/
if (RT_SUCCESS(rc))
{
}
if (RT_SUCCESS(rc))
{
/*
* Allocate space in the hypervisor.
*/
{
if (paPages)
{
if (RT_SUCCESS(rc))
{
if (RT_SUCCESS(rc))
{
/*
* Get relocated image bits.
*/
if (RT_SUCCESS(rc))
{
/*
* Insert the module.
*/
{
/* we don't expect this list to be very long, so rather save the tail pointer. */
}
else
return VINF_SUCCESS;
}
}
else
{
}
}
else
}
else
}
else
}
/* Don't consider VERR_PDM_MODULE_NAME_CLASH and VERR_NO_MEMORY above as these are very unlikely. */
rc = VMSetError(pVM, rc, RT_SRC_POS, N_("Cannot load RC module %s: %s"), pszFilename, ErrInfo.Core.pszMsg);
else if (RT_FAILURE(rc))
return rc;
}
#endif /* VBOX_WITH_RAW_MODE */
/**
* Loads a module into the ring-0 context.
*
* @returns VBox status code.
* @param pUVM Pointer to the user mode VM structure.
* @param pszFilename Filename of the module binary.
* @param pszName Module name. Case sensitive and the length is limited!
* @param pszSearchPath List of directories to search if @a pszFilename is
* not specified. Can be NULL, in which case the arch
* dependent install dir is searched.
*/
static int pdmR3LoadR0U(PUVM pUVM, const char *pszFilename, const char *pszName, const char *pszSearchPath)
{
/*
* Validate input.
*/
while (pCur)
{
{
return VERR_PDM_MODULE_NAME_CLASH;
}
/* next */
}
/*
* Find the file if not specified.
*/
if (!pszFilename)
/*
* Allocate the module list node.
*/
if (!pModule)
{
return VERR_NO_MEMORY;
}
("pazName is too long (%d chars) max is %d chars.\n", strlen(pszName), sizeof(pModule->szName) - 1));
/*
* Ask the support library to load it.
*/
void *pvImageBase;
if (RT_SUCCESS(rc))
{
/*
* Insert the module.
*/
{
/* we don't expect this list to be very long, so rather save the tail pointer. */
}
else
return VINF_SUCCESS;
}
/* Don't consider VERR_PDM_MODULE_NAME_CLASH and VERR_NO_MEMORY above as these are very unlikely. */
rc = VMSetError(pUVM->pVM, rc, RT_SRC_POS, N_("Cannot load R0 module %s: %s"), pszFilename, ErrInfo.Core.pszMsg);
return rc;
}
/**
* Get the address of a symbol in a given HC ring 3 module.
*
* @returns VBox status code.
* @param pVM VM handle.
* @param pszModule Module name.
* @param pszSymbol Symbol name. If it's value is less than 64k it's treated like a
* ordinal value rather than a string pointer.
* @param ppvValue Where to store the symbol value.
*/
VMMR3DECL(int) PDMR3LdrGetSymbolR3(PVM pVM, const char *pszModule, const char *pszSymbol, void **ppvValue)
{
/*
* Validate input.
*/
/*
* Find the module.
*/
{
{
int rc = RTLdrGetSymbolEx(pModule->hLdrMod, pModule->pvBits, pModule->ImageBase, pszSymbol, &Value);
if (RT_SUCCESS(rc))
{
}
else
{
AssertMsg(rc, ("Couldn't symbol '%u' in module '%s'\n", (unsigned)(uintptr_t)pszSymbol, pszModule));
else
}
return rc;
}
}
return VERR_SYMBOL_NOT_FOUND;
}
/**
* Get the address of a symbol in a given HC ring 0 module.
*
* @returns VBox status code.
* @param pVM VM handle.
* @param pszModule Module name. If NULL the main R0 module (VMMR0.r0) is assumes.
* @param pszSymbol Symbol name. If it's value is less than 64k it's treated like a
* ordinal value rather than a string pointer.
* @param ppvValue Where to store the symbol value.
*/
VMMR3DECL(int) PDMR3LdrGetSymbolR0(PVM pVM, const char *pszModule, const char *pszSymbol, PRTR0PTR ppvValue)
{
#ifdef PDMLDR_FAKE_MODE
*ppvValue = 0xdeadbeef;
return VINF_SUCCESS;
#else
/*
* Validate input.
*/
if (!pszModule)
pszModule = "VMMR0.r0";
/*
* Find the module.
*/
{
{
if (RT_FAILURE(rc))
{
}
return rc;
}
}
return VERR_SYMBOL_NOT_FOUND;
#endif
}
/**
* Same as PDMR3LdrGetSymbolR0 except that the module will be attempted loaded if not found.
*
* @returns VBox status code.
* @param pVM VM handle.
* @param pszModule Module name. If NULL the main R0 module (VMMR0.r0) is assumed.
* @param pszSearchPath List of directories to search if @a pszFile is
* not qualified with a path. Can be NULL, in which
* case the arch dependent install dir is searched.
* @param pszSymbol Symbol name. If it's value is less than 64k it's treated like a
* ordinal value rather than a string pointer.
* @param ppvValue Where to store the symbol value.
*/
VMMR3DECL(int) PDMR3LdrGetSymbolR0Lazy(PVM pVM, const char *pszModule, const char *pszSearchPath, const char *pszSymbol,
{
#ifdef PDMLDR_FAKE_MODE
*ppvValue = 0xdeadbeef;
return VINF_SUCCESS;
#else
/*
* Since we're lazy, we'll only check if the module is present
* and hand it over to PDMR3LdrGetSymbolR0 when that's done.
*/
if (pszModule)
{
AssertMsgReturn(!strpbrk(pszModule, "/\\:\n\r\t"), ("pszModule=%s\n", pszModule), VERR_INVALID_PARAMETER);
break;
if (!pModule)
{
}
}
#endif
}
/**
* Get the address of a symbol in a given RC module.
*
* @returns VBox status code.
* @param pVM VM handle.
* @param pszModule Module name. If NULL the main R0 module (VMMGC.gc) is assumes.
* @param pszSymbol Symbol name. If it's value is less than 64k it's treated like a
* ordinal value rather than a string pointer.
* @param pRCPtrValue Where to store the symbol value.
*/
VMMR3DECL(int) PDMR3LdrGetSymbolRC(PVM pVM, const char *pszModule, const char *pszSymbol, PRTRCPTR pRCPtrValue)
{
#if defined(PDMLDR_FAKE_MODE) || !defined(VBOX_WITH_RAW_MODE)
*pRCPtrValue = 0xfeedf00d;
return VINF_SUCCESS;
#else
/*
* Validate input.
*/
if (!pszModule)
pszModule = "VMMGC.gc";
/*
* Find the module.
*/
{
{
int rc = RTLdrGetSymbolEx(pModule->hLdrMod, pModule->pvBits, pModule->ImageBase, pszSymbol, &Value);
if (RT_SUCCESS(rc))
{
}
else
{
AssertMsg(rc, ("Couldn't symbol '%u' in module '%s'\n", (unsigned)(uintptr_t)pszSymbol, pszModule));
else
}
return rc;
}
}
return VERR_SYMBOL_NOT_FOUND;
#endif
}
/**
* Same as PDMR3LdrGetSymbolRC except that the module will be attempted loaded if not found.
*
* @returns VBox status code.
* @param pVM VM handle.
* @param pszModule Module name. If NULL the main R0 module (VMMGC.gc) is assumes.
* @param pszSearchPath List of directories to search if @a pszFile is
* not qualified with a path. Can be NULL, in which
* case the arch dependent install dir is searched.
* @param pszSymbol Symbol name. If it's value is less than 64k it's treated like a
* ordinal value rather than a string pointer.
* @param pRCPtrValue Where to store the symbol value.
*/
VMMR3DECL(int) PDMR3LdrGetSymbolRCLazy(PVM pVM, const char *pszModule, const char *pszSearchPath, const char *pszSymbol,
{
#if defined(PDMLDR_FAKE_MODE) || !defined(VBOX_WITH_RAW_MODE)
*pRCPtrValue = 0xfeedf00d;
return VINF_SUCCESS;
#else
/*
* Since we're lazy, we'll only check if the module is present
* and hand it over to PDMR3LdrGetSymbolRC when that's done.
*/
if (pszModule)
{
AssertMsgReturn(!strpbrk(pszModule, "/\\:\n\r\t"), ("pszModule=%s\n", pszModule), VERR_INVALID_PARAMETER);
break;
if (!pModule)
{
}
}
#endif
}
/**
* Constructs the full filename for a R3 image file.
*
* @returns Pointer to temporary memory containing the filename.
* Caller must free this using RTMemTmpFree().
* @returns NULL on failure.
*
* @param pszFile File name (no path).
*/
{
}
/**
* Constructs the full filename for a R0 image file.
*
* @returns Pointer to temporary memory containing the filename.
* Caller must free this using RTMemTmpFree().
* @returns NULL on failure.
*
* @param pszFile File name (no path).
* @param pszSearchPath List of directories to search if @a pszFile is
* not qualified with a path. Can be NULL, in which
* case the arch dependent install dir is searched.
*/
{
}
/**
* Constructs the full filename for a RC image file.
*
* @returns Pointer to temporary memory containing the filename.
* Caller must free this using RTMemTmpFree().
* @returns NULL on failure.
*
* @param pszFile File name (no path).
* @param pszSearchPath List of directories to search if @a pszFile is
* not qualified with a path. Can be NULL, in which
* case the arch dependent install dir is searched.
*/
{
}
/**
* Worker for pdmR3File().
*
* @returns Pointer to temporary memory containing the filename.
* Caller must free this using RTMemTmpFree().
* @returns NULL on failure.
*
* @param pszDir Directory part
* @param pszFile File name part
* @param pszDefaultExt Extension part
*/
{
/*
* Allocate temp memory for return buffer.
*/
/*
* Default extention?
*/
cchDefaultExt = 0;
else
/*
* Construct the filename.
*/
if (cchDefaultExt)
return pszRet;
}
/**
* Worker for pdmR3FileRC(), pdmR3FileR0() and pdmR3FileR3().
*
* @returns Pointer to temporary memory containing the filename.
* Caller must free this using RTMemTmpFree().
* @returns NULL on failure.
* @param pszFile File name (no path).
* @param pszDefaultExt The default extention, NULL if none.
* @param pszSearchPath List of directories to search if @a pszFile is
* not qualified with a path. Can be NULL, in which
* case the arch dependent install dir is searched.
* search in the private directory (/usr/lib/virtualbox on Unix).
* Ignored if VBOX_PATH_SHARED_LIBS is not defined.
* @todo We'll have this elsewhere than in the root later!
* @todo Remove the fShared hack again once we don't need to link against VBoxDD anymore!
*/
static char *pdmR3File(const char *pszFile, const char *pszDefaultExt, const char *pszSearchPath, bool fShared)
{
char szPath[RTPATH_MAX];
int rc;
/*
* If there is a path, search it.
*/
if ( pszSearchPath
&& *pszSearchPath)
{
/* Check the filename length. */
return NULL;
/*
* Walk the search path.
*/
const char *psz = pszSearchPath;
while (*psz)
{
/* Skip leading blanks - no directories with leading spaces, thank you. */
while (RT_C_IS_BLANK(*psz))
psz++;
/* Find the end of this element. */
const char *pszNext;
if (!pszEnd)
else
{
if (RT_SUCCESS(rc))
{
if (RTFileExists(szPath))
{
if (pszRet)
return pszRet;
}
}
}
/* advance */
}
}
/*
* Use the default location.
*/
if (!RT_SUCCESS(rc))
{
return NULL;
}
}
/** @internal */
typedef struct QMFEIPARG
{
char *pszNearSym1;
char *pszNearSym2;
} QMFEIPARG, *PQMFEIPARG;
/**
* Enumeration callback function used by RTLdrEnumSymbols().
*
* @returns VBox status code. Failure will stop the enumeration.
* @param hLdrMod The loader module handle.
* @param pszSymbol Symbol name. NULL if ordinal only.
* @param uSymbol Symbol ordinal, ~0 if not used.
* @param Value Symbol value.
* @param pvUser The user argument specified to RTLdrEnumSymbols().
*/
static DECLCALLBACK(int) pdmR3QueryModFromEIPEnumSymbols(RTLDRMOD hLdrMod, const char *pszSymbol, unsigned uSymbol, RTUINTPTR Value, void *pvUser)
{
if (off <= 0) /* near1 is before or at same location. */
{
{
{
if (pszSymbol)
else
{
char szOrd[32];
}
}
}
}
else /* near2 is after */
{
{
{
if (pszSymbol)
else
{
char szOrd[32];
}
}
}
}
return VINF_SUCCESS;
}
/**
* Internal worker for PDMR3LdrQueryRCModFromPC and PDMR3LdrQueryR0ModFromPC.
*
* @returns VBox status code.
*
* @param pVM VM handle
* @param enmType The module type.
* @param pszModName Where to store the module name.
* @param cchModName Size of the module name buffer.
* @param pMod Base address of the module.
* @param pszNearSym1 Name of the closes symbol from below.
* @param cchNearSym1 Size of the buffer pointed to by pszNearSym1.
* @param pNearSym1 The address of pszNearSym1.
* @param pszNearSym2 Name of the closes symbol from below.
* @param cchNearSym2 Size of the buffer pointed to by pszNearSym2.
* @param pNearSym2 The address of pszNearSym2.
*/
{
int rc = VERR_MODULE_NOT_FOUND;
{
continue;
/* The following RTLdrOpen call is a dirty hack to get ring-0 module information. */
{
if (RT_FAILURE(rc2))
}
if ( hLdrMod != NIL_RTLDRMOD
{
if (pMod)
if (pszModName && cchModName)
{
*pszModName = '\0';
}
/*
* Locate the nearest symbols.
*/
rc = VINF_SUCCESS;
}
if (RT_SUCCESS(rc))
break;
}
return rc;
}
/**
*
* This is typically used to locate a crash address.
*
* @returns VBox status code.
*
* @param pVM VM handle
* @param pszModName Where to store the module name.
* @param cchModName Size of the module name buffer.
* @param pMod Base address of the module.
* @param pszNearSym1 Name of the closes symbol from below.
* @param cchNearSym1 Size of the buffer pointed to by pszNearSym1.
* @param pNearSym1 The address of pszNearSym1.
* @param pszNearSym2 Name of the closes symbol from below.
* @param cchNearSym2 Size of the buffer pointed to by pszNearSym2.
* @param pNearSym2 The address of pszNearSym2.
*/
{
if (RT_SUCCESS(rc))
{
if (pMod)
if (pNearSym1)
if (pNearSym2)
}
return rc;
}
/**
*
* This is typically used to locate a crash address.
*
* @returns VBox status code.
*
* @param pVM VM handle
* @param pszModName Where to store the module name.
* @param cchModName Size of the module name buffer.
* @param pMod Base address of the module.
* @param pszNearSym1 Name of the closes symbol from below.
* @param cchNearSym1 Size of the buffer pointed to by pszNearSym1.
* @param pNearSym1 The address of pszNearSym1.
* @param pszNearSym2 Name of the closes symbol from below.
* @param cchNearSym2 Size of the buffer pointed to by pszNearSym2. Optional.
* @param pNearSym2 The address of pszNearSym2. Optional.
*/
{
if (RT_SUCCESS(rc))
{
if (pMod)
if (pNearSym1)
if (pNearSym2)
}
return rc;
}
/**
* Enumerate all PDM modules.
*
* @returns VBox status.
* @param pVM VM Handle.
* @param pfnCallback Function to call back for each of the modules.
* @param pvArg User argument.
*/
{
int rc = VINF_SUCCESS;
{
pvArg);
if (RT_FAILURE(rc))
break;
}
return rc;
}
/**
* Locates a module.
*
* @returns Pointer to the module if found.
* @param pUVM Pointer to the user mode VM structure.
* @param pszModule The module name.
* @param enmType The module type.
* @param fLazy Lazy loading the module if set.
* @param pszSearchPath Search path for use when lazy loading.
*/
bool fLazy, const char *pszSearchPath)
{
{
return pModule;
}
if (fLazy)
{
switch (enmType)
{
#ifdef VBOX_WITH_RAW_MODE
case PDMMOD_TYPE_RC:
{
if (pszFilename)
{
if (RT_SUCCESS(rc))
}
break;
}
#endif
case PDMMOD_TYPE_R0:
{
if (RT_SUCCESS(rc))
break;
}
default:
AssertFailed();
}
}
return NULL;
}
/**
* Resolves a ring-0 or raw-mode context interface.
*
* @returns VBox status code.
* @param pVM The VM handle.
* @param pvInterface Pointer to the interface structure. The symbol list
* describes the layout.
* @param cbInterface The size of the structure pvInterface is pointing
* to. For bounds checking.
* @param pszModule The module name. If NULL we assume it's the default
* R0 or RC module (@a fRing0OrRC). We'll attempt to
* load the module if it isn't found in the module
* list.
* @param pszSearchPath The module search path. If NULL, search the
* architecture dependent install directory.
* @param pszSymPrefix What to prefix the symbols in the list with. The
* idea is that you define a list that goes with an
* interface (INTERFACE_SYM_LIST) and reuse it with
* each implementation.
* @param pszSymList The symbol list for the interface. This is a
* semi-colon separated list of symbol base names. As
* mentioned above, each is prefixed with @a
* pszSymPrefix before resolving. There are a couple
* of special symbol names that will cause us to skip
* ahead a little bit:
* - U8:whatever,
* - U16:whatever,
* - U32:whatever,
* - U64:whatever,
* - RCPTR:whatever,
* - R3PTR:whatever,
* - R0PTR:whatever,
* - GCPHYS:whatever,
* - HCPHYS:whatever.
* @param fRing0 Set if it's a ring-0 context interface, clear if
* it's raw-mode context interface.
*/
const char *pszModule, const char *pszSearchPath,
const char *pszSymPrefix, const char *pszSymList,
bool fRing0)
{
/*
* Find the module.
*/
int rc = VINF_SUCCESS;
true /*fLazy*/, pszSearchPath);
if (pModule)
{
/* Prep the symbol name. */
char szSymbol[256];
/*
* Iterate the symbol list.
*/
uint32_t offInterface = 0;
const char *pszCur = pszSymList;
while (pszCur)
{
/*
* Find the end of the current symbol name.
*/
if (pszNext)
{
pszNext++;
}
else
/* Is it a skip instruction? */
if (pszColon)
{
/*
* String switch on the instruction and execute it, checking
* that we didn't overshoot the interface structure.
*/
#define IS_SKIP_INSTR(szInstr) \
if (IS_SKIP_INSTR("U8"))
offInterface += sizeof(uint8_t);
else if (IS_SKIP_INSTR("U16"))
offInterface += sizeof(uint16_t);
else if (IS_SKIP_INSTR("U32"))
offInterface += sizeof(uint32_t);
else if (IS_SKIP_INSTR("U64"))
offInterface += sizeof(uint64_t);
else if (IS_SKIP_INSTR("RCPTR"))
offInterface += sizeof(RTRCPTR);
else if (IS_SKIP_INSTR("R3PTR"))
offInterface += sizeof(RTR3PTR);
else if (IS_SKIP_INSTR("R0PTR"))
offInterface += sizeof(RTR0PTR);
else if (IS_SKIP_INSTR("HCPHYS"))
offInterface += sizeof(RTHCPHYS);
else if (IS_SKIP_INSTR("GCPHYS"))
offInterface += sizeof(RTGCPHYS);
else
AssertMsgFailedBreakStmt(("Invalid skip instruction %.*s (prefix=%s)\n", cchSym, pszCur, pszSymPrefix),
}
else
{
/*
* Construct the symbol name, get its value, store it and
* advance the interface cursor.
*/
if (fRing0)
{
void *pvValue;
offInterface += sizeof(*pValue);
}
else
{
offInterface += sizeof(*pValue);
}
}
/* advance */
}
}
else
return rc;
}