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