|
|
@ -302,8 +302,8 @@ void insert_singleton(TreeAlloc **root_ptr, TreeAlloc *to_insert) { |
|
|
|
|
|
|
|
void insert_right(TreeAlloc** root_ptr, TreeAlloc* to_insert, TreeAlloc* after) { |
|
|
|
if (after->right != NULL) { |
|
|
|
after->right->parent = to_insert; |
|
|
|
to_insert->right = after->right; |
|
|
|
after->right = to_insert; |
|
|
|
to_insert->parent = after; |
|
|
|
} |
|
|
|
after->right = to_insert; |
|
|
|
to_insert->parent = after; |
|
|
@ -312,8 +312,8 @@ void insert_right(TreeAlloc** root_ptr, TreeAlloc* to_insert, TreeAlloc* after) |
|
|
|
|
|
|
|
void insert_left(TreeAlloc** root_ptr, TreeAlloc* to_insert, TreeAlloc* before) { |
|
|
|
if (before->left != NULL) { |
|
|
|
before->left->parent = to_insert; |
|
|
|
to_insert->left = before->left; |
|
|
|
before->left = to_insert; |
|
|
|
to_insert->parent = before; |
|
|
|
} |
|
|
|
before->left = to_insert; |
|
|
|
to_insert->parent = before; |
|
|
@ -344,6 +344,14 @@ int add_new_region(Arena *arena, uintptr_t size, uintptr_t padding, uintptr_t al |
|
|
|
head = head->right; |
|
|
|
} |
|
|
|
insert_right((TreeAlloc**) arena->root_freespace, (TreeAlloc*) newreg, (TreeAlloc*) newreg); |
|
|
|
#ifdef DEBUG |
|
|
|
printf("= POST-REGION-CREATION =\n"); |
|
|
|
printf("==== FREESPACE TREE ====\n"); |
|
|
|
debug_print_tree(0, arena->root_freespace); |
|
|
|
printf("==== TREEALLOC TREE ====\n"); |
|
|
|
debug_print_tree(0, arena->root_treealloc); |
|
|
|
printf("===== END OF TREES =====\n"); |
|
|
|
#endif |
|
|
|
} |
|
|
|
return 1; |
|
|
|
} |
|
|
@ -355,7 +363,7 @@ void unalloc(Arena *arena, void *addr) { |
|
|
|
debug_print_tree(0, arena->root_freespace); |
|
|
|
printf("=== TREEALLOC TREE ===\n"); |
|
|
|
debug_print_tree(0, arena->root_treealloc); |
|
|
|
printf("=== END OF TREES ====\n"); |
|
|
|
printf("==== END OF TREES ====\n"); |
|
|
|
#endif |
|
|
|
if (arena->root_treealloc == NULL) { |
|
|
|
arena->error("attempt to unallocate when there are no allocations!"); |
|
|
@ -414,7 +422,7 @@ void *alloc(Arena *arena, uintptr_t size, uintptr_t align) { |
|
|
|
debug_print_tree(0, arena->root_freespace); |
|
|
|
printf("=== TREEALLOC TREE ===\n"); |
|
|
|
debug_print_tree(0, arena->root_treealloc); |
|
|
|
printf("=== END OF TREES ====\n"); |
|
|
|
printf("==== END OF TREES ====\n"); |
|
|
|
#endif |
|
|
|
if (arena->root_freespace == NULL) { |
|
|
|
// Handle being out of freespace. |
|
|
@ -441,7 +449,6 @@ void *alloc(Arena *arena, uintptr_t size, uintptr_t align) { |
|
|
|
region->left = NULL; |
|
|
|
region->type = RT_TREE_NODE; |
|
|
|
#ifdef DEBUG |
|
|
|
printf("sizeof(TreeAlloc): %lu\n", (uintptr_t) sizeof(TreeAlloc)); |
|
|
|
printf("start: %p, end: %p, adjusted end: %p\n", region, ((void*) region) + size, true_end); |
|
|
|
printf("size: %lu -> %lu\n", size, new_size); |
|
|
|
#endif |
|
|
@ -479,7 +486,10 @@ void *alloc(Arena *arena, uintptr_t size, uintptr_t align) { |
|
|
|
} else { |
|
|
|
region->before = before_alloc; |
|
|
|
} |
|
|
|
return align_after(region + sizeof(TreeAlloc), actual_align); |
|
|
|
#ifdef DEBUG |
|
|
|
printf("region is still at %p\n", region); |
|
|
|
#endif |
|
|
|
return align_after((void*) region + sizeof(TreeAlloc), actual_align); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|