summaryrefslogtreecommitdiff
path: root/Kernel/Net/LocalSocket.cpp
AgeCommit message (Collapse)Author
2021-10-08Kernel: Fix -Wunreachable-code warnings from clangNico Weber
2021-09-16Kernel: Weakly hold on to the file in LocalSocketsin-ack
Because we were holding a strong ref to the OpenFileDescription in LocalSocket and a strong ref to the LocalSocket in Inode, we were creating a reference cycle in the event of the socket being cleaned up after the file description did (i.e. unlinking the file before closing the socket), because the file description never got destructed.
2021-09-15Kernel: Use move semantics in sys$sendfd()Andreas Kling
Avoid an unnecessary NonnullRefPtr<OpenFileDescription> copy.
2021-09-07Kernel/Net: Add a special SOCKET_TRY() and use it in socket codeAndreas Kling
Sockets remember their last error code in the SO_ERROR field, so we need to take special care to remember this when returning an error. This patch adds a SOCKET_TRY() that works like TRY() but also calls set_so_error() on the failure path. There's probably a lot more code that should be using this, but that's outside the scope of this patch.
2021-09-07Kernel: Make DoubleBuffer::try() return KResultOrAndreas Kling
This tidies up error propagation in a number of places.
2021-09-07Kernel: Rename FileDescription => OpenFileDescriptionAndreas Kling
Dr. POSIX really calls these "open file description", not just "file description", so let's call them exactly that. :^)
2021-09-06Kernel: Use TRY() once more in LocalSocket::try_create_connected_pair()Andreas Kling
2021-09-06Kernel: Make KString factories return KResultOr + use TRY() everywhereAndreas Kling
There are a number of places that don't have an error propagation path right now, so I've added FIXME's about that.
2021-09-05Kernel: Make copy_{from,to}_user() return KResult and use TRY()Andreas Kling
This makes EFAULT propagation flow much more naturally. :^)
2021-09-05Kernel: Use TRY() in LocalSocketAndreas Kling
2021-08-31Kernel: Don't VERIFY_NOT_REACHED in LocalSocket::has_attached_peer()Owen Smith
Invoking sendmsg on a listening socket triggers this assertion as sendto calls has_attached_peer before checking the result of send_buffer_for.
2021-08-29Kernel: Rename Socket::lock() => Socket::mutex()Andreas Kling
"lock" is ambiguous (verb vs noun) while "mutex" is not.
2021-08-29Kernel: Add Socket::set_role() and use it everywhereAndreas Kling
Instead of having Socket subclasses write their role into Socket::m_role directly, add a setter to do this.
2021-08-29Kernel: Store LocalSocket address as a KString internallyAndreas Kling
Just because we deal with sockaddr_un at the userspace API layer doesn't mean we have to store an awkward C type internally. :^)
2021-08-29Kernel: Rename LocalSocket::create_connected_pair() => try_*()Andreas Kling
2021-08-29Kernel: Encapsulate assignment of socket origin/acceptor credentialsAndreas Kling
2021-08-29Kernel: Rename LocalSocket factory to try_create() & tighten return typeAndreas Kling
Also tighten the return type to KResultOr<NonnullRefPtr<LocalSocket>> since it cannot return any other socket type.
2021-08-29Kernel: Strongly typed user & group ID'sAndreas Kling
Prior to this change, both uid_t and gid_t were typedef'ed to `u32`. This made it easy to use them interchangeably. Let's not allow that. This patch adds UserID and GroupID using the AK::DistinctNumeric mechanism we've already been employing for pid_t/ProcessID.
2021-08-29Kernel: Rename FileDescription::create() => try_create()Andreas Kling
2021-08-22Kernel: Return ENOTSUP instead of panicking on invalid sockoptPeter Elliott
X11 handles this gracefully, and it makes more sense than panicking.
2021-08-22Kernel+LibC: Implement FIONREAD ioctlPeter Elliott
FIONREAD gets the number of bytes availible to read from a file descriptor without blocking. I only implemented it for regular files and sockets
2021-08-22Kernel: Rename ProtectedValue<T> => MutexProtected<T>Andreas Kling
Let's make it obvious what we're protecting it with.
2021-08-19Kernel: Make Process::current() return a Process& instead of Process*Idan Horowitz
This has several benefits: 1) We no longer just blindly derefence a null pointer in various places 2) We will get nicer runtime error messages if the current process does turn out to be null in the call location 3) GCC no longer complains about possible nullptr dereferences when compiling without KUBSAN
2021-08-14Kernel: Stop allowing implicit conversion from KResult to intAndreas Kling
This patch removes KResult::operator int() and deals with the fallout. This forces a lot of code to be more explicit in its handling of errors, greatly improving readability.
2021-08-10Kernel: Properly implement SO_ERROR optionbrapru
This fixes the placeholder stub for the SO_ERROR via getsockopt. It leverages the m_so_error value that each socket maintains. The SO_ERROR option obtains and then clears this field, which is useful when checking for errors that occur between socket calls. This uses an integer value to return the SO_ERROR status. Resolves #146
2021-08-10Kernel: Add so_error to keep track of the socket's error statebrapru
This sets the m_so_error variable every time the socket returns an error.
2021-08-08Everywhere: Replace AK::Singleton => SingletonAndreas Kling
2021-08-07Kernel: Migrate local socket table locking to ProtectedValueJean-Baptiste Boric
2021-08-07Kernel: Move Lockable into its own headerJean-Baptiste Boric
2021-08-03Kernel: Handle OOM from DoubleBuffer usage in Net/LocalSocketBrian Gianforcaro
LocalSockets keep a DoubleBuffer for both client and server usage. This change converts the usage from using the default constructor which is unable to observe OOM, to the new try_create factory and plumb the result through the constructor.
2021-07-18Kernel: Rename Locker => MutexLockerAndreas Kling
2021-07-17Kernel: Rename Lock to MutexAndreas Kling
Let's be explicit about what kind of lock this is meant to be.
2021-07-11Kernel: Rename VFS => VirtualFileSystemAndreas Kling
2021-06-24Everywhere: Use nothrow new with `adopt_{ref,own}_if_nonnull`Daniel Bertalan
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)`.
2021-06-16Kernel: Use KResultOr<size_t> for the DoubleBuffer classGunnar Beutner
2021-05-26Kernel: Switch LocalSocket to IntrusiveList from InlineLinkedListBrian Gianforcaro
2021-05-13Kernel: Make LocalSocket factory APIs OOM safeBrian Gianforcaro
2021-05-01Kernel: Harden LocalSocket Vector usage against OOM.Brian Gianforcaro
2021-04-28Kernel+LibC: Implement the socketpair() syscallGunnar Beutner
2021-04-25Kernel: Remove the now defunct `LOCKER(..)` macro.Brian Gianforcaro
2021-04-23AK: Rename adopt() to adopt_ref()Andreas Kling
This makes it more symmetrical with adopt_own() (which is used to create a NonnullOwnPtr from the result of a naked new.)
2021-04-22Everything: Move to SPDX license identifiers in all files.Brian Gianforcaro
SPDX License Identifiers are a more compact / standardized way of representing file license information. See: https://spdx.dev/resources/use/#identifiers This was done with the `ambr` search and replace tool. ambr --no-parent-ignore --key-from-file --rep-from-file key.txt rep.txt *
2021-03-08Kernel: Add bitwise operators for Thread::FileBlocker::BlockFlags enumBrian Gianforcaro
Switch to using type-safe bitwise operators for the BlockFlags class, this cleans up a lot of boilerplate casts which are necessary when the enum is declared as `enum class`.
2021-03-02Kernel: Make sockets use AK::TimeBen Wiederhake
2021-02-23Everywhere: Rename ASSERT => VERIFYAndreas Kling
(...and ASSERT_NOT_REACHED => VERIFY_NOT_REACHED) Since all of these checks are done in release builds as well, let's rename them to VERIFY to prevent confusion, as everyone is used to assertions being compiled out in release. We can introduce a new ASSERT macro that is specifically for debug checks, but I'm doing this wholesale conversion first since we've accumulated thousands of these already, and it's not immediately obvious which ones are suitable for ASSERT.
2021-02-15Kernel+LibC: Stub out SO_{SND_RCV}BUFAnotherTest
2021-02-09Kernel: Convert all *Builder::appendf() => appendff()Andreas Kling
2021-02-08Everywhere: Replace dbgln<flag>(...) with dbgln_if(flag, ...)AnotherTest
Replacement made by `find Kernel Userland -name '*.h' -o -name '*.cpp' | sed -i -Ee 's/dbgln\b<(\w+)>\(/dbgln_if(\1, /g'`
2021-01-29Kernel: Bump the number of fd's that can be queued on a local socketAndreas Kling
2021-01-26Meta: Split debug defines into multiple headers.asynts
The following script was used to make these changes: #!/bin/bash set -e tmp=$(mktemp -d) echo "tmp=$tmp" find Kernel \( -name '*.cpp' -o -name '*.h' \) | sort > $tmp/Kernel.files find . \( -path ./Toolchain -prune -o -path ./Build -prune -o -path ./Kernel -prune \) -o \( -name '*.cpp' -o -name '*.h' \) -print | sort > $tmp/EverythingExceptKernel.files cat $tmp/Kernel.files | xargs grep -Eho '[A-Z0-9_]+_DEBUG' | sort | uniq > $tmp/Kernel.macros cat $tmp/EverythingExceptKernel.files | xargs grep -Eho '[A-Z0-9_]+_DEBUG' | sort | uniq > $tmp/EverythingExceptKernel.macros comm -23 $tmp/Kernel.macros $tmp/EverythingExceptKernel.macros > $tmp/Kernel.unique comm -1 $tmp/Kernel.macros $tmp/EverythingExceptKernel.macros > $tmp/EverythingExceptKernel.unique cat $tmp/Kernel.unique | awk '{ print "#cmakedefine01 "$1 }' > $tmp/Kernel.header cat $tmp/EverythingExceptKernel.unique | awk '{ print "#cmakedefine01 "$1 }' > $tmp/EverythingExceptKernel.header for macro in $(cat $tmp/Kernel.unique) do cat $tmp/Kernel.files | xargs grep -l $macro >> $tmp/Kernel.new-includes ||: done cat $tmp/Kernel.new-includes | sort > $tmp/Kernel.new-includes.sorted for macro in $(cat $tmp/EverythingExceptKernel.unique) do cat $tmp/Kernel.files | xargs grep -l $macro >> $tmp/Kernel.old-includes ||: done cat $tmp/Kernel.old-includes | sort > $tmp/Kernel.old-includes.sorted comm -23 $tmp/Kernel.new-includes.sorted $tmp/Kernel.old-includes.sorted > $tmp/Kernel.includes.new comm -13 $tmp/Kernel.new-includes.sorted $tmp/Kernel.old-includes.sorted > $tmp/Kernel.includes.old comm -12 $tmp/Kernel.new-includes.sorted $tmp/Kernel.old-includes.sorted > $tmp/Kernel.includes.mixed for file in $(cat $tmp/Kernel.includes.new) do sed -i -E 's/#include <AK\/Debug\.h>/#include <Kernel\/Debug\.h>/' $file done for file in $(cat $tmp/Kernel.includes.mixed) do echo "mixed include in $file, requires manual editing." done