/* $Id$ */
/** @file
* IPRT - Testcase for RTLdrOpen using ldrLdrObjR0.r0.
*/
/*
* Copyright (C) 2006-2012 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.
*
* The contents of this file may alternatively be used under the terms
* of the Common Development and Distribution License Version 1.0
* (CDDL) only, as it comes in the "COPYING.CDDL" file of the
* VirtualBox OSE distribution, in which case the provisions of the
* CDDL are applicable instead of those of the GPL.
*
* You may elect to license modified versions of this file under the
* terms and conditions of either the GPL or the CDDL or both.
*/
/*******************************************************************************
* Header Files *
*******************************************************************************/
#include <iprt/initterm.h>
/**
* Resolve an external symbol during RTLdrGetBits().
*
* @returns iprt 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) testGetImport(RTLDRMOD hLdrMod, const char *pszModule, const char *pszSymbol, unsigned uSymbol, RTUINTPTR *pValue, void *pvUser)
{
else if (!strcmp(pszSymbol, "RTR0AssertPanicSystem")|| !strcmp(pszSymbol, "_RTR0AssertPanicSystem"))
else
{
return VERR_SYMBOL_NOT_FOUND;
}
return VINF_SUCCESS;
}
/**
* One test iteration with one file.
*
* The test is very simple, we load the file three times
* into two different regions. The first two into each of the
* regions the for compare usage. The third is loaded into one
* and then relocated between the two and other locations a few times.
*
* @returns number of errors.
* @param pszFilename The file to load the mess with.
*/
{
int cErrors = 0;
struct Load
{
void *pvBits;
const char *pszName;
{
};
unsigned i;
int rc;
/*
* Load them.
*/
for (i = 0; i < RT_ELEMENTS(aLoads); i++)
{
else
if (RT_FAILURE(rc))
{
cErrors++;
break;
}
/* size it */
{
cErrors++;
break;
}
/* Allocate bits. */
{
cErrors++;
break;
}
/* Get the bits. */
rc = RTLdrGetBits(aLoads[i].hLdrMod, aLoads[i].pvBits, (uintptr_t)aLoads[i].pvBits, testGetImport, NULL);
if (RT_FAILURE(rc))
{
cErrors++;
break;
}
}
/*
* Execute the code.
*/
if (!cErrors)
{
{
/* get the pointer. */
if (rc == VERR_SYMBOL_NOT_FOUND)
if (RT_FAILURE(rc))
{
cErrors++;
break;
}
DECLCALLBACKPTR(int, pfnDisasmTest1)(void) = (DECLCALLBACKPTR(int, RT_NOTHING)(void))(uintptr_t)Value; /* eeeh. */
RTPrintf("tstLdr-4: pfnDisasmTest1=%p / add-symbol-file %s %#x\n", pfnDisasmTest1, pszFilename, aLoads[i].pvBits);
/* call the test function. */
rc = pfnDisasmTest1();
if (rc)
{
cErrors++;
}
}
}
/*
* Clean up.
*/
for (i = 0; i < RT_ELEMENTS(aLoads); i++)
{
{
if (RT_FAILURE(rc))
{
cErrors++;
}
}
}
return cErrors;
}
{
int cErrors = 0;
/*
* Sanity check.
*/
if (rc)
{
return 1;
}
/*
* Execute the test.
*/
if (RT_SUCCESS(rc))
{
}
else
{
cErrors++;
}
/*
* Test result summary.
*/
if (!cErrors)
RTPrintf("tstLdr-4: SUCCESS\n");
else
return !!cErrors;
}