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