serenity/Kernel/Memory/VMObject.cpp

38 lines
964 B
C++
Raw Normal View History

/*
* Copyright (c) 2018-2021, Andreas Kling <kling@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <AK/Singleton.h>
#include <Kernel/Memory/MemoryManager.h>
#include <Kernel/Memory/VMObject.h>
namespace Kernel::Memory {
2021-08-21 23:37:17 +00:00
static Singleton<SpinlockProtected<VMObject::AllInstancesList>> s_all_instances;
2021-08-21 23:37:17 +00:00
SpinlockProtected<VMObject::AllInstancesList>& VMObject::all_instances()
{
return s_all_instances;
}
VMObject::VMObject(VMObject const& other)
: m_physical_pages(other.m_physical_pages.must_clone_but_fixme_should_propagate_errors())
{
all_instances().with([&](auto& list) { list.append(*this); });
}
VMObject::VMObject(size_t size)
: m_physical_pages(FixedArray<RefPtr<PhysicalPage>>::must_create_but_fixme_should_propagate_errors(ceil_div(size, static_cast<size_t>(PAGE_SIZE))))
{
all_instances().with([&](auto& list) { list.append(*this); });
}
VMObject::~VMObject()
{
VERIFY(m_regions.is_empty());
}
}