]> xenbits.xensource.com Git - unikraft/unikraft.git/log
unikraft/unikraft.git
6 days agolib/posix-fdtab: Adapt to updated libposix-process config options
Michalis Pappas [Tue, 1 Apr 2025 15:29:39 +0000 (17:29 +0200)]
lib/posix-fdtab: Adapt to updated libposix-process config options

Following the consolidation of CONFIG_LIBPOSIX_PROCESS_PIDS and
CONFIG_LIBPOSIX_PROCESS_CLONE into LIBPOSIX_PROCESS_MULTITHREADING,
update to the new config.

Signed-off-by: Michalis Pappas <michalis@unikraft.io>
Approved-by: Andrei Tatar <andrei@unikraft.io>
Reviewed-by: Sergiu Moga <sergiu@unikraft.io>
Reviewed-by: Andrei Tatar <andrei@unikraft.io>
GitHub-Closes: #1627

6 days agolib/uklock: Adapt to updated libposix-process config options
Michalis Pappas [Tue, 1 Apr 2025 15:25:11 +0000 (17:25 +0200)]
lib/uklock: Adapt to updated libposix-process config options

Following the consolidation of CONFIG_LIBPOSIX_PROCESS_PIDS and
CONFIG_LIBPOSIX_PROCESS_CLONE into LIBPOSIX_PROCESS_MULTITHREADING,
update to the new config.

Signed-off-by: Michalis Pappas <michalis@unikraft.io>
Approved-by: Andrei Tatar <andrei@unikraft.io>
Reviewed-by: Sergiu Moga <sergiu@unikraft.io>
Reviewed-by: Andrei Tatar <andrei@unikraft.io>
GitHub-Closes: #1627

6 days agolib/nolibc: Adapt to updated libposix-process config options
Michalis Pappas [Tue, 1 Apr 2025 15:24:16 +0000 (17:24 +0200)]
lib/nolibc: Adapt to updated libposix-process config options

Following the consolidation of CONFIG_LIBPOSIX_PROCESS_PIDS and
CONFIG_LIBPOSIX_PROCESS_CLONE into LIBPOSIX_PROCESS_MULTITHREADING,
update to the new config.

Signed-off-by: Michalis Pappas <michalis@unikraft.io>
Approved-by: Andrei Tatar <andrei@unikraft.io>
Reviewed-by: Sergiu Moga <sergiu@unikraft.io>
Reviewed-by: Andrei Tatar <andrei@unikraft.io>
GitHub-Closes: #1627

6 days agolib/posix-futex: Adapt to updated libposix-process config options
Michalis Pappas [Tue, 1 Apr 2025 15:23:06 +0000 (17:23 +0200)]
lib/posix-futex: Adapt to updated libposix-process config options

Following the consolidation of CONFIG_LIBPOSIX_PROCESS_PIDS and
CONFIG_LIBPOSIX_PROCESS_CLONE into LIBPOSIX_PROCESS_MULTITHREADING,
update to the new config.

Signed-off-by: Michalis Pappas <michalis@unikraft.io>
Approved-by: Andrei Tatar <andrei@unikraft.io>
Reviewed-by: Sergiu Moga <sergiu@unikraft.io>
Reviewed-by: Andrei Tatar <andrei@unikraft.io>
GitHub-Closes: #1627

6 days agolib/syscall-shim: Adapt to updated libposix-process config options
Michalis Pappas [Tue, 1 Apr 2025 15:32:59 +0000 (17:32 +0200)]
lib/syscall-shim: Adapt to updated libposix-process config options

Following the consolidation of CONFIG_LIBPOSIX_PROCESS_PIDS and
CONFIG_LIBPOSIX_PROCESS_CLONE into LIBPOSIX_PROCESS_MULTITHREADING,
update to the new config.

Signed-off-by: Michalis Pappas <michalis@unikraft.io>
Approved-by: Andrei Tatar <andrei@unikraft.io>
Reviewed-by: Sergiu Moga <sergiu@unikraft.io>
Reviewed-by: Andrei Tatar <andrei@unikraft.io>
GitHub-Closes: #1627

6 days agolib/vfscore: Adapt to updated libposix-process config options
Michalis Pappas [Tue, 1 Apr 2025 15:20:37 +0000 (17:20 +0200)]
lib/vfscore: Adapt to updated libposix-process config options

Following the consolidation of CONFIG_LIBPOSIX_PROCESS_PIDS and
CONFIG_LIBPOSIX_PROCESS_CLONE into LIBPOSIX_PROCESS_MULTITHREADING,
update to the new config.

Signed-off-by: Michalis Pappas <michalis@unikraft.io>
Approved-by: Andrei Tatar <andrei@unikraft.io>
Reviewed-by: Sergiu Moga <sergiu@unikraft.io>
Reviewed-by: Andrei Tatar <andrei@unikraft.io>
GitHub-Closes: #1627

6 days agolib/posix-process: Consolidate assignment of pthread parent and self
Michalis Pappas [Mon, 7 Apr 2025 09:50:17 +0000 (11:50 +0200)]
lib/posix-process: Consolidate assignment of pthread parent and self

uk_posix_process_create() is missing the assignment of pthread_self.
Instead of having wrappers perform these assignments of parent and
self, move these assignments to the core functions that create and
release threads.

Signed-off-by: Michalis Pappas <michalis@unikraft.io>
Approved-by: Andrei Tatar <andrei@unikraft.io>
Reviewed-by: Sergiu Moga <sergiu@unikraft.io>
Reviewed-by: Andrei Tatar <andrei@unikraft.io>
GitHub-Closes: #1627

6 days agolib/posix-process: Restrict pthread creation to clone()
Michalis Pappas [Mon, 14 Apr 2025 19:47:15 +0000 (21:47 +0200)]
lib/posix-process: Restrict pthread creation to clone()

The current implementation incorrectly creates a pthread in the current
process, for every new uk_thread created. This behavior is problematic
because during a syscall, libraries may create uk_threads that are
intended to act as kernel threads. Decouple pthread initializaiton from
uk_thread and limit it to clone().

Signed-off-by: Michalis Pappas <michalis@unikraft.io>
Approved-by: Andrei Tatar <andrei@unikraft.io>
Reviewed-by: Sergiu Moga <sergiu@unikraft.io>
Reviewed-by: Andrei Tatar <andrei@unikraft.io>
GitHub-Closes: #1627

6 days agolib/posix-process: Add uk_posix_process_create_pthread()
Michalis Pappas [Mon, 14 Apr 2025 19:32:50 +0000 (21:32 +0200)]
lib/posix-process: Add uk_posix_process_create_pthread()

Provide a function to attach a thread to the current process. This is
intended to be exclusively used by app-elfloader when configured with
initrd, in order to assign the container thread it creates to the init
process.

Move uk_process_kill() to the internal API, and rename to avoid using
the naming convention of public functions, and deprecate the unused
uk_posix_process_create().

Checkpatch-Ignore: REPEATED_WORD
Signed-off-by: Michalis Pappas <michalis@unikraft.io>
Approved-by: Andrei Tatar <andrei@unikraft.io>
Reviewed-by: Sergiu Moga <sergiu@unikraft.io>
Reviewed-by: Andrei Tatar <andrei@unikraft.io>
GitHub-Closes: #1627

6 days agolib/posix-process: Deprecate POSIX_PROCESS_INIT_PIDS
Michalis Pappas [Mon, 19 Feb 2024 11:05:04 +0000 (12:05 +0100)]
lib/posix-process: Deprecate POSIX_PROCESS_INIT_PIDS

Retire POSIX_PROCESS_INIT_PIDS and assign PID 1 to the init process by
default. This improves consistency and reduces configuration complexity.

Signed-off-by: Michalis Pappas <michalis@unikraft.io>
Approved-by: Andrei Tatar <andrei@unikraft.io>
Reviewed-by: Sergiu Moga <sergiu@unikraft.io>
Reviewed-by: Andrei Tatar <andrei@unikraft.io>
GitHub-Closes: #1627

6 days agolib/posix-process: Refactor Kconfig options
Michalis Pappas [Wed, 19 Mar 2025 07:14:56 +0000 (08:14 +0100)]
lib/posix-process: Refactor Kconfig options

Replace CONFIG_LIBPOSIX_PROCESS_PIDS and CONFIG_LIBPOSIX_PROCESS_CLONE
with a single option, CONFIG_LIBPOSIX_PROCESS_MULTITHREADING. This
option enables clone(), _exit(), and exit_group() syscalls as well as
the core logic of libposix-process. Make options previously relevant
to CONFIG_LIBPOSIX_PROCESS_CLONE move to subselection of multithreading.

Without CONFIG_LIBPOSIX_PROCESS_MULTITHREADING the implementation falls
back into stubs. This provides an execution environment for simple
libc-based applications that don't require multithreading, but still
need to execute under a process-like environment. Under this state,
the syscalls involved in multithreading (or multiprocess) return an
error, while others are emulated. Notice that if Unikraft is not configured
to execute main() in a separate uk_thread (i.e. LIBUKBOOT_MAINTHREAD),
_exit() and exit_group() are not available.

Introduce a new config option to enable multiprocess support, namely
CONFIG_LIBPOSIX_PROCESS_MULTIPROCESS. This option replaces the config
option of vfork(), and enforces the selection of multithreading and
execve().

Signed-off-by: Michalis Pappas <michalis@unikraft.io>
Approved-by: Andrei Tatar <andrei@unikraft.io>
Reviewed-by: Sergiu Moga <sergiu@unikraft.io>
Reviewed-by: Andrei Tatar <andrei@unikraft.io>
GitHub-Closes: #1627

6 days agolib: Add Kconfig option to signify support of VFS
Michalis Pappas [Mon, 14 Apr 2025 10:03:20 +0000 (12:03 +0200)]
lib: Add Kconfig option to signify support of VFS

Add HAVE_VFS option in Kconfig for features that depend on VFS support,
and remove redundant defaults. Update libvfscore to select HAVE_VFS.

Signed-off-by: Michalis Pappas <michalis@unikraft.io>
Approved-by: Andrei Tatar <andrei@unikraft.io>
Reviewed-by: Sergiu Moga <sergiu@unikraft.io>
Reviewed-by: Andrei Tatar <andrei@unikraft.io>
GitHub-Closes: #1627

6 days agolib/ukrandom: Validate getrandom input & rm assert
Andrei Tatar [Tue, 29 Apr 2025 15:57:40 +0000 (17:57 +0200)]
lib/ukrandom: Validate getrandom input & rm assert

This change removes the assert on the buffer argument to the getrandom
syscall and replaces it with defined input validation, based on observed
behavior in Linux:
- if the requested number of bytes is 0, getrandom shortcuts to success
- if buffer is NULL and > 0 bytes requested, return -EFAULT instead of
  crashing

Signed-off-by: Andrei Tatar <andrei@unikraft.io>
Approved-by: Michalis Pappas <michalis@unikraft.io>
Reviewed-by: Michalis Pappas <michalis@unikraft.io>
GitHub-Closes: #1637

7 days agolib/vfscore: Fix write const path in automount
Andrei Tatar [Tue, 29 Apr 2025 13:54:03 +0000 (15:54 +0200)]
lib/vfscore: Fix write const path in automount

Previously vfscore_mount_volume would pass a const path to
vfscore_ukopt_mkmp, which expects a mutable path, and indeed does modify
it in-place during execution. This is wrong and rightfully triggers a
compiler warning.
This change fixes this by having mkmp allocate a temporary writable path.

Checkpatch-Ignore: STRCPY
Signed-off-by: Andrei Tatar <andrei@unikraft.io>
Reviewed-by: Michalis Pappas <michalis@unikraft.io>
Approved-by: Michalis Pappas <michalis@unikraft.io>
GitHub-Closes: #1636

12 days agolib/posix-fdtab: Fix exec handler target fdtab stable
Andrei Tatar [Thu, 24 Apr 2025 13:07:31 +0000 (15:07 +0200)]
lib/posix-fdtab: Fix exec handler target fdtab

This change makes the exec handler cloexec the target thread's fdtab
instead of that of the calling thread's.

Signed-off-by: Andrei Tatar <andrei@unikraft.io>
Approved-by: Michalis Pappas <michalis@unikraft.io>
Reviewed-by: Michalis Pappas <michalis@unikraft.io>
GitHub-Closes: #1617

12 days agolib/posix-fdtab: Fix ref leak on fdtab clone
Andrei Tatar [Fri, 21 Mar 2025 09:44:00 +0000 (10:44 +0100)]
lib/posix-fdtab: Fix ref leak on fdtab clone

This change adds a missing ref release of the previous fdtab instance on
clone, leading to a reference (and thus memory) leak with multi-fdtab.

Signed-off-by: Andrei Tatar <andrei@unikraft.io>
Approved-by: Michalis Pappas <michalis@unikraft.io>
Reviewed-by: Michalis Pappas <michalis@unikraft.io>
GitHub-Closes: #1617

13 days agolib/nolibc: Import `signalfd` definitions from `musl`
Sergiu Moga [Thu, 20 Mar 2025 18:56:10 +0000 (20:56 +0200)]
lib/nolibc: Import `signalfd` definitions from `musl`

Import `musl`'s header for `signalfd` definitions to allow
nolibc builds a way to call into the signalfd implementation.

Source of import:
Repository: https://git.musl-libc.org/cgit/musl
Tag: v1.2.4 (f5f55d65)
Path: include/sys/signalfd.h

Checkpatch-Ignore: SPDX_LICENSE_TAG
Checkpatch-Ignore: FUNCTION_ARGUMENTS
Checkpatch-Ignore: PREFER_KERNEL_TYPES
Checkpatch-Ignore: SPACING
Checkpatch-Ignore: COMMIT_LOG_USE_LINK
Signed-off-by: Sergiu Moga <sergiu@unikraft.io>
Approved-by: Michalis Pappas <michalis@unikraft.io>
Reviewed-by: Michalis Pappas <michalis@unikraft.io>
Reviewed-by: Andrei Tatar <andrei@unikraft.io>
GitHub-Closes: #1619

13 days agolib/posix-process: Notify process/thread signal files when possible
Sergiu Moga [Thu, 20 Mar 2025 18:51:06 +0000 (20:51 +0200)]
lib/posix-process: Notify process/thread signal files when possible

Whenever a signal shouldn't be dropped, meaning it is either not ignored by
the process or the process has signal files that are monitoring that
particular signal, notify the existing signal files in question
 of the posix thread/process by setting the input event on said files.

Signed-off-by: Sergiu Moga <sergiu@unikraft.io>
Approved-by: Michalis Pappas <michalis@unikraft.io>
Reviewed-by: Michalis Pappas <michalis@unikraft.io>
Reviewed-by: Andrei Tatar <andrei@unikraft.io>
GitHub-Closes: #1619

13 days agolib/posix-process: Init signal files ctx on signal desc creation
Sergiu Moga [Thu, 20 Mar 2025 18:46:01 +0000 (20:46 +0200)]
lib/posix-process: Init signal files ctx on signal desc creation

We have two initialization places for the signal files context of a
signal files context:
- on vfork when a child process is born and its signal descriptor is
correspondingly inherited from the parent
- on signal descriptor initialization on regular process creation

For the former, at this time, we do not support proper open file
inheritance across vfork/execve for those that do not have the
O_CLOEXEC flag. Therefore, for now, simply just initialize child
process' signal descriptor signal file context as empty.

Signed-off-by: Sergiu Moga <sergiu@unikraft.io>
Approved-by: Michalis Pappas <michalis@unikraft.io>
Reviewed-by: Michalis Pappas <michalis@unikraft.io>
Reviewed-by: Andrei Tatar <andrei@unikraft.io>
GitHub-Closes: #1619

13 days agolib/posix-process: Add `signalfd`/`signalfd4` support
Sergiu Moga [Thu, 20 Mar 2025 17:54:14 +0000 (19:54 +0200)]
lib/posix-process: Add `signalfd`/`signalfd4` support

Add support for the `signalfd`/`signalfd4` syscalls which will
allow callers to add monitored signal files to the current process,
allowing them to be notified of pending signals.

Introduce the primitives required for supporting signalfd: signal files.

These embed the actual base file structure, the mask that shows what
signals are being monitored as well as other file data to properly
register with libukfile.

Each process' signal descriptor holds control over the signal files
context which tracks the combined mask of all of the open signal files
as well as a list of their references. Having a combined mask helps
to make checking to see whether a process has signal files monitoring
for a given signal faster as compared to iterating every time through
each signal file and checking their masks.

Thus, adding a new signal file entry means updating the combined mask.
Deleting one implies resetting the signal mask and reiterating
through all remaining signal files for a proper combined mask. However,
as an optimization, we don't do that. Instead, we defer mask
recalculation until we need to reiterate through the signal files
again, which is when we have to notify the registered signal files
against a signal number.

Signed-off-by: Sergiu Moga <sergiu@unikraft.io>
Approved-by: Michalis Pappas <michalis@unikraft.io>
Reviewed-by: Michalis Pappas <michalis@unikraft.io>
Reviewed-by: Andrei Tatar <andrei@unikraft.io>
GitHub-Closes: #1619

13 days agolib/posix-fdtab: Fix docstring of `uk_fdtab_open`
Sergiu Moga [Thu, 27 Mar 2025 17:30:49 +0000 (19:30 +0200)]
lib/posix-fdtab: Fix docstring of `uk_fdtab_open`

Commit 5050e9f11e57 ("lib/posix-fd: Move heap-alloc ofiles out of fdtab")
did `s/uk_fdtab_ret/uk_ofile_release` across the codebase but forgot to
update the comment for `uk_fdtab_open`. Do so now, indicating to use
`uk_ofile_release` instead.

Signed-off-by: Sergiu Moga <sergiu@unikraft.io>
Approved-by: Michalis Pappas <michalis@unikraft.io>
Reviewed-by: Michalis Pappas <michalis@unikraft.io>
Reviewed-by: Andrei Tatar <andrei@unikraft.io>
GitHub-Closes: #1619

13 days agolib/ukfile: Add `uk_iov_remaining` to help tell remaining iov space
Sergiu Moga [Wed, 26 Mar 2025 16:09:51 +0000 (18:09 +0200)]
lib/ukfile: Add `uk_iov_remaining` to help tell remaining iov space

Add a new routine `uk_iov_remaining` that simply checks how many bytes
the memory regions described by `iov[iovcnt]`, starting at `cur` offset
from the buffer at `iov[iovi]` can fit.

Signed-off-by: Sergiu Moga <sergiu@unikraft.io>
Approved-by: Michalis Pappas <michalis@unikraft.io>
Reviewed-by: Michalis Pappas <michalis@unikraft.io>
Reviewed-by: Andrei Tatar <andrei@unikraft.io>
GitHub-Closes: #1619

2 weeks agolib/posix-process/signal: Add stub for CLONE_SIGHAND
Michalis Pappas [Thu, 3 Apr 2025 13:04:25 +0000 (15:04 +0200)]
lib/posix-process/signal: Add stub for CLONE_SIGHAND

Provide stub for CLONE_SIGHAND when LIBPOSIX_PROCESS_SIGNAL
is not selected. This prevents clone() from returning -ENOTSUP
when signals are not selected.

Signed-off-by: Michalis Pappas <michalis@unikraft.io>
Approved-by: Andrei Tatar <andrei@unikraft.io>
Reviewed-by: Sergiu Moga <sergiu@unikraft.io>
GitHub-Closes: #1628

2 weeks agolib/posix-process/signals: Fix conditional for sigsetops
Michalis Pappas [Tue, 1 Apr 2025 05:57:45 +0000 (07:57 +0200)]
lib/posix-process/signals: Fix conditional for sigsetops

The implementation of sigsetops was conditional to HAVE_LIBC instead of
CONFIG_HAVE_LIBC, causing a build error when musl is used, due to the
definiton of sigset_t to different types. Update the conditional to fix.
Notice that this works as each flavor of libc controls both the type
and the implementation of the functions that operate on it.

Signed-off-by: Michalis Pappas <michalis@unikraft.io>
Reviewed-by: Sergiu Moga <sergiu@unikraft.io>
Reviewed-by: Andrei Tatar <andrei@unikraft.io>
Approved-by: Andrei Tatar <andrei@unikraft.io>
GitHub-Closes: #1626

2 weeks agolib/posix-process: Create PID1 from the thread passed in init
Michalis Pappas [Wed, 26 Mar 2025 04:47:09 +0000 (05:47 +0100)]
lib/posix-process: Create PID1 from the thread passed in init

Update the instantiation of INIT_PID to use the thread passed in the
init context. This allows excluding unikraft's init thread from the
process when libukboot creates a separate thread for main().

Signed-off-by: Michalis Pappas <michalis@unikraft.io>
Approved-by: Andrei Tatar <andrei@unikraft.io>
Approved-by: Sergiu Moga <sergiu@unikraft.io>
Reviewed-by: Andrei Tatar <andrei@unikraft.io>
Reviewed-by: Sergiu Moga <sergiu@unikraft.io>
GitHub-Closes: #1620

2 weeks agolib/ukboot: Pass tmain to init context
Michalis Pappas [Tue, 25 Mar 2025 08:09:50 +0000 (09:09 +0100)]
lib/ukboot: Pass tmain to init context

Populate the init context with the thread that executes main().
When LIBUKBOOT_MAINTHREAD is selected, this allows libposix-process
to create INIT_PID from the main thread while excluding Unikraft's
init thread from the process.

Move the initialization of the main() thread before executing inittab.
With that change, update the parameters main_thread() function to pass
a pointer to ictx, so that it's possible for args to be updated by
inittab.

Signed-off-by: Michalis Pappas <michalis@unikraft.io>
Approved-by: Andrei Tatar <andrei@unikraft.io>
Approved-by: Sergiu Moga <sergiu@unikraft.io>
Reviewed-by: Andrei Tatar <andrei@unikraft.io>
Reviewed-by: Sergiu Moga <sergiu@unikraft.io>
GitHub-Closes: #1620

2 weeks agoinclude/uk/init: Add main thread to init ctx
Michalis Pappas [Tue, 25 Mar 2025 14:46:10 +0000 (15:46 +0100)]
include/uk/init: Add main thread to init ctx

Add a new field to init ctx for the thread that executes main().
If main() does not execute on a separate thread, this is set to
NULL.

Signed-off-by: Michalis Pappas <michalis@unikraft.io>
Approved-by: Andrei Tatar <andrei@unikraft.io>
Approved-by: Sergiu Moga <sergiu@unikraft.io>
Reviewed-by: Andrei Tatar <andrei@unikraft.io>
Reviewed-by: Sergiu Moga <sergiu@unikraft.io>
GitHub-Closes: #1620

2 weeks agolib/posix-process: Define `libc` wrappers for `vfork`
Sergiu Moga [Mon, 24 Mar 2025 17:00:35 +0000 (19:00 +0200)]
lib/posix-process: Define `libc` wrappers for `vfork`

It is impossible to write the libc wrapper of the `vfork` system call
in C since the child might end up reusing and overwriting the parent's
return address when it pops it and then calls `execve`, leaving the
parent to return to an invalid state - typically would overwrite it
with the return address from execve, making it look as if the parent
returned from execve.

Userspace libc's solve this by writing the libc wrapper as something
among the lines of:
popq %<register that the syscall guarantees to preserve>
movq $SYS_vfork, %rax
syscall
pushq %<register we popped return address into 3 lines above>
ret

On ARM64 as well as others, clone() with the flags
`SIGCHLD | CLONE_VM | CLONE_VFORK` is called instead but let's just
still use our `vfork` implementation since it essentially also does
the same exact thing.

However, as a Unikernel with function calls for system calls we do
not need to care about any of that, as our execenv prologue can store
and restore everything without touching the stack. Thus, we can write
our native libc wrappers as a basic jump/branch to said prologue.

Signed-off-by: Sergiu Moga <sergiu@unikraft.io>
Approved-by: Michalis Pappas <michalis@unikraft.io>
Reviewed-by: Michalis Pappas <michalis@unikraft.io>
Reviewed-by: Andrei Tatar <andrei@unikraft.io>
GitHub-Closes: #1618

2 weeks agolib/posix-process: Fix `vfork` signature
Sergiu Moga [Mon, 24 Mar 2025 16:58:57 +0000 (18:58 +0200)]
lib/posix-process: Fix `vfork` signature

A minor oversight during merging of the `vfork` functionality ended
up defining `vfork` with an invalid signature that takes two arguments.

Fix this by defining `vfork` as a syscall that takes no arguments.

Signed-off-by: Sergiu Moga <sergiu@unikraft.io>
Approved-by: Michalis Pappas <michalis@unikraft.io>
Reviewed-by: Michalis Pappas <michalis@unikraft.io>
Reviewed-by: Andrei Tatar <andrei@unikraft.io>
GitHub-Closes: #1618

2 weeks agolib/posix-process: Add `libc` system call wrapper for `clone`
Sergiu Moga [Mon, 24 Mar 2025 16:52:48 +0000 (18:52 +0200)]
lib/posix-process: Add `libc` system call wrapper for `clone`

In order to successfully call the clone system call through a libc
wrapper we need to be able to have an assembly sequence that both
translates the arguments passed by the libc wrapper to those of the
underlying syscall, since their signatures differ, as well as redirect
the parent and child accordingly upon exit from said syscall: child
must run its requested function and argument and parent must return
to the clone caller with an unscathed register context.

Said assembly sequence must be aware of the signature differences
between architectures, e.g. ARM64 vs x86_64 signatures of the
clone system call.

Signed-off-by: Sergiu Moga <sergiu@unikraft.io>
Approved-by: Michalis Pappas <michalis@unikraft.io>
Reviewed-by: Michalis Pappas <michalis@unikraft.io>
Reviewed-by: Andrei Tatar <andrei@unikraft.io>
GitHub-Closes: #1618

2 weeks agolib/syscall_shim: Make `UK_LIBC_SYSCALLS` visible in asm files
Sergiu Moga [Fri, 28 Mar 2025 10:43:46 +0000 (12:43 +0200)]
lib/syscall_shim: Make `UK_LIBC_SYSCALLS` visible in asm files

Define `UK_LIBC_SYSCALLS` outside the `!__ASSEMBLY__` guard so that
assembly files can see it.

Signed-off-by: Sergiu Moga <sergiu@unikraft.io>
Approved-by: Michalis Pappas <michalis@unikraft.io>
Reviewed-by: Michalis Pappas <michalis@unikraft.io>
Reviewed-by: Andrei Tatar <andrei@unikraft.io>
GitHub-Closes: #1618

2 weeks agolib/syscall_shim/arch/x86_64: Restore `RIP` from the auxiliary stack
Sergiu Moga [Mon, 24 Mar 2025 16:46:16 +0000 (18:46 +0200)]
lib/syscall_shim/arch/x86_64: Restore `RIP` from the auxiliary stack

Before this patch, we would simply rely on the original pushed RIP
following the call instruction that got to our assembly wrapper.
However this may not be the same in cases such as those of the clone
or vfork system calls if the child were to reuse the stack: the child
could pop the return address before the parent gets the chance to do it
and even call some other functions (like execve), overwriting whatever
previously was at the bottom of the stack that the parent had prior
to invoking the system call.

To solve this, simply use the RIP pushed at the beginning of the wrapper
instead of assuming the bottom of the stack is untouched.

Signed-off-by: Sergiu Moga <sergiu@unikraft.io>
Approved-by: Michalis Pappas <michalis@unikraft.io>
Reviewed-by: Michalis Pappas <michalis@unikraft.io>
Reviewed-by: Andrei Tatar <andrei@unikraft.io>
GitHub-Closes: #1618

2 weeks agolib/syscall_shim/arch/arm64: Store caller's link register
Sergiu Moga [Mon, 24 Mar 2025 16:42:17 +0000 (18:42 +0200)]
lib/syscall_shim/arch/arm64: Store caller's link register

So far for storing LR and ELR_EL1 we have been using the current
link register for both instead. This does not reflect reality when
it comes to LR as we should instead store the LR that the caller
would know. To achieve this, do a brief level 1 stack unwinding and
fetch caller's LR from the top of its frame.

Signed-off-by: Sergiu Moga <sergiu@unikraft.io>
Approved-by: Michalis Pappas <michalis@unikraft.io>
Reviewed-by: Michalis Pappas <michalis@unikraft.io>
Reviewed-by: Andrei Tatar <andrei@unikraft.io>
GitHub-Closes: #1618

2 weeks agoarch: Define regular function calling convention register arguments
Sergiu Moga [Mon, 24 Mar 2025 16:34:28 +0000 (18:34 +0200)]
arch: Define regular function calling convention register arguments

Define the macros that one could use to access the registers within
`struct __regs` that represent the ABI/calling convention specific
that contain the arguments (and the return value).

Signed-off-by: Sergiu Moga <sergiu@unikraft.io>
Approved-by: Michalis Pappas <michalis@unikraft.io>
Reviewed-by: Michalis Pappas <michalis@unikraft.io>
Reviewed-by: Andrei Tatar <andrei@unikraft.io>
GitHub-Closes: #1618

2 weeks agolib/syscall_shim: Add `uk_syscall_do_` syms for execenv registrations
Sergiu Moga [Mon, 24 Mar 2025 09:03:56 +0000 (11:03 +0200)]
lib/syscall_shim: Add `uk_syscall_do_` syms for execenv registrations

Because of the unnecessary conditional during syscall symbols
generation, execenv syscall registrations would not benefit from
having their `uk_syscall_do_` symbol generated automatically.
Fix this by removing this conditional.

Signed-off-by: Sergiu Moga <sergiu@unikraft.io>
Approved-by: Michalis Pappas <michalis@unikraft.io>
Reviewed-by: Michalis Pappas <michalis@unikraft.io>
Reviewed-by: Andrei Tatar <andrei@unikraft.io>
GitHub-Closes: #1618

2 weeks agolib/posix-process: Register `execve` using non-LL variant
Sergiu Moga [Wed, 19 Mar 2025 15:15:00 +0000 (17:15 +0200)]
lib/posix-process: Register `execve` using non-LL variant

Use the non-LL variant of execenv-based syscall registration for
execenv so that we will automatically have a corresponding libc
wrapper defined.

Signed-off-by: Sergiu Moga <sergiu@unikraft.io>
Approved-by: Michalis Pappas <michalis@unikraft.io>
Reviewed-by: Michalis Pappas <michalis@unikraft.io>
Reviewed-by: Andrei Tatar <andrei@unikraft.io>
GitHub-Closes: #1618

2 weeks agolib/syscall_shim: Remove unnecessary `__used` from execenv variants
Sergiu Moga [Wed, 19 Mar 2025 15:14:10 +0000 (17:14 +0200)]
lib/syscall_shim: Remove unnecessary `__used` from execenv variants

The `__used` attribute in not necessary as we are fine with any of
these potentially being optimised away.

Signed-off-by: Sergiu Moga <sergiu@unikraft.io>
Approved-by: Michalis Pappas <michalis@unikraft.io>
Reviewed-by: Michalis Pappas <michalis@unikraft.io>
Reviewed-by: Andrei Tatar <andrei@unikraft.io>
GitHub-Closes: #1618

2 weeks agolib/syscall_shim: Add non-LL execenv syscall registration variant
Sergiu Moga [Wed, 19 Mar 2025 15:11:28 +0000 (17:11 +0200)]
lib/syscall_shim: Add non-LL execenv syscall registration variant

Based on UK_LLSYSCALL_R_E_DEFINE and provides a libc-style wrapper
in case UK_LIBC_SYSCALLS is enabled.

(Similar to its UK_SYSCALL_R_DEFINE, non-execenv variants)

Checkpatch-Ignore: MACRO_ARG_REUSE
Checkpatch-Ignore: COMPLEX_MACRO
Checkpatch-Ignore: SPACING
Signed-off-by: Sergiu Moga <sergiu@unikraft.io>
Approved-by: Michalis Pappas <michalis@unikraft.io>
Reviewed-by: Michalis Pappas <michalis@unikraft.io>
Reviewed-by: Andrei Tatar <andrei@unikraft.io>
GitHub-Closes: #1618

2 weeks agolib/syscall_shim/arch/x86_64: Save proper rsp in execenv prologue
Sergiu Moga [Wed, 19 Mar 2025 14:31:50 +0000 (16:31 +0200)]
lib/syscall_shim/arch/x86_64: Save proper rsp in execenv prologue

In the execenv prologue meant for native builds we try to mimic the
context save/restore that would happen following a syscall instruction
but in the case of a direct call instruction. This means that the rsp
on entry is actually 8 bytes less than the rsp we are supposed to show
to actual users of this execenv. To cope with this, after pushing the
original rsp do an addition of 8 so that children (e.g. vfork) that may
inherit this context have the proper rsp. Lastly, because of this, upon
exiting the execenv assembly wrapper we must ensure that the context
whose execenv we store/restore is using the proper rsp as well by
undoing aforementioned addition, since it actually returns like a normal
function through ret.

This bug hasn't been caught before because we've only been using this
in the context of the clone syscall for native builds. Unlike vfork,
in the case of clone, the children typically begin execution with a
brand new stack instead of reusing and mimicking that of the parent.

Signed-off-by: Sergiu Moga <sergiu@unikraft.io>
Approved-by: Michalis Pappas <michalis@unikraft.io>
Reviewed-by: Michalis Pappas <michalis@unikraft.io>
Reviewed-by: Andrei Tatar <andrei@unikraft.io>
GitHub-Closes: #1618

2 weeks agolib/syscall_shim: Use global scope inline asm for execenv prologue
Sergiu Moga [Mon, 10 Mar 2025 16:24:54 +0000 (18:24 +0200)]
lib/syscall_shim: Use global scope inline asm for execenv prologue

Avoid having to use weird and unconventional function attributes by
writing the inline assembly in a global scope. This is especially
useful for ARM64 as it does not support the naked attribute on GCC.

Signed-off-by: Sergiu Moga <sergiu@unikraft.io>
Approved-by: Andrei Tatar <andrei@unikraft.io>
Reviewed-by: Andrei Tatar <andrei@unikraft.io>
Reviewed-by: Michalis Pappas <michalis@unikraft.io>
GitHub-Closes: #1598

5 weeks agolib/posix-fd: Move heap-alloc ofiles out of fdtab
Andrei Tatar [Tue, 18 Mar 2025 16:55:34 +0000 (17:55 +0100)]
lib/posix-fd: Move heap-alloc ofiles out of fdtab

This change moves the responsibility for allocating, managing the
lifetime of, and freeing heap-allocated open file descriptions out of
individual fdtab instances and into the main posix-fd API.
This allows libraries to create kernel-wide dynamic open file
descriptions independent of an fdtab.

Signed-off-by: Andrei Tatar <andrei@unikraft.io>
Approved-by: Sergiu Moga <sergiu@unikraft.io>
Reviewed-by: Sergiu Moga <sergiu@unikraft.io>
GitHub-Closes: #1602

5 weeks agolib/posix-fdio: Fix missing error in fcntl(GETFD)
Andrei Tatar [Tue, 18 Mar 2025 16:48:20 +0000 (17:48 +0100)]
lib/posix-fdio: Fix missing error in fcntl(GETFD)

This change fixes a bug where fcntl(F_GETFD) would swallow error codes
from uk_fdtab_getflags and not return them up the callstack.

Signed-off-by: Andrei Tatar <andrei@unikraft.io>
Approved-by: Sergiu Moga <sergiu@unikraft.io>
Reviewed-by: Sergiu Moga <sergiu@unikraft.io>
GitHub-Closes: #1602

5 weeks agolib/posix-fdio: Fix lseek relative from file end
Andrei Tatar [Tue, 18 Mar 2025 16:43:38 +0000 (17:43 +0100)]
lib/posix-fdio: Fix lseek relative from file end

This change fixes a bug in lseek where the file cursor was always set to
the end of file on SEEK_END, ignoring any passed-in offset.

Signed-off-by: Andrei Tatar <andrei@unikraft.io>
Approved-by: Sergiu Moga <sergiu@unikraft.io>
Reviewed-by: Sergiu Moga <sergiu@unikraft.io>
GitHub-Closes: #1602

5 weeks agolib/posix-fdio: Fix lseek error on readonly files
Andrei Tatar [Tue, 18 Mar 2025 16:37:54 +0000 (17:37 +0100)]
lib/posix-fdio: Fix lseek error on readonly files

Previously lseek would wrongly fail when seeking a read-only-opened
file due to a logic error. This change fixes this oversight.

Signed-off-by: Andrei Tatar <andrei@unikraft.io>
Approved-by: Sergiu Moga <sergiu@unikraft.io>
Reviewed-by: Sergiu Moga <sergiu@unikraft.io>
GitHub-Closes: #1602

5 weeks agolib/posix-pipe: Add pipe stat support
Andrei Tatar [Wed, 19 Mar 2025 12:37:23 +0000 (13:37 +0100)]
lib/posix-pipe: Add pipe stat support

This change implements a real getstat operation for pipes, returning
basic information about an open pipe.

Signed-off-by: Andrei Tatar <andrei@unikraft.io>
Approved-by: Sergiu Moga <sergiu@unikraft.io>
Reviewed-by: Sergiu Moga <sergiu@unikraft.io>
GitHub-Closes: #1603

5 weeks agolib/posix-process: Make header definitions conditional to PIDS
Michalis Pappas [Tue, 18 Mar 2025 10:16:59 +0000 (11:16 +0100)]
lib/posix-process: Make header definitions conditional to PIDS

Make definitions in private process.h conditional to
CONFIG_LIBPOSIX_PROCESS_PIDS to prevent compile errors if that header
is if that header is included by files compiled unconditionally to
CONFIG_LIBPOSIX_PROCESS_PIDS.

Signed-off-by: Michalis Pappas <michalis@unikraft.io>
Reviewed-by: Ioan-Teodor Teugea <ioan_teodor.teugea@stud.acs.upb.ro>
Reviewed-by: Sergiu Moga <sergiu@unikraft.io>
Reviewed-by: Andrei Tatar <andrei@unikraft.io>
Approved-by: Andrei Tatar <andrei@unikraft.io>
GitHub-Closes: #1248

5 weeks agolib/posix-process: Resolve warning about struct clone_args
Michalis Pappas [Mon, 17 Feb 2025 13:11:31 +0000 (14:11 +0100)]
lib/posix-process: Resolve warning about struct clone_args

Include the kernel version of sched.h to resolve a missing
definition compiler warning on `struct clone_args`

Signed-off-by: Michalis Pappas <michalis@unikraft.io>
Reviewed-by: Ioan-Teodor Teugea <ioan_teodor.teugea@stud.acs.upb.ro>
Reviewed-by: Sergiu Moga <sergiu@unikraft.io>
Reviewed-by: Andrei Tatar <andrei@unikraft.io>
Approved-by: Andrei Tatar <andrei@unikraft.io>
GitHub-Closes: #1248

5 weeks agolib/uksignal: Retire libuksignal
Michalis Pappas [Fri, 26 Jan 2024 02:58:05 +0000 (03:58 +0100)]
lib/uksignal: Retire libuksignal

Retire libuksignal in favor of the new implementation introduced
in libposix-process. Stubs of equivalent functionality previously
provided in libuksignal are still available in libposix-process,
when CONFIG_POSIX_PROCESS_SIGNAL is not selected.

Signed-off-by: Michalis Pappas <michalis@unikraft.io>
Reviewed-by: Ioan-Teodor Teugea <ioan_teodor.teugea@stud.acs.upb.ro>
Reviewed-by: Sergiu Moga <sergiu@unikraft.io>
Reviewed-by: Andrei Tatar <andrei@unikraft.io>
Approved-by: Andrei Tatar <andrei@unikraft.io>
GitHub-Closes: #1248

5 weeks agolib/posix-process/signals: Add libc wrappers for POSIX sigsetops
Michalis Pappas [Mon, 24 Mar 2025 05:11:27 +0000 (06:11 +0100)]
lib/posix-process/signals: Add libc wrappers for POSIX sigsetops

Add libc wrappers for signal set operations. For more info
see sigsetops(3).

Signed-off-by: Michalis Pappas <michalis@unikraft.io>
Reviewed-by: Ioan-Teodor Teugea <ioan_teodor.teugea@stud.acs.upb.ro>
Reviewed-by: Sergiu Moga <sergiu@unikraft.io>
Reviewed-by: Andrei Tatar <andrei@unikraft.io>
Approved-by: Andrei Tatar <andrei@unikraft.io>
GitHub-Closes: #1248

5 weeks agolib/posix-process/signal: Add stub for alarm()
Michalis Pappas [Tue, 19 Mar 2024 10:56:30 +0000 (11:56 +0100)]
lib/posix-process/signal: Add stub for alarm()

Add stub for alarm() to get on par with libuksignal.

Signed-off-by: Michalis Pappas <michalis@unikraft.io>
Reviewed-by: Ioan-Teodor Teugea <ioan_teodor.teugea@stud.acs.upb.ro>
Reviewed-by: Sergiu Moga <sergiu@unikraft.io>
Reviewed-by: Andrei Tatar <andrei@unikraft.io>
Approved-by: Andrei Tatar <andrei@unikraft.io>
GitHub-Closes: #1248

5 weeks agolib/posix-process/signal: Add rt_sigtimedwait()
Michalis Pappas [Fri, 26 Jan 2024 02:53:09 +0000 (03:53 +0100)]
lib/posix-process/signal: Add rt_sigtimedwait()

rt_sigtimedwait() suspends the execution of the calling thread until a
signal in a caller-provided mask is pending, or a caller provided
timeout is reached. For more info see sigwaitinfo(2)

Signed-off-by: Michalis Pappas <michalis@unikraft.io>
Reviewed-by: Ioan-Teodor Teugea <ioan_teodor.teugea@stud.acs.upb.ro>
Reviewed-by: Sergiu Moga <sergiu@unikraft.io>
Reviewed-by: Andrei Tatar <andrei@unikraft.io>
Approved-by: Andrei Tatar <andrei@unikraft.io>
GitHub-Closes: #1248

5 weeks agolib/posix-process/signal: Add sigsuspend()
Michalis Pappas [Tue, 16 Jan 2024 11:49:36 +0000 (12:49 +0100)]
lib/posix-process/signal: Add sigsuspend()

sigsuspend() temporarily replaces the signal mask of the current
thread and suspends its execution until a signal is delivered.
For more info see sigsuspend(2)

Signed-off-by: Michalis Pappas <michalis@unikraft.io>
Reviewed-by: Ioan-Teodor Teugea <ioan_teodor.teugea@stud.acs.upb.ro>
Reviewed-by: Sergiu Moga <sergiu@unikraft.io>
Reviewed-by: Andrei Tatar <andrei@unikraft.io>
Approved-by: Andrei Tatar <andrei@unikraft.io>
GitHub-Closes: #1248

5 weeks agolib/posix-process/signal: Add pause()
Michalis Pappas [Mon, 15 Jan 2024 06:13:31 +0000 (07:13 +0100)]
lib/posix-process/signal: Add pause()

pause() causes the calling thread to sleep until
a signal is delivered. For more info see pause(2)

Signed-off-by: Michalis Pappas <michalis@unikraft.io>
Reviewed-by: Ioan-Teodor Teugea <ioan_teodor.teugea@stud.acs.upb.ro>
Reviewed-by: Sergiu Moga <sergiu@unikraft.io>
Reviewed-by: Andrei Tatar <andrei@unikraft.io>
Approved-by: Andrei Tatar <andrei@unikraft.io>
GitHub-Closes: #1248

5 weeks agolib/posix-process/signal: Add signal delivery
Michalis Pappas [Wed, 3 Jan 2024 11:36:37 +0000 (12:36 +0100)]
lib/posix-process/signal: Add signal delivery

Implement signal delivery. Signals are delivered at syscall exit
by registering a handler to the syscall shim. The same handler
could be potentially register a handler to a preemptive scheduler's
context switch.

Notable differences from Linux:
- The Core disposition falls back to Term, as we don't support
  application core dumps.
- The Stop and Cont dispositions are ignored, as these are normally
  relevant to shells.

Checkpatch-Ignore: LONG_LINE
Signed-off-by: Michalis Pappas <michalis@unikraft.io>
Reviewed-by: Ioan-Teodor Teugea <ioan_teodor.teugea@stud.acs.upb.ro>
Reviewed-by: Sergiu Moga <sergiu@unikraft.io>
Reviewed-by: Andrei Tatar <andrei@unikraft.io>
Approved-by: Andrei Tatar <andrei@unikraft.io>
GitHub-Closes: #1248

5 weeks agolib/posix-process/signal: Add clone handler for signals
Michalis Pappas [Wed, 3 Jan 2024 11:18:38 +0000 (12:18 +0100)]
lib/posix-process/signal: Add clone handler for signals

Migrate the clone handler into posix-process/signals.
Implement inheritance of signal handlers.

For more info see CLONE(2)

Checkpatch-Ignore: LONG_LINE
Signed-off-by: Michalis Pappas <michalis@unikraft.io>
Reviewed-by: Ioan-Teodor Teugea <ioan_teodor.teugea@stud.acs.upb.ro>
Reviewed-by: Sergiu Moga <sergiu@unikraft.io>
Reviewed-by: Andrei Tatar <andrei@unikraft.io>
Approved-by: Andrei Tatar <andrei@unikraft.io>
GitHub-Closes: #1248

5 weeks agolib/posix-process/signal: Add kill() and sigqueueinfo()
Michalis Pappas [Sun, 7 Jan 2024 10:56:16 +0000 (11:56 +0100)]
lib/posix-process/signal: Add kill() and sigqueueinfo()

Add syscalls for signalling. Internally these share common
abstractions.

The kill syscalls are used for sending signals to processes,
process groups, or threads:

* kill() allows sending a signal to a process group or process.
* tkill() allows sending a signal to a thread.
* tgkill() allows sending a signal to a thread in thread
  group.

The siqeueueinfo syscalls are similar to kill but additionally
allow to accompany the signal with data:

* rt_sigqueueinfo() allows sending signal and data to a process.
* rt_tgsigqueueinfo() allows sending signal and data to a thread
  in thread group.

For more info see kill(2), tkill(2), rt_sigqueueinfo(2)

Signed-off-by: Michalis Pappas <michalis@unikraft.io>
Reviewed-by: Ioan-Teodor Teugea <ioan_teodor.teugea@stud.acs.upb.ro>
Reviewed-by: Sergiu Moga <sergiu@unikraft.io>
Reviewed-by: Andrei Tatar <andrei@unikraft.io>
Approved-by: Andrei Tatar <andrei@unikraft.io>
GitHub-Closes: #1248

5 weeks agolib/posix-process/signal: Add rt_sigpending()
Michalis Pappas [Wed, 3 Jan 2024 11:48:30 +0000 (12:48 +0100)]
lib/posix-process/signal: Add rt_sigpending()

rt_sigpending() allows to examine any pending signals.
For more info see sigpending(2)

Signed-off-by: Michalis Pappas <michalis@unikraft.io>
Reviewed-by: Ioan-Teodor Teugea <ioan_teodor.teugea@stud.acs.upb.ro>
Reviewed-by: Sergiu Moga <sergiu@unikraft.io>
Reviewed-by: Andrei Tatar <andrei@unikraft.io>
Approved-by: Andrei Tatar <andrei@unikraft.io>
GitHub-Closes: #1248

5 weeks agolib/posix-process/signal: Add sigaltstack()
Michalis Pappas [Tue, 2 Jan 2024 17:53:21 +0000 (18:53 +0100)]
lib/posix-process/signal: Add sigaltstack()

sigaltstack() allows setting or retrieving an alternative
signal stack context. For more info see sigaltstack(2)

Signed-off-by: Michalis Pappas <michalis@unikraft.io>
Reviewed-by: Ioan-Teodor Teugea <ioan_teodor.teugea@stud.acs.upb.ro>
Reviewed-by: Sergiu Moga <sergiu@unikraft.io>
Reviewed-by: Andrei Tatar <andrei@unikraft.io>
Approved-by: Andrei Tatar <andrei@unikraft.io>
GitHub-Closes: #1248

5 weeks agolib/posix-process/signal: Add rt_sigaction()
Michalis Pappas [Tue, 18 Mar 2025 08:50:39 +0000 (09:50 +0100)]
lib/posix-process/signal: Add rt_sigaction()

rt_sigaction() allows examining and changing a signal action.
For more info see sigaction(2)

Signed-off-by: Michalis Pappas <michalis@unikraft.io>
Reviewed-by: Ioan-Teodor Teugea <ioan_teodor.teugea@stud.acs.upb.ro>
Reviewed-by: Sergiu Moga <sergiu@unikraft.io>
Reviewed-by: Andrei Tatar <andrei@unikraft.io>
Approved-by: Andrei Tatar <andrei@unikraft.io>
GitHub-Closes: #1248

5 weeks agolib/posix-process/signal: Add rt_sigprocmask()
Michalis Pappas [Tue, 18 Mar 2025 08:49:28 +0000 (09:49 +0100)]
lib/posix-process/signal: Add rt_sigprocmask()

rt_sigprocmask() allows examining and changing blocked signals.
For more info see sigprocmask(2).

Signed-off-by: Michalis Pappas <michalis@unikraft.io>
Reviewed-by: Ioan-Teodor Teugea <ioan_teodor.teugea@stud.acs.upb.ro>
Reviewed-by: Sergiu Moga <sergiu@unikraft.io>
Reviewed-by: Andrei Tatar <andrei@unikraft.io>
Approved-by: Andrei Tatar <andrei@unikraft.io>
GitHub-Closes: #1248

5 weeks agolib/posix-process/signal: Add default signal actions
Michalis Pappas [Fri, 29 Dec 2023 12:37:21 +0000 (13:37 +0100)]
lib/posix-process/signal: Add default signal actions

Add per-architecture default signal actions. These happen to be the
same for arm64 and x86_64, yet it's best to define them in separate
headers for forwards compatibility with future architectures.

Signed-off-by: Michalis Pappas <michalis@unikraft.io>
Reviewed-by: Ioan-Teodor Teugea <ioan_teodor.teugea@stud.acs.upb.ro>
Reviewed-by: Sergiu Moga <sergiu@unikraft.io>
Reviewed-by: Andrei Tatar <andrei@unikraft.io>
Approved-by: Andrei Tatar <andrei@unikraft.io>
GitHub-Closes: #1248

5 weeks agolib/posix-process/signal: Add signal descriptors and primitives
Michalis Pappas [Sun, 7 Jan 2024 15:50:12 +0000 (16:50 +0100)]
lib/posix-process/signal: Add signal descriptors and primitives

Introduce signal descriptors into `struct posix_process` and
`struct posix_thread`. Introduce primitives for various signal
operations such as initialization, allocation, and queueing.

Initialize signal descriptors upon creating a new process or
a thread.

Checkpatch-Ignore: LONG_LINE
Checkpatch-Ignore: MACRO_ARG_REUSE
Checkpatch-Ignore: SPACING
Signed-off-by: Michalis Pappas <michalis@unikraft.io>
Reviewed-by: Ioan-Teodor Teugea <ioan_teodor.teugea@stud.acs.upb.ro>
Reviewed-by: Sergiu Moga <sergiu@unikraft.io>
Reviewed-by: Andrei Tatar <andrei@unikraft.io>
Approved-by: Andrei Tatar <andrei@unikraft.io>
GitHub-Closes: #1248

5 weeks agolib/posix-process: Add config option for POSIX signals
Michalis Pappas [Thu, 28 Dec 2023 09:57:35 +0000 (10:57 +0100)]
lib/posix-process: Add config option for POSIX signals

Add CONFIG_LIBPOSIX_PROCESS_SIGNALS to enable POSIX signals.
If that option is not enabled, the implementation will fall
back to stubs.

Signed-off-by: Michalis Pappas <michalis@unikraft.io>
Reviewed-by: Ioan-Teodor Teugea <ioan_teodor.teugea@stud.acs.upb.ro>
Reviewed-by: Sergiu Moga <sergiu@unikraft.io>
Reviewed-by: Andrei Tatar <andrei@unikraft.io>
Approved-by: Andrei Tatar <andrei@unikraft.io>
GitHub-Closes: #1248

5 weeks agolib/posix-process: Fix formatting of Config.uk
Michalis Pappas [Thu, 28 Dec 2023 09:55:29 +0000 (10:55 +0100)]
lib/posix-process: Fix formatting of Config.uk

Update the indentation of Config.uk to adhere to Unikraft's coding
conventions. Remove `default n` items being redundant as `bool`
symbols default to `n`.

Signed-off-by: Michalis Pappas <michalis@unikraft.io>
Reviewed-by: Ioan-Teodor Teugea <ioan_teodor.teugea@stud.acs.upb.ro>
Reviewed-by: Sergiu Moga <sergiu@unikraft.io>
Reviewed-by: Andrei Tatar <andrei@unikraft.io>
Approved-by: Andrei Tatar <andrei@unikraft.io>
GitHub-Closes: #1248

5 weeks agolib/posix-process: Add helpers for current process and thread
Michalis Pappas [Mon, 13 Nov 2023 18:21:12 +0000 (19:21 +0100)]
lib/posix-process: Add helpers for current process and thread

Add uk_pprocess_current() uk_pthread_current() helpers. For now
these are part of the private API.

Checkpatch-Ignore: GLOBAL_INITIALISERS
Signed-off-by: Michalis Pappas <michalis@unikraft.io>
Reviewed-by: Ioan-Teodor Teugea <ioan_teodor.teugea@stud.acs.upb.ro>
Reviewed-by: Sergiu Moga <sergiu@unikraft.io>
Reviewed-by: Andrei Tatar <andrei@unikraft.io>
Approved-by: Andrei Tatar <andrei@unikraft.io>
GitHub-Closes: #1248

5 weeks agolib/posix-process: Add process table
Michalis Pappas [Thu, 4 Jan 2024 09:57:08 +0000 (10:57 +0100)]
lib/posix-process: Add process table

Add process table that maps `pid_t` to `struct posix_process`.
Add process lookup function and process & thread iterators.

Checkpatch-Ignore: COMPLEX_MACRO
Checkpatch-Ignore: MACRO_ARG_REUSE
Checkpatch-Ignore: SUSPECT_CODE_INDENT
Signed-off-by: Michalis Pappas <michalis@unikraft.io>
Reviewed-by: Ioan-Teodor Teugea <ioan_teodor.teugea@stud.acs.upb.ro>
Reviewed-by: Sergiu Moga <sergiu@unikraft.io>
Reviewed-by: Andrei Tatar <andrei@unikraft.io>
Approved-by: Andrei Tatar <andrei@unikraft.io>
GitHub-Closes: #1248

5 weeks agolib/posix-process: Use negative errors internally
Michalis Pappas [Tue, 2 Apr 2024 14:57:48 +0000 (16:57 +0200)]
lib/posix-process: Use negative errors internally

Update static functions to encode negative errors in
returned pointers.

Signed-off-by: Michalis Pappas <michalis@unikraft.io>
Reviewed-by: Ioan-Teodor Teugea <ioan_teodor.teugea@stud.acs.upb.ro>
Reviewed-by: Sergiu Moga <sergiu@unikraft.io>
Reviewed-by: Andrei Tatar <andrei@unikraft.io>
Approved-by: Andrei Tatar <andrei@unikraft.io>
GitHub-Closes: #1248

5 weeks agolib/posix-process: Add assertions in ukthread2pid / ukthread2tid
Michalis Pappas [Tue, 2 Apr 2024 11:08:57 +0000 (13:08 +0200)]
lib/posix-process: Add assertions in ukthread2pid / ukthread2tid

Add assertions against passing a NULL pointer parameter in
ukthread2pid / ukthread2tid.

Signed-off-by: Michalis Pappas <michalis@unikraft.io>
Reviewed-by: Ioan-Teodor Teugea <ioan_teodor.teugea@stud.acs.upb.ro>
Reviewed-by: Sergiu Moga <sergiu@unikraft.io>
Reviewed-by: Andrei Tatar <andrei@unikraft.io>
Approved-by: Andrei Tatar <andrei@unikraft.io>
GitHub-Closes: #1248

5 weeks agolib/posix-process/signal: Add kernel definition of sigset_t
Michalis Pappas [Tue, 19 Mar 2024 10:25:43 +0000 (11:25 +0100)]
lib/posix-process/signal: Add kernel definition of sigset_t

POSIX specifies that sigset_t can be defined either as integer
type or a structure type. Add kernel definition of sigset_t to
avoid compilation errors caused by flavors of libc that use the
struct definition.

Signed-off-by: Michalis Pappas <michalis@unikraft.io>
Reviewed-by: Ioan-Teodor Teugea <ioan_teodor.teugea@stud.acs.upb.ro>
Reviewed-by: Sergiu Moga <sergiu@unikraft.io>
Reviewed-by: Andrei Tatar <andrei@unikraft.io>
Approved-by: Andrei Tatar <andrei@unikraft.io>
GitHub-Closes: #1248

5 weeks agolib/posix-process/signal: Fix coding style of sigset.h
Michalis Pappas [Tue, 9 Jan 2024 12:09:18 +0000 (13:09 +0100)]
lib/posix-process/signal: Fix coding style of sigset.h

Fix checkpatch issues, prefix macro args with underscore,
remove conditional definition to HAVE_LIBC, include header
for __sigset type.

Checkpatch-Ignore: MACRO_ARG_REUSE
Signed-off-by: Michalis Pappas <michalis@unikraft.io>
Reviewed-by: Ioan-Teodor Teugea <ioan_teodor.teugea@stud.acs.upb.ro>
Reviewed-by: Sergiu Moga <sergiu@unikraft.io>
Reviewed-by: Andrei Tatar <andrei@unikraft.io>
Approved-by: Andrei Tatar <andrei@unikraft.io>
GitHub-Closes: #1248

5 weeks agolib/posix-process: Fix integer overflow in sigset operations
Michalis Pappas [Tue, 9 Jan 2024 12:03:52 +0000 (13:03 +0100)]
lib/posix-process: Fix integer overflow in sigset operations

Fix an integer overflow caused by missing `UL` suffix on
shifted values that would result into incorrect evaluation
when signal numbers >= SIGRTMIN are passed to paremeters.

Signed-off-by: Michalis Pappas <michalis@unikraft.io>
Reviewed-by: Ioan-Teodor Teugea <ioan_teodor.teugea@stud.acs.upb.ro>
Reviewed-by: Sergiu Moga <sergiu@unikraft.io>
Reviewed-by: Andrei Tatar <andrei@unikraft.io>
Approved-by: Andrei Tatar <andrei@unikraft.io>
GitHub-Closes: #1248

5 weeks agolib/posix-process: Import `sigset.h` from libuksignal
Michalis Pappas [Thu, 28 Dec 2023 11:42:17 +0000 (12:42 +0100)]
lib/posix-process: Import `sigset.h` from libuksignal

Migrate `sigset.h` from libuksignal verbatim.

Signed-off-by: Michalis Pappas <michalis@unikraft.io>
Reviewed-by: Ioan-Teodor Teugea <ioan_teodor.teugea@stud.acs.upb.ro>
Reviewed-by: Sergiu Moga <sergiu@unikraft.io>
Reviewed-by: Andrei Tatar <andrei@unikraft.io>
Approved-by: Andrei Tatar <andrei@unikraft.io>
GitHub-Closes: #1248

2 months agoplat/kvm: Select `HAVE_IBMPC` only on x86_64
Samuel Hym [Mon, 20 Jan 2025 17:40:30 +0000 (18:40 +0100)]
plat/kvm: Select `HAVE_IBMPC` only on x86_64

Without this patch, asking `kraft` to build for QEMU on arm64 with its
default configuration gives a series of warnings such as:

```
WARNING: unmet direct dependencies detected for HAVE_IBMPC_VGA
  Depends on [n]: ARCH_X86_64 [=n]
  Selected by [y]:
  - HAVE_IBMPC [=y]
```

and `HAVE_IBMPC` is set to yes in the generated configuration.

Signed-off-by: Samuel Hym <samuel@tarides.com>
Reviewed-by: Sergiu Moga <sergiu@unikraft.io>
Approved-by: Michalis Pappas <michalis@unikraft.io>
GitHub-Closes: #1565

2 months agodrivers/ukintctlr: Delete unnecessary `exportsyms.uk`
Sergiu Moga [Thu, 22 Feb 2024 12:41:08 +0000 (14:41 +0200)]
drivers/ukintctlr: Delete unnecessary `exportsyms.uk`

The philosophy is that each driver is meant to individually export
whatever symbols it sees fit. Therefore, delete the unnecessary
`exportsyms.uk` in the root of the interrupt controller drivers
subsystem.

Signed-off-by: Sergiu Moga <sergiu@unikraft.io>
Approved-by: Michalis Pappas <michalis@unikraft.io>
Reviewed-by: Michalis Pappas <michalis@unikraft.io>
GitHub-Closes: #1265

2 months agodrivers: Add `PS/2` subsystem with a dumbed down PS2 keyboard driver
Sergiu Moga [Tue, 16 Jan 2024 20:35:50 +0000 (22:35 +0200)]
drivers: Add `PS/2` subsystem with a dumbed down PS2 keyboard driver

Add a directory to represent what will be in the future the
subsystem for PS/2 controller drivers subsystem.

Implement a basic, dumbed down, driver stub for the PS/2 keyboard.
Write just enough functionality to register an IRQ handler for the
well known default legacy PIC routed PS/2 keyboard IRQ line and be
able to process 3 scan codes received in a burst manner:
CTRL + ALT + DEL

This functionality is bare minimum required to achieve shutdown with
Firecracker's `SendCtrlAltDel` command. It may not work on QEMU and
is obviously not the way the real driver should be implemented.

Additionally, introduce a new invisible config option:
`CONFIG_HAVE_SHUTDOWN_DISPATCHER`
Now, whenever a component implements the functionality of raising a
shutdown event, it must announce it system-wide by selecting this
config. That being said, make the keyboard driver do this.
(In the future, when we will be able to receive actual keystrokes,
we may be able to make this a separate config of the keyboard driver,
besides the actual functionality of processing keystrokes).

Signed-off-by: Sergiu Moga <sergiu@unikraft.io>
Approved-by: Michalis Pappas <michalis@unikraft.io>
Reviewed-by: Michalis Pappas <michalis@unikraft.io>
GitHub-Closes: #1265

2 months agolib/ukboot: Fix `KConfig` styling of `Config.uk`
Sergiu Moga [Mon, 15 Jan 2024 13:20:44 +0000 (15:20 +0200)]
lib/ukboot: Fix `KConfig` styling of `Config.uk`

Maintain consistency among `KConfig` files and align `lib/ukboot`'s
`Config.uk` file's indentation with the others'.

Signed-off-by: Sergiu Moga <sergiu@unikraft.io>
Approved-by: Michalis Pappas <michalis@unikraft.io>
Reviewed-by: Michalis Pappas <michalis@unikraft.io>
GitHub-Closes: #1265

2 months agolib/posix-unixsocket: Fix NULL crash on accept
Andrei Tatar [Wed, 25 Sep 2024 14:23:19 +0000 (16:23 +0200)]
lib/posix-unixsocket: Fix NULL crash on accept

This change fixes a NULL deref when accept() is handed a legal NULL
argument for addr, in which case it should not attempt to output.

Signed-off-by: Andrei Tatar <andrei@unikraft.io>
Approved-by: Sergiu Moga <sergiu@unikraft.io>
Reviewed-by: Sergiu Moga <sergiu@unikraft.io>
GitHub-Closes: #1593

2 months agolib/posix-timerfd: Output correct old_value on set
Andrei Tatar [Wed, 22 Jan 2025 22:16:37 +0000 (23:16 +0100)]
lib/posix-timerfd: Output correct old_value on set

Previously settime() would output the old timerfd setting verbatim, as
an absolute deadline; this contradicts timerfd_settime(2) which clearly
states that old_value should be output with the same semantics as
gettime() -- relative time remaining until the next expiration.
This change makes settime() calculate and output this time correctly.

Signed-off-by: Andrei Tatar <andrei@unikraft.io>
Approved-by: Sergiu Moga <sergiu@unikraft.io>
Reviewed-by: Sergiu Moga <sergiu@unikraft.io>
GitHub-Closes: #1568

2 months agolib/posix-timerfd: Fix counter on subsequent reads
Andrei Tatar [Wed, 22 Jan 2025 22:26:44 +0000 (23:26 +0100)]
lib/posix-timerfd: Fix counter on subsequent reads

The internal counter of a timerfd is returned on read() and reset to 0,
and should be increased by 1 for every subsequent expiration.
A logic error in the current code makes every update set the counter to
the total expirations rather than since last read, leading to subsequent
successful reads returning wrong counts.
This change fixes this error.

Signed-off-by: Andrei Tatar <andrei@unikraft.io>
Approved-by: Sergiu Moga <sergiu@unikraft.io>
Reviewed-by: Sergiu Moga <sergiu@unikraft.io>
GitHub-Closes: #1567

2 months agolib/posix-timerfd: Validate settime argument
Andrei Tatar [Wed, 22 Jan 2025 22:10:22 +0000 (23:10 +0100)]
lib/posix-timerfd: Validate settime argument

This change adds a validation check on the `new_value` argument to
settime(), refusing to work with negative times and non-canonical
timespec values.

Signed-off-by: Andrei Tatar <andrei@unikraft.io>
Approved-by: Sergiu Moga <sergiu@unikraft.io>
Reviewed-by: Sergiu Moga <sergiu@unikraft.io>
GitHub-Closes: #1566

2 months agolib/uktimeconv: Add time spec validation inlines
Andrei Tatar [Mon, 24 Feb 2025 14:30:07 +0000 (15:30 +0100)]
lib/uktimeconv: Add time spec validation inlines

This change adds inlines to check whether a timespec is in canonical
form, and if so whether it represents positive time.

Signed-off-by: Andrei Tatar <andrei@unikraft.io>
Approved-by: Sergiu Moga <sergiu@unikraft.io>
Reviewed-by: Sergiu Moga <sergiu@unikraft.io>
GitHub-Closes: #1566

2 months agolib/posix-tty: Give names to initial stdin/out
Andrei Tatar [Wed, 25 Sep 2024 15:39:42 +0000 (17:39 +0200)]
lib/posix-tty: Give names to initial stdin/out

This change gives the initial files 0 and 1 the names "stdin" and
"stdout", respectively, with initial fd 2 remaining a duplicate of 1.

Signed-off-by: Andrei Tatar <andrei@unikraft.io>
Approved-by: Sergiu Moga <sergiu@unikraft.io>
Reviewed-by: Sergiu Moga <sergiu@unikraft.io>
GitHub-Closes: #1592

2 months agolib/posix-timerfd: Give name to opened timerfds
Andrei Tatar [Wed, 25 Sep 2024 15:39:00 +0000 (17:39 +0200)]
lib/posix-timerfd: Give name to opened timerfds

This change names newly opened timerfds "timerfd".

Signed-off-by: Andrei Tatar <andrei@unikraft.io>
Approved-by: Sergiu Moga <sergiu@unikraft.io>
Reviewed-by: Sergiu Moga <sergiu@unikraft.io>
GitHub-Closes: #1592

2 months agolib/posix-socket: Give name to opened sockets
Andrei Tatar [Wed, 25 Sep 2024 15:38:05 +0000 (17:38 +0200)]
lib/posix-socket: Give name to opened sockets

This change names newly opened sockets as such:
- generic sockets: "socket"
- sockets opened by a call to accept(): "socket:accepted"
- sockets opened by socketpair(): "socket:pair"

Signed-off-by: Andrei Tatar <andrei@unikraft.io>
Approved-by: Sergiu Moga <sergiu@unikraft.io>
Reviewed-by: Sergiu Moga <sergiu@unikraft.io>
GitHub-Closes: #1592

2 months agolib/posix-poll: Give name to opened epollfds
Andrei Tatar [Wed, 25 Sep 2024 15:37:09 +0000 (17:37 +0200)]
lib/posix-poll: Give name to opened epollfds

This change names newly opened epollfds "epollfd".

Signed-off-by: Andrei Tatar <andrei@unikraft.io>
Approved-by: Sergiu Moga <sergiu@unikraft.io>
Reviewed-by: Sergiu Moga <sergiu@unikraft.io>
GitHub-Closes: #1592

2 months agolib/posix-pipe: Give name to opened pipes
Andrei Tatar [Wed, 25 Sep 2024 15:35:41 +0000 (17:35 +0200)]
lib/posix-pipe: Give name to opened pipes

This change names newly opened pipes "pipe:read" or "pipe:write",
depending on which end it is.

Signed-off-by: Andrei Tatar <andrei@unikraft.io>
Approved-by: Sergiu Moga <sergiu@unikraft.io>
Reviewed-by: Sergiu Moga <sergiu@unikraft.io>
GitHub-Closes: #1592

2 months agolib/posix-eventfd: Give name to opened eventfds
Andrei Tatar [Wed, 25 Sep 2024 15:34:47 +0000 (17:34 +0200)]
lib/posix-eventfd: Give name to opened eventfds

This change names newly opened eventfds as "eventfd".

Signed-off-by: Andrei Tatar <andrei@unikraft.io>
Approved-by: Sergiu Moga <sergiu@unikraft.io>
Reviewed-by: Sergiu Moga <sergiu@unikraft.io>
GitHub-Closes: #1592

2 months agolib/posix-fdtab: Allow named files & partial open
Andrei Tatar [Wed, 25 Sep 2024 15:30:36 +0000 (17:30 +0200)]
lib/posix-fdtab: Allow named files & partial open

This change expands the fdtab API, separating the action of creating a
new open file description with that of associating it with an fd. This
allows callers to perform additional initialization on the open file
description before the fd goes live.

One notable such init is filling in the `name` field of the ofile,
which the API additions now support and take care to allocate space for.

It was a conscious decision to not mandate that the fdtab fill in the
name itself, as drivers may construct names in any manner of ways other
than having a string on hand. Thus, to prevent a redundant memcpy, a
driver can choose to fill in the field itself.

Signed-off-by: Andrei Tatar <andrei@unikraft.io>
Approved-by: Sergiu Moga <sergiu@unikraft.io>
Reviewed-by: Sergiu Moga <sergiu@unikraft.io>
GitHub-Closes: #1592

2 months agolib/posix-fd: Add optional name field to ofiles
Andrei Tatar [Wed, 25 Sep 2024 14:53:47 +0000 (16:53 +0200)]
lib/posix-fd: Add optional name field to ofiles

This change adds an optional, binary-compatible, name field to open file
descriptions, allowing files to be assigned a meaningful name on open.

Signed-off-by: Andrei Tatar <andrei@unikraft.io>
Approved-by: Sergiu Moga <sergiu@unikraft.io>
Reviewed-by: Sergiu Moga <sergiu@unikraft.io>
GitHub-Closes: #1592

2 months agolib/posix-fd: Provide public ofile refcounting
Andrei Tatar [Wed, 25 Sep 2024 14:42:26 +0000 (16:42 +0200)]
lib/posix-fd: Provide public ofile refcounting

This change adds public helpers for refcounting open file descriptions.

Signed-off-by: Andrei Tatar <andrei@unikraft.io>
Approved-by: Sergiu Moga <sergiu@unikraft.io>
Reviewed-by: Sergiu Moga <sergiu@unikraft.io>
GitHub-Closes: #1592

2 months agolib/posix-fdtab: Fix wrong return in exec handler
Andrei Tatar [Wed, 19 Feb 2025 11:54:31 +0000 (12:54 +0100)]
lib/posix-fdtab: Fix wrong return in exec handler

Previously fdtab_handle_execve would return 0 on success, as per common
convention. This is however wrong for event handlers, as these require
specific exit codes on success; in this case UK_EVENT_HANDLED_CONT.
This change fixes this oversight.

Signed-off-by: Andrei Tatar <andrei@unikraft.io>
Approved-by: Michalis Pappas <michalis@unikraft.io>
Reviewed-by: Michalis Pappas <michalis@unikraft.io>
GitHub-Closes: #1278

2 months agolib/posix-fdtab: Simplify active fdtab lookup
Andrei Tatar [Tue, 23 Jan 2024 19:22:49 +0000 (20:22 +0100)]
lib/posix-fdtab: Simplify active fdtab lookup

This change refactors the way fdtab code looks up the currently active
fdtable, simplifying functions and removing boilerplate code.

Signed-off-by: Andrei Tatar <andrei@unikraft.io>
Approved-by: Michalis Pappas <michalis@unikraft.io>
Reviewed-by: Michalis Pappas <michalis@unikraft.io>
GitHub-Closes: #1278

2 months agolib/posix-fdtab: Handle fdtab duplication on clone
Andrei Tatar [Tue, 23 Jan 2024 18:44:06 +0000 (19:44 +0100)]
lib/posix-fdtab: Handle fdtab duplication on clone

This change adds logic to handle fdtab references on clone:
- if  CLONE_FILES: child inherits a reference to parent's tab
- if !CLONE_FILES: child allocates new fdtab duplicate of parent's,
  populated with new references to the same open file descriptions hosted
  by the parent fdtab.

The initial duplication logic is rudimentary and does not provide any
ordering guarantees w.r.t. syscalls modifying the original table (open,
dup, close), under the assumption that it won't trigger race conditions
in the wild. Please revisit if this turns out to be overly optimistic.

Signed-off-by: Andrei Tatar <andrei@unikraft.io>
Approved-by: Michalis Pappas <michalis@unikraft.io>
Reviewed-by: Michalis Pappas <michalis@unikraft.io>
GitHub-Closes: #1278

2 months agolib/posix-fdtab: Add value assert in fmap_xchg
Andrei Tatar [Tue, 23 Jan 2024 18:37:36 +0000 (19:37 +0100)]
lib/posix-fdtab: Add value assert in fmap_xchg

This change adds an assert to sanity-check the value to be exchanged
into the fmap. Exchanging in a NULL value is an invalid operation and
breaks the semantics of fmap, leaving the data structure in a
potentially unsound state.
Calling code should never normally do this; the assert serves as extra
precaution for future development.

Signed-off-by: Andrei Tatar <andrei@unikraft.io>
Approved-by: Michalis Pappas <michalis@unikraft.io>
Reviewed-by: Michalis Pappas <michalis@unikraft.io>
GitHub-Closes: #1278

2 months agolib/posix-fdtab: Support independent fdtab refs
Andrei Tatar [Tue, 23 Jan 2024 18:30:25 +0000 (19:30 +0100)]
lib/posix-fdtab: Support independent fdtab refs

This change adds the config option LIBPOSIX_FDTAB_MULTITAB that enables
independent per-thread fdtab references. If enabled, each thread will
lookup an fdtab reference in its TLS memory.
The static initial fdtab remains, and continues to be used.

To this end, fdtabs are now refcounted and have non-static lifetimes.
New threads inherit their parent's ref, with other components or
their callbacks responsible for initializing a meaningful value.
The init thread, however, holds a reference to the static init fdtab.

Signed-off-by: Andrei Tatar <andrei@unikraft.io>
Approved-by: Michalis Pappas <michalis@unikraft.io>
Reviewed-by: Michalis Pappas <michalis@unikraft.io>
GitHub-Closes: #1278

2 months agolib/ukcpio: Use `uk_syscall_do_` instead of `uk_syscall_r_` symbols
Sergiu Moga [Fri, 14 Feb 2025 14:22:00 +0000 (16:22 +0200)]
lib/ukcpio: Use `uk_syscall_do_` instead of `uk_syscall_r_` symbols

Since `uk_syscall_r_` symbols tend to also invoke the system call enter
and exit tables if the `syscall_shim` library is enabled, replace such
calls with the `uk_syscall_do_` symbol variant which does not involve
any tables.

Checkpatch-Ignore: FUNCTION_ARGUMENTS
Checkpatch-Ignore: AVOID_EXTERNS
Signed-off-by: Sergiu Moga <sergiu@unikraft.io>
Approved-by: Andrei Tatar <andrei@unikraft.io>
Reviewed-by: Andrei Tatar <andrei@unikraft.io>
GitHub-Closes: #1590

2 months agolib/ukcpio: Add temporary `syscall_shim` library dependency
Sergiu Moga [Fri, 14 Feb 2025 14:18:46 +0000 (16:18 +0200)]
lib/ukcpio: Add temporary `syscall_shim` library dependency

Since the CPIO library depends on having the `uk_syscall_r_` symbols
exported by the VFSCore library, which can only do so if the
`syscall_shim` library is enabled, add a dependency to this said
library.

This will be undone in the near future by the deprecation of VFSCore,
but for now do this so we don't break builds that use CPIO without
`syscall_shim`.

Signed-off-by: Sergiu Moga <sergiu@unikraft.io>
Approved-by: Andrei Tatar <andrei@unikraft.io>
Reviewed-by: Andrei Tatar <andrei@unikraft.io>
GitHub-Closes: #1590

2 months agolib/vfscore: Register `creat` using the raw variant
Sergiu Moga [Mon, 17 Feb 2025 13:50:56 +0000 (15:50 +0200)]
lib/vfscore: Register `creat` using the raw variant

The `creat` has been registered as non-raw a long time ago, back
when the registration policy was different. Now, all system calls
should be registered as raw. Do so for `creat` as well and make it
call the `uk_syscall_do_` variant of `open` in order to avoid
invoking the system call enter/exit tables twice.

Signed-off-by: Sergiu Moga <sergiu@unikraft.io>
Approved-by: Andrei Tatar <andrei@unikraft.io>
Reviewed-by: Andrei Tatar <andrei@unikraft.io>
GitHub-Closes: #1591

2 months agolib/vfscore: Use `uk_syscall_do_` instead of `uk_syscall_r_` symbols
Sergiu Moga [Fri, 14 Feb 2025 14:22:00 +0000 (16:22 +0200)]
lib/vfscore: Use `uk_syscall_do_` instead of `uk_syscall_r_` symbols

Since `uk_syscall_r_` symbols tend to also invoke the system call enter
and exit tables if the `syscall_shim` library is enabled, replace such
calls with the `uk_syscall_do_` symbol variant which does not involve
any tables.

Signed-off-by: Sergiu Moga <sergiu@unikraft.io>
Approved-by: Andrei Tatar <andrei@unikraft.io>
Reviewed-by: Andrei Tatar <andrei@unikraft.io>
GitHub-Closes: #1591

2 months agolib/uksignal: Set _GNU_SOURCE to preserve definition of sighandler_t
Michalis Pappas [Tue, 21 Jan 2025 14:07:55 +0000 (15:07 +0100)]
lib/uksignal: Set _GNU_SOURCE to preserve definition of sighandler_t

Adding feature.h in nolibc requires that we set _GNU_SOURCE to preserve
the definition of sighandler_t in signal.c

Signed-off-by: Michalis Pappas <michalis@unikraft.io>
Approved-by: Andrei Tatar <andrei@unikraft.io>
Reviewed-by: Andrei Tatar <andrei@unikraft.io>
GitHub-Closes: #1244