context/build
George Koehler df8fb6b528 Fix ppc32 on Linux musl, NetBSD, OpenBSD; fixes #120
This fixes fcontext on my PowerBook G4 running Void Linux
ppc-musl-20190901, NetBSD/macppc 8.1, or OpenBSD/macppc 6.6-current,
all with g++.  These systems use fcontext for *ppc32_sysv_elf*
(PowerPC 32-bit System V ELF).  The assembly code was wrong for BSD
and crashing on Linux musl.

Linux returns a transfer_t in memory (through a hidden pointer in R3),
but other systems (at least NetBSD and OpenBSD) return a transfer_t in
registers R3:R4.  jump_fcontext() and ontop_fcontext() were always
using the hidden pointer.  Add checks for `#ifdef__linux__`; start
using R3:R4 on other systems.

make_fcontext() was calling _exit(0) through the insecure BSS PLT.
Set R30 to use the secure PLT.  This prevents a crash when musl's
ld.so loads the executable; musl seems to require the secure PLT.

Fix ontop_fcontext() to restore the hidden pointer on Linux.  It was
passing the wrong context's hidden pointer to the ontop-function fn(),
so fn() returned a transfer_t to the wrong stack.  When fn() was
context_exit() in <boost/context/continuation_fcontext.hpp>, it freed
the old stack, then returned `transfer_t{ nullptr, nullptr }` to free
memory.  This crashed on Linux musl.

Now that ontop_fcontext() restores the hidden pointer, it must stop
abusing the same pointer to pass a transfer_t argument to fn().  Add a
new ontop_fcontext_tail() in C++, which takes arguments in registers
and allocates a transfer_t.  The code is in C++ so it can free the
transfer_t argument if fn() throws a C++ exception.

Rearrange the context frame to shrink it from 244 to 240 bytes.  This
fixes the stack alignment: the ABI requires R1 % 16 == 0, and
make_fcontext() respects this, but jump_fcontext() was adding 244 to
R1, so the new context ran with a misaligned stack (244 % 16 == 4).

Remove R13 from the context frame, so new contexts stop loading R13
with garbage.  The ABI uses R13 to point to the executable's small
data, so R13 should have the same value in every context.

Add the backchain to the context frame; make room by moving LR to the
caller's frame.  Order CR, R14 to R31, F14 to F31 at the frame's end,
as is typical for this ABI.  Provide 8-byte alignment for FPSCR and
F14 to F31, to avoid a misalignment penalty.
2019-10-19 14:06:24 -04:00
..
architecture.jam S390x: Add Support for s390x arch 2019-09-06 20:08:10 +05:30
cxx11_hdr_mutex.cpp Don't use Boost.Config build-time configure target. 2016-03-25 18:03:51 +09:00
Jamfile.v2 Fix ppc32 on Linux musl, NetBSD, OpenBSD; fixes #120 2019-10-19 14:06:24 -04:00