2018-01-30 03:56:01 +00:00
|
|
|
# `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.
|
|
|
|
|
|
|
|
|
|
|
|
## supported architectures
|
|
|
|
|
|
|
|
Adding support for new architectures is easy, but you need to know assembly language to do it.
|
|
|
|
|
2018-02-02 18:51:55 +00:00
|
|
|
Right now these archs are supported and should work on bare metal:
|
2018-01-30 03:56:01 +00:00
|
|
|
|
2018-02-01 01:28:19 +00:00
|
|
|
* x86
|
2018-01-30 03:56:01 +00:00
|
|
|
* x86_64
|
2018-01-31 04:13:42 +00:00
|
|
|
* armv6+ (`arm`)
|
2018-01-31 21:23:18 +00:00
|
|
|
* aarch64
|
2018-02-15 05:55:26 +00:00
|
|
|
* s390x
|
2020-03-30 06:38:23 +00:00
|
|
|
* mips (O32 ABI only)
|
|
|
|
* mips64 (N32/N64 ABI only, like Alpine, only N64 ABI has been tested)
|
2020-05-18 03:28:21 +00:00
|
|
|
* riscv64
|
2018-02-02 18:51:55 +00:00
|
|
|
|
ppc32/64: rewrite get/set/swapcontext in assembly
getcontext cannot be correctly implemented in C.
If this calls another function, as it does to call syscall, it needs to
first spill its return address to the stack. If, after getcontext returns,
its caller then calls other functions, this saved return address can be
clobbered. When the context saved by getcontext is later restored, the
(now clobbered) return address will be reloaded from the stack, and the
second return from getcontext will return to the wrong location.
Because the powerpc swapcontext syscall allows either the old context or
new context pointers to be null, it is usable for implementing all of
get/set/swapcontext.
We therefore rewrite swapcontext in assembly, and get/setcontext as simple
assembly function wrappers around swapcontext.
The one piece we keep in C is the code to check the return value of the
system call and to set errno. This code was actually unnecessary before --
libc does this within syscall. However, now that the system call is made
directly in assembly, bypassing libc, it is truly necessary. Because errno
is thread-local and the details of how to set it can vary by libc, this
code remains written in C.
2019-02-23 23:12:37 +00:00
|
|
|
These archs require kernel assistance and use a syscall:
|
2018-02-02 18:51:55 +00:00
|
|
|
|
2018-02-02 18:45:42 +00:00
|
|
|
* ppc
|
2018-02-06 08:05:53 +00:00
|
|
|
* ppc64 (ELFv2 ABI spec only, ELFv1 not supported)
|
2018-02-14 03:06:01 +00:00
|
|
|
|
|
|
|
|
|
|
|
## 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
|
2020-05-18 03:28:21 +00:00
|
|
|
```
|