diff --git a/Kernel/FileSystem/AnonymousFile.h b/Kernel/FileSystem/AnonymousFile.h index 792c161f2a1..3ec333ff5a1 100644 --- a/Kernel/FileSystem/AnonymousFile.h +++ b/Kernel/FileSystem/AnonymousFile.h @@ -13,9 +13,9 @@ namespace Kernel { class AnonymousFile final : public File { public: - static ErrorOr> try_create(NonnullLockRefPtr vmobject) + static ErrorOr> try_create(NonnullLockRefPtr vmobject) { - return adopt_nonnull_lock_ref_or_enomem(new (nothrow) AnonymousFile(move(vmobject))); + return adopt_nonnull_ref_or_enomem(new (nothrow) AnonymousFile(move(vmobject))); } virtual ~AnonymousFile() override; diff --git a/Kernel/FileSystem/FIFO.cpp b/Kernel/FileSystem/FIFO.cpp index c63ec3dac90..6036034990e 100644 --- a/Kernel/FileSystem/FIFO.cpp +++ b/Kernel/FileSystem/FIFO.cpp @@ -16,10 +16,10 @@ namespace Kernel { static Atomic s_next_fifo_id = 1; -ErrorOr> FIFO::try_create(UserID uid) +ErrorOr> FIFO::try_create(UserID uid) { auto buffer = TRY(DoubleBuffer::try_create("FIFO: Buffer"sv)); - return adopt_nonnull_lock_ref_or_enomem(new (nothrow) FIFO(uid, move(buffer))); + return adopt_nonnull_ref_or_enomem(new (nothrow) FIFO(uid, move(buffer))); } ErrorOr> FIFO::open_direction(FIFO::Direction direction) diff --git a/Kernel/FileSystem/FIFO.h b/Kernel/FileSystem/FIFO.h index d16975a625f..bce07e57936 100644 --- a/Kernel/FileSystem/FIFO.h +++ b/Kernel/FileSystem/FIFO.h @@ -24,7 +24,7 @@ public: Writer }; - static ErrorOr> try_create(UserID); + static ErrorOr> try_create(UserID); virtual ~FIFO() override; UserID uid() const { return m_uid; } diff --git a/Kernel/FileSystem/Inode.cpp b/Kernel/FileSystem/Inode.cpp index d0bb1ca1bf2..afe39597255 100644 --- a/Kernel/FileSystem/Inode.cpp +++ b/Kernel/FileSystem/Inode.cpp @@ -180,7 +180,7 @@ void Inode::unregister_watcher(Badge, InodeWatcher& watcher) }); } -ErrorOr> Inode::fifo() +ErrorOr> Inode::fifo() { MutexLocker locker(m_inode_lock); VERIFY(metadata().is_fifo()); @@ -189,7 +189,7 @@ ErrorOr> Inode::fifo() if (!m_fifo) m_fifo = TRY(FIFO::try_create(metadata().uid)); - return NonnullLockRefPtr { *m_fifo }; + return NonnullRefPtr { *m_fifo }; } void Inode::set_metadata_dirty(bool metadata_dirty) diff --git a/Kernel/FileSystem/Inode.h b/Kernel/FileSystem/Inode.h index dcf205513a1..b4cea6b440f 100644 --- a/Kernel/FileSystem/Inode.h +++ b/Kernel/FileSystem/Inode.h @@ -102,7 +102,7 @@ public: ErrorOr register_watcher(Badge, InodeWatcher&); void unregister_watcher(Badge, InodeWatcher&); - ErrorOr> fifo(); + ErrorOr> fifo(); bool can_apply_flock(flock const&, Optional = {}) const; ErrorOr apply_flock(Process const&, OpenFileDescription const&, Userspace, ShouldBlock); @@ -134,7 +134,7 @@ private: LockWeakPtr m_bound_socket; SpinlockProtected, LockRank::None> m_watchers {}; bool m_metadata_dirty { false }; - LockRefPtr m_fifo; + RefPtr m_fifo; IntrusiveListNode m_inode_list_node; struct Flock { diff --git a/Kernel/FileSystem/InodeFile.h b/Kernel/FileSystem/InodeFile.h index 7ee198eed30..9ece2206d44 100644 --- a/Kernel/FileSystem/InodeFile.h +++ b/Kernel/FileSystem/InodeFile.h @@ -14,9 +14,9 @@ class Inode; class InodeFile final : public File { public: - static ErrorOr> create(NonnullRefPtr inode) + static ErrorOr> create(NonnullRefPtr inode) { - auto file = adopt_lock_ref_if_nonnull(new (nothrow) 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 e30e2b4410e..8a62d4c95c3 100644 --- a/Kernel/FileSystem/InodeWatcher.cpp +++ b/Kernel/FileSystem/InodeWatcher.cpp @@ -11,9 +11,9 @@ namespace Kernel { -ErrorOr> InodeWatcher::try_create() +ErrorOr> InodeWatcher::try_create() { - return adopt_nonnull_lock_ref_or_enomem(new (nothrow) InodeWatcher); + return adopt_nonnull_ref_or_enomem(new (nothrow) InodeWatcher); } InodeWatcher::~InodeWatcher() diff --git a/Kernel/FileSystem/InodeWatcher.h b/Kernel/FileSystem/InodeWatcher.h index 2172d667a0d..fb01da67e4a 100644 --- a/Kernel/FileSystem/InodeWatcher.h +++ b/Kernel/FileSystem/InodeWatcher.h @@ -40,7 +40,7 @@ private: class InodeWatcher final : public File { public: - static ErrorOr> try_create(); + static ErrorOr> try_create(); virtual ~InodeWatcher() override; virtual bool can_read(OpenFileDescription const&, u64) const override; diff --git a/Kernel/FileSystem/OpenFileDescription.h b/Kernel/FileSystem/OpenFileDescription.h index 6f9004b68ce..056398143ba 100644 --- a/Kernel/FileSystem/OpenFileDescription.h +++ b/Kernel/FileSystem/OpenFileDescription.h @@ -141,7 +141,7 @@ private: } RefPtr m_inode; - NonnullLockRefPtr m_file; + NonnullRefPtr m_file; struct State { OwnPtr data; diff --git a/Kernel/Net/IPv4Socket.cpp b/Kernel/Net/IPv4Socket.cpp index c6dfeceb774..39318f75ff0 100644 --- a/Kernel/Net/IPv4Socket.cpp +++ b/Kernel/Net/IPv4Socket.cpp @@ -40,7 +40,7 @@ ErrorOr> IPv4Socket::try_create_receive_buffer() return DoubleBuffer::try_create("IPv4Socket: Receive buffer"sv, 256 * KiB); } -ErrorOr> IPv4Socket::create(int type, int protocol) +ErrorOr> IPv4Socket::create(int type, int protocol) { auto receive_buffer = TRY(IPv4Socket::try_create_receive_buffer()); @@ -49,7 +49,7 @@ ErrorOr> IPv4Socket::create(int type, int protocol) if (type == SOCK_DGRAM) return TRY(UDPSocket::try_create(protocol, move(receive_buffer))); if (type == SOCK_RAW) { - auto raw_socket = adopt_lock_ref_if_nonnull(new (nothrow) IPv4Socket(type, protocol, move(receive_buffer), {})); + 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 74169b5d8af..3cc5d360e77 100644 --- a/Kernel/Net/IPv4Socket.h +++ b/Kernel/Net/IPv4Socket.h @@ -28,7 +28,7 @@ struct PortAllocationResult { class IPv4Socket : public Socket { public: - static ErrorOr> create(int type, int protocol); + static ErrorOr> create(int type, int protocol); virtual ~IPv4Socket() override; virtual ErrorOr close() override; diff --git a/Kernel/Net/LocalSocket.cpp b/Kernel/Net/LocalSocket.cpp index 6b88b10d35a..f5963e8be24 100644 --- a/Kernel/Net/LocalSocket.cpp +++ b/Kernel/Net/LocalSocket.cpp @@ -43,11 +43,11 @@ ErrorOr LocalSocket::try_for_each(Function(LocalSocket const }); } -ErrorOr> LocalSocket::try_create(int type) +ErrorOr> LocalSocket::try_create(int type) { auto client_buffer = TRY(DoubleBuffer::try_create("LocalSocket: Client buffer"sv)); auto server_buffer = TRY(DoubleBuffer::try_create("LocalSocket: Server buffer"sv)); - return adopt_nonnull_lock_ref_or_enomem(new (nothrow) LocalSocket(type, move(client_buffer), move(server_buffer))); + return adopt_nonnull_ref_or_enomem(new (nothrow) LocalSocket(type, move(client_buffer), move(server_buffer))); } ErrorOr LocalSocket::try_create_connected_pair(int type) diff --git a/Kernel/Net/LocalSocket.h b/Kernel/Net/LocalSocket.h index 5668b30f255..25d17161220 100644 --- a/Kernel/Net/LocalSocket.h +++ b/Kernel/Net/LocalSocket.h @@ -22,7 +22,7 @@ struct SocketPair { class LocalSocket final : public Socket { public: - static ErrorOr> try_create(int type); + static ErrorOr> try_create(int type); static ErrorOr try_create_connected_pair(int type); virtual ~LocalSocket() override; diff --git a/Kernel/Net/NetworkTask.cpp b/Kernel/Net/NetworkTask.cpp index 5b90d4ad335..cb7586b7a50 100644 --- a/Kernel/Net/NetworkTask.cpp +++ b/Kernel/Net/NetworkTask.cpp @@ -30,13 +30,13 @@ static void handle_ipv4(EthernetFrameHeader const&, size_t frame_size, Time cons static void handle_icmp(EthernetFrameHeader const&, IPv4Packet const&, Time const& packet_timestamp); static void handle_udp(IPv4Packet const&, Time const& packet_timestamp); static void handle_tcp(IPv4Packet const&, Time const& packet_timestamp); -static void send_delayed_tcp_ack(LockRefPtr socket); +static void send_delayed_tcp_ack(TCPSocket& socket); static void send_tcp_rst(IPv4Packet const& ipv4_packet, TCPPacket const& tcp_packet, LockRefPtr adapter); static void flush_delayed_tcp_acks(); static void retransmit_tcp_packets(); static Thread* network_task = nullptr; -static HashTable>* delayed_ack_sockets; +static HashTable>* delayed_ack_sockets; [[noreturn]] static void NetworkTask_main(void*); @@ -57,7 +57,7 @@ bool NetworkTask::is_current() void NetworkTask_main(void*) { - delayed_ack_sockets = new HashTable>; + delayed_ack_sockets = new HashTable>; WaitQueue packet_wait_queue; int pending_packets = 0; @@ -229,7 +229,7 @@ void handle_icmp(EthernetFrameHeader const& eth, IPv4Packet const& ipv4_packet, dbgln_if(ICMP_DEBUG, "handle_icmp: source={}, destination={}, type={:#02x}, code={:#02x}", ipv4_packet.source().to_string(), ipv4_packet.destination().to_string(), icmp_header.type(), icmp_header.code()); { - Vector> icmp_sockets; + Vector> icmp_sockets; IPv4Socket::all_sockets().with_exclusive([&](auto& sockets) { for (auto& socket : sockets) { if (socket.protocol() == (unsigned)IPv4Protocol::ICMP) @@ -302,11 +302,11 @@ void handle_udp(IPv4Packet const& ipv4_packet, Time const& packet_timestamp) socket->did_receive(ipv4_packet.source(), udp_packet.source_port(), { &ipv4_packet, sizeof(IPv4Packet) + ipv4_packet.payload_size() }, packet_timestamp); } -void send_delayed_tcp_ack(LockRefPtr socket) +void send_delayed_tcp_ack(TCPSocket& socket) { - VERIFY(socket->mutex().is_locked()); - if (!socket->should_delay_next_ack()) { - [[maybe_unused]] auto result = socket->send_ack(); + VERIFY(socket.mutex().is_locked()); + if (!socket.should_delay_next_ack()) { + [[maybe_unused]] auto result = socket.send_ack(); return; } @@ -315,11 +315,11 @@ void send_delayed_tcp_ack(LockRefPtr socket) void flush_delayed_tcp_acks() { - Vector, 32> remaining_sockets; + Vector, 32> remaining_sockets; for (auto& socket : *delayed_ack_sockets) { MutexLocker locker(socket->mutex()); if (socket->should_delay_next_ack()) { - MUST(remaining_sockets.try_append(socket)); + MUST(remaining_sockets.try_append(*socket)); continue; } [[maybe_unused]] auto result = socket->send_ack(); @@ -484,7 +484,7 @@ void handle_tcp(IPv4Packet const& ipv4_packet, Time const& packet_timestamp) return; case TCPFlags::ACK | TCPFlags::FIN: socket->set_ack_number(tcp_packet.sequence_number() + payload_size + 1); - send_delayed_tcp_ack(socket); + send_delayed_tcp_ack(*socket); socket->set_state(TCPSocket::State::Closed); socket->set_error(TCPSocket::Error::FINDuringConnect); socket->set_setup_state(Socket::SetupState::Completed); @@ -636,7 +636,7 @@ void handle_tcp(IPv4Packet const& ipv4_packet, Time const& packet_timestamp) socket->did_receive(ipv4_packet.source(), tcp_packet.source_port(), { &ipv4_packet, sizeof(IPv4Packet) + ipv4_packet.payload_size() }, packet_timestamp); socket->set_ack_number(tcp_packet.sequence_number() + payload_size + 1); - send_delayed_tcp_ack(socket); + send_delayed_tcp_ack(*socket); socket->set_state(TCPSocket::State::CloseWait); socket->set_connected(false); return; @@ -647,7 +647,7 @@ void handle_tcp(IPv4Packet const& ipv4_packet, Time const& packet_timestamp) socket->set_ack_number(tcp_packet.sequence_number() + payload_size); dbgln_if(TCP_DEBUG, "Got packet with ack_no={}, seq_no={}, payload_size={}, acking it with new ack_no={}, seq_no={}", tcp_packet.ack_number(), tcp_packet.sequence_number(), payload_size, socket->ack_number(), socket->sequence_number()); - send_delayed_tcp_ack(socket); + send_delayed_tcp_ack(*socket); } } } @@ -657,7 +657,7 @@ void retransmit_tcp_packets() { // We must keep the sockets alive until after we've unlocked the hash table // in case retransmit_packets() realizes that it wants to close the socket. - Vector, 16> sockets; + Vector, 16> sockets; TCPSocket::sockets_for_retransmit().for_each_shared([&](auto const& socket) { // We ignore allocation failures above the first 16 guaranteed socket slots, as // we will just retransmit their packets the next time around diff --git a/Kernel/Net/Socket.cpp b/Kernel/Net/Socket.cpp index 961534ba583..9ae1585b942 100644 --- a/Kernel/Net/Socket.cpp +++ b/Kernel/Net/Socket.cpp @@ -17,7 +17,7 @@ namespace Kernel { -ErrorOr> Socket::create(int domain, int type, int protocol) +ErrorOr> Socket::create(int domain, int type, int protocol) { switch (domain) { case AF_LOCAL: @@ -46,7 +46,7 @@ void Socket::set_setup_state(SetupState new_setup_state) evaluate_block_conditions(); } -LockRefPtr Socket::accept() +RefPtr Socket::accept() { MutexLocker locker(mutex()); if (m_pending.is_empty()) @@ -63,7 +63,7 @@ LockRefPtr Socket::accept() return client; } -ErrorOr Socket::queue_connection_from(NonnullLockRefPtr peer) +ErrorOr Socket::queue_connection_from(NonnullRefPtr peer) { dbgln_if(SOCKET_DEBUG, "Socket({}) queueing connection", this); MutexLocker locker(mutex()); diff --git a/Kernel/Net/Socket.h b/Kernel/Net/Socket.h index 04fe6efd86f..746274e0ffd 100644 --- a/Kernel/Net/Socket.h +++ b/Kernel/Net/Socket.h @@ -20,7 +20,7 @@ class OpenFileDescription; class Socket : public File { public: - static ErrorOr> create(int domain, int type, int protocol); + static ErrorOr> create(int domain, int type, int protocol); virtual ~Socket() override; int domain() const { return m_domain; } @@ -67,7 +67,7 @@ public: void set_connected(bool); bool can_accept() const { return !m_pending.is_empty(); } - LockRefPtr accept(); + RefPtr accept(); ErrorOr shutdown(int how); @@ -111,7 +111,7 @@ public: protected: Socket(int domain, int type, int protocol); - ErrorOr queue_connection_from(NonnullLockRefPtr); + ErrorOr queue_connection_from(NonnullRefPtr); size_t backlog() const { return m_backlog; } void set_backlog(size_t backlog) { m_backlog = backlog; } @@ -181,7 +181,7 @@ private: Optional m_so_error; - Vector> m_pending; + Vector> m_pending; }; // This is a special variant of TRY() that also updates the socket's SO_ERROR field on error. diff --git a/Kernel/Net/TCPSocket.cpp b/Kernel/Net/TCPSocket.cpp index b053d61bd45..f238c47a7dc 100644 --- a/Kernel/Net/TCPSocket.cpp +++ b/Kernel/Net/TCPSocket.cpp @@ -88,9 +88,9 @@ void TCPSocket::set_state(State new_state) evaluate_block_conditions(); } -static Singleton>>> s_socket_closing; +static Singleton>>> s_socket_closing; -MutexProtected>>& TCPSocket::closing_sockets() +MutexProtected>>& TCPSocket::closing_sockets() { return *s_socket_closing; } @@ -102,9 +102,9 @@ MutexProtected>& TCPSocket::sockets_by_tupl return *s_socket_tuples; } -LockRefPtr TCPSocket::from_tuple(IPv4SocketTuple const& tuple) +RefPtr TCPSocket::from_tuple(IPv4SocketTuple const& tuple) { - return sockets_by_tuple().with_shared([&](auto const& table) -> LockRefPtr { + return sockets_by_tuple().with_shared([&](auto const& table) -> RefPtr { auto exact_match = table.get(tuple); if (exact_match.has_value()) return { *exact_match.value() }; @@ -122,10 +122,10 @@ LockRefPtr TCPSocket::from_tuple(IPv4SocketTuple const& tuple) return {}; }); } -ErrorOr> TCPSocket::try_create_client(IPv4Address const& new_local_address, u16 new_local_port, IPv4Address const& new_peer_address, u16 new_peer_port) +ErrorOr> TCPSocket::try_create_client(IPv4Address const& new_local_address, u16 new_local_port, IPv4Address const& new_peer_address, u16 new_peer_port) { auto tuple = IPv4SocketTuple(new_local_address, new_local_port, new_peer_address, new_peer_port); - return sockets_by_tuple().with_exclusive([&](auto& table) -> ErrorOr> { + return sockets_by_tuple().with_exclusive([&](auto& table) -> ErrorOr> { if (table.contains(tuple)) return EEXIST; @@ -154,7 +154,7 @@ void TCPSocket::release_to_originator() m_originator.clear(); } -void TCPSocket::release_for_accept(NonnullLockRefPtr socket) +void TCPSocket::release_for_accept(NonnullRefPtr socket) { VERIFY(m_pending_release_for_accept.contains(socket->tuple())); m_pending_release_for_accept.remove(socket->tuple()); @@ -175,11 +175,11 @@ TCPSocket::~TCPSocket() dbgln_if(TCP_SOCKET_DEBUG, "~TCPSocket in state {}", to_string(state())); } -ErrorOr> TCPSocket::try_create(int protocol, NonnullOwnPtr receive_buffer) +ErrorOr> TCPSocket::try_create(int protocol, NonnullOwnPtr receive_buffer) { // Note: Scratch buffer is only used for SOCK_STREAM sockets. auto scratch_buffer = TRY(KBuffer::try_create_with_size("TCPSocket: Scratch buffer"sv, 65536)); - return adopt_nonnull_lock_ref_or_enomem(new (nothrow) TCPSocket(protocol, move(receive_buffer), move(scratch_buffer))); + return adopt_nonnull_ref_or_enomem(new (nothrow) TCPSocket(protocol, move(receive_buffer), move(scratch_buffer))); } ErrorOr TCPSocket::protocol_size(ReadonlyBytes raw_ipv4_packet) diff --git a/Kernel/Net/TCPSocket.h b/Kernel/Net/TCPSocket.h index b27e09cb2b5..ae73102832c 100644 --- a/Kernel/Net/TCPSocket.h +++ b/Kernel/Net/TCPSocket.h @@ -20,7 +20,7 @@ class TCPSocket final : public IPv4Socket { public: static void for_each(Function); static ErrorOr try_for_each(Function(TCPSocket const&)>); - static ErrorOr> try_create(int protocol, NonnullOwnPtr receive_buffer); + static ErrorOr> try_create(int protocol, NonnullOwnPtr receive_buffer); virtual ~TCPSocket() override; virtual bool unref() const override; @@ -146,15 +146,15 @@ public: bool should_delay_next_ack() const; static MutexProtected>& sockets_by_tuple(); - static LockRefPtr from_tuple(IPv4SocketTuple const& tuple); + static RefPtr from_tuple(IPv4SocketTuple const& tuple); - static MutexProtected>>& closing_sockets(); + static MutexProtected>>& closing_sockets(); - ErrorOr> try_create_client(IPv4Address const& local_address, u16 local_port, IPv4Address const& peer_address, u16 peer_port); + ErrorOr> try_create_client(IPv4Address const& local_address, u16 local_port, IPv4Address const& peer_address, u16 peer_port); void set_originator(TCPSocket& originator) { m_originator = originator; } bool has_originator() { return !!m_originator; } void release_to_originator(); - void release_for_accept(NonnullLockRefPtr); + void release_for_accept(NonnullRefPtr); void retransmit_packets(); @@ -186,7 +186,7 @@ private: void dequeue_for_retransmit(); LockWeakPtr m_originator; - HashMap> m_pending_release_for_accept; + HashMap> m_pending_release_for_accept; Direction m_direction { Direction::Unspecified }; Error m_error { Error::None }; LockRefPtr m_adapter; diff --git a/Kernel/Net/UDPSocket.cpp b/Kernel/Net/UDPSocket.cpp index a109414568b..88fc3388e26 100644 --- a/Kernel/Net/UDPSocket.cpp +++ b/Kernel/Net/UDPSocket.cpp @@ -38,9 +38,9 @@ MutexProtected>& UDPSocket::sockets_by_port() return *s_map; } -LockRefPtr UDPSocket::from_port(u16 port) +RefPtr UDPSocket::from_port(u16 port) { - return sockets_by_port().with_shared([&](auto const& table) -> LockRefPtr { + return sockets_by_port().with_shared([&](auto const& table) -> RefPtr { auto it = table.find(port); if (it == table.end()) return {}; @@ -60,9 +60,9 @@ UDPSocket::~UDPSocket() }); } -ErrorOr> UDPSocket::try_create(int protocol, NonnullOwnPtr receive_buffer) +ErrorOr> UDPSocket::try_create(int protocol, NonnullOwnPtr receive_buffer) { - return adopt_nonnull_lock_ref_or_enomem(new (nothrow) UDPSocket(protocol, move(receive_buffer))); + return adopt_nonnull_ref_or_enomem(new (nothrow) UDPSocket(protocol, move(receive_buffer))); } ErrorOr UDPSocket::protocol_size(ReadonlyBytes raw_ipv4_packet) diff --git a/Kernel/Net/UDPSocket.h b/Kernel/Net/UDPSocket.h index 3cdb9f60eab..d904f97e247 100644 --- a/Kernel/Net/UDPSocket.h +++ b/Kernel/Net/UDPSocket.h @@ -14,10 +14,10 @@ namespace Kernel { class UDPSocket final : public IPv4Socket { public: - static ErrorOr> try_create(int protocol, NonnullOwnPtr receive_buffer); + static ErrorOr> try_create(int protocol, NonnullOwnPtr receive_buffer); virtual ~UDPSocket() override; - static LockRefPtr from_port(u16); + static RefPtr from_port(u16); static void for_each(Function); static ErrorOr try_for_each(Function(UDPSocket const&)>);