diff options
author | Liav A <liavalb@gmail.com> | 2023-04-11 03:50:15 +0300 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2023-04-14 19:27:56 +0200 |
commit | 7c1f645e27038eb12e2e46ea0103cc04c96edbb8 (patch) | |
tree | 4624c34cec0b0477dd0cf4fc9181163e17373d19 /Kernel/Net/NetworkingManagement.h | |
parent | bd7d4513bfcc250c472c84365649f522b074816f (diff) | |
download | serenity-7c1f645e27038eb12e2e46ea0103cc04c96edbb8.zip |
Kernel/Net: Iron out the locking mechanism across the subsystem
There is a big mix of LockRefPtrs all over the Networking subsystem, as
well as lots of room for improvements with our locking patterns, which
this commit will not pursue, but will give a good start for such work.
To deal with this situation, we change the following things:
- Creating instances of NetworkAdapter should always yield a non-locking
NonnullRefPtr. Acquiring an instance from the NetworkingManagement
should give a simple RefPtr,as giving LockRefPtr does not really
protect from concurrency problems in such case.
- Since NetworkingManagement works with normal RefPtrs we should
protect all instances of RefPtr<NetworkAdapter> with SpinlockProtected
to ensure references are gone unexpectedly.
- Protect the so_error class member with a proper spinlock. This happens
to be important because the clear_so_error() method lacked any proper
locking measures. It also helps preventing a possible TOCTOU when we
might do a more fine-grained locking in the Socket code, so this could
be definitely a start for this.
- Change unnecessary LockRefPtr<PacketWithTimestamp> in the structure
of OutgoingPacket to a simple RefPtr<PacketWithTimestamp> as the whole
list should be MutexProtected.
Diffstat (limited to 'Kernel/Net/NetworkingManagement.h')
-rw-r--r-- | Kernel/Net/NetworkingManagement.h | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/Kernel/Net/NetworkingManagement.h b/Kernel/Net/NetworkingManagement.h index 587773030a..ad18a7513e 100644 --- a/Kernel/Net/NetworkingManagement.h +++ b/Kernel/Net/NetworkingManagement.h @@ -8,9 +8,9 @@ #include <AK/Function.h> #include <AK/NonnullOwnPtr.h> +#include <AK/RefPtr.h> #include <AK/Types.h> #include <Kernel/Bus/PCI/Definitions.h> -#include <Kernel/Library/NonnullLockRefPtr.h> #include <Kernel/Locking/SpinlockProtected.h> #include <Kernel/Memory/Region.h> #include <Kernel/Net/NetworkAdapter.h> @@ -33,16 +33,16 @@ public: void for_each(Function<void(NetworkAdapter&)>); ErrorOr<void> try_for_each(Function<ErrorOr<void>(NetworkAdapter&)>); - LockRefPtr<NetworkAdapter> from_ipv4_address(IPv4Address const&) const; - LockRefPtr<NetworkAdapter> lookup_by_name(StringView) const; + RefPtr<NetworkAdapter> from_ipv4_address(IPv4Address const&) const; + RefPtr<NetworkAdapter> lookup_by_name(StringView) const; - NonnullLockRefPtr<NetworkAdapter> loopback_adapter() const; + NonnullRefPtr<NetworkAdapter> loopback_adapter() const; private: ErrorOr<NonnullRefPtr<NetworkAdapter>> determine_network_device(PCI::DeviceIdentifier const&) const; - SpinlockProtected<Vector<NonnullLockRefPtr<NetworkAdapter>>, LockRank::None> m_adapters {}; - LockRefPtr<NetworkAdapter> m_loopback_adapter; + SpinlockProtected<Vector<NonnullRefPtr<NetworkAdapter>>, LockRank::None> m_adapters {}; + RefPtr<NetworkAdapter> m_loopback_adapter; }; } |