]> git.saurik.com Git - apple/libc.git/blob - i386/sys/_sigtramp.s
Libc-498.tar.gz
[apple/libc.git] / i386 / sys / _sigtramp.s
1 /*
2 * Copyright (c) 2007 Apple Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
11 * file.
12 *
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
20 *
21 * @APPLE_LICENSE_HEADER_END@
22 */
23
24 #include <sys/syscall.h>
25
26 #if defined(__DYNAMIC__)
27 .globl ___in_sigtramp
28 .data
29 .align 2
30 ___in_sigtramp:
31 .space 4
32 #endif
33
34 #define UC_TRAD 1
35 #define UC_FLAVOR 30
36
37 /* Structure fields for ucontext and mcontext. */
38 #define UCONTEXT_UC_MCONTEXT 28
39
40 #define MCONTEXT_ES_EXCEPTION 0
41 #define MCONTEXT_SS_EAX 12
42 #define MCONTEXT_SS_EBX 16
43 #define MCONTEXT_SS_ECX 20
44 #define MCONTEXT_SS_EDX 24
45 #define MCONTEXT_SS_EDI 28
46 #define MCONTEXT_SS_ESI 32
47 #define MCONTEXT_SS_EBP 36
48 #define MCONTEXT_SS_ESP 40
49 #define MCONTEXT_SS_EFLAGS 48
50 #define MCONTEXT_SS_EIP 52
51
52 /* register use:
53 %ebp frame pointer
54 %ebx Address of "L00000000001$pb"
55 %esi uctx
56
57 void
58 _sigtramp(
59 union __sigaction_u __sigaction_u,
60 int sigstyle,
61 int sig,
62 siginfo_t *sinfo,
63 ucontext_t *uctx
64 )
65 */
66
67 .globl __sigtramp
68 .text
69 .align 4,0x90
70 __sigtramp:
71 /* Although this routine does not need any stack frame, various parts
72 of the OS can't analyse the stack without them. */
73 pushl %ebp
74 movl %esp, %ebp
75 subl $24, %esp
76 movl 8(%ebp), %ecx # get '__sigaction_u'
77 #if defined(__DYNAMIC__)
78 call 0f
79 "L00000000001$pb":
80 0:
81 popl %ebx
82 incl ___in_sigtramp-"L00000000001$pb"(%ebx)
83 #endif
84 movl 16(%ebp), %edx # get 'sig'
85 movl 20(%ebp), %eax # get 'sinfo'
86 movl 24(%ebp), %esi # get 'uctx'
87 /* Call the signal handler.
88 Some variants are not supposed to get the last two parameters,
89 but the test to prevent this is more expensive than just passing
90 them. */
91 movl %esi, 8(%esp)
92 movl %eax, 4(%esp)
93 movl %edx, (%esp)
94 Lcall_start:
95 call *%ecx
96 Lcall_end:
97 #if defined(__DYNAMIC__)
98 decl ___in_sigtramp-"L00000000001$pb"(%ebx)
99 #endif
100 movl %esi, 4(%esp)
101 movl $ UC_FLAVOR, 8(%esp)
102 movl $ SYS_sigreturn, %eax
103 int $0x80
104
105 /* DWARF unwind table #defines. */
106 #define DW_CFA_advance_loc_4 0x44
107 #define DW_CFA_def_cfa 0x0c
108 #define DW_CFA_def_cfa_expression 0x0F
109 #define DW_CFA_expression 0x10
110 #define DW_CFA_val_expression 0x16
111 #define DW_CFA_offset(column) 0x80+(column)
112
113 /* DWARF expression #defines. */
114 #define DW_OP_deref 0x06
115 #define DW_OP_const1u 0x08
116 #define DW_OP_dup 0x12
117 #define DW_OP_drop 0x13
118 #define DW_OP_over 0x14
119 #define DW_OP_pick 0x15
120 #define DW_OP_swap 0x16
121 #define DW_OP_rot 0x17
122 #define DW_OP_abs 0x19
123 #define DW_OP_and 0x1a
124 #define DW_OP_div 0x1b
125 #define DW_OP_minus 0x1c
126 #define DW_OP_mod 0x1d
127 #define DW_OP_mul 0x1e
128 #define DW_OP_neg 0x1f
129 #define DW_OP_not 0x20
130 #define DW_OP_or 0x21
131 #define DW_OP_plus 0x22
132 #define DW_OP_plus_uconst 0x23
133 #define DW_OP_shl 0x24
134 #define DW_OP_shr 0x25
135 #define DW_OP_shra 0x26
136 #define DW_OP_xor 0x27
137 #define DW_OP_skip 0x2f
138 #define DW_OP_bra 0x28
139 #define DW_OP_eq 0x29
140 #define DW_OP_ge 0x2A
141 #define DW_OP_gt 0x2B
142 #define DW_OP_le 0x2C
143 #define DW_OP_lt 0x2D
144 #define DW_OP_ne 0x2E
145 #define DW_OP_lit(n) 0x30+(n)
146 #define DW_OP_breg(n) 0x70+(n)
147 #define DW_OP_deref_size 0x94
148
149 /* The location expression we'll use. */
150
151 #define loc_expr_for_reg(regno, offs) \
152 .byte DW_CFA_expression, regno, 5 /* block length */, \
153 DW_OP_breg(6), UCONTEXT_UC_MCONTEXT, DW_OP_deref, \
154 DW_OP_plus_uconst, offs
155
156 /* Unwind tables. */
157 .section __TEXT,__eh_frame,coalesced,no_toc+strip_static_syms+live_support
158 EH_frame1:
159 .set L$set$0,LECIE1-LSCIE1
160 .long L$set$0 # Length of Common Information Entry
161 LSCIE1:
162 .long 0 # CIE Identifier Tag
163 .byte 0x3 # CIE Version
164 .ascii "zR\0" # CIE Augmentation
165 .byte 0x1 # uleb128 0x1; CIE Code Alignment Factor
166 .byte 0x7c # sleb128 -4; CIE Data Alignment Factor
167 .byte 0x8 # CIE RA Column
168 .byte 0x1 # uleb128 0x1; Augmentation size
169 .byte 0x10 # FDE Encoding (pcrel)
170 .byte DW_CFA_def_cfa
171 .byte 0x5 # uleb128 0x5
172 .byte 0x4 # uleb128 0x4
173 .byte DW_CFA_offset(8)
174 .byte 0x1 # uleb128 0x1
175 .align 2
176 LECIE1:
177 .globl _sigtramp.eh
178 _sigtramp.eh:
179 LSFDE1:
180 .set L$set$1,LEFDE1-LASFDE1
181 .long L$set$1 # FDE Length
182 LASFDE1:
183 .long LASFDE1-EH_frame1 # FDE CIE offset
184 .long Lcall_start-. # FDE initial location
185 .set L$set$2,Lcall_end-Lcall_start
186 .long L$set$2 # FDE address range
187 .byte 0x0 # uleb128 0x0; Augmentation size
188
189 /* Now for the expressions, which all compute
190 uctx->uc_mcontext->register
191 for each register.
192
193 Describe even the registers that are not call-saved because they
194 might be being used in the prologue to save other registers.
195 Only integer registers are described at present. */
196
197 loc_expr_for_reg (0, MCONTEXT_SS_EAX)
198 loc_expr_for_reg (1, MCONTEXT_SS_ECX)
199 loc_expr_for_reg (2, MCONTEXT_SS_EDX)
200 loc_expr_for_reg (3, MCONTEXT_SS_EBX)
201 loc_expr_for_reg (4, MCONTEXT_SS_EBP) # note that GCC switches
202 loc_expr_for_reg (5, MCONTEXT_SS_ESP) # DWARF registers 4 & 5
203 loc_expr_for_reg (6, MCONTEXT_SS_ESI)
204 loc_expr_for_reg (7, MCONTEXT_SS_EDI)
205 loc_expr_for_reg (9, MCONTEXT_SS_EFLAGS)
206
207 /* The Intel architecture classifies exceptions into three categories,
208 'faults' which put the address of the faulting instruction
209 in EIP, 'traps' which put the following instruction in EIP,
210 and 'aborts' which don't typically report the instruction
211 causing the exception.
212
213 The traps are #BP and #OF. */
214
215 .byte DW_CFA_val_expression, 8
216 .set L$set$3,Lpc_end-Lpc_start
217 .byte L$set$3
218 Lpc_start:
219 /* Push the mcontext address twice. */
220 .byte DW_OP_breg(6), UCONTEXT_UC_MCONTEXT, DW_OP_deref, DW_OP_dup
221 /* Find the value of EIP. */
222 .byte DW_OP_plus_uconst, MCONTEXT_SS_EIP, DW_OP_deref, DW_OP_swap
223 /* Determine the exception type. */
224 .byte DW_OP_plus_uconst, MCONTEXT_ES_EXCEPTION, DW_OP_deref
225 /* Check whether it is #BP (3) or #OF (4). */
226 .byte DW_OP_dup, DW_OP_lit(3), DW_OP_ne
227 .byte DW_OP_swap, DW_OP_lit(4), DW_OP_ne, DW_OP_and
228 /* If it is, then add 1 to the instruction address, so as to point
229 within or past the faulting instruction. */
230 .byte DW_OP_plus
231 Lpc_end:
232
233 /* The CFA will have been saved as the value of ESP (it is not
234 ESP+4). */
235 .byte DW_CFA_def_cfa_expression
236 .set L$set$4,Lcfa_end-Lcfa_start
237 .byte L$set$4
238 Lcfa_start:
239 .byte DW_OP_breg(6), UCONTEXT_UC_MCONTEXT, DW_OP_deref
240 .byte DW_OP_plus_uconst, MCONTEXT_SS_ESP, DW_OP_deref
241 Lcfa_end:
242
243 .align 2
244 LEFDE1:
245
246 .subsections_via_symbols