1 /* $NetBSD: compat_13_machdep.c,v 1.5 2002/09/25 22:21:04 thorpej Exp $ */ 2 3 /* 4 * Copyright (c) 1994-1998 Mark Brinicombe. 5 * Copyright (c) 1994 Brini. 6 * All rights reserved. 7 * 8 * This code is derived from software written for Brini by Mark Brinicombe 9 * 10 * Redistribution and use in source and binary forms, with or without 11 * modification, are permitted provided that the following conditions 12 * are met: 13 * 1. Redistributions of source code must retain the above copyright 14 * notice, this list of conditions and the following disclaimer. 15 * 2. Redistributions in binary form must reproduce the above copyright 16 * notice, this list of conditions and the following disclaimer in the 17 * documentation and/or other materials provided with the distribution. 18 * 3. All advertising materials mentioning features or use of this software 19 * must display the following acknowledgement: 20 * This product includes software developed by Mark Brinicombe 21 * for the NetBSD Project. 22 * 4. The name of the company nor the name of the author may be used to 23 * endorse or promote products derived from this software without specific 24 * prior written permission. 25 * 26 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 27 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 28 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 29 * IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 30 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 31 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 32 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 33 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 34 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 35 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 36 * SUCH DAMAGE. 37 */ 38 39 #include <sys/param.h> 40 41 __KERNEL_RCSID(0, "$NetBSD: compat_13_machdep.c,v 1.5 2002/09/25 22:21:04 thorpej Exp $"); 42 43 #include <sys/systm.h> 44 #include <sys/signalvar.h> 45 #include <sys/kernel.h> 46 #include <sys/proc.h> 47 #include <sys/user.h> 48 #include <sys/mount.h> 49 #include <sys/syscallargs.h> 50 51 int 52 compat_13_sys_sigreturn(struct proc *p, void *v, register_t *retval) 53 { 54 struct compat_13_sys_sigreturn_args /* { 55 syscallarg(struct sigcontext13 *) sigcntxp; 56 } */ *uap = v; 57 struct sigcontext13 *scp, context; 58 struct trapframe *tf; 59 sigset_t mask; 60 61 /* 62 * The trampoline code hands us the context. 63 * It is unsafe to keep track of it ourselves, in the event that a 64 * program jumps out of a signal handler. 65 */ 66 scp = SCARG(uap, sigcntxp); 67 if (copyin((caddr_t)scp, &context, sizeof(*scp)) != 0) 68 return (EFAULT); 69 70 /* 71 * Make sure the processor mode has not been tampered with and 72 * interrupts have not been disabled. 73 */ 74 #ifdef __PROG32 75 if ((context.sc_spsr & PSR_MODE) != PSR_USR32_MODE || 76 (context.sc_spsr & (I32_bit | F32_bit)) != 0) 77 return (EINVAL); 78 #else /* __PROG26 */ 79 if ((context.sc_pc & R15_MODE) != R15_MODE_USR || 80 (context.sc_pc & (R15_IRQ_DISABLE | R15_FIQ_DISABLE)) != 0) 81 return EINVAL; 82 #endif 83 84 /* Restore register context. */ 85 tf = p->p_addr->u_pcb.pcb_tf; 86 tf->tf_r0 = context.sc_r0; 87 tf->tf_r1 = context.sc_r1; 88 tf->tf_r2 = context.sc_r2; 89 tf->tf_r3 = context.sc_r3; 90 tf->tf_r4 = context.sc_r4; 91 tf->tf_r5 = context.sc_r5; 92 tf->tf_r6 = context.sc_r6; 93 tf->tf_r7 = context.sc_r7; 94 tf->tf_r8 = context.sc_r8; 95 tf->tf_r9 = context.sc_r9; 96 tf->tf_r10 = context.sc_r10; 97 tf->tf_r11 = context.sc_r11; 98 tf->tf_r12 = context.sc_r12; 99 tf->tf_usr_sp = context.sc_usr_sp; 100 tf->tf_usr_lr = context.sc_usr_lr; 101 tf->tf_svc_lr = context.sc_svc_lr; 102 tf->tf_pc = context.sc_pc; 103 tf->tf_spsr = context.sc_spsr; 104 105 /* Restore signal stack. */ 106 if (context.sc_onstack & SS_ONSTACK) 107 p->p_sigctx.ps_sigstk.ss_flags |= SS_ONSTACK; 108 else 109 p->p_sigctx.ps_sigstk.ss_flags &= ~SS_ONSTACK; 110 111 /* Restore signal mask. */ 112 native_sigset13_to_sigset(&context.sc_mask, &mask); 113 (void) sigprocmask1(p, SIG_SETMASK, &mask, 0); 114 115 return (EJUSTRETURN); 116 } 117