2 * Copyright (c) 2007, 2011 Apple Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
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
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.
21 * @APPLE_LICENSE_HEADER_END@
24 #include <sys/syscall.h>
29 /* Structure fields for ucontext and mcontext. */
30 #define UCONTEXT_UC_MCONTEXT 48
32 #define MCONTEXT_ES_EXCEPTION 0
33 #define MCONTEXT_SS_RAX 16
34 #define MCONTEXT_SS_RBX 24
35 #define MCONTEXT_SS_RCX 32
36 #define MCONTEXT_SS_RDX 40
37 #define MCONTEXT_SS_RDI 48
38 #define MCONTEXT_SS_RSI 56
39 #define MCONTEXT_SS_RBP 64
40 #define MCONTEXT_SS_RSP 72
41 #define MCONTEXT_SS_R8 80
42 #define MCONTEXT_SS_RIP 144
50 union __sigaction_u __sigaction_u, %rdi
53 siginfo_t *sinfo, %rcx
60 .private_extern __sigtramp
67 /* Although this routine does not need any stack frame, various parts
68 of the OS can't analyse the stack without them. */
72 movq %rdi, %rax # set up address for call
74 #if defined(__DYNAMIC__)
75 incl ___in_sigtramp(%rip)
77 /* Save uctx in %rbx. */
79 /* Save token in %r12. */
81 /* Call the signal handler.
82 Some variants are not supposed to get the last two parameters,
83 but the test to prevent this is more expensive than just passing
91 #if defined(__DYNAMIC__)
92 decl ___in_sigtramp(%rip)
95 movl $ UC_FLAVOR, %esi
98 ud2 /* __sigreturn returning is a fatal error */
102 /* DWARF unwind table #defines. */
103 #define DW_CFA_advance_loc_4 0x44
104 #define DW_CFA_def_cfa 0x0c
105 #define DW_CFA_def_cfa_expression 0x0F
106 #define DW_CFA_expression 0x10
107 #define DW_CFA_val_expression 0x16
108 #define DW_CFA_offset(column) 0x80+(column)
110 /* DWARF expression #defines. */
111 #define DW_OP_deref 0x06
112 #define DW_OP_const1u 0x08
113 #define DW_OP_dup 0x12
114 #define DW_OP_drop 0x13
115 #define DW_OP_over 0x14
116 #define DW_OP_pick 0x15
117 #define DW_OP_swap 0x16
118 #define DW_OP_rot 0x17
119 #define DW_OP_abs 0x19
120 #define DW_OP_and 0x1a
121 #define DW_OP_div 0x1b
122 #define DW_OP_minus 0x1c
123 #define DW_OP_mod 0x1d
124 #define DW_OP_mul 0x1e
125 #define DW_OP_neg 0x1f
126 #define DW_OP_not 0x20
127 #define DW_OP_or 0x21
128 #define DW_OP_plus 0x22
129 #define DW_OP_plus_uconst 0x23
130 #define DW_OP_shl 0x24
131 #define DW_OP_shr 0x25
132 #define DW_OP_shra 0x26
133 #define DW_OP_xor 0x27
134 #define DW_OP_skip 0x2f
135 #define DW_OP_bra 0x28
136 #define DW_OP_eq 0x29
137 #define DW_OP_ge 0x2A
138 #define DW_OP_gt 0x2B
139 #define DW_OP_le 0x2C
140 #define DW_OP_lt 0x2D
141 #define DW_OP_ne 0x2E
142 #define DW_OP_lit(n) 0x30+(n)
143 #define DW_OP_breg(n) 0x70+(n)
144 #define DW_OP_deref_size 0x94
146 /* The location expression we'll use. */
148 #define loc_expr_for_reg(regno, offs) \
149 .byte DW_CFA_expression, regno, 5 /* block length */, \
150 DW_OP_breg(3), UCONTEXT_UC_MCONTEXT, DW_OP_deref, \
151 DW_OP_plus_uconst, offs
153 /* For r8 through r13 */
154 #define loc_expr_rN(regno) \
155 loc_expr_for_reg(regno, MCONTEXT_SS_R8+(8*(regno-8)))
157 /* For r14 through r15 */
158 #define loc_expr_rN_long(regno) \
159 .byte DW_CFA_expression, regno, 6 /* block length */, \
160 DW_OP_breg(3), UCONTEXT_UC_MCONTEXT, DW_OP_deref, \
161 DW_OP_plus_uconst, MCONTEXT_SS_R8+(8*(regno-8)), 1
164 .section __TEXT,__eh_frame,coalesced,no_toc+strip_static_syms+live_support
166 .set L$set$0,LECIE1-LSCIE1
167 .long L$set$0 # Length of Common Information Entry
169 .long 0 # CIE Identifier Tag
170 .byte 0x1 # CIE Version
171 .ascii "zRS\0" # CIE Augmentation
172 .byte 0x1 # uleb128 0x1; CIE Code Alignment Factor
173 .byte 0x78 # sleb128 -8; CIE Data Alignment Factor
174 .byte 0x10 # CIE RA Column
175 .byte 0x1 # uleb128 0x1; Augmentation size
176 .byte 0x10 # FDE Encoding (pcrel)
178 .byte 0x7 # uleb128 0x5
179 .byte 0x8 # uleb128 0x4
180 .byte DW_CFA_offset(16)
181 .byte 0x1 # uleb128 0x1
182 .byte DW_CFA_offset(16) // duplicate DW_CFA_offset (rip, -8) tells linker to not make compact unwind
183 .byte 0x1 # uleb128 0x1
189 .set L$set$1,LEFDE1-LASFDE1
190 .long L$set$1 # FDE Length
192 .long LASFDE1-EH_frame1 # FDE CIE offset
193 .quad Lstart-. # FDE initial location
194 .set L$set$2,Lend-Lstart
195 .quad L$set$2 # FDE address range
196 .byte 0x0 # uleb128 0x0; Augmentation size
198 /* Now for the expressions, which all compute
199 uctx->uc_mcontext->register
202 Describe even the registers that are not call-saved because they
203 might be being used in the prologue to save other registers.
204 Only integer registers are described at present. */
206 loc_expr_for_reg (0, MCONTEXT_SS_RAX)
207 loc_expr_for_reg (1, MCONTEXT_SS_RDX)
208 loc_expr_for_reg (2, MCONTEXT_SS_RCX)
209 loc_expr_for_reg (3, MCONTEXT_SS_RBX)
210 loc_expr_for_reg (4, MCONTEXT_SS_RSI)
211 loc_expr_for_reg (5, MCONTEXT_SS_RDI)
212 loc_expr_for_reg (6, MCONTEXT_SS_RBP)
213 loc_expr_for_reg (7, MCONTEXT_SS_RSP)
220 loc_expr_rN_long (14)
221 loc_expr_rN_long (15)
223 /* The Intel architecture classifies exceptions into three categories,
224 'faults' which put the address of the faulting instruction
225 in EIP, 'traps' which put the following instruction in EIP,
226 and 'aborts' which don't typically report the instruction
227 causing the exception.
229 The traps are #BP and #OF. */
231 .byte DW_CFA_val_expression, 16
232 .set L$set$3,Lpc_end-Lpc_start
235 /* Push the mcontext address twice. */
236 .byte DW_OP_breg(3), UCONTEXT_UC_MCONTEXT, DW_OP_deref, DW_OP_dup
237 /* Find the value of EIP. */
238 .byte DW_OP_plus_uconst, MCONTEXT_SS_RIP, MCONTEXT_SS_RIP >> 7
239 .byte DW_OP_deref, DW_OP_swap
240 /* Determine the exception type. */
241 .byte DW_OP_plus_uconst, MCONTEXT_ES_EXCEPTION, DW_OP_deref_size, 4
242 /* Check whether it is #BP (3) or #OF (4). */
243 .byte DW_OP_dup, DW_OP_lit(3), DW_OP_ne
244 .byte DW_OP_swap, DW_OP_lit(4), DW_OP_ne, DW_OP_and
245 /* If it is not, then add 1 to the instruction address, so as to point
246 within or past the faulting instruction. */
250 /* The CFA will have been saved as the value of RSP (it is not
252 .byte DW_CFA_def_cfa_expression
253 .set L$set$4,Lcfa_end-Lcfa_start
256 .byte DW_OP_breg(3), UCONTEXT_UC_MCONTEXT, DW_OP_deref
257 .byte DW_OP_plus_uconst, MCONTEXT_SS_RSP, DW_OP_deref
263 .subsections_via_symbols