1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-28 19:15:09 +00:00

Kernel: Port VMObject to ListedRefCounted

The VMObject class now manages its own instance list (it was previously
a member of MemoryManager.) Removal from the list is done safely on the
last unref(), closing a race window in the previous implementation.

Note that VMObject::all_instances() now has its own lock instead of
using the global MM lock.
This commit is contained in:
Andreas Kling 2021-08-16 22:54:25 +02:00
parent 3a2d888913
commit 7979b5a8bb
4 changed files with 26 additions and 28 deletions

View file

@ -4,21 +4,29 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <AK/Singleton.h>
#include <Kernel/Memory/MemoryManager.h>
#include <Kernel/Memory/VMObject.h>
namespace Kernel::Memory {
static Singleton<SpinLockProtectedValue<VMObject::AllInstancesList>> s_all_instances;
SpinLockProtectedValue<VMObject::AllInstancesList>& VMObject::all_instances()
{
return s_all_instances;
}
VMObject::VMObject(VMObject const& other)
: m_physical_pages(other.m_physical_pages)
{
MM.register_vmobject(*this);
all_instances().with([&](auto& list) { list.append(*this); });
}
VMObject::VMObject(size_t size)
: m_physical_pages(ceil_div(size, static_cast<size_t>(PAGE_SIZE)))
{
MM.register_vmobject(*this);
all_instances().with([&](auto& list) { list.append(*this); });
}
VMObject::~VMObject()
@ -30,7 +38,6 @@ VMObject::~VMObject()
m_on_deleted.clear();
}
MM.unregister_vmobject(*this);
VERIFY(m_regions.is_empty());
}