1 /* $NetBSD: compat_13_machdep.c,v 1.22 2017/03/16 16:13:20 chs Exp $ */
2
3 /*
4 * Copyright (c) 1994, 1995, 1996 Carnegie-Mellon University.
5 * All rights reserved.
6 *
7 * Author: Chris G. Demetriou
8 *
9 * Permission to use, copy, modify and distribute this software and
10 * its documentation is hereby granted, provided that both the copyright
11 * notice and this permission notice appear in all copies of the
12 * software, derivative works or modified versions, and any portions
13 * thereof, and that both notices appear in supporting documentation.
14 *
15 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
16 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
17 * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
18 *
19 * Carnegie Mellon requests users of this software to return to
20 *
21 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
22 * School of Computer Science
23 * Carnegie Mellon University
24 * Pittsburgh PA 15213-3890
25 *
26 * any improvements or extensions that they make and grant Carnegie the
27 * rights to redistribute these changes.
28 */
29
30 #include <sys/cdefs.h> /* RCS ID & Copyright macro defns */
31
32 __KERNEL_RCSID(0, "$NetBSD: compat_13_machdep.c,v 1.22 2017/03/16 16:13:20 chs Exp $");
33
34 #include <sys/param.h>
35 #include <sys/systm.h>
36 #include <sys/signalvar.h>
37 #include <sys/kernel.h>
38 #include <sys/proc.h>
39 #include <sys/mount.h>
40 #include <sys/syscallargs.h>
41
42 #include <compat/sys/signal.h>
43 #include <compat/sys/signalvar.h>
44
45 #include <machine/cpu.h>
46 #include <machine/reg.h>
47 #include <machine/alpha.h>
48
49 /*
50 * System call to cleanup state after a signal
51 * has been taken. Reset signal mask and
52 * stack state from context left by sendsig (above).
53 * Return to previous pc and psl as specified by
54 * context left by sendsig. Check carefully to
55 * make sure that the user has not modified the
56 * psl to gain improper privileges or to cause
57 * a machine fault.
58 */
59 /* ARGSUSED */
60 int
compat_13_sys_sigreturn(struct lwp * l,const struct compat_13_sys_sigreturn_args * uap,register_t * retval)61 compat_13_sys_sigreturn(struct lwp *l, const struct compat_13_sys_sigreturn_args *uap, register_t *retval)
62 {
63 /* {
64 syscallarg(struct sigcontext13 *) sigcntxp;
65 } */
66 struct sigcontext13 *scp, ksc;
67 struct proc *p = l->l_proc;
68 struct pcb *pcb;
69 sigset13_t mask13;
70 sigset_t mask;
71
72 /*
73 * The trampoline code hands us the context.
74 * It is unsafe to keep track of it ourselves, in the event that a
75 * program jumps out of a signal handler.
76 */
77 scp = SCARG(uap, sigcntxp);
78 if (ALIGN(scp) != (uint64_t)scp)
79 return (EINVAL);
80
81 if (copyin((void *)scp, &ksc, sizeof(ksc)) != 0)
82 return (EFAULT);
83
84 if (ksc.sc_regs[R_ZERO] != 0xACEDBADE) /* magic number */
85 return (EINVAL);
86
87 /* Restore register context. */
88 l->l_md.md_tf->tf_regs[FRAME_PC] = ksc.sc_pc;
89 l->l_md.md_tf->tf_regs[FRAME_PS] =
90 (ksc.sc_ps | ALPHA_PSL_USERSET) & ~ALPHA_PSL_USERCLR;
91
92 regtoframe((struct reg *)ksc.sc_regs, l->l_md.md_tf);
93 alpha_pal_wrusp(ksc.sc_regs[R_SP]);
94
95 /* XXX ksc.sc_ownedfp ? */
96 pcb = lwp_getpcb(l);
97 fpu_discard(l, true);
98 memcpy(&pcb->pcb_fp, (struct fpreg *)ksc.sc_fpregs,
99 sizeof(struct fpreg));
100 /* XXX ksc.sc_fp_control ? */
101
102 mutex_enter(p->p_lock);
103 /* Restore signal stack. */
104 if (ksc.sc_onstack & SS_ONSTACK)
105 l->l_sigstk.ss_flags |= SS_ONSTACK;
106 else
107 l->l_sigstk.ss_flags &= ~SS_ONSTACK;
108 /*
109 * Restore signal mask. Note the mask is a "long" in the stack
110 * frame.
111 */
112 mask13 = ksc.sc_mask;
113 native_sigset13_to_sigset(&mask13, &mask);
114 (void) sigprocmask1(l, SIG_SETMASK, &mask, 0);
115 mutex_exit(p->p_lock);
116
117 return (EJUSTRETURN);
118 }
119