1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-24 15:37:43 +00:00

Kernel: Make AnonymousVMObject::clone/create APIs OOM safe

This commit is contained in:
Brian Gianforcaro 2021-05-14 04:59:47 -07:00 committed by Andreas Kling
parent ede1483e48
commit d45db06826

View file

@ -47,7 +47,7 @@ RefPtr<VMObject> AnonymousVMObject::clone()
// or reset all pages to be copied again if we were previously cloned // or reset all pages to be copied again if we were previously cloned
ensure_or_reset_cow_map(); ensure_or_reset_cow_map();
return adopt_ref(*new AnonymousVMObject(*this)); return adopt_ref_if_nonnull(new AnonymousVMObject(*this));
} }
RefPtr<AnonymousVMObject> AnonymousVMObject::create_with_size(size_t size, AllocationStrategy commit) RefPtr<AnonymousVMObject> AnonymousVMObject::create_with_size(size_t size, AllocationStrategy commit)
@ -57,7 +57,7 @@ RefPtr<AnonymousVMObject> AnonymousVMObject::create_with_size(size_t size, Alloc
if (!MM.commit_user_physical_pages(ceil_div(size, static_cast<size_t>(PAGE_SIZE)))) if (!MM.commit_user_physical_pages(ceil_div(size, static_cast<size_t>(PAGE_SIZE))))
return {}; return {};
} }
return adopt_ref(*new AnonymousVMObject(size, commit)); return adopt_ref_if_nonnull(new AnonymousVMObject(size, commit));
} }
NonnullRefPtr<AnonymousVMObject> AnonymousVMObject::create_with_physical_pages(NonnullRefPtrVector<PhysicalPage> physical_pages) NonnullRefPtr<AnonymousVMObject> AnonymousVMObject::create_with_physical_pages(NonnullRefPtrVector<PhysicalPage> physical_pages)
@ -76,7 +76,7 @@ RefPtr<AnonymousVMObject> AnonymousVMObject::create_for_physical_range(PhysicalA
dbgln("Shenanigans! create_for_physical_range({}, {}) would wrap around", paddr, size); dbgln("Shenanigans! create_for_physical_range({}, {}) would wrap around", paddr, size);
return nullptr; return nullptr;
} }
return adopt_ref(*new AnonymousVMObject(paddr, size)); return adopt_ref_if_nonnull(new AnonymousVMObject(paddr, size));
} }
AnonymousVMObject::AnonymousVMObject(size_t size, AllocationStrategy strategy) AnonymousVMObject::AnonymousVMObject(size_t size, AllocationStrategy strategy)