lx_emul: make memory allocation more clear

This commit is contained in:
Christian Helmuth 2023-11-08 17:22:47 +01:00
parent 963b8b0607
commit 7cefeac8ed

View File

@ -57,16 +57,19 @@ Genode::Dataspace_capability Lx_kit::Mem_allocator::attached_dataspace_cap(void
}
void * Lx_kit::Mem_allocator::alloc(size_t size, size_t align)
void * Lx_kit::Mem_allocator::alloc(size_t const size, size_t const align)
{
if (!size)
return nullptr;
auto cleared_allocation = [] (void * const ptr, size_t const size) {
memset(ptr, 0, size);
return ptr;
};
return _mem.alloc_aligned(size, (unsigned)log2(align)).convert<void *>(
[&] (void *ptr) {
memset(ptr, 0, size);
return ptr; },
[&] (void *ptr) { return cleared_allocation(ptr, size); },
[&] (Range_allocator::Alloc_error) {
@ -92,9 +95,7 @@ void * Lx_kit::Mem_allocator::alloc(size_t size, size_t align)
/* re-try allocation */
return _mem.alloc_aligned(size, (unsigned)log2(align)).convert<void *>(
[&] (void *ptr) {
memset(ptr, 0, size);
return ptr; },
[&] (void *ptr) { return cleared_allocation(ptr, size); },
[&] (Range_allocator::Alloc_error) -> void * {
error("memory allocation failed for ", size, " align ", align);