summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Kernel/DoubleBuffer.cpp6
-rw-r--r--Kernel/DoubleBuffer.h2
-rw-r--r--Kernel/FileSystem/FIFO.cpp8
-rw-r--r--Kernel/Net/IPv4Socket.cpp12
-rw-r--r--Kernel/Net/IPv4Socket.h2
-rw-r--r--Kernel/Net/LocalSocket.cpp13
-rw-r--r--Kernel/Net/TCPSocket.cpp6
-rw-r--r--Kernel/TTY/MasterPTY.cpp6
8 files changed, 23 insertions, 32 deletions
diff --git a/Kernel/DoubleBuffer.cpp b/Kernel/DoubleBuffer.cpp
index 79f72eedc7..d8869135a0 100644
--- a/Kernel/DoubleBuffer.cpp
+++ b/Kernel/DoubleBuffer.cpp
@@ -17,13 +17,13 @@ inline void DoubleBuffer::compute_lockfree_metadata()
m_space_for_writing = m_capacity - m_write_buffer->size;
}
-OwnPtr<DoubleBuffer> DoubleBuffer::try_create(size_t capacity)
+KResultOr<NonnullOwnPtr<DoubleBuffer>> DoubleBuffer::try_create(size_t capacity)
{
auto storage = KBuffer::try_create_with_size(capacity * 2, Memory::Region::Access::ReadWrite, "DoubleBuffer");
if (!storage)
- return {};
+ return ENOMEM;
- return adopt_own_if_nonnull(new (nothrow) DoubleBuffer(capacity, storage.release_nonnull()));
+ return adopt_nonnull_own_or_enomem(new (nothrow) DoubleBuffer(capacity, storage.release_nonnull()));
}
DoubleBuffer::DoubleBuffer(size_t capacity, NonnullOwnPtr<KBuffer> storage)
diff --git a/Kernel/DoubleBuffer.h b/Kernel/DoubleBuffer.h
index 5e87b1afa3..c826f35fa4 100644
--- a/Kernel/DoubleBuffer.h
+++ b/Kernel/DoubleBuffer.h
@@ -16,7 +16,7 @@ namespace Kernel {
class DoubleBuffer {
public:
- [[nodiscard]] static OwnPtr<DoubleBuffer> try_create(size_t capacity = 65536);
+ static KResultOr<NonnullOwnPtr<DoubleBuffer>> try_create(size_t capacity = 65536);
KResultOr<size_t> write(const UserOrKernelBuffer&, size_t);
KResultOr<size_t> write(const u8* data, size_t size)
{
diff --git a/Kernel/FileSystem/FIFO.cpp b/Kernel/FileSystem/FIFO.cpp
index a9cfd1e7fa..42c76c33ab 100644
--- a/Kernel/FileSystem/FIFO.cpp
+++ b/Kernel/FileSystem/FIFO.cpp
@@ -18,10 +18,10 @@ static Atomic<int> s_next_fifo_id = 1;
RefPtr<FIFO> FIFO::try_create(UserID uid)
{
- auto buffer = DoubleBuffer::try_create();
- if (buffer)
- return adopt_ref_if_nonnull(new (nothrow) FIFO(uid, buffer.release_nonnull()));
- return {};
+ auto buffer_or_error = DoubleBuffer::try_create();
+ if (buffer_or_error.is_error())
+ return {};
+ return adopt_ref_if_nonnull(new (nothrow) FIFO(uid, buffer_or_error.release_value()));
}
KResultOr<NonnullRefPtr<OpenFileDescription>> FIFO::open_direction(FIFO::Direction direction)
diff --git a/Kernel/Net/IPv4Socket.cpp b/Kernel/Net/IPv4Socket.cpp
index 0a2ad95a26..88cdf95cc3 100644
--- a/Kernel/Net/IPv4Socket.cpp
+++ b/Kernel/Net/IPv4Socket.cpp
@@ -35,23 +35,21 @@ MutexProtected<IPv4Socket::List>& IPv4Socket::all_sockets()
return *s_all_sockets;
}
-OwnPtr<DoubleBuffer> IPv4Socket::create_receive_buffer()
+KResultOr<NonnullOwnPtr<DoubleBuffer>> IPv4Socket::try_create_receive_buffer()
{
return DoubleBuffer::try_create(256 * KiB);
}
KResultOr<NonnullRefPtr<Socket>> IPv4Socket::create(int type, int protocol)
{
- auto receive_buffer = IPv4Socket::create_receive_buffer();
- if (!receive_buffer)
- return ENOMEM;
+ auto receive_buffer = TRY(IPv4Socket::try_create_receive_buffer());
if (type == SOCK_STREAM)
- return TRY(TCPSocket::try_create(protocol, receive_buffer.release_nonnull()));
+ return TRY(TCPSocket::try_create(protocol, move(receive_buffer)));
if (type == SOCK_DGRAM)
- return TRY(UDPSocket::try_create(protocol, receive_buffer.release_nonnull()));
+ return TRY(UDPSocket::try_create(protocol, move(receive_buffer)));
if (type == SOCK_RAW) {
- auto raw_socket = adopt_ref_if_nonnull(new (nothrow) IPv4Socket(type, protocol, receive_buffer.release_nonnull(), {}));
+ auto raw_socket = adopt_ref_if_nonnull(new (nothrow) IPv4Socket(type, protocol, move(receive_buffer), {}));
if (raw_socket)
return raw_socket.release_nonnull();
return ENOMEM;
diff --git a/Kernel/Net/IPv4Socket.h b/Kernel/Net/IPv4Socket.h
index 4d6cbcc35b..3ec3521acc 100644
--- a/Kernel/Net/IPv4Socket.h
+++ b/Kernel/Net/IPv4Socket.h
@@ -90,7 +90,7 @@ protected:
void set_local_address(IPv4Address address) { m_local_address = address; }
void set_peer_address(IPv4Address address) { m_peer_address = address; }
- static OwnPtr<DoubleBuffer> create_receive_buffer();
+ static KResultOr<NonnullOwnPtr<DoubleBuffer>> try_create_receive_buffer();
private:
virtual bool is_ipv4() const override { return true; }
diff --git a/Kernel/Net/LocalSocket.cpp b/Kernel/Net/LocalSocket.cpp
index 43c59e0a46..9deaa786d2 100644
--- a/Kernel/Net/LocalSocket.cpp
+++ b/Kernel/Net/LocalSocket.cpp
@@ -36,16 +36,9 @@ void LocalSocket::for_each(Function<void(const LocalSocket&)> callback)
KResultOr<NonnullRefPtr<LocalSocket>> LocalSocket::try_create(int type)
{
- auto client_buffer = DoubleBuffer::try_create();
- if (!client_buffer)
- return ENOMEM;
- auto server_buffer = DoubleBuffer::try_create();
- if (!server_buffer)
- return ENOMEM;
- auto socket = adopt_ref_if_nonnull(new (nothrow) LocalSocket(type, client_buffer.release_nonnull(), server_buffer.release_nonnull()));
- if (socket)
- return socket.release_nonnull();
- return ENOMEM;
+ auto client_buffer = TRY(DoubleBuffer::try_create());
+ auto server_buffer = TRY(DoubleBuffer::try_create());
+ return adopt_nonnull_ref_or_enomem(new (nothrow) LocalSocket(type, move(client_buffer), move(server_buffer)));
}
KResultOr<SocketPair> LocalSocket::try_create_connected_pair(int type)
diff --git a/Kernel/Net/TCPSocket.cpp b/Kernel/Net/TCPSocket.cpp
index a3b8dd7ac0..22905a61c8 100644
--- a/Kernel/Net/TCPSocket.cpp
+++ b/Kernel/Net/TCPSocket.cpp
@@ -97,10 +97,10 @@ RefPtr<TCPSocket> TCPSocket::create_client(const IPv4Address& new_local_address,
if (table.contains(tuple))
return {};
- auto receive_buffer = create_receive_buffer();
- if (!receive_buffer)
+ auto receive_buffer = try_create_receive_buffer();
+ if (receive_buffer.is_error())
return {};
- auto client_or_error = TCPSocket::try_create(protocol(), receive_buffer.release_nonnull());
+ auto client_or_error = TCPSocket::try_create(protocol(), receive_buffer.release_value());
if (client_or_error.is_error())
return {};
diff --git a/Kernel/TTY/MasterPTY.cpp b/Kernel/TTY/MasterPTY.cpp
index cdf34f176f..d539cbc5f9 100644
--- a/Kernel/TTY/MasterPTY.cpp
+++ b/Kernel/TTY/MasterPTY.cpp
@@ -18,11 +18,11 @@ namespace Kernel {
RefPtr<MasterPTY> MasterPTY::try_create(unsigned int index)
{
- auto buffer = DoubleBuffer::try_create();
- if (!buffer)
+ auto buffer_or_error = DoubleBuffer::try_create();
+ if (buffer_or_error.is_error())
return {};
- auto master_pty = adopt_ref_if_nonnull(new (nothrow) MasterPTY(index, buffer.release_nonnull()));
+ auto master_pty = adopt_ref_if_nonnull(new (nothrow) MasterPTY(index, buffer_or_error.release_value()));
if (!master_pty)
return {};