1
0
mirror of https://github.com/SerenityOS/serenity synced 2024-07-09 10:20:45 +00:00
serenity/Kernel/Memory/VMObject.cpp
brody-qq a4ca757db9 Kernel: Add method to clean up remapping region loops
In the VMObject code there are multiple examples of loops over
the VMObject's regions (using for_each_region()) that call remap()
on each region.

To clean up usage of this pattern, this patch adds a method in
VMObject that does this remapping loop. VMObject code that needs
to remap its regions call the new method.
2024-06-08 22:36:03 +01:00

49 lines
1.1 KiB
C++

/*
* 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 {
static Singleton<SpinlockProtected<VMObject::AllInstancesList, LockRank::None>> s_all_instances;
SpinlockProtected<VMObject::AllInstancesList, LockRank::None>& VMObject::all_instances()
{
return s_all_instances;
}
ErrorOr<FixedArray<RefPtr<PhysicalRAMPage>>> VMObject::try_clone_physical_pages() const
{
return m_physical_pages.clone();
}
ErrorOr<FixedArray<RefPtr<PhysicalRAMPage>>> VMObject::try_create_physical_pages(size_t size)
{
return FixedArray<RefPtr<PhysicalRAMPage>>::create(ceil_div(size, static_cast<size_t>(PAGE_SIZE)));
}
VMObject::VMObject(FixedArray<RefPtr<PhysicalRAMPage>>&& new_physical_pages)
: m_physical_pages(move(new_physical_pages))
{
all_instances().with([&](auto& list) { list.append(*this); });
}
VMObject::~VMObject()
{
VERIFY(m_regions.is_empty());
}
void VMObject::remap_regions()
{
for_each_region([](Region& region) {
region.remap();
});
}
}