From db2fe172697bfbc533eee02cd6a1e35299ebefa7 Mon Sep 17 00:00:00 2001 From: Norman Feske Date: Mon, 26 Aug 2013 17:24:55 +0200 Subject: [PATCH] base: Add Allocator_avl::size_at function This function provides a way to request the size of an previously allocated block. It is useful to to ease the implementation of realloc functionality based on Allocator_avl. --- base/include/base/allocator_avl.h | 5 +++++ base/src/base/allocator/allocator_avl.cc | 9 +++++++++ 2 files changed, 14 insertions(+) diff --git a/base/include/base/allocator_avl.h b/base/include/base/allocator_avl.h index b7eba7d33f..f2caadd4e7 100644 --- a/base/include/base/allocator_avl.h +++ b/base/include/base/allocator_avl.h @@ -231,6 +231,11 @@ namespace Genode { void free(void *addr, size_t) { free(addr); } + /** + * Return size of block at specified address + */ + size_t size_at(void const *addr) const; + /** * Return the memory overhead per Block * diff --git a/base/src/base/allocator/allocator_avl.cc b/base/src/base/allocator/allocator_avl.cc index 8bff932865..26d1718080 100644 --- a/base/src/base/allocator/allocator_avl.cc +++ b/base/src/base/allocator/allocator_avl.cc @@ -339,6 +339,15 @@ void Allocator_avl_base::free(void *addr) } +size_t Allocator_avl_base::size_at(void const *addr) const +{ + /* lookup corresponding block */ + Block *b = _find_by_address(reinterpret_cast(addr)); + + return (b && b->used()) ? b->size() : 0; +} + + bool Allocator_avl_base::any_block_addr(addr_t *out_addr) { Block *b = _addr_tree.first();