2 * Copyright (c) 2006 Apple Computer, Inc. All Rights Reserved.
4 * @APPLE_LICENSE_OSREFERENCE_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. The rights granted to you under the
10 * License may not be used to create, or enable the creation or
11 * redistribution of, unlawful or unlicensed copies of an Apple operating
12 * system, or to circumvent, violate, or enable the circumvention or
13 * violation of, any terms of an Apple operating system software license
16 * Please obtain a copy of the License at
17 * http://www.opensource.apple.com/apsl/ and read it before using this
20 * The Original Code and all software distributed under the License are
21 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
22 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
23 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
24 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
25 * Please see the License for the specific language governing rights and
26 * limitations under the License.
28 * @APPLE_LICENSE_OSREFERENCE_HEADER_END@
31 * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
34 #include <mach/mach_types.h>
35 #include <mach/exception_types.h>
37 #include <sys/param.h>
38 #include <sys/proc_internal.h>
40 #include <sys/ucontext.h>
41 #include <sys/sysproto.h>
42 #include <sys/systm.h>
43 #include <sys/ux_exception.h>
45 #include <ppc/signal.h>
46 #include <sys/signalvar.h>
47 #include <sys/kdebug.h>
49 #include <kern/thread.h>
50 #include <mach/ppc/thread_status.h>
51 #include <ppc/proc_reg.h>
53 // #include <machine/thread.h> XXX include path messed up for some reason...
55 /* XXX functions not in a Mach headers */
56 extern kern_return_t
thread_getstatus(register thread_t act
, int flavor
,
57 thread_state_t tstate
, mach_msg_type_number_t
*count
);
58 extern int is_64signalregset(void);
59 extern unsigned int get_msr_exportmask(void);
60 extern kern_return_t
thread_setstatus(thread_t thread
, int flavor
,
61 thread_state_t tstate
, mach_msg_type_number_t count
);
62 extern void ppc_checkthreadstate(void *, int);
63 extern struct savearea_vec
*find_user_vec_curr(void);
64 extern int thread_enable_fpe(thread_t act
, int onoff
);
68 #define C_32_REDZONE_LEN 224
69 #define C_32_STK_ALIGN 16
70 #define C_32_PARAMSAVE_LEN 64
71 #define C_32_LINKAGE_LEN 48
73 #define C_64_REDZONE_LEN 320
74 #define C_64_STK_ALIGN 32
75 #define C_64_PARAMSAVE_LEN 64
76 #define C_64_LINKAGE_LEN 48
78 #define TRUNC_DOWN32(a,b,c) ((((uint32_t)a)-(b)) & ((uint32_t)(-(c))))
79 #define TRUNC_DOWN64(a,b,c) ((((uint64_t)a)-(b)) & ((uint64_t)(-(c))))
82 * The stack layout possibilities (info style); This needs to mach with signal trampoline code
86 * Traditional64with vec: 25
88 * 32bit context with vector 35
90 * 64bit context with vector 45
92 * Dual context with vector 55
99 #define UC_TRAD64_VEC 25
101 #define UC_FLAVOR_VEC 35
102 #define UC_FLAVOR64 40
103 #define UC_FLAVOR64_VEC 45
105 #define UC_DUAL_VEC 55
107 /* The following are valid mcontext sizes */
108 #define UC_FLAVOR_SIZE ((PPC_THREAD_STATE_COUNT + PPC_EXCEPTION_STATE_COUNT + PPC_FLOAT_STATE_COUNT) * sizeof(int))
110 #define UC_FLAVOR_VEC_SIZE ((PPC_THREAD_STATE_COUNT + PPC_EXCEPTION_STATE_COUNT + PPC_FLOAT_STATE_COUNT + PPC_VECTOR_STATE_COUNT) * sizeof(int))
112 #define UC_FLAVOR64_SIZE ((PPC_THREAD_STATE64_COUNT + PPC_EXCEPTION_STATE64_COUNT + PPC_FLOAT_STATE_COUNT) * sizeof(int))
114 #define UC_FLAVOR64_VEC_SIZE ((PPC_THREAD_STATE64_COUNT + PPC_EXCEPTION_STATE64_COUNT + PPC_FLOAT_STATE_COUNT + PPC_VECTOR_STATE_COUNT) * sizeof(int))
118 * NOTE: Source and target may *NOT* overlap!
121 ucontext_32to64(struct ucontext64
*in
, struct user_ucontext64
*out
)
123 out
->uc_onstack
= in
->uc_onstack
;
124 out
->uc_sigmask
= in
->uc_sigmask
;
126 /* internal "structure assign" */
127 out
->uc_stack
.ss_sp
= CAST_USER_ADDR_T(in
->uc_stack
.ss_sp
);
128 out
->uc_stack
.ss_size
= in
->uc_stack
.ss_size
;
129 out
->uc_stack
.ss_flags
= in
->uc_stack
.ss_flags
;
131 out
->uc_link
= CAST_USER_ADDR_T(in
->uc_link
);
132 out
->uc_mcsize
= in
->uc_mcsize
;
133 out
->uc_mcontext64
= CAST_USER_ADDR_T(in
->uc_mcontext64
);
137 * This conversion is safe, since if we are converting for a 32 bit process,
138 * then it's values of uc-stack.ss_size and uc_mcsize will never exceed 4G.
140 * NOTE: Source and target may *NOT* overlap!
143 ucontext_64to32(struct user_ucontext64
*in
, struct ucontext64
*out
)
145 out
->uc_onstack
= in
->uc_onstack
;
146 out
->uc_sigmask
= in
->uc_sigmask
;
148 /* internal "structure assign" */
149 out
->uc_stack
.ss_sp
= CAST_DOWN(void *,in
->uc_stack
.ss_sp
);
150 out
->uc_stack
.ss_size
= in
->uc_stack
.ss_size
; /* range reduction */
151 out
->uc_stack
.ss_flags
= in
->uc_stack
.ss_flags
;
153 out
->uc_link
= CAST_DOWN(void *,in
->uc_link
);
154 out
->uc_mcsize
= in
->uc_mcsize
; /* range reduction */
155 out
->uc_mcontext64
= CAST_DOWN(void *,in
->uc_mcontext64
);
159 * NOTE: Source and target may *NOT* overlap!
162 siginfo_64to32(user_siginfo_t
*in
, siginfo_t
*out
)
164 out
->si_signo
= in
->si_signo
;
165 out
->si_errno
= in
->si_errno
;
166 out
->si_code
= in
->si_code
;
167 out
->si_pid
= in
->si_pid
;
168 out
->si_uid
= in
->si_uid
;
169 out
->si_status
= in
->si_status
;
170 out
->si_addr
= CAST_DOWN(void *,in
->si_addr
);
171 /* following cast works for sival_int because of padding */
172 out
->si_value
.sival_ptr
= CAST_DOWN(void *,in
->si_value
.sival_ptr
);
173 out
->si_band
= in
->si_band
; /* range reduction */
174 out
->pad
[0] = in
->pad
[0]; /* mcontext.ss.r1 */
179 * Arrange for this process to run a signal handler
183 sendsig(struct proc
*p
, user_addr_t catcher
, int sig
, int mask
, __unused u_long code
)
186 struct mcontext mctx
;
187 user_addr_t p_mctx
= USER_ADDR_NULL
; /* mcontext dest. */
188 struct mcontext64 mctx64
;
189 user_addr_t p_mctx64
= USER_ADDR_NULL
; /* mcontext dest. */
190 struct user_ucontext64 uctx
;
191 user_addr_t p_uctx
; /* user stack addr top copy ucontext */
192 user_siginfo_t sinfo
;
193 user_addr_t p_sinfo
; /* user stack addr top copy siginfo */
194 struct sigacts
*ps
= p
->p_sigacts
;
197 mach_msg_type_number_t state_count
;
200 int infostyle
= UC_TRAD
;
202 user_addr_t trampact
;
209 th_act
= current_thread();
210 ut
= get_bsdthread_info(th_act
);
213 if (p
->p_sigacts
->ps_siginfo
& sigmask(sig
)) {
214 infostyle
= UC_FLAVOR
;
216 if(is_64signalregset() && (infostyle
== UC_FLAVOR
)) {
220 if (p
->p_sigacts
->ps_64regset
& sigmask(sig
)) {
223 infostyle
= UC_FLAVOR64
;
225 /* treat 64 bit processes as having used 64 bit registers */
226 if ((IS_64BIT_PROCESS(p
) || is_64signalregset()) &&
227 (infostyle
== UC_TRAD
)) {
229 infostyle
= UC_TRAD64
;
231 if (IS_64BIT_PROCESS(p
)) {
236 /* I need this for SIGINFO anyway */
237 flavor
= PPC_THREAD_STATE
;
238 tstate
= (void *)&mctx
.ss
;
239 state_count
= PPC_THREAD_STATE_COUNT
;
240 if (thread_getstatus(th_act
, flavor
, (thread_state_t
)tstate
, &state_count
) != KERN_SUCCESS
)
243 if ((ctx32
== 0) || dualcontext
) {
244 flavor
= PPC_THREAD_STATE64
;
245 tstate
= (void *)&mctx64
.ss
;
246 state_count
= PPC_THREAD_STATE64_COUNT
;
247 if (thread_getstatus(th_act
, flavor
, (thread_state_t
)tstate
, &state_count
) != KERN_SUCCESS
)
251 if ((ctx32
== 1) || dualcontext
) {
252 flavor
= PPC_EXCEPTION_STATE
;
253 tstate
= (void *)&mctx
.es
;
254 state_count
= PPC_EXCEPTION_STATE_COUNT
;
255 if (thread_getstatus(th_act
, flavor
, (thread_state_t
)tstate
, &state_count
) != KERN_SUCCESS
)
259 if ((ctx32
== 0) || dualcontext
) {
260 flavor
= PPC_EXCEPTION_STATE64
;
261 tstate
= (void *)&mctx64
.es
;
262 state_count
= PPC_EXCEPTION_STATE64_COUNT
;
264 if (thread_getstatus(th_act
, flavor
, (thread_state_t
)tstate
, &state_count
) != KERN_SUCCESS
)
270 if ((ctx32
== 1) || dualcontext
) {
271 flavor
= PPC_FLOAT_STATE
;
272 tstate
= (void *)&mctx
.fs
;
273 state_count
= PPC_FLOAT_STATE_COUNT
;
274 if (thread_getstatus(th_act
, flavor
, (thread_state_t
)tstate
, &state_count
) != KERN_SUCCESS
)
278 if ((ctx32
== 0) || dualcontext
) {
279 flavor
= PPC_FLOAT_STATE
;
280 tstate
= (void *)&mctx64
.fs
;
281 state_count
= PPC_FLOAT_STATE_COUNT
;
282 if (thread_getstatus(th_act
, flavor
, (thread_state_t
)tstate
, &state_count
) != KERN_SUCCESS
)
288 if (find_user_vec_curr()) {
291 if ((ctx32
== 1) || dualcontext
) {
292 flavor
= PPC_VECTOR_STATE
;
293 tstate
= (void *)&mctx
.vs
;
294 state_count
= PPC_VECTOR_STATE_COUNT
;
295 if (thread_getstatus(th_act
, flavor
, (thread_state_t
)tstate
, &state_count
) != KERN_SUCCESS
)
300 if ((ctx32
== 0) || dualcontext
) {
301 flavor
= PPC_VECTOR_STATE
;
302 tstate
= (void *)&mctx64
.vs
;
303 state_count
= PPC_VECTOR_STATE_COUNT
;
304 if (thread_getstatus(th_act
, flavor
, (thread_state_t
)tstate
, &state_count
) != KERN_SUCCESS
)
310 trampact
= ps
->ps_trampact
[sig
];
311 oonstack
= ps
->ps_sigstk
.ss_flags
& SA_ONSTACK
;
313 /* figure out where our new stack lives */
314 if ((ps
->ps_flags
& SAS_ALTSTACK
) && !oonstack
&&
315 (ps
->ps_sigonstack
& sigmask(sig
))) {
316 sp
= ps
->ps_sigstk
.ss_sp
;
317 sp
+= ps
->ps_sigstk
.ss_size
;
318 stack_size
= ps
->ps_sigstk
.ss_size
;
319 ps
->ps_sigstk
.ss_flags
|= SA_ONSTACK
;
325 sp
= CAST_USER_ADDR_T(mctx
.ss
.r1
);
329 /* put siginfo on top */
331 /* preserve RED ZONE area */
332 if (IS_64BIT_PROCESS(p
))
333 sp
= TRUNC_DOWN64(sp
, C_64_REDZONE_LEN
, C_64_STK_ALIGN
);
335 sp
= TRUNC_DOWN32(sp
, C_32_REDZONE_LEN
, C_32_STK_ALIGN
);
337 /* next are the saved registers */
338 if ((ctx32
== 0) || dualcontext
) {
339 sp
-= sizeof(struct mcontext64
);
342 if ((ctx32
== 1) || dualcontext
) {
343 sp
-= sizeof(struct mcontext
);
347 if (IS_64BIT_PROCESS(p
)) {
348 /* context goes first on stack */
349 sp
-= sizeof(struct user_ucontext64
);
352 /* this is where siginfo goes on stack */
353 sp
-= sizeof(user_siginfo_t
);
356 sp
= TRUNC_DOWN64(sp
, C_64_PARAMSAVE_LEN
+C_64_LINKAGE_LEN
, C_64_STK_ALIGN
);
359 * struct ucontext and struct ucontext64 are identical in
360 * size and content; the only difference is the internal
361 * pointer type for the last element, which makes no
362 * difference for the copyout().
365 /* context goes first on stack */
366 sp
-= sizeof(struct ucontext64
);
369 /* this is where siginfo goes on stack */
370 sp
-= sizeof(siginfo_t
);
373 sp
= TRUNC_DOWN32(sp
, C_32_PARAMSAVE_LEN
+C_32_LINKAGE_LEN
, C_32_STK_ALIGN
);
376 uctx
.uc_onstack
= oonstack
;
377 uctx
.uc_sigmask
= mask
;
378 uctx
.uc_stack
.ss_sp
= sp
;
379 uctx
.uc_stack
.ss_size
= stack_size
;
381 uctx
.uc_stack
.ss_flags
|= SS_ONSTACK
;
385 uctx
.uc_mcsize
= (size_t)((PPC_EXCEPTION_STATE64_COUNT
+ PPC_THREAD_STATE64_COUNT
+ PPC_FLOAT_STATE_COUNT
) * sizeof(int));
387 uctx
.uc_mcsize
= (size_t)((PPC_EXCEPTION_STATE_COUNT
+ PPC_THREAD_STATE_COUNT
+ PPC_FLOAT_STATE_COUNT
) * sizeof(int));
390 uctx
.uc_mcsize
+= (size_t)(PPC_VECTOR_STATE_COUNT
* sizeof(int));
393 uctx
.uc_mcontext64
= p_mctx64
;
395 uctx
.uc_mcontext64
= p_mctx
;
398 bzero((caddr_t
)&sinfo
, sizeof(user_siginfo_t
));
399 sinfo
.si_signo
= sig
;
401 sinfo
.si_addr
= mctx64
.ss
.srr0
;
402 sinfo
.pad
[0] = mctx64
.ss
.r1
;
404 sinfo
.si_addr
= CAST_USER_ADDR_T(mctx
.ss
.srr0
);
405 sinfo
.pad
[0] = CAST_USER_ADDR_T(mctx
.ss
.r1
);
410 sinfo
.si_pid
= p
->si_pid
;
412 sinfo
.si_status
= p
->si_status
;
414 sinfo
.si_uid
= p
->si_uid
;
416 sinfo
.si_code
= p
->si_code
;
418 if (sinfo
.si_code
== CLD_EXITED
) {
419 if (WIFEXITED(sinfo
.si_status
))
420 sinfo
.si_code
= CLD_EXITED
;
421 else if (WIFSIGNALED(sinfo
.si_status
)) {
422 if (WCOREDUMP(sinfo
.si_status
))
423 sinfo
.si_code
= CLD_DUMPED
;
425 sinfo
.si_code
= CLD_KILLED
;
431 * If it's 64 bit and not a dual context, mctx will
432 * contain uninitialized data, so we have to use
436 if (mctx64
.ss
.srr1
& (1 << (31 - SRR1_PRG_ILL_INS_BIT
)))
437 sinfo
.si_code
= ILL_ILLOPC
;
438 else if (mctx64
.ss
.srr1
& (1 << (31 - SRR1_PRG_PRV_INS_BIT
)))
439 sinfo
.si_code
= ILL_PRVOPC
;
440 else if (mctx64
.ss
.srr1
& (1 << (31 - SRR1_PRG_TRAP_BIT
)))
441 sinfo
.si_code
= ILL_ILLTRP
;
443 sinfo
.si_code
= ILL_NOOP
;
445 if (mctx
.ss
.srr1
& (1 << (31 - SRR1_PRG_ILL_INS_BIT
)))
446 sinfo
.si_code
= ILL_ILLOPC
;
447 else if (mctx
.ss
.srr1
& (1 << (31 - SRR1_PRG_PRV_INS_BIT
)))
448 sinfo
.si_code
= ILL_PRVOPC
;
449 else if (mctx
.ss
.srr1
& (1 << (31 - SRR1_PRG_TRAP_BIT
)))
450 sinfo
.si_code
= ILL_ILLTRP
;
452 sinfo
.si_code
= ILL_NOOP
;
462 * If it's 64 bit and not a dual context, mctx will
463 * contain uninitialized data, so we have to use
467 if (mctx64
.fs
.fpscr
& (1 << (31 - FPSCR_VX
)))
468 sinfo
.si_code
= FPE_FLTINV
;
469 else if (mctx64
.fs
.fpscr
& (1 << (31 - FPSCR_OX
)))
470 sinfo
.si_code
= FPE_FLTOVF
;
471 else if (mctx64
.fs
.fpscr
& (1 << (31 - FPSCR_UX
)))
472 sinfo
.si_code
= FPE_FLTUND
;
473 else if (mctx64
.fs
.fpscr
& (1 << (31 - FPSCR_ZX
)))
474 sinfo
.si_code
= FPE_FLTDIV
;
475 else if (mctx64
.fs
.fpscr
& (1 << (31 - FPSCR_XX
)))
476 sinfo
.si_code
= FPE_FLTRES
;
478 sinfo
.si_code
= FPE_NOOP
;
480 if (mctx
.fs
.fpscr
& (1 << (31 - FPSCR_VX
)))
481 sinfo
.si_code
= FPE_FLTINV
;
482 else if (mctx
.fs
.fpscr
& (1 << (31 - FPSCR_OX
)))
483 sinfo
.si_code
= FPE_FLTOVF
;
484 else if (mctx
.fs
.fpscr
& (1 << (31 - FPSCR_UX
)))
485 sinfo
.si_code
= FPE_FLTUND
;
486 else if (mctx
.fs
.fpscr
& (1 << (31 - FPSCR_ZX
)))
487 sinfo
.si_code
= FPE_FLTDIV
;
488 else if (mctx
.fs
.fpscr
& (1 << (31 - FPSCR_XX
)))
489 sinfo
.si_code
= FPE_FLTRES
;
491 sinfo
.si_code
= FPE_NOOP
;
497 sinfo
.si_addr
= mctx64
.es
.dar
;
499 sinfo
.si_addr
= CAST_USER_ADDR_T(mctx
.es
.dar
);
501 /* on ppc we generate only if EXC_PPC_UNALIGNED */
502 sinfo
.si_code
= BUS_ADRALN
;
507 * If it's 64 bit and not a dual context, mctx will
508 * contain uninitialized data, so we have to use
512 sinfo
.si_addr
= mctx64
.es
.dar
;
513 /* First check in srr1 and then in dsisr */
514 if (mctx64
.ss
.srr1
& (1 << (31 - DSISR_PROT_BIT
)))
515 sinfo
.si_code
= SEGV_ACCERR
;
516 else if (mctx64
.es
.dsisr
& (1 << (31 - DSISR_PROT_BIT
)))
517 sinfo
.si_code
= SEGV_ACCERR
;
519 sinfo
.si_code
= SEGV_MAPERR
;
521 sinfo
.si_addr
= CAST_USER_ADDR_T(mctx
.es
.dar
);
522 /* First check in srr1 and then in dsisr */
523 if (mctx
.ss
.srr1
& (1 << (31 - DSISR_PROT_BIT
)))
524 sinfo
.si_code
= SEGV_ACCERR
;
525 else if (mctx
.es
.dsisr
& (1 << (31 - DSISR_PROT_BIT
)))
526 sinfo
.si_code
= SEGV_ACCERR
;
528 sinfo
.si_code
= SEGV_MAPERR
;
536 /* copy info out to user space */
537 if (IS_64BIT_PROCESS(p
)) {
538 if (copyout(&uctx
, p_uctx
, sizeof(struct user_ucontext64
)))
540 if (copyout(&sinfo
, p_sinfo
, sizeof(user_siginfo_t
)))
543 struct ucontext64 uctx32
;
546 ucontext_64to32(&uctx
, &uctx32
);
547 if (copyout(&uctx32
, p_uctx
, sizeof(struct ucontext64
)))
550 siginfo_64to32(&sinfo
,&sinfo32
);
551 if (copyout(&sinfo32
, p_sinfo
, sizeof(siginfo_t
)))
554 if ((ctx32
== 0) || dualcontext
) {
556 * NOTE: Size of mcontext is not variant between 64bit and
557 * 32bit programs usng 64bit registers.
559 if (copyout(&mctx64
, p_mctx64
, (vec_used
? UC_FLAVOR64_VEC_SIZE
: UC_FLAVOR64_SIZE
)))
562 if ((ctx32
== 1) || dualcontext
) {
563 if (copyout(&mctx
, p_mctx
, uctx
.uc_mcsize
))
568 /* Place our arguments in arg registers: rtm dependent */
569 if(IS_64BIT_PROCESS(p
)) {
570 mctx64
.ss
.r3
= catcher
;
571 mctx64
.ss
.r4
= CAST_USER_ADDR_T(infostyle
);
572 mctx64
.ss
.r5
= CAST_USER_ADDR_T(sig
);
573 mctx64
.ss
.r6
= p_sinfo
;
574 mctx64
.ss
.r7
= p_uctx
;
576 mctx64
.ss
.srr0
= trampact
;
577 /* MSR_EXPORT_MASK_SET */
578 mctx64
.ss
.srr1
= CAST_USER_ADDR_T(get_msr_exportmask());
580 state_count
= PPC_THREAD_STATE64_COUNT
;
581 if ((kretn
= thread_setstatus(th_act
, PPC_THREAD_STATE64
, (void *)&mctx64
.ss
, state_count
)) != KERN_SUCCESS
) {
582 panic("sendsig: thread_setstatus failed, ret = %08X\n", kretn
);
585 mctx
.ss
.r3
= CAST_DOWN(unsigned long,catcher
);
586 mctx
.ss
.r4
= (unsigned long)infostyle
;
587 mctx
.ss
.r5
= (unsigned long)sig
;
588 mctx
.ss
.r6
= CAST_DOWN(unsigned long,p_sinfo
);
589 mctx
.ss
.r7
= CAST_DOWN(unsigned long,p_uctx
);
591 mctx
.ss
.srr0
= CAST_DOWN(unsigned long,trampact
);
592 /* MSR_EXPORT_MASK_SET */
593 mctx
.ss
.srr1
= get_msr_exportmask();
594 mctx
.ss
.r1
= CAST_DOWN(unsigned long,sp
);
595 state_count
= PPC_THREAD_STATE_COUNT
;
596 if ((kretn
= thread_setstatus(th_act
, PPC_THREAD_STATE
, (void *)&mctx
.ss
, state_count
)) != KERN_SUCCESS
) {
597 panic("sendsig: thread_setstatus failed, ret = %08X\n", kretn
);
603 SIGACTION(p
, SIGILL
) = SIG_DFL
;
604 sig
= sigmask(SIGILL
);
605 p
->p_sigignore
&= ~sig
;
606 p
->p_sigcatch
&= ~sig
;
607 ut
->uu_sigmask
&= ~sig
;
608 /* sendsig is called with signal lock held */
609 psignal_lock(p
, SIGILL
, 0);
614 * System call to cleanup state after a signal
615 * has been taken. Reset signal mask and
616 * stack state from context left by sendsig (above).
617 * Return to previous pc and psl as specified by
618 * context left by sendsig. Check carefully to
619 * make sure that the user has not modified the
620 * psl to gain improper priviledges or to cause
626 sigreturn(struct proc
*p
, struct sigreturn_args
*uap
, __unused
int *retval
)
628 struct user_ucontext64 uctx
;
630 char mactx
[sizeof(struct mcontext64
)];
631 struct mcontext
*p_mctx
;
632 struct mcontext64
*p_64mctx
;
635 struct sigacts
*ps
= p
->p_sigacts
;
638 unsigned long state_count
;
639 unsigned int state_flavor
;
642 void *tsptr
, *fptr
, *vptr
;
643 int infostyle
= uap
->infostyle
;
645 th_act
= current_thread();
647 ut
= (struct uthread
*)get_bsdthread_info(th_act
);
648 if (IS_64BIT_PROCESS(p
)) {
649 error
= copyin(uap
->uctx
, &uctx
, sizeof(struct user_ucontext64
));
653 struct ucontext64 uctx32
;
656 * struct ucontext and struct ucontext64 are identical in
657 * size and content; the only difference is the internal
658 * pointer type for the last element, which makes no
659 * difference for the copyin().
661 error
= copyin(uap
->uctx
, &uctx32
, sizeof(struct ucontext
));
664 ucontext_32to64(&uctx32
, &uctx
);
668 /* validate the machine context size */
669 switch (uctx
.uc_mcsize
) {
670 case UC_FLAVOR64_VEC_SIZE
:
671 case UC_FLAVOR64_SIZE
:
672 case UC_FLAVOR_VEC_SIZE
:
680 * The 64 bit process mcontext is identical to the mcontext64, so
681 * there is no conversion necessary.
683 error
= copyin(uctx
.uc_mcontext64
, mactx
, uctx
.uc_mcsize
);
687 if ((uctx
.uc_onstack
& 01))
688 p
->p_sigacts
->ps_sigstk
.ss_flags
|= SA_ONSTACK
;
690 p
->p_sigacts
->ps_sigstk
.ss_flags
&= ~SA_ONSTACK
;
692 ut
->uu_sigmask
= uctx
.uc_sigmask
& ~sigcantmask
;
693 if (ut
->uu_siglist
& ~ut
->uu_sigmask
)
694 signal_setast(current_thread());
698 case UC_FLAVOR64_VEC
:
703 p_64mctx
= (struct mcontext64
*)mactx
;
704 tsptr
= (void *)&p_64mctx
->ss
;
705 fptr
= (void *)&p_64mctx
->fs
;
706 vptr
= (void *)&p_64mctx
->vs
;
707 state_flavor
= PPC_THREAD_STATE64
;
708 state_count
= PPC_THREAD_STATE64_COUNT
;
717 p_mctx
= (struct mcontext
*)mactx
;
718 tsptr
= (void *)&p_mctx
->ss
;
719 fptr
= (void *)&p_mctx
->fs
;
720 vptr
= (void *)&p_mctx
->vs
;
721 state_flavor
= PPC_THREAD_STATE
;
722 state_count
= PPC_THREAD_STATE_COUNT
;
727 /* validate the thread state, set/reset appropriate mode bits in srr1 */
728 (void)ppc_checkthreadstate(tsptr
, state_flavor
);
730 if (thread_setstatus(th_act
, state_flavor
, tsptr
, state_count
) != KERN_SUCCESS
) {
734 state_count
= PPC_FLOAT_STATE_COUNT
;
735 if (thread_setstatus(th_act
, PPC_FLOAT_STATE
, fptr
, state_count
) != KERN_SUCCESS
) {
739 mask
= sigmask(SIGFPE
);
740 if (((ut
->uu_sigmask
& mask
) == 0) && (p
->p_sigcatch
& mask
) && ((p
->p_sigignore
& mask
) == 0)) {
741 action
= ps
->ps_sigact
[SIGFPE
];
742 if((action
!= SIG_DFL
) && (action
!= SIG_IGN
)) {
743 thread_enable_fpe(th_act
, 1);
748 state_count
= PPC_VECTOR_STATE_COUNT
;
749 if (thread_setstatus(th_act
, PPC_VECTOR_STATE
, vptr
, state_count
) != KERN_SUCCESS
) {
753 return (EJUSTRETURN
);
757 * machine_exception() performs MD translation
758 * of a mach exception to a unix signal and code.
765 __unused
int subcode
,
772 case EXC_BAD_INSTRUCTION
:
773 *unix_signal
= SIGILL
;
778 *unix_signal
= SIGFPE
;
783 if (code
== EXC_PPC_TRAP
) {
784 *unix_signal
= SIGTRAP
;