blob: 86e6e3cd598244c2ec95085059a5e4ca4849a0e6 [file] [log] [blame]
The Android Open Source Project1dc9e472009-03-03 19:28:35 -08001/*-
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 Hughes851e68a2014-02-19 16:53:20 -080033#include <private/bionic_asm.h>
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080034
Elliott Hughes8d4c55c2014-12-05 16:25:50 -080035#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 Project1dc9e472009-03-03 19:28:35 -080043
Josh Gao85c14fb2015-09-15 11:30:35 -070044.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 Project1dc9e472009-03-03 19:28:35 -080057ENTRY(setjmp)
Elliott Hughes8d4c55c2014-12-05 16:25:50 -080058 movl 4(%esp),%ecx
Josh Gao85c14fb2015-09-15 11:30:35 -070059 mov $1,%eax
60 jmp .L_sigsetjmp
Elliott Hughes67195002013-02-13 15:12:32 -080061END(setjmp)
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080062
Elliott Hughes8d4c55c2014-12-05 16:25:50 -080063ENTRY(_setjmp)
64 movl 4(%esp),%ecx
Josh Gao85c14fb2015-09-15 11:30:35 -070065 movl $0,%eax
66 jmp .L_sigsetjmp
Elliott Hughes8d4c55c2014-12-05 16:25:50 -080067END(_setjmp)
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080068
Elliott Hughes8d4c55c2014-12-05 16:25:50 -080069ENTRY(sigsetjmp)
70 movl 4(%esp),%ecx
71 movl 8(%esp),%eax
72
Josh Gao85c14fb2015-09-15 11:30:35 -070073.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 Hughes8d4c55c2014-12-05 16:25:50 -080081 movl %eax,(_JB_SIGFLAG * 4)(%ecx)
82
83 // Do we need to save the signal mask?
Josh Gao85c14fb2015-09-15 11:30:35 -070084 testl $1,%eax
Elliott Hughes8d4c55c2014-12-05 16:25:50 -080085 jz 1f
86
Elliott Hughes8d4c55c2014-12-05 16:25:50 -080087 // 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 Hughes8d4c55c2014-12-05 16:25:50 -0800981:
Josh Gao85c14fb2015-09-15 11:30:35 -070099 // Fetch the setjmp cookie and clear the signal flag bit.
100 movl (_JB_SIGFLAG * 4)(%ecx),%eax
101 andl $-2,%eax
102
Elliott Hughes8d4c55c2014-12-05 16:25:50 -0800103 // Save the callee-save registers.
104 movl 0(%esp),%edx
Josh Gao85c14fb2015-09-15 11:30:35 -0700105 m_mangle_registers %eax
Elliott Hughes8d4c55c2014-12-05 16:25:50 -0800106 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 Gao85c14fb2015-09-15 11:30:35 -0700112 m_unmangle_registers %eax
Elliott Hughes8d4c55c2014-12-05 16:25:50 -0800113
114 xorl %eax,%eax
115 ret
116END(sigsetjmp)
117
118ENTRY(siglongjmp)
119 // Do we have a signal mask to restore?
120 movl 4(%esp),%edx
Josh Gao85c14fb2015-09-15 11:30:35 -0700121 movl (_JB_SIGFLAG * 4)(%edx), %eax
122 testl $1,%eax
Elliott Hughes8d4c55c2014-12-05 16:25:50 -0800123 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
1321:
133 // Restore the callee-save registers.
134 movl 4(%esp),%edx
135 movl 8(%esp),%eax
Josh Gao85c14fb2015-09-15 11:30:35 -0700136
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 Gao8dbf02d2015-10-07 13:51:59 -0700154 pushl %ecx
Josh Gao85c14fb2015-09-15 11:30:35 -0700155 pushl (_JB_SIGFLAG * 4)(%edx)
156 call PIC_PLT(__bionic_setjmp_cookie_check)
157 addl $4,%esp
Josh Gao8dbf02d2015-10-07 13:51:59 -0700158 popl %ecx
Josh Gao85c14fb2015-09-15 11:30:35 -0700159 popl %eax
160 PIC_EPILOGUE
Elliott Hughes8d4c55c2014-12-05 16:25:50 -0800161
162 testl %eax,%eax
163 jnz 2f
164 incl %eax
1652:
166 movl %ecx,0(%esp)
167 ret
168END(siglongjmp)
169
Christopher Ferris24958512015-03-25 09:12:00 -0700170ALIAS_SYMBOL(longjmp, siglongjmp)
171ALIAS_SYMBOL(_longjmp, siglongjmp)