From e285ecb76cbcc1fe05a50e7596513cfc18fbe3a9 Mon Sep 17 00:00:00 2001 From: Alexander Boettcher Date: Wed, 30 May 2018 00:20:16 +0200 Subject: [PATCH] core: avoid freeing wrong regions during attach In case of an Alloc_return error, don't free the address at 0. If this is a managed dataspace, there could be valid attachments which then gets lost. Make decreasing alignment search working. Continue with lower alignment restrictions in case the optimal alignment wish can't be fulfilled. --- repos/base/src/core/region_map_component.cc | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/repos/base/src/core/region_map_component.cc b/repos/base/src/core/region_map_component.cc index f6717cec1..ad4db59ca 100644 --- a/repos/base/src/core/region_map_component.cc +++ b/repos/base/src/core/region_map_component.cc @@ -414,24 +414,19 @@ Region_map_component::attach(Dataspace_capability ds_cap, size_t size, Range_allocator::Alloc_return alloc_return = _map.alloc_aligned(size, &attach_at, align_log2); - if (!alloc_return.ok()) - _map.free(attach_at); - typedef Range_allocator::Alloc_return Alloc_return; switch (alloc_return.value) { case Alloc_return::OK: break; /* switch */ case Alloc_return::OUT_OF_METADATA: throw Out_of_ram(); - case Alloc_return::RANGE_CONFLICT: throw Region_conflict(); + case Alloc_return::RANGE_CONFLICT: continue; /* for loop */ } - break; /* for loop */ + } - if (align_log2 < get_page_size_log2()) { - _map.free(attach_at); + if (align_log2 < get_page_size_log2()) throw Region_conflict(); - } } /* store attachment info in meta data */