summaryrefslogtreecommitdiff
path: root/ELFLoader/ExecSpace.h
blob: 1e22468af4336d6b1d30b1ebe6f81cb6e3979cf6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#pragma once

#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();

#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;
};