Skip to content

Commit

Permalink
memory: Handle 0 alignment in MemoryManager::Allocate (#1692)
Browse files Browse the repository at this point in the history
  • Loading branch information
squidbus authored Dec 10, 2024
1 parent aa5293e commit bf41ab6
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/core/memory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down

0 comments on commit bf41ab6

Please sign in to comment.