From 8ea5f548b9146ffeea2074a33a06bbbd07a74402 Mon Sep 17 00:00:00 2001 From: Bobby Bingham 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);