From bf41ab6c40a1236550e26c64ae897d0d74a33968 Mon Sep 17 00:00:00 2001 From: squidbus <175574877+squidbus@users.noreply.github.com> Date: Tue, 10 Dec 2024 03:13:34 -0800 Subject: [PATCH] memory: Handle 0 alignment in MemoryManager::Allocate (#1692) --- src/core/memory.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/core/memory.cpp b/src/core/memory.cpp index 82e4b7ad..980beee7 100644 --- a/src/core/memory.cpp +++ b/src/core/memory.cpp @@ -96,12 +96,12 @@ PAddr MemoryManager::PoolExpand(PAddr search_start, PAddr search_end, size_t siz PAddr MemoryManager::Allocate(PAddr search_start, PAddr search_end, size_t size, u64 alignment, int memory_type) { std::scoped_lock lk{mutex}; + alignment = alignment > 0 ? alignment : 16_KB; auto dmem_area = FindDmemArea(search_start); const auto is_suitable = [&] { - const auto aligned_base = alignment > 0 ? Common::AlignUp(dmem_area->second.base, alignment) - : dmem_area->second.base; + const auto aligned_base = Common::AlignUp(dmem_area->second.base, alignment); const auto alignment_size = aligned_base - dmem_area->second.base; const auto remaining_size = dmem_area->second.size >= alignment_size ? dmem_area->second.size - alignment_size : 0; @@ -114,7 +114,7 @@ PAddr MemoryManager::Allocate(PAddr search_start, PAddr search_end, size_t size, // Align free position PAddr free_addr = dmem_area->second.base; - free_addr = alignment > 0 ? Common::AlignUp(free_addr, alignment) : free_addr; + free_addr = Common::AlignUp(free_addr, alignment); // Add the allocated region to the list and commit its pages. auto& area = CarveDmemArea(free_addr, size)->second;