diff options
author | Idan Horowitz <idan.horowitz@gmail.com> | 2022-01-26 18:33:16 +0200 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2022-01-26 22:05:34 +0000 |
commit | 1e941fc3ccd095ad028abe5149016dc5ed22017a (patch) | |
tree | 0e4b14b74ff0a91fbb1c79e544207cedfe2d75fb | |
parent | 85437abfad4256a19cc2640a927b0865c654be04 (diff) | |
download | serenity-1e941fc3ccd095ad028abe5149016dc5ed22017a.zip |
Kernel: Make VirtualRangeAllocator::carve_from_region OOM-fallible
-rw-r--r-- | Kernel/Memory/VirtualRangeAllocator.cpp | 11 | ||||
-rw-r--r-- | Kernel/Memory/VirtualRangeAllocator.h | 2 |
2 files changed, 7 insertions, 6 deletions
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<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; } 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<void> carve_from_region(VirtualRange const& from, VirtualRange const&); RedBlackTree<FlatPtr, VirtualRange> m_available_ranges; VirtualRange m_total_range; |