Home | History | Annotate | Line # | Download | only in alpha
linux_machdep.c revision 1.51
      1  1.51   thorpej /*	$NetBSD: linux_machdep.c,v 1.51 2020/09/03 14:26:31 thorpej Exp $	*/
      2   1.1       erh 
      3   1.1       erh /*-
      4   1.1       erh  * Copyright (c) 1998 The NetBSD Foundation, Inc.
      5   1.1       erh  * All rights reserved.
      6   1.1       erh  *
      7   1.1       erh  * This code is derived from software contributed to The NetBSD Foundation
      8   1.1       erh  * by Eric Haszlakiewicz.
      9   1.1       erh  *
     10   1.1       erh  * Redistribution and use in source and binary forms, with or without
     11   1.1       erh  * modification, are permitted provided that the following conditions
     12   1.1       erh  * are met:
     13   1.1       erh  * 1. Redistributions of source code must retain the above copyright
     14   1.1       erh  *    notice, this list of conditions and the following disclaimer.
     15   1.1       erh  * 2. Redistributions in binary form must reproduce the above copyright
     16   1.1       erh  *    notice, this list of conditions and the following disclaimer in the
     17   1.1       erh  *    documentation and/or other materials provided with the distribution.
     18   1.1       erh  *
     19   1.1       erh  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20   1.1       erh  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21   1.1       erh  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22   1.1       erh  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23   1.1       erh  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24   1.1       erh  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25   1.1       erh  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26   1.1       erh  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27   1.1       erh  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28   1.1       erh  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29   1.1       erh  * POSSIBILITY OF SUCH DAMAGE.
     30   1.1       erh  *
     31   1.1       erh  * Based on sys/arch/i386/i386/linux_machdep.c:
     32   1.1       erh  *	linux_machdep.c,v 1.42 1998/09/11 12:50:06 mycroft Exp
     33   1.1       erh  *	written by Frank van der Linden
     34   1.1       erh  *
     35   1.1       erh  */
     36  1.19     lukem 
     37  1.19     lukem #include <sys/cdefs.h>
     38  1.51   thorpej __KERNEL_RCSID(0, "$NetBSD: linux_machdep.c,v 1.51 2020/09/03 14:26:31 thorpej Exp $");
     39   1.1       erh 
     40   1.1       erh #include <sys/param.h>
     41   1.1       erh #include <sys/systm.h>
     42   1.1       erh #include <sys/signalvar.h>
     43   1.1       erh #include <sys/kernel.h>
     44   1.1       erh #include <sys/proc.h>
     45   1.1       erh #include <sys/buf.h>
     46   1.1       erh #include <sys/reboot.h>
     47   1.1       erh #include <sys/conf.h>
     48   1.1       erh #include <sys/exec.h>
     49   1.1       erh #include <sys/file.h>
     50   1.1       erh #include <sys/callout.h>
     51   1.1       erh #include <sys/mbuf.h>
     52   1.1       erh #include <sys/msgbuf.h>
     53   1.1       erh #include <sys/mount.h>
     54   1.1       erh #include <sys/vnode.h>
     55   1.1       erh #include <sys/device.h>
     56   1.1       erh #include <sys/syscallargs.h>
     57   1.1       erh #include <sys/filedesc.h>
     58   1.1       erh #include <sys/exec_elf.h>
     59  1.15      manu #include <sys/ioctl.h>
     60  1.34      yamt #include <sys/kauth.h>
     61   1.1       erh 
     62   1.1       erh #include <uvm/uvm_extern.h>
     63   1.1       erh 
     64   1.2  christos #include <compat/linux/common/linux_types.h>
     65   1.2  christos #include <compat/linux/common/linux_signal.h>
     66   1.2  christos #include <compat/linux/common/linux_siginfo.h>
     67   1.2  christos #include <compat/linux/common/linux_util.h>
     68   1.2  christos #include <compat/linux/common/linux_ioctl.h>
     69   1.2  christos #include <compat/linux/common/linux_exec.h>
     70   1.2  christos #include <compat/linux/common/linux_machdep.h>
     71   1.3       erh #include <compat/linux/common/linux_emuldata.h>
     72   1.2  christos 
     73   1.1       erh #include <compat/linux/linux_syscallargs.h>
     74   1.1       erh 
     75   1.3       erh #include <machine/alpha.h>
     76   1.1       erh #include <machine/reg.h>
     77   1.1       erh 
     78  1.17       mrg #if defined(_KERNEL_OPT)
     79   1.1       erh #include "wsdisplay.h"
     80  1.12  jdolecek #endif
     81   1.1       erh #if (NWSDISPLAY >0)
     82   1.1       erh #include <dev/wscons/wsdisplay_usl_io.h>
     83   1.1       erh #endif
     84  1.14  sommerfe #ifdef DEBUG
     85  1.14  sommerfe #include <machine/sigdebug.h>
     86  1.14  sommerfe #endif
     87   1.1       erh 
     88   1.1       erh /*
     89   1.1       erh  * Deal with some alpha-specific things in the Linux emulation code.
     90   1.1       erh  */
     91   1.1       erh 
     92   1.1       erh void
     93  1.46       chs linux_setregs(struct lwp *l, struct exec_package *epp, vaddr_t stack)
     94   1.1       erh {
     95  1.18    simonb #ifdef DEBUG
     96  1.26   thorpej 	struct trapframe *tfp = l->l_md.md_tf;
     97  1.18    simonb #endif
     98  1.18    simonb 
     99  1.26   thorpej 	setregs(l, epp, stack);
    100  1.18    simonb #ifdef DEBUG
    101  1.18    simonb 	/*
    102  1.18    simonb 	 * Linux has registers set to zero on entry; for DEBUG kernels
    103  1.18    simonb 	 * the alpha setregs() fills registers with 0xbabefacedeadbeef.
    104  1.18    simonb 	 */
    105  1.18    simonb 	memset(tfp->tf_regs, 0, FRAME_SIZE * sizeof tfp->tf_regs[0]);
    106  1.18    simonb #endif
    107   1.1       erh }
    108   1.1       erh 
    109  1.30      matt void
    110  1.49  christos setup_linux_rt_sigframe(struct trapframe *tf, const ksiginfo_t *ksi,
    111  1.49  christos     const sigset_t *mask)
    112   1.1       erh {
    113  1.26   thorpej 	struct lwp *l = curlwp;
    114  1.26   thorpej 	struct proc *p = l->l_proc;
    115   1.1       erh 	struct linux_rt_sigframe *sfp, sigframe;
    116  1.36        ad 	int onstack, error;
    117   1.1       erh 	int fsize, rndfsize;
    118  1.49  christos 	int sig = ksi->ksi_signo;
    119   1.1       erh 	extern char linux_rt_sigcode[], linux_rt_esigcode[];
    120   1.1       erh 
    121   1.1       erh 	/* Do we need to jump onto the signal stack? */
    122  1.36        ad 	onstack = (l->l_sigstk.ss_flags & (SS_DISABLE | SS_ONSTACK)) == 0 &&
    123  1.13  jdolecek 		  (SIGACTION(p, sig).sa_flags & SA_ONSTACK) != 0;
    124   1.1       erh 
    125   1.1       erh 	/* Allocate space for the signal handler context.  */
    126   1.1       erh 	fsize = sizeof(struct linux_rt_sigframe);
    127   1.1       erh 	rndfsize = ((fsize + 15) / 16) * 16;
    128   1.1       erh 
    129   1.1       erh 	if (onstack)
    130   1.1       erh 		sfp = (struct linux_rt_sigframe *)
    131  1.38      yamt 		    ((char *)l->l_sigstk.ss_sp + l->l_sigstk.ss_size);
    132   1.1       erh 	else
    133   1.1       erh 		sfp = (struct linux_rt_sigframe *)(alpha_pal_rdusp());
    134  1.38      yamt 	sfp = (struct linux_rt_sigframe *)((char *)sfp - rndfsize);
    135   1.1       erh 
    136   1.1       erh #ifdef DEBUG
    137  1.14  sommerfe 	if ((sigdebug & SDB_KSTACK) && (p->p_pid == sigpid))
    138   1.1       erh 		printf("linux_sendsig(%d): sig %d ssp %p usp %p\n", p->p_pid,
    139   1.1       erh 		    sig, &onstack, sfp);
    140   1.1       erh #endif /* DEBUG */
    141   1.1       erh 
    142   1.1       erh 	/*
    143   1.1       erh 	 * Build the signal context to be used by sigreturn.
    144   1.1       erh 	 */
    145  1.30      matt 	memset(&sigframe.uc, 0, sizeof(struct linux_ucontext));
    146   1.1       erh 	sigframe.uc.uc_mcontext.sc_onstack = onstack;
    147   1.8       erh 
    148   1.8       erh 	/* Setup potentially partial signal mask in sc_mask. */
    149   1.8       erh 	/* But get all of it in uc_sigmask */
    150  1.20  christos 	native_to_linux_old_sigset(&sigframe.uc.uc_mcontext.sc_mask, mask);
    151  1.20  christos 	native_to_linux_sigset(&sigframe.uc.uc_sigmask, mask);
    152   1.8       erh 
    153   1.1       erh 	sigframe.uc.uc_mcontext.sc_pc = tf->tf_regs[FRAME_PC];
    154   1.1       erh 	sigframe.uc.uc_mcontext.sc_ps = ALPHA_PSL_USERMODE;
    155   1.1       erh 	frametoreg(tf, (struct reg *)sigframe.uc.uc_mcontext.sc_regs);
    156   1.1       erh 	sigframe.uc.uc_mcontext.sc_regs[R_SP] = alpha_pal_rdusp();
    157   1.1       erh 
    158  1.48      matt 	fpu_load();
    159  1.48      matt 	alpha_pal_wrfen(1);
    160  1.16      ross 	sigframe.uc.uc_mcontext.sc_fpcr = alpha_read_fpcr();
    161  1.26   thorpej 	sigframe.uc.uc_mcontext.sc_fp_control = alpha_read_fp_c(l);
    162  1.16      ross 	alpha_pal_wrfen(0);
    163   1.1       erh 
    164   1.1       erh 	sigframe.uc.uc_mcontext.sc_traparg_a0 = tf->tf_regs[FRAME_A0];
    165   1.1       erh 	sigframe.uc.uc_mcontext.sc_traparg_a1 = tf->tf_regs[FRAME_A1];
    166   1.1       erh 	sigframe.uc.uc_mcontext.sc_traparg_a2 = tf->tf_regs[FRAME_A2];
    167  1.49  christos 	native_to_linux_siginfo(&sigframe.info, &ksi->ksi_info);
    168  1.36        ad 	sendsig_reset(l, sig);
    169  1.42        ad 	mutex_exit(p->p_lock);
    170  1.37  christos 	error = copyout((void *)&sigframe, (void *)sfp, fsize);
    171  1.42        ad 	mutex_enter(p->p_lock);
    172  1.36        ad 
    173  1.36        ad 	if (error != 0) {
    174   1.1       erh #ifdef DEBUG
    175   1.1       erh 		if ((sigdebug & SDB_KSTACK) && p->p_pid == sigpid)
    176   1.1       erh 			printf("sendsig(%d): copyout failed on sig %d\n",
    177   1.1       erh 			    p->p_pid, sig);
    178   1.1       erh #endif
    179   1.1       erh 		/*
    180   1.1       erh 		 * Process has trashed its stack; give it an illegal
    181   1.1       erh 		 * instruction to halt it in its tracks.
    182   1.1       erh 		 */
    183  1.26   thorpej 		sigexit(l, SIGILL);
    184   1.1       erh 		/* NOTREACHED */
    185   1.1       erh 	}
    186   1.1       erh 
    187   1.1       erh 	/* Pass pointers to siginfo and ucontext in the regs */
    188   1.1       erh 	tf->tf_regs[FRAME_A1] = (unsigned long)&sfp->info;
    189   1.1       erh 	tf->tf_regs[FRAME_A2] = (unsigned long)&sfp->uc;
    190   1.1       erh 
    191   1.1       erh 	/* Address of trampoline code.  End up at this PC after mi_switch */
    192   1.1       erh 	tf->tf_regs[FRAME_PC] =
    193  1.47     joerg 	    (u_int64_t)(p->p_psstrp - (linux_rt_esigcode - linux_rt_sigcode));
    194   1.1       erh 
    195   1.1       erh 	/* Adjust the stack */
    196   1.1       erh 	alpha_pal_wrusp((unsigned long)sfp);
    197   1.1       erh 
    198   1.1       erh 	/* Remember that we're now on the signal stack. */
    199   1.1       erh 	if (onstack)
    200  1.36        ad 		l->l_sigstk.ss_flags |= SS_ONSTACK;
    201   1.1       erh }
    202   1.1       erh 
    203  1.49  christos void setup_linux_sigframe(struct trapframe *tf, const ksiginfo_t *ksi,
    204  1.49  christos     const sigset_t *mask)
    205   1.1       erh {
    206  1.26   thorpej 	struct lwp *l = curlwp;
    207  1.26   thorpej 	struct proc *p = l->l_proc;
    208   1.1       erh 	struct linux_sigframe *sfp, sigframe;
    209  1.36        ad 	int onstack, error;
    210   1.1       erh 	int fsize, rndfsize;
    211  1.49  christos 	int sig = ksi->ksi_signo;
    212   1.1       erh 	extern char linux_sigcode[], linux_esigcode[];
    213   1.1       erh 
    214   1.1       erh 	/* Do we need to jump onto the signal stack? */
    215  1.36        ad 	onstack = (l->l_sigstk.ss_flags & (SS_DISABLE | SS_ONSTACK)) == 0 &&
    216  1.13  jdolecek 		  (SIGACTION(p, sig).sa_flags & SA_ONSTACK) != 0;
    217   1.1       erh 
    218   1.1       erh 	/* Allocate space for the signal handler context.  */
    219   1.1       erh 	fsize = sizeof(struct linux_sigframe);
    220   1.1       erh 	rndfsize = ((fsize + 15) / 16) * 16;
    221   1.1       erh 
    222   1.1       erh 	if (onstack)
    223   1.1       erh 		sfp = (struct linux_sigframe *)
    224  1.38      yamt 		    ((char *)l->l_sigstk.ss_sp + l->l_sigstk.ss_size);
    225   1.1       erh 	else
    226   1.1       erh 		sfp = (struct linux_sigframe *)(alpha_pal_rdusp());
    227  1.38      yamt 	sfp = (struct linux_sigframe *)((char *)sfp - rndfsize);
    228   1.1       erh 
    229   1.1       erh #ifdef DEBUG
    230  1.14  sommerfe 	if ((sigdebug & SDB_KSTACK) && (p->p_pid == sigpid))
    231   1.1       erh 		printf("linux_sendsig(%d): sig %d ssp %p usp %p\n", p->p_pid,
    232   1.1       erh 		    sig, &onstack, sfp);
    233   1.1       erh #endif /* DEBUG */
    234   1.1       erh 
    235   1.1       erh 	/*
    236   1.1       erh 	 * Build the signal context to be used by sigreturn.
    237   1.1       erh 	 */
    238  1.39     pooka 	memset(&sigframe.sf_sc, 0, sizeof(struct linux_sigcontext));
    239   1.1       erh 	sigframe.sf_sc.sc_onstack = onstack;
    240  1.20  christos 	native_to_linux_old_sigset(&sigframe.sf_sc.sc_mask, mask);
    241   1.1       erh 	sigframe.sf_sc.sc_pc = tf->tf_regs[FRAME_PC];
    242   1.1       erh 	sigframe.sf_sc.sc_ps = ALPHA_PSL_USERMODE;
    243   1.1       erh 	frametoreg(tf, (struct reg *)sigframe.sf_sc.sc_regs);
    244   1.1       erh 	sigframe.sf_sc.sc_regs[R_SP] = alpha_pal_rdusp();
    245   1.1       erh 
    246  1.51   thorpej 	if (fpu_valid_p(l)) {
    247  1.45     rmind 		struct pcb *pcb = lwp_getpcb(l);
    248  1.45     rmind 
    249  1.51   thorpej 		fpu_save(l);
    250  1.45     rmind 		sigframe.sf_sc.sc_fpcr = pcb->pcb_fp.fpr_cr;
    251   1.1       erh 	}
    252   1.1       erh 	/* XXX ownedfp ? etc...? */
    253   1.1       erh 
    254   1.1       erh 	sigframe.sf_sc.sc_traparg_a0 = tf->tf_regs[FRAME_A0];
    255   1.1       erh 	sigframe.sf_sc.sc_traparg_a1 = tf->tf_regs[FRAME_A1];
    256   1.1       erh 	sigframe.sf_sc.sc_traparg_a2 = tf->tf_regs[FRAME_A2];
    257   1.1       erh 
    258  1.36        ad 	sendsig_reset(l, sig);
    259  1.42        ad 	mutex_exit(p->p_lock);
    260  1.37  christos 	error = copyout((void *)&sigframe, (void *)sfp, fsize);
    261  1.42        ad 	mutex_enter(p->p_lock);
    262  1.36        ad 
    263  1.36        ad 	if (error != 0) {
    264   1.1       erh #ifdef DEBUG
    265   1.1       erh 		if ((sigdebug & SDB_KSTACK) && p->p_pid == sigpid)
    266   1.1       erh 			printf("sendsig(%d): copyout failed on sig %d\n",
    267   1.1       erh 			    p->p_pid, sig);
    268   1.1       erh #endif
    269   1.1       erh 		/*
    270   1.1       erh 		 * Process has trashed its stack; give it an illegal
    271   1.1       erh 		 * instruction to halt it in its tracks.
    272   1.1       erh 		 */
    273  1.26   thorpej 		sigexit(l, SIGILL);
    274   1.1       erh 		/* NOTREACHED */
    275   1.1       erh 	}
    276   1.1       erh 
    277   1.1       erh 	/* Pass pointers to sigcontext in the regs */
    278   1.1       erh 	tf->tf_regs[FRAME_A1] = 0;
    279   1.1       erh 	tf->tf_regs[FRAME_A2] = (unsigned long)&sfp->sf_sc;
    280   1.1       erh 
    281   1.1       erh 	/* Address of trampoline code.  End up at this PC after mi_switch */
    282   1.1       erh 	tf->tf_regs[FRAME_PC] =
    283  1.47     joerg 	    (u_int64_t)(p->p_psstrp - (linux_esigcode - linux_sigcode));
    284   1.1       erh 
    285   1.1       erh 	/* Adjust the stack */
    286   1.1       erh 	alpha_pal_wrusp((unsigned long)sfp);
    287   1.1       erh 
    288   1.1       erh 	/* Remember that we're now on the signal stack. */
    289   1.1       erh 	if (onstack)
    290  1.36        ad 		l->l_sigstk.ss_flags |= SS_ONSTACK;
    291   1.1       erh }
    292   1.1       erh 
    293   1.1       erh /*
    294   1.1       erh  * Send an interrupt to process.
    295   1.1       erh  *
    296   1.1       erh  * Stack is set up to allow sigcode stored
    297   1.1       erh  * in u. to call routine, followed by kcall
    298   1.1       erh  * to sigreturn routine below.  After sigreturn
    299   1.1       erh  * resets the signal mask, the stack, and the
    300   1.1       erh  * frame pointer, it returns to the user
    301   1.1       erh  * specified pc, psl.
    302   1.1       erh  */
    303   1.1       erh void
    304  1.30      matt linux_sendsig(const ksiginfo_t *ksi, const sigset_t *mask)
    305   1.1       erh {
    306  1.26   thorpej 	struct lwp *l = curlwp;
    307  1.26   thorpej 	struct proc *p = l->l_proc;
    308  1.26   thorpej 	struct trapframe *tf = l->l_md.md_tf;
    309  1.30      matt 	const int sig = ksi->ksi_signo;
    310  1.24   thorpej 	sig_t catcher = SIGACTION(p, sig).sa_handler;
    311  1.11  jdolecek #ifdef notyet
    312   1.3       erh 	struct linux_emuldata *edp;
    313   1.1       erh 
    314   1.1       erh 	/* Setup the signal frame (and part of the trapframe) */
    315   1.1       erh 	/*OLD: if (p->p_sigacts->ps_siginfo & sigmask(sig))*/
    316   1.3       erh /*	XXX XAX this is broken now.  need someplace to store what
    317   1.3       erh 	XXX XAX kind of signal handler a signal has.*/
    318   1.3       erh #if 0
    319   1.3       erh 	edp = (struct linux_emuldata *)p->p_emuldata;
    320   1.3       erh #else
    321   1.3       erh 	edp = 0;
    322   1.3       erh #endif
    323   1.3       erh 	if (edp && sigismember(&edp->ps_siginfo, sig))
    324  1.49  christos 		setup_linux_rt_sigframe(tf, ksi, mask);
    325   1.1       erh 	else
    326  1.11  jdolecek #endif /* notyet */
    327  1.49  christos 		setup_linux_sigframe(tf, ksi, mask);
    328   1.1       erh 
    329   1.1       erh 	/* Signal handler for trampoline code */
    330   1.1       erh 	tf->tf_regs[FRAME_T12] = (u_int64_t)catcher;
    331  1.23  christos 	tf->tf_regs[FRAME_A0] = native_to_linux_signo[sig];
    332   1.1       erh 
    333   1.1       erh 	/*
    334   1.1       erh 	 * Linux has a custom restorer option.  To support it we would
    335   1.1       erh 	 * need to store an array of restorers and a sigcode block
    336   1.1       erh 	 * which knew to use it.  Doesn't seem worth the trouble.
    337   1.1       erh 	 * -erh
    338   1.1       erh 	 */
    339   1.1       erh 
    340   1.1       erh #ifdef DEBUG
    341   1.1       erh 	if (sigdebug & SDB_FOLLOW)
    342  1.26   thorpej 		printf("sendsig(%d): pc %lx, catcher %lx\n", l->l_proc->p_pid,
    343   1.1       erh 		    tf->tf_regs[FRAME_PC], tf->tf_regs[FRAME_A3]);
    344  1.26   thorpej 	if ((sigdebug & SDB_KSTACK) && l->l_proc->p_pid == sigpid)
    345  1.26   thorpej 		printf("sendsig(%d): sig %d returns\n", l->l_proc->p_pid, sig);
    346   1.1       erh #endif
    347   1.1       erh }
    348   1.1       erh 
    349   1.1       erh /*
    350   1.1       erh  * System call to cleanup state after a signal
    351   1.1       erh  * has been taken.  Reset signal mask and
    352   1.1       erh  * stack state from context left by sendsig (above).
    353   1.1       erh  * Return to previous pc as specified by context
    354   1.1       erh  * left by sendsig.
    355   1.1       erh  * Linux real-time signals use a different sigframe,
    356   1.1       erh  * but the sigcontext is the same.
    357   1.1       erh  */
    358   1.1       erh 
    359   1.1       erh int
    360  1.26   thorpej linux_restore_sigcontext(struct lwp *l, struct linux_sigcontext context,
    361   1.8       erh 			 sigset_t *mask)
    362   1.1       erh {
    363  1.36        ad 	struct proc *p = l->l_proc;
    364  1.45     rmind 	struct pcb *pcb;
    365   1.1       erh 
    366   1.1       erh 	/*
    367   1.1       erh 	 * Linux doesn't (yet) have alternate signal stacks.
    368   1.1       erh 	 * However, the OSF/1 sigcontext which they use has
    369   1.1       erh 	 * an onstack member.  This could be needed in the future.
    370   1.1       erh 	 */
    371  1.42        ad 	mutex_enter(p->p_lock);
    372   1.1       erh 	if (context.sc_onstack & LINUX_SA_ONSTACK)
    373  1.36        ad 	    l->l_sigstk.ss_flags |= SS_ONSTACK;
    374   1.1       erh 	else
    375  1.36        ad 	    l->l_sigstk.ss_flags &= ~SS_ONSTACK;
    376   1.1       erh 
    377   1.1       erh 	/* Reset the signal mask */
    378  1.36        ad 	(void) sigprocmask1(l, SIG_SETMASK, mask, 0);
    379  1.42        ad 	mutex_exit(p->p_lock);
    380   1.1       erh 
    381   1.1       erh 	/*
    382   1.1       erh 	 * Check for security violations.
    383   1.1       erh 	 * Linux doesn't allow any changes to the PSL.
    384   1.1       erh 	 */
    385   1.1       erh 	if (context.sc_ps != ALPHA_PSL_USERMODE)
    386   1.1       erh 	    return(EINVAL);
    387   1.1       erh 
    388  1.26   thorpej 	l->l_md.md_tf->tf_regs[FRAME_PC] = context.sc_pc;
    389  1.26   thorpej 	l->l_md.md_tf->tf_regs[FRAME_PS] = context.sc_ps;
    390   1.1       erh 
    391  1.26   thorpej 	regtoframe((struct reg *)context.sc_regs, l->l_md.md_tf);
    392   1.1       erh 	alpha_pal_wrusp(context.sc_regs[R_SP]);
    393   1.1       erh 
    394   1.1       erh 	/* Restore fp regs and fpr_cr */
    395  1.45     rmind 	pcb = lwp_getpcb(l);
    396  1.45     rmind 	memcpy(&pcb->pcb_fp, (struct fpreg *)context.sc_fpregs,
    397   1.1       erh 	    sizeof(struct fpreg));
    398   1.1       erh 	/* XXX sc_ownedfp ? */
    399   1.1       erh 	/* XXX sc_fp_control ? */
    400   1.1       erh 
    401   1.1       erh #ifdef DEBUG
    402   1.1       erh 	if (sigdebug & SDB_FOLLOW)
    403  1.14  sommerfe 		printf("linux_rt_sigreturn(%d): returns\n", p->p_pid);
    404   1.1       erh #endif
    405   1.1       erh 	return (EJUSTRETURN);
    406   1.1       erh }
    407   1.1       erh 
    408   1.1       erh int
    409  1.41       dsl linux_sys_rt_sigreturn(struct lwp *l, const struct linux_sys_rt_sigreturn_args *uap, register_t *retval)
    410   1.1       erh {
    411  1.41       dsl 	/* {
    412   1.1       erh 		syscallarg(struct linux_rt_sigframe *) sfp;
    413  1.41       dsl 	} */
    414   1.1       erh 	struct linux_rt_sigframe *sfp, sigframe;
    415   1.8       erh 	sigset_t mask;
    416   1.1       erh 
    417   1.1       erh 	/*
    418   1.1       erh 	 * The trampoline code hands us the context.
    419   1.1       erh 	 * It is unsafe to keep track of it ourselves, in the event that a
    420   1.1       erh 	 * program jumps out of a signal handler.
    421   1.1       erh 	 */
    422   1.1       erh 
    423   1.1       erh 	sfp = SCARG(uap, sfp);
    424   1.1       erh 
    425   1.1       erh 	if (ALIGN(sfp) != (u_int64_t)sfp)
    426   1.1       erh 		return(EINVAL);
    427   1.1       erh 
    428   1.1       erh 	/*
    429   1.1       erh 	 * Fetch the frame structure.
    430   1.1       erh 	 */
    431  1.37  christos 	if (copyin((void *)sfp, &sigframe,
    432   1.1       erh 			sizeof(struct linux_rt_sigframe)) != 0)
    433   1.1       erh 		return (EFAULT);
    434   1.1       erh 
    435   1.8       erh 	/* Grab the signal mask */
    436  1.21  christos 	linux_to_native_sigset(&mask, &sigframe.uc.uc_sigmask);
    437   1.8       erh 
    438  1.26   thorpej 	return(linux_restore_sigcontext(l, sigframe.uc.uc_mcontext, &mask));
    439   1.1       erh }
    440   1.1       erh 
    441   1.1       erh 
    442   1.1       erh int
    443  1.41       dsl linux_sys_sigreturn(struct lwp *l, const struct linux_sys_sigreturn_args *uap, register_t *retval)
    444   1.1       erh {
    445  1.41       dsl 	/* {
    446   1.1       erh 		syscallarg(struct linux_sigframe *) sfp;
    447  1.41       dsl 	} */
    448   1.8       erh 	struct linux_sigframe *sfp, frame;
    449   1.8       erh 	sigset_t mask;
    450   1.1       erh 
    451   1.1       erh 	/*
    452   1.1       erh 	 * The trampoline code hands us the context.
    453   1.1       erh 	 * It is unsafe to keep track of it ourselves, in the event that a
    454   1.1       erh 	 * program jumps out of a signal handler.
    455   1.1       erh 	 */
    456   1.1       erh 
    457   1.8       erh 	sfp = SCARG(uap, sfp);
    458   1.8       erh 	if (ALIGN(sfp) != (u_int64_t)sfp)
    459   1.1       erh 		return(EINVAL);
    460   1.1       erh 
    461   1.1       erh 	/*
    462   1.8       erh 	 * Fetch the frame structure.
    463   1.1       erh 	 */
    464  1.37  christos 	if (copyin((void *)sfp, &frame, sizeof(struct linux_sigframe)) != 0)
    465   1.8       erh 		return(EFAULT);
    466   1.8       erh 
    467   1.8       erh 	/* Grab the signal mask. */
    468   1.8       erh 	/* XXX use frame.extramask */
    469  1.21  christos 	linux_old_to_native_sigset(&mask, frame.sf_sc.sc_mask);
    470   1.1       erh 
    471  1.26   thorpej 	return(linux_restore_sigcontext(l, frame.sf_sc, &mask));
    472   1.1       erh }
    473   1.1       erh 
    474   1.1       erh /*
    475   1.1       erh  * We come here in a last attempt to satisfy a Linux ioctl() call
    476   1.1       erh  */
    477   1.1       erh /* XXX XAX update this, add maps, etc... */
    478   1.1       erh int
    479  1.41       dsl linux_machdepioctl(struct lwp *l, const struct linux_sys_ioctl_args *uap, register_t *retval)
    480   1.1       erh {
    481  1.41       dsl 	/* {
    482   1.1       erh 		syscallarg(int) fd;
    483   1.1       erh 		syscallarg(u_long) com;
    484  1.37  christos 		syscallarg(void *) data;
    485  1.41       dsl 	} */
    486   1.1       erh 	struct sys_ioctl_args bia;
    487   1.1       erh 	u_long com;
    488   1.1       erh 
    489   1.1       erh 	SCARG(&bia, fd) = SCARG(uap, fd);
    490   1.1       erh 	SCARG(&bia, data) = SCARG(uap, data);
    491   1.1       erh 	com = SCARG(uap, com);
    492   1.1       erh 
    493   1.1       erh 	switch (com) {
    494   1.1       erh 	default:
    495   1.1       erh 		printf("linux_machdepioctl: invalid ioctl %08lx\n", com);
    496   1.1       erh 		return EINVAL;
    497   1.1       erh 	}
    498   1.1       erh 	SCARG(&bia, com) = com;
    499  1.32  christos 	return sys_ioctl(l, &bia, retval);
    500   1.1       erh }
    501   1.1       erh 
    502   1.1       erh /* XXX XAX fix this */
    503   1.1       erh dev_t
    504  1.40       dsl linux_fakedev(dev_t dev, int raw)
    505   1.1       erh {
    506   1.1       erh 	return dev;
    507   1.1       erh }
    508   1.1       erh 
    509  1.31      fvdl int
    510  1.31      fvdl linux_usertrap(struct lwp *l, vaddr_t trapaddr, void *arg)
    511  1.31      fvdl {
    512  1.31      fvdl 	return 0;
    513  1.31      fvdl }
    514