Home | History | Annotate | Line # | Download | only in hppa
sig_machdep.c revision 1.19
      1 /*	$NetBSD: sig_machdep.c,v 1.19 2007/12/22 14:09:03 skrll Exp $	*/
      2 
      3 /*-
      4  * Copyright (c) 2002 The NetBSD Foundation, Inc.
      5  * All rights reserved.
      6  *
      7  * This code is derived from software contributed to The NetBSD Foundation
      8  * by Matthew Fredette.
      9  *
     10  * Redistribution and use in source and binary forms, with or without
     11  * modification, are permitted provided that the following conditions
     12  * are met:
     13  * 1. Redistributions of source code must retain the above copyright
     14  *    notice, this list of conditions and the following disclaimer.
     15  * 2. Redistributions in binary form must reproduce the above copyright
     16  *    notice, this list of conditions and the following disclaimer in the
     17  *    documentation and/or other materials provided with the distribution.
     18  * 3. All advertising materials mentioning features or use of this software
     19  *    must display the following acknowledgement:
     20  *      This product includes software developed by the NetBSD
     21  *      Foundation, Inc. and its contributors.
     22  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23  *    contributors may be used to endorse or promote products derived
     24  *    from this software without specific prior written permission.
     25  *
     26  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36  * POSSIBILITY OF SUCH DAMAGE.
     37  */
     38 
     39 /*
     40  * Copyright (c) 1982, 1986, 1990, 1993
     41  *	The Regents of the University of California.  All rights reserved.
     42  *
     43  * This code is derived from software contributed to Berkeley by
     44  * the Systems Programming Group of the University of Utah Computer
     45  * Science Department.
     46  *
     47  * Redistribution and use in source and binary forms, with or without
     48  * modification, are permitted provided that the following conditions
     49  * are met:
     50  * 1. Redistributions of source code must retain the above copyright
     51  *    notice, this list of conditions and the following disclaimer.
     52  * 2. Redistributions in binary form must reproduce the above copyright
     53  *    notice, this list of conditions and the following disclaimer in the
     54  *    documentation and/or other materials provided with the distribution.
     55  * 3. Neither the name of the University nor the names of its contributors
     56  *    may be used to endorse or promote products derived from this software
     57  *    without specific prior written permission.
     58  *
     59  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     60  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     61  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     62  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     63  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     64  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     65  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     66  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     67  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     68  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     69  * SUCH DAMAGE.
     70  *
     71  *	from: Utah Hdr: machdep.c 1.74 92/12/20
     72  *	from: @(#)machdep.c	8.10 (Berkeley) 4/20/94
     73  */
     74 /*
     75  * Copyright (c) 1988 University of Utah.
     76  *
     77  * This code is derived from software contributed to Berkeley by
     78  * the Systems Programming Group of the University of Utah Computer
     79  * Science Department.
     80  *
     81  * Redistribution and use in source and binary forms, with or without
     82  * modification, are permitted provided that the following conditions
     83  * are met:
     84  * 1. Redistributions of source code must retain the above copyright
     85  *    notice, this list of conditions and the following disclaimer.
     86  * 2. Redistributions in binary form must reproduce the above copyright
     87  *    notice, this list of conditions and the following disclaimer in the
     88  *    documentation and/or other materials provided with the distribution.
     89  * 3. All advertising materials mentioning features or use of this software
     90  *    must display the following acknowledgement:
     91  *	This product includes software developed by the University of
     92  *	California, Berkeley and its contributors.
     93  * 4. Neither the name of the University nor the names of its contributors
     94  *    may be used to endorse or promote products derived from this software
     95  *    without specific prior written permission.
     96  *
     97  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     98  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     99  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
    100  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
    101  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
    102  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
    103  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
    104  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
    105  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
    106  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
    107  * SUCH DAMAGE.
    108  *
    109  *	from: Utah Hdr: machdep.c 1.74 92/12/20
    110  *	from: @(#)machdep.c	8.10 (Berkeley) 4/20/94
    111  */
    112 
    113 #include <sys/cdefs.h>
    114 __KERNEL_RCSID(0, "$NetBSD: sig_machdep.c,v 1.19 2007/12/22 14:09:03 skrll Exp $");
    115 
    116 #include "opt_compat_netbsd.h"
    117 
    118 #include <sys/param.h>
    119 #include <sys/systm.h>
    120 #include <sys/kernel.h>
    121 #include <sys/proc.h>
    122 #include <sys/user.h>
    123 #include <sys/signal.h>
    124 #include <sys/signalvar.h>
    125 
    126 #include <sys/mount.h>
    127 #include <sys/syscallargs.h>
    128 
    129 #include <machine/cpu.h>
    130 #include <machine/reg.h>
    131 #include <machine/frame.h>
    132 
    133 #ifdef DEBUG
    134 int sigdebug = 0;
    135 int sigpid = 0;
    136 #define SDB_FOLLOW	0x01
    137 #define SDB_KSTACK	0x02
    138 #define SDB_FPSTATE	0x04
    139 #endif
    140 
    141 static void *getframe(struct lwp *, int, int *);
    142 static void *
    143 getframe(struct lwp *l, int sig, int *onstack)
    144 {
    145 	struct proc *p = l->l_proc;
    146 	struct trapframe *tf = l->l_md.md_regs;
    147 
    148 	/* Do we need to jump onto the signal stack? */
    149 	*onstack = (l->l_sigstk.ss_flags & (SS_DISABLE | SS_ONSTACK)) == 0
    150 	    && (SIGACTION(p, sig).sa_flags & SA_ONSTACK) != 0;
    151 	if (*onstack)
    152 		return (void *)HPPA_FRAME_ROUND(l->l_sigstk.ss_sp);
    153 	else
    154 		return (void *)HPPA_FRAME_ROUND(tf->tf_sp);
    155 }
    156 
    157 struct sigframe_siginfo {
    158 	siginfo_t sf_si;
    159 	ucontext_t sf_uc;
    160 };
    161 
    162 void
    163 sendsig(const struct ksiginfo *ksi, const sigset_t *mask)
    164 {
    165 	struct lwp *l = curlwp;
    166 	struct proc *p = l->l_proc;
    167 	struct sigacts *ps = p->p_sigacts;
    168 	struct sigframe_siginfo *fp, frame;
    169 	struct trapframe *tf;
    170 	int sig = ksi->ksi_signo;
    171 	sig_t catcher = SIGACTION(p, sig).sa_handler;
    172 	int onstack, error;
    173 
    174 	fp = getframe(l, sig, &onstack);
    175 	tf = (struct trapframe *)l->l_md.md_regs;
    176 
    177 	/* Build stack frame for signal trampoline. */
    178 	switch (ps->sa_sigdesc[sig].sd_vers) {
    179 	default:
    180 		printf("sendsig_siginfo: bad version %d\n",
    181 		       ps->sa_sigdesc[sig].sd_vers);
    182 		sigexit(l, SIGILL);
    183 	case 2:
    184 		break;
    185 	}
    186 
    187 	frame.sf_si._info = ksi->ksi_info;
    188 	frame.sf_uc.uc_flags = _UC_SIGMASK |
    189 		((l->l_sigstk.ss_flags & SS_ONSTACK) ?
    190 		 _UC_SETSTACK : _UC_CLRSTACK);
    191 	frame.sf_uc.uc_sigmask = *mask;
    192 	frame.sf_uc.uc_link = l->l_ctxlink;
    193 	memset(&frame.sf_uc.uc_stack, 0, sizeof(frame.sf_uc.uc_stack));
    194 	sendsig_reset(l, sig);
    195 	mutex_exit(&p->p_smutex);
    196 	cpu_getmcontext(l, &frame.sf_uc.uc_mcontext, &frame.sf_uc.uc_flags);
    197 	error = copyout(&frame, fp, sizeof(frame));
    198 	mutex_enter(&p->p_smutex);
    199 
    200 	if (error != 0) {
    201 
    202 		/*
    203 		 * Process has trashed its stack; give it an illegal
    204 		 * instruction to halt it in its tracks.
    205 		 */
    206 		sigexit(l, SIGILL);
    207 		/* NOTREACHED */
    208 	}
    209 
    210 	/*
    211 	 * Set up the registers to invoke the signal trampoline.
    212 	 */
    213 	tf->tf_arg0 = sig;
    214 	tf->tf_arg1 = (__greg_t)&fp->sf_si;
    215 	tf->tf_arg2 = (__greg_t)&fp->sf_uc;
    216 	tf->tf_r3 = (__greg_t)&fp->sf_uc;
    217 
    218 	fp++;
    219 	tf->tf_iisq_head = tf->tf_iisq_tail = l->l_addr->u_pcb.pcb_space;
    220 	tf->tf_iioq_head =
    221 		(__greg_t)ps->sa_sigdesc[sig].sd_tramp | HPPA_PC_PRIV_USER;
    222 	tf->tf_iioq_tail = tf->tf_iioq_head + 4;
    223 	tf->tf_arg3 = (__greg_t)catcher;
    224 	tf->tf_sp = HPPA_FRAME_ROUND(fp);
    225 
    226 	/* Remember that we're now on the signal stack. */
    227 	if (onstack)
    228 		l->l_sigstk.ss_flags |= SS_ONSTACK;
    229 }
    230