summaryrefslogtreecommitdiff
path: root/Kernel
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
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')
-rw-r--r--Kernel/ACPI/MultiProcessorParser.cpp2
-rw-r--r--Kernel/CoreDump.cpp2
-rw-r--r--Kernel/Devices/USB/USBDevice.cpp2
-rw-r--r--Kernel/Devices/USB/USBPipe.cpp2
-rw-r--r--Kernel/Devices/USB/USBTransfer.cpp2
-rw-r--r--Kernel/FileSystem/AnonymousFile.h2
-rw-r--r--Kernel/FileSystem/Custody.cpp2
-rw-r--r--Kernel/FileSystem/DevFS.cpp4
-rw-r--r--Kernel/FileSystem/Ext2FileSystem.cpp2
-rw-r--r--Kernel/FileSystem/FileDescription.cpp4
-rw-r--r--Kernel/FileSystem/InodeFile.h2
-rw-r--r--Kernel/FileSystem/InodeWatcher.cpp2
-rw-r--r--Kernel/FileSystem/InodeWatcher.h2
-rw-r--r--Kernel/FileSystem/Plan9FileSystem.cpp2
-rw-r--r--Kernel/FileSystem/ProcFS.cpp6
-rw-r--r--Kernel/FileSystem/TmpFS.cpp4
-rw-r--r--Kernel/KBuffer.h8
-rw-r--r--Kernel/KBufferBuilder.cpp2
-rw-r--r--Kernel/Net/E1000ENetworkAdapter.cpp2
-rw-r--r--Kernel/Net/E1000NetworkAdapter.cpp2
-rw-r--r--Kernel/Net/IPv4Socket.cpp2
-rw-r--r--Kernel/Net/LocalSocket.cpp4
-rw-r--r--Kernel/Net/NE2000NetworkAdapter.cpp2
-rw-r--r--Kernel/Net/NetworkAdapter.cpp4
-rw-r--r--Kernel/Net/RTL8139NetworkAdapter.cpp2
-rw-r--r--Kernel/Net/RTL8168NetworkAdapter.cpp2
-rw-r--r--Kernel/Net/TCPSocket.cpp2
-rw-r--r--Kernel/Net/UDPSocket.cpp2
-rw-r--r--Kernel/PerformanceEventBuffer.cpp2
-rw-r--r--Kernel/Process.cpp2
-rw-r--r--Kernel/ProcessGroup.cpp2
-rw-r--r--Kernel/Syscalls/alarm.cpp2
-rw-r--r--Kernel/Syscalls/module.cpp4
-rw-r--r--Kernel/TTY/PTYMultiplexer.cpp2
-rw-r--r--Kernel/Thread.cpp4
-rw-r--r--Kernel/ThreadTracer.h2
-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
42 files changed, 61 insertions, 61 deletions
diff --git a/Kernel/ACPI/MultiProcessorParser.cpp b/Kernel/ACPI/MultiProcessorParser.cpp
index 8266d6411e..f6f909f766 100644
--- a/Kernel/ACPI/MultiProcessorParser.cpp
+++ b/Kernel/ACPI/MultiProcessorParser.cpp
@@ -22,7 +22,7 @@ UNMAP_AFTER_INIT OwnPtr<MultiProcessorParser> MultiProcessorParser::autodetect()
auto floating_pointer = find_floating_pointer();
if (!floating_pointer.has_value())
return {};
- auto parser = adopt_own_if_nonnull(new MultiProcessorParser(floating_pointer.value()));
+ auto parser = adopt_own_if_nonnull(new (nothrow) MultiProcessorParser(floating_pointer.value()));
VERIFY(parser != nullptr);
return parser;
}
diff --git a/Kernel/CoreDump.cpp b/Kernel/CoreDump.cpp
index b73cb9e9f7..1f943b8c33 100644
--- a/Kernel/CoreDump.cpp
+++ b/Kernel/CoreDump.cpp
@@ -32,7 +32,7 @@ OwnPtr<CoreDump> CoreDump::create(NonnullRefPtr<Process> process, const String&
auto fd = create_target_file(process, output_path);
if (!fd)
return {};
- return adopt_own_if_nonnull(new CoreDump(move(process), fd.release_nonnull()));
+ return adopt_own_if_nonnull(new (nothrow) CoreDump(move(process), fd.release_nonnull()));
}
CoreDump::CoreDump(NonnullRefPtr<Process> process, NonnullRefPtr<FileDescription>&& fd)
diff --git a/Kernel/Devices/USB/USBDevice.cpp b/Kernel/Devices/USB/USBDevice.cpp
index 53fce1a49e..609f059f7d 100644
--- a/Kernel/Devices/USB/USBDevice.cpp
+++ b/Kernel/Devices/USB/USBDevice.cpp
@@ -22,7 +22,7 @@ KResultOr<NonnullRefPtr<Device>> Device::try_create(PortNumber port, DeviceSpeed
if (pipe_or_error.is_error())
return pipe_or_error.error();
- auto device = adopt_ref_if_nonnull(new Device(port, speed, pipe_or_error.release_value()));
+ auto device = AK::try_create<Device>(port, speed, pipe_or_error.release_value());
if (!device)
return ENOMEM;
diff --git a/Kernel/Devices/USB/USBPipe.cpp b/Kernel/Devices/USB/USBPipe.cpp
index 9aae7d7968..f7275b5b1c 100644
--- a/Kernel/Devices/USB/USBPipe.cpp
+++ b/Kernel/Devices/USB/USBPipe.cpp
@@ -13,7 +13,7 @@ namespace Kernel::USB {
KResultOr<NonnullOwnPtr<Pipe>> Pipe::try_create_pipe(Type type, Direction direction, u8 endpoint_address, u16 max_packet_size, i8 device_address, u8 poll_interval)
{
- auto pipe = adopt_own_if_nonnull(new Pipe(type, direction, endpoint_address, max_packet_size, device_address, poll_interval));
+ auto pipe = adopt_own_if_nonnull(new (nothrow) Pipe(type, direction, endpoint_address, max_packet_size, device_address, poll_interval));
if (!pipe)
return ENOMEM;
diff --git a/Kernel/Devices/USB/USBTransfer.cpp b/Kernel/Devices/USB/USBTransfer.cpp
index c865f621af..cd9ad7f00b 100644
--- a/Kernel/Devices/USB/USBTransfer.cpp
+++ b/Kernel/Devices/USB/USBTransfer.cpp
@@ -15,7 +15,7 @@ RefPtr<Transfer> Transfer::try_create(Pipe& pipe, u16 len)
if (!vmobject)
return nullptr;
- return adopt_ref_if_nonnull(new Transfer(pipe, len, *vmobject));
+ return AK::try_create<Transfer>(pipe, len, *vmobject);
}
Transfer::Transfer(Pipe& pipe, u16 len, ContiguousVMObject& vmobject)
diff --git a/Kernel/FileSystem/AnonymousFile.h b/Kernel/FileSystem/AnonymousFile.h
index 021611018b..8496108ace 100644
--- a/Kernel/FileSystem/AnonymousFile.h
+++ b/Kernel/FileSystem/AnonymousFile.h
@@ -14,7 +14,7 @@ class AnonymousFile final : public File {
public:
static RefPtr<AnonymousFile> create(NonnullRefPtr<AnonymousVMObject> vmobject)
{
- return adopt_ref_if_nonnull(new AnonymousFile(move(vmobject)));
+ return adopt_ref_if_nonnull(new (nothrow) AnonymousFile(move(vmobject)));
}
virtual ~AnonymousFile() override;
diff --git a/Kernel/FileSystem/Custody.cpp b/Kernel/FileSystem/Custody.cpp
index fca850e674..af21e32687 100644
--- a/Kernel/FileSystem/Custody.cpp
+++ b/Kernel/FileSystem/Custody.cpp
@@ -17,7 +17,7 @@ KResultOr<NonnullRefPtr<Custody>> Custody::try_create(Custody* parent, StringVie
auto name_kstring = KString::try_create(name);
if (!name_kstring)
return ENOMEM;
- auto custody = adopt_ref_if_nonnull(new Custody(parent, name_kstring.release_nonnull(), inode, mount_flags));
+ auto custody = adopt_ref_if_nonnull(new (nothrow) Custody(parent, name_kstring.release_nonnull(), inode, mount_flags));
if (!custody)
return ENOMEM;
return custody.release_nonnull();
diff --git a/Kernel/FileSystem/DevFS.cpp b/Kernel/FileSystem/DevFS.cpp
index ec80bbe59a..f75f66e47e 100644
--- a/Kernel/FileSystem/DevFS.cpp
+++ b/Kernel/FileSystem/DevFS.cpp
@@ -275,7 +275,7 @@ KResultOr<NonnullRefPtr<Inode>> DevFSRootDirectoryInode::create_child(const Stri
}
if (name != "pts")
return EROFS;
- auto new_directory_inode = adopt_ref_if_nonnull(new DevFSPtsDirectoryInode(m_parent_fs));
+ auto new_directory_inode = adopt_ref_if_nonnull(new (nothrow) DevFSPtsDirectoryInode(m_parent_fs));
if (!new_directory_inode)
return ENOMEM;
if (!m_subfolders.try_ensure_capacity(m_subfolders.size() + 1))
@@ -291,7 +291,7 @@ KResultOr<NonnullRefPtr<Inode>> DevFSRootDirectoryInode::create_child(const Stri
if (link.name() == name)
return EEXIST;
}
- auto new_link_inode = adopt_ref_if_nonnull(new DevFSLinkInode(m_parent_fs, name));
+ auto new_link_inode = adopt_ref_if_nonnull(new (nothrow) DevFSLinkInode(m_parent_fs, name));
if (!new_link_inode)
return ENOMEM;
if (!m_links.try_ensure_capacity(m_links.size() + 1))
diff --git a/Kernel/FileSystem/Ext2FileSystem.cpp b/Kernel/FileSystem/Ext2FileSystem.cpp
index 888757974d..aa055957f7 100644
--- a/Kernel/FileSystem/Ext2FileSystem.cpp
+++ b/Kernel/FileSystem/Ext2FileSystem.cpp
@@ -1500,7 +1500,7 @@ KResultOr<Ext2FS::CachedBitmap*> Ext2FS::get_bitmap_block(BlockIndex bitmap_bloc
dbgln("Ext2FS: Failed to load bitmap block {}", bitmap_block_index);
return result;
}
- auto new_bitmap = adopt_own_if_nonnull(new CachedBitmap(bitmap_block_index, move(block)));
+ auto new_bitmap = adopt_own_if_nonnull(new (nothrow) CachedBitmap(bitmap_block_index, move(block)));
if (!new_bitmap)
return ENOMEM;
if (!m_cached_bitmaps.try_append(move(new_bitmap)))
diff --git a/Kernel/FileSystem/FileDescription.cpp b/Kernel/FileSystem/FileDescription.cpp
index 76e1a3cd62..c8794b34c7 100644
--- a/Kernel/FileSystem/FileDescription.cpp
+++ b/Kernel/FileSystem/FileDescription.cpp
@@ -30,7 +30,7 @@ KResultOr<NonnullRefPtr<FileDescription>> FileDescription::create(Custody& custo
if (inode_file.is_error())
return inode_file.error();
- auto description = adopt_ref_if_nonnull(new FileDescription(*inode_file.release_value()));
+ auto description = adopt_ref_if_nonnull(new (nothrow) FileDescription(*inode_file.release_value()));
if (!description)
return ENOMEM;
@@ -45,7 +45,7 @@ KResultOr<NonnullRefPtr<FileDescription>> FileDescription::create(Custody& custo
KResultOr<NonnullRefPtr<FileDescription>> FileDescription::create(File& file)
{
- auto description = adopt_ref_if_nonnull(new FileDescription(file));
+ auto description = adopt_ref_if_nonnull(new (nothrow) FileDescription(file));
if (!description)
return ENOMEM;
auto result = description->attach();
diff --git a/Kernel/FileSystem/InodeFile.h b/Kernel/FileSystem/InodeFile.h
index bdc2d5aaf6..658a03a397 100644
--- a/Kernel/FileSystem/InodeFile.h
+++ b/Kernel/FileSystem/InodeFile.h
@@ -16,7 +16,7 @@ class InodeFile final : public File {
public:
static KResultOr<NonnullRefPtr<InodeFile>> create(NonnullRefPtr<Inode>&& inode)
{
- auto file = adopt_ref_if_nonnull(new InodeFile(move(inode)));
+ auto file = adopt_ref_if_nonnull(new (nothrow) InodeFile(move(inode)));
if (!file)
return ENOMEM;
return file.release_nonnull();
diff --git a/Kernel/FileSystem/InodeWatcher.cpp b/Kernel/FileSystem/InodeWatcher.cpp
index 29be55b502..7880aff286 100644
--- a/Kernel/FileSystem/InodeWatcher.cpp
+++ b/Kernel/FileSystem/InodeWatcher.cpp
@@ -14,7 +14,7 @@ namespace Kernel {
KResultOr<NonnullRefPtr<InodeWatcher>> InodeWatcher::create()
{
- auto watcher = adopt_ref_if_nonnull(new InodeWatcher);
+ auto watcher = adopt_ref_if_nonnull(new (nothrow) InodeWatcher);
if (watcher)
return watcher.release_nonnull();
return ENOMEM;
diff --git a/Kernel/FileSystem/InodeWatcher.h b/Kernel/FileSystem/InodeWatcher.h
index 7a7c68d2dd..5b1ab5420e 100644
--- a/Kernel/FileSystem/InodeWatcher.h
+++ b/Kernel/FileSystem/InodeWatcher.h
@@ -27,7 +27,7 @@ struct WatchDescription {
static KResultOr<NonnullOwnPtr<WatchDescription>> create(int wd, Inode& inode, unsigned event_mask)
{
- auto description = adopt_own_if_nonnull(new WatchDescription(wd, inode, event_mask));
+ auto description = adopt_own_if_nonnull(new (nothrow) WatchDescription(wd, inode, event_mask));
if (description)
return description.release_nonnull();
return ENOMEM;
diff --git a/Kernel/FileSystem/Plan9FileSystem.cpp b/Kernel/FileSystem/Plan9FileSystem.cpp
index 1122213fdf..330f1528f8 100644
--- a/Kernel/FileSystem/Plan9FileSystem.cpp
+++ b/Kernel/FileSystem/Plan9FileSystem.cpp
@@ -576,7 +576,7 @@ KResult Plan9FS::read_and_dispatch_one_message()
auto completion = optional_completion.value();
ScopedSpinLock lock(completion->lock);
completion->result = KSuccess;
- completion->message = adopt_own_if_nonnull(new Message { buffer.release_nonnull() });
+ completion->message = adopt_own_if_nonnull(new (nothrow) Message { buffer.release_nonnull() });
completion->completed = true;
m_completions.remove(header.tag);
diff --git a/Kernel/FileSystem/ProcFS.cpp b/Kernel/FileSystem/ProcFS.cpp
index 7921ccecfa..396e9f474a 100644
--- a/Kernel/FileSystem/ProcFS.cpp
+++ b/Kernel/FileSystem/ProcFS.cpp
@@ -264,7 +264,7 @@ struct ProcFSInodeData : public FileDescriptionData {
RefPtr<ProcFS> ProcFS::create()
{
- return adopt_ref_if_nonnull(new ProcFS);
+ return adopt_ref_if_nonnull(new (nothrow) ProcFS);
}
ProcFS::~ProcFS()
@@ -1073,7 +1073,7 @@ RefPtr<Inode> ProcFS::get_inode(InodeIdentifier inode_id) const
return adopt_ref_if_nonnull(it->value);
// We couldn't ref it, so just create a new one and replace the entry
}
- auto inode = adopt_ref_if_nonnull(new ProcFSInode(const_cast<ProcFS&>(*this), inode_id.index()));
+ auto inode = adopt_ref_if_nonnull(new (nothrow) ProcFSInode(const_cast<ProcFS&>(*this), inode_id.index()));
if (!inode)
return {};
auto result = m_inodes.set(inode_id.index().value(), inode.ptr());
@@ -1163,7 +1163,7 @@ KResult ProcFSInode::refresh_data(FileDescription& description) const
}
if (!cached_data)
- cached_data = adopt_own_if_nonnull(new ProcFSInodeData);
+ cached_data = adopt_own_if_nonnull(new (nothrow) ProcFSInodeData);
auto& buffer = static_cast<ProcFSInodeData&>(*cached_data).buffer;
if (buffer) {
// If we're reusing the buffer, reset the size to 0 first. This
diff --git a/Kernel/FileSystem/TmpFS.cpp b/Kernel/FileSystem/TmpFS.cpp
index a9224363b3..cac983048a 100644
--- a/Kernel/FileSystem/TmpFS.cpp
+++ b/Kernel/FileSystem/TmpFS.cpp
@@ -13,7 +13,7 @@ namespace Kernel {
RefPtr<TmpFS> TmpFS::create()
{
- return adopt_ref_if_nonnull(new TmpFS);
+ return adopt_ref_if_nonnull(new (nothrow) TmpFS);
}
TmpFS::TmpFS()
@@ -86,7 +86,7 @@ TmpFSInode::~TmpFSInode()
RefPtr<TmpFSInode> TmpFSInode::create(TmpFS& fs, InodeMetadata metadata, InodeIdentifier parent)
{
- auto inode = adopt_ref_if_nonnull(new TmpFSInode(fs, metadata, parent));
+ auto inode = adopt_ref_if_nonnull(new (nothrow) TmpFSInode(fs, metadata, parent));
if (inode)
fs.register_inode(*inode);
return inode;
diff --git a/Kernel/KBuffer.h b/Kernel/KBuffer.h
index d933acdb0f..8a136bc32c 100644
--- a/Kernel/KBuffer.h
+++ b/Kernel/KBuffer.h
@@ -32,7 +32,7 @@ public:
auto region = MM.allocate_kernel_region(page_round_up(size), name, access, strategy);
if (!region)
return nullptr;
- return adopt_ref_if_nonnull(new KBufferImpl(region.release_nonnull(), size, strategy));
+ return adopt_ref_if_nonnull(new (nothrow) KBufferImpl(region.release_nonnull(), size, strategy));
}
static RefPtr<KBufferImpl> try_create_with_bytes(ReadonlyBytes bytes, Region::Access access, StringView name = "KBuffer", AllocationStrategy strategy = AllocationStrategy::Reserve)
@@ -42,7 +42,7 @@ public:
return nullptr;
memcpy(region->vaddr().as_ptr(), bytes.data(), bytes.size());
- return adopt_ref_if_nonnull(new KBufferImpl(region.release_nonnull(), bytes.size(), strategy));
+ return adopt_ref_if_nonnull(new (nothrow) KBufferImpl(region.release_nonnull(), bytes.size(), strategy));
}
static RefPtr<KBufferImpl> create_with_size(size_t size, Region::Access access, StringView name, AllocationStrategy strategy = AllocationStrategy::Reserve)
@@ -109,7 +109,7 @@ public:
auto impl = KBufferImpl::try_create_with_size(size, access, name, strategy);
if (!impl)
return {};
- return adopt_own_if_nonnull(new KBuffer(impl.release_nonnull()));
+ return adopt_own_if_nonnull(new (nothrow) KBuffer(impl.release_nonnull()));
}
[[nodiscard]] static OwnPtr<KBuffer> try_create_with_bytes(ReadonlyBytes bytes, Region::Access access = Region::Access::Read | Region::Access::Write, StringView name = "KBuffer", AllocationStrategy strategy = AllocationStrategy::Reserve)
@@ -117,7 +117,7 @@ public:
auto impl = KBufferImpl::try_create_with_bytes(bytes, access, name, strategy);
if (!impl)
return {};
- return adopt_own_if_nonnull(new KBuffer(impl.release_nonnull()));
+ return adopt_own_if_nonnull(new (nothrow) KBuffer(impl.release_nonnull()));
}
[[nodiscard]] static KBuffer create_with_size(size_t size, Region::Access access = Region::Access::Read | Region::Access::Write, StringView name = "KBuffer", AllocationStrategy strategy = AllocationStrategy::Reserve)
diff --git a/Kernel/KBufferBuilder.cpp b/Kernel/KBufferBuilder.cpp
index d1665b09ef..10bc9636be 100644
--- a/Kernel/KBufferBuilder.cpp
+++ b/Kernel/KBufferBuilder.cpp
@@ -39,7 +39,7 @@ OwnPtr<KBuffer> KBufferBuilder::build()
if (!flush())
return {};
- return adopt_own_if_nonnull(new KBuffer(move(m_buffer)));
+ return try_make<KBuffer>(move(m_buffer));
}
KBufferBuilder::KBufferBuilder(bool can_expand)
diff --git a/Kernel/Net/E1000ENetworkAdapter.cpp b/Kernel/Net/E1000ENetworkAdapter.cpp
index 63749e1ce9..fcd092e1ae 100644
--- a/Kernel/Net/E1000ENetworkAdapter.cpp
+++ b/Kernel/Net/E1000ENetworkAdapter.cpp
@@ -188,7 +188,7 @@ UNMAP_AFTER_INIT RefPtr<E1000ENetworkAdapter> E1000ENetworkAdapter::try_to_initi
if (!is_valid_device_id(id.device_id))
return {};
u8 irq = PCI::get_interrupt_line(address);
- auto adapter = adopt_ref_if_nonnull(new E1000ENetworkAdapter(address, irq));
+ auto adapter = adopt_ref_if_nonnull(new (nothrow) E1000ENetworkAdapter(address, irq));
if (!adapter)
return {};
if (adapter->initialize())
diff --git a/Kernel/Net/E1000NetworkAdapter.cpp b/Kernel/Net/E1000NetworkAdapter.cpp
index d8c831e499..64991cd72b 100644
--- a/Kernel/Net/E1000NetworkAdapter.cpp
+++ b/Kernel/Net/E1000NetworkAdapter.cpp
@@ -165,7 +165,7 @@ UNMAP_AFTER_INIT RefPtr<E1000NetworkAdapter> E1000NetworkAdapter::try_to_initial
if (!is_valid_device_id(id.device_id))
return {};
u8 irq = PCI::get_interrupt_line(address);
- auto adapter = adopt_ref_if_nonnull(new E1000NetworkAdapter(address, irq));
+ auto adapter = adopt_ref_if_nonnull(new (nothrow) E1000NetworkAdapter(address, irq));
if (!adapter)
return {};
if (adapter->initialize())
diff --git a/Kernel/Net/IPv4Socket.cpp b/Kernel/Net/IPv4Socket.cpp
index 7268e71549..ef74e35f1d 100644
--- a/Kernel/Net/IPv4Socket.cpp
+++ b/Kernel/Net/IPv4Socket.cpp
@@ -50,7 +50,7 @@ KResultOr<NonnullRefPtr<Socket>> IPv4Socket::create(int type, int protocol)
return udp_socket.release_value();
}
if (type == SOCK_RAW) {
- auto raw_socket = adopt_ref_if_nonnull(new IPv4Socket(type, protocol));
+ auto raw_socket = adopt_ref_if_nonnull(new (nothrow) IPv4Socket(type, protocol));
if (raw_socket)
return raw_socket.release_nonnull();
return ENOMEM;
diff --git a/Kernel/Net/LocalSocket.cpp b/Kernel/Net/LocalSocket.cpp
index 2cd6e4adeb..c8674325f7 100644
--- a/Kernel/Net/LocalSocket.cpp
+++ b/Kernel/Net/LocalSocket.cpp
@@ -33,7 +33,7 @@ void LocalSocket::for_each(Function<void(const LocalSocket&)> callback)
KResultOr<NonnullRefPtr<Socket>> LocalSocket::create(int type)
{
- auto socket = adopt_ref_if_nonnull(new LocalSocket(type));
+ auto socket = adopt_ref_if_nonnull(new (nothrow) LocalSocket(type));
if (socket)
return socket.release_nonnull();
return ENOMEM;
@@ -41,7 +41,7 @@ KResultOr<NonnullRefPtr<Socket>> LocalSocket::create(int type)
KResultOr<SocketPair> LocalSocket::create_connected_pair(int type)
{
- auto socket = adopt_ref_if_nonnull(new LocalSocket(type));
+ auto socket = adopt_ref_if_nonnull(new (nothrow) LocalSocket(type));
if (!socket)
return ENOMEM;
diff --git a/Kernel/Net/NE2000NetworkAdapter.cpp b/Kernel/Net/NE2000NetworkAdapter.cpp
index 438d40867d..7695a3a88c 100644
--- a/Kernel/Net/NE2000NetworkAdapter.cpp
+++ b/Kernel/Net/NE2000NetworkAdapter.cpp
@@ -157,7 +157,7 @@ UNMAP_AFTER_INIT RefPtr<NE2000NetworkAdapter> NE2000NetworkAdapter::try_to_initi
if (!ne2k_ids.span().contains_slow(id))
return {};
u8 irq = PCI::get_interrupt_line(address);
- return adopt_ref_if_nonnull(new NE2000NetworkAdapter(address, irq));
+ return adopt_ref_if_nonnull(new (nothrow) NE2000NetworkAdapter(address, irq));
}
UNMAP_AFTER_INIT NE2000NetworkAdapter::NE2000NetworkAdapter(PCI::Address address, u8 irq)
diff --git a/Kernel/Net/NetworkAdapter.cpp b/Kernel/Net/NetworkAdapter.cpp
index b334cd9150..d752d67297 100644
--- a/Kernel/Net/NetworkAdapter.cpp
+++ b/Kernel/Net/NetworkAdapter.cpp
@@ -118,7 +118,7 @@ RefPtr<PacketWithTimestamp> NetworkAdapter::acquire_packet_buffer(size_t size)
InterruptDisabler disabler;
if (m_unused_packets.is_empty()) {
auto buffer = KBuffer::create_with_size(size, Region::Access::Read | Region::Access::Write, "Packet Buffer", AllocationStrategy::AllocateNow);
- auto packet = adopt_ref_if_nonnull(new PacketWithTimestamp { move(buffer), kgettimeofday() });
+ auto packet = adopt_ref_if_nonnull(new (nothrow) PacketWithTimestamp { move(buffer), kgettimeofday() });
if (!packet)
return nullptr;
packet->buffer.set_size(size);
@@ -133,7 +133,7 @@ RefPtr<PacketWithTimestamp> NetworkAdapter::acquire_packet_buffer(size_t size)
}
auto buffer = KBuffer::create_with_size(size, Region::Access::Read | Region::Access::Write, "Packet Buffer", AllocationStrategy::AllocateNow);
- packet = adopt_ref_if_nonnull(new PacketWithTimestamp { move(buffer), kgettimeofday() });
+ packet = adopt_ref_if_nonnull(new (nothrow) PacketWithTimestamp { move(buffer), kgettimeofday() });
if (!packet)
return nullptr;
packet->buffer.set_size(size);
diff --git a/Kernel/Net/RTL8139NetworkAdapter.cpp b/Kernel/Net/RTL8139NetworkAdapter.cpp
index 2a970ce12c..567948d1ab 100644
--- a/Kernel/Net/RTL8139NetworkAdapter.cpp
+++ b/Kernel/Net/RTL8139NetworkAdapter.cpp
@@ -113,7 +113,7 @@ UNMAP_AFTER_INIT RefPtr<RTL8139NetworkAdapter> RTL8139NetworkAdapter::try_to_ini
if (id != rtl8139_id)
return {};
u8 irq = PCI::get_interrupt_line(address);
- return adopt_ref_if_nonnull(new RTL8139NetworkAdapter(address, irq));
+ return adopt_ref_if_nonnull(new (nothrow) RTL8139NetworkAdapter(address, irq));
}
UNMAP_AFTER_INIT RTL8139NetworkAdapter::RTL8139NetworkAdapter(PCI::Address address, u8 irq)
diff --git a/Kernel/Net/RTL8168NetworkAdapter.cpp b/Kernel/Net/RTL8168NetworkAdapter.cpp
index 344e2935c3..6a31096d7a 100644
--- a/Kernel/Net/RTL8168NetworkAdapter.cpp
+++ b/Kernel/Net/RTL8168NetworkAdapter.cpp
@@ -184,7 +184,7 @@ UNMAP_AFTER_INIT RefPtr<RTL8168NetworkAdapter> RTL8168NetworkAdapter::try_to_ini
if (id.device_id != 0x8168)
return {};
u8 irq = PCI::get_interrupt_line(address);
- return adopt_ref_if_nonnull(new RTL8168NetworkAdapter(address, irq));
+ return adopt_ref_if_nonnull(new (nothrow) RTL8168NetworkAdapter(address, irq));
}
UNMAP_AFTER_INIT RTL8168NetworkAdapter::RTL8168NetworkAdapter(PCI::Address address, u8 irq)
diff --git a/Kernel/Net/TCPSocket.cpp b/Kernel/Net/TCPSocket.cpp
index cbf1af0f9f..5539b51573 100644
--- a/Kernel/Net/TCPSocket.cpp
+++ b/Kernel/Net/TCPSocket.cpp
@@ -149,7 +149,7 @@ TCPSocket::~TCPSocket()
KResultOr<NonnullRefPtr<TCPSocket>> TCPSocket::create(int protocol)
{
- auto socket = adopt_ref_if_nonnull(new TCPSocket(protocol));
+ auto socket = adopt_ref_if_nonnull(new (nothrow) TCPSocket(protocol));
if (socket)
return socket.release_nonnull();
return ENOMEM;
diff --git a/Kernel/Net/UDPSocket.cpp b/Kernel/Net/UDPSocket.cpp
index 7768875eee..a39ed22300 100644
--- a/Kernel/Net/UDPSocket.cpp
+++ b/Kernel/Net/UDPSocket.cpp
@@ -56,7 +56,7 @@ UDPSocket::~UDPSocket()
KResultOr<NonnullRefPtr<UDPSocket>> UDPSocket::create(int protocol)
{
- auto socket = adopt_ref_if_nonnull(new UDPSocket(protocol));
+ auto socket = adopt_ref_if_nonnull(new (nothrow) UDPSocket(protocol));
if (socket)
return socket.release_nonnull();
return ENOMEM;
diff --git a/Kernel/PerformanceEventBuffer.cpp b/Kernel/PerformanceEventBuffer.cpp
index 745b0f06f7..47f31f445e 100644
--- a/Kernel/PerformanceEventBuffer.cpp
+++ b/Kernel/PerformanceEventBuffer.cpp
@@ -257,7 +257,7 @@ OwnPtr<PerformanceEventBuffer> PerformanceEventBuffer::try_create_with_size(size
auto buffer = KBuffer::try_create_with_size(buffer_size, Region::Access::Read | Region::Access::Write, "Performance events", AllocationStrategy::AllocateNow);
if (!buffer)
return {};
- return adopt_own_if_nonnull(new PerformanceEventBuffer(buffer.release_nonnull()));
+ return adopt_own_if_nonnull(new (nothrow) PerformanceEventBuffer(buffer.release_nonnull()));
}
void PerformanceEventBuffer::add_process(const Process& process, ProcessEventType event_type)
diff --git a/Kernel/Process.cpp b/Kernel/Process.cpp
index e42c045757..ccf3adc075 100644
--- a/Kernel/Process.cpp
+++ b/Kernel/Process.cpp
@@ -213,7 +213,7 @@ void Process::unprotect_data()
RefPtr<Process> Process::create(RefPtr<Thread>& first_thread, const String& name, uid_t uid, gid_t gid, ProcessID ppid, bool is_kernel_process, RefPtr<Custody> cwd, RefPtr<Custody> executable, TTY* tty, Process* fork_parent)
{
- auto process = adopt_ref_if_nonnull(new Process(name, uid, gid, ppid, is_kernel_process, move(cwd), move(executable), tty));
+ auto process = adopt_ref_if_nonnull(new (nothrow) Process(name, uid, gid, ppid, is_kernel_process, move(cwd), move(executable), tty));
if (!process)
return {};
auto result = process->attach_resources(first_thread, fork_parent);
diff --git a/Kernel/ProcessGroup.cpp b/Kernel/ProcessGroup.cpp
index 85a08aa396..07472cd471 100644
--- a/Kernel/ProcessGroup.cpp
+++ b/Kernel/ProcessGroup.cpp
@@ -19,7 +19,7 @@ ProcessGroup::~ProcessGroup()
RefPtr<ProcessGroup> ProcessGroup::create(ProcessGroupID pgid)
{
- auto process_group = adopt_ref_if_nonnull(new ProcessGroup(pgid));
+ auto process_group = adopt_ref_if_nonnull(new (nothrow) ProcessGroup(pgid));
if (process_group) {
ScopedSpinLock lock(g_process_groups_lock);
g_process_groups->prepend(*process_group);
diff --git a/Kernel/Syscalls/alarm.cpp b/Kernel/Syscalls/alarm.cpp
index da30599508..0b8ce36440 100644
--- a/Kernel/Syscalls/alarm.cpp
+++ b/Kernel/Syscalls/alarm.cpp
@@ -28,7 +28,7 @@ KResultOr<unsigned> Process::sys$alarm(unsigned seconds)
auto deadline = TimeManagement::the().current_time(CLOCK_REALTIME_COARSE);
deadline = deadline + Time::from_seconds(seconds);
if (!m_alarm_timer) {
- m_alarm_timer = adopt_ref_if_nonnull(new Timer());
+ m_alarm_timer = adopt_ref_if_nonnull(new (nothrow) Timer());
if (!m_alarm_timer)
return ENOMEM;
}
diff --git a/Kernel/Syscalls/module.cpp b/Kernel/Syscalls/module.cpp
index 1ab7dd2ef0..9d267bd4ad 100644
--- a/Kernel/Syscalls/module.cpp
+++ b/Kernel/Syscalls/module.cpp
@@ -37,7 +37,7 @@ KResultOr<int> Process::sys$module_load(Userspace<const char*> user_path, size_t
auto storage = KBuffer::create_with_size(payload.size());
memcpy(storage.data(), payload.data(), payload.size());
- auto elf_image = adopt_own_if_nonnull(new ELF::Image(storage.data(), storage.size()));
+ auto elf_image = try_make<ELF::Image>(storage.data(), storage.size());
if (!elf_image)
return ENOMEM;
if (!elf_image->parse())
@@ -45,7 +45,7 @@ KResultOr<int> Process::sys$module_load(Userspace<const char*> user_path, size_t
HashMap<String, u8*> section_storage_by_name;
- auto module = adopt_own_if_nonnull(new Module());
+ auto module = try_make<Module>();
if (!module)
return ENOMEM;
diff --git a/Kernel/TTY/PTYMultiplexer.cpp b/Kernel/TTY/PTYMultiplexer.cpp
index 1005fad74c..c7a3718265 100644
--- a/Kernel/TTY/PTYMultiplexer.cpp
+++ b/Kernel/TTY/PTYMultiplexer.cpp
@@ -41,7 +41,7 @@ KResultOr<NonnullRefPtr<FileDescription>> PTYMultiplexer::open(int options)
if (m_freelist.is_empty())
return EBUSY;
auto master_index = m_freelist.take_last();
- auto master = adopt_ref_if_nonnull(new MasterPTY(master_index));
+ auto master = try_create<MasterPTY>(master_index);
if (!master)
return ENOMEM;
dbgln_if(PTMX_DEBUG, "PTYMultiplexer::open: Vending master {}", master->index());
diff --git a/Kernel/Thread.cpp b/Kernel/Thread.cpp
index 90f047c45f..b2cc469246 100644
--- a/Kernel/Thread.cpp
+++ b/Kernel/Thread.cpp
@@ -43,11 +43,11 @@ KResultOr<NonnullRefPtr<Thread>> Thread::try_create(NonnullRefPtr<Process> proce
return ENOMEM;
kernel_stack_region->set_stack(true);
- auto block_timer = adopt_ref_if_nonnull(new Timer());
+ auto block_timer = AK::try_create<Timer>();
if (!block_timer)
return ENOMEM;
- auto thread = adopt_ref_if_nonnull(new Thread(move(process), kernel_stack_region.release_nonnull(), block_timer.release_nonnull()));
+ auto thread = adopt_ref_if_nonnull(new (nothrow) Thread(move(process), kernel_stack_region.release_nonnull(), block_timer.release_nonnull()));
if (!thread)
return ENOMEM;
diff --git a/Kernel/ThreadTracer.h b/Kernel/ThreadTracer.h
index dad9a5f84c..5cc360ed07 100644
--- a/Kernel/ThreadTracer.h
+++ b/Kernel/ThreadTracer.h
@@ -15,7 +15,7 @@ namespace Kernel {
class ThreadTracer {
public:
- static OwnPtr<ThreadTracer> create(ProcessID tracer) { return adopt_own_if_nonnull(new ThreadTracer(tracer)); }
+ static OwnPtr<ThreadTracer> create(ProcessID tracer) { return try_make<ThreadTracer>(tracer); }
ProcessID tracer_pid() const { return m_tracer_pid; }
bool has_pending_signal(u32 signal) const { return m_pending_signals & (1 << (signal - 1)); }
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);