mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-12-04 13:30:31 +00:00
Kernel: Make VirtualRangeAllocator::carve_from_region OOM-fallible
This commit is contained in:
parent
85437abfad
commit
1e941fc3cc
Notes:
sideshowbarker
2024-07-17 20:10:35 +09:00
Author: https://github.com/IdanHo Commit: https://github.com/SerenityOS/serenity/commit/1e941fc3ccd Pull-request: https://github.com/SerenityOS/serenity/pull/12145 Reviewed-by: https://github.com/linusg ✅
2 changed files with 7 additions and 6 deletions
|
@ -44,18 +44,19 @@ void VirtualRangeAllocator::dump() const
|
|||
}
|
||||
}
|
||||
|
||||
void VirtualRangeAllocator::carve_from_region(VirtualRange const& from, VirtualRange const& range)
|
||||
ErrorOr<void> 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<VirtualRange> VirtualRangeAllocator::try_allocate_randomized(size_t size, size_t alignment)
|
||||
|
@ -124,7 +125,7 @@ ErrorOr<VirtualRange> 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<VirtualRange> 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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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<void> carve_from_region(VirtualRange const& from, VirtualRange const&);
|
||||
|
||||
RedBlackTree<FlatPtr, VirtualRange> m_available_ranges;
|
||||
VirtualRange m_total_range;
|
||||
|
|
Loading…
Reference in a new issue