aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--arch/x86_64/src/memory/region_allocator.cpp13
1 files changed, 8 insertions, 5 deletions
diff --git a/arch/x86_64/src/memory/region_allocator.cpp b/arch/x86_64/src/memory/region_allocator.cpp
index 11ffce2..d94e810 100644
--- a/arch/x86_64/src/memory/region_allocator.cpp
+++ b/arch/x86_64/src/memory/region_allocator.cpp
@@ -16,6 +16,11 @@ namespace teachos::memory::x86_64
{
return frame::containing(physical_address{region.base + region.size_in_B - 1});
}
+
+ auto constexpr falls_within(frame const & candidate, frame const & start, frame const & end)
+ {
+ return candidate >= start && candidate <= end;
+ }
} // namespace
region_allocator::region_allocator(memory_information const & mem_info)
@@ -65,19 +70,17 @@ namespace teachos::memory::x86_64
{
choose_next_area();
}
- else if (m_next_frame >= m_kernel_start && m_next_frame <= m_kernel_end)
+ else if (falls_within(m_next_frame, m_kernel_start, m_kernel_end))
{
m_next_frame = m_kernel_end + 1;
}
- else if (m_next_frame >= m_multiboot_start && m_next_frame <= m_multiboot_end)
+ else if (falls_within(m_next_frame, m_multiboot_start, m_multiboot_end))
{
m_next_frame = m_multiboot_end + 1;
}
else
{
- auto allocated = m_next_frame;
- ++m_next_frame;
- return allocated;
+ return m_next_frame++;
}
return allocate();