[BACK]Return to compat_16_machdep.c CVS log [TXT][DIR] Up to [cvs.NetBSD.org] / src / sys / arch / powerpc / powerpc

Annotation of src/sys/arch/powerpc/powerpc/compat_16_machdep.c, Revision 1.11.10.1

1.11.10.1! skrll       1: /*     $NetBSD: compat_16_machdep.c,v 1.12 2008/11/21 20:21:12 he 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.10.1! skrll      35: __KERNEL_RCSID(0, "$NetBSD: compat_16_machdep.c,v 1.12 2008/11/21 20:21:12 he Exp $");
1.1       matt       36:
1.11.10.1! skrll      37: #ifdef _KERNEL_OPT
1.1       matt       38: #include "opt_compat_netbsd.h"
1.4       matt       39: #include "opt_altivec.h"
1.1       matt       40: #include "opt_ppcarch.h"
1.11.10.1! skrll      41: #endif
1.1       matt       42:
                     43: #include <sys/param.h>
                     44: #include <sys/mount.h>
                     45: #include <sys/proc.h>
                     46: #include <sys/syscallargs.h>
                     47: #include <sys/systm.h>
                     48: #include <sys/ucontext.h>
                     49: #include <sys/user.h>
                     50:
1.5       he         51: #include <compat/sys/signal.h>
                     52: #include <compat/sys/signalvar.h>
                     53:
1.1       matt       54: #include <machine/fpu.h>
                     55:
                     56: /*
                     57:  * Send a signal to process.
                     58:  */
                     59: void
1.11.10.1! skrll      60: sendsig_sigcontext(const ksiginfo_t *ksi, const sigset_t *mask)
1.1       matt       61: {
                     62:        struct lwp *l = curlwp;
                     63:        struct proc *p = l->l_proc;
                     64:        struct sigacts *ps = p->p_sigacts;
                     65:        struct sigcontext *fp, frame;
                     66:        struct trapframe *tf;
                     67:        struct utrapframe *utf = &frame.sc_frame;
1.7       ad         68:        int onstack, error;
1.11.10.1! skrll      69:        int sig = ksi->ksi_signo;
        !            70:        u_long code = KSI_TRAPCODE(ksi);
1.1       matt       71:        sig_t catcher = SIGACTION(p, sig).sa_handler;
                     72:
                     73:        tf = trapframe(l);
                     74:
                     75:        /* Do we need to jump onto the signal stack? */
                     76:        onstack =
1.7       ad         77:            (l->l_sigstk.ss_flags & (SS_DISABLE | SS_ONSTACK)) == 0 &&
1.1       matt       78:            (SIGACTION(p, sig).sa_flags & SA_ONSTACK) != 0;
                     79:
                     80:        /* Allocate space for the signal handler context. */
                     81:        if (onstack)
1.9       tsutsui    82:                fp = (struct sigcontext *)((char *)l->l_sigstk.ss_sp +
1.7       ad         83:                                                l->l_sigstk.ss_size);
1.1       matt       84:        else
                     85:                fp = (struct sigcontext *)tf->fixreg[1];
                     86:        fp = (struct sigcontext *)((uintptr_t)(fp - 1) & ~0xf);
                     87:
                     88:        /* Save register context. */
                     89:        memcpy(utf->fixreg, tf->fixreg, sizeof(utf->fixreg));
                     90:        utf->lr   = tf->lr;
                     91:        utf->cr   = tf->cr;
                     92:        utf->xer  = tf->xer;
                     93:        utf->ctr  = tf->ctr;
                     94:        utf->srr0 = tf->srr0;
1.4       matt       95:        utf->srr1 = tf->srr1 & PSL_USERSRR1;
1.3       matt       96: #ifdef PPC_HAVE_FPU
                     97:        utf->srr1 |= l->l_addr->u_pcb.pcb_flags & (PCB_FE0|PCB_FE1);
                     98: #endif
1.4       matt       99: #ifdef ALTIVEC
                    100:        utf->srr1 |= l->l_addr->u_pcb.pcb_flags & PCB_ALTIVEC ? PSL_VEC : 0;
                    101: #endif
1.1       matt      102: #ifdef PPC_OEA
                    103:        utf->vrsave = tf->tf_xtra[TF_VRSAVE];
                    104:        utf->mq = tf->tf_xtra[TF_MQ];
                    105: #endif
                    106:
                    107:        /* Save signal stack. */
1.7       ad        108:        frame.sc_onstack = l->l_sigstk.ss_flags & SS_ONSTACK;
1.1       matt      109:
                    110:        /* Save signal mask. */
                    111:        frame.sc_mask = *mask;
                    112:
                    113: #ifdef COMPAT_13
                    114:        /*
                    115:         * XXX We always have to save an old style signal mask because
                    116:         * XXX we might be delivering a signal to a process which will
                    117:         * XXX escape from the signal in a non-standard way and invoke
                    118:         * XXX sigreturn() directly.
                    119:         */
                    120:        native_sigset_to_sigset13(mask, &frame.__sc_mask13);
                    121: #endif
1.7       ad        122:        sendsig_reset(l, sig);
1.11      ad        123:        mutex_exit(p->p_lock);
1.7       ad        124:        error = copyout(&frame, fp, sizeof frame);
1.11      ad        125:        mutex_enter(p->p_lock);
1.1       matt      126:
1.7       ad        127:        if (error != 0) {
1.1       matt      128:                /*
                    129:                 * Process has trashed its stack; give it an illegal
                    130:                 * instructoin to halt it in its tracks.
                    131:                 */
                    132:                sigexit(l, SIGILL);
                    133:                /* NOTREACHED */
                    134:        }
                    135:
                    136:        /*
                    137:         * Build context to run handler in.  Note the trampoline version
                    138:         * numbers are coordinated with machine-dependent code in libc.
                    139:         */
                    140:        switch (ps->sa_sigdesc[sig].sd_vers) {
                    141: #if 1 /* COMPAT_16 */
                    142:        case 0:         /* legacy on-stack sigtramp */
                    143:                tf->fixreg[1] = (register_t)fp;
                    144:                tf->lr = (register_t)catcher;
                    145:                tf->fixreg[3] = (register_t)sig;
                    146:                tf->fixreg[4] = (register_t)code;
                    147:                tf->fixreg[5] = (register_t)fp;
                    148:                tf->srr0 = (register_t)p->p_sigctx.ps_sigcode;
                    149:                break;
                    150: #endif /* COMPAT_16 */
                    151:
                    152:        case 1:
                    153:                tf->fixreg[1] = (register_t)fp;
                    154:                tf->lr = (register_t)catcher;
                    155:                tf->fixreg[3] = (register_t)sig;
                    156:                tf->fixreg[4] = (register_t)code;
                    157:                tf->fixreg[5] = (register_t)fp;
                    158:                tf->srr0 = (register_t)ps->sa_sigdesc[sig].sd_tramp;
                    159:                break;
                    160:
                    161:        default:
                    162:                /* Don't know what trampoline version; kill it. */
                    163:                sigexit(l, SIGILL);
                    164:        }
                    165:
                    166:        /* Remember that we're now on the signal stack. */
                    167:        if (onstack)
1.7       ad        168:                l->l_sigstk.ss_flags |= SS_ONSTACK;
1.1       matt      169: }
                    170:
                    171: /*
                    172:  * System call to cleanup state after a signal handler returns.
                    173:  */
                    174: int
1.10      dsl       175: compat_16_sys___sigreturn14(struct lwp *l, const struct compat_16_sys___sigreturn14_args *uap, register_t *retval)
1.1       matt      176: {
1.10      dsl       177:        /* {
1.1       matt      178:                syscallarg(struct sigcontext *) sigcntxp;
1.10      dsl       179:        } */
1.1       matt      180:        struct proc *p = l->l_proc;
                    181:        struct sigcontext sc;
                    182:        struct trapframe *tf;
                    183:        struct utrapframe * const utf = &sc.sc_frame;
                    184:        int error;
                    185:
                    186:        /*
                    187:         * The trampoline hands us the context.
                    188:         * It is unsafe to keep track of it ourselves, in the event that a
                    189:         * program jumps out of a signal hander.
                    190:         */
                    191:        if ((error = copyin(SCARG(uap, sigcntxp), &sc, sizeof sc)) != 0)
                    192:                return (error);
                    193:
                    194:        /* Restore the register context. */
                    195:        tf = trapframe(l);
1.4       matt      196:
                    197:        /*
                    198:         * Make sure SRR1 hasn't been maliciously tampered with.
                    199:         */
                    200:        if (!PSL_USEROK_P(sc.sc_frame.srr1))
1.1       matt      201:                return (EINVAL);
                    202:
                    203:        /* Restore register context. */
                    204:        memcpy(tf->fixreg, utf->fixreg, sizeof(tf->fixreg));
                    205:        tf->lr   = utf->lr;
                    206:        tf->cr   = utf->cr;
                    207:        tf->xer  = utf->xer;
                    208:        tf->ctr  = utf->ctr;
                    209:        tf->srr0 = utf->srr0;
                    210:        tf->srr1 = utf->srr1;
1.3       matt      211: #ifdef PPC_HAVE_FPU
                    212:        l->l_addr->u_pcb.pcb_flags &= ~(PCB_FE0|PCB_FE1);
                    213:        l->l_addr->u_pcb.pcb_flags |= utf->srr1 & (PCB_FE0|PCB_FE1);
                    214: #endif
1.1       matt      215: #ifdef PPC_OEA
                    216:        tf->tf_xtra[TF_VRSAVE] = utf->vrsave;
                    217:        tf->tf_xtra[TF_MQ] = utf->mq;
                    218: #endif
                    219:
1.11      ad        220:        mutex_enter(p->p_lock);
1.1       matt      221:        /* Restore signal stack. */
                    222:        if (sc.sc_onstack & SS_ONSTACK)
1.7       ad        223:                l->l_sigstk.ss_flags |= SS_ONSTACK;
1.1       matt      224:        else
1.7       ad        225:                l->l_sigstk.ss_flags &= ~SS_ONSTACK;
1.1       matt      226:        /* Restore signal mask. */
1.7       ad        227:        (void) sigprocmask1(l, SIG_SETMASK, &sc.sc_mask, 0);
1.11      ad        228:        mutex_exit(p->p_lock);
1.1       matt      229:
                    230:        return (EJUSTRETURN);
                    231: }

CVSweb <webmaster@jp.NetBSD.org>