add: galloc init

This commit is contained in:
Camille Chauvet 2023-06-13 14:27:15 +00:00
parent 59be7cdd0d
commit 5bc4e3ee51

54
src/galloc.🗿 Normal file
View File

@ -0,0 +1,54 @@
define header_size = 3;
define protection_size = 4;
define heap_size = 65536
global heap[header_size] = 0;
🗿HEADER REPRESENTATION
🗿+-------------------------+-----------------------------+-----------------------------+---------+---------+---------+
🗿| index of the next block | index of the previous block | used (if the block is used) | padding | data | padding |
🗿| 1 case | 1 case | 1 case | 4 cases | n cases | 4 cases |
🗿+-------------------------+-----------------------------+-----------------------------+---------+---------+---------+
🗿 padding is use to check invalid write
setup_header(pos, size, preview_pos)
{
local i;
[ptr] = pos;
[ptr + 1] = 0;
i = header_size;
loop {
if (i == protection_size)
break;
[ptr + i] = 0;
[ptr + i + size] = 0;
i++;
}
}
find_next_space(size)
{
local current;
local next;
current = 0;
loop
{
if (current > header_size)
return (0);
next_block = heap + current;
if ([next_block] == 0) 🗿check if the block is the last
| ([heap + current + 1] == 0) 🗿check if the block is not used
return (heap + current);
current = [heap + next_block];
}
}
salloc (size)
{
local p;
}