blob: 18ad810ee76dc5f21f870911a630c89330686651 [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
44ENTRY(setjmp)
Elliott Hughes8d4c55c2014-12-05 16:25:50 -080045 movl 4(%esp),%ecx
46 movl $1,(_JB_SIGFLAG * 4)(%ecx)
47 jmp .L_sigsetjmp_signal_mask
Elliott Hughes67195002013-02-13 15:12:32 -080048END(setjmp)
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080049
Elliott Hughes8d4c55c2014-12-05 16:25:50 -080050ENTRY(_setjmp)
51 movl 4(%esp),%ecx
52 movl $0,(_JB_SIGFLAG * 4)(%ecx)
53 jmp .L_sigsetjmp_no_signal_mask
54END(_setjmp)
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080055
Elliott Hughes8d4c55c2014-12-05 16:25:50 -080056ENTRY(sigsetjmp)
57 movl 4(%esp),%ecx
58 movl 8(%esp),%eax
59
60 // Record whether or not the signal mask is valid.
61 movl %eax,(_JB_SIGFLAG * 4)(%ecx)
62
63 // Do we need to save the signal mask?
64 testl %eax,%eax
65 jz 1f
66
67.L_sigsetjmp_signal_mask:
68 // Get the current signal mask.
69 PIC_PROLOGUE
70 pushl $0
71 call PIC_PLT(sigblock)
72 addl $4,%esp
73 PIC_EPILOGUE
74
75 // Save the signal mask.
76 movl 4(%esp),%ecx
77 movl %eax,(_JB_SIGMASK * 4)(%ecx)
78
79.L_sigsetjmp_no_signal_mask:
801:
81 // Save the callee-save registers.
82 movl 0(%esp),%edx
83 movl %edx,(_JB_EDX * 4)(%ecx)
84 movl %ebx,(_JB_EBX * 4)(%ecx)
85 movl %esp,(_JB_ESP * 4)(%ecx)
86 movl %ebp,(_JB_EBP * 4)(%ecx)
87 movl %esi,(_JB_ESI * 4)(%ecx)
88 movl %edi,(_JB_EDI * 4)(%ecx)
89
90 xorl %eax,%eax
91 ret
92END(sigsetjmp)
93
94ENTRY(siglongjmp)
95 // Do we have a signal mask to restore?
96 movl 4(%esp),%edx
97 cmpl $0,(_JB_SIGFLAG * 4)(%edx)
98 jz 1f
99
100 // Restore the signal mask.
101 PIC_PROLOGUE
102 pushl (_JB_SIGMASK * 4)(%edx)
103 call PIC_PLT(sigsetmask)
104 addl $4,%esp
105 PIC_EPILOGUE
106
1071:
108 // Restore the callee-save registers.
109 movl 4(%esp),%edx
110 movl 8(%esp),%eax
111 movl (_JB_EDX * 4)(%edx),%ecx
112 movl (_JB_EBX * 4)(%edx),%ebx
113 movl (_JB_ESP * 4)(%edx),%esp
114 movl (_JB_EBP * 4)(%edx),%ebp
115 movl (_JB_ESI * 4)(%edx),%esi
116 movl (_JB_EDI * 4)(%edx),%edi
117
118 testl %eax,%eax
119 jnz 2f
120 incl %eax
1212:
122 movl %ecx,0(%esp)
123 ret
124END(siglongjmp)
125
Christopher Ferris24958512015-03-25 09:12:00 -0700126ALIAS_SYMBOL(longjmp, siglongjmp)
127ALIAS_SYMBOL(_longjmp, siglongjmp)