This commit is based on work by Meisaka Yukara <Meisaka.Yukara@gmail.com>
contributed as the commit bbf7f1e8a5238a2bd1fe8eb1d2cc5c9c2421e2c4. See the
individual file headers for which files contain remnants of this work.
This change adds all the kernel parts of a network stack. The network stack
is partial but implements many of the important parts.
Add if(4) network interface abstraction. Network interfaces are registered
in a global list that can be iterated and each assigned an unique integer
identifier.
Add reference counted packets with a cache that recycles recent packets.
Add support for lo(4) loopback and ether(4) ethernet network interfaces.
The /dev/lo0 loopback device is created automatically on boot.
Add arp(4) address resolution protocol driver for translation of inet(4)
network layer addresses into ether(4) link layer addresses. arp(4) entries
are cached and evicted from the cache when needed or when the entry has not
been used for a while. The cache is limited to 256 entries for now.
Add ip(4) internet protocol version 4 support. IP fragmentation and options
are not implemented yet.
Add tcp(4) transmission control protocol sockets for a reliable transport
layer protocol that provides a reliable byte stream connection between two
hosts. The implementation is incomplete and does not yet implement out of
band data, options, and high performance extensions.
Add udp(4) user datagram protocol sockets for a connectionless transport
layer that provides best-effort delivery of datagrams.
Add ping(4) sockets for a best-effort delivery echo of datagrams.
Change type of sa_family_t from unsigned short to uint16_t.
Add --disable-network-drivers to the kernel(7) options and expose it with a
bootloader menu. tix-iso-bootconfig can set this option by default.
Import CRC32 code from libz for the Ethernet checksum.
This is a compatible ABI change that adds features to socket(2) (AF_INET,
IPPROTO_TCP, IPPROTO_UDP, IPPROTO_PING), the ioctls for if(4), socket
options, and the lo0 loopback interface.
This change refactors the Unix socket / pipe backend to have a ring buffer
containing segments, where each segment has an optional leading ancillary
buffer containing control messages followed by a normal data buffer.
The SCM_RIGHTS control message has been implemented which transfers file
descriptors to the receiving process. File descriptors are reference counted
and cycles are prevented using the following restrictions:
1) Unix sockets cannot be sent on themselves (on either end).
2) Unix sockets themselves being sent cannot be sent on.
3) Unix sockets cannot send a Unix socket being sent on.
This is a compatible ABI change.
Heapsort has O(n·log(n)) worst case runtime and O(1) space usage, which
is better than current implementation's best case, while still keeping
the code simple.
Co-authored-by: Jonas 'Sortie' Termansen <sortie@maxsi.org>
The idle thread is now actually run when the system is idle because it
truly goes idle. The idle thread is made power efficient by using the hlt
instruction rather than a busy loop.
The new futex(2) system call is used to implement fast user-space mutexes,
condition variables, and semaphores. The same backend and design is used as
kutexes for truly sleeping kernel mutexes and condition variables.
The new exit_thread(2) flag EXIT_THREAD_FUTEX_WAKE wakes a futex.
Sleeping on clocks in the kernel now uses timers for true sleep.
The interrupt worker thread now truly sleeps when idle.
Kernel threads are now named.
This is a compatible ABI change.
This change adds missing features:
* %[ for pattern matching with a scanset.
* %m for allocation of strings.
* %p for pointers.
* Field width for integers.
The following features remain unimplemented, like with printf(3):
* Floating point support.
* Wide character support.
* %n$ positional parameters.
The code has been completely refactored to be much more maintainable.
The implemented features should now be standards compliant. A large number
of edge cases have been fixed.
The vscanf_callback(3) function has been renamed to vcbscanf(3) and a new
cbscanf(3) function has been added.
The language in POSIX mentioning overriding blocking or ignoring SIGABRT
refers to the inevitability of exiting by SIGABRT if SIGABRT isn't caught or
if the handler does return.
This implementation of abort(3) implements the standard by raising SIGABRT,
allowing the signal to be caught; and if the signal is blocked or ignored or
the handler returns, then exit_thread(2) forcefully exits the process as if
by SIGABRT.
POSIX allows <fcntl.h> to include <sys/stat.h>, but doesn't require it.
There's little reason to do that, since they are separate headers, and
<fcntl.h> just needs the mode_t constants. Fix the code accidentally
relying on <fcntl.h> including <sys/stat.h>. The mode_t constants are now
provided in their own kernel header <sortix/mode.h>.
Additionally fix <sys/stat.h> pulling in all of <sys/types.h>, which is not
allowed by POSIX, which only requires a few types to be declared. Fix the
code accidentally relying on <sys/stat.h> including <sys/types.h>.
Finally fix <dirent.h> pulling in <stdint.h> through <sortix/dirent.h>.
The <sortix/__/dt.h> and <sortix/__/stat.h> headers are no longer required
and their contents have been merged into <sortix/__/dirent.h>.
OpenSSH is allocating a fd_set of exactly the needed size, which leads to
buffer overflows in select(2) when it tries to zero out the fd_set assuming
it is the normal size.
This reverts commit f6cde2d7a6.
gcc detected this header existing and emitted its own limits.h that
included the libc limits.h. This caused the #include_next chain to reach
the end and including the header failed.
Undoing this commit for now until the compiler toolchain is updated to
avoid this problem.