diff options
Diffstat (limited to 'glibc')
-rw-r--r-- | glibc/sysdeps/unix/sysv/linux/riscv/getcontext.S | 1 | ||||
-rw-r--r-- | glibc/sysdeps/unix/sysv/linux/riscv/makecontext.c | 28 | ||||
-rw-r--r-- | glibc/sysdeps/unix/sysv/linux/riscv/setcontext.S | 19 |
3 files changed, 32 insertions, 16 deletions
diff --git a/glibc/sysdeps/unix/sysv/linux/riscv/getcontext.S b/glibc/sysdeps/unix/sysv/linux/riscv/getcontext.S index c5d5b72..9598ea2 100644 --- a/glibc/sysdeps/unix/sysv/linux/riscv/getcontext.S +++ b/glibc/sysdeps/unix/sysv/linux/riscv/getcontext.S @@ -32,6 +32,7 @@ LEAF (__getcontext) REG_S sp, ( 2 * SZREG + MCONTEXT_GREGS)(a0) REG_S s0, ( 8 * SZREG + MCONTEXT_GREGS)(a0) REG_S s1, ( 9 * SZREG + MCONTEXT_GREGS)(a0) + REG_S x0, (10 * SZREG + MCONTEXT_GREGS)(a0) /* return 0 */ REG_S s2, (18 * SZREG + MCONTEXT_GREGS)(a0) REG_S s3, (19 * SZREG + MCONTEXT_GREGS)(a0) REG_S s4, (20 * SZREG + MCONTEXT_GREGS)(a0) diff --git a/glibc/sysdeps/unix/sysv/linux/riscv/makecontext.c b/glibc/sysdeps/unix/sysv/linux/riscv/makecontext.c index bbbdbf3..a3836ce 100644 --- a/glibc/sysdeps/unix/sysv/linux/riscv/makecontext.c +++ b/glibc/sysdeps/unix/sysv/linux/riscv/makecontext.c @@ -9,36 +9,44 @@ void __makecontext (ucontext_t *ucp, void (*func) (void), int argc, { extern void __start_context(void) attribute_hidden; long i, sp; - va_list vl; - va_start(vl, a4); assert(REG_NARGS == 8); /* Set up the stack. */ sp = ((long)ucp->uc_stack.ss_sp + ucp->uc_stack.ss_size) & ALMASK; + /* Set up the register context. + ra = s0 = 0, terminating the stack for backtracing purposes. + s1 = the function we must call. + s2 = the subsequent context to run. */ + ucp->uc_mcontext.gregs[REG_RA] = 0; + ucp->uc_mcontext.gregs[REG_S0 + 0] = 0; + ucp->uc_mcontext.gregs[REG_S0 + 1] = (long)func; + ucp->uc_mcontext.gregs[REG_S0 + 2] = (long)ucp->uc_link; + ucp->uc_mcontext.gregs[REG_SP] = sp; + ucp->uc_mcontext.gregs[REG_PC] = (long)&__start_context; + /* Put args in a0-a7, then put any remaining args on the stack. */ ucp->uc_mcontext.gregs[REG_A0 + 0] = a0; ucp->uc_mcontext.gregs[REG_A0 + 1] = a1; ucp->uc_mcontext.gregs[REG_A0 + 2] = a2; ucp->uc_mcontext.gregs[REG_A0 + 3] = a3; ucp->uc_mcontext.gregs[REG_A0 + 4] = a4; - if (__builtin_expect(argc > 5, 0)) + + if (__builtin_expect (argc > 5, 0)) { + va_list vl; + va_start(vl, a4); + long reg_args = argc < REG_NARGS ? argc : REG_NARGS; sp = (sp - (argc - reg_args) * sizeof(long)) & ALMASK; for (i = 5; i < reg_args; i++) ucp->uc_mcontext.gregs[REG_A0 + i] = va_arg(vl, long); for (i = 0; i < argc - reg_args; i++) ((long*)sp)[i] = va_arg(vl, long); - } - - ucp->uc_mcontext.gregs[REG_S0] = (long)ucp->uc_link; - ucp->uc_mcontext.gregs[REG_SP] = sp; - ucp->uc_mcontext.gregs[REG_PC] = (long)func; - ucp->uc_mcontext.gregs[REG_RA] = (long)&__start_context; - va_end(vl); + va_end(vl); + } } weak_alias (__makecontext, makecontext) diff --git a/glibc/sysdeps/unix/sysv/linux/riscv/setcontext.S b/glibc/sysdeps/unix/sysv/linux/riscv/setcontext.S index 7ad635c..9748812 100644 --- a/glibc/sysdeps/unix/sysv/linux/riscv/setcontext.S +++ b/glibc/sysdeps/unix/sysv/linux/riscv/setcontext.S @@ -79,8 +79,8 @@ LEAF (__setcontext) /* Note the contents of argument registers will be random unless makecontext() has been called. */ REG_L t1, MCONTEXT_PC(t0) - REG_L ra, ( 1 * SZREG + MCONTEXT_GREGS)(t0) - REG_L sp, ( 2 * SZREG + MCONTEXT_GREGS)(t0) + RESTORE_INT_REG_CFI (ra, 1, t0) + RESTORE_INT_REG (sp, 2, t0) RESTORE_INT_REG_CFI (s0, 8, t0) RESTORE_INT_REG_CFI (s1, 9, t0) RESTORE_INT_REG (a0, 10, t0) @@ -111,9 +111,16 @@ weak_alias (__setcontext, setcontext) LEAF (__start_context) - /* if (link == 0) exit(0); else __setcontext(link); */ - move a0, s0 - bnez s0, __setcontext - j exit + /* Terminate call stack by noting ra == 0. Happily, s0 == 0 here. */ + cfi_register (ra, s0) + + /* Call the function passed to makecontext. */ + jalr s1 + + /* Invoke subsequent context if present, else exit(0). */ + mv a0, s2 + beqz s2, 1f + jal __setcontext +1: j exit PSEUDO_END (__start_context) |