aboutsummaryrefslogtreecommitdiff
path: root/src/memory/maps.hh
blob: 67914b64340c240fb618c271ab209ad5d889607c (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
58
59
60
61
62
#ifndef MEMORY_HH_
#define MEMORY_HH_

#include <filesystem>
#include <fstream>
#include <sstream>
#include <stdexcept>
#include <string>
#include <vector>

namespace memory {

class maps {
public:
    struct region {
    public:
        void* start;
        void* end;
        char perms[5];
        std::string offset; // TODO who cares
        std::string dev;
        int inode;
        std::string pathname;

    public:
        region() noexcept = default;
        region(const region&) = default;
        region(region&&) = default;

    public:
        bool is_read() const noexcept { return this->perms[0] == 'r'; }
        bool is_write() const noexcept { return this->perms[1] == 'w'; }
        bool is_execute() const noexcept { return this->perms[2] == 'x'; }
        bool is_protected() const noexcept { return this->perms[3] == 'p'; }
    };
    using regions_t = std::vector<region>;

private:
    std::string pid;
    regions_t regions;

public:
    auto begin() const noexcept {
        return std::begin(this->regions);
    }
    auto end() const noexcept {
        return std::end(this->regions);
    }

public:
    maps(const char* const name);
    maps(const maps& m) = default;
    maps(maps&&) = default;

public:
    const std::string& get_pid() const noexcept { return this->pid; }
    const regions_t& get_regions() const noexcept { return this->regions; }
};

} // namespace memory

#endif