1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 03:17:35 +00:00

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.
This commit is contained in:
Daniel Bertalan 2021-12-22 12:15:55 +01:00 committed by Andreas Kling
parent 143dbba562
commit 4195a7ef4b

View file

@ -146,9 +146,9 @@ ErrorOr<VirtualRange> 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;