Commit Graph

420 Commits

Author SHA1 Message Date
Juhani Krekelä fc20a4f6a3 Support CSI n L and CSI n M in console and terminal(1).
With these escapes supported, include definitions for line deletion
(dl1, dl) and insertion (il1, il) in terminfo for "sortix".
2023-12-26 19:24:00 +02:00
Jonas 'Sortie' Termansen 95cf3fba98 Save kernel options upon installation. 2023-12-19 00:05:42 +01:00
Jonas 'Sortie' Termansen dc98bcf0ca Add options to kernelinfo(2). 2023-12-19 00:05:42 +01:00
Jonas 'Sortie' Termansen 4533a2ade2 Remove mkinitrd(8). 2023-08-26 14:15:12 +02:00
Jonas 'Sortie' Termansen d189183900 Third generation Tix.
The .tix.tar.xz binary package format now stores the contents in the root
rather than the data/ subdirectory and the tix metadata now has the same
layout as the loose files in /tix, such that a .tix.tar.xz package can
simply be directly extracted into the filesystem. The /tix/manifest/ is now
included in the binary package rather than being generated on installation.

The /tix/collection.conf and /tix/tixinfo metadata files are now in the
tix-vars(1) format in the style of port(5).

The /tix/installed.list file has been removed since it isn't loose file
compatible and one can list the /tix/tixinfo directory instead.

The /tix/repository.list file has been removed since the feature is unused
and doesn't match the future direction of tix.

The kernel support for tix binary packages has been removed since it will
simply install by extracting the tar archive into the root filesystem.

Add the post-install sha256sum to the port version stamp.
2023-07-15 16:43:27 +02:00
Jonas 'Sortie' Termansen ffc1b02b94 Remove workaround for qemu 1.4.x and 1.5.x.
These releases are now 10 years old and are no longer a concern.
2023-07-12 21:54:57 +02:00
Jonas 'Sortie' Termansen e933eb5a1c Replace mkinitrd(1) with tar(1).
The custom initrd format was originally useful when it was mounted,
however it has been extracted into the ramfs for a very long time and
has no advantages over the standard tar format which can be readily
created and modified using standard tools. The kernel initrd(7) support
already supports tar, so this change simply switches the format.
2023-07-12 21:45:11 +02:00
Jonas 'Sortie' Termansen caa92556c5 Try the router when ARP hasn't found neighbors. 2023-04-08 17:17:30 +02:00
Jonas 'Sortie' Termansen cb88c18bf0 Fix system calls returning errno values instead of setting errno. 2023-04-06 23:26:10 +02:00
Jonas 'Sortie' Termansen 9033153c47 Add sub_leap_seconds(3) and add_leap_seconds(3).
Advertise leap seconds being counted via CLOCK_REALTIME_HAS_LEAP_SECONDS.
2023-03-27 00:06:33 +02:00
Jonas 'Sortie' Termansen 8a4548db7d Add memory statistics to struct psctl_stat.
This is an incompatible ABI change.
2023-03-09 20:27:18 +01:00
Jonas 'Sortie' Termansen 2cd7361294 Add memusage(2).
Switch xz to memusage(2) and fix native self-cross issue.

This is a compatible ABI change.
2023-03-09 20:27:17 +01:00
Jonas 'Sortie' Termansen 18cb2651be Support \e[6n for reporting cursor position. 2023-02-26 12:10:58 +01:00
Jonas 'Sortie' Termansen 28cff2f185 Fix listen(2) failing if called twice. 2023-02-17 23:26:05 +01:00
Jonas 'Sortie' Termansen 384218d787 Fix the the. 2023-02-17 23:25:40 +01:00
Jonas 'Sortie' Termansen f291054465 Add em(4) driver.
Co-authored-by: Meisaka Yukara <Meisaka.Yukara@gmail.com>
2023-01-09 23:58:19 +01:00
Jonas 'Sortie' Termansen 2ef6804ead Add networking stack.
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 of echo 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 commit is based on work by Meisaka Yukara contributed as the commit
bbf7f1e8a5238a2bd1fe8eb1d2cc5c9c2421e2c4. Almost no lines of this work
remains in this final commit as it has been rewritten or refactored away
over the years, see the individual file headers for which files contain
remnants of this work.

Co-authored-by: Meisaka Yukara <Meisaka.Yukara@gmail.com>
2022-12-11 13:40:34 +01:00
Jonas 'Sortie' Termansen 3154492dcf Fix deadlocks and lost wakeups in threading primitives.
The futex and kutex implementations used the same linked list for waiting,
however the futex implementation used kutexs and the same thread could be in
the same list twice in the case of contention. This case corrupted the wait
lists and led to deadlocks and lost wakeups. This change fixes the problem
by having separate data structures for futexes and kutexes.

Mutexes contended by multiple threads could lead to lost wakeups since only
one contended thread was awoken and subsequent unlocks are unaware of the
unawakened contended threads. This change fixes the problem with a temporary
solution of waking all the contended threads until a better design is
implemented.

Additional details are tweaked to be more reliable and simpler.
2022-12-10 21:29:23 +01:00
Jonas 'Sortie' Termansen cbf16b4891 Fix absolute timers triggering in the wrong order. 2022-12-03 22:43:33 +01:00
Jonas 'Sortie' Termansen 68a278ddb3 Fix pty write and read logic. 2022-12-03 22:36:34 +01:00
Jonas 'Sortie' Termansen a8c05711aa Switch bga(4) to the new PCI API. 2022-11-16 20:22:29 +01:00
Jonas 'Sortie' Termansen 0f348c192b Fix sethostname(2) nul termination. 2022-10-23 14:42:10 +02:00
Jonas 'Sortie' Termansen 611dc22e73 Standardize header include guards.
This change makes all the standard library and kernel headers use header
guards with a consistent scheme within the reserved namespace to avoid
conflicts with non-standard-library-implementation code.
2022-07-09 20:51:13 +02:00
Jonas 'Sortie' Termansen 0765ac2129 Fix dtable allocation overflow on INT_MAX. 2022-06-09 22:47:06 +02:00
Jonas 'Sortie' Termansen 22f4fd859e Remove kernel thread alignment since malloc is already 16-byte aligned. 2022-04-26 01:08:46 +02:00
Jonas 'Sortie' Termansen 0f0c6a3232 Include the main kernel header in some kernel files. 2022-04-26 01:08:42 +02:00
Jonas 'Sortie' Termansen a0a4030dd3 Fix kernelinfo(2) user-space pointer deference. 2022-04-26 01:08:39 +02:00
Jonas 'Sortie' Termansen 322c8317d6 Fix non-throwing operator new failure checks being optimized away. 2022-04-26 01:08:19 +02:00
Jonas 'Sortie' Termansen 5eb34b4a00 Never deliver signals during stat(2), readlink(2), open(2), and truncate(2). 2022-04-26 00:50:54 +02:00
Jonas 'Sortie' Termansen df9b1ded9a Implement local and remote addresses in filesystem sockets. 2022-03-03 20:52:15 +01:00
auronandace 292aeb3fe7 Rename CLOCK_BOOT to CLOCK_BOOTTIME. 2022-02-22 18:01:57 +00:00
Mathew John Roberts d41beab4a8 Make execve(2) require 1 <= argc. 2022-02-13 16:31:41 +00:00
auronandace aa7c6855f7 Return EBADF on negative fds for dup2(2) and dup3(2). 2022-02-10 17:56:25 +00:00
Juhani Krekelä 332d39445c Fix handling of bad file descriptors in dup(2).
Previously, sys_dup() would do dtable->Get() on the passed in-file
descriptor and then pass the result directly to dtable->Allocate(). If
the file descriptor is not valid, dtable->Get() returns a NULL reference
and sets errno to mark the error. Since sys_dup() did not check the
return value of dtable->Get() and dtable->Allocate() does not check
whether the passed in Ref<Descriptor> is a NULL reference, dup(2) with
invalid file descriptor would succesfully allocate a new file descriptor
with garbage contents.

This commit changes sys_dup() to use a variant of dtable->Allocate()
that takes in a file descriptor as an integer and properly validates it
before use.
2022-02-10 00:06:25 +02:00
Jonas 'Sortie' Termansen 23832546d5 Fix chown(2) not supporting -1 to not set the owner and group. 2022-01-15 20:48:54 +01:00
Jonas 'Sortie' Termansen 4e86394e3d Fix the kernel having an .init section linked at a high address.
The .init section for global constructors in the kernel is unused at the
moment as the _init function is never invoked, but its existence means
it got linked at 128 MiB on i686. This address isn't mapped by the
kernel and the bootloader requires the machine to have that much
physical memory. Unfortunately that meant the i686 build didn't work on
machines with less than 129 MiB of memory.
2022-01-12 21:19:53 +01:00
Juhani Krekelä 4e72c78dc1 Support i686 without SSE.
Previously Sortix would initialize SSE unconditionally as part of the
boot process. Since earlier i686 CPUs like Pentium 2 did not include
SSE, Sortix would not run on them. With this SSE is only enabled for
CPUs that include it, which should theoretically allow Sortix to boot on
all i686 CPUs. Additionally, this removes -msse -msse2 compiler flags
from trianglix/Makefile.
2022-01-09 23:38:16 +02:00
Jonas 'Sortie' Termansen 3c43f71084 Implement file descriptor passing.
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.
2021-12-31 22:24:11 +01:00
Jonas 'Sortie' Termansen b9898086c6 Add file descriptor table reservations.
The file descriptor table now allows reserving room for multiple file
descriptors without assigning their numbers. This functionality means
any error conditions happen up front and the subsequent number
assignment will never fail.

This change uses the new functionality to fix troublesome error handling
when allocating multiple file descriptors. One pty allocation error path
was even wrong.

There were subtle race conditions where one (kernel) thread may have
allocated one file descriptor, and another thread spuciously replaces it
with something else, and then the second file descriptor allocation
failed in the first thread, and it closes the first file descriptor now
pointing to a different file description. This case seems harmless but
it's not a great class of bugs to exist in the first place. The new
behavior means the file descriptions appear in the file descriptor table
without fail and never needs to be cleaned up midway and is certainly
immune to shenangians from other threads.

Reviewed-by: Pedro Falcato <pedro.falcato@gmail.com>
2021-12-31 22:24:07 +01:00
Jonas 'Sortie' Termansen 20648e03d7 Send SIGCHLD to init even for reparented processes. 2021-12-12 22:13:05 +01:00
Juhani Krekelä c6e989909f Add header for working with the PS/2 mouse protocol. 2021-12-12 20:34:07 +02:00
Jonas 'Sortie' Termansen db5b51d673 Fix spurious ptable assertion in the fork error path. 2021-10-10 00:07:06 +02:00
Jonas 'Sortie' Termansen 63ce55e7e9 Fix reading directories not failing with EISDIR. 2021-07-28 22:21:41 +02:00
Jonas 'Sortie' Termansen 16bdb2ba84 Fix setuid(2) and setgid(2) not setting the effective user and group.
Thanks to samis for discovering this problem and the initial attempt at
fixing it.
2021-07-27 00:46:42 +02:00
Juhani Krekelä 6385ea1957 Fix pipes reporting themselves as character devices through fstat(2). 2021-07-16 01:43:33 +03:00
Jonas 'Sortie' Termansen 2d841bae7c Fix kernel deadlock in ppoll(2). 2021-07-14 15:41:28 +02:00
Jonas 'Sortie' Termansen 80f5ca398a Add ATAPI support to ata(4). 2021-06-27 13:54:56 +02:00
Jonas 'Sortie' Termansen 5e7605fad2 Implement threading primitives that truly sleep.
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.
2021-06-23 22:10:47 +02:00
Jonas 'Sortie' Termansen 4daedc31f7 Fix handling of overflow and non-canonical values in timespec APIs.
Support zero relative and absolute times in the timer API.
2021-06-22 21:48:27 +02:00
Jonas 'Sortie' Termansen 3b036b6c5d Add getdnsconfig(2) and setdnsconfig(2). 2021-06-13 23:27:52 +02:00