The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 1 | /*- |
| 2 | * Copyright (c) 1990 The Regents of the University of California. |
| 3 | * All rights reserved. |
| 4 | * |
| 5 | * This code is derived from software contributed to Berkeley by |
| 6 | * William Jolitz. |
| 7 | * |
| 8 | * Redistribution and use in source and binary forms, with or without |
| 9 | * modification, are permitted provided that the following conditions |
| 10 | * are met: |
| 11 | * 1. Redistributions of source code must retain the above copyright |
| 12 | * notice, this list of conditions and the following disclaimer. |
| 13 | * 2. Redistributions in binary form must reproduce the above copyright |
| 14 | * notice, this list of conditions and the following disclaimer in the |
| 15 | * documentation and/or other materials provided with the distribution. |
| 16 | * 3. Neither the name of the University nor the names of its contributors |
| 17 | * may be used to endorse or promote products derived from this software |
| 18 | * without specific prior written permission. |
| 19 | * |
| 20 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND |
| 21 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 22 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 23 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE |
| 24 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 25 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
| 26 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
| 27 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
| 28 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
| 29 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| 30 | * SUCH DAMAGE. |
| 31 | */ |
| 32 | |
Elliott Hughes | 851e68a | 2014-02-19 16:53:20 -0800 | [diff] [blame] | 33 | #include <private/bionic_asm.h> |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 34 | |
Elliott Hughes | 8d4c55c | 2014-12-05 16:25:50 -0800 | [diff] [blame] | 35 | #define _JB_EDX 0 |
| 36 | #define _JB_EBX 1 |
| 37 | #define _JB_ESP 2 |
| 38 | #define _JB_EBP 3 |
| 39 | #define _JB_ESI 4 |
| 40 | #define _JB_EDI 5 |
| 41 | #define _JB_SIGMASK 6 |
| 42 | #define _JB_SIGFLAG 7 |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 43 | |
Josh Gao | 85c14fb | 2015-09-15 11:30:35 -0700 | [diff] [blame] | 44 | .macro m_mangle_registers reg |
| 45 | xorl \reg,%edx |
| 46 | xorl \reg,%ebx |
| 47 | xorl \reg,%esp |
| 48 | xorl \reg,%ebp |
| 49 | xorl \reg,%esi |
| 50 | xorl \reg,%edi |
| 51 | .endm |
| 52 | |
| 53 | .macro m_unmangle_registers reg |
| 54 | m_mangle_registers \reg |
| 55 | .endm |
| 56 | |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 57 | ENTRY(setjmp) |
Elliott Hughes | 8d4c55c | 2014-12-05 16:25:50 -0800 | [diff] [blame] | 58 | movl 4(%esp),%ecx |
Josh Gao | 85c14fb | 2015-09-15 11:30:35 -0700 | [diff] [blame] | 59 | mov $1,%eax |
| 60 | jmp .L_sigsetjmp |
Elliott Hughes | 6719500 | 2013-02-13 15:12:32 -0800 | [diff] [blame] | 61 | END(setjmp) |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 62 | |
Elliott Hughes | 8d4c55c | 2014-12-05 16:25:50 -0800 | [diff] [blame] | 63 | ENTRY(_setjmp) |
| 64 | movl 4(%esp),%ecx |
Josh Gao | 85c14fb | 2015-09-15 11:30:35 -0700 | [diff] [blame] | 65 | movl $0,%eax |
| 66 | jmp .L_sigsetjmp |
Elliott Hughes | 8d4c55c | 2014-12-05 16:25:50 -0800 | [diff] [blame] | 67 | END(_setjmp) |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 68 | |
Elliott Hughes | 8d4c55c | 2014-12-05 16:25:50 -0800 | [diff] [blame] | 69 | ENTRY(sigsetjmp) |
| 70 | movl 4(%esp),%ecx |
| 71 | movl 8(%esp),%eax |
| 72 | |
Josh Gao | 85c14fb | 2015-09-15 11:30:35 -0700 | [diff] [blame] | 73 | .L_sigsetjmp: |
| 74 | PIC_PROLOGUE |
| 75 | pushl %eax |
| 76 | call PIC_PLT(__bionic_setjmp_cookie_get) |
| 77 | addl $4,%esp |
| 78 | PIC_EPILOGUE |
| 79 | |
| 80 | // Record the setjmp cookie and whether or not we're saving the signal mask. |
Elliott Hughes | 8d4c55c | 2014-12-05 16:25:50 -0800 | [diff] [blame] | 81 | movl %eax,(_JB_SIGFLAG * 4)(%ecx) |
| 82 | |
| 83 | // Do we need to save the signal mask? |
Josh Gao | 85c14fb | 2015-09-15 11:30:35 -0700 | [diff] [blame] | 84 | testl $1,%eax |
Elliott Hughes | 8d4c55c | 2014-12-05 16:25:50 -0800 | [diff] [blame] | 85 | jz 1f |
| 86 | |
Elliott Hughes | 8d4c55c | 2014-12-05 16:25:50 -0800 | [diff] [blame] | 87 | // Get the current signal mask. |
| 88 | PIC_PROLOGUE |
| 89 | pushl $0 |
| 90 | call PIC_PLT(sigblock) |
| 91 | addl $4,%esp |
| 92 | PIC_EPILOGUE |
| 93 | |
| 94 | // Save the signal mask. |
| 95 | movl 4(%esp),%ecx |
| 96 | movl %eax,(_JB_SIGMASK * 4)(%ecx) |
| 97 | |
Elliott Hughes | 8d4c55c | 2014-12-05 16:25:50 -0800 | [diff] [blame] | 98 | 1: |
Josh Gao | 85c14fb | 2015-09-15 11:30:35 -0700 | [diff] [blame] | 99 | // Fetch the setjmp cookie and clear the signal flag bit. |
| 100 | movl (_JB_SIGFLAG * 4)(%ecx),%eax |
| 101 | andl $-2,%eax |
| 102 | |
Elliott Hughes | 8d4c55c | 2014-12-05 16:25:50 -0800 | [diff] [blame] | 103 | // Save the callee-save registers. |
| 104 | movl 0(%esp),%edx |
Josh Gao | 85c14fb | 2015-09-15 11:30:35 -0700 | [diff] [blame] | 105 | m_mangle_registers %eax |
Elliott Hughes | 8d4c55c | 2014-12-05 16:25:50 -0800 | [diff] [blame] | 106 | movl %edx,(_JB_EDX * 4)(%ecx) |
| 107 | movl %ebx,(_JB_EBX * 4)(%ecx) |
| 108 | movl %esp,(_JB_ESP * 4)(%ecx) |
| 109 | movl %ebp,(_JB_EBP * 4)(%ecx) |
| 110 | movl %esi,(_JB_ESI * 4)(%ecx) |
| 111 | movl %edi,(_JB_EDI * 4)(%ecx) |
Josh Gao | 85c14fb | 2015-09-15 11:30:35 -0700 | [diff] [blame] | 112 | m_unmangle_registers %eax |
Elliott Hughes | 8d4c55c | 2014-12-05 16:25:50 -0800 | [diff] [blame] | 113 | |
| 114 | xorl %eax,%eax |
| 115 | ret |
| 116 | END(sigsetjmp) |
| 117 | |
| 118 | ENTRY(siglongjmp) |
| 119 | // Do we have a signal mask to restore? |
| 120 | movl 4(%esp),%edx |
Josh Gao | 85c14fb | 2015-09-15 11:30:35 -0700 | [diff] [blame] | 121 | movl (_JB_SIGFLAG * 4)(%edx), %eax |
| 122 | testl $1,%eax |
Elliott Hughes | 8d4c55c | 2014-12-05 16:25:50 -0800 | [diff] [blame] | 123 | jz 1f |
| 124 | |
| 125 | // Restore the signal mask. |
| 126 | PIC_PROLOGUE |
| 127 | pushl (_JB_SIGMASK * 4)(%edx) |
| 128 | call PIC_PLT(sigsetmask) |
| 129 | addl $4,%esp |
| 130 | PIC_EPILOGUE |
| 131 | |
| 132 | 1: |
| 133 | // Restore the callee-save registers. |
| 134 | movl 4(%esp),%edx |
| 135 | movl 8(%esp),%eax |
Josh Gao | 85c14fb | 2015-09-15 11:30:35 -0700 | [diff] [blame] | 136 | |
| 137 | movl (_JB_SIGFLAG * 4)(%edx),%ecx |
| 138 | andl $-2,%ecx |
| 139 | |
| 140 | movl %ecx,%ebx |
| 141 | movl %ecx,%esp |
| 142 | movl %ecx,%ebp |
| 143 | movl %ecx,%esi |
| 144 | movl %ecx,%edi |
| 145 | xorl (_JB_EDX * 4)(%edx),%ecx |
| 146 | xorl (_JB_EBX * 4)(%edx),%ebx |
| 147 | xorl (_JB_ESP * 4)(%edx),%esp |
| 148 | xorl (_JB_EBP * 4)(%edx),%ebp |
| 149 | xorl (_JB_ESI * 4)(%edx),%esi |
| 150 | xorl (_JB_EDI * 4)(%edx),%edi |
| 151 | |
| 152 | PIC_PROLOGUE |
| 153 | pushl %eax |
Josh Gao | 8dbf02d | 2015-10-07 13:51:59 -0700 | [diff] [blame] | 154 | pushl %ecx |
Josh Gao | 85c14fb | 2015-09-15 11:30:35 -0700 | [diff] [blame] | 155 | pushl (_JB_SIGFLAG * 4)(%edx) |
| 156 | call PIC_PLT(__bionic_setjmp_cookie_check) |
| 157 | addl $4,%esp |
Josh Gao | 8dbf02d | 2015-10-07 13:51:59 -0700 | [diff] [blame] | 158 | popl %ecx |
Josh Gao | 85c14fb | 2015-09-15 11:30:35 -0700 | [diff] [blame] | 159 | popl %eax |
| 160 | PIC_EPILOGUE |
Elliott Hughes | 8d4c55c | 2014-12-05 16:25:50 -0800 | [diff] [blame] | 161 | |
| 162 | testl %eax,%eax |
| 163 | jnz 2f |
| 164 | incl %eax |
| 165 | 2: |
| 166 | movl %ecx,0(%esp) |
| 167 | ret |
| 168 | END(siglongjmp) |
| 169 | |
Christopher Ferris | 2495851 | 2015-03-25 09:12:00 -0700 | [diff] [blame] | 170 | ALIAS_SYMBOL(longjmp, siglongjmp) |
| 171 | ALIAS_SYMBOL(_longjmp, siglongjmp) |