diff options
| author | Felix Morgner <felix.morgner@ost.ch> | 2025-10-29 12:11:09 +0100 |
|---|---|---|
| committer | Felix Morgner <felix.morgner@ost.ch> | 2025-10-29 12:11:09 +0100 |
| commit | f06fc25b9a54a800c5301eec7320903380da947c (patch) | |
| tree | 18416a40a9d5d6212a130cc77329fee0ec8e5a45 | |
| parent | f5aee1e1ab521d6aeb4c79f6ef276625159e202f (diff) | |
| download | teachos-f06fc25b9a54a800c5301eec7320903380da947c.tar.xz teachos-f06fc25b9a54a800c5301eec7320903380da947c.zip | |
x86_64/memory: simplify region allocator
| -rw-r--r-- | arch/x86_64/src/memory/region_allocator.cpp | 13 |
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(); |
