2 * Copyright (c) 1999 Apple Computer, 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
30 #import <mach/thread_status.h>
33 * sigvec registers _sigtramp as the handler for any signal requiring
34 * user-mode intervention. All _sigtramp does is find the real handler,
35 * calls it, then sigreturn's.
37 * Note that the kernel saves/restores all of our register state.
39 #if defined(__DYNAMIC__)
40 int __in_sigtramp
= 0;
43 /* These defn should match the kernel one */
46 #if defined(__ppc__) || defined(__ppc64__)
48 #define UC_TRAD64_VEC 25
49 #define UC_FLAVOR_VEC 35
50 #define UC_FLAVOR64 40
51 #define UC_FLAVOR64_VEC 45
53 #define UC_DUAL_VEC 55
55 /* The following are valid mcontext sizes */
56 #define UC_FLAVOR_SIZE ((PPC_THREAD_STATE_COUNT + PPC_EXCEPTION_STATE_COUNT + PPC_FLOAT_STATE_COUNT) * sizeof(int))
58 #define UC_FLAVOR_VEC_SIZE ((PPC_THREAD_STATE_COUNT + PPC_EXCEPTION_STATE_COUNT + PPC_FLOAT_STATE_COUNT + PPC_VECTOR_STATE_COUNT) * sizeof(int))
60 #define UC_FLAVOR64_SIZE ((PPC_THREAD_STATE64_COUNT + PPC_EXCEPTION_STATE64_COUNT + PPC_FLOAT_STATE_COUNT) * sizeof(int))
62 #define UC_FLAVOR64_VEC_SIZE ((PPC_THREAD_STATE64_COUNT + PPC_EXCEPTION_STATE64_COUNT + PPC_FLOAT_STATE_COUNT + PPC_VECTOR_STATE_COUNT) * sizeof(int))
65 #if defined(__ppc__) || defined(__ppc64__)
66 /* This routine will be replaced by an assembly soon */
68 restore64_state(mcontext_t mctx
, mcontext64_t mctx64
, int sigstyle
)
70 if (mctx
->ss
.srr0
!= (unsigned int)mctx64
->ss
.srr0
)
72 if (mctx
->ss
.srr1
!= (unsigned int)mctx64
->ss
.srr1
)
74 if (mctx
->ss
.r0
!= (unsigned int)mctx64
->ss
.r0
)
76 if (mctx
->ss
.r1
!= (unsigned int)mctx
->ss
.r1
)
78 if (mctx
->ss
.r2
!= (unsigned int)mctx
->ss
.r2
)
80 if (mctx
->ss
.r3
!= (unsigned int)mctx
->ss
.r3
)
82 if (mctx
->ss
.r4
!= (unsigned int)mctx
->ss
.r4
)
84 if (mctx
->ss
.r5
!= (unsigned int)mctx
->ss
.r5
)
86 if (mctx
->ss
.r6
!= (unsigned int)mctx
->ss
.r6
)
88 if (mctx
->ss
.r7
!= (unsigned int)mctx
->ss
.r7
)
90 if (mctx
->ss
.r8
!= (unsigned int)mctx
->ss
.r8
)
92 if (mctx
->ss
.r9
!= (unsigned int)mctx
->ss
.r9
)
94 if (mctx
->ss
.r10
!= (unsigned int)mctx
->ss
.r10
)
96 if (mctx
->ss
.r11
!= (unsigned int)mctx
->ss
.r11
)
98 if (mctx
->ss
.r12
!= (unsigned int)mctx
->ss
.r12
)
100 if (mctx
->ss
.r13
!= (unsigned int)mctx
->ss
.r13
)
102 if (mctx
->ss
.r14
!= (unsigned int)mctx
->ss
.r14
)
104 if (mctx
->ss
.r15
!= (unsigned int)mctx
->ss
.r15
)
106 if (mctx
->ss
.r16
!= (unsigned int)mctx
->ss
.r16
)
108 if (mctx
->ss
.r17
!= (unsigned int)mctx
->ss
.r17
)
110 if (mctx
->ss
.r18
!= (unsigned int)mctx
->ss
.r18
)
112 if (mctx
->ss
.r19
!= (unsigned int)mctx
->ss
.r19
)
114 if (mctx
->ss
.r20
!= (unsigned int)mctx
->ss
.r20
)
116 if (mctx
->ss
.r21
!= (unsigned int)mctx
->ss
.r21
)
118 if (mctx
->ss
.r22
!= (unsigned int)mctx64
->ss
.r22
)
120 if (mctx
->ss
.r23
!= (unsigned int)mctx64
->ss
.r23
)
122 if (mctx
->ss
.r24
!= (unsigned int)mctx64
->ss
.r24
)
124 if (mctx
->ss
.r25
!= (unsigned int)mctx64
->ss
.r25
)
126 if (mctx
->ss
.r26
!= (unsigned int)mctx64
->ss
.r26
)
128 if (mctx
->ss
.r27
!= (unsigned int)mctx64
->ss
.r27
)
130 if (mctx
->ss
.r28
!= (unsigned int)mctx64
->ss
.r28
)
132 if (mctx
->ss
.r29
!= (unsigned int)mctx64
->ss
.r29
)
134 if (mctx
->ss
.r30
!= (unsigned int)mctx64
->ss
.r30
)
136 if (mctx
->ss
.r31
!= (unsigned int)mctx64
->ss
.r31
)
139 if (mctx
->ss
.cr
!= mctx64
->ss
.cr
)
141 if (mctx
->ss
.xer
!= (unsigned int)mctx64
->ss
.xer
)
143 if (mctx
->ss
.lr
!= (unsigned int)mctx64
->ss
.lr
)
145 if (mctx
->ss
.ctr
!= (unsigned int)mctx64
->ss
.ctr
)
148 if (bcmp(&mctx
->fs
, &mctx64
->ss
, (PPC_FLOAT_STATE_COUNT
* sizeof(int))))
150 if ((sigstyle
== UC_DUAL_VEC
) && bcmp(&mctx
->vs
, &mctx64
->vs
, (PPC_VECTOR_STATE_COUNT
* sizeof(int))))
161 union __sigaction_u __sigaction_u
,
167 int ctxstyle
= UC_FLAVOR
;
168 #if defined(__ppc__) || defined(__ppc64__)
173 #if defined(__DYNAMIC__)
176 #if defined(__i386__) || defined(__x86_64__)
177 if (sigstyle
== UC_TRAD
)
180 sa_sigaction(sig
, sinfo
, uctx
);
182 #elif defined(__ppc__) || defined(__ppc64__)
183 if ((sigstyle
== UC_TRAD
) || (sigstyle
== UC_TRAD64
) || (sigstyle
== UC_TRAD64_VEC
))
187 sa_sigaction(sig
, sinfo
, uctx
);
189 if ((sigstyle
== UC_DUAL
) || (sigstyle
== UC_DUAL_VEC
)) {
190 mctx
= uctx
->uc_mcontext
;
191 mctx64
= (mcontext64_t
)((char *)(uctx
->uc_mcontext
) + sizeof(struct mcontext
));
192 /* restore 64bit state ? */
193 if (restore64_state(mctx
, mctx64
, sigstyle
)) {
194 uctx
->uc_mcontext
= (void *)mctx64
;
195 if (sigstyle
== UC_DUAL
) {
196 uctx
->uc_mcsize
= UC_FLAVOR64_SIZE
;
197 ctxstyle
= UC_FLAVOR64
;
199 uctx
->uc_mcsize
= UC_FLAVOR64_VEC_SIZE
;
200 ctxstyle
= UC_FLAVOR64_VEC
;
203 if (sigstyle
== UC_DUAL
)
204 ctxstyle
= UC_FLAVOR
;
206 ctxstyle
= UC_FLAVOR_VEC
;
210 #endif /* __ppc__ || __ppc64__ */
212 #if defined(__DYNAMIC__)
215 /* sigreturn(uctx, ctxstyle); */
216 /* syscall (SYS_SIGRETURN, uctx, ctxstyle); */
217 syscall (184, uctx
, ctxstyle
);