Commit Graph

50 Commits

Author SHA1 Message Date
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
Mathew John Roberts d41beab4a8 Make execve(2) require 1 <= argc. 2022-02-13 16:31:41 +00:00
Jonas 'Sortie' Termansen 20648e03d7 Send SIGCHLD to init even for reparented processes. 2021-12-12 22:13:05 +01: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 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 62bd9bf901 Fix pid 1 deadlocking when exiting with children.
The child processes of pid 1 were being reparented to pid 1, causing an
infinite loop. This change fixes the problem by adding a hook that runs in
the last thread about to exit in a process. When pid 1 exits, the hook will
prevent more processes and threads from being created, and then broadcast
kill all processes and threads. The hook is not run in LastPrayer(), as that
function runs in a worker thread and it can't block waiting for another
thread to run LastPrayer() in the same thread.
2018-08-06 23:59:35 +02:00
Jonas 'Sortie' Termansen c14e6c05b9 Fix waitpid(2) when the status pointer is NULL. 2018-08-06 23:59:35 +02:00
Jonas 'Sortie' Termansen db7182ddc3 Add support for sessions.
This change refactors the process group implementation and adds support
for sessions. The setsid(2) and getsid(2) system calls were added.

psctl(2) now has PSCTL_TTYNAME, which lets you get the name of a process's
terminal, and ps(1) now uses it.

The initial terminal is now called /dev/tty1.

/dev/tty is now a factory for the current terminal.

A global lock now protects the process hierarchy which makes it safe to
access other processes. This refactor removes potential vulnerabilities
and increases system robustness.

A number of terminal ioctls have been added.

This is a compatible ABI change.
2016-11-23 22:30:47 +01:00
Jonas 'Sortie' Termansen 2e03bd94d3 Add protection against sigreturn oriented programming (SROP).
This change hardens against invalid calls to sigreturn, which is a very
useful gadget when compromising a process. The system call now verifies
it is a real return from a signal and aborts the process otherwise. This
should render such attacks impossible in threads that are not servicing a
signal, and infeasible in threads that are handling signals they are yet to
return from.

The kernel now keeps track for each thread how many signals are being
handled but haven't returned yet.

Each thread now has a random signal value. It is re-randomized when the
thread handles a signal and the current signal counter is zero. This is
xorred with the context address and used as canary on the stack during
signal dispatch, protecting the saved context on the stack. This works
mostly like the regular stack protector.

The kernel now keeps track of the stack pointer for a single handled
signal per thread. It doesn't seem worth it to keep track of multiple
handled signals, as more than one is rare. Note that each delivered signal
will not necessarily result in a sigreturn because it is valid for a thread
to longjmp(3) out of a signal handler to a valid jmp_buf.

The sigreturn system call will abort if either:

- It was not called from the kernel sigreturn page.
- The thread is not currently processing a signal.
- The thread is processing a single signal, and the stack pointer did not
  have the expected value.
- It fails to read the context on the stack.
- The canary is wrong.
2016-05-15 22:43:29 +02:00
Jonas 'Sortie' Termansen 9f77beaea6 Fix floating point registers of new threads. 2016-03-26 23:29:09 +01: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 af40496ffb Convert utils to C. 2016-03-03 23:02:24 +01:00
Jonas 'Sortie' Termansen 01b59c1947 Convert libc to C. 2016-03-03 23:02:23 +01:00
Jonas 'Sortie' Termansen 02c6316e95 Remove kernel debugger, old kernel US layout and kernel symbol code.
The debugger has fallen behind and has become a maintenance burden.  It was
the only user of the old kernel US layout system, which is good to get rid
of.  The debugger didn't work with graphical output and was likely to
conflict with the new keyboard system if used, which no longer triggered it.
The kernel symbol code was removed to simplify the kernel.

The kernel debugger was an useful debugging feature, but it needs to be done
in a better way before it can be added back.
2016-02-22 00:12:26 +01:00
Jonas 'Sortie' Termansen 4b1079510b Execute only programs with an executable bit set. 2016-01-25 17:39:57 +01:00
Jonas 'Sortie' Termansen 2e3d7c45af Add paging no-execute and write protection support.
Enable the NX bit on x86_64 and set if not PROT_EXEC and enable the write
protection mode (CR0.WP) that disables the default behavior where the kernel
is able to write to read-only memory. Fix kernel broken assumptions it can
access read-only memory and take care to never set PROT_KWRITE on user-space
pages unless PROT_WRITE is also set, otherwise user-space will be able to
write to read-only memory.

This achieves X^W in the whole system except for the core kernel itself as
it is currently don't know the purpose of pages when identity mapping the
first 4 MiB.
2016-01-25 17:39:57 +01:00
Jonas 'Sortie' Termansen ff8b2be515 Implement CLOCK_THREAD_CPUTIME_ID and CLOCK_THREAD_SYSTIME_ID. 2016-01-09 02:28:44 +01:00
Jonas 'Sortie' Termansen a45b93785c Fix program loading bugs. 2016-01-08 00:41:20 +01:00
Jonas 'Sortie' Termansen 4b6b06bbc8 Add scram(2). 2015-12-12 22:53:07 +01:00
Jonas 'Sortie' Termansen fc637c8880 Prevent orphan processes from becoming zombies. 2015-10-28 19:36:33 +01:00
Jonas 'Sortie' Termansen 158716f96a Fix ctype invocations with wrong domain. 2015-08-11 15:57:56 +02:00
Jonas 'Sortie' Termansen fffefeba8f Fix execve(2) keeping program descriptors open. 2015-07-09 19:20:49 +02:00
Jonas 'Sortie' Termansen 9acc74de28 Fix read-only mmap with backing store. 2015-06-27 17:06:33 +02:00
Jonas 'Sortie' Termansen bb70eef85b Replace system call array types with pointers. 2015-01-23 14:52:51 +01:00
Jonas 'Sortie' Termansen ab66b91086 Fix NOTO typo. 2014-12-28 20:18:58 +01:00
Jonas 'Sortie' Termansen bbf454e164 Rewrite program loader. 2014-12-04 16:14:17 +01:00
Jonas 'Sortie' Termansen 5143f01b0a Remove sbrk(2).
Note: This is an incompatible ABI change.
2014-12-03 23:55:55 +01:00
Jonas 'Sortie' Termansen ba1e0882ec Initialize system call table at compile time. 2014-12-03 14:19:49 +01:00
Jonas 'Sortie' Termansen ba12c1d246 Store loaded programs in special allocations rather than the kernel heap. 2014-11-26 22:27:57 +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 f8c5adf20f Add #! support to execve(2). 2014-11-26 21:14:13 +01:00
Jonas 'Sortie' Termansen 152d768112 Memory efficiently extract the initrd. 2014-11-24 22:32:57 +01:00
Jonas 'Sortie' Termansen 400eb2238f Refactor process id allocation and accounting. 2014-11-18 20:33:21 +01:00
Jonas 'Sortie' Termansen 25e07a9083 Refactor kernel interrupt and thread register support. 2014-11-18 20:33:21 +01:00
Jonas 'Sortie' Termansen cef4c8d982 Fix waitpid status copying to user-space. 2014-10-04 17:10:25 +02:00
Jonas 'Sortie' Termansen c0ad3d8a80 Fix error case in tfork(2). 2014-09-25 17:27:54 +02:00
Jonas 'Sortie' Termansen e29f0cdd1e Fix class process constructor forgetting some members. 2014-09-23 20:45:57 +02:00
Jonas 'Sortie' Termansen 6558de636e Fix tfork(2) not copying signal properties. 2014-09-23 20:45:57 +02:00
Jonas 'Sortie' Termansen 30cd318c17 Implement signals.
Note: This is an incompatible ABI change.
2014-07-22 13:25:39 +02:00
Jonas 'Sortie' Termansen 316ed84e60 Fix process constructor not zeroing the user timers. 2014-07-22 13:16:16 +02:00
Jonas 'Sortie' Termansen b4d494cf8b Implement thread creation in tfork(2). 2014-07-08 17:41:52 +02:00
Jonas 'Sortie' Termansen 8411dce330 Add kernel uthread support. 2014-07-08 17:41:50 +02:00
Jonas 'Sortie' Termansen fdcfb1f2da Handle ELF notes during program load. 2014-07-07 17:52:33 +02:00
Jonas 'Sortie' Termansen 874baffd57 Fix wrongly named system call constants. 2014-06-27 15:49:55 +02:00
Jonas 'Sortie' Termansen 1f72c1637c Maintain fsbase and gsbase as per-thread registers.
Note: This is an incompatible ABI change.
2014-05-29 17:07:42 +02:00
Jonas 'Sortie' Termansen 68d379c605 Fix insecure user-space pointer dereferences in sys_execve. 2014-05-16 16:58:33 +02:00
Jonas 'Sortie' Termansen 4283d90102 Fix memory leak of processes that are not process group leaders. 2014-05-16 14:48:27 +02:00
Jonas 'Sortie' Termansen da87b6f0aa Fix troublesome debug assertions in kernel/process.cpp. 2014-03-31 19:47:54 +02:00
Jonas 'Sortie' Termansen 2fe3595feb Add getumask(2). 2014-03-17 19:22:12 +01:00
Jonas 'Sortie' Termansen 98a87fa1e5 Rename Sortix kernel directory to kernel. 2014-03-01 14:37:39 +01:00
Renamed from sortix/process.cpp (Browse further)