#pragma once #include #include #include #include #include #ifdef KERNEL #include class Region; #endif class ELFLoader { public: explicit ELFLoader(const byte*); ~ELFLoader(); bool load(); #if defined(KERNEL) Function alloc_section_hook; Function map_section_hook; VirtualAddress entry() const { return m_image.entry(); } #endif char* symbol_ptr(const char* name); bool has_symbols() const { return m_image.symbol_count(); } String symbolicate(dword address) const; private: bool layout(); bool perform_relocations(); void* lookup(const ELFImage::Symbol&); char* area_for_section(const ELFImage::Section&); char* area_for_section_name(const char*); struct PtrAndSize { PtrAndSize() {} PtrAndSize(char* p, unsigned s) : ptr(p) , size(s) { } char* ptr { nullptr }; unsigned size { 0 }; }; ELFImage m_image; struct SortedSymbol { dword address; const char* name; }; #ifdef KERNEL mutable RefPtr m_sorted_symbols_region; #else mutable Vector m_sorted_symbols; #endif };