2020-01-18 09:38:21 +01:00
|
|
|
/*
|
2021-08-06 13:49:36 +02:00
|
|
|
* Copyright (c) 2018-2021, Andreas Kling <kling@serenityos.org>
|
2020-01-18 09:38:21 +01:00
|
|
|
*
|
2021-04-22 01:24:48 -07:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-01-18 09:38:21 +01:00
|
|
|
*/
|
|
|
|
|
2021-08-16 22:54:25 +02:00
|
|
|
#include <AK/Singleton.h>
|
2021-08-06 10:45:34 +02:00
|
|
|
#include <Kernel/Memory/MemoryManager.h>
|
|
|
|
#include <Kernel/Memory/VMObject.h>
|
2019-04-03 15:13:07 +02:00
|
|
|
|
2021-08-06 13:49:36 +02:00
|
|
|
namespace Kernel::Memory {
|
2020-02-16 01:27:42 +01:00
|
|
|
|
2021-08-22 01:37:17 +02:00
|
|
|
static Singleton<SpinlockProtected<VMObject::AllInstancesList>> s_all_instances;
|
2021-08-16 22:54:25 +02:00
|
|
|
|
2021-08-22 01:37:17 +02:00
|
|
|
SpinlockProtected<VMObject::AllInstancesList>& VMObject::all_instances()
|
2021-08-16 22:54:25 +02:00
|
|
|
{
|
|
|
|
return s_all_instances;
|
|
|
|
}
|
|
|
|
|
2022-08-24 15:56:26 +02:00
|
|
|
ErrorOr<FixedArray<RefPtr<PhysicalPage>>> VMObject::try_clone_physical_pages() const
|
2019-04-03 15:13:07 +02:00
|
|
|
{
|
2022-01-11 18:05:47 +01:00
|
|
|
return m_physical_pages.try_clone();
|
|
|
|
}
|
|
|
|
|
2022-08-24 15:56:26 +02:00
|
|
|
ErrorOr<FixedArray<RefPtr<PhysicalPage>>> VMObject::try_create_physical_pages(size_t size)
|
2022-01-11 18:05:47 +01:00
|
|
|
{
|
2022-08-24 15:56:26 +02:00
|
|
|
return FixedArray<RefPtr<PhysicalPage>>::try_create(ceil_div(size, static_cast<size_t>(PAGE_SIZE)));
|
2022-01-11 18:05:47 +01:00
|
|
|
}
|
|
|
|
|
2022-08-24 15:56:26 +02:00
|
|
|
VMObject::VMObject(FixedArray<RefPtr<PhysicalPage>>&& new_physical_pages)
|
2022-01-11 18:05:47 +01:00
|
|
|
: m_physical_pages(move(new_physical_pages))
|
2019-04-03 15:13:07 +02:00
|
|
|
{
|
2021-08-16 22:54:25 +02:00
|
|
|
all_instances().with([&](auto& list) { list.append(*this); });
|
2019-04-03 15:13:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
VMObject::~VMObject()
|
|
|
|
{
|
2021-07-25 17:11:50 +02:00
|
|
|
VERIFY(m_regions.is_empty());
|
2019-04-03 15:13:07 +02:00
|
|
|
}
|
2020-02-16 01:27:42 +01:00
|
|
|
|
|
|
|
}
|