Commit Graph

79 Commits

Author SHA1 Message Date
Pedro Falcato be563c165e Fix ptsname_r return value
Per POSIX, it should return 0 on success and errno (!= 0) on error.
2023-02-22 17:25:01 +00: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 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 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
Jonas 'Sortie' Termansen 46ebbf82d4 Add grantpt(3). 2016-11-23 22:31:40 +01:00
Jonas 'Sortie' Termansen 2563b926ad Add posix_openpt(3). 2016-11-23 22:31:05 +01:00
Jonas 'Sortie' Termansen 84c0844f56 Seed kernel entropy with randomness from the previous boot.
The bootloader will now load the /boot/random.seed file if it exists, in
which case the kernel will use it as the initial kernel entropy. The kernel
warns if no random seed was loaded, unless the --no-random-seed option was
given. This option is used for live environments that inherently have no
prior secret state. The kernel initializes its entropy pool from the random
seed as of the first things, so randomness is available very early on.

init(8) will emit a fresh /boot/random.seed file on boot to avoid the same
entropy being used twice. init(8) also writes out /boot/random.seed on
system shutdown where the system has the most entropy. init(8) will warn if
writing the file fails, except if /boot is a real-only filesystem, and
keeping such state is impossible. The system administrator is then
responsible for ensuring the bootloader somehow passes a fresh random seed
on the next boot.

/boot/random.seed must be owned by the root user and root group and must
have file permissions 600 to avoid unprivileged users can read it. The file
is passed to the kernel by the bootloader as a multiboot module with the
command line --random-seed.

If no random seed is loaded, the kernel attempts a poor quality fallback
where it seeds the kernel arc4random(3) continuously with the current time.
The timing variance may provide some effective entropy. There is no real
kernel entropy gathering yet. The read of the CMOS real time clock is moved
to an early point in the kernel boot, so the current time is available as
fallback entropy.

The kernel access of the random seed module is supposed to be infallible
and happens before the kernel log is set up, but there is not yet a failsafe
API for mapping single pages in the early kernel.

sysupgrade(8) creates /boot/random.seed if it's absent as a temporary
compatibility measure for people upgrading from the 1.0 release. The GRUB
port will need to be upgraded with support for /boot/random.seed in the
10_sortix script. Installation with manual bootloader configuration will
need to load the random seed with the --random-seed command line. With GRUB,
this can be done with: module /boot/random.seed --random-seed
2016-10-04 00:34:50 +02:00
Ralph Holmes 5d774cce1d Fix execl(3) sentinel undefined behaviour.
execl(3) and its variants use a sentinel to terminate the variadic
argument list, in the form of a null pointer constant of type pointer to
char. POSIX mandates that NULL is a null pointer constant of type
pointer to void, which is not of an equivalent type to that required by
execl(3) and its variants, resulting in undefined behaviour.

This commit casts all such instances of NULL to pointer to char type.
For consistency, it also adds const-qualification to any such instances
which had already been casted, and were not const-qualified.
2016-09-30 23:36:49 +02:00
Jonas 'Sortie' Termansen f6cc06fbd1 Fix bsearch(3) performance. 2016-05-15 19:30:51 +02:00
Jonas 'Sortie' Termansen 2b72262b4f Relicense Sortix to the ISC license.
I hereby relicense all my work on Sortix under the ISC license as below.

All Sortix contributions by other people are already under this license,
are not substantial enough to be copyrightable, or have been removed.

All imported code from other projects is compatible with this license.

All GPL licensed code from other projects had previously been removed.

Copyright 2011-2016 Jonas 'Sortie' Termansen and contributors.

Permission to use, copy, modify, and distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.

THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
2016-03-05 22:21:50 +01:00
Jonas 'Sortie' Termansen 01b59c1947 Convert libc to C. 2016-03-03 23:02:23 +01:00
Jonas 'Sortie' Termansen 4f07e94b0c Rewrite strtof(3). 2016-02-29 01:37:30 +01:00
Jonas 'Sortie' Termansen 2ab9139f35 Fix missing malloc check in canonicalize_file_name_at(3). 2016-02-18 22:15:17 +01:00
Jonas 'Sortie' Termansen 7a7ddc2d73 Add guard page debug malloc. 2016-01-26 22:48:40 +01:00
Jonas 'Sortie' Termansen 4d2901b90e Split stdin, stdout and stderr into their own files. 2016-01-26 19:01:36 +01:00
Jonas 'Sortie' Termansen 2e4b15daed Simplify directory reading. 2016-01-26 18:42:54 +01:00
Jonas 'Sortie' Termansen 4b6b06bbc8 Add scram(2). 2015-12-12 22:53:07 +01:00
Jonas 'Sortie' Termansen 8a653584c4 Fix strtol multiplication overflow check. 2015-10-11 23:25:21 +02:00
Jonas 'Sortie' Termansen 59e7dd00c5 Add mkdtemps(3). 2015-08-26 16:49:18 +02:00
Jonas 'Sortie' Termansen 6405e2ea6e Add arc4random support to the kernel. 2015-08-22 01:04:58 +02:00
Jonas 'Sortie' Termansen 13e8e092a6 Fix mkostemps and mkdtemp not restoring X's on error. 2015-06-27 17:06:43 +02:00
Jonas 'Sortie' Termansen 8c0252300e Fix strtol isspace calls. 2015-05-15 16:18:41 +02:00
Jonas 'Sortie' Termansen 25482f875e Remove mktemp(3). 2015-04-13 00:00:29 +02:00
Jonas 'Sortie' Termansen 60f85af7c4 Fix strtol multiplication overflow check. 2015-02-11 17:35:28 +01:00
Jonas 'Sortie' Termansen 8cd4c1f5a0 Add mkdtemp(3). 2015-02-09 18:56:14 +01:00
Jonas 'Sortie' Termansen f0e3e2cfef Add mkostemps(3) family. 2015-02-09 18:56:14 +01:00
Jonas 'Sortie' Termansen 261b95e0a6 Add reallocarray(3). 2014-12-03 23:55:55 +01:00
Jonas 'Sortie' Termansen 74247eb71e Rewrite malloc(3). 2014-12-03 21:32:50 +01:00
Jonas 'Sortie' Termansen fb8221a381 Improve mkstemp(3) random path generation. 2014-12-01 23:22:11 +01:00
Jonas 'Sortie' Termansen 35708fa900 Retire calltrace support in favor of the kernel debugger. 2014-12-01 21:38:06 +01:00
Jonas 'Sortie' Termansen c24b5ee5a4 Lazily close files in exit(3). 2014-12-01 18:54:41 +01:00
Jonas 'Sortie' Termansen a25f1a931e Initialize stdin, stdout and stderr at compile time. 2014-12-01 18:45:11 +01:00
Jonas 'Sortie' Termansen 9fec909970 Indirectly closedir(3) from exit(3). 2014-12-01 18:45:10 +01:00
Jonas 'Sortie' Termansen 5e60007904 Remove dcloseall() and fcloseall(). 2014-12-01 16:29:43 +01:00
Jonas 'Sortie' Termansen edb19f2394 Add arc4random(3). 2014-11-28 13:35:51 +01:00
Jonas 'Sortie' Termansen a1e9c15bca Add wcstof(3), wcstod(3) and wcstold(3). 2014-11-26 22:49:00 +01:00
Jonas 'Sortie' Termansen 749d123331 Maintain counts of physical frames used for particular purposes. 2014-11-26 22:27:04 +01:00
Jonas 'Sortie' Termansen 5f2106f512 Maintain size of allocated memory in the heap. 2014-11-26 22:25:37 +01:00
Jonas 'Sortie' Termansen f41964fcab Reimplement wchar conversion API. 2014-11-24 17:41:26 +01:00
Jonas 'Sortie' Termansen 5dbd89d2aa Delay heap initialization until first heap expansion. 2014-11-20 21:09:14 +01:00
Jonas 'Sortie' Termansen f3eb87c3ee Improve qsort_r(3) run-time complexity using quicksort. 2014-09-25 18:20:00 +02:00
Jonas 'Sortie' Termansen a9cf3cc684 Add qsort_r(3). 2014-09-25 18:20:00 +02:00
Jonas 'Sortie' Termansen 94a7433cf0 Fix atoi(3) out-of-range cases. 2014-09-25 17:27:54 +02:00
Jonas 'Sortie' Termansen 87fee95949 Fix setenv(3) error case. 2014-09-25 17:27:54 +02:00
Jonas 'Sortie' Termansen 513c5f242d Fix strtol(3) quality. 2014-09-25 17:27:54 +02:00
Jonas 'Sortie' Termansen b75678bcab Fix mkstemp(3) creating files with an insecure mode. 2014-08-23 21:47:04 +02:00
Jonas 'Sortie' Termansen 74fbbb3c78 Fix mkstemp(3) not rejecting bad templates.
Found by musl's libc-test.
2014-08-23 21:47:04 +02:00