linux_machdep.c revision 1.5.2.3 1 1.5.2.3 bouyer /* $NetBSD: linux_machdep.c,v 1.5.2.3 2001/03/27 15:31:46 bouyer Exp $ */
2 1.5.2.2 bouyer
3 1.5.2.2 bouyer /*-
4 1.5.2.2 bouyer * Copyright (c) 1995, 2000, 2001 The NetBSD Foundation, Inc.
5 1.5.2.2 bouyer * All rights reserved.
6 1.5.2.2 bouyer *
7 1.5.2.2 bouyer * This code is derived from software contributed to The NetBSD Foundation
8 1.5.2.2 bouyer * by Frank van der Linden and Emmanuel Dreyfus.
9 1.5.2.2 bouyer *
10 1.5.2.2 bouyer * Redistribution and use in source and binary forms, with or without
11 1.5.2.2 bouyer * modification, are permitted provided that the following conditions
12 1.5.2.2 bouyer * are met:
13 1.5.2.2 bouyer * 1. Redistributions of source code must retain the above copyright
14 1.5.2.2 bouyer * notice, this list of conditions and the following disclaimer.
15 1.5.2.2 bouyer * 2. Redistributions in binary form must reproduce the above copyright
16 1.5.2.2 bouyer * notice, this list of conditions and the following disclaimer in the
17 1.5.2.2 bouyer * documentation and/or other materials provided with the distribution.
18 1.5.2.2 bouyer * 3. All advertising materials mentioning features or use of this software
19 1.5.2.2 bouyer * must display the following acknowledgement:
20 1.5.2.2 bouyer * This product includes software developed by the NetBSD
21 1.5.2.2 bouyer * Foundation, Inc. and its contributors.
22 1.5.2.2 bouyer * 4. Neither the name of The NetBSD Foundation nor the names of its
23 1.5.2.2 bouyer * contributors may be used to endorse or promote products derived
24 1.5.2.2 bouyer * from this software without specific prior written permission.
25 1.5.2.2 bouyer *
26 1.5.2.2 bouyer * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 1.5.2.2 bouyer * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 1.5.2.2 bouyer * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 1.5.2.2 bouyer * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 1.5.2.2 bouyer * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 1.5.2.2 bouyer * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 1.5.2.2 bouyer * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 1.5.2.2 bouyer * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 1.5.2.2 bouyer * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 1.5.2.2 bouyer * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 1.5.2.2 bouyer * POSSIBILITY OF SUCH DAMAGE.
37 1.5.2.2 bouyer */
38 1.5.2.2 bouyer
39 1.5.2.2 bouyer #include <sys/param.h>
40 1.5.2.2 bouyer #include <sys/systm.h>
41 1.5.2.2 bouyer #include <sys/signalvar.h>
42 1.5.2.2 bouyer #include <sys/kernel.h>
43 1.5.2.2 bouyer #include <sys/map.h>
44 1.5.2.2 bouyer #include <sys/proc.h>
45 1.5.2.2 bouyer #include <sys/user.h>
46 1.5.2.2 bouyer #include <sys/buf.h>
47 1.5.2.2 bouyer #include <sys/reboot.h>
48 1.5.2.2 bouyer #include <sys/conf.h>
49 1.5.2.2 bouyer #include <sys/exec.h>
50 1.5.2.2 bouyer #include <sys/file.h>
51 1.5.2.2 bouyer #include <sys/callout.h>
52 1.5.2.2 bouyer #include <sys/malloc.h>
53 1.5.2.2 bouyer #include <sys/mbuf.h>
54 1.5.2.2 bouyer #include <sys/msgbuf.h>
55 1.5.2.2 bouyer #include <sys/mount.h>
56 1.5.2.2 bouyer #include <sys/vnode.h>
57 1.5.2.2 bouyer #include <sys/device.h>
58 1.5.2.2 bouyer #include <sys/syscallargs.h>
59 1.5.2.2 bouyer #include <sys/filedesc.h>
60 1.5.2.2 bouyer #include <sys/exec_elf.h>
61 1.5.2.2 bouyer #include <sys/disklabel.h>
62 1.5.2.2 bouyer #include <sys/ioctl.h>
63 1.5.2.2 bouyer #include <miscfs/specfs/specdev.h>
64 1.5.2.2 bouyer
65 1.5.2.2 bouyer #include <compat/linux/common/linux_types.h>
66 1.5.2.2 bouyer #include <compat/linux/common/linux_signal.h>
67 1.5.2.2 bouyer #include <compat/linux/common/linux_util.h>
68 1.5.2.2 bouyer #include <compat/linux/common/linux_ioctl.h>
69 1.5.2.2 bouyer #include <compat/linux/common/linux_hdio.h>
70 1.5.2.2 bouyer #include <compat/linux/common/linux_exec.h>
71 1.5.2.2 bouyer #include <compat/linux/common/linux_machdep.h>
72 1.5.2.2 bouyer
73 1.5.2.2 bouyer #include <compat/linux/linux_syscallargs.h>
74 1.5.2.2 bouyer
75 1.5.2.2 bouyer #include <machine/cpu.h>
76 1.5.2.2 bouyer #include <machine/psl.h>
77 1.5.2.2 bouyer #include <machine/reg.h>
78 1.5.2.2 bouyer #include <machine/vmparam.h>
79 1.5.2.2 bouyer
80 1.5.2.2 bouyer /*
81 1.5.2.2 bouyer * To see whether wscons is configured (for virtual console ioctl calls).
82 1.5.2.2 bouyer */
83 1.5.2.2 bouyer #if defined(_KERNEL) && !defined(_LKM)
84 1.5.2.2 bouyer #include "wsdisplay.h"
85 1.5.2.2 bouyer #endif
86 1.5.2.2 bouyer #if (NWSDISPLAY > 0)
87 1.5.2.2 bouyer #include <dev/wscons/wsconsio.h>
88 1.5.2.2 bouyer #include <dev/wscons/wsdisplay_usl_io.h>
89 1.5.2.2 bouyer #if defined(_KERNEL) && !defined(_LKM)
90 1.5.2.2 bouyer #endif
91 1.5.2.2 bouyer #endif
92 1.5.2.2 bouyer
93 1.5.2.2 bouyer /*
94 1.5.2.2 bouyer * Set set up registers on exec.
95 1.5.2.2 bouyer * XXX not used at the moment since in sys/kern/exec_conf, LINUX_COMPAT
96 1.5.2.2 bouyer * entry uses NetBSD's native setregs instead of linux_setregs
97 1.5.2.2 bouyer */
98 1.5.2.2 bouyer void
99 1.5.2.2 bouyer linux_setregs(p, pack, stack)
100 1.5.2.2 bouyer struct proc *p;
101 1.5.2.2 bouyer struct exec_package *pack;
102 1.5.2.2 bouyer u_long stack;
103 1.5.2.2 bouyer {
104 1.5.2.2 bouyer setregs(p, pack, stack);
105 1.5.2.2 bouyer }
106 1.5.2.2 bouyer
107 1.5.2.2 bouyer /*
108 1.5.2.2 bouyer * Send an interrupt to process.
109 1.5.2.2 bouyer *
110 1.5.2.2 bouyer * Adapted from arch/powerpc/powerpc/sig_machdep.c:sendsig and
111 1.5.2.2 bouyer * compat/linux/arch/i386/linux_machdep.c:linux_sendsig
112 1.5.2.2 bouyer *
113 1.5.2.3 bouyer * XXX Does not work well yet with RT signals
114 1.5.2.2 bouyer *
115 1.5.2.2 bouyer */
116 1.5.2.2 bouyer
117 1.5.2.2 bouyer void
118 1.5.2.2 bouyer linux_sendsig(catcher, sig, mask, code) /* XXX Check me */
119 1.5.2.2 bouyer sig_t catcher;
120 1.5.2.2 bouyer int sig;
121 1.5.2.2 bouyer sigset_t *mask;
122 1.5.2.2 bouyer u_long code;
123 1.5.2.2 bouyer {
124 1.5.2.2 bouyer struct proc *p = curproc;
125 1.5.2.2 bouyer struct trapframe *tf;
126 1.5.2.2 bouyer struct linux_sigregs *fp, frame;
127 1.5.2.2 bouyer struct linux_pt_regs linux_regs;
128 1.5.2.2 bouyer struct linux_sigcontext sc;
129 1.5.2.2 bouyer int onstack;
130 1.5.2.2 bouyer int i;
131 1.5.2.2 bouyer
132 1.5.2.2 bouyer tf = trapframe(p);
133 1.5.2.2 bouyer
134 1.5.2.2 bouyer /*
135 1.5.2.2 bouyer * Do we need to jump onto the signal stack?
136 1.5.2.2 bouyer */
137 1.5.2.2 bouyer onstack =
138 1.5.2.2 bouyer (p->p_sigctx.ps_sigstk.ss_flags & (SS_DISABLE | SS_ONSTACK)) == 0 &&
139 1.5.2.2 bouyer (SIGACTION(p, sig).sa_flags & SA_ONSTACK) != 0;
140 1.5.2.2 bouyer
141 1.5.2.2 bouyer /*
142 1.5.2.2 bouyer * Signal stack is broken (see at the end of linux_sigreturn), so we do
143 1.5.2.2 bouyer * not use it yet. XXX fix this.
144 1.5.2.2 bouyer */
145 1.5.2.2 bouyer onstack=0;
146 1.5.2.2 bouyer
147 1.5.2.2 bouyer /*
148 1.5.2.2 bouyer * Allocate space for the signal handler context.
149 1.5.2.2 bouyer */
150 1.5.2.2 bouyer if (onstack) {
151 1.5.2.2 bouyer fp = (struct linux_sigregs *)
152 1.5.2.2 bouyer ((caddr_t)p->p_sigctx.ps_sigstk.ss_sp +
153 1.5.2.2 bouyer p->p_sigctx.ps_sigstk.ss_size);
154 1.5.2.2 bouyer } else {
155 1.5.2.2 bouyer fp = (struct linux_sigregs *)tf->fixreg[1];
156 1.5.2.2 bouyer }
157 1.5.2.2 bouyer fp = (struct linux_sigregs *)((int)(fp - 1) & ~0xf);
158 1.5.2.2 bouyer
159 1.5.2.2 bouyer /*
160 1.5.2.2 bouyer * Prepare a sigcontext for later.
161 1.5.2.2 bouyer */
162 1.5.2.2 bouyer sc.lsignal = (int)native_to_linux_sig[sig];
163 1.5.2.2 bouyer sc.lhandler = (unsigned long)catcher;
164 1.5.2.2 bouyer native_to_linux_old_sigset(mask, &sc.lmask);
165 1.5.2.2 bouyer sc.lregs = (struct linux_pt_regs*)fp;
166 1.5.2.2 bouyer
167 1.5.2.2 bouyer /*
168 1.5.2.2 bouyer * Setup the signal stack frame as Linux does it in
169 1.5.2.2 bouyer * arch/ppc/kernel/signal.c:setup_frame()
170 1.5.2.2 bouyer *
171 1.5.2.2 bouyer * Save register context.
172 1.5.2.2 bouyer */
173 1.5.2.2 bouyer for (i = 0; i < 32; i++)
174 1.5.2.2 bouyer linux_regs.lgpr[i] = tf->fixreg[i];
175 1.5.2.2 bouyer linux_regs.lnip = tf->srr0;
176 1.5.2.2 bouyer linux_regs.lmsr = tf->srr1;
177 1.5.2.2 bouyer linux_regs.lorig_gpr3 = tf->fixreg[3]; /* XXX Is that right? */
178 1.5.2.2 bouyer linux_regs.lctr = tf->ctr;
179 1.5.2.2 bouyer linux_regs.llink = tf->lr;
180 1.5.2.2 bouyer linux_regs.lxer = tf->xer;
181 1.5.2.2 bouyer linux_regs.lccr = tf->cr;
182 1.5.2.2 bouyer linux_regs.lmq = 0; /* Unused, 601 only */
183 1.5.2.2 bouyer linux_regs.ltrap = 0; /* XXX What is ltrap counterpart in NetBSD ? */
184 1.5.2.2 bouyer linux_regs.ldar = tf->dar;
185 1.5.2.2 bouyer linux_regs.ldsisr = tf->dsisr;
186 1.5.2.2 bouyer linux_regs.lresult = tf->exc;
187 1.5.2.2 bouyer memcpy(&frame.lgp_regs, &linux_regs, sizeof(frame.lgp_regs));
188 1.5.2.2 bouyer
189 1.5.2.2 bouyer /*
190 1.5.2.2 bouyer * NetBSD does not uses the FPU in the kernel, so there is no
191 1.5.2.2 bouyer * need to save floating point register. However, Linux expects
192 1.5.2.2 bouyer * them to be saved on the stack. Therefore we just keep a
193 1.5.2.2 bouyer * gap of zero'ed data where the FP registers should be stored
194 1.5.2.2 bouyer */
195 1.5.2.2 bouyer memset(&frame.lfp_regs, 0, sizeof (frame.lfp_regs));
196 1.5.2.2 bouyer
197 1.5.2.2 bouyer /*
198 1.5.2.2 bouyer * Copy Linux's signal trampoline on the user stack It should not
199 1.5.2.3 bouyer * be used, but Linux binaries might expect it to be there.
200 1.5.2.2 bouyer */
201 1.5.2.2 bouyer frame.ltramp[0] = 0x38997777; /* li r0, 0x7777 */
202 1.5.2.2 bouyer frame.ltramp[1] = 0x44000002; /* sc */
203 1.5.2.2 bouyer
204 1.5.2.2 bouyer /*
205 1.5.2.2 bouyer * Move it to the user stack
206 1.5.2.2 bouyer * There is a little trick here, about the LINUX_ABIGAP: the
207 1.5.2.2 bouyer * linux_sigreg structure has a 56 int gap to support rs6000/xcoff
208 1.5.2.2 bouyer * binaries. But the Linux kernel seems to do without it, and it
209 1.5.2.2 bouyer * just skip it when building the stack frame. Hence the LINUX_ABIGAP.
210 1.5.2.2 bouyer */
211 1.5.2.2 bouyer if (copyout(&frame, fp, sizeof (frame) - LINUX_ABIGAP) != 0) {
212 1.5.2.2 bouyer /*
213 1.5.2.2 bouyer * Process has trashed its stack; give it an illegal
214 1.5.2.2 bouyer * instructoin to halt it in its tracks.
215 1.5.2.2 bouyer */
216 1.5.2.2 bouyer sigexit(p, SIGILL);
217 1.5.2.2 bouyer /* NOTREACHED */
218 1.5.2.2 bouyer }
219 1.5.2.2 bouyer
220 1.5.2.2 bouyer /*
221 1.5.2.2 bouyer * adjust stack pointer after the previous data copy
222 1.5.2.2 bouyer */
223 1.5.2.2 bouyer fp = (struct linux_sigregs *)
224 1.5.2.2 bouyer ((unsigned long)fp - (sizeof (frame) - LINUX_ABIGAP));
225 1.5.2.2 bouyer
226 1.5.2.2 bouyer /*
227 1.5.2.2 bouyer * "Mind the gap" Linux expects a gap here.
228 1.5.2.2 bouyer */
229 1.5.2.2 bouyer fp = (struct linux_sigregs *)
230 1.5.2.2 bouyer ((unsigned long)fp - LINUX__SIGNAL_FRAMESIZE);
231 1.5.2.2 bouyer
232 1.5.2.2 bouyer /*
233 1.5.2.2 bouyer * Add a sigcontext on the stack
234 1.5.2.2 bouyer */
235 1.5.2.2 bouyer if (copyout(&sc, fp, sizeof (struct linux_sigcontext)) != 0) {
236 1.5.2.2 bouyer /*
237 1.5.2.2 bouyer * Process has trashed its stack; give it an illegal
238 1.5.2.2 bouyer * instructoin to halt it in its tracks.
239 1.5.2.2 bouyer */
240 1.5.2.2 bouyer sigexit(p, SIGILL);
241 1.5.2.2 bouyer /* NOTREACHED */
242 1.5.2.2 bouyer }
243 1.5.2.2 bouyer
244 1.5.2.2 bouyer /*
245 1.5.2.2 bouyer * Here, I expected to need a stack pointer adjust after the copy.
246 1.5.2.2 bouyer * Something like this: (unsigned long)fp-=sizeof(struct sigcontext)
247 1.5.2.2 bouyer * But if we do it, the signal handler does not get its arguments as
248 1.5.2.2 bouyer * expected.
249 1.5.2.2 bouyer */
250 1.5.2.2 bouyer
251 1.5.2.2 bouyer /*
252 1.5.2.2 bouyer * Set the registers according to how the Linux process expects them
253 1.5.2.2 bouyer */
254 1.5.2.2 bouyer tf->fixreg[1] = (int)fp;
255 1.5.2.2 bouyer tf->lr = (int)catcher;
256 1.5.2.3 bouyer tf->fixreg[3] = (int)native_to_linux_sig[sig];
257 1.5.2.2 bouyer tf->fixreg[4] = (int)&fp->lgp_regs;
258 1.5.2.2 bouyer tf->srr0 = (int)p->p_sigctx.ps_sigcode;
259 1.5.2.2 bouyer
260 1.5.2.2 bouyer /*
261 1.5.2.2 bouyer * Remember that we're now on the signal stack.
262 1.5.2.2 bouyer */
263 1.5.2.2 bouyer if (onstack)
264 1.5.2.2 bouyer p->p_sigctx.ps_sigstk.ss_flags |= SS_ONSTACK;
265 1.5.2.2 bouyer #ifdef DEBUG_LINUX
266 1.5.2.2 bouyer printf("linux_sendsig: exitting. fp=0x%lx\n",(long)fp);
267 1.5.2.2 bouyer #endif
268 1.5.2.2 bouyer }
269 1.5.2.2 bouyer
270 1.5.2.2 bouyer /*
271 1.5.2.2 bouyer * System call to cleanup state after a signal
272 1.5.2.2 bouyer * has been taken. Reset signal mask and
273 1.5.2.2 bouyer * stack state from context left by sendsig (above).
274 1.5.2.2 bouyer * Return to previous pc and psl as specified by
275 1.5.2.2 bouyer * context left by sendsig. Check carefully to
276 1.5.2.2 bouyer * make sure that the user has not modified the
277 1.5.2.2 bouyer * psl to gain improper privileges or to cause
278 1.5.2.2 bouyer * a machine fault.
279 1.5.2.2 bouyer *
280 1.5.2.2 bouyer * XXX not tested
281 1.5.2.2 bouyer */
282 1.5.2.2 bouyer int
283 1.5.2.2 bouyer linux_sys_rt_sigreturn(p, v, retval)
284 1.5.2.2 bouyer struct proc *p;
285 1.5.2.2 bouyer void *v;
286 1.5.2.2 bouyer register_t *retval;
287 1.5.2.2 bouyer {
288 1.5.2.2 bouyer struct linux_sys_rt_sigreturn_args /* {
289 1.5.2.2 bouyer syscallarg(struct linux_rt_sigframe *) sfp;
290 1.5.2.2 bouyer } */ *uap = v;
291 1.5.2.2 bouyer struct linux_rt_sigframe *scp, sigframe;
292 1.5.2.2 bouyer struct trapframe *tf;
293 1.5.2.2 bouyer sigset_t mask;
294 1.5.2.2 bouyer int i;
295 1.5.2.2 bouyer
296 1.5.2.2 bouyer /*
297 1.5.2.2 bouyer * The trampoline code hands us the context.
298 1.5.2.2 bouyer * It is unsafe to keep track of it ourselves, in the event that a
299 1.5.2.2 bouyer * program jumps out of a signal handler.
300 1.5.2.2 bouyer */
301 1.5.2.2 bouyer scp = SCARG(uap, sfp);
302 1.5.2.2 bouyer
303 1.5.2.2 bouyer /*
304 1.5.2.2 bouyer * It seems we need a 16 bytes alignement here (it just works with it,
305 1.5.2.2 bouyer * don't ask me why
306 1.5.2.2 bouyer */
307 1.5.2.2 bouyer scp = (struct linux_rt_sigframe *)((unsigned long)scp & ~0xfUL);
308 1.5.2.2 bouyer
309 1.5.2.2 bouyer /*
310 1.5.2.2 bouyer * Get the context from user stack
311 1.5.2.2 bouyer */
312 1.5.2.2 bouyer if (copyin((caddr_t)scp, &sigframe, sizeof(*scp)) != 0)
313 1.5.2.2 bouyer return (EFAULT);
314 1.5.2.2 bouyer
315 1.5.2.2 bouyer /*
316 1.5.2.2 bouyer * Grab the signal mask
317 1.5.2.2 bouyer */
318 1.5.2.2 bouyer linux_to_native_sigset(&sigframe.luc.luc_sigmask, &mask);
319 1.5.2.2 bouyer
320 1.5.2.2 bouyer /*
321 1.5.2.2 bouyer * Restore register context. XXX need security review
322 1.5.2.2 bouyer */
323 1.5.2.2 bouyer tf = trapframe(p);
324 1.5.2.2 bouyer #ifdef DEBUG_LINUX
325 1.5.2.2 bouyer printf("linux_sys_sigreturn: trapframe=0x%lx scp=0x%lx\n",
326 1.5.2.2 bouyer (unsigned long)tf, (unsigned long)scp);
327 1.5.2.2 bouyer #endif
328 1.5.2.2 bouyer
329 1.5.2.2 bouyer if ((sigframe.luc.luc_context.lregs->lmsr & PSL_USERSTATIC) !=
330 1.5.2.2 bouyer (tf->srr1 & PSL_USERSTATIC))
331 1.5.2.2 bouyer return (EINVAL);
332 1.5.2.2 bouyer
333 1.5.2.2 bouyer for (i = 0; i < 32; i++)
334 1.5.2.2 bouyer tf->fixreg[i] = sigframe.luc.luc_context.lregs->lgpr[i];
335 1.5.2.2 bouyer tf->lr = sigframe.luc.luc_context.lregs->llink;
336 1.5.2.2 bouyer tf->cr = sigframe.luc.luc_context.lregs->lccr;
337 1.5.2.2 bouyer tf->xer = sigframe.luc.luc_context.lregs->lxer;
338 1.5.2.2 bouyer tf->ctr = sigframe.luc.luc_context.lregs->lctr;
339 1.5.2.2 bouyer tf->srr0 = sigframe.luc.luc_context.lregs->lnip;
340 1.5.2.2 bouyer tf->srr1 = sigframe.luc.luc_context.lregs->lmsr;
341 1.5.2.2 bouyer tf->dar = sigframe.luc.luc_context.lregs->ldar;
342 1.5.2.2 bouyer tf->dsisr = sigframe.luc.luc_context.lregs->ldsisr;
343 1.5.2.2 bouyer tf->exc = sigframe.luc.luc_context.lregs->lresult;
344 1.5.2.2 bouyer
345 1.5.2.2 bouyer /*
346 1.5.2.2 bouyer * Restore signal stack.
347 1.5.2.2 bouyer *
348 1.5.2.2 bouyer * XXX cannot find the onstack information in Linux sig context.
349 1.5.2.2 bouyer * Is signal stack really supported on Linux?
350 1.5.2.2 bouyer *
351 1.5.2.2 bouyer * It seems to be supported in libc6...
352 1.5.2.2 bouyer */
353 1.5.2.2 bouyer /* if (sc.sc_onstack & SS_ONSTACK)
354 1.5.2.2 bouyer p->p_sigctx.ps_sigstk.ss_flags |= SS_ONSTACK;
355 1.5.2.2 bouyer else */
356 1.5.2.2 bouyer p->p_sigctx.ps_sigstk.ss_flags &= ~SS_ONSTACK;
357 1.5.2.2 bouyer
358 1.5.2.2 bouyer return (EJUSTRETURN);
359 1.5.2.2 bouyer }
360 1.5.2.2 bouyer
361 1.5.2.2 bouyer
362 1.5.2.2 bouyer /*
363 1.5.2.2 bouyer * The following needs code review for potential security issues
364 1.5.2.2 bouyer */
365 1.5.2.2 bouyer int
366 1.5.2.2 bouyer linux_sys_sigreturn(p, v, retval)
367 1.5.2.2 bouyer struct proc *p;
368 1.5.2.2 bouyer void *v;
369 1.5.2.2 bouyer register_t *retval;
370 1.5.2.2 bouyer {
371 1.5.2.2 bouyer struct linux_sys_sigreturn_args /* {
372 1.5.2.2 bouyer syscallarg(struct linux_sigcontext *) scp;
373 1.5.2.2 bouyer } */ *uap = v;
374 1.5.2.2 bouyer struct linux_sigcontext *scp, context;
375 1.5.2.2 bouyer struct trapframe *tf;
376 1.5.2.2 bouyer sigset_t mask;
377 1.5.2.2 bouyer int i;
378 1.5.2.2 bouyer
379 1.5.2.2 bouyer /*
380 1.5.2.2 bouyer * The trampoline code hands us the context.
381 1.5.2.2 bouyer * It is unsafe to keep track of it ourselves, in the event that a
382 1.5.2.2 bouyer * program jumps out of a signal handler.
383 1.5.2.2 bouyer */
384 1.5.2.2 bouyer scp = SCARG(uap, scp);
385 1.5.2.2 bouyer
386 1.5.2.2 bouyer /*
387 1.5.2.2 bouyer * It seems we need a 16 bytes alignement here (it just works with it,
388 1.5.2.2 bouyer * don't ask me why
389 1.5.2.2 bouyer */
390 1.5.2.2 bouyer (unsigned long)scp = (unsigned long) scp & ~0xfUL;
391 1.5.2.2 bouyer
392 1.5.2.2 bouyer /*
393 1.5.2.2 bouyer * Get the context from user stack
394 1.5.2.2 bouyer */
395 1.5.2.2 bouyer if (copyin(scp, &context, sizeof(struct linux_sigcontext)) != 0)
396 1.5.2.2 bouyer return (EFAULT);
397 1.5.2.2 bouyer
398 1.5.2.2 bouyer /*
399 1.5.2.2 bouyer * Restore register context. XXX need security review
400 1.5.2.2 bouyer */
401 1.5.2.2 bouyer tf = trapframe(p);
402 1.5.2.2 bouyer #ifdef DEBUG_LINUX
403 1.5.2.2 bouyer printf("linux_sys_sigreturn: trapframe=0x%lx scp=0x%lx\n",
404 1.5.2.2 bouyer (unsigned long)tf, (unsigned long)scp);
405 1.5.2.2 bouyer #endif
406 1.5.2.2 bouyer
407 1.5.2.2 bouyer if ((context.lregs->lmsr & PSL_USERSTATIC) !=
408 1.5.2.2 bouyer (tf->srr1 & PSL_USERSTATIC))
409 1.5.2.2 bouyer return (EINVAL);
410 1.5.2.2 bouyer
411 1.5.2.2 bouyer for (i = 0; i < 32; i++)
412 1.5.2.2 bouyer tf->fixreg[i] = context.lregs->lgpr[i];
413 1.5.2.2 bouyer tf->lr = context.lregs->llink;
414 1.5.2.2 bouyer tf->cr = context.lregs->lccr;
415 1.5.2.2 bouyer tf->xer = context.lregs->lxer;
416 1.5.2.2 bouyer tf->ctr = context.lregs->lctr;
417 1.5.2.2 bouyer tf->srr0 = context.lregs->lnip;
418 1.5.2.2 bouyer tf->srr1 = context.lregs->lmsr;
419 1.5.2.2 bouyer tf->dar = context.lregs->ldar;
420 1.5.2.2 bouyer tf->dsisr = context.lregs->ldsisr;
421 1.5.2.2 bouyer tf->exc = context.lregs->lresult;
422 1.5.2.2 bouyer
423 1.5.2.2 bouyer /*
424 1.5.2.2 bouyer * Restore signal stack.
425 1.5.2.2 bouyer *
426 1.5.2.2 bouyer * XXX cannot find the onstack information in Linux sig context.
427 1.5.2.2 bouyer * Is signal stack really supported on Linux?
428 1.5.2.2 bouyer */
429 1.5.2.2 bouyer #if 0
430 1.5.2.2 bouyer if (sc.sc_onstack & SS_ONSTACK)
431 1.5.2.2 bouyer p->p_sigctx.ps_sigstk.ss_flags |= SS_ONSTACK;
432 1.5.2.2 bouyer else
433 1.5.2.2 bouyer #endif
434 1.5.2.2 bouyer p->p_sigctx.ps_sigstk.ss_flags &= ~SS_ONSTACK;
435 1.5.2.2 bouyer
436 1.5.2.2 bouyer /* Restore signal mask. */
437 1.5.2.2 bouyer linux_old_to_native_sigset(&context.lmask, &mask);
438 1.5.2.2 bouyer (void) sigprocmask1(p, SIG_SETMASK, &mask, 0);
439 1.5.2.2 bouyer
440 1.5.2.2 bouyer return (EJUSTRETURN);
441 1.5.2.2 bouyer }
442 1.5.2.2 bouyer
443 1.5.2.2 bouyer
444 1.5.2.2 bouyer int
445 1.5.2.2 bouyer linux_sys_modify_ldt(p, v, retval)
446 1.5.2.2 bouyer struct proc *p;
447 1.5.2.2 bouyer void *v;
448 1.5.2.2 bouyer register_t *retval;
449 1.5.2.2 bouyer {
450 1.5.2.2 bouyer /*
451 1.5.2.2 bouyer * This syscall is not implemented in Linux/PowerPC: we should not
452 1.5.2.2 bouyer * be here
453 1.5.2.2 bouyer */
454 1.5.2.2 bouyer #ifdef DEBUG_LINUX
455 1.5.2.2 bouyer printf("linux_sys_modify_ldt: should not be here.\n");
456 1.5.2.2 bouyer #endif
457 1.5.2.2 bouyer return 0;
458 1.5.2.2 bouyer }
459 1.5.2.2 bouyer
460 1.5.2.3 bouyer /*
461 1.5.2.3 bouyer * major device numbers remapping
462 1.5.2.3 bouyer */
463 1.5.2.2 bouyer dev_t
464 1.5.2.2 bouyer linux_fakedev(dev)
465 1.5.2.2 bouyer dev_t dev;
466 1.5.2.2 bouyer {
467 1.5.2.2 bouyer /* XXX write me */
468 1.5.2.2 bouyer return dev;
469 1.5.2.2 bouyer }
470 1.5.2.2 bouyer
471 1.5.2.2 bouyer /*
472 1.5.2.2 bouyer * We come here in a last attempt to satisfy a Linux ioctl() call
473 1.5.2.2 bouyer */
474 1.5.2.2 bouyer int
475 1.5.2.2 bouyer linux_machdepioctl(p, v, retval)
476 1.5.2.2 bouyer struct proc *p;
477 1.5.2.2 bouyer void *v;
478 1.5.2.2 bouyer register_t *retval;
479 1.5.2.2 bouyer {
480 1.5.2.2 bouyer struct linux_sys_ioctl_args /* {
481 1.5.2.2 bouyer syscallarg(int) fd;
482 1.5.2.2 bouyer syscallarg(u_long) com;
483 1.5.2.2 bouyer syscallarg(caddr_t) data;
484 1.5.2.2 bouyer } */ *uap = v;
485 1.5.2.2 bouyer struct sys_ioctl_args bia;
486 1.5.2.2 bouyer u_long com;
487 1.5.2.2 bouyer
488 1.5.2.2 bouyer SCARG(&bia, fd) = SCARG(uap, fd);
489 1.5.2.2 bouyer SCARG(&bia, data) = SCARG(uap, data);
490 1.5.2.2 bouyer com = SCARG(uap, com);
491 1.5.2.2 bouyer
492 1.5.2.2 bouyer switch (com) {
493 1.5.2.2 bouyer default:
494 1.5.2.2 bouyer printf("linux_machdepioctl: invalid ioctl %08lx\n", com);
495 1.5.2.2 bouyer return EINVAL;
496 1.5.2.2 bouyer }
497 1.5.2.2 bouyer SCARG(&bia, com) = com;
498 1.5.2.2 bouyer return sys_ioctl(p, &bia, retval);
499 1.5.2.2 bouyer }
500 1.5.2.2 bouyer /*
501 1.5.2.2 bouyer * Set I/O permissions for a process. Just set the maximum level
502 1.5.2.2 bouyer * right away (ignoring the argument), otherwise we would have
503 1.5.2.2 bouyer * to rely on I/O permission maps, which are not implemented.
504 1.5.2.2 bouyer */
505 1.5.2.2 bouyer int
506 1.5.2.2 bouyer linux_sys_iopl(p, v, retval)
507 1.5.2.2 bouyer struct proc *p;
508 1.5.2.2 bouyer void *v;
509 1.5.2.2 bouyer register_t *retval;
510 1.5.2.2 bouyer {
511 1.5.2.2 bouyer /*
512 1.5.2.2 bouyer * This syscall is not implemented in Linux/PowerPC: we should not be here
513 1.5.2.2 bouyer */
514 1.5.2.2 bouyer #ifdef DEBUG_LINUX
515 1.5.2.2 bouyer printf("linux_sys_iopl: should not be here.\n");
516 1.5.2.2 bouyer #endif
517 1.5.2.2 bouyer return 0;
518 1.5.2.2 bouyer }
519 1.5.2.2 bouyer
520 1.5.2.2 bouyer /*
521 1.5.2.2 bouyer * See above. If a root process tries to set access to an I/O port,
522 1.5.2.2 bouyer * just let it have the whole range.
523 1.5.2.2 bouyer */
524 1.5.2.2 bouyer int
525 1.5.2.2 bouyer linux_sys_ioperm(p, v, retval)
526 1.5.2.2 bouyer struct proc *p;
527 1.5.2.2 bouyer void *v;
528 1.5.2.2 bouyer register_t *retval;
529 1.5.2.2 bouyer {
530 1.5.2.2 bouyer /*
531 1.5.2.2 bouyer * This syscall is not implemented in Linux/PowerPC: we should not be here
532 1.5.2.2 bouyer */
533 1.5.2.2 bouyer #ifdef DEBUG_LINUX
534 1.5.2.2 bouyer printf("linux_sys_ioperm: should not be here.\n");
535 1.5.2.2 bouyer #endif
536 1.5.2.2 bouyer return 0;
537 1.5.2.2 bouyer }
538 1.5.2.2 bouyer
539 1.5.2.2 bouyer /*
540 1.5.2.2 bouyer * wrapper linux_sys_new_uname() -> linux_sys_uname()
541 1.5.2.2 bouyer */
542 1.5.2.2 bouyer int
543 1.5.2.2 bouyer linux_sys_new_uname(p, v, retval)
544 1.5.2.2 bouyer struct proc *p;
545 1.5.2.2 bouyer void *v;
546 1.5.2.2 bouyer register_t *retval;
547 1.5.2.2 bouyer {
548 1.5.2.2 bouyer return linux_sys_uname(p, v, retval);
549 1.5.2.2 bouyer }
550 1.5.2.2 bouyer
551 1.5.2.2 bouyer /*
552 1.5.2.2 bouyer * wrapper linux_sys_new_select() -> linux_sys_select()
553 1.5.2.2 bouyer */
554 1.5.2.2 bouyer int
555 1.5.2.2 bouyer linux_sys_new_select(p, v, retval)
556 1.5.2.2 bouyer struct proc *p;
557 1.5.2.2 bouyer void *v;
558 1.5.2.2 bouyer register_t *retval;
559 1.5.2.2 bouyer {
560 1.5.2.2 bouyer return linux_sys_select(p, v, retval);
561 1.5.2.2 bouyer }
562