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