|
|
@ -4,6 +4,22 @@ |
|
|
|
|
|
|
|
#include "allocator_internal.h" |
|
|
|
|
|
|
|
#ifdef DEBUG |
|
|
|
#include <stdio.h> |
|
|
|
|
|
|
|
void debug_print_tree(int indent, TreeAlloc *node) { |
|
|
|
if (node != NULL) { |
|
|
|
debug_print_tree(indent + 1, node->left); |
|
|
|
for (int ii = 0; ii < indent; ii++) { printf(" "); } |
|
|
|
if (node->color == COLOR_RED) { printf("\e[31"); } |
|
|
|
printf("%p %u\n", node, node->size); |
|
|
|
if (node->color == COLOR_RED) { printf("\e[37"); } |
|
|
|
debug_print_tree(indent + 1, node->right); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
#endif |
|
|
|
|
|
|
|
TreeAlloc *insert_node_at(void *address, uintptr_t padding, uintptr_t align, uintptr_t size) { |
|
|
|
return NULL; |
|
|
|
} |
|
|
@ -354,6 +370,12 @@ void unalloc(Arena *arena, void *addr) { |
|
|
|
|
|
|
|
void *alloc(Arena *arena, uintptr_t size, uintptr_t align) { |
|
|
|
uintptr_t actual_align = lcm(alignof(struct WatermarkAlloc), align); |
|
|
|
#ifdef DEBUG |
|
|
|
printf("=== FREESPACE TREE ===\n"); |
|
|
|
debug_print_tree(0, arena->root_freespace); |
|
|
|
printf("=== TREEALLOC TREE ===\n"); |
|
|
|
debug_print_tree(0, arena->root_treealloc); |
|
|
|
#endif |
|
|
|
if (arena->root_freespace == NULL) { |
|
|
|
// Handle being out of freespace. |
|
|
|
if (!add_new_region(arena, size, sizeof(TreeAlloc), actual_align)) { |
|
|
|