diff options
Diffstat (limited to 'libc/sysdeps/unix/sysv/linux/sh/makecontext.S')
-rw-r--r-- | libc/sysdeps/unix/sysv/linux/sh/makecontext.S | 83 |
1 files changed, 49 insertions, 34 deletions
diff --git a/libc/sysdeps/unix/sysv/linux/sh/makecontext.S b/libc/sysdeps/unix/sysv/linux/sh/makecontext.S index 0a9e07954..a04bc9f63 100644 --- a/libc/sysdeps/unix/sysv/linux/sh/makecontext.S +++ b/libc/sysdeps/unix/sysv/linux/sh/makecontext.S @@ -1,5 +1,5 @@ /* Create new context. - Copyright (C) 2005 Free Software Foundation, Inc. + Copyright (C) 2005-2012 Free Software Foundation, Inc. This file is part of the GNU C Library. The GNU C Library is free software; you can redistribute it and/or @@ -17,6 +17,7 @@ <http://www.gnu.org/licenses/>. */ #include <sysdep.h> +#include <abort-instr.h> #include "ucontext_i.h" @@ -33,44 +34,44 @@ .align 5 ENTRY(__makecontext) mov #4, r3 - mov.l @(oSS_SP,r4), r1 - mov.l @(oSS_SIZE,r4), r2 - add r1, r2 - cmp/gt r6, r3 + mov.l @(oSS_SP,r4), r1 /* r1 <- ucb->stack_base */ + mov.l @(oSS_SIZE,r4), r2 /* r2 <- ucb->stack_size */ + add r1, r2 /* r2 <- stack_top */ + cmp/gt r3, r6 /* argc > 4? */ bf/s 1f - shlr2 r2 + shlr2 r2 /* r2 <- stack_top / 4 */ sub r6, r2 add r3, r2 1: - shll2 r2 + shll2 r2 /* r2 <- stack_top - ((argc > 4) ? 4 * (argc - 4) : 0 */ mov #oR15, r0 mov.l @(oLINK,r4), r1 - mov.l r2, @(r0,r4) - mov.l r1, @(oR8,r4) + mov.l r2, @(r0,r4) /* ucp->r15 <- r2 */ + mov.l r1, @(oR8,r4) /* ucp->r8 <- ucp->uc_link */ mov #oPC, r0 - mov.l r5, @(r0,r4) + mov.l r5, @(r0,r4) /* ucp->PC <- func */ - cmp/pl r6 + cmp/pl r6 /* argc > 0? */ bf/s .L1 dt r6 - mov.l r7, @(oR4,r4) - cmp/pl r6 + mov.l r7, @(oR4,r4) /* ucp->r4 <- argv[0] */ + cmp/pl r6 /* argc > 1? */ bf/s .L1 dt r6 mov.l @(0,r15), r1 - mov.l r1, @(oR5,r4) - cmp/pl r6 + mov.l r1, @(oR5,r4) /* ucp->r5 <- argv[1] */ + cmp/pl r6 /* argc > 2? */ bf/s .L1 dt r6 mov.l @(4,r15), r1 - mov.l r1, @(oR6,r4) - cmp/pl r6 + mov.l r1, @(oR6,r4) /* ucp->r6 <- argv[2] */ + cmp/pl r6 /* argc > 3? */ bf/s .L1 dt r6 mov.l @(8,r15), r1 - mov.l r1, @(oR7,r4) + mov.l r1, @(oR7,r4) /* ucp->r7 <- argv[3] */ mov #12,r0 -.L0: +.L0: /* Save remaining argv[] on the stack. */ cmp/pl r6 bf/s .L1 dt r6 @@ -87,7 +88,7 @@ ENTRY(__makecontext) #endif add #oPR, r4 rts - mov.l r0, @r4 + mov.l r0, @r4 /* ucp->pr <- exitcode */ #ifndef PIC .align 2 .L2: @@ -96,49 +97,63 @@ ENTRY(__makecontext) cfi_endproc .align 5 + cfi_startproc .Lexitcode: - tst r8, r8 - bt/s 2f - mov r8, r4 #ifdef PIC + mov.l r12, @-r15 + cfi_adjust_cfa_offset (4) + cfi_rel_offset (r12, 0) mova .Lgot, r0 mov.l .Lgot, r12 add r0, r12 - mov.l .L3, r1 +#endif + tst r8, r8 /* ucb->uc_link == NULL? */ + bt/s 2f + mov r8, r4 /* r4 <- ucb->uc_link */ + mov.l .Lsetcontext, r1 + sts.l pr, @-r15 + cfi_adjust_cfa_offset (4) + cfi_rel_offset (pr, 0) +#ifdef PIC bsrf r1 .LPCS0: nop #else - mov.l .L3, r1 jsr @r1 nop #endif + /* Restore to keep CFI/CFA balanced. */ + lds.l @r15+, pr + cfi_adjust_cfa_offset (-4) + cfi_restore (pr) + /* If this returns (which can happen if the syscall fails) we'll exit + the program with the return error value (-1). */ + 2: - mov.l .L4, r1 + mov.l .Lexit, r1 #ifdef PIC add r12, r1 #endif jsr @r1 mov r0, r4 -0: - bra 0b - nop + /* The 'exit' call should never return. In case it does cause the + process to terminate. */ + ABORT_INSTRUCTION_ASM .align 2 #ifdef PIC .Lgot: .long _GLOBAL_OFFSET_TABLE_ -.L3: +.Lsetcontext: .long __setcontext@PLT-(.LPCS0+2-(.)) -.L4: +.Lexit: .long HIDDEN_JUMPTARGET(exit)@GOTOFF #else -.L3: +.Lsetcontext: .long __setcontext -.L4: +.Lexit: .long HIDDEN_JUMPTARGET(exit) #endif - cfi_startproc PSEUDO_END(__makecontext) weak_alias (__makecontext, makecontext) |