ladybird/ELFLoader/ExecSpace.h
Andreas Kling b824f15619 Launching an arbitrary ELF executable from disk works! :^)
This is so cool! It's a bit messy now with two Task constructors,
but eventually they should fold into a single constructor somehow.
2018-10-22 15:43:02 +02:00

61 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>
class ELFLoader;
class ExecSpace {
public:
struct Area {
Area(String&& n, char* m, unsigned s)
: name(move(n))
, memory(m)
, size(s)
{
}
String name;
char* memory { 0 };
unsigned size { 0 };
};
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;
#ifdef SERENITY
bool loadELF(ByteBuffer&&);
#else
bool loadELF(MappedFile&&);
#endif
char* symbolPtr(const char* name);
char* allocateArea(String&& name, unsigned size);
void addSymbol(String&& name, char* ptr, unsigned size);
private:
void initializeBuiltins();
Vector<OwnPtr<Area>> m_areas;
HashMap<String, PtrAndSize> m_symbols;
};