2610c7faa7
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. |
||
---|---|---|
arch | ||
.gitignore | ||
LICENSE | ||
Makefile | ||
README.md | ||
test_libucontext.c |
README.md
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.
Right now these archs are supported and should work on bare metal:
- x86
- x86_64
- armv6+ (
arm
) - aarch64
- s390x
These archs require kernel assistance and use a syscall:
- ppc
- ppc64 (ELFv2 ABI spec only, ELFv1 not supported)
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
support
libucontext
is offered as part of the gcompat
project. Accordingly, please address all questions
and bug reports to gcompat@lists.adelielinux.org.