tstLdr-4.cpp revision 7258e84ec2fa7ecaf94e1a244bd6d2cf6b3a40a4
/* $Id$ */
/** @file
* InnoTek Portable Runtime - Testcase for RTLdrOpen using ldrLdrObjR0.r0.
*/
/*
* Copyright (C) 2006 InnoTek Systemberatung GmbH
*
* 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 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.
*
* If you received this file as part of a commercial VirtualBox
* distribution, then only the terms of your commercial VirtualBox
* license agreement apply instead of the previous paragraph.
*/
/*******************************************************************************
* Header Files *
*******************************************************************************/
/**
* 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
{
return VERR_SYMBOL_NOT_FOUND;
}
return VINF_SUCCESS;
}
/**
* One test iteration with one file.
*
* The test is very simple, we load the 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.
*/
static int testLdrOne(const char *pszFilename)
{
int cErrors = 0;
struct Load
{
void *pvBits;
const char *pszName;
} aLoads[6] =
{
};
unsigned i;
int rc;
/*
* Load them.
*/
{
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. */
rc = RTLdrGetSymbolEx(aLoads[i].hLdrMod, aLoads[i].pvBits, (uintptr_t)aLoads[i].pvBits, "DisasmTest1", &Value);
if (rc == VERR_SYMBOL_NOT_FOUND)
rc = RTLdrGetSymbolEx(aLoads[i].hLdrMod, aLoads[i].pvBits, (uintptr_t)aLoads[i].pvBits, "_DisasmTest1", &Value);
if (RT_FAILURE(rc))
{
cErrors++;
break;
}
DECLCALLBACKPTR(int, pfnDisasmTest1)(void) = (DECLCALLBACKPTR(int, )(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.
*/
{
{
if (RT_FAILURE(rc))
{
cErrors++;
}
}
}
return cErrors;
}
{
int cErrors = 0;
RTR3Init();
/*
* Sanity check.
*/
int rc = DisasmTest1();
if (rc)
{
return 1;
}
/*
* Execute the test.
*/
char szPath[RTPATH_MAX];
if (RT_SUCCESS(rc))
{
}
else
{
cErrors++;
}
/*
* Test result summary.
*/
if (!cErrors)
RTPrintf("tstLdr-4: SUCCESS\n");
else
return !!cErrors;
}