2018-10-10 09:53:07 +00:00
|
|
|
#pragma once
|
|
|
|
|
2018-11-04 12:52:53 +00:00
|
|
|
#include <AK/Function.h>
|
2018-10-10 09:53:07 +00:00
|
|
|
#include <AK/HashMap.h>
|
|
|
|
#include <AK/OwnPtr.h>
|
|
|
|
#include <AK/Vector.h>
|
|
|
|
#include "ELFImage.h"
|
|
|
|
|
|
|
|
class ELFLoader {
|
|
|
|
public:
|
2018-11-08 20:20:09 +00:00
|
|
|
explicit ELFLoader(const byte*);
|
2018-10-10 09:53:07 +00:00
|
|
|
~ELFLoader();
|
|
|
|
|
|
|
|
bool load();
|
2018-11-04 12:52:53 +00:00
|
|
|
Function<void*(LinearAddress, size_t, size_t, bool, bool, const String&)> alloc_section_hook;
|
2018-11-08 20:20:09 +00:00
|
|
|
Function<void*(LinearAddress, size_t, size_t, size_t, bool, bool, const String&)> map_section_hook;
|
2018-11-04 12:52:53 +00:00
|
|
|
char* symbol_ptr(const char* name);
|
|
|
|
bool allocate_section(LinearAddress, size_t, size_t alignment, bool is_readable, bool is_writable);
|
2018-11-08 20:20:09 +00:00
|
|
|
bool map_section(LinearAddress, size_t, size_t alignment, size_t offset_in_image, bool is_readable, bool is_writable);
|
2018-12-29 02:28:55 +00:00
|
|
|
LinearAddress entry() const { return m_image.entry(); }
|
2018-10-10 09:53:07 +00:00
|
|
|
|
|
|
|
private:
|
2018-10-25 08:00:37 +00:00
|
|
|
bool layout();
|
2018-11-04 13:09:30 +00:00
|
|
|
bool perform_relocations();
|
2018-10-10 09:53:07 +00:00
|
|
|
void* lookup(const ELFImage::Symbol&);
|
2018-11-04 13:09:30 +00:00
|
|
|
char* area_for_section(const ELFImage::Section&);
|
|
|
|
char* area_for_section_name(const char*);
|
2018-10-10 09:53:07 +00:00
|
|
|
|
2018-11-04 12:52:53 +00:00
|
|
|
struct PtrAndSize {
|
|
|
|
PtrAndSize() { }
|
|
|
|
PtrAndSize(char* p, unsigned s)
|
|
|
|
: ptr(p)
|
|
|
|
, size(s)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
char* ptr { nullptr };
|
|
|
|
unsigned size { 0 };
|
|
|
|
};
|
2018-11-04 13:09:30 +00:00
|
|
|
ELFImage m_image;
|
|
|
|
|
2018-10-10 09:53:07 +00:00
|
|
|
HashMap<String, char*> m_sections;
|
|
|
|
};
|
|
|
|
|