Andreas Kling
b6efd66d56
Kernel: Use move semantics in sys$sendfd()
...
Avoid an unnecessary NonnullRefPtr<OpenFileDescription> copy.
2021-09-15 21:09:47 +02:00
Andreas Kling
308773ffda
Kernel/Net: Add a special SOCKET_TRY() and use it in socket code
...
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-07 15:05:51 +02:00
Andreas Kling
01993d0af3
Kernel: Make DoubleBuffer::try() return KResultOr
...
This tidies up error propagation in a number of places.
2021-09-07 13:53:14 +02:00
Andreas Kling
4a9c18afb9
Kernel: Rename FileDescription => OpenFileDescription
...
Dr. POSIX really calls these "open file description", not just
"file description", so let's call them exactly that. :^)
2021-09-07 13:53:14 +02:00
Andreas Kling
a2bf8244fe
Kernel: Use TRY() once more in LocalSocket::try_create_connected_pair()
2021-09-06 20:26:03 +02:00
Andreas Kling
56a2594de7
Kernel: Make KString factories return KResultOr + use TRY() everywhere
...
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-06 19:25:36 +02:00
Andreas Kling
48a0b31c47
Kernel: Make copy_{from,to}_user() return KResult and use TRY()
...
This makes EFAULT propagation flow much more naturally. :^)
2021-09-05 17:38:37 +02:00
Andreas Kling
81d3f823f7
Kernel: Use TRY() in LocalSocket
2021-09-05 14:08:12 +02:00
Owen Smith
22ec21bd61
Kernel: Don't VERIFY_NOT_REACHED in LocalSocket::has_attached_peer()
...
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-31 16:00:53 +02:00
Andreas Kling
ed0e64943f
Kernel: Rename Socket::lock() => Socket::mutex()
...
"lock" is ambiguous (verb vs noun) while "mutex" is not.
2021-08-29 22:19:42 +02:00
Andreas Kling
a28cd921a1
Kernel: Add Socket::set_role() and use it everywhere
...
Instead of having Socket subclasses write their role into Socket::m_role
directly, add a setter to do this.
2021-08-29 02:21:01 +02:00
Andreas Kling
70b2225b3d
Kernel: Store LocalSocket address as a KString internally
...
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-29 02:21:01 +02:00
Andreas Kling
48a1a3c0ce
Kernel: Rename LocalSocket::create_connected_pair() => try_*()
2021-08-29 01:33:15 +02:00
Andreas Kling
7f96288535
Kernel: Encapsulate assignment of socket origin/acceptor credentials
2021-08-29 01:33:15 +02:00
Andreas Kling
242063866f
Kernel: Rename LocalSocket factory to try_create() & tighten return type
...
Also tighten the return type to KResultOr<NonnullRefPtr<LocalSocket>>
since it cannot return any other socket type.
2021-08-29 01:25:03 +02:00
Andreas Kling
ae197deb6b
Kernel: Strongly typed user & group ID's
...
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-29 01:09:19 +02:00
Andreas Kling
59335bd8ea
Kernel: Rename FileDescription::create() => try_create()
2021-08-29 01:09:19 +02:00
Peter Elliott
38e0d1b456
Kernel: Return ENOTSUP instead of panicking on invalid sockopt
...
X11 handles this gracefully, and it makes more sense than panicking.
2021-08-22 10:29:06 +02:00
Peter Elliott
39a77559f1
Kernel+LibC: Implement FIONREAD ioctl
...
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-22 10:29:06 +02:00
Andreas Kling
c2fc33becd
Kernel: Rename ProtectedValue<T> => MutexProtected<T>
...
Let's make it obvious what we're protecting it with.
2021-08-22 03:34:09 +02:00
Idan Horowitz
cf271183b4
Kernel: Make Process::current() return a Process& instead of Process*
...
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-19 23:49:53 +02:00
Andreas Kling
7676edfb9b
Kernel: Stop allowing implicit conversion from KResult to int
...
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-14 15:19:00 +02:00
brapru
342e1f0a84
Kernel: Properly implement SO_ERROR option
...
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-10 20:59:53 +02:00
brapru
0095c7cb7d
Kernel: Add so_error to keep track of the socket's error state
...
This sets the m_so_error variable every time the socket returns an
error.
2021-08-10 20:59:53 +02:00
Andreas Kling
c94c15d45c
Everywhere: Replace AK::Singleton => Singleton
2021-08-08 00:03:45 +02:00
Jean-Baptiste Boric
edd6c04024
Kernel: Migrate local socket table locking to ProtectedValue
2021-08-07 11:48:00 +02:00
Jean-Baptiste Boric
aea98a85d1
Kernel: Move Lockable into its own header
2021-08-07 11:48:00 +02:00
Brian Gianforcaro
109c885585
Kernel: Handle OOM from DoubleBuffer usage in Net/LocalSocket
...
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-08-03 18:54:23 +02:00
Andreas Kling
9457d83986
Kernel: Rename Locker => MutexLocker
2021-07-18 01:53:04 +02:00
Andreas Kling
cee9528168
Kernel: Rename Lock to Mutex
...
Let's be explicit about what kind of lock this is meant to be.
2021-07-17 21:10:32 +02:00
Andreas Kling
0d39bd04d3
Kernel: Rename VFS => VirtualFileSystem
2021-07-11 00:25:24 +02:00
Daniel Bertalan
f820917a76
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)`.
2021-06-24 17:35:49 +04:30
Gunnar Beutner
ca3cae81eb
Kernel: Use KResultOr<size_t> for the DoubleBuffer class
2021-06-16 21:29:36 +02:00
Brian Gianforcaro
e0da61f9d6
Kernel: Switch LocalSocket to IntrusiveList from InlineLinkedList
2021-05-26 20:24:32 +02:00
Brian Gianforcaro
9375f3dc09
Kernel: Make LocalSocket factory APIs OOM safe
2021-05-13 16:21:53 +02:00
Brian Gianforcaro
e8d6d478c4
Kernel: Harden LocalSocket Vector usage against OOM.
2021-05-01 09:10:30 +02:00
Gunnar Beutner
aa792062cb
Kernel+LibC: Implement the socketpair() syscall
2021-04-28 14:19:45 +02:00
Brian Gianforcaro
8d6e9fad40
Kernel: Remove the now defunct LOCKER(..)
macro.
2021-04-25 09:38:27 +02:00
Andreas Kling
b91c49364d
AK: Rename adopt() to adopt_ref()
...
This makes it more symmetrical with adopt_own() (which is used to
create a NonnullOwnPtr from the result of a naked new.)
2021-04-23 16:46:57 +02:00
Brian Gianforcaro
1682f0b760
Everything: Move to SPDX license identifiers in all files.
...
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-04-22 11:22:27 +02:00
Brian Gianforcaro
5f6ab77352
Kernel: Add bitwise operators for Thread::FileBlocker::BlockFlags enum
...
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-08 18:47:40 +01:00
Ben Wiederhake
5c15ca7b84
Kernel: Make sockets use AK::Time
2021-03-02 08:36:08 +01:00
Andreas Kling
5d180d1f99
Everywhere: Rename ASSERT => VERIFY
...
(...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-23 20:56:54 +01:00
AnotherTest
1e79c04616
Kernel+LibC: Stub out SO_{SND_RCV}BUF
2021-02-15 17:32:56 +01:00
Andreas Kling
1f277f0bd9
Kernel: Convert all *Builder::appendf() => appendff()
2021-02-09 19:18:13 +01:00
AnotherTest
09a43969ba
Everywhere: Replace dbgln<flag>(...) with dbgln_if(flag, ...)
...
Replacement made by `find Kernel Userland -name '*.h' -o -name '*.cpp' | sed -i -Ee 's/dbgln\b<(\w+)>\(/dbgln_if(\1, /g'`
2021-02-08 18:08:55 +01:00
Andreas Kling
a8c823f242
Kernel: Bump the number of fd's that can be queued on a local socket
2021-01-29 22:11:59 +01:00
asynts
7cf0c7cc0d
Meta: Split debug defines into multiple headers.
...
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
2021-01-26 21:20:00 +01:00
asynts
8465683dcf
Everywhere: Debug macros instead of constexpr.
...
This was done with the following script:
find . \( -name '*.cpp' -o -name '*.h' -o -name '*.in' \) -not -path './Toolchain/*' -not -path './Build/*' -exec sed -i -E 's/dbgln<debug_([a-z_]+)>/dbgln<\U\1_DEBUG>/' {} \;
find . \( -name '*.cpp' -o -name '*.h' -o -name '*.in' \) -not -path './Toolchain/*' -not -path './Build/*' -exec sed -i -E 's/if constexpr \(debug_([a-z0-9_]+)/if constexpr \(\U\1_DEBUG/' {} \;
2021-01-25 09:47:36 +01:00
asynts
acdcf59a33
Everywhere: Remove unnecessary debug comments.
...
It would be tempting to uncomment these statements, but that won't work
with the new changes.
This was done with the following commands:
find . \( -name '*.cpp' -o -name '*.h' -o -name '*.in' \) -not -path './Toolchain/*' -not -path './Build/*' -exec awk -i inplace '$0 !~ /\/\/#define/ { if (!toggle) { print; } else { toggle = !toggle } } ; $0 ~/\/\/#define/ { toggle = 1 }' {} \;
find . \( -name '*.cpp' -o -name '*.h' -o -name '*.in' \) -not -path './Toolchain/*' -not -path './Build/*' -exec awk -i inplace '$0 !~ /\/\/ #define/ { if (!toggle) { print; } else { toggle = !toggle } } ; $0 ~/\/\/ #define/ { toggle = 1 }' {} \;
2021-01-25 09:47:36 +01:00