mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 23:17:45 +00:00
Kernel/AK: Move ELF loader to AK
This is in preparation for eventually using it in userspace. LinearAddress.h has not been moved for the time being (as it seems to be only used by a very small part of the code).
This commit is contained in:
parent
5b3c4afff2
commit
6917c42140
8 changed files with 13 additions and 9 deletions
55
AK/ELF/ELFLoader.h
Normal file
55
AK/ELF/ELFLoader.h
Normal file
|
@ -0,0 +1,55 @@
|
|||
#pragma once
|
||||
|
||||
#include <AK/Function.h>
|
||||
#include <AK/HashMap.h>
|
||||
#include <AK/OwnPtr.h>
|
||||
#include <AK/Vector.h>
|
||||
#if defined(KERNEL)
|
||||
#include <Kernel/LinearAddress.h>
|
||||
#endif
|
||||
#include <AK/ELF/ELFImage.h>
|
||||
|
||||
class ELFLoader {
|
||||
public:
|
||||
explicit ELFLoader(const byte*);
|
||||
~ELFLoader();
|
||||
|
||||
bool load();
|
||||
#if defined(KERNEL)
|
||||
Function<void*(LinearAddress, size_t, size_t, bool, bool, const String&)> alloc_section_hook;
|
||||
Function<void*(LinearAddress, size_t, size_t, size_t, bool, bool, const String&)> map_section_hook;
|
||||
LinearAddress 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;
|
||||
};
|
||||
mutable Vector<SortedSymbol> m_sorted_symbols;
|
||||
};
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue