From 4195a7ef4b8bd91e93155af58171167fd99ee085 Mon Sep 17 00:00:00 2001 From: Daniel Bertalan Date: Wed, 22 Dec 2021 12:15:55 +0100 Subject: [PATCH] Kernel: Return EEXIST in VirtualRangeAllocator::try_allocate_specific() This error only ever gets propagated to the userspace if MAP_FIXED_NOREPLACE is requested, as MAP_FIXED unmaps intersecting ranges beforehand, and non-fixed mmap() calls will just fall back to allocating anywhere. Linux specifies MAP_FIXED_NOREPLACE to return EEXIST when it can't allocate, we now match that behavior. --- Kernel/Memory/VirtualRangeAllocator.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Kernel/Memory/VirtualRangeAllocator.cpp b/Kernel/Memory/VirtualRangeAllocator.cpp index d3e0d7b773..5b23074aeb 100644 --- a/Kernel/Memory/VirtualRangeAllocator.cpp +++ b/Kernel/Memory/VirtualRangeAllocator.cpp @@ -146,9 +146,9 @@ ErrorOr VirtualRangeAllocator::try_allocate_specific(VirtualAddres SpinlockLocker lock(m_lock); auto available_range = m_available_ranges.find_largest_not_above(base.get()); if (!available_range) - return ENOMEM; + return EEXIST; if (!available_range->contains(allocated_range)) - return ENOMEM; + return EEXIST; if (*available_range == allocated_range) { m_available_ranges.remove(available_range->base().get()); return allocated_range;