2 * Copyright (c) 1999, 2007 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 * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved
32 #import <mach/thread_status.h>
34 extern int __sigreturn(ucontext_t
*, int);
37 * sigvec registers _sigtramp as the handler for any signal requiring
38 * user-mode intervention. All _sigtramp does is find the real handler,
39 * calls it, then sigreturn's.
41 * Note that the kernel saves/restores all of our register state.
44 /* On i386, i386/sys/_sigtramp.s defines this. */
45 #if defined(__DYNAMIC__) && ! defined(__i386__)
46 int __in_sigtramp
= 0;
49 /* These defn should match the kernel one */
52 #if defined(__ppc__) || defined(__ppc64__)
54 #define UC_TRAD64_VEC 25
55 #define UC_FLAVOR_VEC 35
56 #define UC_FLAVOR64 40
57 #define UC_FLAVOR64_VEC 45
59 #define UC_DUAL_VEC 55
61 /* The following are valid mcontext sizes */
62 #define UC_FLAVOR_SIZE ((PPC_THREAD_STATE_COUNT + PPC_EXCEPTION_STATE_COUNT + PPC_FLOAT_STATE_COUNT) * sizeof(int))
64 #define UC_FLAVOR_VEC_SIZE ((PPC_THREAD_STATE_COUNT + PPC_EXCEPTION_STATE_COUNT + PPC_FLOAT_STATE_COUNT + PPC_VECTOR_STATE_COUNT) * sizeof(int))
66 #define UC_FLAVOR64_SIZE ((PPC_THREAD_STATE64_COUNT + PPC_EXCEPTION_STATE64_COUNT + PPC_FLOAT_STATE_COUNT) * sizeof(int))
68 #define UC_FLAVOR64_VEC_SIZE ((PPC_THREAD_STATE64_COUNT + PPC_EXCEPTION_STATE64_COUNT + PPC_FLOAT_STATE_COUNT + PPC_VECTOR_STATE_COUNT) * sizeof(int))
71 #define UC_SET_ALT_STACK 0x40000000
72 #define UC_RESET_ALT_STACK 0x80000000
75 /* This routine will be replaced by an assembly soon */
77 restore64_state(mcontext_t mctx
, mcontext64_t mctx64
, int sigstyle
)
79 if (mctx
->ss
.srr0
!= (unsigned int)mctx64
->ss
.srr0
)
81 if (mctx
->ss
.srr1
!= (unsigned int)mctx64
->ss
.srr1
)
83 if (mctx
->ss
.r0
!= (unsigned int)mctx64
->ss
.r0
)
85 if (mctx
->ss
.r1
!= (unsigned int)mctx64
->ss
.r1
)
87 if (mctx
->ss
.r2
!= (unsigned int)mctx64
->ss
.r2
)
89 if (mctx
->ss
.r3
!= (unsigned int)mctx64
->ss
.r3
)
91 if (mctx
->ss
.r4
!= (unsigned int)mctx64
->ss
.r4
)
93 if (mctx
->ss
.r5
!= (unsigned int)mctx64
->ss
.r5
)
95 if (mctx
->ss
.r6
!= (unsigned int)mctx64
->ss
.r6
)
97 if (mctx
->ss
.r7
!= (unsigned int)mctx64
->ss
.r7
)
99 if (mctx
->ss
.r8
!= (unsigned int)mctx64
->ss
.r8
)
101 if (mctx
->ss
.r9
!= (unsigned int)mctx64
->ss
.r9
)
103 if (mctx
->ss
.r10
!= (unsigned int)mctx64
->ss
.r10
)
105 if (mctx
->ss
.r11
!= (unsigned int)mctx64
->ss
.r11
)
107 if (mctx
->ss
.r12
!= (unsigned int)mctx64
->ss
.r12
)
109 if (mctx
->ss
.r13
!= (unsigned int)mctx64
->ss
.r13
)
111 if (mctx
->ss
.r14
!= (unsigned int)mctx64
->ss
.r14
)
113 if (mctx
->ss
.r15
!= (unsigned int)mctx64
->ss
.r15
)
115 if (mctx
->ss
.r16
!= (unsigned int)mctx64
->ss
.r16
)
117 if (mctx
->ss
.r17
!= (unsigned int)mctx64
->ss
.r17
)
119 if (mctx
->ss
.r18
!= (unsigned int)mctx64
->ss
.r18
)
121 if (mctx
->ss
.r19
!= (unsigned int)mctx64
->ss
.r19
)
123 if (mctx
->ss
.r20
!= (unsigned int)mctx64
->ss
.r20
)
125 if (mctx
->ss
.r21
!= (unsigned int)mctx64
->ss
.r21
)
127 if (mctx
->ss
.r22
!= (unsigned int)mctx64
->ss
.r22
)
129 if (mctx
->ss
.r23
!= (unsigned int)mctx64
->ss
.r23
)
131 if (mctx
->ss
.r24
!= (unsigned int)mctx64
->ss
.r24
)
133 if (mctx
->ss
.r25
!= (unsigned int)mctx64
->ss
.r25
)
135 if (mctx
->ss
.r26
!= (unsigned int)mctx64
->ss
.r26
)
137 if (mctx
->ss
.r27
!= (unsigned int)mctx64
->ss
.r27
)
139 if (mctx
->ss
.r28
!= (unsigned int)mctx64
->ss
.r28
)
141 if (mctx
->ss
.r29
!= (unsigned int)mctx64
->ss
.r29
)
143 if (mctx
->ss
.r30
!= (unsigned int)mctx64
->ss
.r30
)
145 if (mctx
->ss
.r31
!= (unsigned int)mctx64
->ss
.r31
)
148 if (mctx
->ss
.cr
!= mctx64
->ss
.cr
)
150 if (mctx
->ss
.xer
!= (unsigned int)mctx64
->ss
.xer
)
152 if (mctx
->ss
.lr
!= (unsigned int)mctx64
->ss
.lr
)
154 if (mctx
->ss
.ctr
!= (unsigned int)mctx64
->ss
.ctr
)
157 if (bcmp(&mctx
->fs
, &mctx64
->fs
, (PPC_FLOAT_STATE_COUNT
* sizeof(int))))
159 if ((sigstyle
== UC_DUAL_VEC
) && bcmp(&mctx
->vs
, &mctx64
->vs
, (PPC_VECTOR_STATE_COUNT
* sizeof(int))))
166 /* This routine is called from ppc/sys/_sigtramp.s on return from
174 int ctxstyle
= UC_FLAVOR
;
178 if ((sigstyle
== UC_DUAL
) || (sigstyle
== UC_DUAL_VEC
)) {
179 mctx
= uctx
->uc_mcontext
;
180 mctx64
= (mcontext64_t
)((char *)(uctx
->uc_mcontext
) + sizeof(struct mcontext
));
181 /* restore 64bit state ? */
182 if (restore64_state(mctx
, mctx64
, sigstyle
)) {
183 uctx
->uc_mcontext
= (void *)mctx64
;
184 if (sigstyle
== UC_DUAL
) {
185 uctx
->uc_mcsize
= UC_FLAVOR64_SIZE
;
186 ctxstyle
= UC_FLAVOR64
;
188 uctx
->uc_mcsize
= UC_FLAVOR64_VEC_SIZE
;
189 ctxstyle
= UC_FLAVOR64_VEC
;
192 if (sigstyle
== UC_DUAL
)
193 ctxstyle
= UC_FLAVOR
;
195 ctxstyle
= UC_FLAVOR_VEC
;
200 #if defined(__DYNAMIC__)
204 __sigreturn (uctx
, ctxstyle
);
210 * Reset the kernel's idea of the use of an alternate stack; this is used by
211 * both longjmp() and siglongjmp(). Nothing other than this reset is needed,
212 * since restoring the registers and other operations that would normally be
213 * done by sigreturn() are handled in user space, so we do not pass a user
214 * context (in PPC, a user context is not the same as a jmpbuf mcontext, due
215 * to having more than one set of registers, etc., for the various 32/64 etc.
219 _sigunaltstack(int set
)
221 /* sigreturn(uctx, ctxstyle); */
222 /* syscall (SYS_SIGRETURN, uctx, ctxstyle); */
223 __sigreturn (NULL
, (set
== SS_ONSTACK
) ? UC_SET_ALT_STACK
: UC_RESET_ALT_STACK
);
226 /* On these architectures, _sigtramp is implemented in assembly to
227 ensure it matches its DWARF unwind information. */
228 #if ! defined (__ppc__) && ! defined (__ppc64__) && ! defined (__i386__) \
229 && ! defined (__x86_64__)
233 union __sigaction_u __sigaction_u
,
239 int ctxstyle
= UC_FLAVOR
;
241 #if defined(__DYNAMIC__)
245 if (sigstyle
== UC_TRAD
)
248 sa_sigaction(sig
, sinfo
, uctx
);
251 #if defined(__DYNAMIC__)
254 /* sigreturn(uctx, ctxstyle); */
255 /* syscall (SYS_SIGRETURN, uctx, ctxstyle); */
256 __sigreturn (uctx
, ctxstyle
);
259 #endif /* not ppc nor ppc64 nor i386 nor x86_64 */