]> git.saurik.com Git - apple/libc.git/blob - sys/sigtramp.c
Libc-320.1.3.tar.gz
[apple/libc.git] / sys / sigtramp.c
1 /*
2 * Copyright (c) 1999 Apple Computer, 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 * Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved
25 */
26 #import "sigcatch.h"
27 #import <signal.h>
28 #import <sys/signal.h>
29 #import <ucontext.h>
30
31 /*
32 * sigvec registers _sigtramp as the handler for any signal requiring
33 * user-mode intervention. All _sigtramp does is find the real handler,
34 * calls it, then sigreturn's.
35 *
36 * Note that the kernel saves/restores all of our register state.
37 */
38 #if defined(__DYNAMIC__)
39 int __in_sigtramp = 0;
40 #endif
41
42 /* These defn should match the kernel one */
43 #define UC_TRAD 1
44 #ifdef __ppc__
45 #define UC_TRAD64 20
46 #define UC_TRAD64_VEC 25
47 #define UC_FLAVOR 30
48 #define UC_FLAVOR_VEC 35
49 #define UC_FLAVOR64 40
50 #define UC_FLAVOR64_VEC 45
51 #define UC_DUAL 50
52 #define UC_DUAL_VEC 55
53
54 /* The following are valid mcontext sizes */
55 #define UC_FLAVOR_SIZE ((PPC_THREAD_STATE_COUNT + PPC_EXCEPTION_STATE_COUNT + PPC_FLOAT_STATE_COUNT) * sizeof(int))
56
57 #define UC_FLAVOR_VEC_SIZE ((PPC_THREAD_STATE_COUNT + PPC_EXCEPTION_STATE_COUNT + PPC_FLOAT_STATE_COUNT + PPC_VECTOR_STATE_COUNT) * sizeof(int))
58
59 #define UC_FLAVOR64_SIZE ((PPC_THREAD_STATE64_COUNT + PPC_EXCEPTION_STATE64_COUNT + PPC_FLOAT_STATE_COUNT) * sizeof(int))
60
61 #define UC_FLAVOR64_VEC_SIZE ((PPC_THREAD_STATE64_COUNT + PPC_EXCEPTION_STATE64_COUNT + PPC_FLOAT_STATE_COUNT + PPC_VECTOR_STATE_COUNT) * sizeof(int))
62 #endif
63
64 #ifdef __ppc__
65 /* This routine will be replaced by an assembly soon */
66 static int
67 restore64_state(mcontext_t mctx, mcontext64_t mctx64, int sigstyle)
68 {
69 if (mctx->ss.srr0 != (unsigned int)mctx64->ss.srr0)
70 return(0);
71 if (mctx->ss.srr1 != (unsigned int)mctx64->ss.srr1)
72 return(0);
73 if (mctx->ss.r0 != (unsigned int)mctx64->ss.r0)
74 return(0);
75 if (mctx->ss.r1 != (unsigned int)mctx->ss.r1)
76 return(0);
77 if (mctx->ss.r2 != (unsigned int)mctx->ss.r2)
78 return(0);
79 if (mctx->ss.r3 != (unsigned int)mctx->ss.r3)
80 return(0);
81 if (mctx->ss.r4 != (unsigned int)mctx->ss.r4)
82 return(0);
83 if (mctx->ss.r5 != (unsigned int)mctx->ss.r5)
84 return(0);
85 if (mctx->ss.r6 != (unsigned int)mctx->ss.r6)
86 return(0);
87 if (mctx->ss.r7 != (unsigned int)mctx->ss.r7)
88 return(0);
89 if (mctx->ss.r8 != (unsigned int)mctx->ss.r8)
90 return(0);
91 if (mctx->ss.r9 != (unsigned int)mctx->ss.r9)
92 return(0);
93 if (mctx->ss.r10 != (unsigned int)mctx->ss.r10)
94 return(0);
95 if (mctx->ss.r11 != (unsigned int)mctx->ss.r11)
96 return(0);
97 if (mctx->ss.r12 != (unsigned int)mctx->ss.r12)
98 return(0);
99 if (mctx->ss.r13 != (unsigned int)mctx->ss.r13)
100 return(0);
101 if (mctx->ss.r14 != (unsigned int)mctx->ss.r14)
102 return(0);
103 if (mctx->ss.r15 != (unsigned int)mctx->ss.r15)
104 return(0);
105 if (mctx->ss.r16 != (unsigned int)mctx->ss.r16)
106 return(0);
107 if (mctx->ss.r17 != (unsigned int)mctx->ss.r17)
108 return(0);
109 if (mctx->ss.r18 != (unsigned int)mctx->ss.r18)
110 return(0);
111 if (mctx->ss.r19 != (unsigned int)mctx->ss.r19)
112 return(0);
113 if (mctx->ss.r20 != (unsigned int)mctx->ss.r20)
114 return(0);
115 if (mctx->ss.r21 != (unsigned int)mctx->ss.r21)
116 return(0);
117 if (mctx->ss.r22 != (unsigned int)mctx64->ss.r22)
118 return(0);
119 if (mctx->ss.r23 != (unsigned int)mctx64->ss.r23)
120 return(0);
121 if (mctx->ss.r24 != (unsigned int)mctx64->ss.r24)
122 return(0);
123 if (mctx->ss.r25 != (unsigned int)mctx64->ss.r25)
124 return(0);
125 if (mctx->ss.r26 != (unsigned int)mctx64->ss.r26)
126 return(0);
127 if (mctx->ss.r27 != (unsigned int)mctx64->ss.r27)
128 return(0);
129 if (mctx->ss.r28 != (unsigned int)mctx64->ss.r28)
130 return(0);
131 if (mctx->ss.r29 != (unsigned int)mctx64->ss.r29)
132 return(0);
133 if (mctx->ss.r30 != (unsigned int)mctx64->ss.r30)
134 return(0);
135 if (mctx->ss.r31 != (unsigned int)mctx64->ss.r31)
136 return(0);
137
138 if (mctx->ss.cr != mctx64->ss.cr)
139 return(0);
140 if (mctx->ss.xer != (unsigned int)mctx64->ss.xer)
141 return(0);
142 if (mctx->ss.lr != (unsigned int)mctx64->ss.lr)
143 return(0);
144 if (mctx->ss.ctr != (unsigned int)mctx64->ss.ctr)
145 return(0);
146
147 if (bcmp(&mctx->fs, &mctx64->ss, (PPC_FLOAT_STATE_COUNT * sizeof(int))))
148 return(0);
149 if ((sigstyle == UC_DUAL_VEC) && bcmp(&mctx->vs, &mctx64->vs, (PPC_VECTOR_STATE_COUNT * sizeof(int))))
150 return(0);
151
152 return(1);
153
154 }
155
156 #endif
157
158 void
159 _sigtramp(
160 union __sigaction_u __sigaction_u,
161 int sigstyle,
162 int sig,
163 siginfo_t *sinfo,
164 struct ucontext *uctx
165 ) {
166 #ifdef __ppc__
167 int ctxstyle = UC_FLAVOR;
168 #endif
169 mcontext_t mctx;
170 mcontext64_t mctx64;
171
172 #if defined(__DYNAMIC__)
173 __in_sigtramp++;
174 #endif
175 #ifndef __ppc__
176 if (sigstyle == UC_TRAD)
177 sa_handler(sig);
178 #else /* __ppc__ */
179 if ((sigstyle == UC_TRAD) || (sigstyle == UC_TRAD64) || (sigstyle == UC_TRAD64_VEC))
180 sa_handler(sig);
181
182 else
183 sa_sigaction(sig, sinfo, uctx);
184
185 if ((sigstyle == UC_DUAL) || (sigstyle == UC_DUAL_VEC)) {
186 mctx = uctx->uc_mcontext;
187 mctx64 = (mcontext64_t)((char *)(uctx->uc_mcontext) + sizeof(struct mcontext));
188 /* restore 64bit state ? */
189 if (restore64_state(mctx, mctx64, sigstyle)) {
190 uctx->uc_mcontext = (void *)mctx64;
191 if (sigstyle == UC_DUAL) {
192 uctx->uc_mcsize = UC_FLAVOR64_SIZE;
193 ctxstyle = UC_FLAVOR64;
194 } else {
195 uctx->uc_mcsize = UC_FLAVOR64_VEC_SIZE;
196 ctxstyle = UC_FLAVOR64_VEC;
197 }
198 } else {
199 if (sigstyle == UC_DUAL)
200 ctxstyle = UC_FLAVOR;
201 else
202 ctxstyle = UC_FLAVOR_VEC;
203 }
204 } else
205 ctxstyle = sigstyle;
206 #endif /* __ppc__ */
207
208 #if defined(__DYNAMIC__)
209 __in_sigtramp--;
210 #endif
211 #ifdef __ppc__
212 {
213 /* sigreturn(uctx, ctxstyle); */
214 /* syscall (SYS_SIGRETURN, uctx, ctxstyle); */
215 syscall (184, uctx, ctxstyle);
216 }
217 #else
218 sigreturn(uctx);
219 #endif /* __ppc__ */
220 }
221