summaryrefslogtreecommitdiff
path: root/system/libucontext
diff options
context:
space:
mode:
Diffstat (limited to 'system/libucontext')
-rw-r--r--system/libucontext/APKBUILD17
-rw-r--r--system/libucontext/powerpc.patch1121
-rw-r--r--system/libucontext/ppc64-assembly.patch331
-rw-r--r--system/libucontext/ppc64-stack-layout.patch105
-rw-r--r--system/libucontext/static.patch76
5 files changed, 1203 insertions, 447 deletions
diff --git a/system/libucontext/APKBUILD b/system/libucontext/APKBUILD
index f152933a5..81990e112 100644
--- a/system/libucontext/APKBUILD
+++ b/system/libucontext/APKBUILD
@@ -1,17 +1,14 @@
-# Maintainer:
+# Maintainer: A. Wilcox <awilfox@adelielinux.org>
pkgname=libucontext
-pkgver=0.1.3
-pkgrel=1
+pkgver=0.9.0
+pkgrel=0
pkgdesc="ucontext function implementations"
-url="https://git.dereferenced.org/kaniini/libucontext/"
+url="https://code.foxkit.us/adelie/libucontext/"
arch="all"
license="ISC"
depends=""
subpackages="$pkgname-dev"
-source="https://distfiles.dereferenced.org/libucontext/libucontext-$pkgver.tar.xz
- ppc64-assembly.patch
- ppc64-stack-layout.patch
- "
+source="https://distfiles.adelielinux.org/source/libucontext/libucontext-$pkgver.tar.xz"
case "$CTARGET_ARCH" in
armhf) LIBUCONTEXT_ARCH="arm" ;;
@@ -35,6 +32,4 @@ package() {
make ARCH="$LIBUCONTEXT_ARCH" DESTDIR="$pkgdir" install
}
-sha512sums="9e0694c09f159de714b655f6a4201a05c8d1871ee7376bb6bf824206b45475cfbd8269ca1caa75b9c322624d9f77d3fc3f938228a4bdd267a5ddceb57ca5c1ab libucontext-0.1.3.tar.xz
-dbb7599fe5cc1e470d944bf741c393c13e684d6c27bd794ec380a05ba1ba045597b102903a1ac9bf586a508941440373c2d29fad1d7372ee8c72ffb7f0e11f75 ppc64-assembly.patch
-d6219487a5aa456726a01a5a6a39c3a7f29bc24a66f2fc77ff7f852e1b45ffe64854ad92cafad3cc03d3b52bd77dce786ef125e3e88ddb0398833a560afb5211 ppc64-stack-layout.patch"
+sha512sums="47ffa743e0b364d7a5d5ae633f89e83a7e3bbdf62a8a703a06a522c08b187b785548e8b8d58d53fc4fd984575f086794e74c12d40075326c6e88024e841550b6 libucontext-0.9.0.tar.xz"
diff --git a/system/libucontext/powerpc.patch b/system/libucontext/powerpc.patch
new file mode 100644
index 000000000..ed7604d7b
--- /dev/null
+++ b/system/libucontext/powerpc.patch
@@ -0,0 +1,1121 @@
+From 94216c60c43a30e39fbc4f347450768699c6c77c Mon Sep 17 00:00:00 2001
+From: Bobby Bingham <koorogi@koorogi.info>
+Date: Mon, 1 Apr 2019 23:02:12 -0500
+Subject: [PATCH] test ability to pass 10 args through makecontext
+
+---
+ test_libucontext.c | 23 +++++++++++++++++++++--
+ 1 file changed, 21 insertions(+), 2 deletions(-)
+
+diff --git a/test_libucontext.c b/test_libucontext.c
+index 121cc3e..e5eac83 100644
+--- a/test_libucontext.c
++++ b/test_libucontext.c
+@@ -6,13 +6,32 @@
+ #include <stdio.h>
+ #include <ucontext.h>
+ #include <stdint.h>
++#include <stdlib.h>
+ #include <string.h>
+
+
+ static ucontext_t ctx[3];
+
+
+-static void f1 (void) {
++static void check_arg(int actual, int expected) {
++ if (actual == expected) return;
++ fprintf(stderr, "argument has wrong value. got %d, expected %d.\n", actual, expected);
++ abort();
++}
++
++
++static void f1 (int a, int b, int c, int d, int e, int f, int g, int h, int i, int j) {
++ check_arg(a, 1);
++ check_arg(b, 2);
++ check_arg(c, 3);
++ check_arg(d, 4);
++ check_arg(e, 5);
++ check_arg(f, 6);
++ check_arg(g, 7);
++ check_arg(h, 8);
++ check_arg(i, 9);
++ check_arg(j, 10);
++
+ printf("start f1\n");
+ swapcontext(&ctx[1], &ctx[2]);
+ printf("finish f1\n");
+@@ -40,7 +59,7 @@ int main (int argc, const char *argv[]) {
+ ctx[1].uc_stack.ss_sp = st1;
+ ctx[1].uc_stack.ss_size = sizeof st1;
+ ctx[1].uc_link = &ctx[0];
+- makecontext(&ctx[1], f1, 0);
++ makecontext(&ctx[1], f1, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
+
+
+ getcontext(&ctx[2]);
+From cb59e7ee957b389578a3f973484ae3198f6cfed1 Mon Sep 17 00:00:00 2001
+From: Bobby Bingham <koorogi@koorogi.info>
+Date: Mon, 1 Apr 2019 23:03:21 -0500
+Subject: [PATCH] test calls to getcontext without makecontext
+
+---
+ test_libucontext.c | 12 ++++++++++++
+ 1 file changed, 12 insertions(+)
+
+diff --git a/test_libucontext.c b/test_libucontext.c
+index e5eac83..a4a9b4c 100644
+--- a/test_libucontext.c
++++ b/test_libucontext.c
+@@ -48,6 +48,7 @@ static void f2 (void) {
+ int main (int argc, const char *argv[]) {
+ char st1[8192];
+ char st2[8192];
++ volatile int done = 0;
+
+
+ /* poison each coroutine's stack memory for debugging purposes */
+@@ -70,5 +71,16 @@ int main (int argc, const char *argv[]) {
+
+
+ swapcontext(&ctx[0], &ctx[2]);
++
++
++ /* test ability to use getcontext/setcontext without makecontext */
++ getcontext(&ctx[1]);
++ printf("done = %d\n", done);
++ if (done++ == 0) setcontext(&ctx[1]);
++ if (done != 2) {
++ fprintf(stderr, "wrong value for done. got %d, expected 2\n", done);
++ abort();
++ }
++
+ return 0;
+ }
+From b6a9b5e279123f16569e0fd9f8ff14ff04bed7a3 Mon Sep 17 00:00:00 2001
+From: Bobby Bingham <koorogi@koorogi.info>
+Date: Fri, 5 Apr 2019 13:32:03 -0500
+Subject: [PATCH] ppc32: fix stack alignment
+
+The stack should be 16-byte aligned, not 8 mod 16.
+---
+ arch/ppc/makecontext.c | 2 +-
+ 1 file changed, 1 insertion(+), 1 deletion(-)
+
+diff --git a/arch/ppc/makecontext.c b/arch/ppc/makecontext.c
+index c562ea5..1b9efdf 100644
+--- a/arch/ppc/makecontext.c
++++ b/arch/ppc/makecontext.c
+@@ -37,7 +37,7 @@ __makecontext(ucontext_t *ucp, void (*func)(void), int argc, ...)
+
+ sp = (greg_t *) ((uintptr_t) ucp->uc_stack.ss_sp + ucp->uc_stack.ss_size);
+ sp -= (uc_link + 1);
+- sp = (greg_t *) (((uintptr_t) sp & -16L) - 8);
++ sp = (greg_t *) ((uintptr_t) sp & -16L);
+
+ ucp->uc_mcontext.gregs[REG_NIP] = (uintptr_t) func;
+ ucp->uc_mcontext.gregs[REG_LNK] = (uintptr_t) &__start_context;
+From b9bd4045fb34f060d6cf37fc7da7ab13b91462de Mon Sep 17 00:00:00 2001
+From: Bobby Bingham <koorogi@koorogi.info>
+Date: Fri, 5 Apr 2019 13:35:00 -0500
+Subject: [PATCH] ppc32/64: fix back chain pointer
+
+The ABI states that sp[0] should point to the previous stack frame, or be
+zero if there is no previous stack frame. makecontext previously set this
+slot to point to the __start_context function, rather than to a valid
+stack frame.
+---
+ arch/ppc/makecontext.c | 2 +-
+ arch/ppc64/makecontext.c | 2 +-
+ 2 files changed, 2 insertions(+), 2 deletions(-)
+
+diff --git a/arch/ppc/makecontext.c b/arch/ppc/makecontext.c
+index 1b9efdf..729f465 100644
+--- a/arch/ppc/makecontext.c
++++ b/arch/ppc/makecontext.c
+@@ -44,7 +44,7 @@ __makecontext(ucontext_t *ucp, void (*func)(void), int argc, ...)
+ ucp->uc_mcontext.gregs[REG_R31] = (uintptr_t) ucp->uc_link;
+ ucp->uc_mcontext.gregs[REG_SP] = (uintptr_t) sp;
+
+- sp[0] = (uintptr_t) &__start_context;
++ sp[0] = 0;
+ sp[uc_link] = (uintptr_t) ucp->uc_link;
+ argp = &sp[2];
+
+diff --git a/arch/ppc64/makecontext.c b/arch/ppc64/makecontext.c
+index 9d6b998..91fb579 100644
+--- a/arch/ppc64/makecontext.c
++++ b/arch/ppc64/makecontext.c
+@@ -45,7 +45,7 @@ __makecontext(ucontext_t *ucp, void (*func)(void), int argc, ...)
+ ucp->uc_mcontext.gp_regs[REG_ENTRY] = (uintptr_t) func;
+ ucp->uc_mcontext.gp_regs[REG_R31] = (uintptr_t) ucp->uc_link;
+
+- sp[0] = (uintptr_t) &__start_context;
++ sp[0] = 0;
+ sp[uc_link] = (uintptr_t) ucp->uc_link;
+ argp = &sp[2];
+
+From b500b054c7cf412a6042496afa08b4302f7ed929 Mon Sep 17 00:00:00 2001
+From: Bobby Bingham <koorogi@koorogi.info>
+Date: Fri, 5 Apr 2019 13:38:36 -0500
+Subject: [PATCH] ppc32/64: don't store uc_link on the stack
+
+This was previously stored either in the CR (ppc64) or LR (ppc32) save
+area of the stack, or to one of the parameter save slots.
+
+In either case, the saved value was unused. This value is also passed
+to __start_context via r31, so there's no need to pass it on the stack.
+---
+ arch/ppc/makecontext.c | 6 ++----
+ arch/ppc64/makecontext.c | 6 ++----
+ 2 files changed, 4 insertions(+), 8 deletions(-)
+
+diff --git a/arch/ppc/makecontext.c b/arch/ppc/makecontext.c
+index 729f465..2b7ea67 100644
+--- a/arch/ppc/makecontext.c
++++ b/arch/ppc/makecontext.c
+@@ -30,13 +30,12 @@ __makecontext(ucontext_t *ucp, void (*func)(void), int argc, ...)
+ greg_t *sp, *argp;
+ va_list va;
+ int i;
+- unsigned int uc_link, stack_args;
++ unsigned int stack_args;
+
+ stack_args = argc > 8 ? argc - 8 : 0;
+- uc_link = stack_args + 1;
+
+ sp = (greg_t *) ((uintptr_t) ucp->uc_stack.ss_sp + ucp->uc_stack.ss_size);
+- sp -= (uc_link + 1);
++ sp -= stack_args + 2;
+ sp = (greg_t *) ((uintptr_t) sp & -16L);
+
+ ucp->uc_mcontext.gregs[REG_NIP] = (uintptr_t) func;
+@@ -45,7 +44,6 @@ __makecontext(ucontext_t *ucp, void (*func)(void), int argc, ...)
+ ucp->uc_mcontext.gregs[REG_SP] = (uintptr_t) sp;
+
+ sp[0] = 0;
+- sp[uc_link] = (uintptr_t) ucp->uc_link;
+ argp = &sp[2];
+
+ va_start(va, argc);
+diff --git a/arch/ppc64/makecontext.c b/arch/ppc64/makecontext.c
+index 91fb579..b060371 100644
+--- a/arch/ppc64/makecontext.c
++++ b/arch/ppc64/makecontext.c
+@@ -30,13 +30,12 @@ __makecontext(ucontext_t *ucp, void (*func)(void), int argc, ...)
+ greg_t *sp, *argp;
+ va_list va;
+ int i;
+- unsigned int uc_link, stack_args;
++ unsigned int stack_args;
+
+ stack_args = argc > 8 ? argc - 8 : 0;
+- uc_link = stack_args + 1;
+
+ sp = (greg_t *) ((uintptr_t) ucp->uc_stack.ss_sp + ucp->uc_stack.ss_size);
+- sp -= (uc_link + 1);
++ sp -= stack_args + 2;
+ sp = (greg_t *) (((uintptr_t) sp & -16L));
+
+ ucp->uc_mcontext.gp_regs[REG_NIP] = (uintptr_t) func;
+@@ -46,7 +45,6 @@ __makecontext(ucontext_t *ucp, void (*func)(void), int argc, ...)
+ ucp->uc_mcontext.gp_regs[REG_R31] = (uintptr_t) ucp->uc_link;
+
+ sp[0] = 0;
+- sp[uc_link] = (uintptr_t) ucp->uc_link;
+ argp = &sp[2];
+
+ va_start(va, argc);
+From 55168fcb1809dde45c99450f1f3be27716c473db Mon Sep 17 00:00:00 2001
+From: Bobby Bingham <koorogi@koorogi.info>
+Date: Fri, 5 Apr 2019 13:57:53 -0500
+Subject: [PATCH] ppc32/64: simplify storage of stack parameters
+
+The switch statement is simpler as an if/else, and removing the argp
+variable makes the code more symmetric between the register and stack
+parameter cases.
+---
+ arch/ppc/makecontext.c | 24 ++++++------------------
+ arch/ppc64/makecontext.c | 24 ++++++------------------
+ 2 files changed, 12 insertions(+), 36 deletions(-)
+
+diff --git a/arch/ppc/makecontext.c b/arch/ppc/makecontext.c
+index 2b7ea67..4a404a4 100644
+--- a/arch/ppc/makecontext.c
++++ b/arch/ppc/makecontext.c
+@@ -27,7 +27,7 @@ extern void __start_context(void);
+ void
+ __makecontext(ucontext_t *ucp, void (*func)(void), int argc, ...)
+ {
+- greg_t *sp, *argp;
++ greg_t *sp;
+ va_list va;
+ int i;
+ unsigned int stack_args;
+@@ -44,27 +44,15 @@ __makecontext(ucontext_t *ucp, void (*func)(void), int argc, ...)
+ ucp->uc_mcontext.gregs[REG_SP] = (uintptr_t) sp;
+
+ sp[0] = 0;
+- argp = &sp[2];
+
+ va_start(va, argc);
+
+- for (i = 0; i < argc; i++)
+- switch (i)
+- {
+- case 0:
+- case 1:
+- case 2:
+- case 3:
+- case 4:
+- case 5:
+- case 6:
+- case 7:
++ for (i = 0; i < argc; i++) {
++ if (i < 8)
+ ucp->uc_mcontext.gregs[i + 3] = va_arg (va, greg_t);
+- break;
+- default:
+- *argp++ = va_arg (va, greg_t);
+- break;
+- }
++ else
++ sp[i-8 + 2] = va_arg (va, greg_t);
++ }
+
+ va_end(va);
+ }
+diff --git a/arch/ppc64/makecontext.c b/arch/ppc64/makecontext.c
+index b060371..962f98a 100644
+--- a/arch/ppc64/makecontext.c
++++ b/arch/ppc64/makecontext.c
+@@ -27,7 +27,7 @@ extern void __start_context(void);
+ void
+ __makecontext(ucontext_t *ucp, void (*func)(void), int argc, ...)
+ {
+- greg_t *sp, *argp;
++ greg_t *sp;
+ va_list va;
+ int i;
+ unsigned int stack_args;
+@@ -45,27 +45,15 @@ __makecontext(ucontext_t *ucp, void (*func)(void), int argc, ...)
+ ucp->uc_mcontext.gp_regs[REG_R31] = (uintptr_t) ucp->uc_link;
+
+ sp[0] = 0;
+- argp = &sp[2];
+
+ va_start(va, argc);
+
+- for (i = 0; i < argc; i++)
+- switch (i)
+- {
+- case 0:
+- case 1:
+- case 2:
+- case 3:
+- case 4:
+- case 5:
+- case 6:
+- case 7:
++ for (i = 0; i < argc; i++) {
++ if (i < 8)
+ ucp->uc_mcontext.gp_regs[i + 3] = va_arg (va, greg_t);
+- break;
+- default:
+- *argp++ = va_arg (va, greg_t);
+- break;
+- }
++ else
++ sp[i-8 + 2] = va_arg (va, greg_t);
++ }
+
+ va_end(va);
+ }
+From 8ea5f548b9146ffeea2074a33a06bbbd07a74402 Mon Sep 17 00:00:00 2001
+From: Bobby Bingham <koorogi@koorogi.info>
+Date: Fri, 5 Apr 2019 14:01:10 -0500
+Subject: [PATCH] ppc64: fix makecontext with more than 8 parameters
+
+The ELFv2 ABI used on PPC64 differs from the ELFv1 ABI used on PPC32 here.
+On PPC64, once there are any parameters that need to be passed on the
+stack, space needs to be reserved on the stack to pass all parameters.
+Parameters 0-7 are still only passed by register, but if the callee needs
+to spill them, it can use the stack space reserved for the corresponding
+parameter to do so.
+---
+ arch/ppc64/makecontext.c | 4 ++--
+ 1 file changed, 2 insertions(+), 2 deletions(-)
+
+diff --git a/arch/ppc64/makecontext.c b/arch/ppc64/makecontext.c
+index 962f98a..ea980e9 100644
+--- a/arch/ppc64/makecontext.c
++++ b/arch/ppc64/makecontext.c
+@@ -32,7 +32,7 @@ __makecontext(ucontext_t *ucp, void (*func)(void), int argc, ...)
+ int i;
+ unsigned int stack_args;
+
+- stack_args = argc > 8 ? argc - 8 : 0;
++ stack_args = argc > 8 ? argc : 0;
+
+ sp = (greg_t *) ((uintptr_t) ucp->uc_stack.ss_sp + ucp->uc_stack.ss_size);
+ sp -= stack_args + 2;
+@@ -52,7 +52,7 @@ __makecontext(ucontext_t *ucp, void (*func)(void), int argc, ...)
+ if (i < 8)
+ ucp->uc_mcontext.gp_regs[i + 3] = va_arg (va, greg_t);
+ else
+- sp[i-8 + 2] = va_arg (va, greg_t);
++ sp[i + 2] = va_arg (va, greg_t);
+ }
+
+ va_end(va);
+From a00a05ce2950ca3b306f8ccc3e817ea8cd675015 Mon Sep 17 00:00:00 2001
+From: Bobby Bingham <koorogi@koorogi.info>
+Date: Fri, 5 Apr 2019 14:03:47 -0500
+Subject: [PATCH] ppc64: fix incorrect position of parameters within stack
+ frame
+
+On PPC64, there are 4 register-sized stack slots below the parameter save
+area, which is different from the 2 stack slots on PPC32.
+---
+ arch/ppc64/makecontext.c | 4 ++--
+ 1 file changed, 2 insertions(+), 2 deletions(-)
+
+diff --git a/arch/ppc64/makecontext.c b/arch/ppc64/makecontext.c
+index ea980e9..a4c1bf9 100644
+--- a/arch/ppc64/makecontext.c
++++ b/arch/ppc64/makecontext.c
+@@ -35,7 +35,7 @@ __makecontext(ucontext_t *ucp, void (*func)(void), int argc, ...)
+ stack_args = argc > 8 ? argc : 0;
+
+ sp = (greg_t *) ((uintptr_t) ucp->uc_stack.ss_sp + ucp->uc_stack.ss_size);
+- sp -= stack_args + 2;
++ sp -= stack_args + 4;
+ sp = (greg_t *) (((uintptr_t) sp & -16L));
+
+ ucp->uc_mcontext.gp_regs[REG_NIP] = (uintptr_t) func;
+@@ -52,7 +52,7 @@ __makecontext(ucontext_t *ucp, void (*func)(void), int argc, ...)
+ if (i < 8)
+ ucp->uc_mcontext.gp_regs[i + 3] = va_arg (va, greg_t);
+ else
+- sp[i + 2] = va_arg (va, greg_t);
++ sp[i + 4] = va_arg (va, greg_t);
+ }
+
+ va_end(va);
+From 40d07758a5677e8869d7a62a499236bb6ed01897 Mon Sep 17 00:00:00 2001
+From: Bobby Bingham <koorogi@koorogi.info>
+Date: Fri, 5 Apr 2019 14:09:25 -0500
+Subject: [PATCH] ppc32/64: correct signature of function parameter to
+ makecontext
+
+Because makecontext can pass a set of integer arguments to the provided
+function, it is incorrect to require that this function accept no
+parameters.
+---
+ arch/ppc/makecontext.c | 2 +-
+ arch/ppc64/makecontext.c | 2 +-
+ 2 files changed, 2 insertions(+), 2 deletions(-)
+
+diff --git a/arch/ppc/makecontext.c b/arch/ppc/makecontext.c
+index 4a404a4..0633c0f 100644
+--- a/arch/ppc/makecontext.c
++++ b/arch/ppc/makecontext.c
+@@ -25,7 +25,7 @@ extern void __start_context(void);
+
+
+ void
+-__makecontext(ucontext_t *ucp, void (*func)(void), int argc, ...)
++__makecontext(ucontext_t *ucp, void (*func)(), int argc, ...)
+ {
+ greg_t *sp;
+ va_list va;
+diff --git a/arch/ppc64/makecontext.c b/arch/ppc64/makecontext.c
+index a4c1bf9..8a293b5 100644
+--- a/arch/ppc64/makecontext.c
++++ b/arch/ppc64/makecontext.c
+@@ -25,7 +25,7 @@ extern void __start_context(void);
+
+
+ void
+-__makecontext(ucontext_t *ucp, void (*func)(void), int argc, ...)
++__makecontext(ucontext_t *ucp, void (*func)(), int argc, ...)
+ {
+ greg_t *sp;
+ va_list va;
+From edf69879eadaec0c72ba7ef5e7d2389946c6644b Mon Sep 17 00:00:00 2001
+From: Bobby Bingham <koorogi@koorogi.info>
+Date: Fri, 5 Apr 2019 14:09:39 -0500
+Subject: [PATCH] ppc64: remove unnecessary parentheses
+
+---
+ arch/ppc64/makecontext.c | 2 +-
+ 1 file changed, 1 insertion(+), 1 deletion(-)
+
+diff --git a/arch/ppc64/makecontext.c b/arch/ppc64/makecontext.c
+index 8a293b5..84d390a 100644
+--- a/arch/ppc64/makecontext.c
++++ b/arch/ppc64/makecontext.c
+@@ -36,7 +36,7 @@ __makecontext(ucontext_t *ucp, void (*func)(), int argc, ...)
+
+ sp = (greg_t *) ((uintptr_t) ucp->uc_stack.ss_sp + ucp->uc_stack.ss_size);
+ sp -= stack_args + 4;
+- sp = (greg_t *) (((uintptr_t) sp & -16L));
++ sp = (greg_t *) ((uintptr_t) sp & -16L);
+
+ ucp->uc_mcontext.gp_regs[REG_NIP] = (uintptr_t) func;
+ ucp->uc_mcontext.gp_regs[REG_LNK] = (uintptr_t) &__start_context;
+From 29eac4259adfd85e0f4946a1080bb9e3f8c0cc2e Mon Sep 17 00:00:00 2001
+From: Bobby Bingham <koorogi@koorogi.info>
+Date: Fri, 5 Apr 2019 14:10:28 -0500
+Subject: [PATCH] ppc32/64: remove unused includes
+
+---
+ arch/ppc/makecontext.c | 2 --
+ arch/ppc64/makecontext.c | 2 --
+ 2 files changed, 4 deletions(-)
+
+diff --git a/arch/ppc/makecontext.c b/arch/ppc/makecontext.c
+index 0633c0f..7214a40 100644
+--- a/arch/ppc/makecontext.c
++++ b/arch/ppc/makecontext.c
+@@ -11,10 +11,8 @@
+ */
+
+ #define _GNU_SOURCE
+-#include <stddef.h>
+ #include <stdarg.h>
+ #include <signal.h>
+-#include <string.h>
+ #include <stdint.h>
+
+
+diff --git a/arch/ppc64/makecontext.c b/arch/ppc64/makecontext.c
+index 84d390a..2650f56 100644
+--- a/arch/ppc64/makecontext.c
++++ b/arch/ppc64/makecontext.c
+@@ -11,10 +11,8 @@
+ */
+
+ #define _GNU_SOURCE
+-#include <stddef.h>
+ #include <stdarg.h>
+ #include <signal.h>
+-#include <string.h>
+ #include <stdint.h>
+
+
+From 90ff6330e62c8f836016668c9f769af365b257cb Mon Sep 17 00:00:00 2001
+From: Bobby Bingham <koorogi@koorogi.info>
+Date: Fri, 5 Apr 2019 14:11:21 -0500
+Subject: [PATCH] ppc32/64: update copyright
+
+---
+ arch/ppc/makecontext.c | 1 +
+ arch/ppc64/makecontext.c | 1 +
+ 2 files changed, 2 insertions(+)
+
+diff --git a/arch/ppc/makecontext.c b/arch/ppc/makecontext.c
+index 7214a40..51c492f 100644
+--- a/arch/ppc/makecontext.c
++++ b/arch/ppc/makecontext.c
+@@ -1,5 +1,6 @@
+ /*
+ * Copyright (c) 2018 William Pitcock <nenolod@dereferenced.org>
++ * Copyright (c) 2019 Bobby Bingham <koorogi@koorogi.info>
+ *
+ * Permission to use, copy, modify, and/or distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+diff --git a/arch/ppc64/makecontext.c b/arch/ppc64/makecontext.c
+index 2650f56..43da557 100644
+--- a/arch/ppc64/makecontext.c
++++ b/arch/ppc64/makecontext.c
+@@ -1,5 +1,6 @@
+ /*
+ * Copyright (c) 2018 William Pitcock <nenolod@dereferenced.org>
++ * Copyright (c) 2019 Bobby Bingham <koorogi@koorogi.info>
+ *
+ * Permission to use, copy, modify, and/or distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+From 2610c7faa7b9c4114d53bb659264a6be238cd2a3 Mon Sep 17 00:00:00 2001
+From: Bobby Bingham <koorogi@koorogi.info>
+Date: Sat, 23 Feb 2019 17:12:37 -0600
+Subject: [PATCH] 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.
+---
+ Makefile | 10 +----
+ README.md | 2 +-
+ arch/ppc/getcontext.S | 20 +++++++++
+ arch/ppc/{getcontext.c => retfromsyscall.c} | 30 +++----------
+ arch/ppc/setcontext.S | 21 +++++++++
+ arch/ppc/setcontext.c | 45 -------------------
+ arch/ppc/swapcontext.S | 23 ++++++++++
+ arch/ppc/swapcontext.c | 45 -------------------
+ arch/ppc64/getcontext.S | 25 +++++++++++
+ arch/ppc64/{getcontext.c => retfromsyscall.c} | 30 +++----------
+ arch/ppc64/setcontext.S | 26 +++++++++++
+ arch/ppc64/setcontext.c | 45 -------------------
+ arch/ppc64/swapcontext.S | 28 ++++++++++++
+ arch/ppc64/swapcontext.c | 45 -------------------
+ 14 files changed, 156 insertions(+), 239 deletions(-)
+ create mode 100644 arch/ppc/getcontext.S
+ rename arch/ppc/{getcontext.c => retfromsyscall.c} (53%)
+ create mode 100644 arch/ppc/setcontext.S
+ delete mode 100644 arch/ppc/setcontext.c
+ create mode 100644 arch/ppc/swapcontext.S
+ delete mode 100644 arch/ppc/swapcontext.c
+ create mode 100644 arch/ppc64/getcontext.S
+ rename arch/ppc64/{getcontext.c => retfromsyscall.c} (53%)
+ create mode 100644 arch/ppc64/setcontext.S
+ delete mode 100644 arch/ppc64/setcontext.c
+ create mode 100644 arch/ppc64/swapcontext.S
+ delete mode 100644 arch/ppc64/swapcontext.c
+
+diff --git a/Makefile b/Makefile
+index 51365a3..d6ff1b0 100644
+--- a/Makefile
++++ b/Makefile
+@@ -2,14 +2,8 @@ ARCH := $(shell uname -m)
+
+ CFLAGS = -ggdb3 -O2 -Wall -Iarch/${ARCH}
+
+-LIBUCONTEXT_C_SRC = \
+- arch/${ARCH}/makecontext.c
+-
+-LIBUCONTEXT_S_SRC = \
+- arch/${ARCH}/getcontext.S \
+- arch/${ARCH}/setcontext.S \
+- arch/${ARCH}/swapcontext.S \
+- arch/${ARCH}/startcontext.S
++LIBUCONTEXT_C_SRC = $(wildcard arch/${ARCH}/*.c)
++LIBUCONTEXT_S_SRC = $(wildcard arch/${ARCH}/*.S)
+
+ LIBUCONTEXT_OBJ = ${LIBUCONTEXT_C_SRC:.c=.o} ${LIBUCONTEXT_S_SRC:.S=.o}
+ LIBUCONTEXT_SOVERSION = 0
+diff --git a/README.md b/README.md
+index 6bd4493..27d3d0b 100644
+--- a/README.md
++++ b/README.md
+@@ -19,7 +19,7 @@ Right now these archs are supported and should work on bare metal:
+ * aarch64
+ * s390x
+
+-These archs require kernel assistance and use a syscall (the only assembly is the trampoline):
++These archs require kernel assistance and use a syscall:
+
+ * ppc
+ * ppc64 (ELFv2 ABI spec only, ELFv1 not supported)
+diff --git a/arch/ppc/getcontext.S b/arch/ppc/getcontext.S
+new file mode 100644
+index 0000000..beffaf5
+--- /dev/null
++++ b/arch/ppc/getcontext.S
+@@ -0,0 +1,20 @@
++/*
++ * Copyright (c) 2019 Bobby Bingham <koorogi@koorogi.info>
++ *
++ * Permission to use, copy, modify, and/or distribute this software for any
++ * purpose with or without fee is hereby granted, provided that the above
++ * copyright notice and this permission notice appear in all copies.
++ *
++ * This software is provided 'as is' and without any warranty, express or
++ * implied. In no event shall the authors be liable for any damages arising
++ * from the use of this software.
++ */
++
++.global __getcontext
++.hidden __swapcontext
++__getcontext:
++ li 4, 0
++ b __swapcontext@local
++
++.weak getcontext
++getcontext = __getcontext
+diff --git a/arch/ppc/getcontext.c b/arch/ppc/retfromsyscall.c
+similarity index 53%
+rename from arch/ppc/getcontext.c
+rename to arch/ppc/retfromsyscall.c
+index 5da9dfb..3ad43c0 100644
+--- a/arch/ppc/getcontext.c
++++ b/arch/ppc/retfromsyscall.c
+@@ -1,5 +1,6 @@
+ /*
+ * Copyright (c) 2018 William Pitcock <nenolod@dereferenced.org>
++ * Copyright (c) 2019 Bobby Bingham <koorogi@koorogi.info>
+ *
+ * Permission to use, copy, modify, and/or distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+@@ -10,36 +11,15 @@
+ * from the use of this software.
+ */
+
+-#define _GNU_SOURCE
+-#include <stddef.h>
+-#include <stdarg.h>
+-#include <signal.h>
+-#include <string.h>
+-#include <stdint.h>
+ #include <errno.h>
+-#include <unistd.h>
+-#include <sys/syscall.h>
+
+-
+-int
+-__getcontext(ucontext_t *ucp)
++__attribute__ ((visibility ("hidden")))
++int __retfromsyscall(long retval)
+ {
+-#ifdef SYS_swapcontext
+- int r;
+-
+- r = syscall(SYS_swapcontext, ucp, NULL, sizeof(ucontext_t));
+- if (r < 0)
+- {
+- errno = -r;
++ if (retval < 0) {
++ errno = -retval;
+ return -1;
+ }
+-
+ return 0;
+-#else
+- errno = ENOSYS;
+- return -1;
+-#endif
+ }
+
+-
+-extern __typeof(__getcontext) getcontext __attribute__((weak, __alias__("__getcontext")));
+diff --git a/arch/ppc/setcontext.S b/arch/ppc/setcontext.S
+new file mode 100644
+index 0000000..89e6de0
+--- /dev/null
++++ b/arch/ppc/setcontext.S
+@@ -0,0 +1,21 @@
++/*
++ * Copyright (c) 2019 Bobby Bingham <koorogi@koorogi.info>
++ *
++ * Permission to use, copy, modify, and/or distribute this software for any
++ * purpose with or without fee is hereby granted, provided that the above
++ * copyright notice and this permission notice appear in all copies.
++ *
++ * This software is provided 'as is' and without any warranty, express or
++ * implied. In no event shall the authors be liable for any damages arising
++ * from the use of this software.
++ */
++
++.global __setcontext
++.hidden __swapcontext
++__setcontext:
++ mr 4, 3
++ li 3, 0
++ b __swapcontext@local
++
++.weak setcontext
++setcontext = __setcontext
+diff --git a/arch/ppc/setcontext.c b/arch/ppc/setcontext.c
+deleted file mode 100644
+index 59c65b4..0000000
+--- a/arch/ppc/setcontext.c
++++ /dev/null
+@@ -1,45 +0,0 @@
+-/*
+- * Copyright (c) 2018 William Pitcock <nenolod@dereferenced.org>
+- *
+- * Permission to use, copy, modify, and/or distribute this software for any
+- * purpose with or without fee is hereby granted, provided that the above
+- * copyright notice and this permission notice appear in all copies.
+- *
+- * This software is provided 'as is' and without any warranty, express or
+- * implied. In no event shall the authors be liable for any damages arising
+- * from the use of this software.
+- */
+-
+-#define _GNU_SOURCE
+-#include <stddef.h>
+-#include <stdarg.h>
+-#include <signal.h>
+-#include <string.h>
+-#include <stdint.h>
+-#include <errno.h>
+-#include <unistd.h>
+-#include <sys/syscall.h>
+-
+-
+-int
+-__setcontext(const ucontext_t *ucp)
+-{
+-#ifdef SYS_swapcontext
+- int r;
+-
+- r = syscall(SYS_swapcontext, NULL, (void *) ucp, sizeof(ucontext_t));
+- if (r < 0)
+- {
+- errno = -r;
+- return -1;
+- }
+-
+- return r;
+-#else
+- errno = ENOSYS;
+- return -1;
+-#endif
+-}
+-
+-
+-extern __typeof(__setcontext) setcontext __attribute__((weak, __alias__("__setcontext")));
+diff --git a/arch/ppc/swapcontext.S b/arch/ppc/swapcontext.S
+new file mode 100644
+index 0000000..24b6655
+--- /dev/null
++++ b/arch/ppc/swapcontext.S
+@@ -0,0 +1,23 @@
++/*
++ * Copyright (c) 2019 Bobby Bingham <koorogi@koorogi.info>
++ *
++ * Permission to use, copy, modify, and/or distribute this software for any
++ * purpose with or without fee is hereby granted, provided that the above
++ * copyright notice and this permission notice appear in all copies.
++ *
++ * This software is provided 'as is' and without any warranty, express or
++ * implied. In no event shall the authors be liable for any damages arising
++ * from the use of this software.
++ */
++
++.global __swapcontext
++__swapcontext:
++ li 0, 249 # SYS_swapcontext
++ li 5, 1184 # sizeof(ucontext_t)
++ sc
++
++.hidden __retfromsyscall
++ b __retfromsyscall@local
++
++.weak swapcontext
++swapcontext = __swapcontext
+diff --git a/arch/ppc/swapcontext.c b/arch/ppc/swapcontext.c
+deleted file mode 100644
+index af14bc2..0000000
+--- a/arch/ppc/swapcontext.c
++++ /dev/null
+@@ -1,45 +0,0 @@
+-/*
+- * Copyright (c) 2018 William Pitcock <nenolod@dereferenced.org>
+- *
+- * Permission to use, copy, modify, and/or distribute this software for any
+- * purpose with or without fee is hereby granted, provided that the above
+- * copyright notice and this permission notice appear in all copies.
+- *
+- * This software is provided 'as is' and without any warranty, express or
+- * implied. In no event shall the authors be liable for any damages arising
+- * from the use of this software.
+- */
+-
+-#define _GNU_SOURCE
+-#include <stddef.h>
+-#include <stdarg.h>
+-#include <signal.h>
+-#include <string.h>
+-#include <stdint.h>
+-#include <errno.h>
+-#include <unistd.h>
+-#include <sys/syscall.h>
+-
+-
+-int
+-__swapcontext(ucontext_t *oucp, const ucontext_t *ucp)
+-{
+-#ifdef SYS_swapcontext
+- int r;
+-
+- r = syscall(SYS_swapcontext, oucp, ucp, sizeof(ucontext_t));
+- if (r < 0)
+- {
+- errno = -r;
+- return -1;
+- }
+-
+- return r;
+-#else
+- errno = ENOSYS;
+- return -1;
+-#endif
+-}
+-
+-
+-extern __typeof(__swapcontext) swapcontext __attribute__((weak, __alias__("__swapcontext")));
+diff --git a/arch/ppc64/getcontext.S b/arch/ppc64/getcontext.S
+new file mode 100644
+index 0000000..935edd2
+--- /dev/null
++++ b/arch/ppc64/getcontext.S
+@@ -0,0 +1,25 @@
++/*
++ * Copyright (c) 2019 Bobby Bingham <koorogi@koorogi.info>
++ *
++ * Permission to use, copy, modify, and/or distribute this software for any
++ * purpose with or without fee is hereby granted, provided that the above
++ * copyright notice and this permission notice appear in all copies.
++ *
++ * This software is provided 'as is' and without any warranty, express or
++ * implied. In no event shall the authors be liable for any damages arising
++ * from the use of this software.
++ */
++
++.global __getcontext
++.hidden __swapcontext
++__getcontext:
++ addis 2, 12, .TOC.-__getcontext@ha
++ addi 2, 12, .TOC.-__getcontext@l
++
++ .localentry __getcontext,.-__getcontext
++
++ li 4, 0
++ b __swapcontext
++
++.weak getcontext
++getcontext = __getcontext
+diff --git a/arch/ppc64/getcontext.c b/arch/ppc64/retfromsyscall.c
+similarity index 53%
+rename from arch/ppc64/getcontext.c
+rename to arch/ppc64/retfromsyscall.c
+index 5da9dfb..3ad43c0 100644
+--- a/arch/ppc64/getcontext.c
++++ b/arch/ppc64/retfromsyscall.c
+@@ -1,5 +1,6 @@
+ /*
+ * Copyright (c) 2018 William Pitcock <nenolod@dereferenced.org>
++ * Copyright (c) 2019 Bobby Bingham <koorogi@koorogi.info>
+ *
+ * Permission to use, copy, modify, and/or distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+@@ -10,36 +11,15 @@
+ * from the use of this software.
+ */
+
+-#define _GNU_SOURCE
+-#include <stddef.h>
+-#include <stdarg.h>
+-#include <signal.h>
+-#include <string.h>
+-#include <stdint.h>
+ #include <errno.h>
+-#include <unistd.h>
+-#include <sys/syscall.h>
+
+-
+-int
+-__getcontext(ucontext_t *ucp)
++__attribute__ ((visibility ("hidden")))
++int __retfromsyscall(long retval)
+ {
+-#ifdef SYS_swapcontext
+- int r;
+-
+- r = syscall(SYS_swapcontext, ucp, NULL, sizeof(ucontext_t));
+- if (r < 0)
+- {
+- errno = -r;
++ if (retval < 0) {
++ errno = -retval;
+ return -1;
+ }
+-
+ return 0;
+-#else
+- errno = ENOSYS;
+- return -1;
+-#endif
+ }
+
+-
+-extern __typeof(__getcontext) getcontext __attribute__((weak, __alias__("__getcontext")));
+diff --git a/arch/ppc64/setcontext.S b/arch/ppc64/setcontext.S
+new file mode 100644
+index 0000000..5a0cde3
+--- /dev/null
++++ b/arch/ppc64/setcontext.S
+@@ -0,0 +1,26 @@
++/*
++ * Copyright (c) 2019 Bobby Bingham <koorogi@koorogi.info>
++ *
++ * Permission to use, copy, modify, and/or distribute this software for any
++ * purpose with or without fee is hereby granted, provided that the above
++ * copyright notice and this permission notice appear in all copies.
++ *
++ * This software is provided 'as is' and without any warranty, express or
++ * implied. In no event shall the authors be liable for any damages arising
++ * from the use of this software.
++ */
++
++.global __setcontext
++.hidden __swapcontext
++__setcontext:
++ addis 2, 12, .TOC.-__setcontext@ha
++ addi 2, 12, .TOC.-__setcontext@l
++
++ .localentry __setcontext,.-__setcontext
++
++ mr 4, 3
++ li 3, 0
++ b __swapcontext
++
++.weak setcontext
++setcontext = __setcontext
+diff --git a/arch/ppc64/setcontext.c b/arch/ppc64/setcontext.c
+deleted file mode 100644
+index 59c65b4..0000000
+--- a/arch/ppc64/setcontext.c
++++ /dev/null
+@@ -1,45 +0,0 @@
+-/*
+- * Copyright (c) 2018 William Pitcock <nenolod@dereferenced.org>
+- *
+- * Permission to use, copy, modify, and/or distribute this software for any
+- * purpose with or without fee is hereby granted, provided that the above
+- * copyright notice and this permission notice appear in all copies.
+- *
+- * This software is provided 'as is' and without any warranty, express or
+- * implied. In no event shall the authors be liable for any damages arising
+- * from the use of this software.
+- */
+-
+-#define _GNU_SOURCE
+-#include <stddef.h>
+-#include <stdarg.h>
+-#include <signal.h>
+-#include <string.h>
+-#include <stdint.h>
+-#include <errno.h>
+-#include <unistd.h>
+-#include <sys/syscall.h>
+-
+-
+-int
+-__setcontext(const ucontext_t *ucp)
+-{
+-#ifdef SYS_swapcontext
+- int r;
+-
+- r = syscall(SYS_swapcontext, NULL, (void *) ucp, sizeof(ucontext_t));
+- if (r < 0)
+- {
+- errno = -r;
+- return -1;
+- }
+-
+- return r;
+-#else
+- errno = ENOSYS;
+- return -1;
+-#endif
+-}
+-
+-
+-extern __typeof(__setcontext) setcontext __attribute__((weak, __alias__("__setcontext")));
+diff --git a/arch/ppc64/swapcontext.S b/arch/ppc64/swapcontext.S
+new file mode 100644
+index 0000000..982537a
+--- /dev/null
++++ b/arch/ppc64/swapcontext.S
+@@ -0,0 +1,28 @@
++/*
++ * Copyright (c) 2019 Bobby Bingham <koorogi@koorogi.info>
++ *
++ * Permission to use, copy, modify, and/or distribute this software for any
++ * purpose with or without fee is hereby granted, provided that the above
++ * copyright notice and this permission notice appear in all copies.
++ *
++ * This software is provided 'as is' and without any warranty, express or
++ * implied. In no event shall the authors be liable for any damages arising
++ * from the use of this software.
++ */
++
++.global __swapcontext
++__swapcontext:
++ addis 2, 12, .TOC.-__swapcontext@ha
++ addi 2, 12, .TOC.-__swapcontext@l
++
++ .localentry __swapcontext,.-__swapcontext
++
++ li 0, 249 # SYS_swapcontext
++ li 5, 1696 # sizeof(ucontext_t)
++ sc
++
++.hidden __retfromsyscall
++ b __retfromsyscall
++
++.weak swapcontext
++swapcontext = __swapcontext
+diff --git a/arch/ppc64/swapcontext.c b/arch/ppc64/swapcontext.c
+deleted file mode 100644
+index af14bc2..0000000
+--- a/arch/ppc64/swapcontext.c
++++ /dev/null
+@@ -1,45 +0,0 @@
+-/*
+- * Copyright (c) 2018 William Pitcock <nenolod@dereferenced.org>
+- *
+- * Permission to use, copy, modify, and/or distribute this software for any
+- * purpose with or without fee is hereby granted, provided that the above
+- * copyright notice and this permission notice appear in all copies.
+- *
+- * This software is provided 'as is' and without any warranty, express or
+- * implied. In no event shall the authors be liable for any damages arising
+- * from the use of this software.
+- */
+-
+-#define _GNU_SOURCE
+-#include <stddef.h>
+-#include <stdarg.h>
+-#include <signal.h>
+-#include <string.h>
+-#include <stdint.h>
+-#include <errno.h>
+-#include <unistd.h>
+-#include <sys/syscall.h>
+-
+-
+-int
+-__swapcontext(ucontext_t *oucp, const ucontext_t *ucp)
+-{
+-#ifdef SYS_swapcontext
+- int r;
+-
+- r = syscall(SYS_swapcontext, oucp, ucp, sizeof(ucontext_t));
+- if (r < 0)
+- {
+- errno = -r;
+- return -1;
+- }
+-
+- return r;
+-#else
+- errno = ENOSYS;
+- return -1;
+-#endif
+-}
+-
+-
+-extern __typeof(__swapcontext) swapcontext __attribute__((weak, __alias__("__swapcontext")));
diff --git a/system/libucontext/ppc64-assembly.patch b/system/libucontext/ppc64-assembly.patch
deleted file mode 100644
index 66fb3104d..000000000
--- a/system/libucontext/ppc64-assembly.patch
+++ /dev/null
@@ -1,331 +0,0 @@
-From 7b864e86e3e8e64fe69363137384ee9b858fe78d Mon Sep 17 00:00:00 2001
-From: Bobby Bingham <koorogi@koorogi.info>
-Date: Sat, 23 Feb 2019 17:12:37 -0600
-Subject: [PATCH 2/3] ppc64: rewrite get/set/swapcontext in assembly
-
-If getcontext makes any function call, which it does to call syscall, then
-it must spill its return address to the stack. After it returns to its
-caller, that return address can be clobbered. When setcontext is called
-to resume this saved context, the correct return address is not available.
----
- Makefile | 10 ++-------
- arch/ppc64/getcontext.S | 25 +++++++++++++++++++++
- arch/ppc64/getcontext.c | 45 -------------------------------------
- arch/ppc64/retfromsyscall.c | 24 ++++++++++++++++++++
- arch/ppc64/setcontext.S | 26 +++++++++++++++++++++
- arch/ppc64/setcontext.c | 45 -------------------------------------
- arch/ppc64/swapcontext.S | 28 +++++++++++++++++++++++
- arch/ppc64/swapcontext.c | 45 -------------------------------------
- 8 files changed, 105 insertions(+), 143 deletions(-)
- create mode 100644 arch/ppc64/getcontext.S
- delete mode 100644 arch/ppc64/getcontext.c
- create mode 100644 arch/ppc64/retfromsyscall.c
- create mode 100644 arch/ppc64/setcontext.S
- delete mode 100644 arch/ppc64/setcontext.c
- create mode 100644 arch/ppc64/swapcontext.S
- delete mode 100644 arch/ppc64/swapcontext.c
-
-diff --git a/Makefile b/Makefile
-index 51365a3..d6ff1b0 100644
---- a/Makefile
-+++ b/Makefile
-@@ -2,14 +2,8 @@ ARCH := $(shell uname -m)
-
- CFLAGS = -ggdb3 -O2 -Wall -Iarch/${ARCH}
-
--LIBUCONTEXT_C_SRC = \
-- arch/${ARCH}/makecontext.c
--
--LIBUCONTEXT_S_SRC = \
-- arch/${ARCH}/getcontext.S \
-- arch/${ARCH}/setcontext.S \
-- arch/${ARCH}/swapcontext.S \
-- arch/${ARCH}/startcontext.S
-+LIBUCONTEXT_C_SRC = $(wildcard arch/${ARCH}/*.c)
-+LIBUCONTEXT_S_SRC = $(wildcard arch/${ARCH}/*.S)
-
- LIBUCONTEXT_OBJ = ${LIBUCONTEXT_C_SRC:.c=.o} ${LIBUCONTEXT_S_SRC:.S=.o}
- LIBUCONTEXT_SOVERSION = 0
-diff --git a/arch/ppc64/getcontext.S b/arch/ppc64/getcontext.S
-new file mode 100644
-index 0000000..935edd2
---- /dev/null
-+++ b/arch/ppc64/getcontext.S
-@@ -0,0 +1,25 @@
-+/*
-+ * Copyright (c) 2019 Bobby Bingham <koorogi@koorogi.info>
-+ *
-+ * Permission to use, copy, modify, and/or distribute this software for any
-+ * purpose with or without fee is hereby granted, provided that the above
-+ * copyright notice and this permission notice appear in all copies.
-+ *
-+ * This software is provided 'as is' and without any warranty, express or
-+ * implied. In no event shall the authors be liable for any damages arising
-+ * from the use of this software.
-+ */
-+
-+.global __getcontext
-+.hidden __swapcontext
-+__getcontext:
-+ addis 2, 12, .TOC.-__getcontext@ha
-+ addi 2, 12, .TOC.-__getcontext@l
-+
-+ .localentry __getcontext,.-__getcontext
-+
-+ li 4, 0
-+ b __swapcontext
-+
-+.weak getcontext
-+getcontext = __getcontext
-diff --git a/arch/ppc64/getcontext.c b/arch/ppc64/getcontext.c
-deleted file mode 100644
-index 5da9dfb..0000000
---- a/arch/ppc64/getcontext.c
-+++ /dev/null
-@@ -1,45 +0,0 @@
--/*
-- * Copyright (c) 2018 William Pitcock <nenolod@dereferenced.org>
-- *
-- * Permission to use, copy, modify, and/or distribute this software for any
-- * purpose with or without fee is hereby granted, provided that the above
-- * copyright notice and this permission notice appear in all copies.
-- *
-- * This software is provided 'as is' and without any warranty, express or
-- * implied. In no event shall the authors be liable for any damages arising
-- * from the use of this software.
-- */
--
--#define _GNU_SOURCE
--#include <stddef.h>
--#include <stdarg.h>
--#include <signal.h>
--#include <string.h>
--#include <stdint.h>
--#include <errno.h>
--#include <unistd.h>
--#include <sys/syscall.h>
--
--
--int
--__getcontext(ucontext_t *ucp)
--{
--#ifdef SYS_swapcontext
-- int r;
--
-- r = syscall(SYS_swapcontext, ucp, NULL, sizeof(ucontext_t));
-- if (r < 0)
-- {
-- errno = -r;
-- return -1;
-- }
--
-- return 0;
--#else
-- errno = ENOSYS;
-- return -1;
--#endif
--}
--
--
--extern __typeof(__getcontext) getcontext __attribute__((weak, __alias__("__getcontext")));
-diff --git a/arch/ppc64/retfromsyscall.c b/arch/ppc64/retfromsyscall.c
-new file mode 100644
-index 0000000..22c5134
---- /dev/null
-+++ b/arch/ppc64/retfromsyscall.c
-@@ -0,0 +1,24 @@
-+/*
-+ * Copyright (c) 2019 Bobby Bingham <koorogi@koorogi.info>
-+ *
-+ * Permission to use, copy, modify, and/or distribute this software for any
-+ * purpose with or without fee is hereby granted, provided that the above
-+ * copyright notice and this permission notice appear in all copies.
-+ *
-+ * This software is provided 'as is' and without any warranty, express or
-+ * implied. In no event shall the authors be liable for any damages arising
-+ * from the use of this software.
-+ */
-+
-+#include <errno.h>
-+
-+__attribute__ ((visibility ("hidden")))
-+int __retfromsyscall(long retval)
-+{
-+ if (retval < 0) {
-+ errno = -retval;
-+ return -1;
-+ }
-+ return 0;
-+}
-+
-diff --git a/arch/ppc64/setcontext.S b/arch/ppc64/setcontext.S
-new file mode 100644
-index 0000000..5a0cde3
---- /dev/null
-+++ b/arch/ppc64/setcontext.S
-@@ -0,0 +1,26 @@
-+/*
-+ * Copyright (c) 2019 Bobby Bingham <koorogi@koorogi.info>
-+ *
-+ * Permission to use, copy, modify, and/or distribute this software for any
-+ * purpose with or without fee is hereby granted, provided that the above
-+ * copyright notice and this permission notice appear in all copies.
-+ *
-+ * This software is provided 'as is' and without any warranty, express or
-+ * implied. In no event shall the authors be liable for any damages arising
-+ * from the use of this software.
-+ */
-+
-+.global __setcontext
-+.hidden __swapcontext
-+__setcontext:
-+ addis 2, 12, .TOC.-__setcontext@ha
-+ addi 2, 12, .TOC.-__setcontext@l
-+
-+ .localentry __setcontext,.-__setcontext
-+
-+ mr 4, 3
-+ li 3, 0
-+ b __swapcontext
-+
-+.weak setcontext
-+setcontext = __setcontext
-diff --git a/arch/ppc64/setcontext.c b/arch/ppc64/setcontext.c
-deleted file mode 100644
-index 59c65b4..0000000
---- a/arch/ppc64/setcontext.c
-+++ /dev/null
-@@ -1,45 +0,0 @@
--/*
-- * Copyright (c) 2018 William Pitcock <nenolod@dereferenced.org>
-- *
-- * Permission to use, copy, modify, and/or distribute this software for any
-- * purpose with or without fee is hereby granted, provided that the above
-- * copyright notice and this permission notice appear in all copies.
-- *
-- * This software is provided 'as is' and without any warranty, express or
-- * implied. In no event shall the authors be liable for any damages arising
-- * from the use of this software.
-- */
--
--#define _GNU_SOURCE
--#include <stddef.h>
--#include <stdarg.h>
--#include <signal.h>
--#include <string.h>
--#include <stdint.h>
--#include <errno.h>
--#include <unistd.h>
--#include <sys/syscall.h>
--
--
--int
--__setcontext(const ucontext_t *ucp)
--{
--#ifdef SYS_swapcontext
-- int r;
--
-- r = syscall(SYS_swapcontext, NULL, (void *) ucp, sizeof(ucontext_t));
-- if (r < 0)
-- {
-- errno = -r;
-- return -1;
-- }
--
-- return r;
--#else
-- errno = ENOSYS;
-- return -1;
--#endif
--}
--
--
--extern __typeof(__setcontext) setcontext __attribute__((weak, __alias__("__setcontext")));
-diff --git a/arch/ppc64/swapcontext.S b/arch/ppc64/swapcontext.S
-new file mode 100644
-index 0000000..982537a
---- /dev/null
-+++ b/arch/ppc64/swapcontext.S
-@@ -0,0 +1,28 @@
-+/*
-+ * Copyright (c) 2019 Bobby Bingham <koorogi@koorogi.info>
-+ *
-+ * Permission to use, copy, modify, and/or distribute this software for any
-+ * purpose with or without fee is hereby granted, provided that the above
-+ * copyright notice and this permission notice appear in all copies.
-+ *
-+ * This software is provided 'as is' and without any warranty, express or
-+ * implied. In no event shall the authors be liable for any damages arising
-+ * from the use of this software.
-+ */
-+
-+.global __swapcontext
-+__swapcontext:
-+ addis 2, 12, .TOC.-__swapcontext@ha
-+ addi 2, 12, .TOC.-__swapcontext@l
-+
-+ .localentry __swapcontext,.-__swapcontext
-+
-+ li 0, 249 # SYS_swapcontext
-+ li 5, 1696 # sizeof(ucontext_t)
-+ sc
-+
-+.hidden __retfromsyscall
-+ b __retfromsyscall
-+
-+.weak swapcontext
-+swapcontext = __swapcontext
-diff --git a/arch/ppc64/swapcontext.c b/arch/ppc64/swapcontext.c
-deleted file mode 100644
-index af14bc2..0000000
---- a/arch/ppc64/swapcontext.c
-+++ /dev/null
-@@ -1,45 +0,0 @@
--/*
-- * Copyright (c) 2018 William Pitcock <nenolod@dereferenced.org>
-- *
-- * Permission to use, copy, modify, and/or distribute this software for any
-- * purpose with or without fee is hereby granted, provided that the above
-- * copyright notice and this permission notice appear in all copies.
-- *
-- * This software is provided 'as is' and without any warranty, express or
-- * implied. In no event shall the authors be liable for any damages arising
-- * from the use of this software.
-- */
--
--#define _GNU_SOURCE
--#include <stddef.h>
--#include <stdarg.h>
--#include <signal.h>
--#include <string.h>
--#include <stdint.h>
--#include <errno.h>
--#include <unistd.h>
--#include <sys/syscall.h>
--
--
--int
--__swapcontext(ucontext_t *oucp, const ucontext_t *ucp)
--{
--#ifdef SYS_swapcontext
-- int r;
--
-- r = syscall(SYS_swapcontext, oucp, ucp, sizeof(ucontext_t));
-- if (r < 0)
-- {
-- errno = -r;
-- return -1;
-- }
--
-- return r;
--#else
-- errno = ENOSYS;
-- return -1;
--#endif
--}
--
--
--extern __typeof(__swapcontext) swapcontext __attribute__((weak, __alias__("__swapcontext")));
---
-2.19.2
-
diff --git a/system/libucontext/ppc64-stack-layout.patch b/system/libucontext/ppc64-stack-layout.patch
deleted file mode 100644
index d030b61af..000000000
--- a/system/libucontext/ppc64-stack-layout.patch
+++ /dev/null
@@ -1,105 +0,0 @@
-From a17b01bc9df4004a1852ba272d452b0f46f5927c Mon Sep 17 00:00:00 2001
-From: Bobby Bingham <koorogi@koorogi.info>
-Date: Tue, 19 Feb 2019 06:27:28 +0000
-Subject: [PATCH 3/3] ppc64: fix stack frame layout
-
----
- arch/ppc64/makecontext.c | 48 +++++++++++++++++-----------------------
- 1 file changed, 20 insertions(+), 28 deletions(-)
-
-diff --git a/arch/ppc64/makecontext.c b/arch/ppc64/makecontext.c
-index 9d6b998..6d9841c 100644
---- a/arch/ppc64/makecontext.c
-+++ b/arch/ppc64/makecontext.c
-@@ -1,5 +1,6 @@
- /*
- * Copyright (c) 2018 William Pitcock <nenolod@dereferenced.org>
-+ * Copyright (c) 2019 Bobby Bingham <koorogi@koorogi.info>
- *
- * Permission to use, copy, modify, and/or distribute this software for any
- * purpose with or without fee is hereby granted, provided that the above
-@@ -11,32 +12,39 @@
- */
-
- #define _GNU_SOURCE
--#include <stddef.h>
- #include <stdarg.h>
- #include <signal.h>
--#include <string.h>
- #include <stdint.h>
-
--
- #include "defs.h"
-
-
- extern void __start_context(void);
-
-
-+#define SAVEARG(i,val) \
-+ do { \
-+ *(i < 8 ? &ucp->uc_mcontext.gp_regs[3+i] : argp) = val; \
-+ argp++; \
-+ } while (0)
-+
- void
- __makecontext(ucontext_t *ucp, void (*func)(void), int argc, ...)
- {
- greg_t *sp, *argp;
- va_list va;
-- int i;
-- unsigned int uc_link, stack_args;
-+ unsigned int stack_args;
-+
-+ /* We pass uc_link as an argument, so in total we have argc+1 args */
-+ stack_args = argc + 1;
-
-- stack_args = argc > 8 ? argc - 8 : 0;
-- uc_link = stack_args + 1;
-+ /* We can pass 8 args before needing the stack. If any arg is passed
-+ * on the stack, then stack space must be reserved for all args, even
-+ * though the first 8 don't need to be stored there */
-+ if (stack_args <= 8) stack_args = 0;
-
- sp = (greg_t *) ((uintptr_t) ucp->uc_stack.ss_sp + ucp->uc_stack.ss_size);
-- sp -= (uc_link + 1);
-+ sp -= stack_args + 4;
- sp = (greg_t *) (((uintptr_t) sp & -16L));
-
- ucp->uc_mcontext.gp_regs[REG_NIP] = (uintptr_t) func;
-@@ -45,29 +53,13 @@ __makecontext(ucontext_t *ucp, void (*func)(void), int argc, ...)
- ucp->uc_mcontext.gp_regs[REG_ENTRY] = (uintptr_t) func;
- ucp->uc_mcontext.gp_regs[REG_R31] = (uintptr_t) ucp->uc_link;
-
-- sp[0] = (uintptr_t) &__start_context;
-- sp[uc_link] = (uintptr_t) ucp->uc_link;
-- argp = &sp[2];
-+ sp[0] = 0;
-+ argp = &sp[4];
-
- va_start(va, argc);
-
-- for (i = 0; i < argc; i++)
-- switch (i)
-- {
-- case 0:
-- case 1:
-- case 2:
-- case 3:
-- case 4:
-- case 5:
-- case 6:
-- case 7:
-- ucp->uc_mcontext.gp_regs[i + 3] = va_arg (va, greg_t);
-- break;
-- default:
-- *argp++ = va_arg (va, greg_t);
-- break;
-- }
-+ for (int i = 0; i < argc; i++) SAVEARG(i, va_arg(va, greg_t));
-+ SAVEARG(argc, (uintptr_t) ucp->uc_link);
-
- va_end(va);
- }
---
-2.19.2
-
diff --git a/system/libucontext/static.patch b/system/libucontext/static.patch
new file mode 100644
index 000000000..a51e55f64
--- /dev/null
+++ b/system/libucontext/static.patch
@@ -0,0 +1,76 @@
+From 9cc1a2c0e62c75dc7afd20d5e337953f44693b70 Mon Sep 17 00:00:00 2001
+From: =?UTF-8?q?Gabriel=20Iva=C8=99cu?= <givascu@bitdefender.com>
+Date: Tue, 9 Apr 2019 16:07:39 +0300
+Subject: [PATCH] Build static library too
+
+---
+ Makefile | 6 +++++-
+ 1 file changed, 5 insertions(+), 1 deletion(-)
+
+diff --git a/Makefile b/Makefile
+index d6ff1b0..d81153c 100644
+--- a/Makefile
++++ b/Makefile
+@@ -8,10 +8,14 @@ LIBUCONTEXT_S_SRC = $(wildcard arch/${ARCH}/*.S)
+ LIBUCONTEXT_OBJ = ${LIBUCONTEXT_C_SRC:.c=.o} ${LIBUCONTEXT_S_SRC:.S=.o}
+ LIBUCONTEXT_SOVERSION = 0
+ LIBUCONTEXT_NAME = libucontext.so
++LIBUCONTEXT_STATIC_NAME = libucontext.a
+ LIBUCONTEXT_SONAME = libucontext.so.${LIBUCONTEXT_SOVERSION}
+ LIBUCONTEXT_PATH = /lib/${LIBUCONTEXT_SONAME}
+
+-all: ${LIBUCONTEXT_SONAME}
++all: ${LIBUCONTEXT_SONAME} ${LIBUCONTEXT_STATIC_NAME}
++
++${LIBUCONTEXT_STATIC_NAME}: ${LIBUCONTEXT_OBJ}
++ $(AR) rcs ${LIBUCONTEXT_STATIC_NAME} ${LIBUCONTEXT_OBJ}
+
+ ${LIBUCONTEXT_NAME}: ${LIBUCONTEXT_OBJ}
+ $(CC) -o ${LIBUCONTEXT_NAME} -Wl,-soname,${LIBUCONTEXT_SONAME} \
+From 2e15b383272fafbbb92882990b8f339e2c6888d2 Mon Sep 17 00:00:00 2001
+From: =?UTF-8?q?Gabriel=20Iva=C8=99cu?= <givascu@bitdefender.com>
+Date: Fri, 12 Apr 2019 10:48:24 +0300
+Subject: [PATCH] Makefile: Handle static library at clean/install
+
+---
+ .gitignore | 1 +
+ Makefile | 5 ++++-
+ 2 files changed, 5 insertions(+), 1 deletion(-)
+
+diff --git a/.gitignore b/.gitignore
+index 4fb95ca..d2e350f 100644
+--- a/.gitignore
++++ b/.gitignore
+@@ -34,5 +34,6 @@ Makefile.in
+
+ *.o
+ test_libucontext
++libucontext.a
+ libucontext.so
+ libucontext.so.*
+diff --git a/Makefile b/Makefile
+index d81153c..8a605fd 100644
+--- a/Makefile
++++ b/Makefile
+@@ -11,6 +11,7 @@ LIBUCONTEXT_NAME = libucontext.so
+ LIBUCONTEXT_STATIC_NAME = libucontext.a
+ LIBUCONTEXT_SONAME = libucontext.so.${LIBUCONTEXT_SOVERSION}
+ LIBUCONTEXT_PATH = /lib/${LIBUCONTEXT_SONAME}
++LIBUCONTEXT_STATIC_PATH = /lib/${LIBUCONTEXT_STATIC_NAME}
+
+ all: ${LIBUCONTEXT_SONAME} ${LIBUCONTEXT_STATIC_NAME}
+
+@@ -31,10 +32,12 @@ ${LIBUCONTEXT_SONAME}: ${LIBUCONTEXT_NAME}
+ $(CC) -fPIC -DPIC ${CFLAGS} ${CPPFLAGS} -c -o $@ $<
+
+ clean:
+- rm -f ${LIBUCONTEXT_NAME} ${LIBUCONTEXT_SONAME} ${LIBUCONTEXT_OBJ} test_libucontext
++ rm -f ${LIBUCONTEXT_NAME} ${LIBUCONTEXT_SONAME} ${LIBUCONTEXT_STATIC_NAME} \
++ ${LIBUCONTEXT_OBJ} test_libucontext
+
+ install: all
+ install -D -m755 ${LIBUCONTEXT_NAME} ${DESTDIR}/${LIBUCONTEXT_PATH}
++ install -D -m664 ${LIBUCONTEXT_STATIC_NAME} ${DESTDIR}/${LIBUCONTEXT_STATIC_PATH}
+ ln -sf ${LIBUCONTEXT_SONAME} ${DESTDIR}/lib/${LIBUCONTEXT_NAME}
+
+ check: test_libucontext ${LIBUCONTEXT_SONAME}