From 397f564144f0f954c86c8bcfdef89d2d7cc9d1f8 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Tue, 9 Mar 2021 14:42:49 +0100 Subject: [PATCH] UserspaceEmulator: Honor alignment requests in virt$mmap(MAP_RANDOMIZED) --- Userland/DevTools/UserspaceEmulator/RangeAllocator.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Userland/DevTools/UserspaceEmulator/RangeAllocator.cpp b/Userland/DevTools/UserspaceEmulator/RangeAllocator.cpp index 8d6bdef488a..7dfc8c6e492 100644 --- a/Userland/DevTools/UserspaceEmulator/RangeAllocator.cpp +++ b/Userland/DevTools/UserspaceEmulator/RangeAllocator.cpp @@ -81,8 +81,7 @@ Optional RangeAllocator::allocate_randomized(size_t size, size_t alignmen // FIXME: I'm sure there's a smarter way to do this. static constexpr size_t maximum_randomization_attempts = 1000; for (size_t i = 0; i < maximum_randomization_attempts; ++i) { - VirtualAddress random_address { get_random() }; - random_address.mask(PAGE_MASK); + VirtualAddress random_address { round_up_to_power_of_two(get_random(), alignment) }; if (!m_total_range.contains(random_address, size)) continue;