[BACK]Return to sig_machdep.c CVS log [TXT][DIR] Up to [local] / sys / arch / m88k / m88k

Annotation of sys/arch/m88k/m88k/sig_machdep.c, Revision 1.1.1.1

1.1       nbrk        1: /*     $OpenBSD: sig_machdep.c,v 1.4 2006/01/02 19:46:12 miod Exp $    */
                      2: /*
                      3:  * Copyright (c) 1998, 1999, 2000, 2001 Steve Murphree, Jr.
                      4:  * Copyright (c) 1996 Nivas Madhur
                      5:  * All rights reserved.
                      6:  *
                      7:  * Redistribution and use in source and binary forms, with or without
                      8:  * modification, are permitted provided that the following conditions
                      9:  * are met:
                     10:  * 1. Redistributions of source code must retain the above copyright
                     11:  *    notice, this list of conditions and the following disclaimer.
                     12:  * 2. Redistributions in binary form must reproduce the above copyright
                     13:  *    notice, this list of conditions and the following disclaimer in the
                     14:  *    documentation and/or other materials provided with the distribution.
                     15:  * 3. All advertising materials mentioning features or use of this software
                     16:  *    must display the following acknowledgement:
                     17:  *      This product includes software developed by Nivas Madhur.
                     18:  * 4. The name of the author may not be used to endorse or promote products
                     19:  *    derived from this software without specific prior written permission
                     20:  *
                     21:  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
                     22:  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
                     23:  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
                     24:  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
                     25:  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
                     26:  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
                     27:  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
                     28:  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
                     29:  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
                     30:  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
                     31:  *
                     32:  */
                     33: /*
                     34:  * Mach Operating System
                     35:  * Copyright (c) 1993-1991 Carnegie Mellon University
                     36:  * Copyright (c) 1991 OMRON Corporation
                     37:  * All Rights Reserved.
                     38:  *
                     39:  * Permission to use, copy, modify and distribute this software and its
                     40:  * documentation is hereby granted, provided that both the copyright
                     41:  * notice and this permission notice appear in all copies of the
                     42:  * software, derivative works or modified versions, and any portions
                     43:  * thereof, and that both notices appear in supporting documentation.
                     44:  *
                     45:  */
                     46:
                     47: #include <sys/param.h>
                     48: #include <sys/systm.h>
                     49: #include <sys/signalvar.h>
                     50: #include <sys/kernel.h>
                     51: #include <sys/proc.h>
                     52: #include <sys/user.h>
                     53: #include <sys/mount.h>
                     54: #include <sys/syscallargs.h>
                     55: #include <sys/errno.h>
                     56:
                     57: #include <machine/reg.h>
                     58:
                     59: #include <uvm/uvm_extern.h>
                     60:
                     61: struct sigstate {
                     62:        int              ss_flags;      /* which of the following are valid */
                     63:        struct trapframe ss_frame;      /* original exception frame */
                     64: };
                     65:
                     66: /*
                     67:  * WARNING: sigcode() in subr.s assumes sf_scp is the first field of the
                     68:  * sigframe.
                     69:  */
                     70: struct sigframe {
                     71:        struct sigcontext       *sf_scp;        /* context ptr for handler */
                     72:        struct sigcontext        sf_sc;         /* actual context */
                     73:        siginfo_t                sf_si;
                     74: };
                     75:
                     76: #ifdef DEBUG
                     77: int sigdebug = 0;
                     78: int sigpid = 0;
                     79: #define SDB_FOLLOW     0x01
                     80: #define SDB_KSTACK     0x02
                     81: #endif
                     82:
                     83: /*
                     84:  * Send an interrupt to process.
                     85:  */
                     86: void
                     87: sendsig(sig_t catcher, int sig, int mask, unsigned long code, int type,
                     88:     union sigval val)
                     89: {
                     90:        struct proc *p = curproc;
                     91:        struct trapframe *tf;
                     92:        struct sigacts *psp = p->p_sigacts;
                     93:        struct sigframe *fp;
                     94:        int oonstack, fsize;
                     95:        struct sigframe sf;
                     96:        vaddr_t addr;
                     97:
                     98:        tf = p->p_md.md_tf;
                     99:        oonstack = psp->ps_sigstk.ss_flags & SS_ONSTACK;
                    100:        /*
                    101:         * Allocate and validate space for the signal handler
                    102:         * context. Note that if the stack is in data space, the
                    103:         * call to grow() is a nop, and the copyout()
                    104:         * will fail if the process has not already allocated
                    105:         * the space with a `brk'.
                    106:         */
                    107:        fsize = sizeof(struct sigframe);
                    108:        if ((psp->ps_flags & SAS_ALTSTACK) &&
                    109:            (psp->ps_sigstk.ss_flags & SS_ONSTACK) == 0 &&
                    110:            (psp->ps_sigonstack & sigmask(sig))) {
                    111:                fp = (struct sigframe *)(psp->ps_sigstk.ss_sp +
                    112:                                         psp->ps_sigstk.ss_size - fsize);
                    113:                psp->ps_sigstk.ss_flags |= SS_ONSTACK;
                    114:        } else
                    115:                fp = (struct sigframe *)(tf->tf_r[31] - fsize);
                    116:
                    117:        /* make sure the frame is aligned on a 8 byte boundary */
                    118:        if (((vaddr_t)fp & 0x07) != 0)
                    119:                fp = (struct sigframe *)((vaddr_t)fp & ~0x07);
                    120:
                    121:        if ((unsigned)fp <= USRSTACK - ctob(p->p_vmspace->vm_ssize))
                    122:                (void)uvm_grow(p, (unsigned)fp);
                    123:
                    124: #ifdef DEBUG
                    125:        if ((sigdebug & SDB_FOLLOW) ||
                    126:            ((sigdebug & SDB_KSTACK) && p->p_pid == sigpid))
                    127:                printf("sendsig(%d): sig %d ssp %x usp %x scp %x\n",
                    128:                       p->p_pid, sig, &oonstack, fp, &fp->sf_sc);
                    129: #endif
                    130:        /*
                    131:         * Build the signal context to be used by sigreturn.
                    132:         */
                    133:        sf.sf_scp = &fp->sf_sc;
                    134:        sf.sf_sc.sc_onstack = oonstack;
                    135:        sf.sf_sc.sc_mask = mask;
                    136:
                    137:        if (psp->ps_siginfo & sigmask(sig)) {
                    138:                initsiginfo(&sf.sf_si, sig, code, type, val);
                    139:        }
                    140:
                    141:        /*
                    142:         * Copy the whole user context into signal context that we
                    143:         * are building.
                    144:         */
                    145:        bcopy((const void *)&tf->tf_regs, (void *)&sf.sf_sc.sc_regs,
                    146:            sizeof(sf.sf_sc.sc_regs));
                    147:
                    148:        if (copyout((caddr_t)&sf, (caddr_t)fp, sizeof sf)) {
                    149:                /*
                    150:                 * Process has trashed its stack; give it an illegal
                    151:                 * instruction to halt it in its tracks.
                    152:                 */
                    153:                sigexit(p, SIGILL);
                    154:                /* NOTREACHED */
                    155:        }
                    156:
                    157:        /*
                    158:         * Set up registers for the signal handler invocation.
                    159:         */
                    160:        tf->tf_r[1] = p->p_sigcode;             /* return to sigcode */
                    161:        tf->tf_r[2] = sig;                      /* first arg is signo */
                    162:        tf->tf_r[3] = (vaddr_t)&fp->sf_si;      /* second arg is siginfo */
                    163:        addr = (vaddr_t)catcher;                /* and resume in the handler */
                    164: #ifdef M88100
                    165:        if (CPU_IS88100) {
                    166:                tf->tf_snip = (addr & NIP_ADDR) | NIP_V;
                    167:                tf->tf_sfip = (tf->tf_snip + 4) | FIP_V;
                    168:        }
                    169: #endif
                    170: #ifdef M88110
                    171:        if (CPU_IS88110) {
                    172:                tf->tf_exip = (addr & XIP_ADDR);
                    173:        }
                    174: #endif
                    175:        tf->tf_r[31] = (vaddr_t)fp;
                    176:
                    177: #ifdef DEBUG
                    178:        if ((sigdebug & SDB_FOLLOW) ||
                    179:            ((sigdebug & SDB_KSTACK) && p->p_pid == sigpid))
                    180:                printf("sendsig(%d): sig %d returns\n", p->p_pid, sig);
                    181: #endif
                    182: }
                    183:
                    184: /*
                    185:  * System call to cleanup state after a signal has been taken.  Reset signal
                    186:  * mask and stack state from context left by sendsig (above).  Return to
                    187:  * previous pc and psl as specified by context left by sendsig.  Check
                    188:  * carefully to make sure that the user has not modified the psl to gain
                    189:  * improper privileges or to cause a machine fault.
                    190:  */
                    191:
                    192: /* ARGSUSED */
                    193: int
                    194: sys_sigreturn(struct proc *p, void *v, register_t *retval)
                    195: {
                    196:        struct sys_sigreturn_args /* {
                    197:           syscallarg(struct sigcontext *) sigcntxp;
                    198:        } */ *uap = v;
                    199:        struct sigcontext *scp;
                    200:        struct trapframe *tf;
                    201:        struct sigcontext ksc;
                    202:
                    203:        scp = (struct sigcontext *)SCARG(uap, sigcntxp);
                    204: #ifdef DEBUG
                    205:        if (sigdebug & SDB_FOLLOW)
                    206:                printf("sigreturn: pid %d, scp %x\n", p->p_pid, scp);
                    207: #endif
                    208:        if (((vaddr_t)scp & 3) != 0 ||
                    209:            copyin((caddr_t)scp, (caddr_t)&ksc, sizeof(struct sigcontext)))
                    210:                return (EINVAL);
                    211:
                    212:        tf = p->p_md.md_tf;
                    213:        scp = &ksc;
                    214:
                    215:        bcopy((const void *)&scp->sc_regs, (caddr_t)&tf->tf_regs,
                    216:            sizeof(scp->sc_regs));
                    217:
                    218:        /*
                    219:         * Restore the user supplied information
                    220:         */
                    221:        if (scp->sc_onstack & SS_ONSTACK)
                    222:                p->p_sigacts->ps_sigstk.ss_flags |= SS_ONSTACK;
                    223:        else
                    224:                p->p_sigacts->ps_sigstk.ss_flags &= ~SS_ONSTACK;
                    225:        p->p_sigmask = scp->sc_mask & ~sigcantmask;
                    226:
                    227:        return (EJUSTRETURN);
                    228: }

CVSweb