-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathcmem.h
More file actions
54 lines (41 loc) · 1.12 KB
/
cmem.h
File metadata and controls
54 lines (41 loc) · 1.12 KB
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
//
// Project: clibparser
// Created by bajdcc
//
#ifndef CLIBPARSER_CMEM_H
#define CLIBPARSER_CMEM_H
#include <vector>
#include <map>
#include "types.h"
#define MAX_PAGE_PER_PROCESS 64
namespace clib {
class imem {
public:
virtual void map_page(uint32_t addr, uint32_t id) = 0;
};
class cmem {
public:
explicit cmem(imem *m);
cmem(const cmem &) = delete;
cmem &operator=(const cmem &) = delete;
uint32_t alloc(uint32_t size);
uint32_t free(uint32_t addr);
int page_size() const;
void copy_from(const cmem &mem);
private:
uint32_t new_page(uint32_t size);
uint32_t new_page_single();
uint32_t new_page_all(uint32_t size);
void error(const string_t &) const;
void dump() const;
void check() const;
private:
std::vector<std::vector<byte>> memory;
std::vector<uint32_t> memory_page;
std::map<uint32_t, uint32_t> memory_free;
std::map<uint32_t, uint32_t> memory_used;
size_t available_size{0};
imem *m{nullptr};
};
}
#endif //CLIBPARSER_CMEM_H