diff --git a/include/libmalloc/buddy_alloc.h b/include/libmalloc/buddy_alloc.h index c913b78..34fe2d4 100644 --- a/include/libmalloc/buddy_alloc.h +++ b/include/libmalloc/buddy_alloc.h @@ -45,9 +45,9 @@ unsigned long buddy_map_size(const memory_map_t *map, unsigned long block_size); unsigned long buddy_reserve(buddy_descriptor_t *heap, unsigned long size); -void buddy_free(buddy_descriptor_t *heap, unsigned long location); +unsigned long buddy_free(buddy_descriptor_t *heap, unsigned long location); -void buddy_free_size(buddy_descriptor_t *heap, unsigned long size, +unsigned long buddy_free_size(buddy_descriptor_t *heap, unsigned long size, unsigned long location); int buddy_alloc_init(buddy_descriptor_t *heap, memory_map_t *map); diff --git a/src/buddy_alloc.c b/src/buddy_alloc.c index b617e64..abde7d0 100644 --- a/src/buddy_alloc.c +++ b/src/buddy_alloc.c @@ -83,19 +83,21 @@ unsigned long buddy_reserve(buddy_descriptor_t *heap, unsigned long size) return NOMEM; } -void buddy_free(buddy_descriptor_t *heap, unsigned long location) +unsigned long buddy_free(buddy_descriptor_t *heap, unsigned long location) { unsigned long index = (location - (unsigned long)heap->offset) / heap->block_size; unsigned long k = llog2((heap->block_size * (1UL << heap->block_map[index].kval)) / heap->block_size); insert_block(heap, index, k); + return (1UL << k) * heap->block_size; } -void buddy_free_size(buddy_descriptor_t *heap, unsigned long location, +unsigned long buddy_free_size(buddy_descriptor_t *heap, unsigned long location, unsigned long size) { unsigned long index = (location - (unsigned long)heap->offset) / heap->block_size; unsigned long k = llog2(size / heap->block_size); insert_block(heap, index, k); + return (1UL << k) * heap->block_size; } int buddy_alloc_init(buddy_descriptor_t *heap, memory_map_t *map)