[kernel] Ensure all VMA sizes are multiples of page size

Using a 0 address in vma_create_map or vma_map would run into issues if
VMAs had sizes that didn't end on page boundaries. Since any size that's
not a multiples of the page size is a lie, make vm_area's ctor enforce
page sizing.
This commit is contained in:
Justin C. Miller
2024-08-12 19:28:08 -07:00
parent 372325fab7
commit ee24ec8d5c

View File

@@ -10,7 +10,7 @@ namespace obj {
using mem::frame_size; using mem::frame_size;
vm_area::vm_area(size_t size, util::bitset32 flags) : vm_area::vm_area(size_t size, util::bitset32 flags) :
m_size {size}, m_size {mem::page_count(size) * mem::frame_size},
m_flags {flags}, m_flags {flags},
m_spaces {m_vector_static, 0, static_size}, m_spaces {m_vector_static, 0, static_size},
kobject {kobject::type::vma} kobject {kobject::type::vma}
@@ -34,6 +34,10 @@ void
vm_area::remove_from(vm_space *space) vm_area::remove_from(vm_space *space)
{ {
m_spaces.remove_swap(space); m_spaces.remove_swap(space);
// If we were keeping this space around after its refcount
// dropped to zero because it was mapped, check if we should
// clean it up now.
if (!m_spaces.count() && !handle_count()) if (!m_spaces.count() && !handle_count())
delete this; delete this;
} }