Commit Graph

783 Commits

Author SHA1 Message Date
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 db4ab331c7 Fix <psctl.h> using the same include guard as <sys/ioctl.h>. 2021-12-12 22:13:05 +01:00
Jonas 'Sortie' Termansen e65ff1827c Add __stack_chk_fail_local needed by some architectures. 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
Juhani Krekelä 8b57a79567 Change qsort(3) and qsort_r(3) to use heapsort.
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>
2021-12-12 15:18:26 +00: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 29b14378e8 Fix usleep(2) sleeping 1000x too much regression. 2021-06-23 22:09:57 +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
Jonas 'Sortie' Termansen 9d87d76957 Abort on overlapping memcpy. 2021-05-30 23:48:19 +02:00
Jonas 'Sortie' Termansen 1c9233e0c9 Add ENOMEDIUM. 2021-05-29 00:52:33 +02:00
Jonas 'Sortie' Termansen 11be0007b8 Remove ENOUSER and ENOGROUP.
The <pwd.h> and <grp.h> family of functions are supposed to return
nothing with no error set if there is no matching entry.
2021-05-10 23:26:31 +02:00
Jonas 'Sortie' Termansen 6a778c6089 Fix strftime(3) error handling and add %F, %z, and %Z support. 2021-04-06 23:22:22 +02:00
Jonas 'Sortie' Termansen 50543d3c36 Fix printf(3) handling of negative precision. 2021-02-13 22:33:03 +01:00
Jonas 'Sortie' Termansen b2235844da Add TCP_MAXSEG and TCP_NOPUSH definitions. 2021-01-23 00:35:38 +01:00
Jonas 'Sortie' Termansen f22d736633 Fix inet_pton(3) parsing 1:: and ::1.2.3.4 cases. 2020-08-01 14:23:44 +02:00
Jonas 'Sortie' Termansen a969564af4 Delete inet_addr(3) and inet_ntoa(3). 2020-07-29 21:38:41 +02:00
Jonas 'Sortie' Termansen 185a9fa221 Support IPv6 shorthand and IPv4-mapped addresses in inet_{pton,ntop}(3). 2020-07-27 23:49:42 +02:00
Jonas 'Sortie' Termansen 8d4b932f0f Add <sha2.h>. 2020-04-13 22:15:04 +02:00
Jonas 'Sortie' Termansen d3a2eb8a79 Unify EWOULDBLOCK and EAGAIN. 2020-03-15 23:13:17 +01:00
Jonas 'Sortie' Termansen 221fa7d954 Rewrite scanf(3) to be standards compliant.
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.
2020-03-07 23:31:05 +01:00
Jonas 'Sortie' Termansen 976d686779 Fix fputc(3) potentially miswriting the next byte after flushing. 2020-03-06 00:08:59 +01:00
Jonas 'Sortie' Termansen 5837421478 Don't unblock SIGABRT in abort(3) before calling raise(SIGABRT).
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.
2018-09-01 12:56:07 +02:00
Jonas 'Sortie' Termansen 29555d72bb Fix <fcntl.h> including <sys/stat.h> namespace pollution.
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>.
2018-08-06 23:59:34 +02:00
Jonas 'Sortie' Termansen 9c3af039ca Fix <stdio.h> pulling in <pthread.h> through <FILE.h> when __is_sortix_libc. 2018-07-17 12:25:52 +02:00
Jonas 'Sortie' Termansen 53592a6e3f Fix getdelim(3) not returning a final line without a delimiter. 2018-04-08 20:35:30 +02:00
Jonas 'Sortie' Termansen 9380ed82ac Fix typo in getentropy(2). 2018-02-04 13:39:37 +01:00
Jonas 'Sortie' Termansen 7c91ea1b19 Add restartable system calls compatibility macro. 2017-12-04 23:56:47 +01:00
Jonas 'Sortie' Termansen c8ba4b0973 Add float formating and parsing compatibility macros. 2017-12-04 23:56:47 +01:00
Jonas 'Sortie' Termansen b0496023a1 Allow AF_UNSPEC family in socketpair(2). 2017-08-26 16:49:57 +02:00
Jonas 'Sortie' Termansen 2f61df05c2 Fix <string.h> including <sys/__/types.h> in strict C mode. 2017-08-20 12:44:34 +02:00
Jonas 'Sortie' Termansen 515d91a31b Fix <stdlib.h> using long long in C89 mode. 2017-08-20 12:44:34 +02:00
Jonas 'Sortie' Termansen 95bcd5667e Fix <locale.h> not defining NULL. 2017-08-20 12:44:34 +02:00
Jonas 'Sortie' Termansen 07e6c69097 Fix empty struct thread_rwlockattr_t. 2017-08-20 12:44:33 +02:00
Jonas 'Sortie' Termansen c14d7fa3b8 Fix <signal.h> namespace pollution for strict C. 2017-08-20 12:44:33 +02:00
Jonas 'Sortie' Termansen 66e5ddcfab Fix kernel HEAP_GUARD_DEBUG support. 2017-05-15 22:11:24 +02:00
Jonas 'Sortie' Termansen cd7a984e9f Fix select(2) buffer overflow if the fd_set is smaller than normal.
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.
2017-04-09 22:44:32 +02:00
Jonas 'Sortie' Termansen eb7d0f4dd4 Fix select(2) error and end of file handling. 2017-03-19 13:25:27 +01:00
Jonas 'Sortie' Termansen fcefd86432 Implement shutdown(2). 2017-02-18 15:29:40 +01:00
Jonas 'Sortie' Termansen 4b2cf28bbf Add socket(2).
This removes the /dev/net socket interface.

This is an incompatible ABI change.
2017-02-14 20:43:31 +01:00
Jonas 'Sortie' Termansen 50266bb724 Add getnameinfo(3). 2017-02-14 20:43:30 +01:00
Jonas 'Sortie' Termansen 5de36cf449 Add inet_pton(3). 2017-02-14 20:43:30 +01:00
Jonas 'Sortie' Termansen ba3b6d386e Add inet_ntop(3). 2017-02-14 20:43:30 +01:00
Jonas 'Sortie' Termansen e5eed18cf4 Deprecate inet_addr(3) and inet_ntoa(3). 2017-02-14 20:43:30 +01:00
Jonas 'Sortie' Termansen 0b6e58a7ef Document scram(2). 2017-02-12 13:59:07 +01:00
Jonas 'Sortie' Termansen ef1d85ca55 Fix EDESTADDRREQ typo. 2016-12-28 23:08:29 +01:00
Jonas 'Sortie' Termansen 0cf88fd58a Revert "Add <limits.h>."
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.
2016-12-27 21:58:07 +01:00
Jonas 'Sortie' Termansen 52ea22d793 Add ptsname_r(3). 2016-11-23 22:31:41 +01:00
Jonas 'Sortie' Termansen 1f742d521c Add ptsname(3). 2016-11-23 22:31:40 +01:00
Jonas 'Sortie' Termansen 88de69487b Add unlockpt(3). 2016-11-23 22:31:40 +01:00