s390x: fix makecontext(3) implementation for passing arguments via stack

pull/17/head
Ariadne Conill 2020-03-30 01:04:16 -05:00
parent f708c95659
commit ef42ad682a
1 changed files with 12 additions and 23 deletions

View File

@ -28,41 +28,30 @@ extern int __setcontext(const ucontext_t *ucp);
void void
__makecontext(ucontext_t *ucp, void (*func)(void), int argc, ...) __makecontext(ucontext_t *ucp, void (*func)(void), int argc, ...)
{ {
greg_t *sp, *argp; greg_t *sp;
va_list va; va_list va;
int i; int i;
unsigned int stack_args;
stack_args = argc > 5 ? argc - 5 : 0;
sp = (greg_t *) ((uintptr_t) ucp->uc_stack.ss_sp + ucp->uc_stack.ss_size); sp = (greg_t *) ((uintptr_t) ucp->uc_stack.ss_sp + ucp->uc_stack.ss_size);
sp -= stack_args; // maybe +1 sp = (greg_t *) (((uintptr_t) sp & -8L));
sp = (greg_t *) (((uintptr_t) sp & -16L));
ucp->uc_mcontext.gregs[7] = (uintptr_t) func; ucp->uc_mcontext.gregs[7] = (uintptr_t) func;
ucp->uc_mcontext.gregs[8] = (uintptr_t) ucp->uc_link; ucp->uc_mcontext.gregs[8] = (uintptr_t) ucp->uc_link;
ucp->uc_mcontext.gregs[9] = (uintptr_t) &__setcontext; ucp->uc_mcontext.gregs[9] = (uintptr_t) &__setcontext;
ucp->uc_mcontext.gregs[14] = (uintptr_t) &__start_context; ucp->uc_mcontext.gregs[14] = (uintptr_t) &__start_context;
argp = sp;
va_start(va, argc); va_start(va, argc);
for (i = 0; i < argc; i++) for (i = 0; i < argc && i < 5; i++)
switch (i) ucp->uc_mcontext.gregs[i + 2] = va_arg (va, greg_t);
{
case 0: if (argc > 5)
case 1: {
case 2: sp -= argc - 5;
case 3:
case 4: for (i = 5; i < argc; i++)
case 5: sp[i - 5] = va_arg (va, greg_t);
ucp->uc_mcontext.gregs[i + 2] = va_arg (va, greg_t); }
break;
default:
*argp++ = va_arg (va, greg_t);
break;
}
va_end(va); va_end(va);