Expand PMF_FN_* macros.
[netbsd-mini2440.git] / sys / arch / m68k / m68k / compat_13_machdep.c
blob68cba6196d6254178529b6e5ca629513f39fb08c
1 /* $NetBSD: compat_13_machdep.c,v 1.13 2008/04/24 18:39:20 ad Exp $ */
3 /*
4 * Copyright (c) 1982, 1986, 1990, 1993
5 * The Regents of the University of California. All rights reserved.
7 * This code is derived from software contributed to Berkeley by
8 * the Systems Programming Group of the University of Utah Computer
9 * Science Department.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
19 * 3. Neither the name of the University nor the names of its contributors
20 * may be used to endorse or promote products derived from this software
21 * without specific prior written permission.
23 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 * SUCH DAMAGE.
35 * from: Utah Hdr: machdep.c 1.74 92/12/20
36 * from: @(#)machdep.c 8.10 (Berkeley) 4/20/94
39 * Copyright (c) 1988 University of Utah.
41 * This code is derived from software contributed to Berkeley by
42 * the Systems Programming Group of the University of Utah Computer
43 * Science Department.
45 * Redistribution and use in source and binary forms, with or without
46 * modification, are permitted provided that the following conditions
47 * are met:
48 * 1. Redistributions of source code must retain the above copyright
49 * notice, this list of conditions and the following disclaimer.
50 * 2. Redistributions in binary form must reproduce the above copyright
51 * notice, this list of conditions and the following disclaimer in the
52 * documentation and/or other materials provided with the distribution.
53 * 3. All advertising materials mentioning features or use of this software
54 * must display the following acknowledgement:
55 * This product includes software developed by the University of
56 * California, Berkeley and its contributors.
57 * 4. Neither the name of the University nor the names of its contributors
58 * may be used to endorse or promote products derived from this software
59 * without specific prior written permission.
61 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
62 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
63 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
64 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
65 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
66 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
67 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
68 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
69 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
70 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
71 * SUCH DAMAGE.
73 * from: Utah Hdr: machdep.c 1.74 92/12/20
74 * from: @(#)machdep.c 8.10 (Berkeley) 4/20/94
77 #include <sys/cdefs.h>
78 __KERNEL_RCSID(0, "$NetBSD: compat_13_machdep.c,v 1.13 2008/04/24 18:39:20 ad Exp $");
80 #include <sys/param.h>
81 #include <sys/systm.h>
82 #include <sys/kernel.h>
83 #include <sys/proc.h>
84 #include <sys/signal.h>
85 #include <sys/signalvar.h>
87 #include <sys/mount.h>
88 #include <sys/syscallargs.h>
90 #include <compat/sys/signal.h>
91 #include <compat/sys/signalvar.h>
93 #include <machine/cpu.h>
94 #include <machine/reg.h>
97 * System call to cleanup state after a signal
98 * has been taken. Reset signal mask and
99 * stack state from context left by sendsig (above).
100 * Return to previous pc and psl as specified by
101 * context left by sendsig. Check carefully to
102 * make sure that the user has not modified the
103 * psl to gain improper privileges or to cause
104 * a machine fault.
107 compat_13_sys_sigreturn(struct lwp *l, const struct compat_13_sys_sigreturn_args *uap, register_t *retval)
109 /* {
110 syscallarg(struct sigcontext13 *) sigcntxp;
111 } */
112 struct proc *p = l->l_proc;
113 struct sigcontext13 *scp;
114 struct frame *frame;
115 struct sigcontext13 tsigc;
116 sigset_t mask;
119 * The trampoline code hands us the context.
120 * It is unsafe to keep track of it ourselves, in the event that a
121 * program jumps out of a signal handler.
123 scp = SCARG(uap, sigcntxp);
124 if ((int)scp & 1)
125 return EINVAL;
127 if (copyin(scp, &tsigc, sizeof(tsigc)) != 0)
128 return EFAULT;
129 scp = &tsigc;
131 /* Make sure the user isn't pulling a fast one on us! */
132 if ((scp->sc_ps & (PSL_MBZ|PSL_IPL|PSL_S)) != 0)
133 return EINVAL;
135 /* Restore register context. */
136 frame = (struct frame *)l->l_md.md_regs;
139 * We only support restoring the sigcontext13 in this call.
140 * We are not called from the sigcode (per sendsig()), so
141 * we will not have a sigstate to restore.
143 if (scp->sc_ap != 0)
144 return EINVAL;
147 * Restore the user supplied information.
148 * This should be at the last so that the error (EINVAL)
149 * is reported to the sigreturn caller, not to the
150 * jump destination.
153 frame->f_regs[SP] = scp->sc_sp;
154 frame->f_regs[A6] = scp->sc_fp;
155 frame->f_pc = scp->sc_pc;
156 frame->f_sr = scp->sc_ps;
158 mutex_enter(p->p_lock);
160 /* Restore signal stack. */
161 if (scp->sc_onstack & SS_ONSTACK)
162 l->l_sigstk.ss_flags |= SS_ONSTACK;
163 else
164 l->l_sigstk.ss_flags &= ~SS_ONSTACK;
166 /* Restore signal mask. */
167 native_sigset13_to_sigset(&scp->sc_mask, &mask);
168 (void)sigprocmask1(l, SIG_SETMASK, &mask, 0);
170 mutex_exit(p->p_lock);
172 return EJUSTRETURN;