From a4a389156db00ad070b5d9bdbc1895ffdf2cd70d Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sun, 15 Nov 2020 17:29:24 +0100 Subject: [PATCH] UserspaceEmulator: Make sure the (crappy) VM allocator is page-aligned We don't want the next_address pointer losing its alignment somehow. This whole thing should be replaced at some point, since UE hosted programs won't be able to run forever with this allocation strategy. --- DevTools/UserspaceEmulator/Emulator.cpp | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/DevTools/UserspaceEmulator/Emulator.cpp b/DevTools/UserspaceEmulator/Emulator.cpp index be96bfc5bf0..a6edf5e8458 100644 --- a/DevTools/UserspaceEmulator/Emulator.cpp +++ b/DevTools/UserspaceEmulator/Emulator.cpp @@ -857,14 +857,12 @@ FlatPtr Emulator::allocate_vm(size_t size, size_t alignment) FlatPtr final_address; - if (alignment) { - // FIXME: What if alignment is not a power of 2? - final_address = round_up_to_power_of_two(next_address, alignment); - } else { - final_address = next_address; - } + if (!alignment) + alignment = PAGE_SIZE; - next_address = final_address + size; + // FIXME: What if alignment is not a power of 2? + final_address = round_up_to_power_of_two(next_address, alignment); + next_address = round_up_to_power_of_two(final_address + size, PAGE_SIZE); return final_address; }