summaryrefslogtreecommitdiff
path: root/Kernel/VM
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2020-02-19 22:19:55 +0100
committerAndreas Kling <kling@serenityos.org>2020-02-19 22:19:55 +0100
commita87544fe8b39a3cdf57d6f48eb5b72dce6375221 (patch)
tree86082bf0bba273e3dc58b607d6fda6746154a316 /Kernel/VM
parent26fb3f7269e8f0136e1e7d042e16914559fcdde3 (diff)
downloadserenity-a87544fe8b39a3cdf57d6f48eb5b72dce6375221.zip
Kernel: Refuse to allocate 0 bytes of virtual address space
Diffstat (limited to 'Kernel/VM')
-rw-r--r--Kernel/VM/RangeAllocator.cpp6
1 files changed, 6 insertions, 0 deletions
diff --git a/Kernel/VM/RangeAllocator.cpp b/Kernel/VM/RangeAllocator.cpp
index 4504d810c6..509d7e4a71 100644
--- a/Kernel/VM/RangeAllocator.cpp
+++ b/Kernel/VM/RangeAllocator.cpp
@@ -96,6 +96,9 @@ void RangeAllocator::carve_at_index(int index, const Range& range)
Range RangeAllocator::allocate_anywhere(size_t size, size_t alignment)
{
+ if (!size)
+ return {};
+
#ifdef VM_GUARD_PAGES
// NOTE: We pad VM allocations with a guard page on each side.
size_t effective_size = size + PAGE_SIZE * 2;
@@ -135,6 +138,9 @@ Range RangeAllocator::allocate_anywhere(size_t size, size_t alignment)
Range RangeAllocator::allocate_specific(VirtualAddress base, size_t size)
{
+ if (!size)
+ return {};
+
Range allocated_range(base, size);
for (int i = 0; i < m_available_ranges.size(); ++i) {
auto& available_range = m_available_ranges[i];