kaniini / libucontext

ucontext implementation featuring glibc-compatible ABI
Other
102 stars 41 forks source link

libucontext

libucontext is a library which provides the ucontext.h C API. Unlike other implementations, it faithfully follows the kernel process ABI when doing context swaps.

Notably, when combined with gcompat, it provides a fully compatible implementation of the ucontext functions that are ABI compatible with glibc.

Since version 0.13, for some architectures, you can deploy to bare metal using newlib via the FREESTANDING=yes make option. Systems which use a syscall cannot work this way. The table below shows which architecture ports have been adapted to build with FREESTANDING=yes.

Adding support for new architectures is easy, but you need to know assembly language for the target to do it.

supported features

Architecture Works on musl Syscall Supports FREESTANDING Common trampoline
aarch64
arm
loongarch64
m68k
mips
mips64
or1k
ppc
ppc64
riscv32
riscv64
s390x
sh
x86
x86_64

building

libucontext uses a simple makefile build system. You should define ARCH= at build time, otherwise the build system will attempt to guess using uname -m.

$ make ARCH=x86_64
$ make ARCH=x86_64 check
$ make ARCH=x86_64 DESTDIR=out install

There are a few options:

If you have scdoc installed, you can build manpages and install them:

$ make docs
$ make DESTDIR=out install_docs

real-world use cases

libucontext is used on almost all musl distributions to provide the legacy ucontext.h API. Additionally, it is used by:

caveats

libucontext, while largely functionally equivalent does have some differences over traditional POSIX ucontext functions: