From 55168fcb1809dde45c99450f1f3be27716c473db Mon Sep 17 00:00:00 2001 From: Bobby Bingham 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); }