]>
git.saurik.com Git - apple/xnu.git/blob - bsd/dev/i386/unix_signal.c
0c06ff2fd865a706566de961e1abc504f38c56a9
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
20 * @APPLE_LICENSE_HEADER_END@
23 * Copyright (c) 1992 NeXT, Inc.
26 * 13 May 1992 ? at NeXT
30 #include <mach/mach_types.h>
31 #include <mach/exception.h>
33 #include <kern/thread.h>
34 #include <kern/thread_act.h>
36 #include <sys/param.h>
42 #include <mach/i386/thread_status.h>
43 #include <dev/i386/sel_inline.h>
47 * FIXME.. should be included from mach_kernel/i386/seg.h
53 #define UDATA_SEL USER_DS
54 #define UCODE_SEL USER_CS
56 #define valid_user_code_selector(x) (TRUE)
57 #define valid_user_data_selector(x) (TRUE)
58 #define valid_user_stack_selector(x) (TRUE)
64 * Send an interrupt to process.
66 * Stack is set up to allow sigcode stored
67 * in u. to call routine, followed by chmk
68 * to sigreturn routine below. After sigreturn
69 * resets the signal mask, the stack, the frame
70 * pointer, and the argument pointer, it returns
71 * to the user specified pc, psl.
75 sendsig(p
, catcher
, sig
, mask
, code
)
87 struct sigcontext
* scp
;
89 struct sigcontext context
, *scp
;
90 struct sigacts
*ps
= p
->p_sigacts
;
92 thread_t thread
= current_thread();
93 thread_act_t th_act
= current_act();
95 struct i386_saved_state
* saved_state
= get_user_regs(th_act
);
98 ut
= get_bsdthread_info(th_act
);
99 oonstack
= ps
->ps_sigstk
.ss_flags
& SA_ONSTACK
;
100 if ((ps
->ps_flags
& SAS_ALTSTACK
) && !oonstack
&&
101 (ps
->ps_sigonstack
& sigmask(sig
))) {
102 scp
= ((struct sigcontext
*)ps
->ps_sigstk
.ss_sp
) - 1;
103 ps
->ps_sigstk
.ss_flags
|= SA_ONSTACK
;
105 scp
= ((struct sigcontext
*)saved_state
->uesp
) - 1;
106 fp
= ((struct sigframe
*)scp
) - 1;
109 * Build the argument list for the signal handler.
112 trampact
= ps
->ps_trampact
[sig
];
113 /* Handler should call sigreturn to get out of it */
114 frame
.retaddr
= 0xffffffff;
115 frame
.catcher
= catcher
;
119 if (sig
== SIGILL
|| sig
== SIGFPE
) {
124 if (copyout((caddr_t
)&frame
, (caddr_t
)fp
, sizeof (frame
)))
129 PCcontext_t context
= threadPCContext(thread
);
131 if (context
&& context
->running
) {
133 context
->running
= FALSE
;
138 * Build the signal context to be used by sigreturn.
140 context
.sc_onstack
= oonstack
;
141 context
.sc_mask
= mask
;
142 context
.sc_eax
= saved_state
->eax
;
143 context
.sc_ebx
= saved_state
->ebx
;
144 context
.sc_ecx
= saved_state
->ecx
;
145 context
.sc_edx
= saved_state
->edx
;
146 context
.sc_edi
= saved_state
->edi
;
147 context
.sc_esi
= saved_state
->esi
;
148 context
.sc_ebp
= saved_state
->ebp
;
149 context
.sc_esp
= saved_state
->uesp
;
150 context
.sc_ss
= saved_state
->ss
;
151 context
.sc_eflags
= saved_state
->efl
;
152 context
.sc_eip
= saved_state
->eip
;
153 context
.sc_cs
= saved_state
->cs
;
154 if (saved_state
->efl
& EFL_VM
) {
155 context
.sc_ds
= saved_state
->v86_segs
.v86_ds
;
156 context
.sc_es
= saved_state
->v86_segs
.v86_es
;
157 context
.sc_fs
= saved_state
->v86_segs
.v86_fs
;
158 context
.sc_gs
= saved_state
->v86_segs
.v86_gs
;
160 saved_state
->efl
&= ~EFL_VM
;
162 context
.sc_ds
= saved_state
->ds
;
163 context
.sc_es
= saved_state
->es
;
164 context
.sc_fs
= saved_state
->fs
;
165 context
.sc_gs
= saved_state
->gs
;
167 if (copyout((caddr_t
)&context
, (caddr_t
)scp
, sizeof (context
)))
170 saved_state
->eip
= (unsigned int)trampact
;
171 saved_state
->cs
= UCODE_SEL
;
173 saved_state
->uesp
= (unsigned int)fp
;
174 saved_state
->ss
= UDATA_SEL
;
176 saved_state
->ds
= UDATA_SEL
;
177 saved_state
->es
= UDATA_SEL
;
178 saved_state
->fs
= NULL_SEG
;
179 saved_state
->gs
= NULL_SEG
;
183 SIGACTION(p
, SIGILL
) = SIG_DFL
;
184 sig
= sigmask(SIGILL
);
185 p
->p_sigignore
&= ~sig
;
186 p
->p_sigcatch
&= ~sig
;
187 ut
->uu_sigmask
&= ~sig
;
188 /* sendsig is called with signal lock held */
189 psignal_lock(p
, SIGILL
, 0);
194 * System call to cleanup state after a signal
195 * has been taken. Reset signal mask and
196 * stack state from context left by sendsig (above).
197 * Return to previous pc and psl as specified by
198 * context left by sendsig. Check carefully to
199 * make sure that the user has not modified the
200 * psl to gain improper priviledges or to cause
203 struct sigreturn_args
{
204 struct sigcontext
*sigcntxp
;
208 sigreturn(p
, uap
, retval
)
210 struct sigreturn_args
*uap
;
213 struct sigcontext context
;
214 thread_t thread
= current_thread();
215 thread_act_t th_act
= current_act();
217 struct i386_saved_state
* saved_state
= get_user_regs(th_act
);
222 if (saved_state
== NULL
)
225 if (error
= copyin((caddr_t
)uap
->sigcntxp
, (caddr_t
)&context
,
228 ut
= (struct uthread
*)get_bsdthread_info(th_act
);
230 if (context
.sc_onstack
& 01)
231 p
->p_sigacts
->ps_sigstk
.ss_flags
|= SA_ONSTACK
;
233 p
->p_sigacts
->ps_sigstk
.ss_flags
&= ~SA_ONSTACK
;
234 ut
->uu_sigmask
= context
.sc_mask
&~ sigcantmask
;
235 if(ut
->uu_siglist
& ~ut
->uu_sigmask
)
236 signal_setast(current_act());
237 saved_state
->eax
= context
.sc_eax
;
238 saved_state
->ebx
= context
.sc_ebx
;
239 saved_state
->ecx
= context
.sc_ecx
;
240 saved_state
->edx
= context
.sc_edx
;
241 saved_state
->edi
= context
.sc_edi
;
242 saved_state
->esi
= context
.sc_esi
;
243 saved_state
->ebp
= context
.sc_ebp
;
244 saved_state
->uesp
= context
.sc_esp
;
245 saved_state
->ss
= context
.sc_ss
;
246 saved_state
->efl
= context
.sc_eflags
;
247 saved_state
->efl
&= ~EFL_USERCLR
;
248 saved_state
->efl
|= EFL_USERSET
;
249 saved_state
->eip
= context
.sc_eip
;
250 saved_state
->cs
= context
.sc_cs
;
252 if (context
.sc_eflags
& EFL_VM
) {
253 saved_state
->ds
= NULL_SEG
;
254 saved_state
->es
= NULL_SEG
;
255 saved_state
->fs
= NULL_SEG
;
256 saved_state
->gs
= NULL_SEG
;
257 saved_state
->v86_segs
.v86_ds
= context
.sc_ds
;
258 saved_state
->v86_segs
.v86_es
= context
.sc_es
;
259 saved_state
->v86_segs
.v86_fs
= context
.sc_fs
;
260 saved_state
->v86_segs
.v86_gs
= context
.sc_gs
;
262 saved_state
->efl
|= EFL_VM
;
265 saved_state
->ds
= context
.sc_ds
;
266 saved_state
->es
= context
.sc_es
;
267 saved_state
->fs
= context
.sc_fs
;
268 saved_state
->gs
= context
.sc_gs
;
272 if (context
.sc_onstack
& 02) {
273 PCcontext_t context
= threadPCContext(thread
);
276 context
->running
= TRUE
;
280 return (EJUSTRETURN
);
284 * machine_exception() performs MD translation
285 * of a mach exception to a unix signal and code.
300 case EXC_BAD_INSTRUCTION
:
301 *unix_signal
= SIGILL
;
306 *unix_signal
= SIGFPE
;