summaryrefslogtreecommitdiff
path: root/Kernel/VM
diff options
context:
space:
mode:
authorDaniel Bertalan <dani@danielbertalan.dev>2021-06-20 10:21:16 +0200
committerAli Mohammad Pur <Ali.mpfard@gmail.com>2021-06-24 17:35:49 +0430
commitf820917a765d1ac74af5f66567becb955996b0d8 (patch)
tree98dc6d46387daef9ecedd815bd822753a2f8813a /Kernel/VM
parent00915e89482994a07321fe0788e12cdab0b761fe (diff)
downloadserenity-f820917a765d1ac74af5f66567becb955996b0d8.zip
Everywhere: Use nothrow new with `adopt_{ref,own}_if_nonnull`
This commit converts naked `new`s to `AK::try_make` and `AK::try_create` wherever possible. If the called constructor is private, this can not be done, so we instead now use the standard-defined and compiler-agnostic `new (nothrow)`.
Diffstat (limited to 'Kernel/VM')
-rw-r--r--Kernel/VM/AnonymousVMObject.cpp12
-rw-r--r--Kernel/VM/ContiguousVMObject.cpp2
-rw-r--r--Kernel/VM/PrivateInodeVMObject.cpp4
-rw-r--r--Kernel/VM/Region.cpp4
-rw-r--r--Kernel/VM/ScatterGatherList.cpp2
-rw-r--r--Kernel/VM/Space.cpp2
6 files changed, 13 insertions, 13 deletions
diff --git a/Kernel/VM/AnonymousVMObject.cpp b/Kernel/VM/AnonymousVMObject.cpp
index af568710f5..9b479f8e51 100644
--- a/Kernel/VM/AnonymousVMObject.cpp
+++ b/Kernel/VM/AnonymousVMObject.cpp
@@ -40,7 +40,7 @@ RefPtr<VMObject> AnonymousVMObject::clone()
// one would keep the one it still has. This ensures that the original
// one and this one, as well as the clone have sufficient resources
// to cow all pages as needed
- m_shared_committed_cow_pages = adopt_ref_if_nonnull(new CommittedCowPages(need_cow_pages));
+ m_shared_committed_cow_pages = try_create<CommittedCowPages>(need_cow_pages);
if (!m_shared_committed_cow_pages) {
MM.uncommit_user_physical_pages(need_cow_pages);
@@ -52,7 +52,7 @@ RefPtr<VMObject> AnonymousVMObject::clone()
ensure_or_reset_cow_map();
// FIXME: If this allocation fails, we need to rollback all changes.
- return adopt_ref_if_nonnull(new AnonymousVMObject(*this));
+ return adopt_ref_if_nonnull(new (nothrow) AnonymousVMObject(*this));
}
RefPtr<AnonymousVMObject> AnonymousVMObject::create_with_size(size_t size, AllocationStrategy commit)
@@ -62,17 +62,17 @@ 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))))
return {};
}
- return adopt_ref_if_nonnull(new AnonymousVMObject(size, commit));
+ return adopt_ref_if_nonnull(new (nothrow) AnonymousVMObject(size, commit));
}
RefPtr<AnonymousVMObject> AnonymousVMObject::create_with_physical_pages(NonnullRefPtrVector<PhysicalPage> physical_pages)
{
- return adopt_ref_if_nonnull(new AnonymousVMObject(physical_pages));
+ return adopt_ref_if_nonnull(new (nothrow) AnonymousVMObject(physical_pages));
}
RefPtr<AnonymousVMObject> AnonymousVMObject::create_with_physical_page(PhysicalPage& page)
{
- return adopt_ref_if_nonnull(new AnonymousVMObject(page));
+ return adopt_ref_if_nonnull(new (nothrow) AnonymousVMObject(page));
}
RefPtr<AnonymousVMObject> AnonymousVMObject::create_for_physical_range(PhysicalAddress paddr, size_t size)
@@ -81,7 +81,7 @@ RefPtr<AnonymousVMObject> AnonymousVMObject::create_for_physical_range(PhysicalA
dbgln("Shenanigans! create_for_physical_range({}, {}) would wrap around", paddr, size);
return nullptr;
}
- return adopt_ref_if_nonnull(new AnonymousVMObject(paddr, size));
+ return adopt_ref_if_nonnull(new (nothrow) AnonymousVMObject(paddr, size));
}
AnonymousVMObject::AnonymousVMObject(size_t size, AllocationStrategy strategy)
diff --git a/Kernel/VM/ContiguousVMObject.cpp b/Kernel/VM/ContiguousVMObject.cpp
index 312c9bd671..96f5a63368 100644
--- a/Kernel/VM/ContiguousVMObject.cpp
+++ b/Kernel/VM/ContiguousVMObject.cpp
@@ -15,7 +15,7 @@ RefPtr<ContiguousVMObject> ContiguousVMObject::create_with_size(size_t size, siz
auto contiguous_physical_pages = MM.allocate_contiguous_supervisor_physical_pages(size, physical_alignment);
if (contiguous_physical_pages.is_empty())
return {};
- return adopt_ref_if_nonnull(new ContiguousVMObject(size, contiguous_physical_pages));
+ return adopt_ref_if_nonnull(new (nothrow) ContiguousVMObject(size, contiguous_physical_pages));
}
ContiguousVMObject::ContiguousVMObject(size_t size, NonnullRefPtrVector<PhysicalPage>& contiguous_physical_pages)
diff --git a/Kernel/VM/PrivateInodeVMObject.cpp b/Kernel/VM/PrivateInodeVMObject.cpp
index 1ddd894089..5bca30d915 100644
--- a/Kernel/VM/PrivateInodeVMObject.cpp
+++ b/Kernel/VM/PrivateInodeVMObject.cpp
@@ -11,12 +11,12 @@ namespace Kernel {
RefPtr<PrivateInodeVMObject> PrivateInodeVMObject::create_with_inode(Inode& inode)
{
- return adopt_ref_if_nonnull(new PrivateInodeVMObject(inode, inode.size()));
+ return adopt_ref_if_nonnull(new (nothrow) PrivateInodeVMObject(inode, inode.size()));
}
RefPtr<VMObject> PrivateInodeVMObject::clone()
{
- return adopt_ref_if_nonnull(new PrivateInodeVMObject(*this));
+ return adopt_ref_if_nonnull(new (nothrow) PrivateInodeVMObject(*this));
}
PrivateInodeVMObject::PrivateInodeVMObject(Inode& inode, size_t size)
diff --git a/Kernel/VM/Region.cpp b/Kernel/VM/Region.cpp
index 0c3a03ab80..bd1fa22e2b 100644
--- a/Kernel/VM/Region.cpp
+++ b/Kernel/VM/Region.cpp
@@ -210,7 +210,7 @@ size_t Region::amount_shared() const
NonnullOwnPtr<Region> Region::create_user_accessible(Process* owner, const Range& range, NonnullRefPtr<VMObject> vmobject, size_t offset_in_vmobject, OwnPtr<KString> name, Region::Access access, Cacheable cacheable, bool shared)
{
- auto region = adopt_own_if_nonnull(new Region(range, move(vmobject), offset_in_vmobject, move(name), access, cacheable, shared));
+ auto region = adopt_own_if_nonnull(new (nothrow) Region(range, move(vmobject), offset_in_vmobject, move(name), access, cacheable, shared));
if (region && owner)
region->m_owner = owner->make_weak_ptr();
// FIXME: Return OwnPtr and propagate failure, currently there are too many assumptions made by down stream callers.
@@ -219,7 +219,7 @@ NonnullOwnPtr<Region> Region::create_user_accessible(Process* owner, const Range
OwnPtr<Region> Region::create_kernel_only(const Range& range, NonnullRefPtr<VMObject> vmobject, size_t offset_in_vmobject, OwnPtr<KString> name, Region::Access access, Cacheable cacheable)
{
- return adopt_own_if_nonnull(new Region(range, move(vmobject), offset_in_vmobject, move(name), access, cacheable, false));
+ return adopt_own_if_nonnull(new (nothrow) Region(range, move(vmobject), offset_in_vmobject, move(name), access, cacheable, false));
}
bool Region::should_cow(size_t page_index) const
diff --git a/Kernel/VM/ScatterGatherList.cpp b/Kernel/VM/ScatterGatherList.cpp
index a8452de263..031a28518e 100644
--- a/Kernel/VM/ScatterGatherList.cpp
+++ b/Kernel/VM/ScatterGatherList.cpp
@@ -13,7 +13,7 @@ RefPtr<ScatterGatherList> ScatterGatherList::create(AsyncBlockDeviceRequest& req
auto vm_object = AnonymousVMObject::create_with_physical_pages(allocated_pages);
if (!vm_object)
return {};
- return adopt_ref_if_nonnull(new ScatterGatherList(vm_object.release_nonnull(), request, device_block_size));
+ return adopt_ref_if_nonnull(new (nothrow) ScatterGatherList(vm_object.release_nonnull(), request, device_block_size));
}
ScatterGatherList::ScatterGatherList(NonnullRefPtr<AnonymousVMObject> vm_object, AsyncBlockDeviceRequest& request, size_t device_block_size)
diff --git a/Kernel/VM/Space.cpp b/Kernel/VM/Space.cpp
index bb8bc68b29..8a9ec5cc0e 100644
--- a/Kernel/VM/Space.cpp
+++ b/Kernel/VM/Space.cpp
@@ -20,7 +20,7 @@ OwnPtr<Space> Space::create(Process& process, const Space* parent)
auto page_directory = PageDirectory::create_for_userspace(parent ? &parent->page_directory().range_allocator() : nullptr);
if (!page_directory)
return {};
- auto space = adopt_own_if_nonnull(new Space(process, page_directory.release_nonnull()));
+ auto space = adopt_own_if_nonnull(new (nothrow) Space(process, page_directory.release_nonnull()));
if (!space)
return {};
space->page_directory().set_space({}, *space);