mirror of
https://github.com/genodelabs/genode.git
synced 2025-01-18 10:46:25 +00:00
lx_emul: make memory allocation more clear
This commit is contained in:
parent
963b8b0607
commit
7cefeac8ed
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user