Home | History | Annotate | Line # | Download | only in hppa
sig_machdep.c revision 1.2.8.2
      1  1.2.8.2     skrll /*	$NetBSD: sig_machdep.c,v 1.2.8.2 2004/08/06 10:14:01 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.1     skrll __KERNEL_RCSID(0, "$NetBSD: sig_machdep.c,v 1.2.8.2 2004/08/06 10:14:01 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.1     skrll void sendsig_sigcontext(const struct ksiginfo *, const sigset_t *);
    145  1.2.8.1     skrll 
    146      1.1  fredette /*
    147      1.1  fredette  * Send an interrupt to process.
    148      1.1  fredette  */
    149      1.1  fredette void
    150  1.2.8.1     skrll sendsig_sigcontext(const struct ksiginfo *ksi, const sigset_t *mask)
    151      1.1  fredette {
    152  1.2.8.1     skrll 	int sig = ksi->ksi_signo;
    153  1.2.8.1     skrll 	u_long code = ksi->ksi_trap;
    154  1.2.8.1     skrll 
    155  1.2.8.1     skrll 	struct lwp *l = curlwp;
    156  1.2.8.1     skrll 	struct proc *p = l->l_proc;
    157      1.2   thorpej 	struct sigacts *ps = p->p_sigacts;
    158      1.1  fredette 	struct sigframe *fp, kf;
    159      1.1  fredette 	caddr_t sp;
    160      1.1  fredette 	struct trapframe *tf;
    161      1.1  fredette 	int onstack, fsize;
    162      1.2   thorpej 	sig_t catcher = SIGACTION(p, sig).sa_handler;
    163      1.1  fredette 
    164  1.2.8.1     skrll 	tf = (struct trapframe *)l->l_md.md_regs;
    165      1.1  fredette 
    166      1.1  fredette 	/* Do we need to jump onto the signal stack? */
    167      1.1  fredette 	onstack =
    168      1.1  fredette 	    (p->p_sigctx.ps_sigstk.ss_flags & (SS_DISABLE | SS_ONSTACK)) == 0 &&
    169      1.1  fredette 	    (SIGACTION(p, sig).sa_flags & SA_ONSTACK) != 0;
    170      1.1  fredette 
    171      1.1  fredette 	/*
    172      1.1  fredette 	 * Allocate space for the signal handler context.
    173      1.1  fredette 	 * The PA-RISC calling convention mandates that
    174      1.1  fredette 	 * the stack pointer must always be 64-byte aligned,
    175      1.1  fredette 	 * and points to the first *unused* byte.
    176      1.1  fredette 	 */
    177      1.1  fredette 	fsize = sizeof(struct sigframe);
    178      1.1  fredette 	sp = (onstack ?
    179      1.1  fredette 	      (caddr_t)p->p_sigctx.ps_sigstk.ss_sp :
    180      1.1  fredette 	      (caddr_t)tf->tf_sp);
    181      1.1  fredette 	sp = (caddr_t)(((u_int)(sp + fsize + 63)) & ~63);
    182      1.1  fredette 	fp = (struct sigframe *) (sp - fsize);
    183      1.1  fredette 
    184      1.1  fredette #ifdef DEBUG
    185      1.1  fredette 	if ((sigdebug & SDB_FOLLOW) && (!sigpid || p->p_pid == sigpid))
    186      1.1  fredette 		printf("sendsig: %s[%d] sig %d catcher %p\n",
    187      1.1  fredette 		    p->p_comm, p->p_pid, sig, catcher);
    188      1.1  fredette #endif
    189      1.1  fredette 
    190      1.1  fredette 	/*
    191      1.1  fredette 	 * Save necessary hardware state.  Currently this includes:
    192      1.1  fredette 	 *      - original exception frame
    193      1.1  fredette 	 *      - FP coprocessor state
    194      1.1  fredette 	 */
    195      1.1  fredette 	kf.sf_state.ss_flags = SS_USERREGS;
    196      1.1  fredette 	memcpy(&kf.sf_state.ss_frame, tf, sizeof(*tf));
    197      1.1  fredette 	/* XXX FP state */
    198      1.1  fredette 
    199      1.1  fredette 	/* Build the signal context to be used by sigreturn. */
    200      1.1  fredette 	kf.sf_sc.sc_sp = tf->tf_sp;
    201      1.1  fredette 	kf.sf_sc.sc_fp = tf->tf_sp;	/* XXX fredette - is this right? */
    202      1.1  fredette 	kf.sf_sc.sc_ap = (int)&fp->sf_state;
    203      1.1  fredette 	kf.sf_sc.sc_pcsqh = tf->tf_iisq_head;
    204      1.1  fredette 	kf.sf_sc.sc_pcoqh = tf->tf_iioq_head;
    205      1.1  fredette 	kf.sf_sc.sc_pcsqt = tf->tf_iisq_tail;
    206      1.1  fredette 	kf.sf_sc.sc_pcoqt = tf->tf_iioq_tail;
    207      1.1  fredette 	kf.sf_sc.sc_ps = tf->tf_ipsw;
    208      1.1  fredette 
    209      1.1  fredette 	/* Save signal stack. */
    210      1.1  fredette 	kf.sf_sc.sc_onstack = p->p_sigctx.ps_sigstk.ss_flags & SS_ONSTACK;
    211      1.1  fredette 
    212      1.1  fredette 	/* Save signal mask. */
    213      1.1  fredette 	kf.sf_sc.sc_mask = *mask;
    214      1.1  fredette 
    215      1.1  fredette 	/* Fill the calling convention part of the signal frame. */
    216      1.1  fredette 	kf.sf_psp = 0;
    217      1.1  fredette 	kf.sf_clup = 0;		/* XXX fredette - is this right? */
    218      1.1  fredette 	kf.sf_sl = 0;		/* XXX fredette - is this right? */
    219      1.1  fredette 	kf.sf_edp = 0;		/* XXX fredette - is this right? */
    220      1.1  fredette 
    221      1.1  fredette 	/* Copy out the signal frame. */
    222      1.1  fredette 	if (copyout(&kf, fp, fsize)) {
    223      1.1  fredette #ifdef DEBUG
    224      1.1  fredette 		if ((sigdebug & SDB_KSTACK) && p->p_pid == sigpid)
    225      1.1  fredette 			printf("sendsig(%d): copyout failed on sig %d\n",
    226      1.1  fredette 			       p->p_pid, sig);
    227      1.1  fredette #endif
    228      1.1  fredette 		/*
    229      1.1  fredette 		 * Process has trashed its stack; give it an illegal
    230      1.1  fredette 		 * instruction to halt it in its tracks.
    231      1.1  fredette 		 */
    232  1.2.8.1     skrll 		sigexit(l, SIGILL);
    233      1.1  fredette 		/* NOTREACHED */
    234      1.1  fredette 	}
    235      1.1  fredette #ifdef DEBUG
    236      1.1  fredette 	if (sigdebug & SDB_FOLLOW)
    237      1.1  fredette 		printf("sendsig(%d): sig %d scp %p fp %p sc_sp %x sc_ap %x\n",
    238      1.1  fredette 		       p->p_pid, sig, &fp->sf_sc, fp,
    239      1.1  fredette 		       kf.sf_sc.sc_sp, kf.sf_sc.sc_ap);
    240      1.1  fredette #endif
    241      1.1  fredette 
    242      1.1  fredette 	/* Set up the registers to return to sigcode. */
    243      1.2   thorpej 	switch (ps->sa_sigdesc[sig].sd_vers) {
    244      1.2   thorpej #if 1 /* COMPAT_16 */
    245      1.2   thorpej 	case 0:		/* legacy on-stack sigtramp */
    246      1.2   thorpej 		tf->tf_iioq_head =
    247      1.2   thorpej 		    (int)p->p_sigctx.ps_sigcode | HPPA_PC_PRIV_USER;
    248      1.2   thorpej 		tf->tf_iioq_tail = tf->tf_iioq_head + 4;
    249      1.2   thorpej 		break;
    250      1.2   thorpej #endif
    251      1.2   thorpej 
    252      1.2   thorpej 	case 1:
    253      1.2   thorpej 		tf->tf_iioq_head =
    254      1.2   thorpej 		    (int)ps->sa_sigdesc[sig].sd_tramp | HPPA_PC_PRIV_USER;
    255      1.2   thorpej 		tf->tf_iioq_tail = tf->tf_iioq_head + 4;
    256      1.2   thorpej 		break;
    257      1.2   thorpej 
    258      1.2   thorpej 	default:
    259      1.2   thorpej 		/* Don't know what trampoline version; kill it. */
    260  1.2.8.1     skrll 		sigexit(l, SIGILL);
    261      1.2   thorpej 	}
    262      1.2   thorpej 
    263      1.1  fredette 	tf->tf_sp = (int)sp;
    264      1.1  fredette 	tf->tf_r3 = (int)&fp->sf_sc;
    265      1.1  fredette 	tf->tf_arg0 = sig;
    266      1.1  fredette 	tf->tf_arg1 = code;
    267      1.1  fredette 	tf->tf_arg2 = (int)&fp->sf_sc;
    268      1.1  fredette 	tf->tf_arg3 = (int)catcher;
    269      1.2   thorpej 
    270      1.1  fredette 	/* Remember that we're now on the signal stack. */
    271      1.1  fredette 	if (onstack)
    272      1.1  fredette 		p->p_sigctx.ps_sigstk.ss_flags |= SS_ONSTACK;
    273      1.1  fredette 
    274      1.1  fredette #ifdef DEBUG
    275      1.1  fredette 	if ((sigdebug & SDB_KSTACK) && p->p_pid == sigpid)
    276      1.1  fredette 		printf("sendsig(%d): sig %d returns\n",
    277      1.1  fredette 		       p->p_pid, sig);
    278      1.1  fredette #endif
    279      1.1  fredette }
    280      1.1  fredette 
    281  1.2.8.1     skrll void *getframe(struct lwp *, int, int *);
    282  1.2.8.1     skrll void sendsig_siginfo(const struct ksiginfo *, const sigset_t *);
    283  1.2.8.1     skrll 
    284  1.2.8.1     skrll void *
    285  1.2.8.1     skrll getframe(struct lwp *l, int sig, int *onstack)
    286  1.2.8.1     skrll {
    287  1.2.8.1     skrll 	struct proc *p = l->l_proc;
    288  1.2.8.1     skrll 	struct sigctx *ctx = &p->p_sigctx;
    289  1.2.8.1     skrll 	struct trapframe *tf = l->l_md.md_regs;
    290  1.2.8.1     skrll 
    291  1.2.8.1     skrll 	/* Do we need to jump onto the signal stack? */
    292  1.2.8.1     skrll 	*onstack = (ctx->ps_sigstk.ss_flags & (SS_DISABLE | SS_ONSTACK)) == 0
    293  1.2.8.1     skrll 	    && (SIGACTION(p, sig).sa_flags & SA_ONSTACK) != 0;
    294  1.2.8.1     skrll 	if (*onstack)
    295  1.2.8.1     skrll 		return (void *)ctx->ps_sigstk.ss_sp;
    296  1.2.8.1     skrll 	else
    297  1.2.8.1     skrll 		return (void *)tf->tf_sp;
    298  1.2.8.1     skrll }
    299  1.2.8.1     skrll 
    300  1.2.8.1     skrll struct sigframe_siginfo {
    301  1.2.8.1     skrll 	siginfo_t sf_si;
    302  1.2.8.1     skrll 	ucontext_t sf_uc;
    303  1.2.8.1     skrll };
    304  1.2.8.1     skrll 
    305  1.2.8.1     skrll void
    306  1.2.8.1     skrll sendsig_siginfo(const struct ksiginfo *ksi, const sigset_t *mask)
    307  1.2.8.1     skrll {
    308  1.2.8.1     skrll 	struct lwp *l = curlwp;
    309  1.2.8.1     skrll 	struct proc *p = l->l_proc;
    310  1.2.8.1     skrll 	struct sigacts *ps = p->p_sigacts;
    311  1.2.8.1     skrll 	struct sigframe_siginfo *fp, frame;
    312  1.2.8.1     skrll 	struct trapframe *tf;
    313  1.2.8.1     skrll 	int sig = ksi->ksi_signo;
    314  1.2.8.1     skrll 	sig_t catcher = SIGACTION(p, sig).sa_handler;
    315  1.2.8.1     skrll 	int onstack;
    316  1.2.8.1     skrll 
    317  1.2.8.1     skrll 	fp = getframe(l, sig, &onstack);
    318  1.2.8.1     skrll 	tf = (struct trapframe *)l->l_md.md_regs;
    319  1.2.8.1     skrll 
    320  1.2.8.1     skrll 	/* Build stack frame for signal trampoline. */
    321  1.2.8.1     skrll 	switch (ps->sa_sigdesc[sig].sd_vers) {
    322  1.2.8.1     skrll 	default:
    323  1.2.8.1     skrll 		printf("sendsig_siginfo: bad version %d\n",
    324  1.2.8.1     skrll 		       ps->sa_sigdesc[sig].sd_vers);
    325  1.2.8.1     skrll 		sigexit(l, SIGILL);
    326  1.2.8.1     skrll 	case 2:
    327  1.2.8.1     skrll 		break;
    328  1.2.8.1     skrll 	}
    329  1.2.8.1     skrll 
    330  1.2.8.2     skrll 	frame.sf_si._info = ksi->ksi_info;
    331  1.2.8.1     skrll 	frame.sf_uc.uc_flags = _UC_SIGMASK |
    332  1.2.8.1     skrll 		((p->p_sigctx.ps_sigstk.ss_flags & SS_ONSTACK) ?
    333  1.2.8.1     skrll 		 _UC_SETSTACK : _UC_CLRSTACK);
    334  1.2.8.1     skrll 	frame.sf_uc.uc_sigmask = *mask;
    335  1.2.8.1     skrll 	frame.sf_uc.uc_link = NULL;
    336  1.2.8.1     skrll 	memset(&frame.sf_uc.uc_stack, 0, sizeof(frame.sf_uc.uc_stack));
    337  1.2.8.1     skrll 	cpu_getmcontext(l, &frame.sf_uc.uc_mcontext, &frame.sf_uc.uc_flags);
    338  1.2.8.1     skrll 
    339  1.2.8.1     skrll 	if (copyout(&frame, fp, sizeof(frame)) != 0) {
    340  1.2.8.1     skrll 
    341  1.2.8.1     skrll 		/*
    342  1.2.8.1     skrll 		 * Process has trashed its stack; give it an illegal
    343  1.2.8.1     skrll 		 * instruction to halt it in its tracks.
    344  1.2.8.1     skrll 		 */
    345  1.2.8.1     skrll 		sigexit(l, SIGILL);
    346  1.2.8.1     skrll 		/* NOTREACHED */
    347  1.2.8.1     skrll 	}
    348  1.2.8.1     skrll 
    349  1.2.8.1     skrll 	/*
    350  1.2.8.1     skrll 	 * Set up the registers to invoke the signal trampoline.
    351  1.2.8.1     skrll 	 */
    352  1.2.8.1     skrll 	tf->tf_arg0 = sig;
    353  1.2.8.1     skrll 	tf->tf_arg1 = (__greg_t)&fp->sf_si;
    354  1.2.8.1     skrll 	tf->tf_arg2 = (__greg_t)&fp->sf_uc;
    355  1.2.8.1     skrll 	tf->tf_r3 = (__greg_t)&fp->sf_uc;
    356  1.2.8.1     skrll 
    357  1.2.8.1     skrll 	tf->tf_iioq_head =
    358  1.2.8.1     skrll 		(__greg_t)ps->sa_sigdesc[sig].sd_tramp | HPPA_PC_PRIV_USER;
    359  1.2.8.1     skrll 	tf->tf_iioq_tail = tf->tf_iioq_head + 4;
    360  1.2.8.1     skrll 	tf->tf_arg3 = (__greg_t)catcher;
    361  1.2.8.1     skrll 	tf->tf_sp = HPPA_FRAME_ROUND((uintptr_t)fp + sizeof(*fp) +
    362  1.2.8.1     skrll 				     HPPA_FRAME_SIZE);
    363  1.2.8.1     skrll 
    364  1.2.8.1     skrll 	/* Remember that we're now on the signal stack. */
    365  1.2.8.1     skrll 	if (onstack)
    366  1.2.8.1     skrll 		p->p_sigctx.ps_sigstk.ss_flags |= SS_ONSTACK;
    367  1.2.8.1     skrll }
    368  1.2.8.1     skrll 
    369  1.2.8.1     skrll void
    370  1.2.8.1     skrll sendsig(const ksiginfo_t *ksi, const sigset_t *mask)
    371  1.2.8.1     skrll {
    372  1.2.8.1     skrll 	if (curproc->p_sigacts->sa_sigdesc[ksi->ksi_signo].sd_vers < 2)
    373  1.2.8.1     skrll 		sendsig_sigcontext(ksi, mask);
    374  1.2.8.1     skrll 	else
    375  1.2.8.1     skrll 		sendsig_siginfo(ksi, mask);
    376  1.2.8.1     skrll }
    377  1.2.8.1     skrll 
    378      1.1  fredette int
    379  1.2.8.1     skrll compat_16_sys___sigreturn14(struct lwp *l, void *v, register_t *retval)
    380      1.1  fredette {
    381  1.2.8.1     skrll 	struct compat_16_sys___sigreturn14_args /* {
    382      1.1  fredette 		syscallarg(struct sigcontext *) sigcntxp;
    383      1.1  fredette 	} */ *uap = v;
    384  1.2.8.1     skrll 	struct proc *p = l->l_proc;
    385      1.1  fredette 	struct sigcontext *scp;
    386      1.1  fredette 	struct trapframe *tf;
    387      1.1  fredette 	struct sigcontext tsigc;
    388      1.1  fredette 	struct sigstate tstate;
    389      1.1  fredette 	int rf, flags;
    390      1.1  fredette 
    391      1.1  fredette 	/*
    392      1.1  fredette 	 * The trampoline code hands us the context.
    393      1.1  fredette 	 * It is unsafe to keep track of it ourselves, in the event that a
    394      1.1  fredette 	 * program jumps out of a signal handler.
    395      1.1  fredette 	 */
    396      1.1  fredette 	scp = SCARG(uap, sigcntxp);
    397      1.1  fredette #ifdef DEBUG
    398      1.1  fredette 	if (sigdebug & SDB_FOLLOW)
    399      1.1  fredette 		printf("sigreturn: pid %d, scp %p\n", p->p_pid, scp);
    400      1.1  fredette #endif
    401      1.1  fredette 	if ((int)scp & 3)
    402      1.1  fredette 		return (EINVAL);
    403      1.1  fredette 
    404      1.1  fredette 	if (copyin(scp, &tsigc, sizeof(tsigc)) != 0)
    405      1.1  fredette 		return (EFAULT);
    406      1.1  fredette 	scp = &tsigc;
    407      1.1  fredette 
    408      1.1  fredette 	/* Make sure the user isn't pulling a fast one on us! */
    409      1.1  fredette 	/* XXX fredette - until this is done, huge security hole here. */
    410      1.1  fredette 	/* XXX fredette - requiring that PSL_R be zero will hurt debuggers. */
    411      1.1  fredette 	if ((scp->sc_ps & (PSW_MBS|PSW_MBZ)) != PSW_MBS)
    412      1.1  fredette 		return (EINVAL);
    413      1.1  fredette 
    414      1.1  fredette 	/* Restore register context. */
    415  1.2.8.1     skrll 	tf = (struct trapframe *)l->l_md.md_regs;
    416      1.1  fredette 
    417      1.1  fredette 	/*
    418      1.1  fredette 	 * Grab pointer to hardware state information.
    419      1.1  fredette 	 * If zero, the user is probably doing a longjmp.
    420      1.1  fredette 	 */
    421      1.1  fredette 	if ((rf = scp->sc_ap) == 0)
    422      1.1  fredette 		goto restore;
    423      1.1  fredette 
    424      1.1  fredette 	/*
    425      1.1  fredette 	 * See if there is anything to do before we go to the
    426      1.1  fredette 	 * expense of copying in the trapframe
    427      1.1  fredette 	 */
    428      1.1  fredette 	flags = fuword((caddr_t)rf);
    429      1.1  fredette #ifdef DEBUG
    430      1.1  fredette 	if (sigdebug & SDB_FOLLOW)
    431      1.1  fredette 		printf("sigreturn(%d): sc_ap %x flags %x\n",
    432      1.1  fredette 		       p->p_pid, rf, flags);
    433      1.1  fredette #endif
    434      1.1  fredette 	/* fuword failed (bogus sc_ap value). */
    435      1.1  fredette 	if (flags == -1)
    436      1.1  fredette 		return (EINVAL);
    437      1.1  fredette 
    438      1.1  fredette 	if (flags == 0 || copyin((caddr_t)rf, &tstate, sizeof(tstate)) != 0)
    439      1.1  fredette 		goto restore;
    440      1.1  fredette #ifdef DEBUG
    441      1.1  fredette 	if ((sigdebug & SDB_KSTACK) && p->p_pid == sigpid)
    442      1.1  fredette 		printf("sigreturn(%d): ssp %p usp %x scp %p\n",
    443      1.1  fredette 		       p->p_pid, &flags, scp->sc_sp, SCARG(uap, sigcntxp));
    444      1.1  fredette #endif
    445      1.1  fredette 
    446      1.1  fredette 	/*
    447      1.1  fredette 	 * Restore most of the users registers except for those
    448      1.1  fredette 	 * in the sigcontext; they will be handled below.
    449      1.1  fredette 	 */
    450      1.1  fredette 	if (flags & SS_USERREGS) {
    451      1.1  fredette 
    452      1.1  fredette 		/*
    453      1.1  fredette 		 * There are more registers that the user can tell
    454      1.1  fredette 		 * us to bash than registers that, for security
    455      1.1  fredette 		 * or other reasons, we must protect.  So it's
    456      1.1  fredette 		 * easier (but not faster), to copy these sensitive
    457      1.1  fredette 		 * register values into the user-provided frame,
    458      1.1  fredette 		 * then bulk-copy the user-provided frame into
    459      1.1  fredette 		 * the process' frame.
    460      1.1  fredette 		 */
    461      1.1  fredette #define	SIG_PROTECT(r) tstate.ss_frame.r = tf->r
    462      1.1  fredette 		/* SRs 5,6,7 must be protected. */
    463      1.1  fredette 		SIG_PROTECT(tf_sr5);
    464      1.1  fredette 		SIG_PROTECT(tf_sr6);
    465      1.1  fredette 		SIG_PROTECT(tf_sr7);
    466      1.1  fredette 
    467      1.1  fredette 		/* all CRs except CR11 must be protected. */
    468      1.1  fredette 		SIG_PROTECT(tf_rctr);	/* CR0 */
    469      1.1  fredette 		/* CRs 1-8 are reserved */
    470      1.1  fredette 		SIG_PROTECT(tf_pidr1);	/* CR8 */
    471      1.1  fredette 		SIG_PROTECT(tf_pidr2);	/* CR9 */
    472      1.1  fredette 		SIG_PROTECT(tf_ccr);	/* CR10 */
    473      1.1  fredette 		SIG_PROTECT(tf_pidr3);	/* CR12 */
    474      1.1  fredette 		SIG_PROTECT(tf_pidr4);	/* CR14 */
    475      1.1  fredette 		SIG_PROTECT(tf_eiem);	/* CR15 */
    476      1.1  fredette 		/* CR17 is the IISQ head */
    477      1.1  fredette 		/* CR18 is the IIOQ head */
    478      1.1  fredette 		SIG_PROTECT(tf_iir);	/* CR19 */
    479      1.1  fredette 		SIG_PROTECT(tf_isr);	/* CR20 */
    480      1.1  fredette 		SIG_PROTECT(tf_ior);	/* CR21 */
    481      1.1  fredette 		/* CR22 is the IPSW */
    482      1.1  fredette 		SIG_PROTECT(tf_eirr);	/* CR23 */
    483      1.1  fredette 		SIG_PROTECT(tf_hptm);	/* CR24 */
    484      1.1  fredette 		SIG_PROTECT(tf_vtop);	/* CR25 */
    485      1.1  fredette 		/* XXX where are CR26, CR27, CR29, CR31? */
    486      1.1  fredette 		SIG_PROTECT(tf_cr28);	/* CR28 */
    487      1.1  fredette 		SIG_PROTECT(tf_cr30);	/* CR30 */
    488      1.1  fredette #undef	SIG_PROTECT
    489      1.1  fredette 
    490      1.1  fredette 		/* The bulk copy. */
    491      1.1  fredette 		*tf = tstate.ss_frame;
    492      1.1  fredette 	}
    493      1.1  fredette 
    494      1.1  fredette 	/*
    495      1.1  fredette 	 * Restore the original FP context
    496      1.1  fredette 	 */
    497      1.1  fredette 	/* XXX fredette */
    498      1.1  fredette 
    499      1.1  fredette  restore:
    500      1.1  fredette 	/*
    501      1.1  fredette 	 * Restore the user supplied information.
    502      1.1  fredette 	 * This should be at the last so that the error (EINVAL)
    503      1.1  fredette 	 * is reported to the sigreturn caller, not to the
    504      1.1  fredette 	 * jump destination.
    505      1.1  fredette 	 */
    506      1.1  fredette 
    507      1.1  fredette 	tf->tf_sp = scp->sc_sp;
    508      1.1  fredette 	/* XXX should we be doing the space registers? */
    509      1.1  fredette 	tf->tf_iisq_head = scp->sc_pcsqh;
    510      1.1  fredette 	tf->tf_iioq_head = scp->sc_pcoqh | HPPA_PC_PRIV_USER;
    511      1.1  fredette 	tf->tf_iisq_tail = scp->sc_pcsqt;
    512      1.1  fredette 	tf->tf_iioq_tail = scp->sc_pcoqt | HPPA_PC_PRIV_USER;
    513      1.1  fredette 	tf->tf_ipsw = scp->sc_ps;
    514      1.1  fredette 
    515      1.1  fredette 	/* Restore signal stack. */
    516      1.1  fredette 	if (scp->sc_onstack & SS_ONSTACK)
    517      1.1  fredette 		p->p_sigctx.ps_sigstk.ss_flags |= SS_ONSTACK;
    518      1.1  fredette 	else
    519      1.1  fredette 		p->p_sigctx.ps_sigstk.ss_flags &= ~SS_ONSTACK;
    520      1.1  fredette 
    521      1.1  fredette 	/* Restore signal mask. */
    522      1.1  fredette 	(void) sigprocmask1(p, SIG_SETMASK, &scp->sc_mask, 0);
    523      1.1  fredette 
    524      1.1  fredette #ifdef DEBUG
    525      1.1  fredette #if 0 /* XXX FP state */
    526      1.1  fredette 	if ((sigdebug & SDB_FPSTATE) && *(char *)&tstate.ss_fpstate)
    527      1.1  fredette 		printf("sigreturn(%d): copied in FP state (%x) at %p\n",
    528      1.1  fredette 		       p->p_pid, *(u_int *)&tstate.ss_fpstate,
    529      1.1  fredette 		       &tstate.ss_fpstate);
    530      1.1  fredette #endif
    531      1.1  fredette 	if ((sigdebug & SDB_FOLLOW) ||
    532      1.1  fredette 	    ((sigdebug & SDB_KSTACK) && p->p_pid == sigpid))
    533      1.1  fredette 		printf("sigreturn(%d): returns\n", p->p_pid);
    534      1.1  fredette #endif
    535      1.1  fredette 	return (EJUSTRETURN);
    536      1.1  fredette }
    537      1.1  fredette 
    538