DBGPlugInCommonELF.cpp revision 14ea3173c84464d4e7bd7d4862fb14154820f7e2
/* $Id$ */
/** @file
* DBGPlugInCommonELF - Common code for dealing with ELF images.
*/
/*
* Copyright (C) 2008 Sun Microsystems, Inc.
*
* 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.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
* Clara, CA 95054 USA or visit http://www.sun.com if you need
* additional information or have any questions.
*/
/*******************************************************************************
* Header Files *
*******************************************************************************/
#include "DBGPlugInCommonELF.h"
/**
* Common 32-bit ELF module parser.
*
* It takes the essential bits of the ELF module (elf header, section headers,
*
*
* @returns VBox status code.
*
* @param pVM The VM handle.
* @param pszModName The module name.
* @param pszFilename The filename. optional.
* @param fFlags Flags.
* @param pEhdr Pointer to the ELF header.
* @param paShdrs Pointer to the section headers. The caller must verify that
* the e_shnum member of the ELF header is within the bounds of
* this table. The caller should also adjust the section addresses
* so these correspond to actual load addresses.
* @param paSyms Pointer to the symbol table.
* @param cMaxSyms The maximum number of symbols paSyms may hold. This isn't
* the exact count, it's just a cap for avoiding SIGSEGVs
* and general corruption.
* @param pbStrings Pointer to the string table.
* @param cbMaxStrings The size of the memory pbStrings points to. This doesn't
* have to match the string table size exactly, it's just to
* avoid SIGSEGV when a bad string index is encountered.
*/
int DBGDiggerCommonParseElf32Mod(PVM pVM, const char *pszModName, const char *pszFilename, uint32_t fFlags,
{
/*
* Validate the ELF header.
*/
return VERR_INVALID_EXE_SIGNATURE;
return VERR_LDRELF_MACHINE;
return VERR_LDRELF_ODD_ENDIAN;
return VERR_LDRELF_VERSION;
return VERR_LDRELF_VERSION;
return VERR_BAD_EXE_FORMAT;
return VERR_LDRELF_MACHINE;
return VERR_BAD_EXE_FORMAT;
return VERR_BAD_EXE_FORMAT;
return VERR_BAD_EXE_FORMAT;
return VERR_BAD_EXE_FORMAT;
return VERR_BAD_EXE_FORMAT;
/*
* Validate the section headers, finding the string
* and symbol table headers while at it.
*/
{
/* Minimal validation. */
return VERR_BAD_EXE_FORMAT;
/* Is it the symbol table?*/
{
if (pSymShdr)
return VERR_LDRELF_MULTIPLE_SYMTABS;
return VERR_BAD_EXE_FORMAT;
}
}
/*
* Validate the symbol table.
*/
: cMaxSyms;
{
if ( !(fFlags & DBG_DIGGER_ELF_FUNNY_SHDRS)
/*|| paSyms[iSym].st_shndx > SHN_HIRESERVE*/
return VERR_BAD_EXE_FORMAT;
}
/*
* Create a module / update it.
*/
/** @todo debug modules - the funny shdrs (solaris) are going to be cool here... */
/*
* Add all relevant symbols in the module
*/
{
/* Undefined symbols are not exports, they are imports. */
{
/* Get the symbol name. */
continue;
if (!*pszSymbol)
continue;
/* Calc the address (value) and size. */
/* absolute symbols are not subject to any relocation. */;
else if (fFlags & DBG_DIGGER_ELF_ADJUST_SYM_VALUE)
{
AssertFailed(/*impossible*/);
/* relative to the section. */
}
}
/*else: silently ignore */
}
return VINF_SUCCESS;
}