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