Elliott Hughes | 4906e56 | 2013-10-04 14:55:30 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2001 Wasabi Systems, Inc. |
| 3 | * All rights reserved. |
| 4 | * |
| 5 | * Written by Frank van der Linden for Wasabi Systems, Inc. |
| 6 | * |
| 7 | * Redistribution and use in source and binary forms, with or without |
| 8 | * modification, are permitted provided that the following conditions |
| 9 | * are met: |
| 10 | * 1. Redistributions of source code must retain the above copyright |
| 11 | * notice, this list of conditions and the following disclaimer. |
| 12 | * 2. Redistributions in binary form must reproduce the above copyright |
| 13 | * notice, this list of conditions and the following disclaimer in the |
| 14 | * documentation and/or other materials provided with the distribution. |
| 15 | * 3. All advertising materials mentioning features or use of this software |
| 16 | * must display the following acknowledgement: |
| 17 | * This product includes software developed for the NetBSD Project by |
| 18 | * Wasabi Systems, Inc. |
| 19 | * 4. The name of Wasabi Systems, Inc. may not be used to endorse |
| 20 | * or promote products derived from this software without specific prior |
| 21 | * written permission. |
| 22 | * |
| 23 | * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND |
| 24 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED |
| 25 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
| 26 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC |
| 27 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 28 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 29 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 30 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
| 31 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 32 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 33 | * POSSIBILITY OF SUCH DAMAGE. |
| 34 | */ |
| 35 | |
Elliott Hughes | 851e68a | 2014-02-19 16:53:20 -0800 | [diff] [blame] | 36 | #include <private/bionic_asm.h> |
Elliott Hughes | 4906e56 | 2013-10-04 14:55:30 -0700 | [diff] [blame] | 37 | |
Elliott Hughes | 8d4c55c | 2014-12-05 16:25:50 -0800 | [diff] [blame] | 38 | // These are only the callee-saved registers. Code calling setjmp |
| 39 | // will expect the rest to be clobbered anyway. |
| 40 | |
| 41 | #define _JB_RBX 0 |
| 42 | #define _JB_RBP 1 |
| 43 | #define _JB_R12 2 |
| 44 | #define _JB_R13 3 |
| 45 | #define _JB_R14 4 |
| 46 | #define _JB_R15 5 |
| 47 | #define _JB_RSP 6 |
| 48 | #define _JB_PC 7 |
| 49 | #define _JB_SIGFLAG 8 |
| 50 | #define _JB_SIGMASK 9 |
Elliott Hughes | 1c0c0ed | 2014-12-05 22:24:49 -0800 | [diff] [blame] | 51 | #define _JB_SIGMASK_RT 10 // sigprocmask will write here too. |
Elliott Hughes | 4906e56 | 2013-10-04 14:55:30 -0700 | [diff] [blame] | 52 | |
| 53 | ENTRY(setjmp) |
Elliott Hughes | 8d4c55c | 2014-12-05 16:25:50 -0800 | [diff] [blame] | 54 | movl $1,%esi |
| 55 | jmp PIC_PLT(sigsetjmp) |
Christopher Ferris | 507cfe2 | 2013-11-19 13:45:27 -0800 | [diff] [blame] | 56 | END(setjmp) |
Elliott Hughes | 4906e56 | 2013-10-04 14:55:30 -0700 | [diff] [blame] | 57 | |
Elliott Hughes | 8d4c55c | 2014-12-05 16:25:50 -0800 | [diff] [blame] | 58 | ENTRY(_setjmp) |
| 59 | movl $0,%esi |
| 60 | jmp PIC_PLT(sigsetjmp) |
| 61 | END(_setjmp) |
Elliott Hughes | 4906e56 | 2013-10-04 14:55:30 -0700 | [diff] [blame] | 62 | |
Elliott Hughes | 8d4c55c | 2014-12-05 16:25:50 -0800 | [diff] [blame] | 63 | // int sigsetjmp(sigjmp_buf env, int save_signal_mask); |
| 64 | ENTRY(sigsetjmp) |
| 65 | // Record whether or not we're saving the signal mask. |
Elliott Hughes | 1c0c0ed | 2014-12-05 22:24:49 -0800 | [diff] [blame] | 66 | movl %esi,(_JB_SIGFLAG * 8)(%rdi) |
Elliott Hughes | 4906e56 | 2013-10-04 14:55:30 -0700 | [diff] [blame] | 67 | |
Elliott Hughes | 8d4c55c | 2014-12-05 16:25:50 -0800 | [diff] [blame] | 68 | // Do we need to save the signal mask? |
| 69 | testl %esi,%esi |
| 70 | jz 2f |
| 71 | |
Elliott Hughes | 1c0c0ed | 2014-12-05 22:24:49 -0800 | [diff] [blame] | 72 | // Save current signal mask. |
| 73 | pushq %rdi // Push 'env'. |
| 74 | // The 'how' argument is ignored if new_mask is NULL. |
| 75 | xorq %rsi,%rsi // NULL. |
| 76 | leaq (_JB_SIGMASK * 8)(%rdi),%rdx // old_mask. |
| 77 | call PIC_PLT(sigprocmask) |
| 78 | popq %rdi // Pop 'env'. |
Elliott Hughes | 8d4c55c | 2014-12-05 16:25:50 -0800 | [diff] [blame] | 79 | |
| 80 | 2: |
| 81 | // Save the callee-save registers. |
| 82 | movq (%rsp),%r11 |
| 83 | movq %rbx,(_JB_RBX * 8)(%rdi) |
| 84 | movq %rbp,(_JB_RBP * 8)(%rdi) |
| 85 | movq %r12,(_JB_R12 * 8)(%rdi) |
| 86 | movq %r13,(_JB_R13 * 8)(%rdi) |
| 87 | movq %r14,(_JB_R14 * 8)(%rdi) |
| 88 | movq %r15,(_JB_R15 * 8)(%rdi) |
| 89 | movq %rsp,(_JB_RSP * 8)(%rdi) |
| 90 | movq %r11,(_JB_PC * 8)(%rdi) |
| 91 | |
| 92 | xorl %eax,%eax |
| 93 | ret |
| 94 | END(sigsetjmp) |
| 95 | |
| 96 | // void siglongjmp(sigjmp_buf env, int value); |
| 97 | ENTRY(siglongjmp) |
| 98 | movq %rdi,%r12 |
| 99 | pushq %rsi // Push 'value'. |
| 100 | |
| 101 | // Do we need to restore the signal mask? |
Elliott Hughes | 1c0c0ed | 2014-12-05 22:24:49 -0800 | [diff] [blame] | 102 | cmpl $0,(_JB_SIGFLAG * 8)(%rdi) |
Elliott Hughes | 8d4c55c | 2014-12-05 16:25:50 -0800 | [diff] [blame] | 103 | jz 2f |
| 104 | |
| 105 | // Restore the signal mask. |
Elliott Hughes | 1c0c0ed | 2014-12-05 22:24:49 -0800 | [diff] [blame] | 106 | movq $2,%rdi // SIG_SETMASK. |
| 107 | leaq (_JB_SIGMASK * 8)(%r12),%rsi // new_mask. |
| 108 | xorq %rdx,%rdx // NULL. |
| 109 | call PIC_PLT(sigprocmask) |
Elliott Hughes | 8d4c55c | 2014-12-05 16:25:50 -0800 | [diff] [blame] | 110 | |
| 111 | 2: |
| 112 | popq %rax // Pop 'value'. |
| 113 | |
| 114 | // Restore the callee-save registers. |
| 115 | movq (_JB_RBX * 8)(%r12),%rbx |
| 116 | movq (_JB_RBP * 8)(%r12),%rbp |
| 117 | movq (_JB_R13 * 8)(%r12),%r13 |
| 118 | movq (_JB_R14 * 8)(%r12),%r14 |
| 119 | movq (_JB_R15 * 8)(%r12),%r15 |
| 120 | movq (_JB_RSP * 8)(%r12),%rsp |
| 121 | movq (_JB_PC * 8)(%r12),%r11 |
| 122 | movq (_JB_R12 * 8)(%r12),%r12 |
| 123 | |
| 124 | testl %eax,%eax |
| 125 | jnz 1f |
| 126 | incl %eax |
| 127 | 1: |
| 128 | movq %r11,0(%rsp) |
| 129 | ret |
| 130 | END(siglongjmp) |
| 131 | |
| 132 | .globl longjmp |
| 133 | .equ longjmp, siglongjmp |
| 134 | .globl _longjmp |
| 135 | .equ _longjmp, siglongjmp |