6 void *
sbrk(ptrdiff_t incr);
14 static void * heap_base =
NULL;
19 uintptr_t prev_top, next_bot;
23 prev_top = (uintptr_t) prev->
ptr + prev->
size;
24 next_bot = (uintptr_t) prev->
next - prev_top;
38 size = (size +
sizeof(
heap_t) + 7) & ~7;
45 heap_ptr =
sbrk(size);
50 ptr = (
void *) ((uintptr_t) heap_ptr +
sizeof(
heap_t));
51 head = (
heap_t *) heap_ptr;
63 if (((uintptr_t) heap_base +
size) < (uintptr_t) head) {
64 new = (
heap_t *) heap_base;
65 ptr = (
void *) ((uintptr_t)
new +
sizeof(
heap_t));
68 new->size = size -
sizeof(
heap_t);
77 prev = find_fit(head, size);
80 ptr = (
void *) ((uintptr_t)
new +
sizeof(
heap_t));
83 new->size = size -
sizeof(
heap_t);
92 heap_ptr =
sbrk(size);
96 ptr = (
void *) ((uintptr_t) heap_ptr +
sizeof(
heap_t));
99 new->size = size -
sizeof(
heap_t);
119 size = (size +
sizeof(
heap_t) + 7) & ~7;
124 if (prev->
size >= size) {
144 if ((prev->
next->
ptr - ptr) > size) {
154 memcpy(
new, ptr, prev->
size);
168 if (ptr == head->
ptr) {
169 size = head->
size + (size_t) (head->
ptr - (
void *) head);
184 for (cur = head; ptr != cur->
ptr; cur = cur->
next)