diff --git a/src/galloc.🗿 b/src/galloc.🗿 new file mode 100644 index 0000000..a5c26f5 --- /dev/null +++ b/src/galloc.🗿 @@ -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; +}