-
Notifications
You must be signed in to change notification settings - Fork 0
/
vma.h
126 lines (111 loc) · 3.76 KB
/
vma.h
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#pragma once
#include "ll.h"
#include "locators.h"
// VMA functions
/*
* @brief -> allocates and initializes arena
* @param -> size = size of arena a.k.a. total number of addresses
* (const uint64_t)
* @return -> newly created arena stuct (arena_t *)
*/
arena_t *alloc_arena(const uint64_t size);
/*
* @brief -> frees all resources of the arena (including blocks,
* miniblocks and linked lists)
* @param -> arena (arena_t *)
* @return -> void
*/
void dealloc_arena(arena_t *arena);
/*
* @brief -> creates and initializes a new miniblock struct
* @param -> address = miniblock start adress (const uint64_t)
* @param -> size = miniblock size (const uint64_t)
* @return -> newly created miniblock
*/
miniblock_t *create_miniblock(const uint64_t address, const uint64_t size);
/*
* @brief -> creates and initializes a new block struct
* @param -> address = block start adress (const uint64_t)
* @param -> size = block size (const uint64_t)
* @return -> newly created block
*/
block_t *create_block(const uint64_t address, const uint64_t size);
/*
* @brief -> implementation of alloc_block case of double adjacency
* @param -> arena (arena_t *)
* @param -> address = block start adress (uint64_t)
* @param -> size = block size (uint64_t)
* @param -> sh_start = index of the block sharing the new block's
* start address
* @return -> void
*/
void double_adjacent(arena_t *arena, uint64_t address, uint64_t size,
uint64_t sh_start);
/*
* @brief -> implementation of alloc_block case of left adjacency
* @param -> arena (arena_t *)
* @param -> address = block start adress (uint64_t)
* @param -> size = block size (uint64_t)
* @param -> sh_start = index of the block sharing the new block's
* start address
* @return -> void
*/
void left_adjacent(arena_t *arena, uint64_t address, uint64_t size,
uint64_t sh_start);
/*
* @brief -> implementation of alloc_block case of right adjacency
* @param -> arena (arena_t *)
* @param -> address = block start adress (uint64_t)
* @param -> size = block size (uint64_t)
* @param -> sh_end = index of the block sharing the new block's
* end address
* @return -> void
*/
void right_adjacent(arena_t *arena, uint64_t address, uint64_t size,
uint64_t sh_end);
/*
* @brief -> allocates a new block and adds to the arena list
* @param -> arena (arena_t *)
* @param -> address = block start adress (const uint64_t)
* @param -> size = block size (const uint64_t)
* @return -> void
*/
void alloc_block(arena_t *arena, const uint64_t address, const uint64_t size);
/*
* @brief -> frees block and its resources (miniblocks and miniblock list)
* @param -> arena (arena_t *)
* @param -> address = block start adress (const uint64_t)
* @return -> void
*/
void free_block(arena_t *arena, const uint64_t address);
/*
* @brief -> print data stored at given address in the arena
* @param -> arena (arena_t *)
* @param -> address = read start adress (uint64_t)
* @param -> size = number of bytes to read (uint64_t)
* @return -> void
*/
void read(arena_t *arena, uint64_t address, uint64_t size);
/*
* @brief -> write data at given address in the arena
* @param -> arena (arena_t *)
* @param -> address = write start adress (const uint64_t)
* @param -> size = number of bytes to write (const uint64_t)
* @return -> void
*/
void write(arena_t *arena, const uint64_t address, const uint64_t size,
int8_t *data);
/*
* @brief -> pmap function implementation
* @param -> arena (arena_t *)
* @return -> void
*/
void pmap(const arena_t *arena);
/*
* @brief -> change permissions to the ones given
* @param -> arena (arena_t *)
* @param -> address = miniblock start adress (uint64_t)
* @param -> pemission (int8_t *)
* @return -> void
*/
void mprotect(arena_t *arena, uint64_t address, int8_t *permission);