Serenity Operating System
1/*
2 * Copyright (c) 2018-2021, Andreas Kling <kling@serenityos.org>
3 *
4 * SPDX-License-Identifier: BSD-2-Clause
5 */
6
7#include <AK/Singleton.h>
8#include <Kernel/Memory/MemoryManager.h>
9#include <Kernel/Memory/VMObject.h>
10
11namespace Kernel::Memory {
12
13static Singleton<SpinlockProtected<VMObject::AllInstancesList, LockRank::None>> s_all_instances;
14
15SpinlockProtected<VMObject::AllInstancesList, LockRank::None>& VMObject::all_instances()
16{
17 return s_all_instances;
18}
19
20ErrorOr<FixedArray<RefPtr<PhysicalPage>>> VMObject::try_clone_physical_pages() const
21{
22 return m_physical_pages.clone();
23}
24
25ErrorOr<FixedArray<RefPtr<PhysicalPage>>> VMObject::try_create_physical_pages(size_t size)
26{
27 return FixedArray<RefPtr<PhysicalPage>>::create(ceil_div(size, static_cast<size_t>(PAGE_SIZE)));
28}
29
30VMObject::VMObject(FixedArray<RefPtr<PhysicalPage>>&& new_physical_pages)
31 : m_physical_pages(move(new_physical_pages))
32{
33 all_instances().with([&](auto& list) { list.append(*this); });
34}
35
36VMObject::~VMObject()
37{
38 VERIFY(m_regions.is_empty());
39}
40
41}