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
|
|
|
|
2022-11-09 11:39:58 +01:00
|
|
|
static Singleton<SpinlockProtected<VMObject::AllInstancesList, LockRank::None>> s_all_instances;
|
2021-08-16 22:54:25 +02:00
|
|
|
|
2022-11-09 11:39:58 +01:00
|
|
|
SpinlockProtected<VMObject::AllInstancesList, LockRank::None>& VMObject::all_instances()
|
2021-08-16 22:54:25 +02:00
|
|
|
{
|
|
|
|
return s_all_instances;
|
|
|
|
}
|
|
|
|
|
2024-05-11 18:15:51 +03:00
|
|
|
ErrorOr<FixedArray<RefPtr<PhysicalRAMPage>>> VMObject::try_clone_physical_pages() const
|
2019-04-03 15:13:07 +02:00
|
|
|
{
|
2023-01-28 20:12:17 +00:00
|
|
|
return m_physical_pages.clone();
|
2022-01-11 18:05:47 +01:00
|
|
|
}
|
|
|
|
|
2024-05-11 18:15:51 +03:00
|
|
|
ErrorOr<FixedArray<RefPtr<PhysicalRAMPage>>> VMObject::try_create_physical_pages(size_t size)
|
2022-01-11 18:05:47 +01:00
|
|
|
{
|
2024-05-11 18:15:51 +03:00
|
|
|
return FixedArray<RefPtr<PhysicalRAMPage>>::create(ceil_div(size, static_cast<size_t>(PAGE_SIZE)));
|
2022-01-11 18:05:47 +01:00
|
|
|
}
|
|
|
|
|
2024-05-11 18:15:51 +03:00
|
|
|
VMObject::VMObject(FixedArray<RefPtr<PhysicalRAMPage>>&& 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
|
|
|
|
2024-06-02 01:51:14 +01:00
|
|
|
void VMObject::remap_regions()
|
|
|
|
{
|
|
|
|
for_each_region([](Region& region) {
|
|
|
|
region.remap();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2024-06-28 10:47:56 +01:00
|
|
|
bool VMObject::remap_regions_one_page(size_t page_index, NonnullRefPtr<PhysicalRAMPage> page)
|
|
|
|
{
|
|
|
|
bool success = true;
|
|
|
|
for_each_region([&](Region& region) {
|
|
|
|
if (!region.remap_vmobject_page(page_index, *page))
|
|
|
|
success = false;
|
|
|
|
});
|
|
|
|
return success;
|
|
|
|
}
|
|
|
|
|
2020-02-16 01:27:42 +01:00
|
|
|
}
|