1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 13:48:12 +00:00
serenity/ELFLoader/ExecSpace.h
Andreas Kling aa6d06b47e Use ELF program headers to load executables smarter.
This turned out way better than the old code. ELF loading is now quite
straightforward, and we don't need the weird concept of subregions anymore.

Next step is to respect the is_writable flag.
2018-11-03 11:29:30 +01:00

53 lines
1.1 KiB
C++

#pragma once
#include <AK/Function.h>
#include <AK/HashMap.h>
#include <AK/MappedFile.h>
#include <AK/OwnPtr.h>
#include <AK/Vector.h>
#include "types.h"
class ELFLoader;
class ExecSpace {
public:
struct PtrAndSize {
PtrAndSize() { }
PtrAndSize(char* p, unsigned s)
: ptr(p)
, size(s)
{
}
char* ptr { nullptr };
unsigned size { 0 };
};
ExecSpace();
~ExecSpace();
Function<void*(const String&, size_t)> hookableAlloc;
Function<void*(LinearAddress, size_t, size_t, bool, bool, const String&)> alloc_section_hook;
#ifdef SERENITY
bool loadELF(ByteBuffer&&);
#else
bool loadELF(MappedFile&&);
#endif
char* symbolPtr(const char* name);
void addSymbol(String&& name, char* ptr, unsigned size);
void allocateUniverse(size_t);
bool allocate_section(LinearAddress, size_t, size_t alignment, bool is_readable, bool is_writable);
private:
void initializeBuiltins();
Vector<char*> m_allocated_regions;
HashMap<String, PtrAndSize> m_symbols;
char* m_universe { nullptr };
};