Jelajahi Sumber

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)`.
Daniel Bertalan 4 tahun lalu
induk
melakukan
f820917a76
45 mengubah file dengan 64 tambahan dan 68 penghapusan
  1. 1 1
      Kernel/ACPI/MultiProcessorParser.cpp
  2. 1 1
      Kernel/CoreDump.cpp
  3. 1 1
      Kernel/Devices/USB/USBDevice.cpp
  4. 1 1
      Kernel/Devices/USB/USBPipe.cpp
  5. 1 1
      Kernel/Devices/USB/USBTransfer.cpp
  6. 1 1
      Kernel/FileSystem/AnonymousFile.h
  7. 1 1
      Kernel/FileSystem/Custody.cpp
  8. 2 2
      Kernel/FileSystem/DevFS.cpp
  9. 1 1
      Kernel/FileSystem/Ext2FileSystem.cpp
  10. 2 2
      Kernel/FileSystem/FileDescription.cpp
  11. 1 1
      Kernel/FileSystem/InodeFile.h
  12. 1 1
      Kernel/FileSystem/InodeWatcher.cpp
  13. 1 1
      Kernel/FileSystem/InodeWatcher.h
  14. 1 1
      Kernel/FileSystem/Plan9FileSystem.cpp
  15. 3 3
      Kernel/FileSystem/ProcFS.cpp
  16. 2 2
      Kernel/FileSystem/TmpFS.cpp
  17. 4 4
      Kernel/KBuffer.h
  18. 1 1
      Kernel/KBufferBuilder.cpp
  19. 1 1
      Kernel/Net/E1000ENetworkAdapter.cpp
  20. 1 1
      Kernel/Net/E1000NetworkAdapter.cpp
  21. 1 1
      Kernel/Net/IPv4Socket.cpp
  22. 2 2
      Kernel/Net/LocalSocket.cpp
  23. 1 1
      Kernel/Net/NE2000NetworkAdapter.cpp
  24. 2 2
      Kernel/Net/NetworkAdapter.cpp
  25. 1 1
      Kernel/Net/RTL8139NetworkAdapter.cpp
  26. 1 1
      Kernel/Net/RTL8168NetworkAdapter.cpp
  27. 1 1
      Kernel/Net/TCPSocket.cpp
  28. 1 1
      Kernel/Net/UDPSocket.cpp
  29. 1 1
      Kernel/PerformanceEventBuffer.cpp
  30. 1 1
      Kernel/Process.cpp
  31. 1 1
      Kernel/ProcessGroup.cpp
  32. 1 1
      Kernel/Syscalls/alarm.cpp
  33. 2 2
      Kernel/Syscalls/module.cpp
  34. 1 1
      Kernel/TTY/PTYMultiplexer.cpp
  35. 2 2
      Kernel/Thread.cpp
  36. 1 1
      Kernel/ThreadTracer.h
  37. 6 6
      Kernel/VM/AnonymousVMObject.cpp
  38. 1 1
      Kernel/VM/ContiguousVMObject.cpp
  39. 2 2
      Kernel/VM/PrivateInodeVMObject.cpp
  40. 2 2
      Kernel/VM/Region.cpp
  41. 1 1
      Kernel/VM/ScatterGatherList.cpp
  42. 1 1
      Kernel/VM/Space.cpp
  43. 1 1
      Tests/AK/TestRefPtr.cpp
  44. 1 1
      Tests/AK/TestVariant.cpp
  45. 1 5
      Userland/Shell/AST.h

+ 1 - 1
Kernel/ACPI/MultiProcessorParser.cpp

@@ -22,7 +22,7 @@ UNMAP_AFTER_INIT OwnPtr<MultiProcessorParser> MultiProcessorParser::autodetect()
     auto floating_pointer = find_floating_pointer();
     auto floating_pointer = find_floating_pointer();
     if (!floating_pointer.has_value())
     if (!floating_pointer.has_value())
         return {};
         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);
     VERIFY(parser != nullptr);
     return parser;
     return parser;
 }
 }

+ 1 - 1
Kernel/CoreDump.cpp

@@ -32,7 +32,7 @@ OwnPtr<CoreDump> CoreDump::create(NonnullRefPtr<Process> process, const String&
     auto fd = create_target_file(process, output_path);
     auto fd = create_target_file(process, output_path);
     if (!fd)
     if (!fd)
         return {};
         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)
 CoreDump::CoreDump(NonnullRefPtr<Process> process, NonnullRefPtr<FileDescription>&& fd)

+ 1 - 1
Kernel/Devices/USB/USBDevice.cpp

@@ -22,7 +22,7 @@ KResultOr<NonnullRefPtr<Device>> Device::try_create(PortNumber port, DeviceSpeed
     if (pipe_or_error.is_error())
     if (pipe_or_error.is_error())
         return pipe_or_error.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)
     if (!device)
         return ENOMEM;
         return ENOMEM;
 
 

+ 1 - 1
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)
 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)
     if (!pipe)
         return ENOMEM;
         return ENOMEM;
 
 

+ 1 - 1
Kernel/Devices/USB/USBTransfer.cpp

@@ -15,7 +15,7 @@ RefPtr<Transfer> Transfer::try_create(Pipe& pipe, u16 len)
     if (!vmobject)
     if (!vmobject)
         return nullptr;
         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)
 Transfer::Transfer(Pipe& pipe, u16 len, ContiguousVMObject& vmobject)

+ 1 - 1
Kernel/FileSystem/AnonymousFile.h

@@ -14,7 +14,7 @@ class AnonymousFile final : public File {
 public:
 public:
     static RefPtr<AnonymousFile> create(NonnullRefPtr<AnonymousVMObject> vmobject)
     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;
     virtual ~AnonymousFile() override;

+ 1 - 1
Kernel/FileSystem/Custody.cpp

@@ -17,7 +17,7 @@ KResultOr<NonnullRefPtr<Custody>> Custody::try_create(Custody* parent, StringVie
     auto name_kstring = KString::try_create(name);
     auto name_kstring = KString::try_create(name);
     if (!name_kstring)
     if (!name_kstring)
         return ENOMEM;
         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)
     if (!custody)
         return ENOMEM;
         return ENOMEM;
     return custody.release_nonnull();
     return custody.release_nonnull();

+ 2 - 2
Kernel/FileSystem/DevFS.cpp

@@ -275,7 +275,7 @@ KResultOr<NonnullRefPtr<Inode>> DevFSRootDirectoryInode::create_child(const Stri
         }
         }
         if (name != "pts")
         if (name != "pts")
             return EROFS;
             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)
         if (!new_directory_inode)
             return ENOMEM;
             return ENOMEM;
         if (!m_subfolders.try_ensure_capacity(m_subfolders.size() + 1))
         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)
             if (link.name() == name)
                 return EEXIST;
                 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)
         if (!new_link_inode)
             return ENOMEM;
             return ENOMEM;
         if (!m_links.try_ensure_capacity(m_links.size() + 1))
         if (!m_links.try_ensure_capacity(m_links.size() + 1))

+ 1 - 1
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);
         dbgln("Ext2FS: Failed to load bitmap block {}", bitmap_block_index);
         return result;
         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)
     if (!new_bitmap)
         return ENOMEM;
         return ENOMEM;
     if (!m_cached_bitmaps.try_append(move(new_bitmap)))
     if (!m_cached_bitmaps.try_append(move(new_bitmap)))

+ 2 - 2
Kernel/FileSystem/FileDescription.cpp

@@ -30,7 +30,7 @@ KResultOr<NonnullRefPtr<FileDescription>> FileDescription::create(Custody& custo
     if (inode_file.is_error())
     if (inode_file.is_error())
         return inode_file.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)
     if (!description)
         return ENOMEM;
         return ENOMEM;
 
 
@@ -45,7 +45,7 @@ KResultOr<NonnullRefPtr<FileDescription>> FileDescription::create(Custody& custo
 
 
 KResultOr<NonnullRefPtr<FileDescription>> FileDescription::create(File& file)
 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)
     if (!description)
         return ENOMEM;
         return ENOMEM;
     auto result = description->attach();
     auto result = description->attach();

+ 1 - 1
Kernel/FileSystem/InodeFile.h

@@ -16,7 +16,7 @@ class InodeFile final : public File {
 public:
 public:
     static KResultOr<NonnullRefPtr<InodeFile>> create(NonnullRefPtr<Inode>&& inode)
     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)
         if (!file)
             return ENOMEM;
             return ENOMEM;
         return file.release_nonnull();
         return file.release_nonnull();

+ 1 - 1
Kernel/FileSystem/InodeWatcher.cpp

@@ -14,7 +14,7 @@ namespace Kernel {
 
 
 KResultOr<NonnullRefPtr<InodeWatcher>> InodeWatcher::create()
 KResultOr<NonnullRefPtr<InodeWatcher>> InodeWatcher::create()
 {
 {
-    auto watcher = adopt_ref_if_nonnull(new InodeWatcher);
+    auto watcher = adopt_ref_if_nonnull(new (nothrow) InodeWatcher);
     if (watcher)
     if (watcher)
         return watcher.release_nonnull();
         return watcher.release_nonnull();
     return ENOMEM;
     return ENOMEM;

+ 1 - 1
Kernel/FileSystem/InodeWatcher.h

@@ -27,7 +27,7 @@ struct WatchDescription {
 
 
     static KResultOr<NonnullOwnPtr<WatchDescription>> create(int wd, Inode& inode, unsigned event_mask)
     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)
         if (description)
             return description.release_nonnull();
             return description.release_nonnull();
         return ENOMEM;
         return ENOMEM;

+ 1 - 1
Kernel/FileSystem/Plan9FileSystem.cpp

@@ -576,7 +576,7 @@ KResult Plan9FS::read_and_dispatch_one_message()
         auto completion = optional_completion.value();
         auto completion = optional_completion.value();
         ScopedSpinLock lock(completion->lock);
         ScopedSpinLock lock(completion->lock);
         completion->result = KSuccess;
         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;
         completion->completed = true;
 
 
         m_completions.remove(header.tag);
         m_completions.remove(header.tag);

+ 3 - 3
Kernel/FileSystem/ProcFS.cpp

@@ -264,7 +264,7 @@ struct ProcFSInodeData : public FileDescriptionData {
 
 
 RefPtr<ProcFS> ProcFS::create()
 RefPtr<ProcFS> ProcFS::create()
 {
 {
-    return adopt_ref_if_nonnull(new ProcFS);
+    return adopt_ref_if_nonnull(new (nothrow) ProcFS);
 }
 }
 
 
 ProcFS::~ProcFS()
 ProcFS::~ProcFS()
@@ -1073,7 +1073,7 @@ RefPtr<Inode> ProcFS::get_inode(InodeIdentifier inode_id) const
             return adopt_ref_if_nonnull(it->value);
             return adopt_ref_if_nonnull(it->value);
         // We couldn't ref it, so just create a new one and replace the entry
         // 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)
     if (!inode)
         return {};
         return {};
     auto result = m_inodes.set(inode_id.index().value(), inode.ptr());
     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)
     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;
     auto& buffer = static_cast<ProcFSInodeData&>(*cached_data).buffer;
     if (buffer) {
     if (buffer) {
         // If we're reusing the buffer, reset the size to 0 first. This
         // If we're reusing the buffer, reset the size to 0 first. This

+ 2 - 2
Kernel/FileSystem/TmpFS.cpp

@@ -13,7 +13,7 @@ namespace Kernel {
 
 
 RefPtr<TmpFS> TmpFS::create()
 RefPtr<TmpFS> TmpFS::create()
 {
 {
-    return adopt_ref_if_nonnull(new TmpFS);
+    return adopt_ref_if_nonnull(new (nothrow) TmpFS);
 }
 }
 
 
 TmpFS::TmpFS()
 TmpFS::TmpFS()
@@ -86,7 +86,7 @@ TmpFSInode::~TmpFSInode()
 
 
 RefPtr<TmpFSInode> TmpFSInode::create(TmpFS& fs, InodeMetadata metadata, InodeIdentifier parent)
 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)
     if (inode)
         fs.register_inode(*inode);
         fs.register_inode(*inode);
     return inode;
     return inode;

+ 4 - 4
Kernel/KBuffer.h

@@ -32,7 +32,7 @@ public:
         auto region = MM.allocate_kernel_region(page_round_up(size), name, access, strategy);
         auto region = MM.allocate_kernel_region(page_round_up(size), name, access, strategy);
         if (!region)
         if (!region)
             return nullptr;
             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)
     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;
             return nullptr;
         memcpy(region->vaddr().as_ptr(), bytes.data(), bytes.size());
         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)
     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);
         auto impl = KBufferImpl::try_create_with_size(size, access, name, strategy);
         if (!impl)
         if (!impl)
             return {};
             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)
     [[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);
         auto impl = KBufferImpl::try_create_with_bytes(bytes, access, name, strategy);
         if (!impl)
         if (!impl)
             return {};
             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)
     [[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)

+ 1 - 1
Kernel/KBufferBuilder.cpp

@@ -39,7 +39,7 @@ OwnPtr<KBuffer> KBufferBuilder::build()
     if (!flush())
     if (!flush())
         return {};
         return {};
 
 
-    return adopt_own_if_nonnull(new KBuffer(move(m_buffer)));
+    return try_make<KBuffer>(move(m_buffer));
 }
 }
 
 
 KBufferBuilder::KBufferBuilder(bool can_expand)
 KBufferBuilder::KBufferBuilder(bool can_expand)

+ 1 - 1
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))
     if (!is_valid_device_id(id.device_id))
         return {};
         return {};
     u8 irq = PCI::get_interrupt_line(address);
     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)
     if (!adapter)
         return {};
         return {};
     if (adapter->initialize())
     if (adapter->initialize())

+ 1 - 1
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))
     if (!is_valid_device_id(id.device_id))
         return {};
         return {};
     u8 irq = PCI::get_interrupt_line(address);
     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)
     if (!adapter)
         return {};
         return {};
     if (adapter->initialize())
     if (adapter->initialize())

+ 1 - 1
Kernel/Net/IPv4Socket.cpp

@@ -50,7 +50,7 @@ KResultOr<NonnullRefPtr<Socket>> IPv4Socket::create(int type, int protocol)
         return udp_socket.release_value();
         return udp_socket.release_value();
     }
     }
     if (type == SOCK_RAW) {
     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)
         if (raw_socket)
             return raw_socket.release_nonnull();
             return raw_socket.release_nonnull();
         return ENOMEM;
         return ENOMEM;

+ 2 - 2
Kernel/Net/LocalSocket.cpp

@@ -33,7 +33,7 @@ void LocalSocket::for_each(Function<void(const LocalSocket&)> callback)
 
 
 KResultOr<NonnullRefPtr<Socket>> LocalSocket::create(int type)
 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)
     if (socket)
         return socket.release_nonnull();
         return socket.release_nonnull();
     return ENOMEM;
     return ENOMEM;
@@ -41,7 +41,7 @@ KResultOr<NonnullRefPtr<Socket>> LocalSocket::create(int type)
 
 
 KResultOr<SocketPair> LocalSocket::create_connected_pair(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)
     if (!socket)
         return ENOMEM;
         return ENOMEM;
 
 

+ 1 - 1
Kernel/Net/NE2000NetworkAdapter.cpp

@@ -157,7 +157,7 @@ UNMAP_AFTER_INIT RefPtr<NE2000NetworkAdapter> NE2000NetworkAdapter::try_to_initi
     if (!ne2k_ids.span().contains_slow(id))
     if (!ne2k_ids.span().contains_slow(id))
         return {};
         return {};
     u8 irq = PCI::get_interrupt_line(address);
     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)
 UNMAP_AFTER_INIT NE2000NetworkAdapter::NE2000NetworkAdapter(PCI::Address address, u8 irq)

+ 2 - 2
Kernel/Net/NetworkAdapter.cpp

@@ -118,7 +118,7 @@ RefPtr<PacketWithTimestamp> NetworkAdapter::acquire_packet_buffer(size_t size)
     InterruptDisabler disabler;
     InterruptDisabler disabler;
     if (m_unused_packets.is_empty()) {
     if (m_unused_packets.is_empty()) {
         auto buffer = KBuffer::create_with_size(size, Region::Access::Read | Region::Access::Write, "Packet Buffer", AllocationStrategy::AllocateNow);
         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)
         if (!packet)
             return nullptr;
             return nullptr;
         packet->buffer.set_size(size);
         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);
     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)
     if (!packet)
         return nullptr;
         return nullptr;
     packet->buffer.set_size(size);
     packet->buffer.set_size(size);

+ 1 - 1
Kernel/Net/RTL8139NetworkAdapter.cpp

@@ -113,7 +113,7 @@ UNMAP_AFTER_INIT RefPtr<RTL8139NetworkAdapter> RTL8139NetworkAdapter::try_to_ini
     if (id != rtl8139_id)
     if (id != rtl8139_id)
         return {};
         return {};
     u8 irq = PCI::get_interrupt_line(address);
     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)
 UNMAP_AFTER_INIT RTL8139NetworkAdapter::RTL8139NetworkAdapter(PCI::Address address, u8 irq)

+ 1 - 1
Kernel/Net/RTL8168NetworkAdapter.cpp

@@ -184,7 +184,7 @@ UNMAP_AFTER_INIT RefPtr<RTL8168NetworkAdapter> RTL8168NetworkAdapter::try_to_ini
     if (id.device_id != 0x8168)
     if (id.device_id != 0x8168)
         return {};
         return {};
     u8 irq = PCI::get_interrupt_line(address);
     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)
 UNMAP_AFTER_INIT RTL8168NetworkAdapter::RTL8168NetworkAdapter(PCI::Address address, u8 irq)

+ 1 - 1
Kernel/Net/TCPSocket.cpp

@@ -149,7 +149,7 @@ TCPSocket::~TCPSocket()
 
 
 KResultOr<NonnullRefPtr<TCPSocket>> TCPSocket::create(int protocol)
 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)
     if (socket)
         return socket.release_nonnull();
         return socket.release_nonnull();
     return ENOMEM;
     return ENOMEM;

+ 1 - 1
Kernel/Net/UDPSocket.cpp

@@ -56,7 +56,7 @@ UDPSocket::~UDPSocket()
 
 
 KResultOr<NonnullRefPtr<UDPSocket>> UDPSocket::create(int protocol)
 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)
     if (socket)
         return socket.release_nonnull();
         return socket.release_nonnull();
     return ENOMEM;
     return ENOMEM;

+ 1 - 1
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);
     auto buffer = KBuffer::try_create_with_size(buffer_size, Region::Access::Read | Region::Access::Write, "Performance events", AllocationStrategy::AllocateNow);
     if (!buffer)
     if (!buffer)
         return {};
         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)
 void PerformanceEventBuffer::add_process(const Process& process, ProcessEventType event_type)

+ 1 - 1
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)
 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)
     if (!process)
         return {};
         return {};
     auto result = process->attach_resources(first_thread, fork_parent);
     auto result = process->attach_resources(first_thread, fork_parent);

+ 1 - 1
Kernel/ProcessGroup.cpp

@@ -19,7 +19,7 @@ ProcessGroup::~ProcessGroup()
 
 
 RefPtr<ProcessGroup> ProcessGroup::create(ProcessGroupID pgid)
 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) {
     if (process_group) {
         ScopedSpinLock lock(g_process_groups_lock);
         ScopedSpinLock lock(g_process_groups_lock);
         g_process_groups->prepend(*process_group);
         g_process_groups->prepend(*process_group);

+ 1 - 1
Kernel/Syscalls/alarm.cpp

@@ -28,7 +28,7 @@ KResultOr<unsigned> Process::sys$alarm(unsigned seconds)
         auto deadline = TimeManagement::the().current_time(CLOCK_REALTIME_COARSE);
         auto deadline = TimeManagement::the().current_time(CLOCK_REALTIME_COARSE);
         deadline = deadline + Time::from_seconds(seconds);
         deadline = deadline + Time::from_seconds(seconds);
         if (!m_alarm_timer) {
         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)
             if (!m_alarm_timer)
                 return ENOMEM;
                 return ENOMEM;
         }
         }

+ 2 - 2
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());
     auto storage = KBuffer::create_with_size(payload.size());
     memcpy(storage.data(), payload.data(), 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)
     if (!elf_image)
         return ENOMEM;
         return ENOMEM;
     if (!elf_image->parse())
     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;
     HashMap<String, u8*> section_storage_by_name;
 
 
-    auto module = adopt_own_if_nonnull(new Module());
+    auto module = try_make<Module>();
     if (!module)
     if (!module)
         return ENOMEM;
         return ENOMEM;
 
 

+ 1 - 1
Kernel/TTY/PTYMultiplexer.cpp

@@ -41,7 +41,7 @@ KResultOr<NonnullRefPtr<FileDescription>> PTYMultiplexer::open(int options)
     if (m_freelist.is_empty())
     if (m_freelist.is_empty())
         return EBUSY;
         return EBUSY;
     auto master_index = m_freelist.take_last();
     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)
     if (!master)
         return ENOMEM;
         return ENOMEM;
     dbgln_if(PTMX_DEBUG, "PTYMultiplexer::open: Vending master {}", master->index());
     dbgln_if(PTMX_DEBUG, "PTYMultiplexer::open: Vending master {}", master->index());

+ 2 - 2
Kernel/Thread.cpp

@@ -43,11 +43,11 @@ KResultOr<NonnullRefPtr<Thread>> Thread::try_create(NonnullRefPtr<Process> proce
         return ENOMEM;
         return ENOMEM;
     kernel_stack_region->set_stack(true);
     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)
     if (!block_timer)
         return ENOMEM;
         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)
     if (!thread)
         return ENOMEM;
         return ENOMEM;
 
 

+ 1 - 1
Kernel/ThreadTracer.h

@@ -15,7 +15,7 @@ namespace Kernel {
 
 
 class ThreadTracer {
 class ThreadTracer {
 public:
 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; }
     ProcessID tracer_pid() const { return m_tracer_pid; }
     bool has_pending_signal(u32 signal) const { return m_pending_signals & (1 << (signal - 1)); }
     bool has_pending_signal(u32 signal) const { return m_pending_signals & (1 << (signal - 1)); }

+ 6 - 6
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 would keep the one it still has. This ensures that the original
     // one and this one, as well as the clone have sufficient resources
     // one and this one, as well as the clone have sufficient resources
     // to cow all pages as needed
     // 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) {
     if (!m_shared_committed_cow_pages) {
         MM.uncommit_user_physical_pages(need_cow_pages);
         MM.uncommit_user_physical_pages(need_cow_pages);
@@ -52,7 +52,7 @@ RefPtr<VMObject> AnonymousVMObject::clone()
     ensure_or_reset_cow_map();
     ensure_or_reset_cow_map();
 
 
     // FIXME: If this allocation fails, we need to rollback all changes.
     // 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)
 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))))
         if (!MM.commit_user_physical_pages(ceil_div(size, static_cast<size_t>(PAGE_SIZE))))
             return {};
             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)
 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)
 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)
 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);
         dbgln("Shenanigans! create_for_physical_range({}, {}) would wrap around", paddr, size);
         return nullptr;
         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)
 AnonymousVMObject::AnonymousVMObject(size_t size, AllocationStrategy strategy)

+ 1 - 1
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);
     auto contiguous_physical_pages = MM.allocate_contiguous_supervisor_physical_pages(size, physical_alignment);
     if (contiguous_physical_pages.is_empty())
     if (contiguous_physical_pages.is_empty())
         return {};
         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)
 ContiguousVMObject::ContiguousVMObject(size_t size, NonnullRefPtrVector<PhysicalPage>& contiguous_physical_pages)

+ 2 - 2
Kernel/VM/PrivateInodeVMObject.cpp

@@ -11,12 +11,12 @@ namespace Kernel {
 
 
 RefPtr<PrivateInodeVMObject> PrivateInodeVMObject::create_with_inode(Inode& inode)
 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()
 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)
 PrivateInodeVMObject::PrivateInodeVMObject(Inode& inode, size_t size)

+ 2 - 2
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)
 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)
     if (region && owner)
         region->m_owner = owner->make_weak_ptr();
         region->m_owner = owner->make_weak_ptr();
     // FIXME: Return OwnPtr and propagate failure, currently there are too many assumptions made by down stream callers.
     // 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)
 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
 bool Region::should_cow(size_t page_index) const

+ 1 - 1
Kernel/VM/ScatterGatherList.cpp

@@ -13,7 +13,7 @@ RefPtr<ScatterGatherList> ScatterGatherList::create(AsyncBlockDeviceRequest& req
     auto vm_object = AnonymousVMObject::create_with_physical_pages(allocated_pages);
     auto vm_object = AnonymousVMObject::create_with_physical_pages(allocated_pages);
     if (!vm_object)
     if (!vm_object)
         return {};
         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)
 ScatterGatherList::ScatterGatherList(NonnullRefPtr<AnonymousVMObject> vm_object, AsyncBlockDeviceRequest& request, size_t device_block_size)

+ 1 - 1
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);
     auto page_directory = PageDirectory::create_for_userspace(parent ? &parent->page_directory().range_allocator() : nullptr);
     if (!page_directory)
     if (!page_directory)
         return {};
         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)
     if (!space)
         return {};
         return {};
     space->page_directory().set_space({}, *space);
     space->page_directory().set_space({}, *space);

+ 1 - 1
Tests/AK/TestRefPtr.cpp

@@ -150,7 +150,7 @@ TEST_CASE(self_observers)
 
 
 TEST_CASE(adopt_ref_if_nonnull)
 TEST_CASE(adopt_ref_if_nonnull)
 {
 {
-    RefPtr<SelfAwareObject> object = adopt_ref_if_nonnull(new SelfAwareObject);
+    RefPtr<SelfAwareObject> object = adopt_ref_if_nonnull(new (nothrow) SelfAwareObject);
     EXPECT_EQ(object.is_null(), false);
     EXPECT_EQ(object.is_null(), false);
     EXPECT_EQ(object->ref_count(), 1u);
     EXPECT_EQ(object->ref_count(), 1u);
 
 

+ 1 - 1
Tests/AK/TestVariant.cpp

@@ -160,7 +160,7 @@ TEST_CASE(return_values)
 
 
 TEST_CASE(return_values_by_reference)
 TEST_CASE(return_values_by_reference)
 {
 {
-    auto ref = adopt_ref_if_nonnull(new Object());
+    auto ref = adopt_ref_if_nonnull(new (nothrow) Object());
     Variant<int, String, float> the_value { 42.0f };
     Variant<int, String, float> the_value { 42.0f };
 
 
     auto& value = the_value.visit(
     auto& value = the_value.visit(

+ 1 - 5
Userland/Shell/AST.h

@@ -20,11 +20,7 @@
 
 
 namespace Shell::AST {
 namespace Shell::AST {
 
 
-template<typename T, typename... Args>
-static inline NonnullRefPtr<T> create(Args... args)
-{
-    return adopt_ref(*new T(args...));
-}
+using AK::create;
 
 
 template<typename T>
 template<typename T>
 static inline NonnullRefPtr<T> create(std::initializer_list<NonnullRefPtr<Value>> arg)
 static inline NonnullRefPtr<T> create(std::initializer_list<NonnullRefPtr<Value>> arg)