Annotation of src/sys/arch/powerpc/powerpc/compat_16_machdep.c, Revision 1.11.4.3
1.11.4.3! wrstuden 1: /* $NetBSD: compat_16_machdep.c,v 1.11.4.2 2008/05/14 01:35:00 wrstuden Exp $ */
1.1 matt 2:
3: /*
4: * Copyright (C) 1995, 1996 Wolfgang Solfrank.
5: * Copyright (C) 1995, 1996 TooLs GmbH.
6: * All rights reserved.
7: *
8: * Redistribution and use in source and binary forms, with or without
9: * modification, are permitted provided that the following conditions
10: * are met:
11: * 1. Redistributions of source code must retain the above copyright
12: * notice, this list of conditions and the following disclaimer.
13: * 2. Redistributions in binary form must reproduce the above copyright
14: * notice, this list of conditions and the following disclaimer in the
15: * documentation and/or other materials provided with the distribution.
16: * 3. All advertising materials mentioning features or use of this software
17: * must display the following acknowledgement:
18: * This product includes software developed by TooLs GmbH.
19: * 4. The name of TooLs GmbH may not be used to endorse or promote products
20: * derived from this software without specific prior written permission.
21: *
22: * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``AS IS'' AND ANY EXPRESS OR
23: * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
24: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
25: * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26: * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
27: * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
28: * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
29: * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
30: * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
31: * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32: */
33:
34: #include <sys/cdefs.h>
1.11.4.3! wrstuden 35: __KERNEL_RCSID(0, "$NetBSD: compat_16_machdep.c,v 1.11.4.2 2008/05/14 01:35:00 wrstuden Exp $");
1.1 matt 36:
37: #include "opt_compat_netbsd.h"
1.4 matt 38: #include "opt_altivec.h"
1.1 matt 39: #include "opt_ppcarch.h"
40:
41: #include <sys/param.h>
42: #include <sys/mount.h>
43: #include <sys/proc.h>
44: #include <sys/syscallargs.h>
45: #include <sys/systm.h>
46: #include <sys/ucontext.h>
47: #include <sys/user.h>
48:
1.5 he 49: #include <compat/sys/signal.h>
50: #include <compat/sys/signalvar.h>
51:
1.1 matt 52: #include <machine/fpu.h>
53:
54: /*
55: * Send a signal to process.
56: */
57: void
1.2 matt 58: sendsig_sigcontext(int sig, const sigset_t *mask, u_long code)
1.1 matt 59: {
60: struct lwp *l = curlwp;
61: struct proc *p = l->l_proc;
62: struct sigacts *ps = p->p_sigacts;
63: struct sigcontext *fp, frame;
64: struct trapframe *tf;
65: struct utrapframe *utf = &frame.sc_frame;
1.7 ad 66: int onstack, error;
1.1 matt 67: sig_t catcher = SIGACTION(p, sig).sa_handler;
68:
69: tf = trapframe(l);
70:
71: /* Do we need to jump onto the signal stack? */
72: onstack =
1.11.4.3! wrstuden 73: (l->l_sigstk.ss_flags & (SS_DISABLE | SS_ONSTACK)) == 0 &&
1.1 matt 74: (SIGACTION(p, sig).sa_flags & SA_ONSTACK) != 0;
75:
76: /* Allocate space for the signal handler context. */
77: if (onstack)
1.11.4.3! wrstuden 78: fp = (struct sigcontext *)((char *)l->l_sigstk.ss_sp +
! 79: l->l_sigstk.ss_size);
1.1 matt 80: else
81: fp = (struct sigcontext *)tf->fixreg[1];
82: fp = (struct sigcontext *)((uintptr_t)(fp - 1) & ~0xf);
83:
84: /* Save register context. */
85: memcpy(utf->fixreg, tf->fixreg, sizeof(utf->fixreg));
86: utf->lr = tf->lr;
87: utf->cr = tf->cr;
88: utf->xer = tf->xer;
89: utf->ctr = tf->ctr;
90: utf->srr0 = tf->srr0;
1.4 matt 91: utf->srr1 = tf->srr1 & PSL_USERSRR1;
1.3 matt 92: #ifdef PPC_HAVE_FPU
93: utf->srr1 |= l->l_addr->u_pcb.pcb_flags & (PCB_FE0|PCB_FE1);
94: #endif
1.4 matt 95: #ifdef ALTIVEC
96: utf->srr1 |= l->l_addr->u_pcb.pcb_flags & PCB_ALTIVEC ? PSL_VEC : 0;
97: #endif
1.1 matt 98: #ifdef PPC_OEA
99: utf->vrsave = tf->tf_xtra[TF_VRSAVE];
100: utf->mq = tf->tf_xtra[TF_MQ];
101: #endif
102:
103: /* Save signal stack. */
1.11.4.3! wrstuden 104: frame.sc_onstack = l->l_sigstk.ss_flags & SS_ONSTACK;
1.1 matt 105:
106: /* Save signal mask. */
107: frame.sc_mask = *mask;
108:
109: #ifdef COMPAT_13
110: /*
111: * XXX We always have to save an old style signal mask because
112: * XXX we might be delivering a signal to a process which will
113: * XXX escape from the signal in a non-standard way and invoke
114: * XXX sigreturn() directly.
115: */
116: native_sigset_to_sigset13(mask, &frame.__sc_mask13);
117: #endif
1.7 ad 118: sendsig_reset(l, sig);
1.11 ad 119: mutex_exit(p->p_lock);
1.7 ad 120: error = copyout(&frame, fp, sizeof frame);
1.11 ad 121: mutex_enter(p->p_lock);
1.1 matt 122:
1.7 ad 123: if (error != 0) {
1.1 matt 124: /*
125: * Process has trashed its stack; give it an illegal
126: * instructoin to halt it in its tracks.
127: */
128: sigexit(l, SIGILL);
129: /* NOTREACHED */
130: }
131:
132: /*
133: * Build context to run handler in. Note the trampoline version
134: * numbers are coordinated with machine-dependent code in libc.
135: */
136: switch (ps->sa_sigdesc[sig].sd_vers) {
137: #if 1 /* COMPAT_16 */
138: case 0: /* legacy on-stack sigtramp */
139: tf->fixreg[1] = (register_t)fp;
140: tf->lr = (register_t)catcher;
141: tf->fixreg[3] = (register_t)sig;
142: tf->fixreg[4] = (register_t)code;
143: tf->fixreg[5] = (register_t)fp;
144: tf->srr0 = (register_t)p->p_sigctx.ps_sigcode;
145: break;
146: #endif /* COMPAT_16 */
147:
148: case 1:
149: tf->fixreg[1] = (register_t)fp;
150: tf->lr = (register_t)catcher;
151: tf->fixreg[3] = (register_t)sig;
152: tf->fixreg[4] = (register_t)code;
153: tf->fixreg[5] = (register_t)fp;
154: tf->srr0 = (register_t)ps->sa_sigdesc[sig].sd_tramp;
155: break;
156:
157: default:
158: /* Don't know what trampoline version; kill it. */
159: sigexit(l, SIGILL);
160: }
161:
162: /* Remember that we're now on the signal stack. */
163: if (onstack)
1.11.4.3! wrstuden 164: l->l_sigstk.ss_flags |= SS_ONSTACK;
1.1 matt 165: }
166:
167: /*
168: * System call to cleanup state after a signal handler returns.
169: */
170: int
1.10 dsl 171: compat_16_sys___sigreturn14(struct lwp *l, const struct compat_16_sys___sigreturn14_args *uap, register_t *retval)
1.1 matt 172: {
1.10 dsl 173: /* {
1.1 matt 174: syscallarg(struct sigcontext *) sigcntxp;
1.10 dsl 175: } */
1.1 matt 176: struct proc *p = l->l_proc;
177: struct sigcontext sc;
178: struct trapframe *tf;
179: struct utrapframe * const utf = &sc.sc_frame;
180: int error;
181:
182: /*
183: * The trampoline hands us the context.
184: * It is unsafe to keep track of it ourselves, in the event that a
185: * program jumps out of a signal hander.
186: */
187: if ((error = copyin(SCARG(uap, sigcntxp), &sc, sizeof sc)) != 0)
188: return (error);
189:
190: /* Restore the register context. */
191: tf = trapframe(l);
1.4 matt 192:
193: /*
194: * Make sure SRR1 hasn't been maliciously tampered with.
195: */
196: if (!PSL_USEROK_P(sc.sc_frame.srr1))
1.1 matt 197: return (EINVAL);
198:
199: /* Restore register context. */
200: memcpy(tf->fixreg, utf->fixreg, sizeof(tf->fixreg));
201: tf->lr = utf->lr;
202: tf->cr = utf->cr;
203: tf->xer = utf->xer;
204: tf->ctr = utf->ctr;
205: tf->srr0 = utf->srr0;
206: tf->srr1 = utf->srr1;
1.3 matt 207: #ifdef PPC_HAVE_FPU
208: l->l_addr->u_pcb.pcb_flags &= ~(PCB_FE0|PCB_FE1);
209: l->l_addr->u_pcb.pcb_flags |= utf->srr1 & (PCB_FE0|PCB_FE1);
210: #endif
1.1 matt 211: #ifdef PPC_OEA
212: tf->tf_xtra[TF_VRSAVE] = utf->vrsave;
213: tf->tf_xtra[TF_MQ] = utf->mq;
214: #endif
215:
1.11 ad 216: mutex_enter(p->p_lock);
1.1 matt 217: /* Restore signal stack. */
218: if (sc.sc_onstack & SS_ONSTACK)
1.11.4.3! wrstuden 219: l->l_sigstk.ss_flags |= SS_ONSTACK;
1.1 matt 220: else
1.11.4.3! wrstuden 221: l->l_sigstk.ss_flags &= ~SS_ONSTACK;
1.1 matt 222: /* Restore signal mask. */
1.7 ad 223: (void) sigprocmask1(l, SIG_SETMASK, &sc.sc_mask, 0);
1.11 ad 224: mutex_exit(p->p_lock);
1.1 matt 225:
226: return (EJUSTRETURN);
227: }
CVSweb <webmaster@jp.NetBSD.org>