libc: Add Libc::Mem_alloc::size_at

Adding this function eases the implementation of realloc based on
'Libc::Mem_alloc'. Note that this allocator is not used by libc's
default malloc implementation but it is useful for customized C
runtimes, e.g., for the runtime of VirtualBox.
This commit is contained in:
Norman Feske 2013-08-26 17:26:13 +02:00 committed by Christian Helmuth
parent db2fe17269
commit 75366c66a4
2 changed files with 13 additions and 1 deletions

View File

@ -88,7 +88,7 @@ namespace Libc {
_ram_session = ram, _rm_session = rm; }
};
Lock _lock;
Lock mutable _lock;
Dataspace_pool _ds_pool; /* list of dataspaces */
Allocator_avl _alloc; /* local allocator */
size_t _chunk_size;
@ -114,6 +114,7 @@ namespace Libc {
void *alloc(Genode::size_t size, Genode::size_t align_log2);
void free(void *ptr);
Genode::size_t size_at(void const *ptr) const;
};
}
@ -223,6 +224,16 @@ void Libc::Mem_alloc_impl::free(void *addr)
}
Genode::size_t Libc::Mem_alloc_impl::size_at(void const *addr) const
{
/* serialize access of heap functions */
Lock::Guard lock_guard(_lock);
/* forward request to our local allocator */
return _alloc.size_at(addr);
}
Libc::Mem_alloc *Libc::mem_alloc()
{
static Libc::Mem_alloc_impl inst;

View File

@ -16,6 +16,7 @@ namespace Libc {
{
virtual void *alloc(Genode::size_t size, Genode::size_t align_log2) = 0;
virtual void free(void *ptr) = 0;
virtual Genode::size_t size_at(void const *ptr) const = 0;
};
/**