mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 08:08:12 +00:00
Kernel: Make VMOBject construction OOM-aware
This commit moves the allocation of the resources required for VMObject from its constructors to the constructors of its child classes. We're making this change to give the child classes the chance to expose the fallibility of the allocation.
This commit is contained in:
parent
64778f9e69
commit
d1f265e851
4 changed files with 30 additions and 13 deletions
|
@ -17,14 +17,28 @@ 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())
|
||||
ErrorOr<FixedArray<RefPtr<PhysicalPage>>> VMObject::try_clone_physical_pages() const
|
||||
{
|
||||
all_instances().with([&](auto& list) { list.append(*this); });
|
||||
return m_physical_pages.try_clone();
|
||||
}
|
||||
|
||||
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))))
|
||||
FixedArray<RefPtr<PhysicalPage>> VMObject::must_clone_physical_pages_but_fixme_should_propagate_errors() const
|
||||
{
|
||||
return MUST(try_clone_physical_pages());
|
||||
}
|
||||
|
||||
ErrorOr<FixedArray<RefPtr<PhysicalPage>>> VMObject::try_create_physical_pages(size_t size)
|
||||
{
|
||||
return FixedArray<RefPtr<PhysicalPage>>::try_create(ceil_div(size, static_cast<size_t>(PAGE_SIZE)));
|
||||
}
|
||||
|
||||
FixedArray<RefPtr<PhysicalPage>> VMObject::must_create_physical_pages_but_fixme_should_propagate_errors(size_t size)
|
||||
{
|
||||
return MUST(try_create_physical_pages(size));
|
||||
}
|
||||
|
||||
VMObject::VMObject(FixedArray<RefPtr<PhysicalPage>>&& new_physical_pages)
|
||||
: m_physical_pages(move(new_physical_pages))
|
||||
{
|
||||
all_instances().with([&](auto& list) { list.append(*this); });
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue