|
The Pedigree Project 0.1
|
Inheritance diagram for KernelElf:
Collaboration diagram for KernelElf:Classes | |
| class | RuntimeLoad |
Public Types | |
| enum class | RuntimeUnloadResult { Unloaded , NotFound , Busy , Pinned , DependedOn , Shutdown } |
| enum class | RuntimeLoadResult { Ready , Loaded , InvalidImage , UnsupportedImage , ImageTooLarge , NoMemory , Busy , Shutdown , Duplicate , MissingDependency , EntryFailed , ProtectionFailed } |
| typedef bool(* | TerminalQuiesceHook) () |
Public Types inherited from Elf | |
| enum class | ExecutableValidationResult { Valid , Malformed , WrongArchitecture , UnsupportedType , UnsupportedLayout , MultipleInterpreters } |
Public Member Functions | |
| bool | initialise (const BootstrapStruct_t &pBootstrap) INITIALISATION_ONLY |
| Module * | loadModule (uint8_t *pModule, size_t len, bool silent=false) |
| Module * | loadModule (struct ModuleInfo *info, bool silent=false) |
| void | executeModules (bool silent=false, bool progress=true) |
| bool | unloadModule (const char *name, bool silent=false, bool progress=true) |
| bool | unloadModule (Module *module, bool silent=false, bool progress=true) |
| RuntimeUnloadResult | unloadModuleRuntime (const char *name) |
| bool | prepareRuntimeModules () |
| RuntimeLoadResult | beginRuntimeModuleLoad (size_t length, RuntimeLoad &load) |
| RuntimeLoadResult | loadModuleRuntime (RuntimeLoad &load) |
| MUST_USE_RESULT bool | unloadModules () |
| bool | isShuttingDown () const |
| bool | registerTerminalQuiesce (ModuleEntry ownerEntry, TerminalQuiesceHook hook) |
| bool | registerUnloadAdmission (ModuleEntry ownerEntry, Module::UnloadAdmissionHook hook) |
| bool | unregisterTerminalQuiesce (ModuleEntry ownerEntry, TerminalQuiesceHook hook) |
| bool | moduleIsLoaded (char *name) |
| char * | getDependingModule (char *name) |
| uintptr_t | globalLookupSymbol (const char *pName) |
| const char * | globalLookupSymbol (uintptr_t addr, uintptr_t *startAddr=0) |
| size_t | getModuleCount () |
| const Module * | getModule (size_t index) |
| MemoryAllocator & | getModuleAllocator () |
| bool | hasPendingModules () const |
| void | updateModuleStatus (Module *module, bool status, bool runFailureLifecycle=true) |
| void | waitForModulesToLoad () |
| void | invokeInitModule () |
| Invokes the module named 'init'. When a module named init is discovered, rather than executing it in the usual module order, it is kept aside until this function is called. | |
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, size_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, uintptr_t destinationBase=0) |
| List< char * > & | neededLibraries () |
| String & | getInterpreter () |
| 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) |
| SymbolTable * | getSymbolTable () |
| uintptr_t | getEntryPoint () |
| uintptr_t | debugFrameTable () |
| uintptr_t | debugFrameTableLength () |
| void | setName (const String &s) |
| const String & | getName () const |
Static Public Member Functions | |
| static KernelElf & | instance () |
Static Public Member Functions inherited from Elf | |
| static ExecutableValidationResult | validateExecutableHeader (const uint8_t *pBuffer, size_t length, size_t fileSize, ExecutableMetadata &metadata) |
| static ExecutableValidationResult | validateExecutableProgramHeaders (const uint8_t *pBuffer, size_t length, size_t fileSize, ExecutableMetadata &metadata) |
| static ExecutableValidationResult | validateExecutableInterpreter (const uint8_t *pBuffer, size_t length, const ExecutableMetadata &metadata) |
| 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 | |
| enum | ModuleUnloadClaim { UnloadClaimed , UnloadComplete , UnloadBusy , UnloadPinned , UnloadRuntimePinned , UnloadDependedOn , UnloadUnknown , UnloadShutdown } |
| enum | TerminalQuiesceState { QuiesceOpen , QuiesceInvoking , QuiesceComplete , QuiesceFailed } |
| enum | ModuleShutdownState { ShutdownOpen , ShutdownRunning , ShutdownComplete , ShutdownFailed } |
| typedef ElfSectionHeader_t | KernelElfSectionHeader_t |
| typedef ElfSymbol_t | KernelElfSymbol_t |
Private Member Functions | |
| KernelElf () INITIALISATION_ONLY | |
| KernelElf (const KernelElf &) | |
| virtual | ~KernelElf () |
| KernelElf & | operator= (const KernelElf &) |
| bool | moduleDependenciesSatisfiedLocked (Module *module) const |
| bool | claimModuleExecutionLocked (Module *module) |
| bool | executeModule (Module *module) |
| void | abandonRuntimeModuleLoad (RuntimeLoad &load) |
| bool | retireRuntimeModule (Module *module, bool runLifecycle) |
| uintptr_t | runtimeExportLocked (const char *name, Module *owner=nullptr) const |
| const char * | runtimeLookupSymbolLocked (uintptr_t addr, uintptr_t *startAddr) const |
| uintptr_t | resolveRuntimeImport (const char *name, Module *consumer) |
| bool | beginModuleLoad () |
| void | finishModuleLoad () |
| bool | moduleRegisteredLocked (Module *module) const |
| ModuleUnloadClaim | claimModuleUnloadLocked (Module *module, bool allowShutdown, bool requireMembership, bool enforceDependencies, bool &wasFailed, bool &runLifecycle) |
| bool | completeUnloadAttempt (Module *module, ModuleUnloadClaim claim, bool wasFailed, bool runLifecycle, bool silent, bool progress, bool terminal=false) |
| void | finishClaimedUnload (Module *module, bool wasFailed) |
| void | lockModules () |
| void | unlockModules () |
Static Private Member Functions | |
| static Module * | findModuleByName (const Vector< Module * > &modules, const String &name) |
| static bool | moduleDependsOn (Module *consumer, Module *provider) |
| static bool | hasLiveDependent (const Vector< Module * > &modules, Module *provider) |
| static Module * | findUnloadCandidate (const Vector< Module * > &modules, bool &waiting) |
| template<class T > | |
| static T * | rebase (Module *module, T *ptr) |
Private Attributes | |
| MemoryRegion | m_AdditionalSectionContents |
| MemoryRegion * | m_AdditionalSectionHeaders |
| Vector< Module * > | m_Modules |
| MemoryAllocator | m_ModuleAllocator |
| bool | m_ModuleAllocatorInitialised |
| bool | m_RuntimeModulesPrepared |
| ElfSectionHeader_t * | m_pSectionHeaders |
| ElfSymbol_t * | m_pSymbolTable |
| Spinlock | m_ModuleAdjustmentLock |
| bool | m_ModuleShutdown |
| ModuleShutdownState | m_ModuleShutdownStatus |
| bool | m_ModuleLoading |
| Module * | m_UnloadingModule |
| size_t | m_ModuleExecutions |
| size_t | m_ModuleExecutionPasses |
| Module * | m_TerminalQuiesceOwner |
| TerminalQuiesceHook | m_TerminalQuiesceHook |
| TerminalQuiesceState | m_TerminalQuiesceStatus |
| Module * | m_InitModule |
Static Private Attributes | |
| static KernelElf | m_Instance |
Friends | |
| void | _cxx_main (BootstrapStruct_t &) |
Definition at line 127 of file KernelElf.h.
|
private |
Definition at line 405 of file KernelElf.h.
|
private |
Definition at line 406 of file KernelElf.h.
| typedef bool(* KernelElf::TerminalQuiesceHook) () |
Definition at line 131 of file KernelElf.h.
|
private |
Definition at line 333 of file KernelElf.h.
|
private |
Definition at line 315 of file KernelElf.h.
|
strong |
Definition at line 165 of file KernelElf.h.
|
strong |
Definition at line 160 of file KernelElf.h.
|
private |
Definition at line 326 of file KernelElf.h.
|
private |
Default constructor does nothing
Definition at line 323 of file KernelElf.cc.
|
private |
Copy-constructor
|
privatevirtual |
Destructor does nothing
Definition at line 344 of file KernelElf.cc.
|
private |
Definition at line 436 of file KernelElf-runtime.cc.
|
private |
Definition at line 356 of file KernelElf.cc.
| KernelElf::RuntimeLoadResult KernelElf::beginRuntimeModuleLoad | ( | size_t | length, |
| RuntimeLoad & | load | ||
| ) |
Definition at line 183 of file KernelElf-runtime.cc.
|
private |
Definition at line 1431 of file KernelElf.cc.
|
private |
Definition at line 707 of file KernelElf.cc.
|
private |
Definition at line 764 of file KernelElf.cc.
|
private |
Definition at line 1557 of file KernelElf.cc.
| void KernelElf::executeModules | ( | bool | silent = false, |
| bool | progress = true |
||
| ) |
Executes all modules.
Definition at line 505 of file KernelElf.cc.
References Vector< T >::count(), Scheduler::instance(), lockModules(), m_Modules, unlockModules(), and Scheduler::yield().
|
staticprivate |
Definition at line 648 of file KernelElf.cc.
|
staticprivate |
Definition at line 687 of file KernelElf.cc.
|
private |
Definition at line 754 of file KernelElf.cc.
|
private |
Definition at line 366 of file KernelElf.cc.
| char * KernelElf::getDependingModule | ( | char * | name | ) |
Returns the name of the first module that have the specified module as dependency.
Definition at line 1402 of file KernelElf.cc.
References lockModules(), m_Modules, rebase(), and unlockModules().
| const Module * KernelElf::getModule | ( | size_t | index | ) |
Returns a module record by index, or nullptr when the index is invalid.
Definition at line 1741 of file KernelElf.cc.
References lockModules(), and unlockModules().
|
inline |
Returns the address space allocator for modules.
Definition at line 274 of file KernelElf.h.
| size_t KernelElf::getModuleCount | ( | ) |
Returns the number of module records currently retained by the loader.
Definition at line 1734 of file KernelElf.cc.
References Vector< T >::count(), lockModules(), m_Modules, and unlockModules().
| 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 1695 of file KernelElf.cc.
References lockModules(), SymbolTable::lookup(), and unlockModules().
Referenced by DisassembleCommand::execute(), LookupCommand::execute(), SlamCommand::execute(), and TraceCommand::execute().
Here is the caller graph for this function:| const char * KernelElf::globalLookupSymbol | ( | uintptr_t | addr, |
| uintptr_t * | startAddr = 0 |
||
| ) |
Definition at line 1706 of file KernelElf.cc.
|
staticprivate |
Definition at line 675 of file KernelElf.cc.
| bool KernelElf::hasPendingModules | ( | ) | const |
Do we have pending modules still?
Definition at line 1748 of file KernelElf.cc.
References m_Modules.
| bool KernelElf::initialise | ( | const BootstrapStruct_t & | pBootstrap | ) |
Extracts the symbol and string tables from the given BootstrapInfo class.
Definition at line 74 of file KernelElf.cc.
References PhysicalMemoryManager::allocateRegion(), PhysicalMemoryManager::continuous, EMIT_IF, PhysicalMemoryManager::getPageSize(), Hex, SymbolTable::insert(), PhysicalMemoryManager::instance(), VirtualAddressSpace::KernelMode, m_AdditionalSectionContents, SymbolTable::preallocate(), and VirtualAddressSpace::Write.
|
inlinestatic |
Get the class instance
Definition at line 135 of file KernelElf.h.
Referenced by Elf::applyRelocation(), DisassembleCommand::execute(), LookupCommand::execute(), SlamCommand::execute(), TraceCommand::execute(), X64InterruptManager::interrupt(), Elf::loadModule(), panic(), Backtrace::performBacktrace(), and Backtrace::performDwarfBacktrace().
Here is the caller graph for this function:| void KernelElf::invokeInitModule | ( | ) |
Invokes the module named 'init'. When a module named init is discovered, rather than executing it in the usual module order, it is kept aside until this function is called.
This ensures the init module (which is generally used to invoke the userspace and become user-interactive) is always run last, and is not impacted by modules that load after it.
Definition at line 1650 of file KernelElf.cc.
References lockModules(), m_InitModule, m_Modules, moduleDependenciesSatisfiedLocked(), prepareRuntimeModules(), Vector< T >::pushBack(), and unlockModules().
|
inline |
Definition at line 208 of file KernelElf.h.
| Module * KernelElf::loadModule | ( | struct ModuleInfo * | info, |
| bool | silent = false |
||
| ) |
Load a static driver.
Definition at line 576 of file KernelElf.cc.
References EMIT_IF, lockModules(), m_InitModule, m_Modules, Vector< T >::pushBack(), rebase(), and unlockModules().
| 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.
| pModule | A pointer to an ELF module/driver. |
| len | The length of pModule, in bytes. |
| silent | If true will not update the boot progress(default is false). |
Definition at line 372 of file KernelElf.cc.
References Dec, EMIT_IF, RangeList< T, Reversed >::free(), VirtualAddressSpace::getKernelAddressSpace(), VirtualAddressSpace::getKernelModulesEnd(), VirtualAddressSpace::getKernelModulesStart(), Hex, lockModules(), m_InitModule, m_ModuleAllocator, m_Modules, Vector< T >::pushBack(), rebase(), UNLIKELY, and unlockModules().
| KernelElf::RuntimeLoadResult KernelElf::loadModuleRuntime | ( | RuntimeLoad & | load | ) |
Definition at line 293 of file KernelElf-runtime.cc.
|
private |
Lock for access to the module data structures.
Definition at line 1759 of file KernelElf.cc.
References Spinlock::acquire(), and EMIT_IF.
Referenced by executeModules(), getDependingModule(), getModule(), getModuleCount(), globalLookupSymbol(), invokeInitModule(), loadModule(), loadModule(), moduleIsLoaded(), prepareRuntimeModules(), registerTerminalQuiesce(), registerUnloadAdmission(), unloadModule(), unloadModuleRuntime(), unloadModules(), unregisterTerminalQuiesce(), updateModuleStatus(), and waitForModulesToLoad().
Here is the caller graph for this function:
|
private |
Requires the module lock.
Definition at line 1442 of file KernelElf.cc.
References m_Modules, and rebase().
Referenced by invokeInitModule().
Here is the caller graph for this function:Definition at line 657 of file KernelElf.cc.
| bool KernelElf::moduleIsLoaded | ( | char * | name | ) |
Returns true if a module with the specified name has been loaded.
Definition at line 1386 of file KernelElf.cc.
References lockModules(), and m_Modules.
|
private |
Definition at line 639 of file KernelElf.cc.
Assignment operator
| bool KernelElf::prepareRuntimeModules | ( | ) |
Trusted boot preparation; runtime admission never allocates or maps pages.
Definition at line 102 of file KernelElf-runtime.cc.
References RangeList< T, Reversed >::allocate(), PhysicalMemoryManager::allocatePage(), Vector< T >::count(), RangeList< T, Reversed >::free(), PhysicalMemoryManager::freePage(), VirtualAddressSpace::getKernelAddressSpace(), PhysicalMemoryManager::getPageSize(), PhysicalMemoryManager::instance(), VirtualAddressSpace::KernelMode, lockModules(), m_ModuleAllocator, m_Modules, Vector< T >::pushBack(), Vector< T >::reserve(), unlockModules(), and VirtualAddressSpace::Write.
Referenced by invokeInitModule().
Here is the caller graph for this function:
|
inlinestaticprivate |
Rebase a pointer for the given loaded module.
Definition at line 363 of file KernelElf.h.
References EMIT_IF.
Referenced by getDependingModule(), loadModule(), loadModule(), and moduleDependenciesSatisfiedLocked().
Here is the caller graph for this function:| bool KernelElf::registerTerminalQuiesce | ( | ModuleEntry | ownerEntry, |
| TerminalQuiesceHook | hook | ||
| ) |
Registers one terminal quiesce callback owned by the module whose entry point is ownerEntry. Registration is valid only while that module is executing or active and before terminal module shutdown begins.
Definition at line 1028 of file KernelElf.cc.
References lockModules(), m_Modules, and unlockModules().
| bool KernelElf::registerUnloadAdmission | ( | ModuleEntry | ownerEntry, |
| Module::UnloadAdmissionHook | hook | ||
| ) |
Called outside the module lock after exclusive unload claim. Refusal must reopen any resource admission the hook closed. Ready must retain closed admission through exit. Busy aborts terminal shutdown; KeepMapped permits safe retention without invoking exit.
Definition at line 1007 of file KernelElf.cc.
References lockModules(), m_Modules, and unlockModules().
|
private |
Requires the exclusive runtime load claim; providers cannot retire.
Definition at line 273 of file KernelElf-runtime.cc.
References SymbolTable::lookupOwned(), and m_Modules.
|
private |
Definition at line 395 of file KernelElf-runtime.cc.
|
private |
Definition at line 218 of file KernelElf-runtime.cc.
|
private |
Requires the module lock.
Definition at line 240 of file KernelElf-runtime.cc.
| bool KernelElf::unloadModule | ( | const char * | name, |
| bool | silent = false, |
||
| bool | progress = true |
||
| ) |
Unloads the specified module.
Definition at line 929 of file KernelElf.cc.
References lockModules(), and unlockModules().
| bool KernelElf::unloadModule | ( | Module * | module, |
| bool | silent = false, |
||
| bool | progress = true |
||
| ) |
Definition at line 950 of file KernelElf.cc.
| KernelElf::RuntimeUnloadResult KernelElf::unloadModuleRuntime | ( | const char * | name | ) |
Unloads an active module; completed unloads are absent from this lookup.
Definition at line 960 of file KernelElf.cc.
References lockModules(), m_Modules, and unlockModules().
| bool KernelElf::unloadModules | ( | ) |
Unloads modules; false forbids the final platform shutdown handoff.
Definition at line 1086 of file KernelElf.cc.
References Vector< T >::clear(), Scheduler::instance(), lockModules(), m_InitModule, m_Modules, Vector< T >::pushBack(), Machine::setShutdownPhase(), unlockModules(), and Scheduler::yield().
|
private |
Unlock access to module data structures.
Definition at line 1765 of file KernelElf.cc.
References EMIT_IF, and Spinlock::release().
Referenced by executeModules(), getDependingModule(), getModule(), getModuleCount(), globalLookupSymbol(), invokeInitModule(), loadModule(), loadModule(), prepareRuntimeModules(), registerTerminalQuiesce(), registerUnloadAdmission(), unloadModule(), unloadModuleRuntime(), unloadModules(), unregisterTerminalQuiesce(), updateModuleStatus(), and waitForModulesToLoad().
Here is the caller graph for this function:| bool KernelElf::unregisterTerminalQuiesce | ( | ModuleEntry | ownerEntry, |
| TerminalQuiesceHook | hook | ||
| ) |
Removes a terminal callback only when both its owner and function match.
Definition at line 1068 of file KernelElf.cc.
References lockModules(), and unlockModules().
| void KernelElf::updateModuleStatus | ( | Module * | module, |
| bool | status, | ||
| bool | runFailureLifecycle = true |
||
| ) |
Updates the status of the given module.
Definition at line 1563 of file KernelElf.cc.
References lockModules(), and unlockModules().
| void KernelElf::waitForModulesToLoad | ( | ) |
Waits for all modules to complete (whether successfully or not).
Definition at line 1598 of file KernelElf.cc.
References Vector< T >::count(), Scheduler::instance(), lockModules(), m_Modules, unlockModules(), and Scheduler::yield().
|
friend |
Definition at line 288 of file system/kernel/core/main.cc.
|
private |
Additional section headers we have loaded for this ELF binary.
Definition at line 389 of file KernelElf.h.
Referenced by initialise().
|
private |
Definition at line 390 of file KernelElf.h.
|
private |
Pending init module.
Definition at line 420 of file KernelElf.h.
Referenced by invokeInitModule(), loadModule(), loadModule(), and unloadModules().
|
staticprivate |
Instance of the KernelElf class
Definition at line 393 of file KernelElf.h.
|
private |
Definition at line 408 of file KernelElf.h.
|
private |
Memory allocator for modules - where they can be loaded.
Definition at line 398 of file KernelElf.h.
Referenced by loadModule(), and prepareRuntimeModules().
|
private |
Definition at line 399 of file KernelElf.h.
|
private |
Definition at line 414 of file KernelElf.h.
|
private |
Definition at line 413 of file KernelElf.h.
|
private |
Definition at line 411 of file KernelElf.h.
List of modules
Definition at line 396 of file KernelElf.h.
Referenced by executeModules(), getDependingModule(), getModuleCount(), hasPendingModules(), invokeInitModule(), loadModule(), loadModule(), moduleDependenciesSatisfiedLocked(), moduleIsLoaded(), prepareRuntimeModules(), registerTerminalQuiesce(), registerUnloadAdmission(), resolveRuntimeImport(), unloadModuleRuntime(), unloadModules(), and waitForModulesToLoad().
|
private |
Definition at line 409 of file KernelElf.h.
|
private |
Definition at line 410 of file KernelElf.h.
|
private |
Definition at line 402 of file KernelElf.h.
|
private |
Definition at line 403 of file KernelElf.h.
|
private |
Definition at line 400 of file KernelElf.h.
|
private |
Definition at line 416 of file KernelElf.h.
|
private |
Definition at line 415 of file KernelElf.h.
|
private |
Definition at line 417 of file KernelElf.h.
|
private |
Definition at line 412 of file KernelElf.h.