IronGOLEM/src/galloc.🗿

55 lines
1.2 KiB
Plaintext
Raw Normal View History

2023-06-13 10:27:15 -04:00
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;
}