From 5bc4e3ee51d7d0d9668fe680086735333f5e1ccf Mon Sep 17 00:00:00 2001 From: Camille Chauvet Date: Tue, 13 Jun 2023 14:27:15 +0000 Subject: [PATCH] add: galloc init --- src/galloc.🗿 | 54 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 src/galloc.🗿 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; +}