mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 15:40:19 +00:00
3c05261611
FixedArray now doesn't expose any infallible constructors anymore. Rather, it exposes fallible methods. Therefore, it can be used for OOM-safe code. This commit also converts the rest of the system to use the new API. However, as an example, VMObject can't take advantage of this yet, as we would have to endow VMObject with a fallible static construction method, which would require a very fundamental change to VMObject's whole inheritance hierarchy.
37 lines
964 B
C++
37 lines
964 B
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>> s_all_instances;
|
|
|
|
SpinlockProtected<VMObject::AllInstancesList>& VMObject::all_instances()
|
|
{
|
|
return s_all_instances;
|
|
}
|
|
|
|
VMObject::VMObject(VMObject const& other)
|
|
: m_physical_pages(other.m_physical_pages.must_clone_but_fixme_should_propagate_errors())
|
|
{
|
|
all_instances().with([&](auto& list) { list.append(*this); });
|
|
}
|
|
|
|
VMObject::VMObject(size_t size)
|
|
: m_physical_pages(FixedArray<RefPtr<PhysicalPage>>::must_create_but_fixme_should_propagate_errors(ceil_div(size, static_cast<size_t>(PAGE_SIZE))))
|
|
{
|
|
all_instances().with([&](auto& list) { list.append(*this); });
|
|
}
|
|
|
|
VMObject::~VMObject()
|
|
{
|
|
VERIFY(m_regions.is_empty());
|
|
}
|
|
|
|
}
|