From ee24ec8d5cf3ad995c0ea1fb523b291948481823 Mon Sep 17 00:00:00 2001 From: "Justin C. Miller" Date: Mon, 12 Aug 2024 19:28:08 -0700 Subject: [PATCH] [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. --- src/kernel/objects/vm_area.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/kernel/objects/vm_area.cpp b/src/kernel/objects/vm_area.cpp index 4a7ef86..22a6925 100644 --- a/src/kernel/objects/vm_area.cpp +++ b/src/kernel/objects/vm_area.cpp @@ -10,7 +10,7 @@ namespace obj { using mem::frame_size; 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_spaces {m_vector_static, 0, static_size}, kobject {kobject::type::vma} @@ -34,6 +34,10 @@ void vm_area::remove_from(vm_space *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()) delete this; }