The Pedigree Project  0.1
Public Member Functions | Static Public Member Functions | Private Types | Private Member Functions | Static Private Member Functions | Private Attributes | Static Private Attributes | Friends | List of all members
KernelElf Class Reference
+ Inheritance diagram for KernelElf:
+ Collaboration diagram for KernelElf:

Public Member Functions

bool initialise (const BootstrapStruct_t &pBootstrap) INITIALISATION_ONLY
 
ModuleloadModule (uint8_t *pModule, size_t len, bool silent=false)
 
void executeModules (bool silent=false, bool progress=true)
 
void unloadModule (const char *name, bool silent=false, bool progress=true)
 
void unloadModule (Module *module, bool silent=false, bool progress=true)
 
void unloadModules ()
 
bool moduleIsLoaded (char *name)
 
char * getDependingModule (char *name)
 
uintptr_t globalLookupSymbol (const char *pName)
 
const char * globalLookupSymbol (uintptr_t addr, uintptr_t *startAddr=0)
 
MemoryAllocatorgetModuleAllocator ()
 
bool hasPendingModules () const
 
void updateModuleStatus (Module *module, bool status)
 
void waitForModulesToLoad ()
 
- Public Member Functions inherited from Elf
 Elf ()
 
virtual ~Elf ()
 
 Elf (const Elf &)
 
bool validate (uint8_t *pBuffer, size_t length)
 
bool create (uint8_t *pBuffer, size_t length)
 
bool createNeededOnly (uint8_t *pBuffer, size_t length)
 
bool loadModule (uint8_t *pBuffer, size_t length, uintptr_t &loadBase, size_t &loadSize, SymbolTable *pSymbolTableCopy=0)
 
bool finaliseModule (uint8_t *pBuffer, uintptr_t length)
 
bool allocate (uint8_t *pBuffer, size_t length, uintptr_t &loadBase, SymbolTable *pSymtab=0, bool bAllocate=true, size_t *pSize=0)
 
bool load (uint8_t *pBuffer, size_t length, uintptr_t loadBase, SymbolTable *pSymtab=0, uintptr_t nStart=0, uintptr_t nEnd=~0, bool relocate=true)
 
List< char * > & neededLibraries ()
 
StringgetInterpreter ()
 
uintptr_t getLastAddress ()
 
uintptr_t getInitFunc ()
 
uintptr_t getFiniFunc ()
 
template<class T = ElfSymbol_t>
const char * lookupSymbol (uintptr_t addr, uintptr_t *startAddr, T *symbolTable)
 
const char * lookupSymbol (uintptr_t addr, uintptr_t *startAddr)
 
uintptr_t lookupSymbol (const char *pName)
 
uintptr_t lookupDynamicSymbolAddress (const char *str, uintptr_t loadBase)
 
uintptr_t applySpecificRelocation (uintptr_t off, SymbolTable *pSymtab, uintptr_t loadBase, SymbolTable::Policy policy=SymbolTable::LocalFirst)
 
uintptr_t getGlobalOffsetTable ()
 
size_t getPltSize ()
 
void populateSymbolTable (SymbolTable *pSymtab, uintptr_t loadBase)
 
void preallocateSymbols (SymbolTable *pSymtabOverride=nullptr, SymbolTable *pAdditionalSymtab=nullptr)
 
SymbolTablegetSymbolTable ()
 
uintptr_t getEntryPoint ()
 
uintptr_t debugFrameTable ()
 
uintptr_t debugFrameTableLength ()
 
void setName (const String &s)
 
const StringgetName () const
 

Static Public Member Functions

static KernelElfinstance ()
 
- Static Public Member Functions inherited from Elf
static bool extractEntryPoint (uint8_t *pBuffer, size_t length, uintptr_t &entry)
 
static bool extractInformation (uint8_t *pBuffer, size_t length, size_t &phdrCount, size_t &phdrEntrySize, uintptr_t &phdrAddress)
 

Private Types

typedef Elf32SectionHeader_t KernelElfSectionHeader_t
 
typedef Elf32Symbol_t KernelElfSymbol_t
 

Private Member Functions

 KernelElf () INITIALISATION_ONLY
 
 KernelElf (const KernelElf &)
 
virtual ~KernelElf ()
 
KernelElfoperator= (const KernelElf &)
 
bool moduleDependenciesSatisfied (Module *module)
 
bool executeModule (Module *module)
 
void lockModules ()
 
void unlockModules ()
 

Static Private Member Functions

template<class T >
static T * rebase (Module *module, T *ptr)
 

Private Attributes

MemoryRegion m_AdditionalSectionContents
 
MemoryRegionm_AdditionalSectionHeaders
 
Vector< Module * > m_Modules
 
MemoryAllocator m_ModuleAllocator
 
Elf32SectionHeader_t * m_pSectionHeaders
 
Elf32Symbol_tm_pSymbolTable
 
Semaphore m_ModuleProgress
 
Spinlock m_ModuleAdjustmentLock
 

Static Private Attributes

static KernelElf m_Instance
 

Friends

void system_reset ()
 

Additional Inherited Members

- Protected Attributes inherited from Elf
struct Elf::ElfHeader_t PACKED
 
struct Elf::ElfProgramHeader_t PACKED
 
struct Elf::ElfSectionHeader_t PACKED
 
struct Elf::Elf32SectionHeader_t PACKED
 
struct Elf::ElfSymbol_t PACKED
 
struct Elf::Elf32Symbol_t PACKED
 
struct Elf::ElfDyn_t PACKED
 
struct Elf::ElfRel_t PACKED
 
struct Elf::ElfRela_t PACKED
 
ElfSymbol_tm_pSymbolTable
 
size_t m_nSymbolTableSize
 
char * m_pStringTable
 
size_t m_nStringTableSize
 
char * m_pShstrtab
 
size_t m_nShstrtabSize
 
uintptr_t * m_pGotTable
 
ElfRel_tm_pRelTable
 
ElfRela_tm_pRelaTable
 
size_t m_nRelTableSize
 
size_t m_nRelaTableSize
 
ElfRel_tm_pPltRelTable
 
ElfRela_tm_pPltRelaTable
 
bool m_bUsesRela
 
uint32_t * m_pDebugTable
 
size_t m_nDebugTableSize
 
ElfSymbol_tm_pDynamicSymbolTable
 
size_t m_nDynamicSymbolTableSize
 
char * m_pDynamicStringTable
 
size_t m_nDynamicStringTableSize
 
ElfSectionHeader_tm_pSectionHeaders
 
size_t m_nSectionHeaders
 
ElfProgramHeader_tm_pProgramHeaders
 
size_t m_nProgramHeaders
 
size_t m_nPltSize
 
uintptr_t m_nEntry
 
List< char * > m_NeededLibraries
 
SymbolTable m_SymbolTable
 
uintptr_t m_InitFunc
 
uintptr_t m_FiniFunc
 
String m_sInterpreter
 
String m_Name
 
uintptr_t m_LoadBase
 

Detailed Description

Definition at line 122 of file KernelElf.h.

Constructor & Destructor Documentation

KernelElf::KernelElf ( )
private

Default constructor does nothing

Definition at line 403 of file KernelElf.cc.

KernelElf::KernelElf ( const KernelElf )
private

Copy-constructor

Note
NOT implemented (singleton class)
KernelElf::~KernelElf ( )
privatevirtual

Destructor does nothing

Definition at line 417 of file KernelElf.cc.

Member Function Documentation

void KernelElf::executeModules ( bool  silent = false,
bool  progress = true 
)

Executes all modules.

Definition at line 569 of file KernelElf.cc.

References Vector< T >::begin(), Vector< T >::count(), DEBUG_LOG, loadModule(), m_Modules, NOTICE, and Vector< T >::pushBack().

char * KernelElf::getDependingModule ( char *  name)

Returns the name of the first module that have the specified module as dependency.

Definition at line 809 of file KernelElf.cc.

References Thread::detach(), FATAL, Elf::finaliseModule(), Processor::information(), instance(), Elf::lookupSymbol(), m_Modules, NOTICE, rebase(), updateModuleStatus(), and WARNING.

MemoryAllocator& KernelElf::getModuleAllocator ( )
inline

Returns the address space allocator for modules.

Definition at line 174 of file KernelElf.h.

References INITIALISATION_ONLY.

uintptr_t KernelElf::globalLookupSymbol ( const char *  pName)

Looks up the address of the symbol with name 'pName' globally, that is throughout all modules and the kernel itself.

Definition at line 1031 of file KernelElf.cc.

References SymbolTable::lookup().

Referenced by DisassembleCommand::execute(), LookupCommand::execute(), ThreadsCommand::execute(), SlamCommand::execute(), AllocationCommand::execute(), TraceCommand::execute(), LocksCommand::execute(), and Backtrace::performBpBacktrace().

+ Here is the caller graph for this function:

const char * KernelElf::globalLookupSymbol ( uintptr_t  addr,
uintptr_t *  startAddr = 0 
)
Todo:
This shouldn't match local or weak symbols.

Definition at line 1036 of file KernelElf.cc.

References Hex, lockModules(), Elf::lookupSymbol(), m_Modules, and unlockModules().

bool KernelElf::hasPendingModules ( ) const

Do we have pending modules still?

Definition at line 1071 of file KernelElf.cc.

References m_Modules, and NOTICE.

bool KernelElf::initialise ( const BootstrapStruct_t pBootstrap)
static KernelElf& KernelElf::instance ( )
inlinestatic
Module * KernelElf::loadModule ( uint8_t *  pModule,
size_t  len,
bool  silent = false 
)

Treats the given pointer as an ELF partially linked object file and loads it, relocates it and links it.

Parameters
pModuleA pointer to an ELF module/driver.
lenThe length of pModule, in bytes.
silentIf true will not update the boot progress(default is false).
Returns
A pointer to a Elf class describing the loaded module.

Definition at line 432 of file KernelElf.cc.

References Vector< T >::count(), Elf::create(), DEBUG_LOG, Dec, Elf::Elf(), ERROR, FATAL, RangeList< T, Reversed >::free(), VirtualAddressSpace::getKernelAddressSpace(), VirtualAddressSpace::getKernelModulesEnd(), VirtualAddressSpace::getKernelModulesStart(), Hex, Elf::loadModule(), Elf::lookupSymbol(), m_ModuleAllocator, m_Modules, NOTICE, Vector< T >::pushBack(), rebase(), Elf::setName(), and UNLIKELY.

Referenced by executeModules().

+ Here is the caller graph for this function:

void KernelElf::lockModules ( )
private

Lock for access to the module data structures.

Definition at line 1084 of file KernelElf.cc.

References Spinlock::acquire().

Referenced by globalLookupSymbol().

+ Here is the caller graph for this function:

bool KernelElf::moduleIsLoaded ( char *  name)

Returns true if a module with the specified name has been loaded.

Definition at line 790 of file KernelElf.cc.

References m_Modules.

KernelElf& KernelElf::operator= ( const KernelElf )
private

Assignment operator

Note
NOT implemented (singleton class)
template<class T >
static T* KernelElf::rebase ( Module module,
T *  ptr 
)
inlinestaticprivate

Rebase a pointer for the given loaded module.

Definition at line 205 of file KernelElf.h.

Referenced by getDependingModule(), and loadModule().

+ Here is the caller graph for this function:

void KernelElf::unloadModule ( const char *  name,
bool  silent = false,
bool  progress = true 
)
void KernelElf::unloadModules ( )

Unloads all loaded modules.

Definition at line 773 of file KernelElf.cc.

References m_Modules, and unloadModule().

void KernelElf::unlockModules ( )
private

Unlock access to module data structures.

Definition at line 1091 of file KernelElf.cc.

References Spinlock::release().

Referenced by globalLookupSymbol().

+ Here is the caller graph for this function:

void KernelElf::updateModuleStatus ( Module module,
bool  status 
)

Updates the status of the given module.

Definition at line 983 of file KernelElf.cc.

References m_ModuleProgress, NOTICE, Semaphore::release(), and unloadModule().

Referenced by getDependingModule().

+ Here is the caller graph for this function:

void KernelElf::waitForModulesToLoad ( )

Waits for all modules to complete (whether successfully or not).

Definition at line 1003 of file KernelElf.cc.

References Semaphore::acquire(), Vector< T >::count(), m_ModuleProgress, m_Modules, and NOTICE.

Member Data Documentation

KernelElf KernelElf::m_Instance
staticprivate

Instance of the KernelElf class

Definition at line 222 of file KernelElf.h.

MemoryAllocator KernelElf::m_ModuleAllocator
private

Memory allocator for modules - where they can be loaded.

Definition at line 227 of file KernelElf.h.

Referenced by loadModule(), and unloadModule().

Semaphore KernelElf::m_ModuleProgress
private

Tracks the module loading process.

Definition at line 246 of file KernelElf.h.

Referenced by updateModuleStatus(), and waitForModulesToLoad().

Vector<Module *> KernelElf::m_Modules
private
Elf32SectionHeader_t* KernelElf::m_pSectionHeaders
private

Override Elf base class members.

Definition at line 231 of file KernelElf.h.

Referenced by initialise().


The documentation for this class was generated from the following files: