diff --git a/Kernel/Memory/VirtualRangeAllocator.cpp b/Kernel/Memory/VirtualRangeAllocator.cpp index 5b23074aeb..214bb6d7ed 100644 --- a/Kernel/Memory/VirtualRangeAllocator.cpp +++ b/Kernel/Memory/VirtualRangeAllocator.cpp @@ -44,18 +44,19 @@ void VirtualRangeAllocator::dump() const } } -void VirtualRangeAllocator::carve_from_region(VirtualRange const& from, VirtualRange const& range) +ErrorOr VirtualRangeAllocator::carve_from_region(VirtualRange const& from, VirtualRange const& range) { VERIFY(m_lock.is_locked()); auto remaining_parts = from.carve(range); VERIFY(remaining_parts.size() >= 1); VERIFY(m_total_range.contains(remaining_parts[0])); m_available_ranges.remove(from.base().get()); - m_available_ranges.insert(remaining_parts[0].base().get(), remaining_parts[0]); + TRY(m_available_ranges.try_insert(remaining_parts[0].base().get(), remaining_parts[0])); if (remaining_parts.size() == 2) { VERIFY(m_total_range.contains(remaining_parts[1])); - m_available_ranges.insert(remaining_parts[1].base().get(), remaining_parts[1]); + TRY(m_available_ranges.try_insert(remaining_parts[1].base().get(), remaining_parts[1])); } + return {}; } ErrorOr VirtualRangeAllocator::try_allocate_randomized(size_t size, size_t alignment) @@ -124,7 +125,7 @@ ErrorOr VirtualRangeAllocator::try_allocate_anywhere(size_t size, m_available_ranges.remove(it.key()); return allocated_range; } - carve_from_region(*it, allocated_range); + TRY(carve_from_region(*it, allocated_range)); return allocated_range; } dmesgln("VirtualRangeAllocator: Failed to allocate anywhere: size={}, alignment={}", size, alignment); @@ -153,7 +154,7 @@ ErrorOr VirtualRangeAllocator::try_allocate_specific(VirtualAddres m_available_ranges.remove(available_range->base().get()); return allocated_range; } - carve_from_region(*available_range, allocated_range); + TRY(carve_from_region(*available_range, allocated_range)); return allocated_range; } diff --git a/Kernel/Memory/VirtualRangeAllocator.h b/Kernel/Memory/VirtualRangeAllocator.h index b469966d67..fdbb409f08 100644 --- a/Kernel/Memory/VirtualRangeAllocator.h +++ b/Kernel/Memory/VirtualRangeAllocator.h @@ -31,7 +31,7 @@ public: bool contains(VirtualRange const& range) const { return m_total_range.contains(range); } private: - void carve_from_region(VirtualRange const& from, VirtualRange const&); + ErrorOr carve_from_region(VirtualRange const& from, VirtualRange const&); RedBlackTree m_available_ranges; VirtualRange m_total_range;